linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Christopher Li <sparse@chrisli.org>,
	Josh Triplett <josh@freedesktop.org>,
	linux-sparse@vger.kernel.org,
	Anton Vorontsov <anton.vorontsov@linaro.org>
Subject: Re: Killing off __cond_lock()
Date: Mon, 26 Mar 2012 11:00:37 +0200	[thread overview]
Message-ID: <1332752437.7081.5.camel@jlt3.sipsolutions.net> (raw)
In-Reply-To: <1332749494.16159.74.camel@twins>

On Mon, 2012-03-26 at 10:11 +0200, Peter Zijlstra wrote:

> > However, note that today sparse doesn't evaluate anything in the
> > context, it doesn't even look at the first argument. So another thing
> > you can't really annotate well is things like this:
> > 
> > struct foo_object *get_locked_object(...);
> > 
> > This is why I used RETURN to give the return value a name, so you could
> > write
> > 	__acquires(&RETURN->lock)
> 
> 
> Right, but if it doesn't actually evaluate the expression used in the
> context this is going to be problematic.

It probably could -- but the question is what context to evaluate it in.

> > But I was also trying to make sparse actually evaluate the first
> > argument so it could tell the difference between two locks, which you
> > might not even care about ... (it would be nice though I think)
> 
> Right, so what I thought we could maybe do is inject code in the
> callsites of these functions.
> 
> So after the OP_CALL emit a piece of code that works like the
> __context__ stmt and can reference the return value that exists at that
> point.
> 
> This also makes the conditional thing quite simple to do.

Indeed, but you'd need some sort of expression rewriting. Consider

void lock_obj(obj_t *o) __acquires(&o->lock);

void lock_obj(obj_t *obj)
{
	__acquire(&obj->lock);

	...
}


void foo(void)
{
	...
	lock_obj(&f);
	...
	unlock_obj(&f);
	...
}


Now you suddenly need to replace "&o->lock" with "&(&f)->lock", when
checking the function itself it really is called "obj", not "o". Not
that sparse actually checks that the function behaviour matches the
declaration today though.

johannes


PS: Something else I had wanted to remind you of: the cond_lock thing
only works due to some sort of optimiser pass (is there such a thing?)
in sparse, sometimes it fails mysteriously because the condition isn't
the exact same condition or something.



  reply	other threads:[~2012-03-26  9:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-24 16:23 Killing off __cond_lock() Peter Zijlstra
2012-03-25  8:48 ` Johannes Berg
2012-03-26  8:11   ` Peter Zijlstra
2012-03-26  9:00     ` Johannes Berg [this message]
2012-03-26  9:29     ` Josh Triplett

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=1332752437.7081.5.camel@jlt3.sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=anton.vorontsov@linaro.org \
    --cc=josh@freedesktop.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=sparse@chrisli.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).