linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: p.rosenberger@kunbus.com, woojung.huh@microchip.com,
	UNGLinuxDriver@microchip.com, andrew@lunn.ch,
	vivien.didelot@gmail.com, f.fainelli@gmail.com,
	davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/3] Fix for KSZ DSA switch shutdown
Date: Thu, 9 Sep 2021 18:47:34 +0300	[thread overview]
Message-ID: <20210909154734.ujfnzu6omcjuch2a@skbuf> (raw)
In-Reply-To: <trinity-85ae3f9c-38f9-4442-98d3-bdc01279c7a8-1631193592256@3c-app-gmx-bs01>

On Thu, Sep 09, 2021 at 03:19:52PM +0200, Lino Sanfilippo wrote:
> > Do you see similar things on your 5.10 kernel?
> 
> For the master device is see
> 
> lrwxrwxrwx 1 root root 0 Sep  9 14:10 /sys/class/net/eth0/device/consumer:spi:spi3.0 -> ../../../virtual/devlink/platform:fd580000.ethernet--spi:spi3.0

So this is the worst of the worst, we have a device link but it doesn't help.

Where the device link helps is here:

__device_release_driver
	while (device_links_busy(dev))
		device_links_unbind_consumers(dev);

but during dev_shutdown, device_links_unbind_consumers does not get called
(actually I am not even sure whether it should).

I've reproduced your issue by making this very simple change:

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index 60d94e0a07d6..ec00f34cac47 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -1372,6 +1372,7 @@ static struct pci_driver enetc_pf_driver = {
 	.id_table = enetc_pf_id_table,
 	.probe = enetc_pf_probe,
 	.remove = enetc_pf_remove,
+	.shutdown = enetc_pf_remove,
 #ifdef CONFIG_PCI_IOV
 	.sriov_configure = enetc_sriov_configure,
 #endif

on my DSA master driver. This is what the genet driver has "special".

I was led into grave error by Documentation/driver-api/device_link.rst,
which I've based my patch on, where it clearly says that device links
are supposed to help with shutdown ordering (how?!).

So the question is, why did my DSA trees get torn down on shutdown?
Basically the short answer is that my SPI controller driver does
implement .shutdown, and calls the same code path as the .remove code,
which calls spi_unregister_controller which removes all SPI children..

When I added this device link, one of the main objectives was to not
modify all DSA drivers. I was certain based on the documentation that
device links would help, now I'm not so sure anymore.

So what happens is that the DSA master attempts to unregister its net
device on .shutdown, but DSA does not implement .shutdown, so it just
sits there holding a reference (supposedly via dev_hold, but where from?!)
to the master, which makes netdev_wait_allrefs to wait and wait.

I need more time for the denial phase to pass, and to understand what
can actually be done. I will also be away from the keyboard for the next
few days, so it might take a while. Your patches obviously offer a
solution only for KSZ switches, we need something more general. If I
understand your solution, it works not by virtue of there being any
shutdown ordering guarantee at all, but simply due to the fact that
DSA's .shutdown hook gets called eventually, and the reference to the
master gets freed eventually, which unblocks the unregister_netdevice
call from the master. I don't yet understand why DSA holds a long-term
reference to the master, that's one thing I need to figure out.

  parent reply	other threads:[~2021-09-09 15:47 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09  9:53 [PATCH 0/3] Fix for KSZ DSA switch shutdown Lino Sanfilippo
2021-09-09  9:53 ` [PATCH 1/3] net: dsa: introduce function dsa_tree_shutdown() Lino Sanfilippo
2021-09-09  9:53 ` [PATCH 2/3] net: dsa: microchip: provide the function ksz_switch_shutdown() Lino Sanfilippo
2021-09-09  9:53 ` [PATCH 3/3] net: dsa: microchip: tear down DSA tree at system shutdown Lino Sanfilippo
2021-09-09 10:14 ` [PATCH 0/3] Fix for KSZ DSA switch shutdown Vladimir Oltean
2021-09-09 11:08   ` Lino Sanfilippo
2021-09-09 11:42     ` Vladimir Oltean
2021-09-09 12:56       ` Vladimir Oltean
2021-09-09 13:19         ` Aw: " Lino Sanfilippo
2021-09-09 14:29           ` Lino Sanfilippo
2021-09-09 15:17             ` Andrew Lunn
2021-09-09 16:41               ` Lino Sanfilippo
2021-09-09 15:11           ` Andrew Lunn
2021-09-09 16:46             ` Lino Sanfilippo
2021-09-09 17:55               ` Andrew Lunn
2021-09-09 15:47           ` Vladimir Oltean [this message]
2021-09-09 16:00             ` Florian Fainelli
2021-09-10  1:32               ` Saravana Kannan
2021-09-09 16:37             ` Lino Sanfilippo
2021-09-09 16:44               ` Florian Fainelli
2021-09-09 17:07                 ` Lino Sanfilippo
2021-09-09 22:54                   ` Vladimir Oltean
2021-09-09 23:23                     ` Vladimir Oltean
2021-09-10  1:08                       ` Vladimir Oltean
2021-09-10  2:15                     ` Florian Fainelli
2021-09-10 11:51                       ` Andrew Lunn
2021-09-10 14:58                         ` Vladimir Oltean
2021-09-11 11:44                           ` Vladimir Oltean
2021-09-12 20:19                           ` Lino Sanfilippo
2021-09-12 20:29                             ` Vladimir Oltean
2021-09-13 10:32                               ` Aw: " Lino Sanfilippo
2021-09-13 10:44                                 ` Vladimir Oltean
2021-09-13 11:01                                   ` Aw: " Lino Sanfilippo
2021-09-14 18:48                                     ` Vladimir Oltean
2021-09-15  5:42                                       ` Lino Sanfilippo
2021-09-18 19:37                                         ` Lino Sanfilippo
2021-09-18 22:04                                           ` Vladimir Oltean
2021-09-19  0:29                                             ` Vladimir Oltean
2021-09-09 12:40 ` Andrew Lunn

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=20210909154734.ujfnzu6omcjuch2a@skbuf \
    --to=olteanv@gmail.com \
    --cc=LinoSanfilippo@gmx.de \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=p.rosenberger@kunbus.com \
    --cc=vivien.didelot@gmail.com \
    --cc=woojung.huh@microchip.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).