BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Machon" <daniel.machon@microchip.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v3 05/13] net: lan966x: export FDMA helpers for reuse
Date: Tue, 05 May 2026 18:22:56 +0000	[thread overview]
Message-ID: <20260505182256.A54BCC2BCB4@smtp.kernel.org> (raw)
In-Reply-To: <20260504-lan966x-pci-fdma-v3-5-a56f5740d870@microchip.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Data race and Use-After-Free during driver teardown due to lockless state modification and incorrect ordering
- [High] Unsafe DMA teardown due to ignored timeout in lan966x_fdma_tx_disable() and lan966x_fdma_rx_disable()
--

commit d9b72843e1c15f3261008784be970a31341a866d
Author: Daniel Machon <daniel.machon@microchip.com>

net: lan966x: export FDMA helpers for reuse

Make shared FDMA helpers non-static, so they can be reused by the PCIe
FDMA implementation.

> diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> index 6c5761e886d47..25e673bdf0841 100644
> --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
[ ... ]
> @@ -171,7 +171,7 @@ static void lan966x_fdma_rx_start(struct lan966x_rx *rx)
>  		lan966x, FDMA_CH_ACTIVATE);
>  }
>  
> -static void lan966x_fdma_rx_disable(struct lan966x_rx *rx)
> +void lan966x_fdma_rx_disable(struct lan966x_rx *rx)
>  {
>  	struct lan966x *lan966x = rx->lan966x;
>  	struct fdma *fdma = &rx->fdma;

This isn't a bug introduced in this patch, but exporting this function
exposes an existing issue.

Does this code handle hardware timeouts safely? Looking at the implementation
of lan966x_fdma_rx_disable(), the return value of readx_poll_timeout_atomic()
is ignored:

    readx_poll_timeout_atomic(lan966x_fdma_channel_active, lan966x,
                              val, !(val & BIT(fdma->channel_id)),
                              READL_SLEEP_US, READL_TIMEOUT_US);

If the hardware is unresponsive and the poll times out, the driver might
falsely assume the channel is halted and proceed to alter hardware state.

If the caller later frees the coherent DMA rings while the DMA engine is
still active, could this lead to memory corruption or IOMMU faults?

[ ... ]
> @@ -265,7 +265,7 @@ static void lan966x_fdma_tx_activate(struct lan966x_tx *tx)
>  		lan966x, FDMA_CH_ACTIVATE);
>  }
>  
> -static void lan966x_fdma_tx_disable(struct lan966x_tx *tx)
> +void lan966x_fdma_tx_disable(struct lan966x_tx *tx)
>  {
>  	struct lan966x *lan966x = tx->lan966x;
>  	struct fdma *fdma = &tx->fdma;

This is another pre-existing issue exposed by exporting these helpers.

The same ignored timeout issue from readx_poll_timeout_atomic() exists
here in lan966x_fdma_tx_disable().

Additionally, is it safe to modify tx->activated without holding the
lan966x->tx_lock?

Looking at the driver teardown path, lan966x_remove() appears to call
lan966x->ops->fdma_deinit() (which calls lan966x_fdma_tx_disable() and frees
the DMA rings) before lan966x_cleanup_ports() unregisters the netdev.

If the network interface is up and actively transmitting during module
removal, could the networking stack concurrently call lan966x_port_xmit(),
acquire tx_lock, and write to tx->fdma.dcbs while it is being freed,
resulting in a use-after-free?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260504-lan966x-pci-fdma-v3-0-a56f5740d870@microchip.com?part=5

  reply	other threads:[~2026-05-05 18:22 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04 14:23 [PATCH net-next v3 00/13] net: lan966x: add support for PCIe FDMA Daniel Machon
2026-05-04 14:23 ` [PATCH net-next v3 01/13] MAINTAINERS: add FDMA library to Sparx5 SoC entry Daniel Machon
2026-05-04 14:23 ` [PATCH net-next v3 02/13] net: microchip: fdma: rename contiguous dataptr helpers Daniel Machon
2026-05-04 14:23 ` [PATCH net-next v3 03/13] net: microchip: fdma: add PCIe ATU support Daniel Machon
2026-05-05 18:22   ` sashiko-bot
2026-05-04 14:23 ` [PATCH net-next v3 04/13] net: lan966x: add FDMA LLP register write helper Daniel Machon
2026-05-05 18:22   ` sashiko-bot
2026-05-04 14:23 ` [PATCH net-next v3 05/13] net: lan966x: export FDMA helpers for reuse Daniel Machon
2026-05-05 18:22   ` sashiko-bot [this message]
2026-05-04 14:23 ` [PATCH net-next v3 06/13] net: lan966x: add FDMA ops dispatch for PCIe support Daniel Machon
2026-05-05 18:22   ` sashiko-bot
2026-05-04 14:23 ` [PATCH net-next v3 07/13] net: lan966x: clear FDMA interrupt stickies after switch reset Daniel Machon
2026-05-04 14:23 ` [PATCH net-next v3 08/13] net: lan966x: add shutdown callback to stop FDMA on reboot Daniel Machon
2026-05-05 18:22   ` sashiko-bot
2026-05-04 14:23 ` [PATCH net-next v3 09/13] net: lan966x: add PCIe FDMA support Daniel Machon
2026-05-05 18:22   ` sashiko-bot
2026-05-07  8:54   ` Paolo Abeni
2026-05-07  9:21     ` Daniel Machon
2026-05-04 14:23 ` [PATCH net-next v3 10/13] net: lan966x: add PCIe FDMA MTU change support Daniel Machon
2026-05-05 18:22   ` sashiko-bot
2026-05-04 14:23 ` [PATCH net-next v3 11/13] net: lan966x: add PCIe FDMA XDP support Daniel Machon
2026-05-05 18:22   ` sashiko-bot
2026-05-04 14:23 ` [PATCH net-next v3 12/13] misc: lan966x-pci: dts: extend cpu reg to cover PCIE DBI space Daniel Machon
2026-05-04 14:23 ` [PATCH net-next v3 13/13] misc: lan966x-pci: dts: add fdma interrupt to overlay Daniel Machon

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=20260505182256.A54BCC2BCB4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel.machon@microchip.com \
    --cc=sashiko@lists.linux.dev \
    /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