Re: [PATCH net-next v13 2/5] net: mana: keep HWC queues until the PF acknowledges teardown
From: netdev-bot+sashiko
Date: Fri Dec 04 2026 - 23:36:51 EST
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] A DESTROY_HWC failure now leaves the channel retained, and
nothing retries DESTROY automatically.
- [Medium] The patch rests on the premise that the PF may keep DMAing
into the HWC rings and message buffers until it acknowledges…
- [Medium] Every DESTROY_HWC failure is treated as 'the PF may still
DMA'.
- [Low] This Fixes:-tagged patch also makes behaviour changes in the PCI
service handling that the commit message does not describe: -…
- [Low] mana_serv_reset() in
drivers/net/ethernet/microsoft/mana/gdma_pci.c now declares…
--
net: mana: keep HWC queues until the PF acknowledges teardown
If the PF does not acknowledge DESTROY_HWC, this patch keeps the HWC rings
and message buffers instead of freeing them. It retries the DESTROY before a
new channel is established on the same binding. It also reworks how cq_table
is published for EQ dispatch, serializes the shared-memory transactions, and
changes probe/resume/service recovery so that a retained channel turns off
the probe-time rescan.
Link: https://lore.kernel.org/r/179527856753.3135.1812581824985082274@xxxxxxxxxx
> diff --git a/drivers/net/ethernet/microsoft/mana/gdma_pci.c b/drivers/net/ethernet/microsoft/mana/gdma_pci.c
> index 208dadbcf977c..1cfeb69973727 100644
> --- a/drivers/net/ethernet/microsoft/mana/gdma_pci.c
> +++ b/drivers/net/ethernet/microsoft/mana/gdma_pci.c
[ ... ]
> @@ -32,49 +31,49 @@ static struct mana_dev_recovery_work {
[ ... ]
> -static void mana_serv_rescan(struct pci_dev *pdev)
> +enum mana_rescan_reason {
> + MANA_RESCAN_PROBE,
> + MANA_RESCAN_RESET,
> + MANA_RESCAN_FPGA,
> +};
> +
> +static void mana_serv_rescan(struct pci_dev *pdev,
> + enum mana_rescan_reason reason)
> {
> + struct pci_dev *target = pdev;
> struct pci_bus *parent;
> + bool rescan;
>
[ ... ]
> + /* Filter stale work. A separate bind can still race PCI removal. */
> + device_lock(&pdev->dev);
> + if (reason == MANA_RESCAN_PROBE)
> + rescan = !pdev->dev.driver;
> + else
> + rescan = pdev->driver == &mana_driver;
> + device_unlock(&pdev->dev);
> + if (!rescan)
> + return;
>
> pci_lock_rescan_remove();
[ ... ]
> - parent = bus->parent;
> - if (!parent) {
> + if (reason == MANA_RESCAN_FPGA)
> + target = pci_upstream_bridge(pdev);
> + if (!target || !target->bus) {
> dev_err(&pdev->dev, "MANA service: no parent bus\n");
> goto out;
> }
>
> - pci_stop_and_remove_bus_device(bus->self);
> + parent = target->bus;
> + pci_stop_and_remove_bus_device(target);
[Severity: Low]
The commit message does not seem to describe several behaviour changes in
this patch. Because of the Fixes: tag, a stable backport would pull them in
without any explanation:
- mana_serv_fpga() is folded into mana_serv_rescan(). FPGA reconfig
recovery used to run unconditionally. It now runs only when
pdev->driver == &mana_driver.
- The bridge to remove now comes from pci_upstream_bridge(pdev), which goes
through pci_physfn(), instead of bus->self with bus->parent as the rescan
target.
- mana_serv_reset() now holds the device lock across suspend, the 10 second
msleep(), and resume.
- mana_gd_destroy_eq() in gdma_main.c becomes idempotent for every EQ, not
only the HWC one:
if (queue->eq.msix_index == INVALID_PCI_MSIX_INDEX)
return;
...
mana_gd_deregister_irq(queue);
queue->eq.msix_index = INVALID_PCI_MSIX_INDEX;
Could these changes be split out, or at least described in the commit
message?
> @@ -82,19 +81,18 @@ static void mana_serv_fpga(struct pci_dev *pdev)
[ ... ]
> -static void mana_serv_reset(struct pci_dev *pdev)
> +/* Return true if recovery needs to escalate to PCI re-enumeration. */
> +static bool mana_serv_reset(struct pci_dev *pdev)
> {
[ ... ]
> + guard(device)(&pdev->dev);
> + if (pdev->driver != &mana_driver)
> + return false;
>
> + gc = pci_get_drvdata(pdev);
> hwc = gc->hwc.driver_data;
> if (!hwc) {
> dev_err(&pdev->dev, "MANA service: no HWC\n");
[ ... ]
> @@ -125,17 +122,19 @@ static void mana_serv_reset(struct pci_dev *pdev)
>
> out:
> clear_bit(GC_IN_SERVICE, &gc->flags);
> + return false;
> }
[Severity: Low]
mana_serv_reset() now uses guard(device)(&pdev->dev) together with the
existing "goto out" and its clear_bit() label. include/linux/cleanup.h says
goto and the scope-based cleanup helpers should not be mixed in the same
function.
The function behaves correctly today, because the goto stays inside the
guard's scope. Could the "no HWC" path call clear_bit() and return false
directly instead, or use scoped_guard()?
> @@ -632,8 +631,16 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> xa_destroy(&gc->irq_contexts);
> pci_iounmap(pdev, bar0_va);
> free_gc:
> + /* No binding remains to retry DESTROY. Do not start another probe
> + * which could abandon another set of coherent allocations.
> + */
> + if (gc->hwc.driver_data) {
> + dev_err(&pdev->dev,
> + "HWC teardown failed, disabling probe recovery\n");
> + err = -ENOTRECOVERABLE;
> + }
> pci_set_drvdata(pdev, NULL);
> - vfree(gc);
> + mana_gd_free_context(gc);
[ ... ]
> @@ -714,7 +720,7 @@ static int mana_gd_resume(struct pci_dev *pdev)
>
> err = mana_gd_setup(gc);
> if (err)
> - return err;
> + goto check_hwc;
[ ... ]
> @@ -728,6 +734,10 @@ static int mana_gd_resume(struct pci_dev *pdev)
>
> cleanup_gd:
> mana_gd_cleanup(gc);
> +check_hwc:
> + /* Keep the binding and DMA handles for a later DESTROY retry. */
> + if (gc->hwc.driver_data)
> + return -ENOTRECOVERABLE;
> return err;
> }
[Severity: Medium]
After DESTROY_HWC fails, does anything ever retry it automatically?
This is the reset-service path:
mana_serv_reset()
mana_gd_suspend()
mana_gd_cleanup()
mana_hwc_destroy_channel()
mana_smc_teardown_hwc() fails, channel is retained
msleep(MANA_SERVICE_PERIOD * 1000)
mana_gd_resume()
mana_gd_setup()
mana_hwc_create_channel()
mana_hwc_destroy_channel() fails again, returns -ETIMEDOUT
check_hwc: returns -ENOTRECOVERABLE
mana_serv_reset() only escalates on these two codes:
ret = mana_gd_resume(pdev);
if (ret == -ETIMEDOUT || ret == -EPROTO) {
So it logs a message and stops. By then the error path in mana_gd_setup()
has already removed the IRQs and the service workqueue, so no further
RESET_REQUEST can arrive. Does that leave the VF bound with a dead NIC
until someone unbinds and rebinds it by hand?
The probe path ends the same way. The free_gc block above rewrites err to
-ENOTRECOVERABLE, so the delayed recovery rescan further down is never
queued. Its comment says it exists for exactly this case: "Hardware could be
in recovery mode and the HWC returns TIMEDOUT or EPROTO".
The channel can also stay retained when the PF mappings are probably gone:
- mana_smc_setup_hwc_locked() sets *submitted = true before the MMIO
writes. It never clears it, even when the PF sends a well-formed NAK
(hdr.status != 0, which gives -EPROTO).
- mana_smc_teardown_hwc_locked() polls with
mana_smc_poll_register(sc->base, false). A device that is in reset or has
been removed reads all-ones, which looks like PF ownership, so the poll
times out after about 20-40 seconds.
- Only a DESTROY response with status 0 clears setup_active. Recovery
therefore depends on the PF acknowledging DESTROY_HWC for an HWC it has
already destroyed or never installed.
The commit message does describe part of this trade-off ("If resume cannot
tear down its retained channel, leave it bound rather than escalating to
PCI removal"). Could the code tell a definitive NAK or an all-ones aperture
apart from a PF that is just slow, or schedule a later DESTROY retry?
Currently it treats all of these as "the PF may still DMA".
> diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> index 130b249318f20..39a0ed32e43c7 100644
> --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
> +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
[ ... ]
> @@ -827,25 +918,45 @@ int mana_hwc_create_channel(struct gdma_context *gc)
[ ... ]
> void mana_hwc_destroy_channel(struct gdma_context *gc)
> {
[ ... ]
> + err = mana_smc_teardown_hwc(&gc->shm_channel, false,
> + &hwc->setup_active);
> + if (err) {
> + dev_err(hwc->dev,
> + "HWC teardown failed: %d, retaining PF-visible resources\n",
> + err);
> + mana_hwc_fence_channel(gc, hwc);
> + return;
> }
[Severity: Medium]
What happens on the shutdown/kexec path when this branch is taken?
mana_gd_shutdown()
mana_rdma_remove()
mana_remove(&gc->mana, true)
mana_gd_cleanup()
mana_hwc_destroy_channel()
mana_smc_teardown_hwc() fails
mana_hwc_fence_channel(); return;
pci_disable_device()
The next kernel then treats the HWC rings and message buffers as free
memory. This patch assumes the PF may keep using them until it acknowledges
DESTROY_HWC. By that reasoning, couldn't the PF write into memory the
kexec'd kernel has already reused?
The commit message covers final PCI or CDX detach and resume, but not
shutdown. Does this path need an FLR through the existing bus_ops dev_reset,
or a DESTROY with reset_vf set, before memory is handed over?
> @@ -871,9 +979,44 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)
[ ... ]
> +/* Final disposal after IRQ and service-work teardown, not a retry path.
> + * Free only software state: unacknowledged HWC DMA allocations stay live.
> + */
> +void mana_hwc_free_retained_channel(struct gdma_context *gc)
> +{
[ ... ]
> + if (hwc->cq) {
> + kfree(hwc->cq->gdma_eq);
> + kfree(hwc->cq->gdma_cq);
> + kfree(hwc->cq->comp_buf);
> + kfree(hwc->cq);
> + }
> +
> + mana_hwc_free_retained_wq(hwc->txq);
> + mana_hwc_free_retained_wq(hwc->rxq);
[Severity: Medium]
Does this leak the coherent DMA memory for the HWC EQ, CQ, RQ and SQ rings
and for both message buffers? Only the software structs are kfree()d.
mana_gd_free_memory() and mana_hwc_dealloc_dma_buf() are never called, so
the DMA allocations become unreachable.
mana_hwc_destroy_channel() treats every teardown error as "the PF may still
DMA", even when the device is gone. On a surprise removal or VF revocation,
MMIO reads return 0xFFFFFFFF, and mana_smc_poll_register(sc->base, false)
times out:
mana_gd_remove()
mana_gd_cleanup()
mana_hwc_destroy_channel()
mana_smc_teardown_hwc() times out polling
fences and returns
mana_gd_free_context()
mana_hwc_free_retained_channel() frees only software state
A removed device cannot DMA. Nothing checks pci_dev_is_disconnected(),
pci_channel_offline() or an all-ones read before the channel is retained.
Each hot-remove cycle leaks another bundle, and so does each failed probe
whose DESTROY fails. Before this patch, mana_hwc_destroy_channel() always
freed the DMA memory, whatever the teardown result.
Could the disconnected case be detected so this memory is freed normally?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/hwc-v13.ab4ca86c3bf24a51ad8a84cc8a0220d1.0%40linux.microsoft.com