Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: 杨硕 <shanqn@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: why does there need to lock?
Date: Mon, 22 Mar 2010 09:05:26 +0100	[thread overview]
Message-ID: <1269245126.3029.3.camel@edumazet-laptop> (raw)
In-Reply-To: <ffe582101003211741v59da3c56yaffdaa151a6821be@mail.gmail.com>

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



      reply	other threads:[~2010-03-22  8:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-22  0:41 why does there need to lock? 杨硕
2010-03-22  8:05 ` Eric Dumazet [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1269245126.3029.3.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=shanqn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox