netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3] Lost locking in fl6_sock_lookup
@ 2007-10-18 11:53 Pavel Emelyanov
  2007-10-18 12:00 ` YOSHIFUJI Hideaki / 吉藤英明
  2007-10-18 12:16 ` David Miller
  0 siblings, 2 replies; 7+ messages in thread
From: Pavel Emelyanov @ 2007-10-18 11:53 UTC (permalink / raw)
  To: David Miller; +Cc: Linux Netdev List, devel

This routine scans the ipv6_fl_list whose update is
protected with the socket lock and the ip6_sk_fl_lock.

Since the socket lock is not taken in the lookup, use
the other one.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

---

diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index 8550df2..f40a086 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -190,14 +190,17 @@ struct ip6_flowlabel * fl6_sock_lookup(struct sock *sk, __be32 label)
 
 	label &= IPV6_FLOWLABEL_MASK;
 
+	read_lock_bh(&ip6_sk_fl_lock);
 	for (sfl=np->ipv6_fl_list; sfl; sfl = sfl->next) {
 		struct ip6_flowlabel *fl = sfl->fl;
 		if (fl->label == label) {
+			read_unlock_bh(&ip6_sk_fl_lock);
 			fl->lastuse = jiffies;
 			atomic_inc(&fl->users);
 			return fl;
 		}
 	}
+	read_unlock_bh(&ip6_sk_fl_lock);
 	return NULL;
 }
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] Lost locking in fl6_sock_lookup
  2007-10-18 11:53 [PATCH 2/3] Lost locking in fl6_sock_lookup Pavel Emelyanov
@ 2007-10-18 12:00 ` YOSHIFUJI Hideaki / 吉藤英明
  2007-10-18 12:11   ` Pavel Emelyanov
  2007-10-18 12:16 ` David Miller
  1 sibling, 1 reply; 7+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2007-10-18 12:00 UTC (permalink / raw)
  To: xemul; +Cc: davem, netdev, devel, yoshfuji

In article <47174950.6060409@openvz.org> (at Thu, 18 Oct 2007 15:53:52 +0400), Pavel Emelyanov <xemul@openvz.org> says:

> This routine scans the ipv6_fl_list whose update is
> protected with the socket lock and the ip6_sk_fl_lock.

>  		struct ip6_flowlabel *fl = sfl->fl;
>  		if (fl->label == label) {
> +			read_unlock_bh(&ip6_sk_fl_lock);
>  			fl->lastuse = jiffies;
>  			atomic_inc(&fl->users);
>  			return fl;

We should increment fl->users within the critical section, shouldn't we?

--yoshfuji

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] Lost locking in fl6_sock_lookup
  2007-10-18 12:00 ` YOSHIFUJI Hideaki / 吉藤英明
@ 2007-10-18 12:11   ` Pavel Emelyanov
  2007-10-18 12:14     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Emelyanov @ 2007-10-18 12:11 UTC (permalink / raw)
  To: YOSHIFUJI Hideaki / 吉藤英明; +Cc: davem, netdev, devel

YOSHIFUJI Hideaki wrote:
> In article <47174950.6060409@openvz.org> (at Thu, 18 Oct 2007 15:53:52 +0400), Pavel Emelyanov <xemul@openvz.org> says:
> 
>> This routine scans the ipv6_fl_list whose update is
>> protected with the socket lock and the ip6_sk_fl_lock.
> 
>>  		struct ip6_flowlabel *fl = sfl->fl;
>>  		if (fl->label == label) {
>> +			read_unlock_bh(&ip6_sk_fl_lock);
>>  			fl->lastuse = jiffies;
>>  			atomic_inc(&fl->users);
>>  			return fl;
> 
> We should increment fl->users within the critical section, shouldn't we?

Not necessary. The users is more than zero (because it is 
linked in the sock's list) so garbage collector won't catch 
it in any way.

Thanks,
Pavel

> --yoshfuji
> -
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] Lost locking in fl6_sock_lookup
  2007-10-18 12:11   ` Pavel Emelyanov
@ 2007-10-18 12:14     ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2007-10-18 12:14 UTC (permalink / raw)
  To: xemul; +Cc: yoshfuji, netdev, devel

From: Pavel Emelyanov <xemul@openvz.org>
Date: Thu, 18 Oct 2007 16:11:58 +0400

> YOSHIFUJI Hideaki wrote:
> > In article <47174950.6060409@openvz.org> (at Thu, 18 Oct 2007 15:53:52 +0400), Pavel Emelyanov <xemul@openvz.org> says:
> > 
> >> This routine scans the ipv6_fl_list whose update is
> >> protected with the socket lock and the ip6_sk_fl_lock.
> > 
> >>  		struct ip6_flowlabel *fl = sfl->fl;
> >>  		if (fl->label == label) {
> >> +			read_unlock_bh(&ip6_sk_fl_lock);
> >>  			fl->lastuse = jiffies;
> >>  			atomic_inc(&fl->users);
> >>  			return fl;
> > 
> > We should increment fl->users within the critical section, shouldn't we?
> 
> Not necessary. The users is more than zero (because it is 
> linked in the sock's list) so garbage collector won't catch 
> it in any way.

Right, we're grabbing an "extra" reference here and only
someone who gets the socket lock (which we have) can unlink
it and thus potentially drop the count to zero.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] Lost locking in fl6_sock_lookup
  2007-10-18 11:53 [PATCH 2/3] Lost locking in fl6_sock_lookup Pavel Emelyanov
  2007-10-18 12:00 ` YOSHIFUJI Hideaki / 吉藤英明
@ 2007-10-18 12:16 ` David Miller
  2007-10-18 12:22   ` Pavel Emelyanov
  1 sibling, 1 reply; 7+ messages in thread
From: David Miller @ 2007-10-18 12:16 UTC (permalink / raw)
  To: xemul; +Cc: netdev, devel

From: Pavel Emelyanov <xemul@openvz.org>
Date: Thu, 18 Oct 2007 15:53:52 +0400

> This routine scans the ipv6_fl_list whose update is
> protected with the socket lock and the ip6_sk_fl_lock.
> 
> Since the socket lock is not taken in the lookup, use
> the other one.
> 
> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

Applied.

But I notice that I was wrong in my email, we don't
hold the socket lock here.

What prevents an unlink from the socket's list
and thus a reference count of zero occurring for
a brief moment?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] Lost locking in fl6_sock_lookup
  2007-10-18 12:16 ` David Miller
@ 2007-10-18 12:22   ` Pavel Emelyanov
  2007-10-18 12:33     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Emelyanov @ 2007-10-18 12:22 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, devel

David Miller wrote:
> From: Pavel Emelyanov <xemul@openvz.org>
> Date: Thu, 18 Oct 2007 15:53:52 +0400
> 
>> This routine scans the ipv6_fl_list whose update is
>> protected with the socket lock and the ip6_sk_fl_lock.
>>
>> Since the socket lock is not taken in the lookup, use
>> the other one.
>>
>> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
> 
> Applied.
> 
> But I notice that I was wrong in my email, we don't
> hold the socket lock here.
> 
> What prevents an unlink from the socket's list
> and thus a reference count of zero occurring for
> a brief moment?

Oops. You're right here :( I looked at the ip6_fl_lock
and messed it with the ip6_sk_fl_lock.

Should I resend the whole patch, or just make an 
incremental one?

Thanks,
Pavel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] Lost locking in fl6_sock_lookup
  2007-10-18 12:22   ` Pavel Emelyanov
@ 2007-10-18 12:33     ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2007-10-18 12:33 UTC (permalink / raw)
  To: xemul; +Cc: netdev, devel

From: Pavel Emelyanov <xemul@openvz.org>
Date: Thu, 18 Oct 2007 16:22:49 +0400

> Oops. You're right here :( I looked at the ip6_fl_lock
> and messed it with the ip6_sk_fl_lock.
> 
> Should I resend the whole patch, or just make an 
> incremental one?

Please make an incremental one.

And hurry, I'm trying to go to bed :-)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-10-18 12:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-18 11:53 [PATCH 2/3] Lost locking in fl6_sock_lookup Pavel Emelyanov
2007-10-18 12:00 ` YOSHIFUJI Hideaki / 吉藤英明
2007-10-18 12:11   ` Pavel Emelyanov
2007-10-18 12:14     ` David Miller
2007-10-18 12:16 ` David Miller
2007-10-18 12:22   ` Pavel Emelyanov
2007-10-18 12:33     ` David Miller

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).