Normalize opid IRQ state to a boolean
Subsystems (2)
PATCH 1/1 Normalize opid IRQ state to a boolean
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.
---
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(-)
kernel/trace/rv/monitors/opid/opid.c +1 -1
@@ -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 ;
kernel/trace/rv/monitors/opid/opid_kunit.c +6 -0
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 6 lines · Karl Mehltretter
The opid hybrid-automaton guards compare
irq_offwith 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.
Quoted 8 lines
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 LLMSigned-off-by Karl Mehltretter <[email protected]>---
Looks reasonable, thanks!
Quoted 45 lines
Tested with an ARMv7 GCC 16 W=1 build and targeted SMP1 QEMU run:
rv_test_opidand 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(-)kernel/trace/rv/monitors/opid/opid.c +1
-1@@ -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 ;kernel/trace/rv/monitors/opid/opid_kunit.c +6
-0@@ -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