[PATCH] ARM: fix smp_processor_id() in preemptible warning in harden_branch_predictor()

Subsystems: arm port, the rest

STALE1967d

4 messages, 3 authors, 2021-03-25 · open the first message on its own page

[PATCH] ARM: fix smp_processor_id() in preemptible warning in harden_branch_predictor()

From: Liu Xiang <hidden>
Date: 2021-03-25 09:51:39

When CONFIG_HARDEN_BRANCH_PREDICTOR is selected and user aborts occur,
there is a warning:

BUG: using smp_processor_id() in preemptible [00000000] code: errnotest/577
caller is __do_user_fault.constprop.4+0x24/0x88
CPU: 1 PID: 577 Comm: errnotest Not tainted 4.14.188-rt87-fmsh-00004-g58055877a #1
Hardware name: FMSH PSOC Platform
[<8010d6d4>] (unwind_backtrace) from [<8010a228>] (show_stack+0x10/0x14)
[<8010a228>] (show_stack) from [<80698f44>] (dump_stack+0x7c/0x98)
[<80698f44>] (dump_stack) from [<803d17d0>] (check_preemption_disabled+0xc4/0xfc)
[<803d17d0>] (check_preemption_disabled) from [<80110eb8>] (__do_user_fault.constprop.4+0x24/0x88)
[<80110eb8>] (__do_user_fault.constprop.4) from [<801112e4>] (do_page_fault+0x2dc/0x310)
[<801112e4>] (do_page_fault) from [<801012a8>] (do_DataAbort+0x38/0xb8)
[<801012a8>] (do_DataAbort) from [<8010b03c>] (__dabt_usr+0x3c/0x40)
Exception stack(0xb21d1fb0 to 0xb21d1ff8)
1fa0:                                     fffffff4 00000000 00000054 fffffff4
1fc0: 00000000 00000000 7ed81cc8 7ed81ca0 0007a440 00000000 00000000 00000000
1fe0: 00000000 7ed81ca0 00010493 0001f330 20030010 ffffffff

Signed-off-by: Liu Xiang <redacted>
---
 arch/arm/include/asm/system_misc.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/system_misc.h b/arch/arm/include/asm/system_misc.h
index 66f6a3ae6..4a55cfbdf 100644
--- a/arch/arm/include/asm/system_misc.h
+++ b/arch/arm/include/asm/system_misc.h
@@ -22,9 +22,10 @@ DECLARE_PER_CPU(harden_branch_predictor_fn_t, harden_branch_predictor_fn);
 static inline void harden_branch_predictor(void)
 {
 	harden_branch_predictor_fn_t fn = per_cpu(harden_branch_predictor_fn,
-						  smp_processor_id());
+						  get_cpu());
 	if (fn)
 		fn();
+	put_cpu();
 }
 #else
 #define harden_branch_predictor() do { } while (0)
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH] ARM: fix smp_processor_id() in preemptible warning in harden_branch_predictor()

From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Date: 2021-03-25 10:06:57

On Thu, Mar 25, 2021 at 05:50:49PM +0800, Liu Xiang wrote:
When CONFIG_HARDEN_BRANCH_PREDICTOR is selected and user aborts occur,
there is a warning:

BUG: using smp_processor_id() in preemptible [00000000] code: errnotest/577
caller is __do_user_fault.constprop.4+0x24/0x88
CPU: 1 PID: 577 Comm: errnotest Not tainted 4.14.188-rt87-fmsh-00004-g58055877a #1
Hardware name: FMSH PSOC Platform
[<8010d6d4>] (unwind_backtrace) from [<8010a228>] (show_stack+0x10/0x14)
[<8010a228>] (show_stack) from [<80698f44>] (dump_stack+0x7c/0x98)
[<80698f44>] (dump_stack) from [<803d17d0>] (check_preemption_disabled+0xc4/0xfc)
[<803d17d0>] (check_preemption_disabled) from [<80110eb8>] (__do_user_fault.constprop.4+0x24/0x88)
[<80110eb8>] (__do_user_fault.constprop.4) from [<801112e4>] (do_page_fault+0x2dc/0x310)
[<801112e4>] (do_page_fault) from [<801012a8>] (do_DataAbort+0x38/0xb8)
[<801012a8>] (do_DataAbort) from [<8010b03c>] (__dabt_usr+0x3c/0x40)
Exception stack(0xb21d1fb0 to 0xb21d1ff8)
1fa0:                                     fffffff4 00000000 00000054 fffffff4
1fc0: 00000000 00000000 7ed81cc8 7ed81ca0 0007a440 00000000 00000000 00000000
1fe0: 00000000 7ed81ca0 00010493 0001f330 20030010 ffffffff
This is not the right fix - preemption is supposed to be disabled before
this function is called. I'm not sure at the present time what the right
fix is supposed to be because I've forgotten most of the background
behind why this was placed where it is.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH] ARM: fix smp_processor_id() in preemptible warning in harden_branch_predictor()

From: Liu Xiang <hidden>
Date: 2021-03-25 13:34:02

Russell King - ARM Linux admin [off-list ref] 于2021年3月25日周四 下午6:06写道:
On Thu, Mar 25, 2021 at 05:50:49PM +0800, Liu Xiang wrote:
quoted
When CONFIG_HARDEN_BRANCH_PREDICTOR is selected and user aborts occur,
there is a warning:

BUG: using smp_processor_id() in preemptible [00000000] code: errnotest/577
caller is __do_user_fault.constprop.4+0x24/0x88
CPU: 1 PID: 577 Comm: errnotest Not tainted 4.14.188-rt87-fmsh-00004-g58055877a #1
Hardware name: FMSH PSOC Platform
[<8010d6d4>] (unwind_backtrace) from [<8010a228>] (show_stack+0x10/0x14)
[<8010a228>] (show_stack) from [<80698f44>] (dump_stack+0x7c/0x98)
[<80698f44>] (dump_stack) from [<803d17d0>] (check_preemption_disabled+0xc4/0xfc)
[<803d17d0>] (check_preemption_disabled) from [<80110eb8>] (__do_user_fault.constprop.4+0x24/0x88)
[<80110eb8>] (__do_user_fault.constprop.4) from [<801112e4>] (do_page_fault+0x2dc/0x310)
[<801112e4>] (do_page_fault) from [<801012a8>] (do_DataAbort+0x38/0xb8)
[<801012a8>] (do_DataAbort) from [<8010b03c>] (__dabt_usr+0x3c/0x40)
Exception stack(0xb21d1fb0 to 0xb21d1ff8)
1fa0:                                     fffffff4 00000000 00000054 fffffff4
1fc0: 00000000 00000000 7ed81cc8 7ed81ca0 0007a440 00000000 00000000 00000000
1fe0: 00000000 7ed81ca0 00010493 0001f330 20030010 ffffffff
This is not the right fix - preemption is supposed to be disabled before
this function is called. I'm not sure at the present time what the right
fix is supposed to be because I've forgotten most of the background
behind why this was placed where it is.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
I have tested with the current mainline kernel, the warning still exists.
[   14.404322] BUG: using smp_processor_id() in preemptible [00000000]
code: errnotest/81
[   14.404795] caller is __do_user_fault.constprop.5+0x54/0x7c
[   14.405163] CPU: 1 PID: 81 Comm: errnotest Not tainted
5.12.0-rc4-ge97a94a30e55-dirty #6
[   14.405616] Hardware name: ARM-Versatile Express
[   14.406475] [<c010af58>] (unwind_backtrace) from [<c01064c4>]
(show_stack+0x10/0x14)
[   14.407018] [<c01064c4>] (show_stack) from [<c0a6a0cc>]
(dump_stack+0x8c/0xa0)
[   14.407398] [<c0a6a0cc>] (dump_stack) from [<c0a6d0a4>]
(check_preemption_disabled+0x114/0x118)
[   14.407906] [<c0a6d0a4>] (check_preemption_disabled) from
[<c010ef68>] (__do_user_fault.constprop.5+0x54/0x7c)
[   14.408367] [<c010ef68>] (__do_user_fault.constprop.5) from
[<c010f274>] (do_page_fault+0x208/0x3bc)
[   14.408907] [<c010f274>] (do_page_fault) from [<c010f588>]
(do_DataAbort+0x3c/0xbc)
[   14.409266] [<c010f588>] (do_DataAbort) from [<c0100e7c>]
(__dabt_usr+0x3c/0x40)
[   14.409721] Exception stack(0xc285ffb0 to 0xc285fff8)
[   14.410099] ffa0:                                     fffffff4
00000000 00000054 fffffff4
[   14.411000] ffc0: 00000000 00000000 bed90d28 bed90d00 0007a440
00000000 00000000 00000000
[   14.411386] ffe0: 00000000 bed90d00 00010493 0001f330 20030010 ffffffff
Segmentation fault

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH] ARM: fix smp_processor_id() in preemptible warning in harden_branch_predictor()

From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Date: 2021-03-25 14:21:07

On Thu, Mar 25, 2021 at 09:32:35PM +0800, Liu Xiang wrote:
Russell King - ARM Linux admin [off-list ref] 于2021年3月25日周四 下午6:06写道:
quoted
On Thu, Mar 25, 2021 at 05:50:49PM +0800, Liu Xiang wrote:
quoted
When CONFIG_HARDEN_BRANCH_PREDICTOR is selected and user aborts occur,
there is a warning:

BUG: using smp_processor_id() in preemptible [00000000] code: errnotest/577
caller is __do_user_fault.constprop.4+0x24/0x88
CPU: 1 PID: 577 Comm: errnotest Not tainted 4.14.188-rt87-fmsh-00004-g58055877a #1
Hardware name: FMSH PSOC Platform
[<8010d6d4>] (unwind_backtrace) from [<8010a228>] (show_stack+0x10/0x14)
[<8010a228>] (show_stack) from [<80698f44>] (dump_stack+0x7c/0x98)
[<80698f44>] (dump_stack) from [<803d17d0>] (check_preemption_disabled+0xc4/0xfc)
[<803d17d0>] (check_preemption_disabled) from [<80110eb8>] (__do_user_fault.constprop.4+0x24/0x88)
[<80110eb8>] (__do_user_fault.constprop.4) from [<801112e4>] (do_page_fault+0x2dc/0x310)
[<801112e4>] (do_page_fault) from [<801012a8>] (do_DataAbort+0x38/0xb8)
[<801012a8>] (do_DataAbort) from [<8010b03c>] (__dabt_usr+0x3c/0x40)
Exception stack(0xb21d1fb0 to 0xb21d1ff8)
1fa0:                                     fffffff4 00000000 00000054 fffffff4
1fc0: 00000000 00000000 7ed81cc8 7ed81ca0 0007a440 00000000 00000000 00000000
1fe0: 00000000 7ed81ca0 00010493 0001f330 20030010 ffffffff
This is not the right fix - preemption is supposed to be disabled before
this function is called. I'm not sure at the present time what the right
fix is supposed to be because I've forgotten most of the background
behind why this was placed where it is.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
I have tested with the current mainline kernel, the warning still exists.
Yes, it still exists, because it's never been fixed, but the way you are
fixing it is not correct. We do not paper over warnings with incorrect
fixes.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help