linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	linux-sparse@vger.kernel.org
Subject: Re: [PATCH net-next] net: add annotation for sock_{lock,unlock}_fast
Date: Tue, 17 Nov 2020 18:36:18 +0100	[thread overview]
Message-ID: <ad72a4d612d95e0d5c0b6923926e43239c506171.camel@redhat.com> (raw)
In-Reply-To: <20201117165830.e44pu3nd5vx3jzmz@ltop.local>

Hello,

On Tue, 2020-11-17 at 17:58 +0100, Luc Van Oostenryck wrote:
> On Tue, Nov 17, 2020 at 09:38:45AM +0100, Paolo Abeni wrote:
> > Hello,
> > 
> > Thank you for the feedback!
> > 
> > On Mon, 2020-11-16 at 23:27 +0100, Luc Van Oostenryck wrote:
> > > > @@ -1606,10 +1607,12 @@ bool lock_sock_fast(struct sock *sk);
> > > >   */
> > > >  static inline void unlock_sock_fast(struct sock *sk, bool slow)
> > > >  {
> > > > -	if (slow)
> > > > +	if (slow) {
> > > >  		release_sock(sk);
> > > > -	else
> > > > +		__release(&sk->sk_lock.slock);
> > > 
> > > The correct solution would be to annotate the declaration of
> > > release_sock() with '__releases(&sk->sk_lock.slock)'.
> > 
> > If I add such annotation to release_sock(), I'll get several sparse
> > warnings for context imbalance (on each lock_sock()/release_sock()
> > pair), unless I also add an '__acquires()' annotation to lock_sock(). 
> > 
> > The above does not look correct to me ?!? When release_sock() completes
> > the socket spin lock is not held.
> 
> Yes, that's fine, but I suppose it somehow releases the mutex that
> is taken in lock_sock_fast() when returning true, right?

Well, it has mutex semantics, but does not really acquire any mutex.

> > The annotation added above is
> > somewhat an artifact to let unlock_sock_fast() matches lock_sock_fast()
> > from sparse perspective. I intentionally avoided changing
> > the release_sock() annotation to avoid introducing more artifacts.
> > 
> > The proposed schema is not 100% accurate, as it will also allow e.g. a
> > really-not-fitting bh_lock_sock()/unlock_sock_fast() pair, but I could
> > not come-up with anything better.
> > 
> > Can we go with the schema I proposed?
> 
> Well, I suppose it's a first step.
> But can you then add a '__releases(...)' to unlock_sock_fast()?
> It's not needed by sparse because it's an inline function and sparse
> can then deduce it but it will help to see the pairing with
> lock_sock_fast() is OK.

Ok, I'll send a v2 with such annotation.

Thanks!

Paolo


      reply	other threads:[~2020-11-17 17:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16 10:36 [PATCH net-next] net: add annotation for sock_{lock,unlock}_fast Paolo Abeni
2020-11-16 22:27 ` Luc Van Oostenryck
2020-11-17  8:38   ` Paolo Abeni
2020-11-17 16:58     ` Luc Van Oostenryck
2020-11-17 17:36       ` Paolo Abeni [this message]

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=ad72a4d612d95e0d5c0b6923926e43239c506171.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=netdev@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;
as well as URLs for NNTP newsgroup(s).