The opid hybrid-automaton guards compare irq_off with 1. However,
irqs_disabled() only guarantees zero or nonzero. On 32-bit Arm,
arch_irqs_disabled_flags() returns the CPSR I bit, 0x80. Consequently,
valid events with interrupts disabled fail the guard and spuriously
trigger the reactor.

Normalize the value before returning it. Add a KUnit regression test
that handles a need-resched event with local interrupts disabled.
Without the normalization, the test triggers a reaction on Arm.

Fixes: 2b406fdb33387 ("rv: Convert the opid monitor to a hybrid automaton")
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <[email protected]>
---
Tested with an ARMv7 GCC 16 W=1 build and targeted SMP1 QEMU run:
rv_test_opid and the RV KUnit suite pass.

 kernel/trace/rv/monitors/opid/opid.c       | 2 +-
 kernel/trace/rv/monitors/opid/opid_kunit.c | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/rv/monitors/opid/opid.c 
b/kernel/trace/rv/monitors/opid/opid.c
index 9ae619f176fa1..a14532cc41778 100644
--- a/kernel/trace/rv/monitors/opid/opid.c
+++ b/kernel/trace/rv/monitors/opid/opid.c
@@ -20,7 +20,7 @@
 static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs_opid env, u64 
time_ns)
 {
        if (env == irq_off_opid)
-               return irqs_disabled();
+               return !!irqs_disabled();
        else if (env == preempt_off_opid) {
                if (IS_ENABLED(CONFIG_PREEMPTION))
                        return (preempt_count() & PREEMPT_MASK) > 0;
diff --git a/kernel/trace/rv/monitors/opid/opid_kunit.c 
b/kernel/trace/rv/monitors/opid/opid_kunit.c
index 3cb087a74241e..8aa1fb9c62344 100644
--- a/kernel/trace/rv/monitors/opid/opid_kunit.c
+++ b/kernel/trace/rv/monitors/opid/opid_kunit.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/kernel.h>
+#include <linux/irqflags.h>
 #include <linux/rv.h>
 #include <rv/kunit.h>
 #include <trace/events/sched.h>
@@ -17,6 +18,11 @@ static void rv_test_opid(struct kunit *test)
        guard(migrate)();
        KUNIT_EXPECT_TRUE(test, preemptible());
 
+       /* Need resched with interrupts disabled */
+       scoped_guard(irq)
+               rv_opid_ops.handle_sched_need_resched(NULL, NULL, 0, 
TIF_NEED_RESCHED);
+       RV_KUNIT_EXPECT_NO_REACTION(test, ctx);
+
        /* Wakeup with preemption and interrupts enabled */
        RV_KUNIT_EXPECT_REACTION_HERE(test, ctx)
                rv_opid_ops.handle_sched_waking(NULL, NULL);

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
-- 
2.39.5 (Apple Git-154)


Reply via email to