public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Damato <jdamato@fastly.com>
To: Stanislav Fomichev <stfomichev@gmail.com>
Cc: Stanislav Fomichev <sdf@fomichev.me>,
	netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com,
	Saeed Mahameed <saeed@kernel.org>
Subject: Re: [RFC net-next 1/4] net: Hold netdev instance lock during ndo_open/ndo_stop
Date: Wed, 5 Feb 2025 14:32:28 -0800	[thread overview]
Message-ID: <Z6Pm_AaXEwVFzHyI@LQ3V64L9R2> (raw)
In-Reply-To: <Z6PYvNeBE2_dpRDG@mini-arch>

On Wed, Feb 05, 2025 at 01:31:40PM -0800, Stanislav Fomichev wrote:
> On 02/05, Joe Damato wrote:
> > On Tue, Feb 04, 2025 at 03:00:54PM -0800, Stanislav Fomichev wrote:
> > > For the drivers that use shaper API, switch to the mode where
> > > core stack holds the netdev lock. This affects two drivers:
> > > 
> > > * iavf - already grabs netdev lock in ndo_open/ndo_stop, so mostly
> > >          remove these
> > > * netdevsim - switch to _locked APIs to avoid deadlock
> > > 
> > > Cc: Saeed Mahameed <saeed@kernel.org>
> > > Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> > > ---
> > >  Documentation/networking/netdevices.rst     |  6 ++++--
> > >  drivers/net/ethernet/intel/iavf/iavf_main.c | 14 ++++++-------
> > >  drivers/net/netdevsim/netdev.c              | 14 ++++++++-----
> > >  include/linux/netdevice.h                   | 23 +++++++++++++++++++++
> > >  net/core/dev.c                              | 12 +++++++++++
> > >  net/core/dev.h                              |  6 ++++--
> > >  6 files changed, 58 insertions(+), 17 deletions(-)
> > 
> > [...]
> > 
> > > @@ -4474,12 +4471,12 @@ static int iavf_close(struct net_device *netdev)
> > >  	u64 aq_to_restore;
> > >  	int status;
> > >  
> > > -	netdev_lock(netdev);
> > > +	netdev_assert_locked(netdev);
> > > +
> > >  	mutex_lock(&adapter->crit_lock);
> > >  
> > >  	if (adapter->state <= __IAVF_DOWN_PENDING) {
> > >  		mutex_unlock(&adapter->crit_lock);
> > > -		netdev_unlock(netdev);
> > >  		return 0;
> > >  	}
> > >  
> > > @@ -4532,6 +4529,7 @@ static int iavf_close(struct net_device *netdev)
> > >  	if (!status)
> > >  		netdev_warn(netdev, "Device resources not yet released\n");
> > >  
> > > +	netdev_lock(netdev);
> > 
> > I'm probably just misreading the rest of the patch, but I was just
> > wondering: is this netdev_lock call here intentional? I am asking
> > because I thought the lock was taken in ndo_stop before this is
> > called?
> 
> Yes, this part is a bit confusing. Existing iavf_close looks like
> this:
> 
> iavf_close() {
>   netdev_lock()
>   .. 
>   netdev_unlock()
>   wait_event_timeout(down_waitqueue)
> }
> 
> I change it to the following:
> 
> netdev_lock()
> iavf_close() {
>   .. 
>   netdev_unlock()
>   wait_event_timeout(down_waitqueue)
>   netdev_lock()
> }
> netdev_unlock()
> 
> And the diff is confusing because I reuse existing netdev_lock call,
> so it looks like I only add netdev_unlock...

Ah, I see. Thanks for explaining that; I looked at it a second time
more closely and I see that you are correct and I did miss the
existing netdev_lock call.

> I don't think I can hold instance lock during wait_event_timeout because
> the wake_up(down_waitqueue) callers grab netdev instance lock as well.

Agreed.

  reply	other threads:[~2025-02-05 22:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-04 23:00 [RFC net-next 0/4] net: Hold netdev instance lock during ndo operations Stanislav Fomichev
2025-02-04 23:00 ` [RFC net-next 1/4] net: Hold netdev instance lock during ndo_open/ndo_stop Stanislav Fomichev
2025-02-05 19:32   ` Joe Damato
2025-02-05 21:31     ` Stanislav Fomichev
2025-02-05 22:32       ` Joe Damato [this message]
2025-02-04 23:00 ` [RFC net-next 2/4] net: Hold netdev instance lock during ndo_setup_tc Stanislav Fomichev
2025-02-04 23:00 ` [RFC net-next 3/4] net: Hold netdev instance lock for more NDOs Stanislav Fomichev
2025-02-04 23:00 ` [RFC net-next 4/4] net: Hold netdev instance lock during queue operations Stanislav Fomichev
2025-02-14  2:10 ` [RFC net-next 0/4] net: Hold netdev instance lock during ndo operations Saeed Mahameed
2025-02-14  2:55   ` Stanislav Fomichev

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=Z6Pm_AaXEwVFzHyI@LQ3V64L9R2 \
    --to=jdamato@fastly.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeed@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=stfomichev@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