* why does there need to lock?
@ 2010-03-22 0:41 杨硕
2010-03-22 8:05 ` Eric Dumazet
0 siblings, 1 reply; 2+ messages in thread
From: 杨硕 @ 2010-03-22 0:41 UTC (permalink / raw)
To: netdev
Hi, i'm confused about why does "rcu_assign_pointer(dev->ip_ptr,
in_dev);" need to rcu lock?
TIA :)
static struct in_device *inetdev_init(struct net_device *dev)
{
struct in_device *in_dev;
ASSERT_RTNL();
in_dev = kzalloc(sizeof(*in_dev), GFP_KERNEL);
if (!in_dev)
goto out;
memcpy(&in_dev->cnf, dev_net(dev)->ipv4.devconf_dflt,
sizeof(in_dev->cnf));
in_dev->cnf.sysctl = NULL;
in_dev->dev = dev;
if ((in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl)) == NULL)
goto out_kfree;
if (IPV4_DEVCONF(in_dev->cnf, FORWARDING))
dev_disable_lro(dev);
/* Reference in_dev->dev */
dev_hold(dev);
/* Account for reference dev->ip_ptr (below) */
in_dev_hold(in_dev);
devinet_sysctl_register(in_dev);
ip_mc_init_dev(in_dev);
if (dev->flags & IFF_UP)
ip_mc_up(in_dev);
/* we can receive as soon as ip_ptr is set -- do this last */
rcu_assign_pointer(dev->ip_ptr, in_dev);
out:
return in_dev;
out_kfree:
kfree(in_dev);
in_dev = NULL;
goto out;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: why does there need to lock?
2010-03-22 0:41 why does there need to lock? 杨硕
@ 2010-03-22 8:05 ` Eric Dumazet
0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 2010-03-22 8:05 UTC (permalink / raw)
To: 杨硕; +Cc: netdev
Le lundi 22 mars 2010 à 08:41 +0800, 杨硕 a écrit :
> Hi, i'm confused about why does "rcu_assign_pointer(dev->ip_ptr,
> in_dev);" need to rcu lock?
>
I am confused by your question
rcu_assign_pointer doesnt need rcu lock.
It only makes sure all previous memory changes are committed to memory
before the "dev->ip_ptr = in_dev;" assignement, so that concurrent
readers cannot find the new pointer and read previous values of
dev->ip_ptr->fields
> TIA :)
>
> static struct in_device *inetdev_init(struct net_device *dev)
> {
> struct in_device *in_dev;
>
> ASSERT_RTNL();
>
> in_dev = kzalloc(sizeof(*in_dev), GFP_KERNEL);
> if (!in_dev)
> goto out;
> memcpy(&in_dev->cnf, dev_net(dev)->ipv4.devconf_dflt,
> sizeof(in_dev->cnf));
> in_dev->cnf.sysctl = NULL;
> in_dev->dev = dev;
> if ((in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl)) == NULL)
> goto out_kfree;
> if (IPV4_DEVCONF(in_dev->cnf, FORWARDING))
> dev_disable_lro(dev);
> /* Reference in_dev->dev */
> dev_hold(dev);
> /* Account for reference dev->ip_ptr (below) */
> in_dev_hold(in_dev);
>
> devinet_sysctl_register(in_dev);
> ip_mc_init_dev(in_dev);
> if (dev->flags & IFF_UP)
> ip_mc_up(in_dev);
>
> /* we can receive as soon as ip_ptr is set -- do this last */
> rcu_assign_pointer(dev->ip_ptr, in_dev);
> out:
> return in_dev;
> out_kfree:
> kfree(in_dev);
> in_dev = NULL;
> goto out;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-03-22 8:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-22 0:41 why does there need to lock? 杨硕
2010-03-22 8:05 ` Eric Dumazet
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.