[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aEmt4Aa3-gULNtic@localhost.localdomain>
Date: Wed, 11 Jun 2025 18:25:04 +0200
From: Frederic Weisbecker <frederic@...nel.org>
To: Joel Fernandes <joelagnelf@...dia.com>
Cc: linux-kernel@...r.kernel.org, "Paul E. McKenney" <paulmck@...nel.org>,
Xiongfeng Wang <wangxiongfeng2@...wei.com>, rcu@...r.kernel.org,
bpf@...r.kernel.org
Subject: Re: [PATCH 1/2] context_tracking: Provide helper to determine if
we're in IRQ
Le Mon, Jun 09, 2025 at 02:01:23PM -0400, Joel Fernandes a écrit :
> 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@...dia.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;
If rcu_is_watching() and not in an interrupt, ct_nmi_nesting()
is actually CT_NESTING_IRQ_NONIDLE. If rcu_is_watching() and
in an interrupt, ct_nmi_nesting() can be CT_NESTING_IRQ_NONIDLE + whatever.
So this doesn't work. I wish we could remove that CT_NESTING_IRQ_NONIDLE
that is there for hysterical raisins but that doesn't fit in an urgent pile.
So probably:
bool ct_in_irq(void)
{
long nesting = ct_nmi_nesting();
return (nesting && nesting != CT_NESTING_IRQ_NONIDLE);
}
Thanks.
--
Frederic Weisbecker
SUSE Labs
Powered by blists - more mailing lists