[RFC PATCH 07/12] entry: Carry ordinary-hardirq provenance through kernel return
Karl Mehltretter
kmehltretter at gmail.com
Wed Oct 21 22:16:49 PDT 2026
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.
Record ordinary-hardirq provenance in irqentry_state_t and initialize it
in every entry path. 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 | 4 ++++
kernel/entry/common.c | 6 +++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/include/linux/irq-entry-common.h b/include/linux/irq-entry-common.h
index 24c2b9fdff4f4..2ed637cf66b0c 100644
--- a/include/linux/irq-entry-common.h
+++ b/include/linux/irq-entry-common.h
@@ -333,6 +333,8 @@ static __always_inline void irqentry_exit_to_user_mode(struct pt_regs *regs)
* 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: Records that irqentry_hardirq_enter() established this state for
+ * an ordinary hard interrupt.
*
* This opaque object is filled in by the irqentry_*_enter() functions and
* must be passed back into the corresponding irqentry_*_exit() functions
@@ -347,6 +349,7 @@ typedef struct irqentry_state {
bool exit_rcu;
bool lockdep;
};
+ bool hardirq;
} irqentry_state_t;
#endif
@@ -396,6 +399,7 @@ __irqentry_enter_from_kernel_mode(struct pt_regs *regs, bool hardirq)
{
irqentry_state_t ret = {
.exit_rcu = false,
+ .hardirq = hardirq,
};
/*
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index 36c43d3c76eae..ba5959a84bc4a 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 = false,
};
irqentry_enter_from_user_mode(regs);
@@ -140,6 +141,7 @@ noinstr irqentry_state_t irqentry_hardirq_enter(struct pt_regs *regs)
if (user_mode(regs)) {
irqentry_state_t ret = {
.exit_rcu = false,
+ .hardirq = true,
};
__enter_from_user_mode(regs, true);
@@ -199,7 +201,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 = false,
+ };
irq_state.lockdep = lockdep_hardirqs_enabled_raw();
--
2.39.5 (Apple Git-154)
More information about the linux-arm-kernel
mailing list