bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] context_tracking: Provide helper to determine if we're in IRQ
@ 2025-06-09 18:01 Joel Fernandes
  2025-06-09 18:01 ` [PATCH 2/2] rcu: Fix lockup when RCU reader used while IRQ exiting Joel Fernandes
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Joel Fernandes @ 2025-06-09 18:01 UTC (permalink / raw)
  To: linux-kernel, Frederic Weisbecker, Paul E. McKenney
  Cc: Xiongfeng Wang, rcu, bpf, Joel Fernandes

context_tracking keeps track of whether we're handling IRQ well after
the preempt masks give take it off their books. We need this
functionality in a follow-up patch to fix a bug. Provide a helper API
for the same.

Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
---
 include/linux/context_tracking_irq.h |  2 ++
 kernel/context_tracking.c            | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/linux/context_tracking_irq.h b/include/linux/context_tracking_irq.h
index 197916ee91a4..35a5ad971514 100644
--- a/include/linux/context_tracking_irq.h
+++ b/include/linux/context_tracking_irq.h
@@ -9,6 +9,7 @@ void ct_irq_enter_irqson(void);
 void ct_irq_exit_irqson(void);
 void ct_nmi_enter(void);
 void ct_nmi_exit(void);
+bool ct_in_irq(void);
 #else
 static __always_inline void ct_irq_enter(void) { }
 static __always_inline void ct_irq_exit(void) { }
@@ -16,6 +17,7 @@ static inline void ct_irq_enter_irqson(void) { }
 static inline void ct_irq_exit_irqson(void) { }
 static __always_inline void ct_nmi_enter(void) { }
 static __always_inline void ct_nmi_exit(void) { }
+static inline bool ct_in_irq(void) { return false; }
 #endif
 
 #endif
diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c
index fb5be6e9b423..d0759ef9a6bd 100644
--- a/kernel/context_tracking.c
+++ b/kernel/context_tracking.c
@@ -392,6 +392,18 @@ noinstr void ct_irq_exit(void)
 	ct_nmi_exit();
 }
 
+/**
+ * ct_in_irq - check if CPU is in a context-tracked IRQ context.
+ *
+ * Returns true if ct_irq_enter() has been called and ct_irq_exit()
+ * has not yet been called. This indicates the CPU is currently
+ * processing an interrupt.
+ */
+bool ct_in_irq(void)
+{
+	return ct_nmi_nesting() != 0;
+}
+
 /*
  * Wrapper for ct_irq_enter() where interrupts are enabled.
  *
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-06-12 11:37 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-09 18:01 [PATCH 1/2] context_tracking: Provide helper to determine if we're in IRQ Joel Fernandes
2025-06-09 18:01 ` [PATCH 2/2] rcu: Fix lockup when RCU reader used while IRQ exiting Joel Fernandes
2025-06-09 19:49   ` Boqun Feng
2025-06-09 23:26     ` Frederic Weisbecker
2025-06-10  0:49       ` Boqun Feng
2025-06-10 12:23   ` Frederic Weisbecker
2025-06-10 15:47     ` Joel Fernandes
2025-06-12  3:06     ` Xiongfeng Wang
2025-06-12 11:37       ` Frederic Weisbecker
2025-06-11 16:05   ` Boqun Feng
2025-06-11 16:16     ` Paul E. McKenney
2025-06-11 16:21       ` Boqun Feng
2025-06-09 18:05 ` [PATCH 1/2] context_tracking: Provide helper to determine if we're in IRQ Joel Fernandes
2025-06-11 16:25 ` Frederic Weisbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).