[RFC PATCH v2 09/13] entry: Carry ordinary-hardirq provenance through kernel return
flat view
HOTtoday
From: Karl Mehltretter <hidden>
Date: 2026-10-28 03:32:09
Also in:
linux-doc, linux-rt-devel, linux-trace-kernel, lkml, llvm
Subsystem:
generic entry code, the rest · Maintainers:
Thomas Gleixner, Peter Zijlstra, Andy Lutomirski, Linus Torvalds
The entry state can cross hardirq teardown and a possible reschedule before the architecture completes its return tail. At that point preempt_count() no longer identifies whether the original entry was an ordinary hardirq, a synchronous exception, or an NMI-like event. Initialize the hardirq state in every entry path so irqentry_state_t distinguishes ordinary hardirqs from other entries across kernel return while keeping the two-byte generic state layout. A later return tail can restore hardirq classification only for entries which established the pre-counted hardirq lifecycle. Assisted-by: LLM --- include/linux/irq-entry-common.h | 6 ++++-- kernel/entry/common.c | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/include/linux/irq-entry-common.h b/include/linux/irq-entry-common.h
index e1fd9155410c1..6f649f6613312 100644
--- a/include/linux/irq-entry-common.h
+++ b/include/linux/irq-entry-common.h@@ -341,8 +341,8 @@ enum irqentry_hardirq_state { * exit path has to invoke ct_irq_exit(). * @lockdep: Used exclusively in the irqentry_nmi_*() calls; ensures that * lockdep state is restored correctly on exit from nmi. - * @hardirq: Encodes whether the current staged hardirq-count attempt was - * applied. + * @hardirq: Encodes ordinary-hardirq provenance and whether the current + * staged hardirq-count attempt was applied. * * This opaque object is filled in by the irqentry_*_enter() functions and * must be passed back into the corresponding irqentry_*_exit() functions
@@ -412,6 +412,8 @@ __irqentry_enter_from_kernel_mode(struct pt_regs *regs, bool hardirq) { irqentry_state_t ret = { .exit_rcu = false, + .hardirq = hardirq ? IRQENTRY_HARDIRQ_APPLIED : + IRQENTRY_HARDIRQ_NONE, }; /*
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index 9d207c37c5707..c7814c51bb35d 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c@@ -112,6 +112,7 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs) if (user_mode(regs)) { irqentry_state_t ret = { .exit_rcu = false, + .hardirq = IRQENTRY_HARDIRQ_NONE, }; irqentry_enter_from_user_mode(regs);
@@ -144,6 +145,7 @@ noinstr irqentry_state_t irqentry_hardirq_enter(struct pt_regs *regs) if (user_mode(regs)) { ret = (irqentry_state_t) { .exit_rcu = false, + .hardirq = IRQENTRY_HARDIRQ_APPLIED, }; irqentry_hardirq_count_state_set(&ret, cookie);
@@ -193,7 +195,9 @@ noinstr void irqentry_exit(struct pt_regs *regs, irqentry_state_t state) irqentry_state_t noinstr irqentry_nmi_enter(struct pt_regs *regs) { - irqentry_state_t irq_state; + irqentry_state_t irq_state = { + .hardirq = IRQENTRY_HARDIRQ_NONE, + }; irq_state.lockdep = lockdep_hardirqs_enabled_raw();
--
2.39.5 (Apple Git-154)