Skip to contentSkip to conversation

X25: Replace BKL in sockopts calls

PATCH In review Andrew Hendry 3 participants 4 messages May 9, 2010 – May 10, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 X25: Replace BKL in sockopts calls

x25_setsockopt only updates the socket
x25_get only reads

---
 net/x25/af_x25.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
net/x25/af_x25.c +4 -6
index 296e65e..9f177a1 100644
@@ -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;
 }
 
Signature · 1 line
1.7.0.4
maintainer
#1 lore raw

From: Andrew Hendry <[email protected]>
Date: Sun, 09 May 2010 22:45:23 +1000

net/x25/af_x25.c static int x25_setsockopt(struct socket *sock, int level, int optname, · line 469

Quoted 7 lines
net/x25/af_x25.c +2 -0
@@ -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.

#2 lore raw
Quoted 13 lines · David Miller

From: Andrew Hendry <[email protected]>
Date: Sun, 09 May 2010 22:45:23 +1000

net/x25/af_x25.c static int x25_setsockopt(struct socket *sock, int level, int optname, · line 469

Quoted 7 lines
net/x25/af_x25.c +2 -0
@@ -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.

Quoted 4 lines

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.

maintainer
#3 lore raw

From: Eric Dumazet <[email protected]>
Date: Mon, 10 May 2010 06:50:40 +0200

Quoted 4 lines

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.

Quoted 2 lines

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.