netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] X25: Replace BKL in sockopts calls
@ 2010-05-09 12:45 Andrew Hendry
  2010-05-10  1:46 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Hendry @ 2010-05-09 12:45 UTC (permalink / raw)
  To: netdev


x25_setsockopt only updates the socket
x25_get only reads

Signed-off-by: Andrew Hendry <andrew.hendry@gmail.com>

---
 net/x25/af_x25.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 296e65e..9f177a1 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -453,7 +453,6 @@ static int x25_setsockopt(struct socket *sock, int level, int optname,
 	struct sock *sk = sock->sk;
 	int rc = -ENOPROTOOPT;
 
-	lock_kernel();
 	if (level != SOL_X25 || optname != X25_QBITINCL)
 		goto out;
 
@@ -465,20 +464,20 @@ static int x25_setsockopt(struct socket *sock, int level, int optname,
 	if (get_user(opt, (int __user *)optval))
 		goto out;
 
+	lock_sock(sk);
 	x25_sk(sk)->qbitincl = !!opt;
+	release_sock(sk);
 	rc = 0;
 out:
-	unlock_kernel();
 	return rc;
 }
 
 static int x25_getsockopt(struct socket *sock, int level, int optname,
 			  char __user *optval, int __user *optlen)
 {
-	struct sock *sk = sock->sk;
+	struct x25_sock *sk = x25_sk(sock->sk);
 	int val, len, rc = -ENOPROTOOPT;
 
-	lock_kernel();
 	if (level != SOL_X25 || optname != X25_QBITINCL)
 		goto out;
 
@@ -496,10 +495,9 @@ static int x25_getsockopt(struct socket *sock, int level, int optname,
 	if (put_user(len, optlen))
 		goto out;
 
-	val = x25_sk(sk)->qbitincl;
+	val = sk->qbitincl;
 	rc = copy_to_user(optval, &val, len) ? -EFAULT : 0;
 out:
-	unlock_kernel();
 	return rc;
 }
 
-- 
1.7.0.4



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

* Re: [PATCH] X25: Replace BKL in sockopts calls
  2010-05-09 12:45 [PATCH] X25: Replace BKL in sockopts calls Andrew Hendry
@ 2010-05-10  1:46 ` David Miller
  2010-05-10  4:50   ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2010-05-10  1:46 UTC (permalink / raw)
  To: andrew.hendry; +Cc: netdev

From: Andrew Hendry <andrew.hendry@gmail.com>
Date: Sun, 09 May 2010 22:45:23 +1000

> @@ -465,20 +464,20 @@ static int x25_setsockopt(struct socket *sock, int level, int optname,
>  	if (get_user(opt, (int __user *)optval))
>  		goto out;
>  
> +	lock_sock(sk);
>  	x25_sk(sk)->qbitincl = !!opt;
> +	release_sock(sk);

This is completely bogus.

A store is always atomic on an SMP system, and "opt" is in a local variable
rather than being computed based upon some memory values.

There is no reason to require locking for this operation.

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

* Re: [PATCH] X25: Replace BKL in sockopts calls
  2010-05-10  1:46 ` David Miller
@ 2010-05-10  4:50   ` Eric Dumazet
  2010-05-10 11:44     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2010-05-10  4:50 UTC (permalink / raw)
  To: David Miller; +Cc: andrew.hendry, netdev

Le dimanche 09 mai 2010 à 18:46 -0700, David Miller a écrit :
> From: Andrew Hendry <andrew.hendry@gmail.com>
> Date: Sun, 09 May 2010 22:45:23 +1000
> 
> > @@ -465,20 +464,20 @@ static int x25_setsockopt(struct socket *sock, int level, int optname,
> >  	if (get_user(opt, (int __user *)optval))
> >  		goto out;
> >  
> > +	lock_sock(sk);
> >  	x25_sk(sk)->qbitincl = !!opt;
> > +	release_sock(sk);
> 
> This is completely bogus.
> 
> A store is always atomic on an SMP system, and "opt" is in a local variable
> rather than being computed based upon some memory values.
> 
> There is no reason to require locking for this operation.

Well, its probably better than lock_kernel() ;)

qbitincl is a char, I suspect some arches cant store a char in an atomic
way ? Alpha comes to mind.


We now have lock_sock_bh()/unlock_sock_bh() for this kind of very short
sections, where we cant sleep.




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

* Re: [PATCH] X25: Replace BKL in sockopts calls
  2010-05-10  4:50   ` Eric Dumazet
@ 2010-05-10 11:44     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2010-05-10 11:44 UTC (permalink / raw)
  To: eric.dumazet; +Cc: andrew.hendry, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Mon, 10 May 2010 06:50:40 +0200

> Well, its probably better than lock_kernel() ;)
> 
> qbitincl is a char, I suspect some arches cant store a char in an atomic
> way ? Alpha comes to mind.

True.

> We now have lock_sock_bh()/unlock_sock_bh() for this kind of very short
> sections, where we cant sleep.

Another option is to simply use an atomic bitmask to represent these
booleans instead of a crufty set of chars.

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

end of thread, other threads:[~2010-05-10 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-09 12:45 [PATCH] X25: Replace BKL in sockopts calls Andrew Hendry
2010-05-10  1:46 ` David Miller
2010-05-10  4:50   ` Eric Dumazet
2010-05-10 11:44     ` 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).