* sparse context tags
@ 2007-03-12 22:37 Russ Cox
2007-03-13 0:32 ` Christopher Li
0 siblings, 1 reply; 3+ messages in thread
From: Russ Cox @ 2007-03-12 22:37 UTC (permalink / raw)
To: linux-sparse
Is the optional leading context argument
(the x in __attribute__((context(x, 0, 1)))
documented anywhere? Apologies if this is
a FAQ, but I've looked.
Failing that, can someone enlighten me about
why sparse doesn't find any problems with
the function bad() below? I am using sparse-0.2.
Thanks.
Russ
---
#define __acquires(x) __attribute__((context(x, 0, 1)))
#define __releases(x) __attribute__((context(x, 1, 0)))
typedef struct redlock redlock_t;
typedef struct bluelock bluelock_t;
void redlock(redlock_t *r) __acquires(r);
void redunlock(redlock_t *r) __releases(r);
void bluelock(bluelock_t *b) __acquires(b);
void blueunlock(bluelock_t *b) __releases(b);
void
bad(redlock_t *r, bluelock_t *b)
{
redlock(r);
blueunlock(b);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: sparse context tags
2007-03-12 22:37 sparse context tags Russ Cox
@ 2007-03-13 0:32 ` Christopher Li
2007-03-13 1:31 ` Pavel Roskin
0 siblings, 1 reply; 3+ messages in thread
From: Christopher Li @ 2007-03-13 0:32 UTC (permalink / raw)
To: Russ Cox; +Cc: linux-sparse
On Mon, Mar 12, 2007 at 06:37:34PM -0400, Russ Cox wrote:
> Is the optional leading context argument
> (the x in __attribute__((context(x, 0, 1)))
> documented anywhere? Apologies if this is
> a FAQ, but I've looked.
I don't know about the document. The x is mostly
for human reading currently. Sparse does not use
it yet.
>
> Failing that, can someone enlighten me about
> why sparse doesn't find any problems with
> the function bad() below? I am using sparse-0.2.
That is because sparse can't distinguish which lock is
acquired. It is actually hard to get that information.
Even though the expression is the same, the actual lock
might be different.
e.g.
redlock(foo->redlock);
foo = bar;
redunlock (foo->redlock);
Depend on the value of foo, even the same expression can
mean different locks.
So sparse currently just stack all the lock level into one place,
it will complain about any lock level that is has mismatch.
> void
> bad(redlock_t *r, bluelock_t *b)
> {
> redlock(r);
> blueunlock(b);
> }
Sparse sees:
Some lock acquired and some lock release exactly once in the function.
Nothing to complain.
How ever, if you do:
#define __acquires_red(x) __attribute__((context(x, 0, 1)))
#define __releases_red(x) __attribute__((context(x, 1, 0)))
#define __acquires_blue(x) __attribute__((context(x, 0, 1024)))
#define __releases_blue(x) __attribute__((context(x, 1024, 0)))
Assume your redlock level did not go up to 1024, then:
void redlock(redlock_t *r) __acquires_red(r);
void bluelock(redlock_t *r) __acquires_blue(r);
void blueunlock(redlock_t *r) __releases_blue(r);
You will get the complain about lock level not match at exit.
Chris
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: sparse context tags
2007-03-13 0:32 ` Christopher Li
@ 2007-03-13 1:31 ` Pavel Roskin
0 siblings, 0 replies; 3+ messages in thread
From: Pavel Roskin @ 2007-03-13 1:31 UTC (permalink / raw)
To: Christopher Li; +Cc: Russ Cox, linux-sparse
On Mon, 2007-03-12 at 17:32 -0700, Christopher Li wrote:
> That is because sparse can't distinguish which lock is
> acquired. It is actually hard to get that information.
> Even though the expression is the same, the actual lock
> might be different.
>
> e.g.
>
> redlock(foo->redlock);
> foo = bar;
> redunlock (foo->redlock);
Just an idea. The Linux "runtime locking correctness validator" (see
Documentation/lockdep-design.txt in the Linux sources) distinguishes
between lock classes.
Sparse could use a similar approach. I think it would not catch your
example, but it would catch a more realistic case when one lock is
acquired and another is released even by the same function with the same
attributes:
lock(foo->redlock);
lock(foo->bluelock);
unlock(foo->redlock);
unlock(foo->bluelock);
Lock class could be just a unique reference to a place where the lock
was declared. That would put some limitations on what a lock could be
(an address of a variable or a field), but I think it's OK.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-03-13 1:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-12 22:37 sparse context tags Russ Cox
2007-03-13 0:32 ` Christopher Li
2007-03-13 1:31 ` Pavel Roskin
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).