netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: "Lucero Palau, Alejandro" <alejandro.lucero-palau@amd.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-net-drivers (AMD-Xilinx)" <linux-net-drivers@amd.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"edumazet@google.com" <edumazet@google.com>,
	"ecree.xilinx@gmail.com" <ecree.xilinx@gmail.com>
Subject: Re: [PATCH net-next 1/7] sfc: add devlink support for ef100
Date: Thu, 19 Jan 2023 10:44:27 -0800	[thread overview]
Message-ID: <20230119104427.69d95782@kernel.org> (raw)
In-Reply-To: <82a57ba1-bd28-3742-0027-a6a284569aee@amd.com>

On Thu, 19 Jan 2023 17:52:42 +0000 Lucero Palau, Alejandro wrote:
> On 1/19/23 17:16, Jakub Kicinski wrote:
> > On Thu, 19 Jan 2023 11:31:34 +0000 alejandro.lucero-palau@amd.com wrote:  
> >> +		devlink_unregister(efx->devlink);
> >> +		devlink_free(efx->devlink);  
> > Please use the devl_ APIs and take the devl_lock() explicitly.
> > Once you start adding sub-objects the API with implicit locking
> > gets racy.  
> 
> I need more help here.
> 
> The explicit locking you refer to, is it for this specific code only?

I only had a quick look at the series, but I saw you add ports.
So the locking should be something like:

  devlink = devlink_alloc();
  devl_lock(devlink);
  ...
  devl_register(devlink);
  ...
  netdev_register(netdev);
  devl_port_register(port_for_the_netdev);
  ...
  devl_unlock();

And the inverse on the .remove path.
Basically you want to hold the devlink instance lock for most of 
the .probe and .remove. That way nothing can bother the devlink
instance and the driver while the driver is initializing/finalizing.

Without holding the lock the linking between the devlink port and 
the netdev gets a bit iffy. It's a circular dependency of sorts
because both the netdev carries a link to the port and the port
carries info about the netdev.

We've been figuring out workarounds for subtle ordering and locking
problems since devlink ports were created. Recently we just gave up
and started asking drivers to hold the instance lock across .probe/
/.remove.

> Also, I can not see all drivers locking/unlocking when doing 
> devlink_unregister. Those doing it are calling code which invoke 
> unregister devlink ports, like the NFP and I think ml5x as well.

Right, only netdevsim was fully converted so far. The syzbot and other
testers use netdevsim mostly. We'll push actual HW drivers towards this
locking slowly.

> In this case, no devlink port remains at this point, and no netdev either.
> 
> What is the potential race against?

Right, I don't mean this particular spot, just over-trimmed the quote.

  reply	other threads:[~2023-01-19 18:44 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-19 11:31 [PATCH net-next 0/7] sfc: devlink support for ef100 alejandro.lucero-palau
2023-01-19 11:31 ` [PATCH net-next 1/7] sfc: add " alejandro.lucero-palau
2023-01-19 12:14   ` Jiri Pirko
2023-01-19 14:51     ` Lucero Palau, Alejandro
2023-01-19 16:29       ` Lucero Palau, Alejandro
2023-01-20 11:02         ` Jiri Pirko
2023-01-20 11:00       ` Jiri Pirko
2023-01-19 15:50   ` kernel test robot
2023-01-19 17:16   ` Jakub Kicinski
2023-01-19 17:52     ` Lucero Palau, Alejandro
2023-01-19 18:44       ` Jakub Kicinski [this message]
2023-01-19 19:08         ` Lucero Palau, Alejandro
2023-01-19 23:40   ` Jacob Keller
2023-01-20 14:11     ` Lucero Palau, Alejandro
2023-01-24  6:13       ` Edward Cree
2023-01-24  7:31         ` Lucero Palau, Alejandro
2023-01-24 11:05     ` Lucero Palau, Alejandro
2023-01-24 22:12       ` Jacob Keller
2023-01-20 13:59   ` kernel test robot
2023-01-19 11:31 ` [PATCH net-next 2/7] sfc: enumerate mports in ef100 alejandro.lucero-palau
2023-01-19 23:48   ` Jacob Keller
2023-01-20 14:13     ` Lucero Palau, Alejandro
2023-01-20 12:47   ` kernel test robot
2023-01-19 11:31 ` [PATCH net-next 3/7] sfc: add mport lookup based on driver's mport data alejandro.lucero-palau
2023-01-19 23:57   ` Jacob Keller
2023-01-20  9:34     ` Lucero Palau, Alejandro
2023-01-20 18:36       ` Keller, Jacob E
2023-01-19 11:31 ` [PATCH net-next 4/7] sfc: add devlink port support for ef100 alejandro.lucero-palau
2023-01-19 12:33   ` Jiri Pirko
2023-01-19 15:03     ` Lucero Palau, Alejandro
2023-01-19 13:37   ` kernel test robot
2023-01-20 21:21   ` kernel test robot
2023-01-19 11:31 ` [PATCH net-next 5/7] sfc: obtain device mac address based on firmware handle " alejandro.lucero-palau
2023-01-19 19:47   ` kernel test robot
2023-01-20  0:03   ` Jacob Keller
2023-01-19 11:31 ` [PATCH net-next 6/7] sfc: add support for port_function_hw_addr_get devlink in ef100 alejandro.lucero-palau
2023-01-19 12:25   ` Jiri Pirko
2023-01-19 14:59     ` Lucero Palau, Alejandro
2023-01-20 11:05       ` Jiri Pirko
2023-01-22 16:41         ` Lucero Palau, Alejandro
2023-01-19 12:37   ` Jiri Pirko
2023-01-19 15:09     ` Lucero Palau, Alejandro
2023-01-20 11:08       ` Jiri Pirko
2023-01-20 12:48         ` Lucero Palau, Alejandro
2023-01-22 16:36           ` Lucero Palau, Alejandro
2023-01-23  8:38             ` Jiri Pirko
2023-01-23  9:45               ` Lucero Palau, Alejandro
2023-01-23 10:18                 ` Jiri Pirko
2023-01-19 11:31 ` [PATCH net-next 7/7] sfc: add support for devlink port_function_hw_addr_set " alejandro.lucero-palau
2023-01-19 12:27   ` Jiri Pirko
2023-01-19 15:10     ` Lucero Palau, Alejandro
2023-01-20  8:55 ` [PATCH net-next 0/7] sfc: devlink support for ef100 Martin Habets

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=20230119104427.69d95782@kernel.org \
    --to=kuba@kernel.org \
    --cc=alejandro.lucero-palau@amd.com \
    --cc=davem@davemloft.net \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@google.com \
    --cc=linux-net-drivers@amd.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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).