diff mbox

RDMA/addr: Use appropriate locking with for_each_netdev()

Message ID 4AF8EBA4.2070102@gmail.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Eric Dumazet Nov. 10, 2009, 4:27 a.m. UTC
for_each_netdev() should be used with RTNL or dev_base_lock held,
or risk a crash.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 drivers/infiniband/core/addr.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

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

Comments

Sean Hefty Nov. 11, 2009, 6:18 p.m. UTC | #1
>for_each_netdev() should be used with RTNL or dev_base_lock held,
>or risk a crash.
>
>Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Thanks - I'm working on a patch set in this area.  Roland, I can merge Eric's
changes into that patch set if it makes things easier.

> drivers/infiniband/core/addr.c |    9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
>index bd07803..5ca0b2c 100644
>--- a/drivers/infiniband/core/addr.c
>+++ b/drivers/infiniband/core/addr.c
>@@ -131,6 +131,7 @@ int rdma_translate_ip(struct sockaddr *addr, struct

The changes to this function are still valid.

>@@ -391,15 +393,17 @@ static int addr_resolve_local(struct sockaddr *src_in,

This function is going away.

- Sean

--
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
Roland Dreier Nov. 11, 2009, 6:25 p.m. UTC | #2
> >for_each_netdev() should be used with RTNL or dev_base_lock held,
 > >or risk a crash.
 > >
 > >Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
 > 
 > Thanks - I'm working on a patch set in this area.  Roland, I can merge Eric's
 > changes into that patch set if it makes things easier.

Would it be possible for you to take Eric's patch as the first in your
set (keeping his From: of course) and base your fixes on top of that?
That seems the cleanest thing to me.

Thanks,
  Roland
--
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
Sean Hefty Nov. 11, 2009, 8:55 p.m. UTC | #3
>Would it be possible for you to take Eric's patch as the first in your
>set (keeping his From: of course) and base your fixes on top of that?

Will do.

--
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
diff mbox

Patch

diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index bd07803..5ca0b2c 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -131,6 +131,7 @@  int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr)
 
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
 	case AF_INET6:
+		read_lock(&dev_base_lock);
 		for_each_netdev(&init_net, dev) {
 			if (ipv6_chk_addr(&init_net,
 					  &((struct sockaddr_in6 *) addr)->sin6_addr,
@@ -139,6 +140,7 @@  int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr)
 				break;
 			}
 		}
+		read_unlock(&dev_base_lock);
 		break;
 #endif
 	}
@@ -391,15 +393,17 @@  static int addr_resolve_local(struct sockaddr *src_in,
 	{
 		struct in6_addr *a;
 
+		read_lock(&dev_base_lock);
 		for_each_netdev(&init_net, dev)
 			if (ipv6_chk_addr(&init_net,
 					  &((struct sockaddr_in6 *) dst_in)->sin6_addr,
 					  dev, 1))
 				break;
 
-		if (!dev)
+		if (!dev) {
+			read_unlock(&dev_base_lock);
 			return -EADDRNOTAVAIL;
-
+		}
 		a = &((struct sockaddr_in6 *) src_in)->sin6_addr;
 
 		if (ipv6_addr_any(a)) {
@@ -416,6 +420,7 @@  static int addr_resolve_local(struct sockaddr *src_in,
 			if (!ret)
 				memcpy(addr->dst_dev_addr, dev->dev_addr, MAX_ADDR_LEN);
 		}
+		read_unlock(&dev_base_lock);
 		break;
 	}
 #endif