Netdev List
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Neil Horman <nhorman@redhat.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Nikolay Aleksandrov <nikolay@cumulusnetworks.com>,
	netdev@vger.kernel.org, Alexander Duyck <aduyck@mirantis.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] netpoll: Fix extra refcount release in netpoll_cleanup()
Date: Fri, 25 Mar 2016 11:46:39 -0500	[thread overview]
Message-ID: <20160325164639.GA29822@localhost> (raw)
In-Reply-To: <20160325113342.GA21579@hmsreliant.think-freely.org>

On Fri, Mar 25, 2016 at 07:33:42AM -0400, Neil Horman wrote:
> On Thu, Mar 24, 2016 at 09:56:21PM -0500, Bjorn Helgaas wrote:
> > netpoll_setup() does a dev_hold() on np->dev, the netpoll device.  If it
> > fails, it correctly does a dev_put() but leaves np->dev set.  If we call
> > netpoll_cleanup() after the failure, np->dev is still set so we do another
> > dev_put(), which decrements the refcount an extra time.
> > 
> > It's questionable to call netpoll_cleanup() after netpoll_setup() fails,
> > but it can be difficult to find the problem, and we can easily avoid it in
> > this case.  The extra decrements can lead to hangs like this:
> > 
> >   unregister_netdevice: waiting for bond0 to become free. Usage count = -3
> > 
> > Set and clear np->dev at the points where we dev_hold() and dev_put() the
> > device.
> > 
> > Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> > ---
> >  net/core/netpoll.c |    3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/core/netpoll.c b/net/core/netpoll.c
> > index 94acfc8..a57bd17 100644
> > --- a/net/core/netpoll.c
> > +++ b/net/core/netpoll.c
> > @@ -603,7 +603,6 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
> >  	const struct net_device_ops *ops;
> >  	int err;
> >  
> > -	np->dev = ndev;
> >  	strlcpy(np->dev_name, ndev->name, IFNAMSIZ);
> >  	INIT_WORK(&np->cleanup_work, netpoll_async_cleanup);
> >  
> > @@ -670,6 +669,7 @@ int netpoll_setup(struct netpoll *np)
> >  		goto unlock;
> >  	}
> >  	dev_hold(ndev);
> > +	np->dev = ndev;
> >  
> >  	if (netdev_master_upper_dev_get(ndev)) {
> >  		np_err(np, "%s is a slave device, aborting\n", np->dev_name);
> > @@ -770,6 +770,7 @@ int netpoll_setup(struct netpoll *np)
> >  	return 0;
> >  
> >  put:
> > +	np->dev = NULL;
> >  	dev_put(ndev);
> >  unlock:
> >  	rtnl_unlock();
> > 
> 
> Is this safe for stacked devices?  It makes good sense for the typical case, but
> if you attempt to setup a netpoll client on a bridge/bond/vlan, etc, the lower
> device will get its own netpoll struct registered and have no associated np->dev
> pointer.  It not be a real problem in practice, But you probably want to check
> to make sure that stacked  devices which recursively call the netpoll api don't
> do anyting with the np->dev pointer.

You're right, there is an issue here.  I reproduced a problem with a
bond device.  bond_netpoll_setup() calls __netpoll_setup() directly
(not netpoll_setup()).  I'll debug it more; just wanted to let you
know there *is* a problem with this patch.

Bjorn

  reply	other threads:[~2016-03-25 16:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-25  2:56 [PATCH v2] netpoll: Fix extra refcount release in netpoll_cleanup() Bjorn Helgaas
2016-03-25 11:33 ` Neil Horman
2016-03-25 16:46   ` Bjorn Helgaas [this message]
2016-03-25 19:16     ` David Miller
2016-03-28 13:18       ` Neil Horman
2016-03-25 15:24 ` David Miller

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=20160325164639.GA29822@localhost \
    --to=helgaas@kernel.org \
    --cc=aduyck@mirantis.com \
    --cc=bhelgaas@google.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=nikolay@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