* [PATCH net-next2.6] ipv6: avoid dev_hold()/dev_put() in rawv6_bind()
@ 2009-11-06 10:53 Eric Dumazet
2009-11-06 16:48 ` Brian Haley
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2009-11-06 10:53 UTC (permalink / raw)
To: David S. Miller; +Cc: Linux Netdev List
Using RCU helps not touching device refcount in rawv6_bind()
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
net/ipv6/raw.c | 23 +++++++++++------------
1 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 818ef21..80f356a 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -249,7 +249,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
/* Raw sockets are IPv6 only */
if (addr_type == IPV6_ADDR_MAPPED)
- return(-EADDRNOTAVAIL);
+ return -EADDRNOTAVAIL;
lock_sock(sk);
@@ -257,6 +257,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
if (sk->sk_state != TCP_CLOSE)
goto out;
+ rcu_read_unlock();
/* Check if the address belongs to the host. */
if (addr_type != IPV6_ADDR_ANY) {
struct net_device *dev = NULL;
@@ -272,13 +273,13 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
/* Binding to link-local address requires an interface */
if (!sk->sk_bound_dev_if)
- goto out;
+ goto out_unlock;
- dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if);
- if (!dev) {
- err = -ENODEV;
- goto out;
- }
+ err = -ENODEV;
+ dev = dev_get_by_index_rcu(sock_net(sk),
+ sk->sk_bound_dev_if);
+ if (!dev)
+ goto out_unlock;
}
/* ipv4 addr of the socket is invalid. Only the
@@ -289,13 +290,9 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
err = -EADDRNOTAVAIL;
if (!ipv6_chk_addr(sock_net(sk), &addr->sin6_addr,
dev, 0)) {
- if (dev)
- dev_put(dev);
- goto out;
+ goto out_unlock;
}
}
- if (dev)
- dev_put(dev);
}
inet->inet_rcv_saddr = inet->inet_saddr = v4addr;
@@ -303,6 +300,8 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
if (!(addr_type & IPV6_ADDR_MULTICAST))
ipv6_addr_copy(&np->saddr, &addr->sin6_addr);
err = 0;
+out_unlock:
+ rcu_read_unlock();
out:
release_sock(sk);
return err;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next2.6] ipv6: avoid dev_hold()/dev_put() in rawv6_bind()
2009-11-06 10:53 [PATCH net-next2.6] ipv6: avoid dev_hold()/dev_put() in rawv6_bind() Eric Dumazet
@ 2009-11-06 16:48 ` Brian Haley
2009-11-06 17:01 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Brian Haley @ 2009-11-06 16:48 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David S. Miller, Linux Netdev List
Eric Dumazet wrote:
> @@ -257,6 +257,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
> if (sk->sk_state != TCP_CLOSE)
> goto out;
>
> + rcu_read_unlock();
> /* Check if the address belongs to the host. */
> if (addr_type != IPV6_ADDR_ANY) {
> struct net_device *dev = NULL;
This was supposed to be rcu_read_lock(), right?
-Brian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next2.6] ipv6: avoid dev_hold()/dev_put() in rawv6_bind()
2009-11-06 16:48 ` Brian Haley
@ 2009-11-06 17:01 ` Eric Dumazet
2009-11-08 8:44 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2009-11-06 17:01 UTC (permalink / raw)
To: Brian Haley; +Cc: David S. Miller, Linux Netdev List
Brian Haley a écrit :
> Eric Dumazet wrote:
>> @@ -257,6 +257,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
>> if (sk->sk_state != TCP_CLOSE)
>> goto out;
>>
>> + rcu_read_unlock();
>> /* Check if the address belongs to the host. */
>> if (addr_type != IPV6_ADDR_ANY) {
>> struct net_device *dev = NULL;
>
> This was supposed to be rcu_read_lock(), right?
>
Oops ! Indeed ! Thanks for spotting this Brian.
[PATCH net-next2.6] ipv6: avoid dev_hold()/dev_put() in rawv6_bind()
Using RCU helps not touching device refcount in rawv6_bind()
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
net/ipv6/raw.c | 23 +++++++++++------------
1 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 818ef21..926ce8e 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -249,7 +249,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
/* Raw sockets are IPv6 only */
if (addr_type == IPV6_ADDR_MAPPED)
- return(-EADDRNOTAVAIL);
+ return -EADDRNOTAVAIL;
lock_sock(sk);
@@ -257,6 +257,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
if (sk->sk_state != TCP_CLOSE)
goto out;
+ rcu_read_lock();
/* Check if the address belongs to the host. */
if (addr_type != IPV6_ADDR_ANY) {
struct net_device *dev = NULL;
@@ -272,13 +273,13 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
/* Binding to link-local address requires an interface */
if (!sk->sk_bound_dev_if)
- goto out;
+ goto out_unlock;
- dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if);
- if (!dev) {
- err = -ENODEV;
- goto out;
- }
+ err = -ENODEV;
+ dev = dev_get_by_index_rcu(sock_net(sk),
+ sk->sk_bound_dev_if);
+ if (!dev)
+ goto out_unlock;
}
/* ipv4 addr of the socket is invalid. Only the
@@ -289,13 +290,9 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
err = -EADDRNOTAVAIL;
if (!ipv6_chk_addr(sock_net(sk), &addr->sin6_addr,
dev, 0)) {
- if (dev)
- dev_put(dev);
- goto out;
+ goto out_unlock;
}
}
- if (dev)
- dev_put(dev);
}
inet->inet_rcv_saddr = inet->inet_saddr = v4addr;
@@ -303,6 +300,8 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
if (!(addr_type & IPV6_ADDR_MULTICAST))
ipv6_addr_copy(&np->saddr, &addr->sin6_addr);
err = 0;
+out_unlock:
+ rcu_read_unlock();
out:
release_sock(sk);
return err;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next2.6] ipv6: avoid dev_hold()/dev_put() in rawv6_bind()
2009-11-06 17:01 ` Eric Dumazet
@ 2009-11-08 8:44 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2009-11-08 8:44 UTC (permalink / raw)
To: eric.dumazet; +Cc: brian.haley, netdev
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 06 Nov 2009 18:01:17 +0100
> [PATCH net-next2.6] ipv6: avoid dev_hold()/dev_put() in rawv6_bind()
>
> Using RCU helps not touching device refcount in rawv6_bind()
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-11-08 8:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-06 10:53 [PATCH net-next2.6] ipv6: avoid dev_hold()/dev_put() in rawv6_bind() Eric Dumazet
2009-11-06 16:48 ` Brian Haley
2009-11-06 17:01 ` Eric Dumazet
2009-11-08 8: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).