From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796445402; b=tPjxO3Z45xVxoC2HxJAJSwt1lO4JfDVmKY06N5OcI52CCdw5DvyeZC6vrWdYVryTG4nO Qtyxu9PzA0fymDjCrCpsBYJWmJLfZhn8ycRFQK9BbrS6hjKZ5UKugyEi7a8kevqAwgHs8 sWWF15m8lnY2UyCKZycGR0PPo8lxFfFES1lkalwHgu1My3fwjaJSWeIz920c8O089ai8a mfdbnvR3NYx9PTJZZOQyQGrM054ve0v3COG8/xusb7qg2iijE80tu4VUdvdOCYH9AsQL2 P8NwqvmoZWIE+9ik6VV4DH1k3AoJzjnrlxkRO9d1wBLvr/IGoO09XmiVSJ2sUsIPTlw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796445402; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=mVTpMgdO4TW/dNNcpptlRXq1PaI+OvFIx1B2eeVLtXo=; b=5Myzs/P4l/hIyLQmX2tYLQqe47aiETECo0uwnuucF9vr0VsIelXGvtj9JmXKZ5w7l8T/ uosiWA8wLXMGoVAgt5NPGkhcEwpeWa3E/+oqs0nprJhOpJ2AI3lEjH1j+PweGA7NiKlME pmzzDe+1JHFbuMqGlBM568LpfudTlz9NaaKrbgqUhEkl9n3SXJgQwu733GfoLn4ISz4vB YUxgAoRT5AGGSOgDTmNe4La52sDW+6OYdYCXNY6bdEZm93p2qm7miVr1yf23J7V+JPoBF FmxO8valdG3+FujJJ7EmntQbZEvhlir8KPyuGu0DZHXRvPf4XyfthcdG94rXXcbhY7g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GU4SuIWK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0303606A322; Sat, 5 Dec 2026 04:36:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GU4SuIWK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AC071F0092B; Sat, 5 Dec 2026 04:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796445402; bh=mVTpMgdO4TW/dNNcpptlRXq1PaI+OvFIx1B2eeVLtXo=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=GU4SuIWKcW5UKXXqKGfosU1FAawRW35sFvzV4sH993kpQnTiRhrFBywgtQjaiFrEJ dCL2ODEMmHj8IXB/PN+S0VltIuLiB0KtMNCzTUIM/WBt6ngFMsS7FCnt0PgGsqP1j3 VlyIvL5YBAjDNPK7e+3YAXvl9AF+C642SwhuDB+bu6P1D14hOgybA0YktxQd+T0nb4 grMMEJrMiRzlYr8ZQZ5F3/+m+8EDjPIfqjN5zsbJ8eL94rZrPBggZeGTGB2Zc3PpJL 44G3HQdUC5IFRsZB84RRlQx4puFdm60dFnKRSFHIlNXa0lVN8V+0xHDyRbRhKN/bbr g5nSANPNyWE+A== Subject: Re: [PATCH net-next v13 2/5] net: mana: keep HWC queues until the PF acknowledges teardown From: netdev-bot+sashiko@kernel.org To: weh@linux.microsoft.com Cc: longli@kernel.org, kotaranov@microsoft.com, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, jgg@ziepe.ca, leon@kernel.org, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, shradhagupta@linux.microsoft.com, horms@kernel.org, ernis@linux.microsoft.com, stephen@networkplumber.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, gargaditya@linux.microsoft.com, kees+treewide@kernel.org, kees@kernel.org, mawasthi@linux.microsoft.com, weh@microsoft.com, edumazet@kernel.org Date: Sat, 05 Dec 2026 04:36:40 +0000 Message-ID: <179644540052.3146.227950481764856725@kernel.org> In-Reply-To: References: X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-hyperv@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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@kernel.org > 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