netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Shearman <rshearma@brocade.com>
To: roopa <roopa@cumulusnetworks.com>
Cc: <davem@davemloft.net>, <netdev@vger.kernel.org>, <ebiederm@xmission.com>
Subject: Re: [PATCH net-next v4 1/2] mpls: multipath route support
Date: Thu, 22 Oct 2015 14:48:55 +0100	[thread overview]
Message-ID: <5628E947.60707@brocade.com> (raw)
In-Reply-To: <5628E594.4070900@cumulusnetworks.com>

On 22/10/15 14:33, roopa wrote:
> On 10/22/15, 3:24 AM, Robert Shearman wrote:
>> On 19/10/15 02:20, Roopa Prabhu wrote:
>>>        return dev;
>>>    }
>>>
>>> +static int mpls_nh_assign_dev(struct net *net, struct mpls_nh *nh, int oif)
>>> +{
>>> +    struct net_device *dev = NULL;
>>> +    int err = -ENODEV;
>>> +
>>> +    dev = find_outdev(net, nh, oif);
>>> +    if (IS_ERR(dev)) {
>>> +        err = PTR_ERR(dev);
>>> +        dev = NULL;
>>> +        goto errout;
>>> +    }
>>> +
>>> +    /* Ensure this is a supported device */
>>> +    err = -EINVAL;
>>> +    if (!mpls_dev_get(dev))
>>> +        goto errout;
>>> +
>>> +    /* For now just support ethernet devices */
>>> +    if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
>>> +        goto errout;
>>> +
>>> +    RCU_INIT_POINTER(nh->nh_dev, dev);
>>> +    dev_put(dev);
>>
>> If it's safe to not keep a reference to dev (i.e. because the device cannot go away while a netlink message is being processed), then why not just change find_outdev to use __dev_get_by_index?
> yes, rtnl is held here. dev_get_by_index was used by the original code. So i did not feel the need to change that.
> I can see the need to get away with the dev_hold instead of doing a dev_hold with dev_get_by_index, rcu assign and put because of rtnl. But, it seems cleaner to use it the way it is today, given the other cases where the dev is already held during lookup when oif is not specified.
>
>> If the dev can go away during this, then we could end up adding an mpls route that points to a freed interface, because until we've added the route to the label table mpls_ifdown won't find it.
> dev should not go away because we have rtnl held at this point. no ?
> If there is a problem i can think about moving the dev_put's for nexthop devs after mpls_route_update

Yes, either do that or change find_outdev to avoid holding a reference 
to the dev (which given that it's safe is my preference). The way it is 
here is slightly confusing as it raises the question in the reader's 
mind about whether a reference to dev is required or not.

Thanks,
Rob

      reply	other threads:[~2015-10-22 13:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-19  1:20 [PATCH net-next v4 1/2] mpls: multipath route support Roopa Prabhu
2015-10-22  2:00 ` Eric W. Biederman
2015-10-22 13:06   ` roopa
2015-10-22 10:24 ` Robert Shearman
2015-10-22 13:33   ` roopa
2015-10-22 13:48     ` Robert Shearman [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=5628E947.60707@brocade.com \
    --to=rshearma@brocade.com \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.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;
as well as URLs for NNTP newsgroup(s).