All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cheng-Jui Wang (王正睿)" <Cheng-Jui.Wang@mediatek.com>
To: "paulmck@kernel.org" <paulmck@kernel.org>
Cc: "sumit.garg@linaro.org" <sumit.garg@linaro.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"dianders@chromium.org" <dianders@chromium.org>,
	"rostedt@goodmis.org" <rostedt@goodmis.org>,
	"frederic@kernel.org" <frederic@kernel.org>,
	wsd_upstream <wsd_upstream@mediatek.com>,
	"Bobule Chang (張弘義)" <bobule.chang@mediatek.com>,
	"mark.rutland@arm.com" <mark.rutland@arm.com>,
	"kernel-team@meta.com" <kernel-team@meta.com>,
	"joel@joelfernandes.org" <joel@joelfernandes.org>,
	"rcu@vger.kernel.org" <rcu@vger.kernel.org>
Subject: Re: [PATCH v3 rcu 3/3] rcu: Finer-grained grace-period-end checks in rcu_dump_cpu_stacks()
Date: Fri, 1 Nov 2024 07:41:27 +0000	[thread overview]
Message-ID: <00ace254f9085aad12684185b77504bd911aed63.camel@mediatek.com> (raw)
In-Reply-To: <9e90d04e-081b-4730-890b-295ed52747de@paulmck-laptop>

On Wed, 2024-10-30 at 06:54 -0700, Paul E. McKenney wrote:
> > > Alternatively, arm64 could continue using nmi_trigger_cpumask_backtrace()
> > > with normal interrupts (for example, on SoCs not implementing true NMIs),
> > > but have a short timeout (maybe a few jiffies?) after which its returns
> > > false (and presumably also cancels the backtrace request so that when
> > > the non-NMI interrupt eventually does happen, its handler simply returns
> > > without backtracing).  This should be implemented using atomics to avoid
> > > deadlock issues.  This alternative approach would provide accurate arm64
> > > backtraces in the common case where interrupts are enabled, but allow
> > > a graceful fallback to remote tracing otherwise.
> > > 
> > > Would you be interested in working this issue, whatever solution the
> > > arm64 maintainers end up preferring?
> > 
> > The 10-second timeout is hard-coded in nmi_trigger_cpumask_backtrace().
> > It is shared code and not architecture-specific. Currently, I haven't
> > thought of a feasible solution. I have also CC'd the authors of the
> > aforementioned patch to see if they have any other ideas.
> 
> It should be possible for arm64 to have an architecture-specific hook
> that enables them to use a much shorter timeout.  Or, to eventually
> switch to real NMIs.

There is already another thread discussing the timeout issue, but I
still have some questions about RCU. To avoid mixing the discussions, I
start this separate thread to discuss RCU.

> > Regarding the rcu stall warning, I think the purpose of acquiring `rnp-
> > > lock` is to protect the rnp->qsmask variable rather than to protect
> > 
> > the `dump_cpu_task()` operation, right?
> 
> As noted below, it is also to prevent false-positive stack dumps.
> 
> > Therefore, there is no need to call dump_cpu_task() while holding the
> > lock.
> > When holding the spinlock, we can store the CPUs that need to be dumped
> > into a cpumask, and then dump them all at once after releasing the
> > lock.
> > Here is my temporary solution used locally based on kernel-6.11.
> > 
> > +     cpumask_var_t mask;
> > +     bool mask_ok;
> > 
> > +     mask_ok = zalloc_cpumask_var(&mask, GFP_ATOMIC);
> >       rcu_for_each_leaf_node(rnp) {
> >               raw_spin_lock_irqsave_rcu_node(rnp, flags);
> >               for_each_leaf_node_possible_cpu(rnp, cpu)
> >                       if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu))
> > {
> >                               if (cpu_is_offline(cpu))
> >                                       pr_err("Offline CPU %d blocking
> > current GP.\n", cpu);
> > +                             else if (mask_ok)
> > +                                     cpumask_set_cpu(cpu, mask);
> >                               else
> >                                       dump_cpu_task(cpu);
> >                       }
> >               raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
> >       }
> > +     if (mask_ok) {
> > +             if (!trigger_cpumask_backtrace(mask)) {
> > +                     for_each_cpu(cpu, mask)
> > +                             dump_cpu_task(cpu);
> > +             }
> > +             free_cpumask_var(mask);
> > +     }
> > 
> > After applying this, I haven't encountered the lockup issue for five
> > days, whereas it used to occur about once a day.
> 
> We used to do it this way, and the reason that we changed was to avoid
> false-positive (and very confusing) stack dumps in the surprisingly
> common case where the act of dumping the first stack caused the stalled
> grace period to end.
> 
> So sorry, but we really cannot go back to doing it that way.
> 
>                                                         Thanx, Paul

Let me clarify, the reason for the issue mentioned above is that it
pre-determines all the CPUs to be dumped before starting the dump
process. Then, dumping the first stack caused the stalled grace period
to end. Subsequently, many CPUs that do not need to be dumped (false
positives) are dumped.

So,to prevent false positives, it should be about excluding those CPUs
that do not to be dumped, right? Therefore, the action that trully help
is actually "releasing the lock after each dump (allowing other CPUs to
update qsmask) and rechecking (gp_seq and qsmask) to confirm whether to
continue dumping".

I think holding the lock while dumping CPUs does not help prevent false
positives; it only blocks those CPUs waiting for the lock (e.g., CPUs
aboult to report qs). For CPUs that do not interact with this lock,
holding it should not have any impact. Did I miss anything?

-Cheng-Jui

  parent reply	other threads:[~2024-11-01  7:41 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09 18:05 [PATCH rcu 0/3] RCU CPU stall-warning changes for v6.13 Paul E. McKenney
2024-10-09 18:05 ` [PATCH rcu 1/3] rcu: Delete unused rcu_gp_might_be_stalled() function Paul E. McKenney
2024-10-09 18:05 ` [PATCH rcu 2/3] rcu: Stop stall warning from dumping stacks if grace period ends Paul E. McKenney
2024-10-15 18:48   ` Joel Fernandes
2024-10-09 18:05 ` [PATCH rcu 3/3] rcu: Finer-grained grace-period-end checks in rcu_dump_cpu_stacks() Paul E. McKenney
2024-10-15 18:49 ` [PATCH rcu 0/3] RCU CPU stall-warning changes for v6.13 Joel Fernandes
2024-10-15 23:02   ` Paul E. McKenney
2024-10-16  0:01     ` Joel Fernandes
2024-10-16 16:18 ` [PATCH v2 " Paul E. McKenney
2024-10-16 16:19   ` [PATCH v2 rcu 1/3] rcu: Delete unused rcu_gp_might_be_stalled() function Paul E. McKenney
2024-10-16 16:19   ` [PATCH v2 rcu 2/3] rcu: Stop stall warning from dumping stacks if grace period ends Paul E. McKenney
2024-10-16 16:19   ` [PATCH v2 rcu 3/3] rcu: Finer-grained grace-period-end checks in rcu_dump_cpu_stacks() Paul E. McKenney
2024-10-29  0:22     ` [PATCH v3 " Paul E. McKenney
2024-10-29  2:20       ` Cheng-Jui Wang (王正睿)
2024-10-29 16:29         ` Paul E. McKenney
2024-10-30  3:55           ` Cheng-Jui Wang (王正睿)
2024-10-30 13:54             ` Paul E. McKenney
2024-10-30 20:12               ` Doug Anderson
2024-10-30 23:26                 ` Paul E. McKenney
2024-10-31  0:21                   ` Doug Anderson
2024-10-31  5:03                     ` Paul E. McKenney
2024-10-31 21:27                       ` Doug Anderson
2024-11-01  1:44                         ` Cheng-Jui Wang (王正睿)
2024-11-01 13:55                           ` Paul E. McKenney
2025-10-30  8:30                             ` Tze-nan Wu (吳澤南)
2024-11-01  7:41               ` Cheng-Jui Wang (王正睿) [this message]
2024-11-01 13:59                 ` Paul E. McKenney
2024-10-18 21:49   ` [PATCH v2 rcu 0/3] RCU CPU stall-warning changes for v6.13 Frederic Weisbecker

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=00ace254f9085aad12684185b77504bd911aed63.camel@mediatek.com \
    --to=cheng-jui.wang@mediatek.com \
    --cc=bobule.chang@mediatek.com \
    --cc=dianders@chromium.org \
    --cc=frederic@kernel.org \
    --cc=joel@joelfernandes.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sumit.garg@linaro.org \
    --cc=wsd_upstream@mediatek.com \
    /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.