Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
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, shacharr@microsoft.com
Subject: Re: [PATCH net-next v12 2/5] net: mana: keep HWC queues until the PF acknowledges teardown
Date: Sat, 28 Nov 2026 16:39:48 +0000	[thread overview]
Message-ID: <179588398847.3135.906138429587218178@kernel.org> (raw)
In-Reply-To: <hwc-v12.91ec3eff9cb647d5bc5cc932b3c6f60c.2@linux.microsoft.com>

Thank you for your contribution! Sashiko AI review found 8 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 5 · Low: 3

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] After this patch, a DESTROY_HWC that the PF does not
  acknowledge leaves the NIC bound but permanently dead, and nothing in…
- [Medium] The unbound-sibling veto on the FPGA path of
  mana_serv_rescan() is too broad.
- [Medium] On the FPGA path, mana_serv_rescan() now calls
  pci_walk_bus(target->subordinate, mana_check_unbound, ...) while…
- [Medium] The unbound-sibling check in mana_serv_rescan() is not atomic
  with the bridge removal it is meant to guard.
- [Medium] The patch treats every failed DESTROY_HWC as "the PF may still
  DMA into these buffers", even when the function is gone.
- [Low] The commit message does not describe several user-visible changes
  to PCI service and recovery in gdma_pci.c and gdma_main.c: -…
- [Low] The comment on the new prototype in include/net/mana/gdma.h says
  mana_gd_fence_eq() "Remove[s] an EQ from interrupt dispatch without…
- [Low] Two new functions mix scope-based cleanup with goto-based cleanup
  labels, which include/linux/cleanup.h and the subsystem guide say not…

--

net: mana: keep HWC queues until the PF acknowledges teardown

This patch serializes HWC setup and teardown over the shared memory
channel. When DESTROY_HWC fails, it fences the HWC EQ and keeps the queues
and their DMA memory instead of freeing them. It also changes how the
cq_table is published and torn down, and changes PCI probe, resume and
service recovery so that a function with a retained HWC is not probed
again.

> A failed PCI probe has no context left to retry the destroy. Do not
> start another automatic probe that could lose another set of coherent
> allocations. A failed resume can keep the binding and retry in place.

[Severity: Low]
The changelog doesn't mention several behaviour changes in gdma_pci.c and
gdma_main.c:

- mana_serv_fpga() is folded into mana_serv_rescan(). FPGA-reconfig
  recovery is now skipped entirely when any MANA-ID function under the
  upstream bridge has no driver bound.

- The new global mana_rescan_task lets mana_gd_remove() veto the
  pci_rescan_bus() that follows removal. When the veto fires, the removed
  device is never re-enumerated. On the FPGA path that is the whole bridge
  subtree.

- Both service paths now take the device lock.

- mana_gd_process_eqe() drops the WARN_ON_ONCE() checks for an
  out-of-range cq_id and for a NULL cq. This applies to every CQ, not only
  the HWC, so those EQEs are now silently discarded.

Could the changelog describe these as well?

> diff --git a/drivers/net/ethernet/microsoft/mana/gdma_pci.c b/drivers/net/ethernet/microsoft/mana/gdma_pci.c
> index 208dadbcf977c..cec2e548f36ea 100644
> --- a/drivers/net/ethernet/microsoft/mana/gdma_pci.c
> +++ b/drivers/net/ethernet/microsoft/mana/gdma_pci.c

[ ... ]

> +static int mana_check_unbound(struct pci_dev *pdev, void *data)
> +{
> +	bool *unbound = data;
>  
> -	pci_stop_and_remove_bus_device(pdev);
> -	pci_rescan_bus(parent);
> +	if (READ_ONCE(pdev->driver) ||
> +	    !pci_match_id(mana_driver.id_table, pdev))
> +		return 0;

[Severity: Medium]
Is this check atomic with the bridge removal it guards?
mana_check_unbound() reads each sibling's pdev->driver while holding only
pci_rescan_remove_lock and the serviced device's device lock. It does not
hold the sibling's device lock.

local_pci_probe() sets pdev->driver before calling ->probe() and clears it
if the probe fails:

drivers/pci/pci-driver.c:local_pci_probe() {
    ...
	pci_dev->driver = pci_drv;
	rc = pci_drv->probe(pci_dev, ddi->id);
    ...
}

Sysfs bind and async probing don't take pci_rescan_remove_lock. So a
sibling that is still inside mana_gd_probe() looks bound to this walk.

Suppose that probe then fails with a retained HWC and returns
-ENOTRECOVERABLE. The sibling ends up unbound. When
pci_stop_and_remove_bus_device(target) reaches it, there is no driver, so
no ->remove() runs to clear mana_rescan_task. pci_rescan_bus() then
probes the sibling again.

Doesn't that start the extra automatic probe that the commit message says
must be avoided? That probe could abandon another set of HWC coherent
allocations.

[ ... ]

> -static void mana_serv_fpga(struct pci_dev *pdev)
> +static void mana_serv_rescan(struct pci_dev *pdev,
> +			     enum mana_rescan_reason reason)
>  {
> -	struct pci_bus *bus, *parent;
> +	struct pci_dev *target = pdev;
> +	struct pci_bus *parent;
> +	bool unbound = false;
>  
>  	pci_lock_rescan_remove();
> -
> -	bus = pdev->bus;
> -	if (!bus) {
> -		dev_err(&pdev->dev, "MANA service: no bus\n");
> +	if (!device_is_registered(&pdev->dev))
>  		goto out;
> +
> +	scoped_guard(device, &pdev->dev) {
> +		if (reason == MANA_RESCAN_PROBE) {
> +			if (pdev->dev.driver)
> +				goto out;

[Severity: Low]
This isn't a bug, but this function and mana_serv_reset() both mix
guard()/scoped_guard() with goto-based cleanup labels.
include/linux/cleanup.h asks to avoid that.

Here pci_lock_rescan_remove() is taken by hand and the device lock is a
scoped_guard. Three goto out exits leave the guard to reach
pci_unlock_rescan_remove() at the label.

In mana_serv_reset(), guard(device) is at function scope. Its out label
runs clear_bit(GC_IN_SERVICE, &gc->flags), and the early return false and
return true exits skip that label.

Would it be clearer to convert each function to a single style? That would
make it obvious which exits unlock and which clear GC_IN_SERVICE.

> +		} else if (pdev->driver != &mana_driver) {
> +			goto out;
> +		} else if (reason == MANA_RESCAN_FPGA) {
> +			struct gdma_context *gc = pci_get_drvdata(pdev);
> +
> +			/* An unbound sibling cannot veto the bridge rescan in
> +			 * ->remove(). Its last probe may have lost HWC DMA.
> +			 */
> +			target = pci_upstream_bridge(pdev);
> +			if (target)
> +				pci_walk_bus(target->subordinate,
> +					     mana_check_unbound, &unbound);

[Severity: Medium]
Can this deadlock against PCIe error recovery? pci_walk_bus() takes
down_read(&pci_bus_sem) while scoped_guard(device, &pdev->dev) holds the
MANA device lock.

AER recovery takes the two locks in the opposite order:

pcie_do_recovery()
  pci_walk_bridge()
    pci_walk_bus()                <- pci_bus_sem held for read
      report_frozen_detected()
        report_error_detected()
          device_lock(&dev->dev)

rwsem readers queue behind a waiting writer. Some pci_bus_sem writers
don't take pci_rescan_remove_lock. One example is
pci_register_host_bridge(), reached through pci_scan_root_bus_bridge()
from create_root_hv_pci_bus() in pci-hyperv.c.

With such a writer queued:

AER thread:   holds pci_bus_sem (read), waits for the MANA device lock
writer:       waits in down_write(&pci_bus_sem) for the AER reader
MANA service: holds the device lock, waits in down_read() behind writer

Lockdep won't report this, because device mutexes are novalidate. The old
code never held a device lock across a bus walk.

pci_rescan_remove_lock is already held at this point. Could the walk be
done outside the device lock?

> +			if (unbound) {
> +				dev_err(&pdev->dev,
> +					"Unbound MANA function, skipping bridge rescan\n");
> +				clear_bit(GC_IN_SERVICE, &gc->flags);
> +				goto out;
> +			}

[Severity: Medium]
Is this veto broader than intended? mana_check_unbound() flags any MANA-ID
function under the upstream bridge that has no driver. It can't tell a
function whose probe lost HWC DMA from one that is unbound for other
reasons, for example:

- an administrator unbound it through sysfs
- SR-IOV VFs that weren't autoprobed, or whose probe failed
- a sibling whose probe failed with -ENOMEM or a DMA mask error
- a sibling that failed with -ETIMEDOUT or -EPROTO and is waiting for the
  delayed recovery re-probe

pci_walk_bus() also descends into VF virtual buses, so PF hosts with
unbound VFs can hit this.

In each of these cases, a GDMA_EQE_HWC_FPGA_RECONFIG event on a bound
function now logs, clears GC_IN_SERVICE and returns. mana_serv_fpga()
always did the bridge remove, sleep and rescan here.

Doesn't that leave the bound function with stale hardware state after the
FPGA reconfiguration, with nothing retrying recovery?

> +		}
>  	}
>  
> -	parent = bus->parent;
> -	if (!parent) {
> +	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;
> +	WRITE_ONCE(mana_rescan_task, current);
> +	pci_stop_and_remove_bus_device(target);
> +	if (!READ_ONCE(mana_rescan_task))
> +		goto out;
> +	WRITE_ONCE(mana_rescan_task, NULL);

[ ... ]

> @@ -682,11 +723,16 @@ static void mana_gd_remove(struct pci_dev *pdev)
>  
>  	mana_gd_cleanup(gc);
>  
> +	if (gc->hwc.driver_data && READ_ONCE(mana_rescan_task) == current) {
> +		dev_err(gc->dev, "HWC teardown failed, skipping PCI rescan\n");
> +		WRITE_ONCE(mana_rescan_task, NULL);
> +	}
> +
>  	xa_destroy(&gc->irq_contexts);
>  
>  	pci_iounmap(pdev, gc->bar0_va);
>  
> -	vfree(gc);
> +	mana_gd_free_context(gc);

[Severity: Medium]
What happens here when the function has been surprise removed, or is
otherwise unreachable?

Every SMC read returns 0xFFFFFFFF, and mana_smc_teardown_hwc() is called
with reset_vf=false. mana_smc_poll_register() therefore spins for the
whole poll window (20-40 seconds) before DESTROY fails.

mana_gd_free_context() then calls mana_hwc_free_retained_channel(), which
only frees the software wrappers:

mana_hwc_free_retained_wq() {
	...
	kfree(wq->msg_buf);
	kfree(wq->gdma_wq);
	kfree(wq);
}

Doesn't that permanently leak the coherent DMA allocations for the
EQ/CQ/RQ/SQ rings and the message buffers? A disconnected device can't
DMA into them, but nothing checks pci_dev_is_disconnected() or
pci_channel_offline() before deciding to keep them.

On the FPGA_RECONFIG path, the same failure clears mana_rescan_task here.
mana_serv_rescan() then takes this exit:

	if (!READ_ONCE(mana_rescan_task))
		goto out;

That skips both the reconfiguration wait and pci_rescan_bus(). Would the
reconfigured function, and every sibling under the removed bridge, then
stay gone until a manual rescan or a reboot?

[ ... ]

> @@ -728,6 +774,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]
Is anything left to do the "retry in place"?

Only a successful DESTROY response clears hwc->setup_active. Teardown
passes reset_vf=false, so during a reset an all-ones aperture is treated
as PF ownership until mana_smc_poll_register() times out.

For a GDMA_EQE_HWC_RESET_REQUEST where DESTROY is not acknowledged:

mana_serv_reset()
  mana_gd_suspend()
    mana_gd_cleanup()
      mana_hwc_destroy_channel()   <- fails, fences HWC EQ, keeps hwc
  msleep(10 s)
  mana_gd_resume()
    mana_gd_setup()
      mana_hwc_create_channel()
        mana_hwc_destroy_channel() <- single retry fails, -ETIMEDOUT
      gc->bus_ops->remove_irqs()
    check_hwc: return -ENOTRECOVERABLE

mana_serv_reset() only escalates on these errors:

	if (ret == -ETIMEDOUT || ret == -EPROTO) {

so it just logs and clears GC_IN_SERVICE. Before this patch, this path
went on to mana_serv_rescan() and re-enumerated the function.

No IRQs are registered now, so no later RESET_REQUEST or FPGA_RECONFIG
event can arrive. No work item or timer retries DESTROY either. Does the
NIC then stay bound but dead until a PM cycle, a manual unbind or a
reboot?

The probe path is similar. The free_gc label in mana_gd_probe() turns
-ETIMEDOUT/-EPROTO into -ENOTRECOVERABLE. So the delayed recovery work,
which the comment below reserves for the case where "Hardware could be in
recovery mode", is never scheduled.

[ ... ]

> diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h
> index bde68d6a99f01..2da086a3b8f72 100644
> --- a/include/net/mana/gdma.h
> +++ b/include/net/mana/gdma.h
> @@ -600,6 +600,9 @@ int mana_gd_create_mana_wq_cq(struct gdma_dev *gd,
>  
>  void mana_gd_destroy_queue(struct gdma_context *gc, struct gdma_queue *queue);
>  
> +/* Remove an EQ from interrupt dispatch without freeing its queue memory. */
> +void mana_gd_fence_eq(struct gdma_context *gc, struct gdma_queue *queue);

[Severity: Low]
This doesn't break anything today, but does the comment match what
mana_gd_fence_eq() does? The function is just
mana_gd_destroy_eq(gc, false, queue), and that does more than remove the
EQ from dispatch:

- It sets queue->eq.msix_index to INVALID_PCI_MSIX_INDEX. A later
  mana_gd_destroy_queue() on the same EQ then returns early.

- It calls mana_gd_disable_queue() when queue->eq.disable_needed is set.

disable_needed is true for every EQ created through
mana_gd_create_hw_eq(), which covers all the data-path EQs. Both current
callers pass HWC EQs, where disable_needed is false, so the mismatch is
latent for now. A future caller that relies on the comment would disable
the hardware EQ without meaning to.

Could the comment say what the helper actually does?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/hwc-v12.91ec3eff9cb647d5bc5cc932b3c6f60c.0%40linux.microsoft.com

  reply	other threads:[~2026-11-28 16:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 15:40 [PATCH net-next v12 0/5] net: mana: concurrent HWC requests Wei Hu
2026-11-24 15:40 ` [PATCH net-next v12 1/5] net: mana: validate the HWC doorbell before ringing it Wei Hu
2026-11-24 15:40 ` [PATCH net-next v12 2/5] net: mana: keep HWC queues until the PF acknowledges teardown Wei Hu
2026-11-28 16:39   ` netdev-bot+sashiko [this message]
2026-11-24 15:40 ` [PATCH net-next v12 3/5] net: mana: protect the HWC response buffer until the sender returns Wei Hu
2026-11-24 15:40 ` [PATCH net-next v12 4/5] net: mana: support concurrent HWC requests Wei Hu
2026-11-28 16:39   ` netdev-bot+sashiko
2026-11-24 15:40 ` [PATCH net-next v12 5/5] net: mana: use the reported HWC queue depth Wei Hu
2026-11-28 16:39   ` netdev-bot+sashiko
2026-11-24 15:44 ` [PATCH net-next v12 0/5] net: mana: concurrent HWC requests netdev-bot+sinfo
2026-11-25  3:13   ` [EXTERNAL] " Wei Hu
2026-11-24 16:00 ` sashiko-bot

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=179588398847.3135.906138429587218178@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=edumazet@google.com \
    --cc=edumazet@kernel.org \
    --cc=ernis@linux.microsoft.com \
    --cc=gargaditya@linux.microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=horms@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=kees+treewide@kernel.org \
    --cc=kees@kernel.org \
    --cc=kotaranov@microsoft.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=longli@kernel.org \
    --cc=mawasthi@linux.microsoft.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shacharr@microsoft.com \
    --cc=shradhagupta@linux.microsoft.com \
    --cc=stephen@networkplumber.org \
    --cc=weh@linux.microsoft.com \
    --cc=weh@microsoft.com \
    --cc=wei.liu@kernel.org \
    /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