From: Joel Fernandes <joel@joelfernandes.org>
To: Huacai Chen <chenhuacai@loongson.cn>
Cc: "Paul E . McKenney" <paulmck@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <quic_neeraju@quicinc.com>,
Josh Triplett <josh@joshtriplett.org>,
Boqun Feng <boqun.feng@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Zqiang <qiang.zhang1211@gmail.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
chenhuacai@kernel.org, rcu@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Binbin Zhou <zhoubinbin@loongson.cn>
Subject: Re: [PATCH V3] rcu: Update jiffies locally in rcu_cpu_stall_reset()
Date: Tue, 22 Aug 2023 15:34:16 +0000 [thread overview]
Message-ID: <20230822153416.GA72567@google.com> (raw)
In-Reply-To: <20230822040248.329442-1-chenhuacai@loongson.cn>
On Tue, Aug 22, 2023 at 12:02:48PM +0800, Huacai Chen wrote:
> The KGDB initial breakpoint gets an rcu stall warning after commit
> a80be428fbc1f1f3bc9ed924 ("rcu: Do not disable GP stall detection in
> rcu_cpu_stall_reset()").
>
> [ 53.452051] rcu: INFO: rcu_preempt self-detected stall on CPU
[...]
>
> [1] https://lore.kernel.org/rcu/20230814020045.51950-1-chenhuacai@loongson.cn/T/#t
>
> Cc: stable@vger.kernel.org
> Fixes: a80be428fbc1f1f3bc9ed924 ("rcu: Do not disable GP stall detection in rcu_cpu_stall_reset()")
> Reported-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> V2: Use NMI safe functions.
> V3: Add comments to explain why.
>
> kernel/rcu/tree_stall.h | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
> index b10b8349bb2a..e4e53113d062 100644
> --- a/kernel/rcu/tree_stall.h
> +++ b/kernel/rcu/tree_stall.h
> @@ -150,11 +150,26 @@ static void panic_on_rcu_stall(void)
> * rcu_cpu_stall_reset - restart stall-warning timeout for current grace period
> *
> * The caller must disable hard irqs.
> + *
> + * The jiffies updating may be delayed for a very long time due to tickless and
> + * irq disabled, especially in the KGDB case, so we need to add the delayed time
> + * (delta) to rcu_state.jiffies_stall.
> + *
> + * This function may be called in NMI context, so we cannot use ktime_get_ns()
> + * and ktime_get_coarse_ns(). Instead, we use their inaccurate but safe friends
> + * ktime_get_mono_fast_ns() and ktime_get_seconds() which will cause rcu_state.
> + * jiffies_stall to be a little large than expected (harmless and safer).
> */
> void rcu_cpu_stall_reset(void)
> {
> + u64 curr, last, delta;
> +
> + curr = ktime_get_mono_fast_ns();
> + last = ktime_get_seconds() * NSEC_PER_SEC;
> + delta = nsecs_to_jiffies(curr - last);
> +
> WRITE_ONCE(rcu_state.jiffies_stall,
> - jiffies + rcu_jiffies_till_stall_check());
> + jiffies + delta + rcu_jiffies_till_stall_check());
> }
I prefer the following diff on top of your patch to take advantage of UBSAN
detecting overflows.
If you take my diff, feel free to add:
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---8<-----------------------
diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
index 5e9e4779bdf1..3398cf2d19c5 100644
--- a/kernel/rcu/tree_stall.h
+++ b/kernel/rcu/tree_stall.h
@@ -162,14 +162,15 @@ static void panic_on_rcu_stall(void)
*/
void rcu_cpu_stall_reset(void)
{
- u64 curr, last, delta;
+ ktime_t last, delta_ns;
+ u64 delta_jiff;
- curr = ktime_get_mono_fast_ns();
last = ktime_get_seconds() * NSEC_PER_SEC;
- delta = nsecs_to_jiffies(curr - last);
+ delta_ns = ktime_sub(ktime_get_mono_fast_ns(), last);
+ delta_jiff = nsecs_to_jiffies(delta_ns);
WRITE_ONCE(rcu_state.jiffies_stall,
- jiffies + delta + rcu_jiffies_till_stall_check());
+ jiffies + delta_jiff + rcu_jiffies_till_stall_check());
}
//////////////////////////////////////////////////////////////////////////////
next prev parent reply other threads:[~2023-08-22 15:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-22 4:02 [PATCH V3] rcu: Update jiffies locally in rcu_cpu_stall_reset() Huacai Chen
2023-08-22 15:34 ` Joel Fernandes [this message]
2023-08-22 15:48 ` Huacai Chen
2023-08-22 15:57 ` Joel Fernandes
2023-08-22 16:05 ` Huacai Chen
2023-08-24 9:37 ` Thomas Gleixner
2023-08-24 12:52 ` Huacai Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230822153416.GA72567@google.com \
--to=joel@joelfernandes.org \
--cc=boqun.feng@gmail.com \
--cc=chenhuacai@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=paulmck@kernel.org \
--cc=qiang.zhang1211@gmail.com \
--cc=quic_neeraju@quicinc.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=zhoubinbin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.