* [PATCH] signal: annotate siglock acquisition
@ 2010-09-25 9:21 Namhyung Kim
2010-09-25 9:42 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2010-09-25 9:21 UTC (permalink / raw)
To: Oleg Nesterov, Roland McGrath; +Cc: linux-kernel
lock_task_sighand() conditionally acquires sighand->siglock in case of
returning non-NULL but unlock_task_sighand() releases it unconditionally.
This leads sparse to complain about the lock context imbalance. Annotate it
to make sparse happier.
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
kernel/signal.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index bded651..85c1efd 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1037,7 +1037,7 @@ int do_send_sig_info(int sig, struct siginfo *info, struct task_struct *p,
unsigned long flags;
int ret = -ESRCH;
- if (lock_task_sighand(p, &flags)) {
+ if (__cond_lock(&p->sighand->siglock, lock_task_sighand(p, &flags))) {
ret = send_signal(sig, info, p, group);
unlock_task_sighand(p, &flags);
}
@@ -1226,7 +1226,8 @@ int kill_pid_info_as_uid(int sig, struct siginfo *info, struct pid *pid,
goto out_unlock;
if (sig) {
- if (lock_task_sighand(p, &flags)) {
+ if (__cond_lock(&p->sighand->siglock,
+ lock_task_sighand(p, &flags))) {
ret = __send_signal(sig, info, p, 1, 0);
unlock_task_sighand(p, &flags);
} else
@@ -1403,7 +1404,9 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
ret = -1;
- if (!likely(lock_task_sighand(t, &flags)))
+ if (likely(lock_task_sighand(t, &flags)))
+ __acquire(&t->sighand->siglock);
+ else
goto ret;
ret = 1; /* the signal is ignored */
--
1.7.2.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] signal: annotate siglock acquisition
2010-09-25 9:21 [PATCH] signal: annotate siglock acquisition Namhyung Kim
@ 2010-09-25 9:42 ` Eric Dumazet
2010-09-25 11:33 ` Namhyung Kim
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2010-09-25 9:42 UTC (permalink / raw)
To: Namhyung Kim; +Cc: Oleg Nesterov, Roland McGrath, linux-kernel
Le samedi 25 septembre 2010 à 18:21 +0900, Namhyung Kim a écrit :
> lock_task_sighand() conditionally acquires sighand->siglock in case of
> returning non-NULL but unlock_task_sighand() releases it unconditionally.
> This leads sparse to complain about the lock context imbalance. Annotate it
> to make sparse happier.
> @@ -1403,7 +1404,9 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
> BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
>
> ret = -1;
> - if (!likely(lock_task_sighand(t, &flags)))
> + if (likely(lock_task_sighand(t, &flags)))
> + __acquire(&t->sighand->siglock);
> + else
> goto ret;
>
> ret = 1; /* the signal is ignored */
making sparse happy is good, but changing a likely clause is not,
unless you meant it ;)
maybe -->
if (!likely(lock_task_sighand(t, &flags)))
goto ret;
else
__acquire(&t->sighand->siglock);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] signal: annotate siglock acquisition
2010-09-25 9:42 ` Eric Dumazet
@ 2010-09-25 11:33 ` Namhyung Kim
2010-09-25 12:23 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2010-09-25 11:33 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Oleg Nesterov, Roland McGrath, linux-kernel
On Sat, Sep 25, 2010 at 18:42, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Le samedi 25 septembre 2010 à 18:21 +0900, Namhyung Kim a écrit :
>> @@ -1403,7 +1404,9 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
>> BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
>>
>> ret = -1;
>> - if (!likely(lock_task_sighand(t, &flags)))
>> + if (likely(lock_task_sighand(t, &flags)))
>> + __acquire(&t->sighand->siglock);
>> + else
>> goto ret;
>>
>> ret = 1; /* the signal is ignored */
>
> making sparse happy is good, but changing a likely clause is not,
> unless you meant it ;)
>
> maybe -->
>
> if (!likely(lock_task_sighand(t, &flags)))
> goto ret;
> else
> __acquire(&t->sighand->siglock);
>
>
>
>
What's the difference? I didn't change the semantics of likely clause
but simply exchange the order of then-else part because IMHO a
negative expression make it hard to understand, generally.
I've checked compiled binaries for both cases on x86 and they
produced exactly same code.
Thanks.
--
Regards,
Namhyung Kim
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] signal: annotate siglock acquisition
2010-09-25 11:33 ` Namhyung Kim
@ 2010-09-25 12:23 ` Eric Dumazet
2010-09-25 12:51 ` Namhyung Kim
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2010-09-25 12:23 UTC (permalink / raw)
To: Namhyung Kim; +Cc: Oleg Nesterov, Roland McGrath, linux-kernel
Le samedi 25 septembre 2010 à 20:33 +0900, Namhyung Kim a écrit :
> What's the difference? I didn't change the semantics of likely clause
> but simply exchange the order of then-else part because IMHO a
> negative expression make it hard to understand, generally.
> I've checked compiled binaries for both cases on x86 and they
> produced exactly same code.
>
Anyway, re-reading your patch, I just dont get why you use __cond_lock()
two times, but not on this part ?
if (!likely(__cond_lock(&t->sighand->siglock,
lock_task_sighand(t, &flags))))
goto ret;
This way, your patch would not be misleading.
Another way to deal with this sparse mess is to use a macro, like we do
for read_trylock() :
#define read_trylock(lock) __cond_lock(lock, _raw_read_trylock(lock))
-->
#define lock_task_sighand(t, flags) \
__cond_lock(&(t)->sighand->siglock, \
_raw_lock_task_sighand(t, flags))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] signal: annotate siglock acquisition
2010-09-25 12:23 ` Eric Dumazet
@ 2010-09-25 12:51 ` Namhyung Kim
0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2010-09-25 12:51 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Oleg Nesterov, Roland McGrath, linux-kernel
On Sat, Sep 25, 2010 at 21:23, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> #define lock_task_sighand(t, flags) \
> __cond_lock(&(t)->sighand->siglock, \
> _raw_lock_task_sighand(t, flags))
>
Looks great! Will use it in a new patch.
Many thanks.
--
Regards,
Namhyung Kim
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-09-25 12:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-25 9:21 [PATCH] signal: annotate siglock acquisition Namhyung Kim
2010-09-25 9:42 ` Eric Dumazet
2010-09-25 11:33 ` Namhyung Kim
2010-09-25 12:23 ` Eric Dumazet
2010-09-25 12:51 ` Namhyung Kim
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®