net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()
Le dimanche 05 décembre 2010 à 09:19 +0100, Eric Dumazet a écrit : > Hmm.. > > If somebody can explain why RTNL is held in arp_ioctl() (and therefore > in arp_req_delete()), we might first remove RTNL use in arp_ioctl() so > that your patch can be applied. > > Right now it is not good, because RTNL wont be necessarly held when you > are going to call arp_invalidate() ? While doing this analysis, I found a refcount bug in llc, I'll send a patch for net-2.6 Meanwhile, here is the patch for net-next-2.6 Your patch then can be applied after mine. Thanks [PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl() dev_getbyhwaddr() was called under RTNL. Rename it to dev_getbyhwaddr_rcu() and change all its caller to now use RCU locking instead of RTNL. Change arp_ioctl() to use RCU instead of RTNL locking. Note: this fix a dev refcount bug in llc Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
a2d4b65d47
commit
941666c2e3
5 changed files with 27 additions and 27 deletions
|
@ -1360,7 +1360,8 @@ static inline struct net_device *first_net_device(struct net *net)
|
||||||
|
|
||||||
extern int netdev_boot_setup_check(struct net_device *dev);
|
extern int netdev_boot_setup_check(struct net_device *dev);
|
||||||
extern unsigned long netdev_boot_base(const char *prefix, int unit);
|
extern unsigned long netdev_boot_base(const char *prefix, int unit);
|
||||||
extern struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *hwaddr);
|
extern struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
|
||||||
|
const char *hwaddr);
|
||||||
extern struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
|
extern struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
|
||||||
extern struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type);
|
extern struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type);
|
||||||
extern void dev_add_pack(struct packet_type *pt);
|
extern void dev_add_pack(struct packet_type *pt);
|
||||||
|
|
|
@ -743,34 +743,31 @@ struct net_device *dev_get_by_index(struct net *net, int ifindex)
|
||||||
EXPORT_SYMBOL(dev_get_by_index);
|
EXPORT_SYMBOL(dev_get_by_index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dev_getbyhwaddr - find a device by its hardware address
|
* dev_getbyhwaddr_rcu - find a device by its hardware address
|
||||||
* @net: the applicable net namespace
|
* @net: the applicable net namespace
|
||||||
* @type: media type of device
|
* @type: media type of device
|
||||||
* @ha: hardware address
|
* @ha: hardware address
|
||||||
*
|
*
|
||||||
* Search for an interface by MAC address. Returns NULL if the device
|
* Search for an interface by MAC address. Returns NULL if the device
|
||||||
* is not found or a pointer to the device. The caller must hold the
|
* is not found or a pointer to the device. The caller must hold RCU
|
||||||
* rtnl semaphore. The returned device has not had its ref count increased
|
* The returned device has not had its ref count increased
|
||||||
* and the caller must therefore be careful about locking
|
* and the caller must therefore be careful about locking
|
||||||
*
|
*
|
||||||
* BUGS:
|
|
||||||
* If the API was consistent this would be __dev_get_by_hwaddr
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *ha)
|
struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
|
||||||
|
const char *ha)
|
||||||
{
|
{
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
|
|
||||||
ASSERT_RTNL();
|
for_each_netdev_rcu(net, dev)
|
||||||
|
|
||||||
for_each_netdev(net, dev)
|
|
||||||
if (dev->type == type &&
|
if (dev->type == type &&
|
||||||
!memcmp(dev->dev_addr, ha, dev->addr_len))
|
!memcmp(dev->dev_addr, ha, dev->addr_len))
|
||||||
return dev;
|
return dev;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(dev_getbyhwaddr);
|
EXPORT_SYMBOL(dev_getbyhwaddr_rcu);
|
||||||
|
|
||||||
struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type)
|
struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,11 +52,11 @@ struct net_device *ieee802154_get_dev(struct net *net,
|
||||||
|
|
||||||
switch (addr->addr_type) {
|
switch (addr->addr_type) {
|
||||||
case IEEE802154_ADDR_LONG:
|
case IEEE802154_ADDR_LONG:
|
||||||
rtnl_lock();
|
rcu_read_lock();
|
||||||
dev = dev_getbyhwaddr(net, ARPHRD_IEEE802154, addr->hwaddr);
|
dev = dev_getbyhwaddr_rcu(net, ARPHRD_IEEE802154, addr->hwaddr);
|
||||||
if (dev)
|
if (dev)
|
||||||
dev_hold(dev);
|
dev_hold(dev);
|
||||||
rtnl_unlock();
|
rcu_read_unlock();
|
||||||
break;
|
break;
|
||||||
case IEEE802154_ADDR_SHORT:
|
case IEEE802154_ADDR_SHORT:
|
||||||
if (addr->pan_id == 0xffff ||
|
if (addr->pan_id == 0xffff ||
|
||||||
|
|
|
@ -1017,13 +1017,14 @@ static int arp_req_set_proxy(struct net *net, struct net_device *dev, int on)
|
||||||
IPV4_DEVCONF_ALL(net, PROXY_ARP) = on;
|
IPV4_DEVCONF_ALL(net, PROXY_ARP) = on;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (__in_dev_get_rtnl(dev)) {
|
if (__in_dev_get_rcu(dev)) {
|
||||||
IN_DEV_CONF_SET(__in_dev_get_rtnl(dev), PROXY_ARP, on);
|
IN_DEV_CONF_SET(__in_dev_get_rcu(dev), PROXY_ARP, on);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* must be called with rcu_read_lock() */
|
||||||
static int arp_req_set_public(struct net *net, struct arpreq *r,
|
static int arp_req_set_public(struct net *net, struct arpreq *r,
|
||||||
struct net_device *dev)
|
struct net_device *dev)
|
||||||
{
|
{
|
||||||
|
@ -1033,7 +1034,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r,
|
||||||
if (mask && mask != htonl(0xFFFFFFFF))
|
if (mask && mask != htonl(0xFFFFFFFF))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!dev && (r->arp_flags & ATF_COM)) {
|
if (!dev && (r->arp_flags & ATF_COM)) {
|
||||||
dev = dev_getbyhwaddr(net, r->arp_ha.sa_family,
|
dev = dev_getbyhwaddr_rcu(net, r->arp_ha.sa_family,
|
||||||
r->arp_ha.sa_data);
|
r->arp_ha.sa_data);
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
@ -1225,10 +1226,10 @@ int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg)
|
||||||
if (!(r.arp_flags & ATF_NETMASK))
|
if (!(r.arp_flags & ATF_NETMASK))
|
||||||
((struct sockaddr_in *)&r.arp_netmask)->sin_addr.s_addr =
|
((struct sockaddr_in *)&r.arp_netmask)->sin_addr.s_addr =
|
||||||
htonl(0xFFFFFFFFUL);
|
htonl(0xFFFFFFFFUL);
|
||||||
rtnl_lock();
|
rcu_read_lock();
|
||||||
if (r.arp_dev[0]) {
|
if (r.arp_dev[0]) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
dev = __dev_get_by_name(net, r.arp_dev);
|
dev = dev_get_by_name_rcu(net, r.arp_dev);
|
||||||
if (dev == NULL)
|
if (dev == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -1252,12 +1253,12 @@ int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg)
|
||||||
break;
|
break;
|
||||||
case SIOCGARP:
|
case SIOCGARP:
|
||||||
err = arp_req_get(&r, dev);
|
err = arp_req_get(&r, dev);
|
||||||
if (!err && copy_to_user(arg, &r, sizeof(r)))
|
|
||||||
err = -EFAULT;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
rtnl_unlock();
|
rcu_read_unlock();
|
||||||
|
if (cmd == SIOCGARP && !err && copy_to_user(arg, &r, sizeof(r)))
|
||||||
|
err = -EFAULT;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -316,9 +316,9 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
|
||||||
if (unlikely(addr->sllc_family != AF_LLC))
|
if (unlikely(addr->sllc_family != AF_LLC))
|
||||||
goto out;
|
goto out;
|
||||||
rc = -ENODEV;
|
rc = -ENODEV;
|
||||||
rtnl_lock();
|
rcu_read_lock();
|
||||||
if (sk->sk_bound_dev_if) {
|
if (sk->sk_bound_dev_if) {
|
||||||
llc->dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if);
|
llc->dev = dev_get_by_index_rcu(&init_net, sk->sk_bound_dev_if);
|
||||||
if (llc->dev) {
|
if (llc->dev) {
|
||||||
if (!addr->sllc_arphrd)
|
if (!addr->sllc_arphrd)
|
||||||
addr->sllc_arphrd = llc->dev->type;
|
addr->sllc_arphrd = llc->dev->type;
|
||||||
|
@ -329,14 +329,15 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
|
||||||
!llc_mac_match(addr->sllc_mac,
|
!llc_mac_match(addr->sllc_mac,
|
||||||
llc->dev->dev_addr)) {
|
llc->dev->dev_addr)) {
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
dev_put(llc->dev);
|
|
||||||
llc->dev = NULL;
|
llc->dev = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
llc->dev = dev_getbyhwaddr(&init_net, addr->sllc_arphrd,
|
llc->dev = dev_getbyhwaddr_rcu(&init_net, addr->sllc_arphrd,
|
||||||
addr->sllc_mac);
|
addr->sllc_mac);
|
||||||
rtnl_unlock();
|
if (llc->dev)
|
||||||
|
dev_hold(llc->dev);
|
||||||
|
rcu_read_unlock();
|
||||||
if (!llc->dev)
|
if (!llc->dev)
|
||||||
goto out;
|
goto out;
|
||||||
if (!addr->sllc_sap) {
|
if (!addr->sllc_sap) {
|
||||||
|
|
Loading…
Reference in a new issue