All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Sean Christopherson <seanjc@google.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [Question] srcu: is it making sense to recursively invoke srcu_read_lock?
Date: Fri, 22 Apr 2022 08:52:12 +0800	[thread overview]
Message-ID: <20220422005212.2569-1-hdanton@sina.com> (raw)
In-Reply-To: <20220421133414.GP4285@paulmck-ThinkPad-P17-Gen-1>

On Thu, 21 Apr 2022 06:34:14 -0700 Paul E. McKenney wrote:
> On Thu, Apr 21, 2022 at 12:22:11PM +0800, Hillf Danton wrote:
> > Given rcu_lock_acquire() in srcu_read_lock(),
> > 
> > 	iA = srcu_read_lock(foo);
> > 	iB = srcu_read_lock(foo); // not bar
> > 	...
> > 	srcu_read_unlock(foo, iB);
> > 	srcu_read_unlock(foo, iA);
> > 
> > can the call sequence above trigger warning with CONFIG_DEBUG_LOCK_ALLOC enabled?
> 
> I hope not!  After all, nesting SRCU read-side critical sections is
> perfectly legal.  But why not just try it and see?

Thanks for shedding light on nested SRCUs - it cures my pain working out
the reason for how detecting nested SRCUs is added [1]. Now I see why it
is out of kernel/rcu.

Hillf

[1] https://lore.kernel.org/lkml/20220415004343.2203171-4-seanjc@google.com/

> > Does it make sense to add srcu_lock_acquire() in line with rwsem_acquire_read() if
> > warning is expected but not triggered?
> 
> Please understand that while SRCU can often be used where an rwsem
> might otherwise be used, SRCU is not an rwsem.  For one thing, rwsem
> readers can deadlock in ways that SRCU reader cannot.
> 
> Now, I don't yet know of a non-destructive use case for partially
> overlapping SRCU read-side critical sections, for example, if you
> switched the two srcu_read_unlock() calls above.  But at the same
> time, I cannot prove that there is no valid use case, not yet,
> anyway.
> 
> 						Thanx, Paul
> 
> > Thanks
> > Hillf
> > 
> > static inline void rcu_lock_acquire(struct lockdep_map *map)
> > {
> > 	lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_);
> > }
> > 
> > static inline void srcu_lock_acquire(struct lockdep_map *map)
> > {
> > 	lock_acquire(map, 0, 0, 1, 0, NULL, _THIS_IP_);
> > }
> 


  parent reply	other threads:[~2022-04-22  0:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21  4:22 [Question] srcu: is it making sense to recursively invoke srcu_read_lock? Hillf Danton
2022-04-21 13:34 ` Paul E. McKenney
2022-04-21 23:08   ` Paul E. McKenney
2022-04-22  0:52   ` Hillf Danton [this message]
2022-04-22  3:09     ` Paul E. McKenney

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=20220422005212.2569-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=paulmck@kernel.org \
    --cc=seanjc@google.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.