mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: "Zhang, Qiang1" <qiang1.zhang@intel.com>
Cc: "Zhuo, Qiuxu" <qiuxu.zhuo@intel.com>,
	"paulmck@kernel.org" <paulmck@kernel.org>,
	"frederic@kernel.org" <frederic@kernel.org>,
	"quic_neeraju@quicinc.com" <quic_neeraju@quicinc.com>,
	"rcu@vger.kernel.org" <rcu@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rcu-tasks: Directly invoke rcuwait_wake_up() in call_rcu_tasks_generic()
Date: Thu, 23 Feb 2023 21:35:13 -0500	[thread overview]
Message-ID: <CAEXW_YRTOYu5ZR6aX7AaTGyCQJwjB2aEmuPMYExYD4A2csRP1w@mail.gmail.com> (raw)
In-Reply-To: <Y/ggCdoMEhMO8vs+@google.com>

On Thu, Feb 23, 2023 at 9:25 PM Joel Fernandes <joel@joelfernandes.org> wrote:
>
> On Fri, Feb 24, 2023 at 12:36:05AM +0000, Zhang, Qiang1 wrote:
> > On Thu, Feb 23, 2023 at 08:43:05AM +0000, Zhang, Qiang1 wrote:
> > > > From: Zqiang <qiang1.zhang@intel.com>
> > > > Sent: Thursday, February 23, 2023 2:30 PM
> > > > To: paulmck@kernel.org; frederic@kernel.org; quic_neeraju@quicinc.com;
> > > > joel@joelfernandes.org
> > > > Cc: rcu@vger.kernel.org; linux-kernel@vger.kernel.org
> > > > Subject: [PATCH] rcu-tasks: Directly invoke rcuwait_wake_up() in
> > > > call_rcu_tasks_generic()
> > > >
> > > > According to commit '3063b33a347c ("Avoid raw-spinlocked wakeups from
> > > > call_rcu_tasks_generic()")', the grace-period kthread is delayed to wakeup
> > > > using irq_work_queue() is because if the caller of
> > > > call_rcu_tasks_generic() holds a raw spinlock, when the kernel is built with
> > > > CONFIG_PROVE_RAW_LOCK_NESTING=y, due to a spinlock will be hold in
> > > > wake_up(), so the lockdep splats will happen. but now using
> > > > rcuwait_wake_up() to wakeup grace-period kthread instead of wake_up(), in
> > > > rcuwait_wake_up() no spinlock will be acquired, so this commit remove using
> > > >
> > > >There are still spinlock-acquisition and spinlock-release invocations within the call path from rcuwait_wake_up().
> > > >
> > > >rcuwait_wake_up() -> wake_up_process() -> try_to_wake_up(), then:
> > > >
> > > >    raw_spin_lock_irqsave()
> > > >    ...
> > > >    raw_spin_unlock_irqrestore
> > >
> > > Yes, but this is raw_spinlock acquisition and release(note: spinlock will convert to
> > > sleepable lock in Preempt-RT kernel, but raw spinlock is not change).
> > >
> > > acquire raw_spinlock -> acquire spinlock  will trigger lockdep warning.
> > >
> > >Is this really safe in the long run though? I seem to remember there are
> > >weird locking dependencies if RCU is used from within the scheduler [1].
> > >
> >
> >
> > I have  been running rcutorture with rcutorture.type = tasks-tracing,
> > so far no problems have been found.
> >
> >
> > >I prefer to keep it as irq_work_queue() unless you are seeing some benefit.
> > >Generally, there has to be a 'win' or other justification for adding more
> > >risk.
> > >
> > >thanks,
> > >
> > >- Joel
> > >[1] http://www.joelfernandes.org/rcu/scheduler/locking/2019/09/02/rcu-schedlocks.html
> >
> >
> > The problem in this link,  in an earlier RCU version, rcu_read_unlock_special()
> > Invoke wakeup and enter scheduler can lead to deadlock, but my modification is for
> > call_rcu_tasks_generic(), even if there is a lock dependency problem, we should pay
> > more attention to rcu_read_unlock_trace_special()
>
> Consider ABBA deadlocks as well, not just self-deadlocks (which IIRC is what
> the straight-RCU rcu_read_unlock() issues were about).
>
> What prevents the following scenario?
>
> In the scheduler you have code like this:
>                 rq = task_rq_lock(p, &rf);
>                 trace_sched_wait_task(p);
>
> Someone can hook up a BPF program to that tracepoint that then calls
> rcu_read_unlock_trace() -> rcu_read_unlock_trace_special(). All of
> this while holding the rq and pi scheduler locks.
>
> That's A (rq lock) -> B (rtpcp lock).
>
> In another path, your change adds the following dependency due to doing
> wakeup under the rtpcp lock.
>
> That's call_rcu_tasks_generic() -> B (rtpcp lock) -> A (rq lock).

I would like to correct this last statement. That cannot happen but
the concern I guess is, can the following happen due to the change?

call_rcu_tasks_generic() -> B (some BPF lock) -> A (rq lock)

So by doing a wakeup in this change, you have added the dependency for
callers of call_rcu_tasks_trace() . Now, the BPF program is called
from the trace point above and you have ABBA deadlock possibility.

 - Joel

  reply	other threads:[~2023-02-24  2:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23  6:30 Zqiang
2023-02-23  8:36 ` Zhuo, Qiuxu
2023-02-23  8:43   ` Zhang, Qiang1
2023-02-23 14:36     ` Zhuo, Qiuxu
2023-02-23 16:10     ` Joel Fernandes
2023-02-23 16:57       ` Joel Fernandes
2023-02-23 17:13         ` Paul E. McKenney
2023-02-24  0:36       ` Zhang, Qiang1
2023-02-24  2:25         ` Joel Fernandes
2023-02-24  2:35           ` Joel Fernandes [this message]
2023-02-24  2:36             ` Joel Fernandes
2023-02-24  3:04               ` Zhang, Qiang1
2023-02-24  3:11                 ` Joel Fernandes
2023-02-24  3:22                   ` Zhang, Qiang1
2023-02-24  4:30                     ` Joel Fernandes

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=CAEXW_YRTOYu5ZR6aX7AaTGyCQJwjB2aEmuPMYExYD4A2csRP1w@mail.gmail.com \
    --to=joel@joelfernandes.org \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=qiang1.zhang@intel.com \
    --cc=qiuxu.zhuo@intel.com \
    --cc=quic_neeraju@quicinc.com \
    --cc=rcu@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®