All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: wei.fang@oss.nxp.com
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH v5 net-next 4/9] net: dsa: netc: tie setup resources and reset to DSA setup/teardown
Date: Tue, 13 Oct 2026 09:59:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-169415@kernel.org> (raw)
In-Reply-To: <20261012095924.1129312-5-wei.fang@oss.nxp.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] dsa: AB-BA deadlock between dsa2_mutex and pci device_lock during switch setup/teardown
- [High] netc: race condition in netc_switch_reset() leading to unheld PCI device lock
--

commit f362c9d18af3d66bf5d5401a43abc544295b1901
Author: Wei Fang <wei.fang@nxp.com>
Subject: net: dsa: netc: tie setup resources and reset to DSA setup/teardown

This commit modifies the NETC switch driver to explicitly allocate and free
resources during DSA setup and teardown, instead of relying on devm allocations
during PCI probe. It also adds a PCI reset into netc_setup() to ensure a
clean hardware state when starting up.

> diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
> --- a/drivers/net/dsa/netc/netc_main.c
> +++ b/drivers/net/dsa/netc/netc_main.c

[ ... ]

> +static int netc_switch_reset(struct netc_switch *priv)
> +{
> +	if (priv->in_probe)
> +		return pci_reset_function_locked(priv->pdev);

[Severity: High]
Can a concurrent thread execute this path without holding the PCI device
lock?

In a multi-switch DSA tree, priv->in_probe is set to true during
netc_switch_probe(). The thread then calls dsa_register_switch(), which
internally acquires and releases dsa2_mutex. If the DSA tree is incomplete,
it returns, and the thread can be preempted before executing
priv->in_probe = false.

Concurrently, a second thread could probe the second switch, complete the
tree, acquire dsa2_mutex, and call dsa_tree_setup_switches(). This invokes
netc_setup() for the first switch. Observing priv->in_probe == true, the
second thread would call pci_reset_function_locked() on the first switch's
PCI device, despite not holding its device lock.

> +
> +	return pci_reset_function(priv->pdev);

[Severity: High]
Does this introduce an AB-BA deadlock between the PCI device lock and
dsa2_mutex?

When a multi-switch DSA tree is set up, netc_setup() can be called for an
already-probed switch. In this case, priv->in_probe is false, and
netc_switch_reset() calls pci_reset_function(), which acquires the PCI
device lock. However, netc_setup() is invoked by the DSA core with the
global dsa2_mutex held.

Conversely, when a switch is unbound (e.g. via sysfs), the driver core first
acquires the switch's device lock and then calls the driver's remove
callback. The netc_switch_remove() function calls dsa_unregister_switch(),
which attempts to acquire dsa2_mutex:

net/dsa/dsa.c:dsa_unregister_switch() {
    ...
    mutex_lock(&dsa2_mutex);
    dsa_switch_remove(ds);
    mutex_unlock(&dsa2_mutex);
    ...
}

If Thread 1 is unbinding Switch A (holding the device lock for A and waiting
for dsa2_mutex) while Thread 2 is probing Switch B (holding dsa2_mutex and
calling pci_reset_function(A) inside netc_setup(A)), the system could
deadlock.

> +}

[ ... ]

> @@ -2475,12 +2565,15 @@ static int netc_switch_probe(struct pci_dev *pdev,
>  	ds->ageing_time_max = U32_MAX;
>  	ds->priv = priv;
>  	priv->ds = ds;
> +	priv->in_probe = true;
>  
>  	err = dsa_register_switch(ds);
>  	if (err)
>  		return dev_err_probe(dev, err,
>  				     "Failed to register DSA switch\n");
>  
> +	priv->in_probe = false;
> +
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012095924.1129312-1-wei.fang@oss.nxp.com?part=4

  reply	other threads:[~2026-10-13  9:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12  9:59 [PATCH v5 net-next 0/9] net: dsa: netc: add PTP support for NETC switch wei.fang
2026-10-12  9:59 ` [PATCH v5 net-next 1/9] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access wei.fang
2026-10-12  9:59 ` [PATCH v5 net-next 2/9] ptp: netc: remove unnecessary pcie_flr() call in probe wei.fang
2026-10-12  9:59 ` [PATCH v5 net-next 3/9] ptp: netc: export netc_timer_get_current_time() for cross-driver use wei.fang
2026-10-12  9:59 ` [PATCH v5 net-next 4/9] net: dsa: netc: tie setup resources and reset to DSA setup/teardown wei.fang
2026-10-13  9:59   ` sashiko-bot [this message]
2026-10-13 10:57   ` netdev-bot+sashiko
2026-10-12  9:59 ` [PATCH v5 net-next 5/9] net: dsa: netc: use entry ID instead of pointer to track host flood rule wei.fang
2026-10-13  9:59   ` sashiko-bot
2026-10-12  9:59 ` [PATCH v5 net-next 6/9] net: dsa: netc: check return value of ntmp_ipft_delete_entry() wei.fang
2026-10-13 10:57   ` netdev-bot+sashiko
2026-10-12  9:59 ` [PATCH v5 net-next 7/9] net: dsa: netc: enable ingress port filtering lookup by default wei.fang
2026-10-12  9:59 ` [PATCH v5 net-next 8/9] net: dsa: netc: add PTP two-step timestamping support wei.fang
2026-10-13  9:59   ` sashiko-bot
2026-10-13 10:57   ` netdev-bot+sashiko
2026-10-12  9:59 ` [PATCH v5 net-next 9/9] net: dsa: netc: add PTP one-step " wei.fang
2026-10-13  9:59   ` sashiko-bot
2026-10-13 10:57   ` netdev-bot+sashiko

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=sashiko-outbox-169415@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wei.fang@oss.nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.