Re: [PATCH v2 3/3] ARM: vfp: Fix broken softirq handling with instrumentation enabled

From
Ard Biesheuvel <ardb@kernel.org>
Date
2023-03-16 08:03:41
Reply to
Ard Biesheuvel, 2023-03-14
On Tue, 14 Mar 2023 at 23:25, Ard Biesheuvel [off-list ref] wrote:
On Tue, 14 Mar 2023 at 22:46, Peter Zijlstra [off-list ref] wrote:
quoted
On Tue, Mar 14, 2023 at 09:46:21PM +0100, Linus Walleij wrote:
quoted
Hi Ard,

On Tue, Mar 14, 2023 at 8:28 PM Ard Biesheuvel [off-list ref] wrote:
quoted
Commit 62b95a7b44d1 ("ARM: 9282/1: vfp: Manipulate task VFP state with
softirqs disabled") replaced the en/disable preemption calls inside the
VFP state handling code with en/disabling of soft IRQs, which is
necessary to allow kernel use of the VFP/SIMD unit when handling a soft
IRQ.

Unfortunately, when lockdep is enabled (or other instrumentation that
enables TRACE_IRQFLAGS), the disable path implemented in asm fails to
perform the lockdep and RCU related bookkeeping, resulting in spurious
warnings and other badness.
Not good.
quoted
Set let's rework the VFP entry code a little bit so we can make the
local_bh_disable() call from C, with all the instrumentations that
happen to have been configured. Calling local_bh_enable() can be done
from asm, as it is always a callable function.
Here it says local_bh_enable() is called

(...)
quoted
+local_bh_enable_and_ret:
+       adr     r0, .
+       mov     r1, #SOFTIRQ_DISABLE_OFFSET
+       b       __local_bh_enable_ip    @ tail call
Please add a comment here that this is an open coded version of
local_bh_enable() from the <linux/bottom_half.h> header file
and we hope that inline code will not change.

I.e this:

static inline void local_bh_enable(void)
{
        __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
}

I almost want to make a warning comment into <linux/bottom_half.h>
that the same function exists in an open coded version in arch/arm/vfp/vfphw.S
so this static inline cannot be refactored without consequences.
So we could do something like the below to make local_bh_enable() both
an inline and an actual symbol for those who need to call it from asm.

It seems to compile on both GCC-12 and Clang-15.
diff --git a/include/linux/bottom_half.h b/include/linux/bottom_half.h
index fc53e0ad56d9..85fcdf647f9f 100644
--- a/include/linux/bottom_half.h
+++ b/include/linux/bottom_half.h
@@ -28,7 +28,7 @@ static inline void local_bh_enable_ip(unsigned long ip)
        __local_bh_enable_ip(ip, SOFTIRQ_DISABLE_OFFSET);
 }

-static inline void local_bh_enable(void)
+extern inline void local_bh_enable(void)
 {
        __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
 }
diff --git a/kernel/softirq.c b/kernel/softirq.c
index c8a6913c067d..91d8677f890a 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -1010,3 +1010,8 @@ unsigned int __weak arch_dynirq_lower_bound(unsigned int from)
 {
        return from;
 }
+
+void local_bh_enable(void)
+{
+       __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
+}
That would be much better, yes.

These fixes ultimately need to be backported to v6.2 so I'm not sure
if we want to include this now, or keep it as a cleanup for the next
cycle?
Actually, I ended up going a bit further than this, and reimplemented
vfp_support_entry() in C entirely. I will add that as a patch to the
next revision, but that one should not be backported.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Thread (11 messages) 11 messages, 4 authors, last reply 2023-03-16
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help