Skip to contentSkip to conversation

net: mana: concurrent HWC requests and dynamic queue depth

PATCH In review Wei Hu 5 participants 21 messages Nov 17 – Nov 23

Subsystems (5)
lore
Share & tools
lore

Wei Hu

author
#0 lore raw

v11 cover net: mana: concurrent HWC requests and dynamic queue depth

This is v11 of Long Li's four-patch HWC series. I am carrying the series forward with review fixes and integration work. Original authorship and sign-offs are retained.

The series supports concurrent requests over the MANA hardware channel and rebuilds its queues using the queue depth and message sizes required by the PF. It prepares ownership and teardown, gives each message its own completion, adds concurrent request tracking, and enables dynamic sizing.

Changes since v10:
- Rebase onto current net-next, including Erni Sri Satya Vennela's 6964ff21c5d8 ("net: mana: Allocate queue MSI-X vectors on demand"). Preserve the upstream allocation, affinity and shared-vector behavior.
- Distinguish a local HWC rejection from a command posted and then timed out. Propagate that distinction through GDMA, Ethernet and RDMA cleanup so a destroy that could not be sent does not release device-owned queue memory, RX pages or RDMA pins. Retain relevant EQ/MSI-X references.
- Cover failed creation unwinds, transferred queue ownership and partial multi-command DMA regions. Preserve verbs dependencies on rejection and avoid repeating acknowledged RSS WQ destroys during a partial retry. Keep previously retained CQ callback state until destruction succeeds.
- Wait on a full mixed pool while a healthy occupied slot can still make progress, rather than failing merely because another slot was abandoned. Keep quarantine, stop/cancellation wakeups and available-slot behavior.
- Preserve the specific private-bootstrap EQ-test failure diagnostic and initialize the context drain waitqueue once in PCI/CDX probe.
- Correct the stale WARN and teardown/RCU comments. Add original-driver Fixes lineage and dependency-complete backport guidance; do not mark the whole feature stack for automatic stable pickup.
- Document nonzero PF-report validation and EPROTO, including fallback, and the existing unchecked-doorbell fix. PF-directed geometry and directional-size contracts are unchanged.

Independent pre-existing RX, CQ-lifetime and broader lifecycle findings remain separate. The posted-command timeout/PF-error cleanup policy is also unchanged. Unacknowledged DMA, pins and references may be deliberately retained; this revision does not infer quiescence from a reset or delay, or promise automatic reclamation.

Validation on this exact revision:
- Ten GCC/Clang W=1 MANA Ethernet/RDMA target builds: unmodified base plus each of the four intermediate commits, with no compiler diagnostics.
- Thirteen inherited bounded actual-source regression suites and four throttle/CQ/EQ lifetime suites.
- Eight new GCC/Clang ASan/UBSan suites exercise cleanup rejection, callback/dependency retention, partial DMA creation, retries, healthy controls and the unchanged posted-error policy. There are 175 new cases and 25 negative controls per compiler.
- Source-cited local review following netdev/Sashiko criteria, including the fault-state caller interactions and failed construction unwinds.
- Strict 80-column checks have no source diagnostics. Checkpatch reports the retained Co-authored-by metadata warning once on each patch.

These are static/offline checks, not actual bot or hardware approval. No new full-kernel, runtime or performance qualification is claimed.

Previous revision:
https://lore.kernel.org/all/[email protected]/

Base: 6964ff21c5d8b75649211a52dbfd92753e605649

Long Li (4):
net: mana: prepare HWC ownership for safe reinitialization
net: mana: give each HWC message slot its own completion state
net: mana: support concurrent HWC requests
net: mana: add dynamic HWC queue depth with reinit path

 drivers/infiniband/hw/mana/cq.c               |   17 +-
 drivers/infiniband/hw/mana/main.c             |   91 +-
 drivers/infiniband/hw/mana/mana_ib.h          |    5 +-
 drivers/infiniband/hw/mana/mr.c               |   28 +-
 drivers/infiniband/hw/mana/qp.c               |  106 +-
 drivers/infiniband/hw/mana/wq.c               |    4 +-
 .../net/ethernet/microsoft/mana/gdma_cdx.c    |    6 +-
 .../net/ethernet/microsoft/mana/gdma_main.c   |  207 +++-
 .../net/ethernet/microsoft/mana/gdma_pci.c    |   20 +-
 .../net/ethernet/microsoft/mana/hw_channel.c  | 1021 ++++++++++++++---
 drivers/net/ethernet/microsoft/mana/mana_en.c |   49 +-
 .../net/ethernet/microsoft/mana/shm_channel.c |   58 +-
 include/net/mana/gdma.h                       |   26 +-
 include/net/mana/hw_channel.h                 |   70 +-
 include/net/mana/mana.h                       |    4 +-
 include/net/mana/shm_channel.h                |   10 +-
 16 files changed, 1404 insertions(+), 318 deletions(-)

base-commit: 6964ff21c5d8b75649211a52dbfd92753e605649

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v11 1/4 net: mana: prepare HWC ownership for safe reinitialization

From: Long Li <[email protected]>

Dynamic HWC queue sizing tears down the bootstrap queues and establishes a second channel before publishing it. Prepare the existing HWC ownership and teardown paths so that sequence cannot free or reuse state still reachable by either the PF or an EQ handler.

The shared-memory aperture carries one request at a time. Serialize the complete ESTABLISH_HWC and DESTROY_HWC transactions, including possession polling and response validation. Record setup_active immediately before the MMIO submission and clear it only after DESTROY_HWC is acknowledged.

Treat an unacknowledged destroy as retained PF ownership. Fence the HWC EQ and withdraw its CQ from dispatch, but keep all queue memory and wrappers for a later teardown retry. A new channel creation retries that retained context before assigning fresh queues to the PF.

When a PCI or CDX transport permanently discards its gdma_context, no such retry is possible. After IRQ and service-work teardown, release the software-only HWC state through a common final-disposal helper. Leave the coherent DMA allocations unreclaimed rather than exposing freed memory to a PF whose teardown was not acknowledged.

Snapshot the bootstrap CQ count and CQ ID after INIT_DONE. Publish the fixed bound with the allocated table so later init events cannot grow the bound past the allocation. Use a single acquire-loaded table snapshot in both normal and throttled EQE dispatch, with annotated CQ-slot reads. Out-of-range IDs and empty slots are deliberately quiet drops, including during teardown; remove the stale reference to their former WARN.

On acknowledged teardown, withdraw the CQ table and wait for all existing IRQ-side RCU readers before freeing the table and HWC queue bundle. This also covers a completion dispatched through a different EQ, without a per-event reference. Fence the dedicated EQ's remaining callbacks before releasing the CQ, completion buffer and work queues. Keep the parent EQ allocated until CQ destruction has detached its throttled-EQE child entry. Preserve the existing generic CQ detach and RCU handling.

The original driver could free HWC memory after unacknowledged teardown and trust a mutable PF-reported CQ bound. These lifetime and malformed-init fixes are prerequisites for rebuilding; a backport needs their complete dependencies, not an automatic backport of the feature stack.

Copilot-Session: 8c2361e6-c0f4-4b0c-bf01-b5e4cdacec50

---
 .../net/ethernet/microsoft/mana/gdma_cdx.c    |   4 +-
 .../net/ethernet/microsoft/mana/gdma_main.c   |  41 +++-
 .../net/ethernet/microsoft/mana/gdma_pci.c    |   4 +-
 .../net/ethernet/microsoft/mana/hw_channel.c  | 187 +++++++++++++++---
 drivers/net/ethernet/microsoft/mana/mana_en.c |   4 +-
 .../net/ethernet/microsoft/mana/shm_channel.c |  58 +++++-
 include/net/mana/gdma.h                       |   4 +
 include/net/mana/hw_channel.h                 |   5 +
 include/net/mana/shm_channel.h                |  10 +-
 9 files changed, 277 insertions(+), 40 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_cdx.c +2 -2
index 0d01e3d2f0d9..2e0dcb902d7e 100644
@@ -279,7 +279,7 @@ static int mana_cdx_gd_probe(struct cdx_device *cdx_dev)
 	iounmap(bar0_va);
 free_gc:
 	dev_set_drvdata(&cdx_dev->dev, NULL);
-	vfree(gc);
+	mana_gd_free_context(gc);
 clear_master:
 	cdx_clear_master(cdx_dev);
 	return err;
@@ -298,7 +298,7 @@ static int mana_cdx_gd_remove(struct cdx_device *cdx_dev)
 	iounmap(gc->bar0_va);
 
 	dev_set_drvdata(&cdx_dev->dev, NULL);
-	vfree(gc);
+	mana_gd_free_context(gc);
 	return 0;
 }
 
drivers/net/ethernet/microsoft/mana/gdma_main.c +35 -6

103 lines not on this page · raw message

drivers/net/ethernet/microsoft/mana/gdma_pci.c +2 -2
index 208dadbcf977..e59c0666db3b 100644
@@ -633,7 +633,7 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	pci_iounmap(pdev, bar0_va);
 free_gc:
 	pci_set_drvdata(pdev, NULL);
-	vfree(gc);
+	mana_gd_free_context(gc);
 release_region:
 	pci_release_regions(pdev);
 disable_dev:
@@ -686,7 +686,7 @@ static void mana_gd_remove(struct pci_dev *pdev)
 
 	pci_iounmap(pdev, gc->bar0_va);
 
-	vfree(gc);
+	mana_gd_free_context(gc);
 
 	pci_release_regions(pdev);
 	pci_disable_device(pdev);
drivers/net/ethernet/microsoft/mana/hw_channel.c +165 -22

277 lines not on this page · raw message

drivers/net/ethernet/microsoft/mana/mana_en.c +2 -2
index 7e9223143fc7..744e6ceb7d2b 100644
@@ -2736,8 +2736,8 @@ static void mana_destroy_txq(struct mana_port_context *apc)
 		if (apc->tx_qp[i]->txq.napi_initialized) {
 			/* Detach the CQ only after the WQ object is destroyed,
 			 * so a completion EQE that arrives before then still
-			 * finds the CQ in cq_table[] rather than hitting the
-			 * WARN in mana_gd_process_eqe(). One grace period then
+			 * finds the CQ in cq_table[] rather than being dropped
+			 * by mana_gd_process_eqe(). One grace period then
 			 * covers both mana_gd_intr() and NAPI users.
 			 */
 			mana_gd_detach_cq(gc, apc->tx_qp[i]->tx_cq.gdma_cq);
drivers/net/ethernet/microsoft/mana/shm_channel.c +54 -4

95 lines not on this page · raw message

include/net/mana/gdma.h +4 -0
index 1f0f9897b806..8375a208a248 100644
@@ -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);
+
 int mana_gd_poll_cq(struct gdma_queue *cq, struct gdma_comp *comp, int num_cqe);
 
 void mana_gd_ring_cq(struct gdma_queue *cq, u8 arm_bit);
@@ -1150,6 +1153,7 @@ int mana_gd_verify_vf_version(struct gdma_context *gc);
 int mana_gd_query_max_resources(struct gdma_context *gc);
 int mana_gd_setup(struct gdma_context *gc);
 void mana_gd_cleanup(struct gdma_context *gc);
+void mana_gd_free_context(struct gdma_context *gc);
 int mana_gd_detect_devices(struct gdma_context *gc);
 int mana_gd_init_registers(struct gdma_context *gc);
 irqreturn_t mana_gd_intr(int irq, void *arg);
include/net/mana/hw_channel.h +5 -0
index 1ab2d66c891e..1320bdfa9d2a 100644
@@ -185,6 +185,8 @@ struct hw_channel_context {
 	u16 hwc_init_q_depth_max;
 	u32 hwc_init_max_req_msg_size;
 	u32 hwc_init_max_resp_msg_size;
+	u32 hwc_init_max_num_cqs;
+	u32 hwc_init_cq_id;
 
 	struct completion hwc_init_eqe_comp;
 
@@ -199,11 +201,14 @@ struct hw_channel_context {
 	u32 dest_vrcq_id;
 	u32 hwc_timeout;
 
+	/* The PF may own the HWC queues while this is true. */
+	bool setup_active;
 	struct hwc_caller_ctx *caller_ctx;
 };
 
 int mana_hwc_create_channel(struct gdma_context *gc);
 void mana_hwc_destroy_channel(struct gdma_context *gc);
+void mana_hwc_free_retained_channel(struct gdma_context *gc);
 
 int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 			  const void *req, u32 resp_len, void *resp);
include/net/mana/shm_channel.h +8 -2
index dbabcfb95daf..c8daa61fa759 100644
@@ -4,6 +4,8 @@
 #ifndef _SHM_CHANNEL_H
 #define _SHM_CHANNEL_H
 
+#include <linux/mutex.h>
+
 #define SMC_APERTURE_BITS 256
 #define SMC_BASIC_UNIT (sizeof(u32))
 #define SMC_APERTURE_DWORDS (SMC_APERTURE_BITS / (SMC_BASIC_UNIT * 8))
@@ -13,6 +15,9 @@
 struct shm_channel {
 	struct device *dev;
 	void __iomem *base;
+	/* Protects base and complete aperture request/response transactions. */
+	struct mutex transaction_lock;
+	bool transaction_lock_initialized;
 };
 
 void mana_smc_init(struct shm_channel *sc, struct device *dev,
@@ -20,8 +25,9 @@ void mana_smc_init(struct shm_channel *sc, struct device *dev,
 
 int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
 		       u64 cq_addr, u64 rq_addr, u64 sq_addr,
-		       u32 eq_msix_index);
+		       u32 eq_msix_index, bool *submitted);
 
-int mana_smc_teardown_hwc(struct shm_channel *sc, bool reset_vf);
+int mana_smc_teardown_hwc(struct shm_channel *sc, bool reset_vf,
+			  bool *setup_active);
 
 #endif /* _SHM_CHANNEL_H */
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH net-next v11 1/4] net: mana: prepare HWC ownership for safe reinitialization

Sashiko has reviewed this patch and found no issues.
Quoted 15 lines

From: Long Li <[email protected]>

Dynamic HWC queue sizing tears down the bootstrap queues and establishes a second channel before publishing it. Prepare the existing HWC ownership and teardown paths so that sequence cannot free or reuse state still reachable by either the PF or an EQ handler.

The shared-memory aperture carries one request at a time. Serialize the complete ESTABLISH_HWC and DESTROY_HWC transactions, including possession polling and response validation. Record setup_active immediately before the MMIO submission and clear it only after DESTROY_HWC is acknowledged.

Treat an unacknowledged destroy as retained PF ownership. Fence the HWC EQ and withdraw its CQ from dispatch, but keep all queue memory and wrappers for a later teardown retry. A new channel creation retries that retained

Quoted 6 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH net-next v11 1/4] net: mana: prepare HWC ownership for safe reinitialization

In reply to Wei Hu
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

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

Critical: 0 · High: 0 (1) · Medium: 2 · Low: 0

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] The HWC DMA leak that the commit message describes as a one- time 'final disposal' cost can repeat without limit, because the…
- [Medium] mana_smc_setup_hwc_locked() sets *submitted (hwc->setup_active) to true just before the aperture writel() loop,…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch documents and relies on it being absent.

--

net: mana: prepare HWC ownership for safe reinitialization

This commit serializes the SMC ESTABLISH_HWC and DESTROY_HWC transactions. It tracks whether the PF may own the HWC queues through setup_active, and keeps the HWC queue memory when DESTROY_HWC is not acknowledged. It also snapshots the PF-reported CQ count and CQ ID, publishes cq_table with acquire/release ordering, and adds a final-disposal helper that frees only software state when a gdma_context is discarded.

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -0
index d6ae89c2ccddc..fc460d83fb800 100644

[ ... ]

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +5 -1
@@ -796,11 +804,16 @@ static void mana_gd_process_eqe(struct gdma_queue *eq)
 	switch (type) {
 	case GDMA_EQE_COMPLETION:
 		cq_id = eqe->details[0] & 0xFFFFFF;
-		if (WARN_ON_ONCE(cq_id >= gc->max_num_cqs))
+		/* HWC teardown unpublishes this table and waits for these
+		 * RCU readers before freeing it, then fences its own EQ.
+		 */
+		cq_table = smp_load_acquire(&gc->cq_table);
+		if (!cq_table || cq_id >= READ_ONCE(gc->max_num_cqs))

drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_process_eqe(struct gdma_queue *eq) · line 819

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +3 -2
 			break;
 
-		cq = gc->cq_table[cq_id];
-		if (WARN_ON_ONCE(!cq || cq->type != GDMA_CQ || cq->id != cq_id))
+		cq = READ_ONCE(cq_table[cq_id]);
+		if (!cq || WARN_ON_ONCE(cq->type != GDMA_CQ ||
+					cq->id != cq_id))
 			break;
 
 		if (cq->cq.callback)

[Severity: High]

This isn't a bug introduced by this patch, but the new comment describes a rule for cq_table (unpublish the slot, wait for RCU readers, then free) that mana_ib does not follow. Can this IRQ path dereference a gdma_queue that mana_ib has already freed?

drivers/infiniband/hw/mana/cq.c:mana_ib_remove_cq_cb() {
    ...
	kfree(gc->cq_table[cq->queue.id]);
	gc->cq_table[cq->queue.id] = NULL;
}

The entry is freed while it is still published. The slot is then cleared with a plain store, and there is no grace period before or after.

A possible interleaving:

CPU0 (mana_gd_intr, under rcu_read_lock)
mana_gd_process_eqe()

    cq = READ_ONCE(cq_table[cq_id]);

CPU1
mana_ib_destroy_cq()

    mana_ib_remove_cq_cb()
        kfree(gc->cq_table[cq->queue.id]);

CPU0

    cq->type / cq->id checks
    cq->cq.callback(cq->cq.context, cq);

CPU0 then calls through a function pointer read from freed memory. mana_ib_cq_handler() also dereferences the mana_ib_cq, which the IB core frees after destroy_cq returns.

mana_ib_destroy_cq() calls mana_ib_remove_cq_cb() before mana_ib_gd_destroy_cq(), so the device can still generate completions for that CQ. The error path in mana_ib_create_qp_rss() has the same ordering:
it calls mana_ib_remove_cq_cb() before mana_ib_destroy_wq_obj().

mana_ib_install_cq_cb() also publishes the new gdma_cq with a plain store. Nothing orders it against these READ_ONCE() readers:

	gc->cq_table[cq->queue.id] = gdma_cq;

Should mana_ib unpublish the slot, wait for a grace period, and only then free the object, as the HWC teardown path in this patch does?

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0 -0
index fb9f38f65911c..9e0964072af9a 100644

[ ... ]

Quoted 30 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +23 -2
@@ -852,9 +960,44 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)
 	kfree(hwc);
 	gc->hwc.driver_data = NULL;
 	gc->hwc.gdma_context = NULL;
+}
 
-	vfree(gc->cq_table);
-	gc->cq_table = NULL;
+static void mana_hwc_free_retained_wq(struct hwc_wq *wq)
+{
+	if (!wq)
+		return;
+
+	kfree(wq->msg_buf);
+	kfree(wq->gdma_wq);
+	kfree(wq);
+}
+
+/* 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)
+{
+	struct hw_channel_context *hwc = gc->hwc.driver_data;
+
+	if (!hwc)
+		return;
+
+	gc->hwc.driver_data = NULL;
+	mana_hwc_clear_cq_table(gc);

drivers/net/ethernet/microsoft/mana/hw_channel.c void mana_hwc_destroy_channel(struct gdma_context *gc) · line 996

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +10 -0
+
+	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]

Can this leak repeat without limit through the existing PCI recovery loop?

When DESTROY_HWC is not acknowledged, mana_hwc_destroy_channel() leaves the hwc in gc->hwc.driver_data. On probe failure or remove, mana_gd_free_context() calls this function.

This function kfree()s gdma_eq, gdma_cq, and each wq's gdma_wq and msg_buf. Those structures hold the only copies of the mem_info for the EQ/CQ/RQ/SQ rings and both message buffers. mana_gd_free_memory() is never called, so nothing can reach those coherent allocations afterwards.

After freeing the context, the probe error path schedules recovery:

mana_gd_probe() {
    ...
free_gc:
	pci_set_drvdata(pdev, NULL);
	mana_gd_free_context(gc);
    ...
	if (err == -ETIMEDOUT || err == -ENOTCONN || err == -EPROTO) {
		...
		schedule_delayed_work(&mana_dev_recovery_work.work,
				      secs_to_jiffies(MANA_SERVICE_PERIOD));

mana_serv_reset() then runs with gc == NULL and calls mana_serv_rescan(), which probes the device again.

Consider a PF that keeps accepting ESTABLISH_HWC but never acknowledges DESTROY_HWC, for example when INIT_DONE never arrives and DESTROY then times out. Each cycle would leak another full HWC DMA footprint, and nothing limits the number of retries.

The in-place reset path also behaves differently now. Before this patch, mana_serv_reset() -> suspend/resume re-established the HWC in place, because the teardown error was ignored. With a retained context, mana_hwc_create_channel() returns a fixed -ETIMEDOUT and the real teardown error is lost:

	if (gd->driver_data) {
		mana_hwc_destroy_channel(gc);
		if (gd->driver_data)
			return -ETIMEDOUT;
	}

mana_serv_reset() turns that error into a full remove/rescan:

	ret = mana_gd_resume(pdev);
	if (ret == -ETIMEDOUT || ret == -ENOTCONN || ret == -EPROTO) {
		/* Perform PCI rescan on device if we failed on HWC */
		dev_err(&pdev->dev, "MANA service: resume failed, rescanning\n");
		mana_serv_rescan(pdev);

The rescan then reaches the leaking path above.

The commit message describes this as a one-time final disposal. Should recovery attempts be limited once HWC DMA has been retained? If not, could the changelog at least describe this interaction?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/shm_channel.c +0 -0
index d21b5db06e509..df9d05062dd57 100644

[ ... ]

drivers/net/ethernet/microsoft/mana/shm_channel.c int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr, · line 249

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/shm_channel.c +1 -0
@@ -229,6 +243,7 @@ int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
 	/* Write 256-message buffer to shared memory (final 32-bit write
 	 * triggers HW to set possession bit to PF).
 	 */
+	*submitted = true;
 	dword = (u32 *)shm_buf;
 	for (i = 0; i < SMC_APERTURE_DWORDS; i++)
 		writel(*dword++, sc->base + i * SMC_BASIC_UNIT);

[Severity: Medium]

What happens to setup_active when the PF returns possession with a well-formed ESTABLISH_HWC response that carries a non-zero status?

In that case mana_smc_read_response() returns -EPROTO:

	if (hdr.status != 0) {
		dev_err(sc->dev, "SMC operation failed: 0x%x\n", hdr.status);
		return -EPROTO;
	}

smc_proto_hdr defines status as the operation result on a response (success = 0, failure = 1 or greater), so this is an explicit rejection. Even so, *submitted stays true, and hwc->setup_active still records that the PF owns the HWC queues.

Only mana_smc_teardown_hwc_locked() clears the flag, and only after a DESTROY_HWC sent with reset_vf=false is acknowledged. As a result, the create failure path in mana_hwc_create_channel() sends DESTROY_HWC for a channel the PF reported it never established.

If the PF rejects or ignores that DESTROY, the hwc is retained. Every later mana_hwc_create_channel() on that gc then returns -ETIMEDOUT, and mana_hwc_free_retained_channel() leaks all of the HWC coherent DMA memory.

The baseline sent DESTROY only after init events had arrived (max_num_cqs > 0).

Could an explicit non-zero status in the ESTABLISH_HWC response clear *submitted? Alternatively, could a DESTROY with reset_vf set be tried as a fallback before the context is retained?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794751992.git.weh%40linux.microsoft.com
author
#4 lore raw

Re: [PATCH net-next v11 1/4] net: mana: prepare HWC ownership for safe reinitialization

Quoted 2 lines · netdev-bot+sashiko

Should mana_ib unpublish the slot, wait for a grace period, and only then free the object, as the HWC teardown path in this patch does?

The HWC teardown protects the table itself, not the lifetime of each RDMA CQ in it. The individual CQ race exists upstream; v12 leaves it out of this series.

Quoted 1 line

Can this leak repeat without limit through the existing PCI recovery loop?

Yes, in v11. In v12, if probe cleanup can't get a DESTROY_HWC ack, the driver doesn't schedule another PCI probe. If teardown fails during removal for a driver-initiated rescan, it skips the rescan. A bound device can retry the destroy. Final removal can still leak the last set of HWC buffers: the PF may still be using them.

Quoted 2 lines

What happens to setup_active when the PF returns possession with a well-formed ESTABLISH_HWC response that carries a non-zero status?

It stays set. Once the VF has submitted the queue addresses, an error reply doesn't establish that the PF has dropped the mappings. The VF still attempts DESTROY_HWC and waits for its ack before freeing them. A reset notification isn't a substitute for that ack.

Thanks,
Wei

author
#5 lore raw

PATCH v11 2/4 net: mana: give each HWC message slot its own completion state

In reply to Wei Hu

From: Long Li <[email protected]>

Concurrent requests require the response handler and the waiting sender to agree on the lifetime and result state of each message slot.

Protect the caller's output buffer, Linux error and device status with a per-slot lock. Publish the output buffer only while the sender is waiting and withdraw it before every return. This fixes the original driver's late response copy through caller storage whose lifetime has ended.

Reinitialize completion and result state under both the allocation and per-slot locks when acquiring the slot. This also fixes stale completion state surviving a timed-out request. A response handler can still hold the per-slot lock after the previous sender has returned its admission permit, so an unpublished bitmap bit alone is not sufficient protection. If the response records its result while the timed wait expires, return that result instead of reporting a false timeout.

Keep the baseline's post-timeout admission behavior at this step rather than introducing a temporary channel-wide latch that suppresses subsequent teardown commands. This patch alone does not solve late-response correlation or TX-buffer reuse after a timeout. The next patch adds response ownership, per-slot quarantine and the associated admission and cleanup rules together; backporting the fixes needs that dependency.

Split response-status handling and request cleanup into helpers so the send path has structured returns rather than phase-jumping gotos.

Copilot-Session: 8c2361e6-c0f4-4b0c-bf01-b5e4cdacec50

---
 .../net/ethernet/microsoft/mana/hw_channel.c  | 125 +++++++++++++-----
 include/net/mana/hw_channel.h                 |   4 +-
 2 files changed, 95 insertions(+), 34 deletions(-)
drivers/net/ethernet/microsoft/mana/hw_channel.c +92 -33
index 9e0964072af9..6f0ccdeffc4f 100644
@@ -9,6 +9,7 @@
 static int mana_hwc_get_msg_index(struct hw_channel_context *hwc, u16 *msg_id)
 {
 	struct gdma_resource *r = &hwc->inflight_msg_res;
+	struct hwc_caller_ctx *ctx;
 	unsigned long flags;
 	u32 index;
 
@@ -19,8 +20,17 @@ static int mana_hwc_get_msg_index(struct hw_channel_context *hwc, u16 *msg_id)
 	index = find_first_zero_bit(hwc->inflight_msg_res.map,
 				    hwc->inflight_msg_res.size);
 
+	ctx = &hwc->caller_ctx[index];
+	spin_lock(&ctx->lock);
+	reinit_completion(&ctx->comp_event);
+	ctx->output_buf = NULL;
+	ctx->output_buflen = 0;
+	ctx->error = -EINPROGRESS;
+	ctx->status_code = 0;
+
 	bitmap_set(hwc->inflight_msg_res.map, index, 1);
 
+	spin_unlock(&ctx->lock);
 	spin_unlock_irqrestore(&r->lock, flags);
 
 	*msg_id = index;
@@ -90,14 +100,21 @@ static void mana_hwc_handle_resp(struct hw_channel_context *hwc, u32 resp_len,
 	}
 
 	ctx = hwc->caller_ctx + msg_id;
-	err = mana_hwc_verify_resp_msg(ctx, resp_msg, resp_len);
-	if (err)
-		goto out;
 
-	ctx->status_code = resp_msg->status;
+	spin_lock(&ctx->lock);
+	if (!ctx->output_buf) {
+		spin_unlock(&ctx->lock);
+		mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
+		return;
+	}
 
-	memcpy(ctx->output_buf, resp_msg, resp_len);
-out:
+	err = mana_hwc_verify_resp_msg(ctx, resp_msg, resp_len);
+	if (!err) {
+		ctx->status_code = resp_msg->status;
+		memcpy(ctx->output_buf, resp_msg, resp_len);
+	}
+
+	ctx->output_buf = NULL;
 	ctx->error = err;
 
 	/* Must post rx wqe before complete(), otherwise the next rx may
@@ -106,6 +123,7 @@ static void mana_hwc_handle_resp(struct hw_channel_context *hwc, u32 resp_len,
 	mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
 
 	complete(&ctx->comp_event);
+	spin_unlock(&ctx->lock);
 }
 
 static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
@@ -696,8 +714,10 @@ static int mana_hwc_test_channel(struct hw_channel_context *hwc, u16 q_depth,
 	if (!ctx)
 		return -ENOMEM;
 
-	for (i = 0; i < q_depth; ++i)
+	for (i = 0; i < q_depth; ++i) {
 		init_completion(&ctx[i].comp_event);
+		spin_lock_init(&ctx[i].lock);
+	}
 
 	hwc->caller_ctx = ctx;
 
@@ -1000,6 +1020,37 @@ void mana_hwc_free_retained_channel(struct gdma_context *gc)
 	gc->hwc.gdma_context = NULL;
 }
 
+static int mana_hwc_response_status(struct hw_channel_context *hwc,
+				    u32 command, int error, u32 status)
+{
+	if (error)
+		return error;
+
+	if (!status || status == GDMA_STATUS_MORE_ENTRIES)
+		return 0;
+
+	if (status == GDMA_STATUS_CMD_UNSUPPORTED)
+		return -EOPNOTSUPP;
+
+	if (command != MANA_QUERY_PHY_STAT)
+		dev_err(hwc->dev, "Command 0x%x failed with status: 0x%x\n",
+			command, status);
+
+	return -EPROTO;
+}
+
+static void mana_hwc_finish_request(struct hw_channel_context *hwc,
+				    struct hwc_caller_ctx *ctx, u16 msg_id)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&ctx->lock, flags);
+	ctx->output_buf = NULL;
+	spin_unlock_irqrestore(&ctx->lock, flags);
+
+	mana_hwc_put_msg_index(hwc, msg_id);
+}
+
 int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 			  const void *req, u32 resp_len, void *resp)
 {
@@ -1007,26 +1058,32 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 	struct hwc_wq *txq = hwc->txq;
 	struct gdma_req_hdr *req_msg;
 	struct hwc_caller_ctx *ctx;
+	unsigned long flags;
 	u32 dest_vrcq;
 	u32 dest_vrq;
 	u32 command;
+	u32 status;
 	u16 msg_id;
 	int err;
 
-	mana_hwc_get_msg_index(hwc, &msg_id);
+	err = mana_hwc_get_msg_index(hwc, &msg_id);
+	if (err)
+		return err;
 
 	tx_wr = &txq->msg_buf->reqs[msg_id];
+	ctx = hwc->caller_ctx + msg_id;
 
 	if (req_len > tx_wr->buf_len) {
 		dev_err(hwc->dev, "HWC: req msg size: %d > %d\n", req_len,
 			tx_wr->buf_len);
-		err = -EINVAL;
-		goto out;
+		mana_hwc_finish_request(hwc, ctx, msg_id);
+		return -EINVAL;
 	}
 
-	ctx = hwc->caller_ctx + msg_id;
+	spin_lock_irqsave(&ctx->lock, flags);
 	ctx->output_buf = resp;
 	ctx->output_buflen = resp_len;
+	spin_unlock_irqrestore(&ctx->lock, flags);
 
 	req_msg = (struct gdma_req_hdr *)tx_wr->buf_va;
 	if (req)
@@ -1048,11 +1105,24 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 	err = mana_hwc_post_tx_wqe(txq, tx_wr, dest_vrq, dest_vrcq, false);
 	if (err) {
 		dev_err(hwc->dev, "HWC: Failed to post send WQE: %d\n", err);
-		goto out;
+		mana_hwc_finish_request(hwc, ctx, msg_id);
+		return err;
 	}
 
 	if (!wait_for_completion_timeout(&ctx->comp_event,
-					 (msecs_to_jiffies(hwc->hwc_timeout)))) {
+					 msecs_to_jiffies(hwc->hwc_timeout))) {
+		spin_lock_irqsave(&ctx->lock, flags);
+		ctx->output_buf = NULL;
+		err = ctx->error;
+		status = ctx->status_code;
+		spin_unlock_irqrestore(&ctx->lock, flags);
+
+		if (err != -EINPROGRESS) {
+			mana_hwc_finish_request(hwc, ctx, msg_id);
+			return mana_hwc_response_status(hwc, command, err,
+							status);
+		}
+
 		if (hwc->hwc_timeout != 0)
 			dev_err(hwc->dev, "Command 0x%x timed out: %u ms\n",
 				command, hwc->hwc_timeout);
@@ -1061,27 +1131,16 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 		if (hwc->hwc_timeout > 1)
 			hwc->hwc_timeout = 1;
 
-		err = -ETIMEDOUT;
-		goto out;
+		mana_hwc_finish_request(hwc, ctx, msg_id);
+		return -ETIMEDOUT;
 	}
 
-	if (ctx->error) {
-		err = ctx->error;
-		goto out;
-	}
+	spin_lock_irqsave(&ctx->lock, flags);
+	ctx->output_buf = NULL;
+	err = ctx->error;
+	status = ctx->status_code;
+	spin_unlock_irqrestore(&ctx->lock, flags);
 
-	if (ctx->status_code && ctx->status_code != GDMA_STATUS_MORE_ENTRIES) {
-		if (ctx->status_code == GDMA_STATUS_CMD_UNSUPPORTED) {
-			err = -EOPNOTSUPP;
-			goto out;
-		}
-		if (command != MANA_QUERY_PHY_STAT)
-			dev_err(hwc->dev, "Command 0x%x failed with status: 0x%x\n",
-				command, ctx->status_code);
-		err = -EPROTO;
-		goto out;
-	}
-out:
-	mana_hwc_put_msg_index(hwc, msg_id);
-	return err;
+	mana_hwc_finish_request(hwc, ctx, msg_id);
+	return mana_hwc_response_status(hwc, command, err, status);
 }
include/net/mana/hw_channel.h +3 -1
index 1320bdfa9d2a..c7570a5f7376 100644
@@ -168,10 +168,12 @@ struct hwc_wq {
 
 struct hwc_caller_ctx {
 	struct completion comp_event;
+	/* Protects initialization, output storage and response state. */
+	spinlock_t lock;
 	void *output_buf;
 	u32 output_buflen;
 
-	u32 error; /* Linux error code */
+	int error; /* Linux error code */
 	u32 status_code;
 };
 
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH net-next v11 2/4] net: mana: give each HWC message slot its own completion state

Sashiko has reviewed this patch and found no issues.
Quoted 15 lines

From: Long Li <[email protected]>

Concurrent requests require the response handler and the waiting sender to agree on the lifetime and result state of each message slot.

Protect the caller's output buffer, Linux error and device status with a per-slot lock. Publish the output buffer only while the sender is waiting and withdraw it before every return. This fixes the original driver's late response copy through caller storage whose lifetime has ended.

Reinitialize completion and result state under both the allocation and per-slot locks when acquiring the slot. This also fixes stale completion state surviving a timed-out request. A response handler can still hold the per-slot lock after the previous sender has returned its admission permit, so an unpublished bitmap bit alone is not sufficient protection. If the

Quoted 6 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw

Re: [PATCH net-next v11 2/4] net: mana: give each HWC message slot its own completion state

In reply to Wei Hu
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message for "net: mana: give each HWC message slot its own completion state" ends with two trailers the kernel does not…

--

net: mana: give each HWC message slot its own completion state

This commit adds a per-slot spinlock to struct hwc_caller_ctx in the MANA hardware channel. The lock lets the response handler and the waiting sender agree on the output buffer, error and device status of each message slot.

Slot state is reinitialized under both the bitmap and per-slot locks. The output buffer is withdrawn before every return from mana_hwc_send_request(). Status handling and cleanup are split out into mana_hwc_response_status() and mana_hwc_finish_request().

Quoted 4 lines

Copilot-Session: 8c2361e6-c0f4-4b0c-bf01-b5e4cdacec50

[Severity: Low]
This isn't a bug, but should these last two trailers go into the kernel history?

The kernel does not recognise Co-authored-by: as a tag, and checkpatch.pl warns about it with "Non-standard signature: Co-authored-by:".

The closest kernel tag is Co-developed-by:. It must be followed by a Signed-off-by from the co-developer. AI agents must not add Signed-off-by (see Documentation/process/coding-assistants.rst), so an AI agent cannot meet that requirement.

Copilot-Session: is a session ID internal to the tool. It means nothing to maintainers or to stable tooling.

The other patches in the series carry the same trailers. Could they be dropped from all of them? Any AI assistance could be described in the commit body instead.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794751992.git.weh%40linux.microsoft.com
author
#8 lore raw

PATCH v11 3/4 net: mana: support concurrent HWC requests

In reply to Wei Hu

From: Long Li <[email protected]>

Give HWC message slots separate sender and response ownership. Initialize each slot under the inflight resource and per-slot locks, publish its bitmap bit last, and release the slot only after both references are released. The per-slot lock also excludes an older duplicate callback from resetting or consuming the next caller's state.

Serialize SQ posting so concurrent senders cannot corrupt the producer state. A posted request which times out keeps its response reference, ID and TX buffer until its late response arrives or teardown cancels it. This also fixes the original wrong-command response bug: releasing an ID at timeout could deliver its late response to the next command using that ID. The preceding per-slot state fix and this quarantine are both needed for a dependency-complete backport. The bootstrap channel remains depth one here; the next patch selects and allocates larger queues.

Wait for a free slot while any non-abandoned occupied slot can still make progress. Partial abandonment alone does not end this wait. Wake waiters on slot release, abandonment, cancellation and channel stop. Return -ENOTCONN when the full pool is quarantined or cancelled with no free slot, distinguishing local rejection from an admitted command's bounded response timeout. A stopped channel returns -ENODEV. Retire each abandoned response count with its response reference exactly once.

Local rejection must not make existing destructive callers free DMA that the device still owns. Propagate it through queue disable, DMA-region and WQ-object destruction. Withdraw software CQ/IRQ callbacks, but retain the affected Ethernet queue memory and RX pages when their destroy was rejected. Keep an EQ's MSI-X reference if its disable was not delivered. Handle the same ownership transfer in failed EQ construction.

For RDMA, leave live verbs objects and their dependencies intact on local rejection. Retain queue mappings on failed creation unwinds, including regions already transferred to a QP/CQ handle and partial multi-command DMA-region creation. Do not unpin their memory merely because a cleanup request could not acquire an HWC slot. This may deliberately retain resources on a failed cleanup; it is not proof of device quiescence.

Keep available slots usable for best-effort commands after cancellation. Preserve the baseline cleanup policy for commands that were actually posted and then timed out or received PF errors; this patch does not repair that independent data-DMA failure policy. Keep timeout recovery and expected logging consistent with the new local-rejection result.

Synchronize hwc_timeout updates with atomic access helpers. Cancellation is terminal for a channel instance; firmware and query updates may replace only a live timeout, and fail-fast may only lower a live value to one millisecond.

Keep setup private until queues, admission state, caller contexts and the direct EQ test are ready. Preserve the private test's specific failure diagnostic without publishing the HWC early. Runtime teardown unpublishes the channel, rejects new admissions, wakes waiters and drains active senders before releasing or retaining PF-owned mappings. Initialize the per-context drain waitqueue once in PCI/CDX probe, beside hwc_lock, not on every channel creation. Apply the same unpublication and sender-drain rules to final disposal of retained software state.

Split admission, submission, waiting, response status and unwind into helpers so mana_hwc_send_request() uses structured returns.

Copilot-Session: 8c2361e6-c0f4-4b0c-bf01-b5e4cdacec50

---
 drivers/infiniband/hw/mana/cq.c               |  17 +-
 drivers/infiniband/hw/mana/main.c             |  72 ++-
 drivers/infiniband/hw/mana/mana_ib.h          |   5 +-
 drivers/infiniband/hw/mana/mr.c               |  28 +-
 drivers/infiniband/hw/mana/qp.c               | 106 +++-
 drivers/infiniband/hw/mana/wq.c               |   4 +-
 .../net/ethernet/microsoft/mana/gdma_cdx.c    |   2 +
 .../net/ethernet/microsoft/mana/gdma_main.c   | 150 ++++-
 .../net/ethernet/microsoft/mana/gdma_pci.c    |  16 +-
 .../net/ethernet/microsoft/mana/hw_channel.c  | 599 +++++++++++++-----
 drivers/net/ethernet/microsoft/mana/mana_en.c |  49 +-
 include/net/mana/gdma.h                       |  20 +-
 include/net/mana/hw_channel.h                 |  46 +-
 include/net/mana/mana.h                       |   4 +-
 14 files changed, 827 insertions(+), 291 deletions(-)
drivers/infiniband/hw/mana/cq.c +8 -9
index 843e2c64b32b..95b7c250494b 100644
@@ -149,7 +149,8 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
 err_remove_cq_cb:
 	mana_ib_remove_cq_cb(mdev, cq);
 err_destroy_rnic_cq:
-	mana_ib_gd_destroy_cq(mdev, cq);
+	if (mana_gd_is_request_rejected(mana_ib_gd_destroy_cq(mdev, cq)))
+		WRITE_ONCE(cq->queue.retain_dma, true);
 err_destroy_queue:
 	mana_ib_destroy_queue(mdev, &cq->queue);
 
@@ -169,16 +170,14 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
 
 	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
 
-	mana_ib_remove_cq_cb(mdev, cq);
-
-	/* Ignore return code as there is not much we can do about it.
-	 * The error message is printed inside.
-	 */
-	mana_ib_gd_destroy_cq(mdev, cq);
+	err = mana_ib_gd_destroy_cq(mdev, cq);
+	if (mana_gd_is_request_rejected(err) ||
+	    READ_ONCE(cq->queue.retain_dma))
+		return err ? err : -ENOTCONN;
 
-	mana_ib_destroy_queue(mdev, &cq->queue);
+	mana_ib_remove_cq_cb(mdev, cq);
 
-	return 0;
+	return mana_ib_destroy_queue(mdev, &cq->queue);
 }
 
 static void mana_ib_cq_handler(void *ctx, struct gdma_queue *gdma_cq)
drivers/infiniband/hw/mana/main.c +52 -20

152 lines not on this page · raw message

drivers/infiniband/hw/mana/mana_ib.h +4 -1
index 9173ca64d2e1..de7869ba556c 100644
@@ -76,6 +76,8 @@ struct mana_ib_queue {
 	struct gdma_queue *kmem;
 	u64 gdma_region;
 	u64 id;
+	/* A locally rejected parent destroy left this mapping PF-owned. */
+	bool retain_dma;
 };
 
 struct mana_ib_dev {
@@ -823,7 +825,8 @@ int mana_ib_create_kernel_queue(struct mana_ib_dev *mdev, u32 size, enum gdma_qu
 				struct mana_ib_queue *queue);
 int mana_ib_create_queue(struct mana_ib_dev *mdev, u64 addr, u32 size,
 			 struct mana_ib_queue *queue, bool is_cq);
-void mana_ib_destroy_queue(struct mana_ib_dev *mdev, struct mana_ib_queue *queue);
+int mana_ib_destroy_queue(struct mana_ib_dev *mdev,
+			  struct mana_ib_queue *queue);
 
 struct ib_wq *mana_ib_create_wq(struct ib_pd *pd,
 				struct ib_wq_init_attr *init_attr,
drivers/infiniband/hw/mana/mr.c +20 -8
index 1233685b4b89..7b95f9f1db53 100644
@@ -107,8 +107,8 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 length,
 	struct ib_device *ibdev = ibpd->device;
 	struct mana_ib_dev *dev;
 	struct mana_ib_mr *mr;
-	u64 dma_region_handle;
-	int err;
+	u64 dma_region_handle = GDMA_INVALID_DMA_REGION;
+	int err, destroy_err;
 
 	if (dmah)
 		return ERR_PTR(-EOPNOTSUPP);
@@ -178,10 +178,16 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 length,
 	return &mr->ibmr;
 
 err_dma_region:
-	mana_gd_destroy_dma_region(mdev_to_gc(dev), dma_region_handle);
+	destroy_err = mana_gd_destroy_dma_region(mdev_to_gc(dev),
+						 dma_region_handle);
+	if (mana_gd_is_request_rejected(destroy_err))
+		goto err_free;
+	dma_region_handle = GDMA_INVALID_DMA_REGION;
 
 err_umem:
-	ib_umem_release(mr->umem);
+	if (!mana_gd_is_request_rejected(err) ||
+	    dma_region_handle == GDMA_INVALID_DMA_REGION)
+		ib_umem_release(mr->umem);
 
 err_free:
 	kfree(mr);
@@ -199,8 +205,8 @@ struct ib_mr *mana_ib_reg_user_mr_dmabuf(struct ib_pd *ibpd, u64 start, u64 leng
 	struct ib_umem_dmabuf *umem_dmabuf;
 	struct mana_ib_dev *dev;
 	struct mana_ib_mr *mr;
-	u64 dma_region_handle;
-	int err;
+	u64 dma_region_handle = GDMA_INVALID_DMA_REGION;
+	int err, destroy_err;
 
 	if (dmah)
 		return ERR_PTR(-EOPNOTSUPP);
@@ -252,10 +258,16 @@ struct ib_mr *mana_ib_reg_user_mr_dmabuf(struct ib_pd *ibpd, u64 start, u64 leng
 	return &mr->ibmr;
 
 err_dma_region:
-	mana_gd_destroy_dma_region(mdev_to_gc(dev), dma_region_handle);
+	destroy_err = mana_gd_destroy_dma_region(mdev_to_gc(dev),
+						 dma_region_handle);
+	if (mana_gd_is_request_rejected(destroy_err))
+		goto err_free;
+	dma_region_handle = GDMA_INVALID_DMA_REGION;
 
 err_umem:
-	ib_umem_release(mr->umem);
+	if (!mana_gd_is_request_rejected(err) ||
+	    dma_region_handle == GDMA_INVALID_DMA_REGION)
+		ib_umem_release(mr->umem);
 
 err_free:
 	kfree(mr);
drivers/infiniband/hw/mana/qp.c +84 -22

187 lines not on this page · raw message

drivers/infiniband/hw/mana/wq.c +3 -1
index 4042f26632c0..9884fb808b73 100644
@@ -64,7 +64,9 @@ int mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_udata *udata)
 
 	mdev = container_of(ib_dev, struct mana_ib_dev, ib_dev);
 
-	mana_ib_destroy_queue(mdev, &wq->queue);
+	err = mana_ib_destroy_queue(mdev, &wq->queue);
+	if (mana_gd_is_request_rejected(err))
+		return err;
 
 	kfree(wq);
 
drivers/net/ethernet/microsoft/mana/gdma_cdx.c +2 -0
index 2e0dcb902d7e..1f124cfbdefd 100644
@@ -221,6 +221,8 @@ static int mana_cdx_gd_probe(struct cdx_device *cdx_dev)
 
 	mutex_init(&gc->eq_test_event_mutex);
 	mutex_init(&gc->gic_mutex);
+	spin_lock_init(&gc->hwc_lock);
+	init_waitqueue_head(&gc->hwc_drain_waitq);
 	dev_set_drvdata(&cdx_dev->dev, gc);
 	gc->bar0_pa = cdx_resource_start(cdx_dev, 0);
 	gc->bar0_size = cdx_resource_len(cdx_dev, 0);
drivers/net/ethernet/microsoft/mana/gdma_main.c +116 -34

283 lines not on this page · raw message

drivers/net/ethernet/microsoft/mana/gdma_pci.c +7 -9
index e59c0666db3b..15d376beb8b4 100644
@@ -14,7 +14,6 @@
 #include <linux/xarray.h>
 
 #include <net/mana/mana.h>
-#include <net/mana/hw_channel.h>
 
 struct mana_dev_recovery {
 	struct list_head list;
@@ -85,7 +84,6 @@ static void mana_serv_fpga(struct pci_dev *pdev)
 static void mana_serv_reset(struct pci_dev *pdev)
 {
 	struct gdma_context *gc = pci_get_drvdata(pdev);
-	struct hw_channel_context *hwc;
 	int ret;
 
 	if (!gc) {
@@ -95,15 +93,13 @@ static void mana_serv_reset(struct pci_dev *pdev)
 		return;
 	}
 
-	hwc = gc->hwc.driver_data;
-	if (!hwc) {
+	/* HWC is not responding in this case, so don't wait */
+	ret = mana_gd_cancel_hwc_timeout(gc);
+	if (ret) {
 		dev_err(&pdev->dev, "MANA service: no HWC\n");
 		goto out;
 	}
 
-	/* HWC is not responding in this case, so don't wait */
-	hwc->hwc_timeout = 0;
-
 	dev_info(&pdev->dev, "MANA reset cycle start\n");
 
 	mana_gd_suspend(pdev, PMSG_SUSPEND);
@@ -111,7 +107,7 @@ static void mana_serv_reset(struct pci_dev *pdev)
 	msleep(MANA_SERVICE_PERIOD * 1000);
 
 	ret = mana_gd_resume(pdev);
-	if (ret == -ETIMEDOUT || ret == -EPROTO) {
+	if (ret == -ETIMEDOUT || ret == -ENOTCONN || ret == -EPROTO) {
 		/* Perform PCI rescan on device if we failed on HWC */
 		dev_err(&pdev->dev, "MANA service: resume failed, rescanning\n");
 		mana_serv_rescan(pdev);
@@ -582,6 +578,8 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	mutex_init(&gc->eq_test_event_mutex);
 	mutex_init(&gc->gic_mutex);
+	spin_lock_init(&gc->hwc_lock);
+	init_waitqueue_head(&gc->hwc_drain_waitq);
 	pci_set_drvdata(pdev, gc);
 	gc->bar0_pa = pci_resource_start(pdev, 0);
 	gc->bar0_size = pci_resource_len(pdev, 0);
@@ -647,7 +645,7 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 * perform the device recovery procedure after MANA_SERVICE_PERIOD
 	 * seconds.
 	 */
-	if (err == -ETIMEDOUT || err == -EPROTO) {
+	if (err == -ETIMEDOUT || err == -ENOTCONN || err == -EPROTO) {
 		struct mana_dev_recovery *dev;
 		unsigned long flags;
 
drivers/net/ethernet/microsoft/mana/hw_channel.c +435 -164

830 lines not on this page · raw message

drivers/net/ethernet/microsoft/mana/mana_en.c +33 -16

124 lines not on this page · raw message

include/net/mana/gdma.h +19 -1
index 8375a208a248..2e60e401b2e6 100644
@@ -5,6 +5,7 @@
 #define _GDMA_H
 
 #include <linux/dma-mapping.h>
+#include <linux/errno.h>
 #include <linux/netdevice.h>
 #include <rdma/ib_verbs.h>
 
@@ -548,6 +549,15 @@ struct gdma_context {
 	/* Hardware communication channel (HWC) */
 	struct gdma_dev		hwc;
 
+	/* Sender drain; the final wakeup runs under hwc_lock. */
+	wait_queue_head_t	hwc_drain_waitq;
+
+	/* Protects runtime HWC publication and active sender references.
+	 * Setup owns an unpublished HWC directly; timeout updates use atomic
+	 * access helpers and do not require this lock.
+	 */
+	spinlock_t		hwc_lock;
+
 	/* Azure network adapter */
 	struct gdma_dev		mana;
 
@@ -598,7 +608,13 @@ int mana_gd_create_mana_wq_cq(struct gdma_dev *gd,
 			      const struct gdma_queue_spec *spec,
 			      struct gdma_queue **queue_ptr);
 
-void mana_gd_destroy_queue(struct gdma_context *gc, struct gdma_queue *queue);
+int mana_gd_destroy_queue(struct gdma_context *gc, struct gdma_queue *queue);
+
+/* Local HWC rejection does not revoke the device's DMA ownership. */
+static inline bool mana_gd_is_request_rejected(int err)
+{
+	return err == -ENOTCONN || err == -ENODEV || err == -EMSGSIZE;
+}
 
 /* Remove an EQ from interrupt dispatch without freeing its queue memory. */
 void mana_gd_fence_eq(struct gdma_context *gc, struct gdma_queue *queue);
@@ -1196,6 +1212,8 @@ void mana_gd_free_memory(struct gdma_mem_info *gmi);
 int mana_gd_send_request(struct gdma_context *gc, u32 req_len, const void *req,
 			 u32 resp_len, void *resp);
 
+int mana_gd_cancel_hwc_timeout(struct gdma_context *gc);
+
 int mana_gd_destroy_dma_region(struct gdma_context *gc, u64 dma_region_handle);
 void mana_register_debugfs(void);
 void mana_unregister_debugfs(void);
include/net/mana/hw_channel.h +42 -4

85 lines not on this page · raw message

include/net/mana/mana.h +2 -2
index 218d540bc994..31daaa341515 100644
@@ -1162,8 +1162,8 @@ int mana_create_wq_obj(struct mana_port_context *apc,
 		       struct mana_obj_spec *cq_spec,
 		       mana_handle_t *wq_obj);
 
-void mana_destroy_wq_obj(struct mana_port_context *apc, u32 wq_type,
-			 mana_handle_t wq_obj);
+int mana_destroy_wq_obj(struct mana_port_context *apc, u32 wq_type,
+			mana_handle_t wq_obj);
 
 int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id,
 		   u32 doorbell_pg_id, bool check_channel_changing);
Signature · 1 line
2.43.0
#9 lore raw

Re: [PATCH net-next v11 3/4] net: mana: support concurrent HWC requests

Quoted 1 line · Wei Hu

From: Long Li <[email protected]>

<...>

Quoted 6 lines

For RDMA, leave live verbs objects and their dependencies intact on local rejection. Retain queue mappings on failed creation unwinds, including regions already transferred to a QP/CQ handle and partial multi-command DMA-region creation. Do not unpin their memory merely because a cleanup request could not acquire an HWC slot. This may deliberately retain resources on a failed cleanup; it is not proof of device quiescence.

This sounds wrong at first glance. Unfortunately, the entire series was written using AI tools, making it difficult to provide meaningful feedback based on the commit messages. However, in RDMA, object destruction should not fail and we shouldn't leave pinned memory for the user space process which already exited.

Thanks

author
#10 lore raw

Re: [PATCH net-next v11 3/4] net: mana: support concurrent HWC requests

Quoted 2 lines · Leon Romanovsky

Unfortunately, the entire series was written using AI tools, making it difficult to provide meaningful feedback based on the commit messages.

I rewrote the v12 commit messages to explain what goes wrong and why each change is needed.

Quoted 2 lines

However, in RDMA, object destruction should not fail and we shouldn't leave pinned memory for the user space process which already exited.

Agreed. ib_free_cq() frees the CQ even if destroy returns an error. I removed the CQ and QP early returns in v12. Teardown no longer relies on an exiting process retrying.

When a posted HWC command reaches its normal response timeout, the PF guarantees that DMA through the old MR has stopped and cannot restart. The driver can then unpin the pages without a destroy reply.

Thanks,
Wei

#11 lore raw

Re: [PATCH net-next v11 3/4] net: mana: support concurrent HWC requests

In reply to Wei Hu
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] net: mana: skipped mana_gd_put_gic() on EQ teardown breaks remove_irqs() - [High] RDMA/mana_ib…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] net: mana: skipped mana_gd_put_gic() on EQ teardown breaks remove_irqs()
- [High] RDMA/mana_ib: returning errors in mana_ib_destroy_qp() breaks teardown
- [High] RDMA/mana_ib: mana_ib_destroy_cq() leaves dangling callback on rejection
- [Medium] net: mana: leaked GIC ref when mana_gd_create_mana_eq() is rejected
--

commit 2f3af75d69a80c300f076a62ab2f24d6ea93aab2
Author: Long Li <[email protected]>

net: mana: support concurrent HWC requests

This commit adds reference-counted HWC caller slots, serializes SQ posting, quarantines timed-out HWC slots, and propagates local HWC request rejections across MANA Ethernet and RDMA teardown paths.

Quoted 15 lines
drivers/infiniband/hw/mana/cq.c +1 -6
index 843e2c64b32bc..95b7c250494b1 100644
@@ -169,16 +170,14 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
 
 	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
 
-	mana_ib_remove_cq_cb(mdev, cq);
-
-	/* Ignore return code as there is not much we can do about it.
-	 * The error message is printed inside.
-	 */
-	mana_ib_gd_destroy_cq(mdev, cq);
+	err = mana_ib_gd_destroy_cq(mdev, cq);

drivers/infiniband/hw/mana/cq.c int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) · line 181

Quoted 10 lines
drivers/infiniband/hw/mana/cq.c +5 -2
+	if (mana_gd_is_request_rejected(err) ||
+	    READ_ONCE(cq->queue.retain_dma))
+		return err ? err : -ENOTCONN;
 
-	mana_ib_destroy_queue(mdev, &cq->queue);
+	mana_ib_remove_cq_cb(mdev, cq);
 
-	return 0;
+	return mana_ib_destroy_queue(mdev, &cq->queue);
 }

[Severity: High]
Does returning early here leave a dangling CQ callback in gc->cq_table[cq->queue.id]?

For kernel CQs, ib_free_cq() and the error path of __ib_alloc_cq() free the ib_cq even when destroy_cq() returns an error; for user CQs, uverbs_destroy_ufile_hw() falls back to RDMA_REMOVE_DRIVER_FAILURE and frees cq->ibcq.uobject. Because mana_ib_remove_cq_cb() and mana_gd_detach_cq() (called via mana_ib_destroy_queue() -> mana_gd_destroy_queue() for kernel CQs) are both skipped when mana_ib_gd_destroy_cq() is rejected or retain_dma is set, a subsequent completion EQE will invoke mana_ib_cq_handler() on the freed CQ or uobject.

Quoted 4 lines
drivers/infiniband/hw/mana/qp.c +0 -0
index 15c5d6cefd628..5e4eed814d61b 100644

[ ... ]

Quoted 43 lines
drivers/infiniband/hw/mana/qp.c +12 -9
@@ -1030,12 +1093,11 @@ static int mana_ib_destroy_rc_qp(struct mana_ib_qp *qp, struct ib_udata *udata)
 	if (err)
 		return err;
 
-	mana_table_remove_qp(mdev, qp);
+	err = mana_ib_gd_destroy_rnic_qp(mdev, qp);
+	if (mana_gd_is_request_rejected(err))
+		return err;
 
-	/* Ignore return code as there is not much we can do about it.
-	 * The error message is printed inside.
-	 */
-	mana_ib_gd_destroy_rnic_qp(mdev, qp);
+	mana_table_remove_qp(mdev, qp);
 	for (i = 0; i < MANA_RC_QUEUE_TYPE_MAX; ++i)
 		mana_ib_destroy_queue(mdev, &qp->rc_qp.queues[i]);
 
@@ -1052,11 +1114,11 @@ static int mana_ib_destroy_uc_qp(struct mana_ib_qp *qp, struct ib_udata *udata)
 	if (err)
 		return err;
 
+	err = mana_ib_gd_destroy_rnic_qp(mdev, qp);
+	if (mana_gd_is_request_rejected(err))
+		return err;
+
 	mana_table_remove_qp(mdev, qp);
-	/* Ignore return code as there is not much we can do about it.
-	 * The error message is printed inside.
-	 */
-	mana_ib_gd_destroy_rnic_qp(mdev, qp);
 	for (i = 0; i < MANA_UC_QUEUE_TYPE_MAX; ++i)
 		mana_ib_destroy_queue(mdev, &qp->uc_qp.queues[i]);
 
@@ -1073,16 +1135,16 @@ static int mana_ib_destroy_ud_qp(struct mana_ib_qp *qp, struct ib_udata *udata)
 	if (err)
 		return err;
 
+	err = mana_ib_gd_destroy_ud_qp(mdev, qp);
+	if (mana_gd_is_request_rejected(err))
+		return err;
+
 	mana_table_remove_qp(mdev, qp);
 	mana_remove_qp_from_cqs(qp, false);

drivers/infiniband/hw/mana/qp.c static int mana_ib_destroy_ud_qp(struct mana_ib_qp *qp, struct ib_udata *udata) · line 1149

Quoted 10 lines
drivers/infiniband/hw/mana/qp.c +0 -4
 
 	destroy_shadow_queue(&qp->shadow_rq);
 	destroy_shadow_queue(&qp->shadow_sq);
 
-	/* Ignore return code as there is not much we can do about it.
-	 * The error message is printed inside.
-	 */
-	mana_ib_gd_destroy_ud_qp(mdev, qp);
 	for (i = 0; i < MANA_UD_QUEUE_TYPE_MAX; ++i)
 		mana_ib_destroy_queue(mdev, &qp->ud_qp.queues[i]);

[Severity: High]
Can returning an error from mana_ib_destroy_{rc,uc,ud}_qp() before mana_table_remove_qp() and mana_remove_qp_from_cqs() cause a use-after-free during device removal or HWC reset recovery?

During mana_serv_reset() -> mana_gd_suspend() -> mana_rdma_remove() -> mana_ib_remove(), mana_drain_gsi_sqs() adds the kernel GSI QP to the MAD CQ's send_err_qp_list and schedules cq->work. When ib_unregister_device() then closes the MAD port, mana_ib_destroy_ud_qp() returns -ENOTCONN, which causes ib_destroy_qp_user() to abort without dropping port_priv->cq->usecnt or removing the QP from send_err_qp_list and mdev->qp_table_wq. ib_free_cq() then hits WARN_ON_ONCE(atomic_read(&cq->usecnt)) and skips cancelling cq->work before ib_dealloc_device() frees mdev, leaving ib_cq_poll_work() and EQE handlers to dereference freed memory.

In addition, create_qp()'s err_security unwind in drivers/infiniband/core/verbs.c ignores the return value of destroy_qp() and frees qp, and uverbs_destroy_ufile_hw() frees qp->uobject on RDMA_REMOVE_DRIVER_FAILURE, both leaving a freed QP in mdev->qp_table_wq.

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -0
index fc460d83fb800..0160ad55a21ff 100644

[ ... ]

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2 -1
@@ -1117,7 +1181,8 @@ static int mana_gd_create_eq(struct gdma_dev *gd,
 	return 0;
 out:
 	dev_err(dev, "Failed to create EQ: %d\n", err);
-	mana_gd_destroy_eq(gc, false, queue);
+	if (mana_gd_is_request_rejected(mana_gd_destroy_eq(gc, false, queue)))
+		err = -ENOTCONN;
 	queue->eq.msix_index = INVALID_PCI_MSIX_INDEX;
 	return err;
 }

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_main.c int mana_gd_create_mana_eq(struct gdma_dev *gd, · line 1460

Quoted 12 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +4 -1
@@ -1385,7 +1451,10 @@ int mana_gd_create_mana_eq(struct gdma_dev *gd,
 out:
 	dev_err(gc->dev, "Failed to create queue type %d of size: %u, err: %d\n",
 		spec->type, spec->queue_size, err);
-	mana_gd_free_memory(gmi);
+	if (!mana_gd_is_request_rejected(err) ||
+	    (gmi->dma_region_handle == GDMA_INVALID_DMA_REGION &&
+	     !queue->eq.disable_needed))
+		mana_gd_free_memory(gmi);
 free_q:
 	kfree(queue);
 	return err;

[Severity: Medium]
Does mana_gd_create_mana_eq() cause its callers (mana_create_eq() and mana_ib_create_eqs()) to leak the GIC reference and MSI-X bitmap entry when an HWC request is rejected before the hardware EQ exists, or when mana_gd_destroy_eq() succeeds after mana_gd_test_eq() is rejected?

In both cases queue->eq.disable_needed is false and queue is freed, yet mana_gd_create_mana_eq() still returns a rejected error code (-ENOTCONN or -ENODEV), so the callers skip mana_gd_put_gic(). Also, if mana_gd_create_dma_region() succeeded and mana_gd_create_eq() then fails before mana_gd_create_hw_eq() consumes gmi->dma_region_handle, the unwind path never calls mana_gd_destroy_dma_region().

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0 -0
index 744e6ceb7d2b9..1af0ed35c5988 100644

[ ... ]

drivers/net/ethernet/microsoft/mana/mana_en.c void mana_destroy_eq(struct mana_port_context *apc) · line 1800

Quoted 11 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2 -2
@@ -1791,8 +1793,8 @@ void mana_destroy_eq(struct mana_port_context *apc)
 			continue;
 
 		msi = eq->eq.msix_index;
-		mana_gd_destroy_queue(gc, eq);
-		mana_gd_put_gic(gc, !gc->msi_sharing, msi);
+		if (!mana_gd_is_request_rejected(mana_gd_destroy_queue(gc, eq)))
+			mana_gd_put_gic(gc, !gc->msi_sharing, msi);
 	}
 
 	kfree(apc->eqs);

[Severity: High]
Does skipping mana_gd_put_gic() here and in mana_ib_destroy_eqs() break mana_gd_remove_irqs() and mana_cdx_remove_irqs() during device reset or removal?

When HWC requests are rejected (for example after mana_serv_reset() calls mana_gd_cancel_hwc_timeout()), mana_gd_destroy_queue() returns -ENOTCONN after deregistering the EQ from gic->eq_list, and the callers free apc->eqs and mdev->eqs without dropping their gic->refcount references. When mana_gd_cleanup() then runs mana_gd_remove_irqs() or mana_cdx_remove_irqs(), it calls mana_gd_put_gic() only once per vector:

drivers/net/ethernet/microsoft/mana/gdma_pci.c:mana_gd_remove_irqs() {
	...
	xa_for_each(&gc->irq_contexts, msi, gic)
		mana_gd_put_gic(gc, false, msi);

	WARN_ON(!xa_empty(&gc->irq_contexts));

	pci_free_irq_vectors(pdev);
}

For any vector whose refcount was elevated by both setup_hwc_irqs and an EQ (such as MSI 0 used by fatal_err_eq, shared MSI vectors, or all vectors on CDX and non-dynamic MSI-X), refcount_dec_and_test(&gic->refcount) does not reach zero, so free_irq() and xa_erase() are skipped before WARN_ON(!xa_empty(&gc->irq_contexts)) and pci_free_irq_vectors() / msi_domain_free_irqs_all(), leaving the IRQ handlers registered when gc is freed or resumed.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#12 lore raw

Re: [PATCH net-next v11 3/4] net: mana: support concurrent HWC requests

In reply to Wei Hu
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.

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

Critical: 1 · High: 2 · Medium: 2 · Low: 0

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).

- [Critical] When a kernel CQ destroy is rejected locally, mana_ib_destroy_cq() leaves a dangling CQ callback, and a later…
- [High] EQ references to MSI-X/IRQ contexts (GIC references) that are kept after a rejected EQ destroy break mana_gd_remove_irqs() and the…
- [High] RDMA/mana_ib: returning errors in mana_ib_destroy_qp() breaks teardown
- [Medium] mana_create_eq() (mana_en.c) and mana_ib_create_eqs() (infiniband main.c) skip mana_gd_put_gic() whenever…
- [Medium] The Ethernet objects that are kept after a rejected destroy become unreachable, so they leak permanently on every service-reset…

--

net: mana: support concurrent HWC requests

This patch gives each HWC message slot separate sender and response references. Timed-out requests are quarantined until their late response arrives, and admission now waits on a waitqueue instead of a semaphore. It also adds a "locally rejected" error class (-ENOTCONN/-ENODEV/-EMSGSIZE) and propagates it through the Ethernet and RDMA destroy paths, so that memory the device may still own is retained instead of freed.

Quoted 4 lines
drivers/infiniband/hw/mana/cq.c +0 -0
index 843e2c64b32bc..95b7c250494b1 100644

[ ... ]

Quoted 4 lines
drivers/infiniband/hw/mana/cq.c +0 -0
@@ -169,16 +170,14 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
 
 	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
 

drivers/infiniband/hw/mana/cq.c int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) · line 176

Quoted 10 lines
drivers/infiniband/hw/mana/cq.c +4 -6
-	mana_ib_remove_cq_cb(mdev, cq);
-
-	/* Ignore return code as there is not much we can do about it.
-	 * The error message is printed inside.
-	 */
-	mana_ib_gd_destroy_cq(mdev, cq);
+	err = mana_ib_gd_destroy_cq(mdev, cq);
+	if (mana_gd_is_request_rejected(err) ||
+	    READ_ONCE(cq->queue.retain_dma))
+		return err ? err : -ENOTCONN;

[Severity: Critical]
Can this leave a dangling CQ callback for kernel CQs, which then runs on freed memory?

For a kernel CQ, mana_ib_install_cq_cb() puts cq->queue.kmem into the global table, and its context points back at the mana_ib_cq:

    gdma_cq->cq.context = cq;
    gdma_cq->cq.callback = mana_ib_cq_handler;
    gc->cq_table[cq->queue.id] = gdma_cq;

Before this patch the entry was always detached by mana_ib_destroy_queue()->mana_gd_destroy_queue(kmem)->mana_gd_destroy_cq(). With the early return above, neither mana_ib_remove_cq_cb() nor mana_ib_destroy_queue() runs when the destroy is rejected.

ib_free_cq() does not honour the driver's error, though:

drivers/infiniband/core/cq.c:ib_free_cq() {
    ...
	else
		ret = cq->device->ops.destroy_cq(cq, NULL);
	WARN_ONCE(ret, "Destroy of kernel CQ shouldn't fail");
	kfree(cq->wc);
	kfree(cq);
}

The freed mana_ib_cq can therefore still be reached through gc->cq_table. mana_gd_process_eqe() indexes that table with the cq_id from any EQE, whether it comes from an RDMA EQ, a still-live Ethernet EQ or the HWC EQ:

    cq = READ_ONCE(cq_table[cq_id]);
    ...
    if (cq->cq.callback)
        cq->cq.callback(cq->cq.context, cq);

mana_ib_cq_handler() then loads cq->ibcq.comp_handler from the freed object and calls through it.

One way to reach this is mana_serv_reset()->mana_gd_cancel_hwc_timeout(). After that, mana_gd_suspend()->mana_rdma_remove()->ib_unregister_device() tears down the GSI QP and calls ib_free_cq(). mana_ib_gd_destroy_cq() is rejected with -ENOTCONN because no slot is free and the timeout is 0. A single 30s timeout on the depth-one channel has the same effect, since it quarantines the only slot.

mana_ib_retain_qp() is a second trigger. After a rejected UD/GSI QP destroy in a create unwind, it sets retain_dma on the kernel send/recv CQs, so their later destroy also takes this early return.

The WARN_ONCE in ib_free_cq() also fires every time this path is taken.

Should the software callback for kernel CQs be withdrawn here unconditionally, even when the DMA memory has to be retained?

Quoted 7 lines
drivers/infiniband/hw/mana/cq.c +2 -2
-	mana_ib_destroy_queue(mdev, &cq->queue);
+	mana_ib_remove_cq_cb(mdev, cq);
 
-	return 0;
+	return mana_ib_destroy_queue(mdev, &cq->queue);
 }

[ ... ]

Quoted 4 lines
drivers/infiniband/hw/mana/main.c +0 -0
index 858bbc325eb29..7d5a8fc7380d7 100644

[ ... ]

drivers/infiniband/hw/mana/main.c int mana_ib_create_eqs(struct mana_ib_dev *mdev) · line 868

Quoted 9 lines
drivers/infiniband/hw/mana/main.c +2 -1
@@ -841,7 +862,8 @@ int mana_ib_create_eqs(struct mana_ib_dev *mdev)
 
 	err = mana_gd_create_mana_eq(mdev->gdma_dev, &spec, &mdev->fatal_err_eq);
 	if (err) {
-		mana_gd_put_gic(gc, false, 0);
+		if (!mana_gd_is_request_rejected(err))
+			mana_gd_put_gic(gc, false, 0);
 		return err;
 	}

[Severity: High]
Can a rejected destroy here leave the driver tracking a QP that the RDMA core then frees anyway?

mana_ib_destroy_ud_qp(), mana_ib_destroy_rc_qp() and mana_ib_destroy_uc_qp() now return before mana_table_remove_qp() and mana_remove_qp_from_cqs() when the HWC rejects the command. The core does not treat that error as "object still exists" in every caller.

First, ib_destroy_qp_user() returns the error without calling ib_qp_usecnt_dec(), so the PD and CQ usecnt stay elevated. For the kernel GSI QP this is on the same reset path as the CQ issue above:
mana_serv_reset()->mana_gd_cancel_hwc_timeout(), then mana_gd_suspend()->mana_rdma_remove()->mana_ib_remove().

mana_drain_gsi_sqs() first links the GSI QP onto the MAD CQ's send_err_qp_list and schedules cq->work. ib_unregister_device() then reaches ib_mad_port_close()->destroy_mad_qp(), which gets -ENOTCONN. ib_free_cq() hits WARN_ON_ONCE(atomic_read(&cq->usecnt)) and returns without cancelling the CQ work. ib_dealloc_pd() warns, port_priv is freed, and ib_dealloc_device() frees the mana_ib_dev. The queued CQ work and later EQEs still reach the QP through mdev->qp_table_wq and the CQ error lists, so they run on freed memory.

Second, the create_qp() unwind in drivers/infiniband/core/verbs.c ignores the destroy_qp() return value at its err_security label and does kfree(qp) unconditionally. mana_table_store_qp() has already run at that point, so mdev->qp_table_wq keeps a pointer to the freed QP. mana_get_qp_ref() then hands that pointer to mana_ib_event_handler() on the next GDMA_EQE_RNIC_QP_FATAL.

Third, on uverbs close or disassociation, uverbs_destroy_ufile_hw() falls back to RDMA_REMOVE_DRIVER_FAILURE. That path warns and frees the uobject anyway. The undestroyed QP stays in mdev->qp_table_wq, and its event handler dereferences the freed qp->uobject. The new error returns from mana_ib_destroy_wq() and mana_ib_destroy_cq() have the same problem on this path.

None of this needs unusual user action. A service reset, or a single timeout on the depth-one channel, is enough to make the destroys reject.

Could the destroy paths always drop the software state (qp table entry, CQ error lists, CQ callbacks) and retain only the PF-owned DMA mappings and umem, the way the Ethernet paths retain queue memory? If the verbs object itself really has to stay alive, how is that meant to work with core callers that cannot handle a failed destroy?

[Severity: Medium]
Does this leak the GIC reference when the rejected command was not the EQ disable?

Both this call site and the matching one in mana_create_eq() in mana_en.c decide whether to keep the GIC from the errno class alone. The assumption is that a rejected errno means the device still owns the vector. But mana_gd_create_mana_eq() also returns a rejected errno in cases where no device EQ refers to the vector.

First, mana_gd_create_dma_region() can be rejected before any IRQ or EQ exists. The region is still GDMA_INVALID_DMA_REGION and disable_needed is false, so this branch frees the memory and still returns -ENOTCONN/-ENODEV:

    if (!mana_gd_is_request_rejected(err) ||
        (gmi->dma_region_handle == GDMA_INVALID_DMA_REGION &&
         !queue->eq.disable_needed))
        mana_gd_free_memory(gmi);

Second, mana_gd_create_hw_eq() can be rejected while disable_needed is still false. Third, mana_gd_test_eq() can be rejected after create_hw_eq() succeeded, and the cleanup disable then completes. In both cases mana_gd_create_eq() keeps the original rejected err, because it only remaps when the destroy itself is rejected:

if (mana_gd_is_request_rejected(mana_gd_destroy_eq(gc, false, queue)))
err = -ENOTCONN;

In each of these cases the reference from mana_gd_get_gic() is never dropped, and in dedicated-MSI mode the msi_bitmap bit also stays set.

Could mana_gd_create_mana_eq() report whether the vector is still in use by the device, instead of the callers inferring it from the errno?

[ ... ]

drivers/infiniband/hw/mana/main.c int mana_ib_create_eqs(struct mana_ib_dev *mdev) · line 921

Quoted 11 lines
drivers/infiniband/hw/mana/main.c +0 -0
 void mana_ib_destroy_eqs(struct mana_ib_dev *mdev)

{

drivers/infiniband/hw/mana/main.c +4 -3
 	struct gdma_context *gc = mdev_to_gc(mdev);
-	int i, msi;
+	int err, i, msi;
 
-	mana_gd_destroy_queue(gc, mdev->fatal_err_eq);
-	mana_gd_put_gic(gc, false, 0);
+	err = mana_gd_destroy_queue(gc, mdev->fatal_err_eq);
+	if (!mana_gd_is_request_rejected(err))
+		mana_gd_put_gic(gc, false, 0);

[Severity: High]
What releases this retained GIC reference later?

Neither mana_ib_destroy_eqs() nor mana_destroy_eq() in mana_en.c keeps the EQ anywhere afterwards; mana_destroy_eq() frees apc->eqs right after this loop. mana_gd_remove_irqs() was not updated and still drops exactly one reference per irq_contexts entry:

drivers/net/ethernet/microsoft/mana/gdma_pci.c:mana_gd_remove_irqs() {
    ...
	xa_for_each(&gc->irq_contexts, msi, gic)
		mana_gd_put_gic(gc, false, msi);

	WARN_ON(!xa_empty(&gc->irq_contexts));

	pci_free_irq_vectors(pdev);
    ...
}

If an EQ destroy was rejected, that GIC keeps a reference of 1. free_irq() and xa_erase() never run for it, the WARN_ON fires, and pci_free_irq_vectors() frees vectors whose handlers are still requested.

On the next mana_gd_resume() for the same gc, mana_gd_setup_irqs()->mana_gd_get_gic() finds the stale entry:

    gic = xa_load(&gc->irq_contexts, msix_index);
    if (gic) {
        refcount_inc(&gic->refcount);
        ...
        goto out;
    }

request_irq() is never called on the newly allocated vector, and the old gic->irq is used instead. msi 0 is shared between fatal_err_eq and the HWC EQ, so would the new HWC come up without a working interrupt after a service reset?

The path is mana_serv_reset()->mana_gd_cancel_hwc_timeout(), then mana_gd_suspend()->mana_rdma_remove()->mana_ib_destroy_eqs(), where mana_gd_disable_queue() gets -ENOTCONN. mana_destroy_eq() then does the same for each Ethernet EQ, and finally mana_gd_cleanup() calls mana_gd_remove_irqs().

Quoted 11 lines
drivers/infiniband/hw/mana/main.c +3 -2
 	for (i = 0; i < mdev->ib_dev.num_comp_vectors; i++) {
-		mana_gd_destroy_queue(gc, mdev->eqs[i]);
 		msi = (i + 1) % gc->num_msix_usable;
-		mana_gd_put_gic(gc, false, msi);
+		err = mana_gd_destroy_queue(gc, mdev->eqs[i]);
+		if (!mana_gd_is_request_rejected(err))
+			mana_gd_put_gic(gc, false, msi);
 	}
 
 	kfree(mdev->eqs);

[ ... ]

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0 -0
index 744e6ceb7d2b9..1af0ed35c5988 100644

[ ... ]

Quoted 1 line
drivers/net/ethernet/microsoft/mana/mana_en.c +0 -0
@@ -2730,21 +2733,29 @@ static void mana_destroy_txq(struct mana_port_context *apc)

[ ... ]

drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_destroy_txq(struct mana_port_context *apc) · line 2761

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7 -0
+		if (mana_gd_is_request_rejected(err)) {
+			if (apc->tx_qp[i]->tx_cq.gdma_cq)
+				mana_gd_detach_cq(gc,
+						  apc->tx_qp[i]->tx_cq.gdma_cq);
+			continue;
+		}
+
 		mana_deinit_cq(apc, &apc->tx_qp[i]->tx_cq);
 
 		mana_deinit_txq(apc, &apc->tx_qp[i]->txq);

[Severity: Medium]
After the continue, what still points to the retained tx_qp[i]?

The loop is followed by:

    kfree(apc->tx_qp);
    apc->tx_qp = NULL;

So the retained mana_tx_qp, its CQ/SQ queues and their DMA memory become unreachable. mana_destroy_rxq() is similar. It returns before page_pool_destroy(), the RX page frees and kvfree(rxq), and the caller then sets apc->rxqs[idx] to NULL. mana_destroy_eq() also skips the EQ free and the GIC put, then calls kfree(apc->eqs).

This patch also makes mana_serv_reset() call mana_gd_cancel_hwc_timeout() before mana_gd_suspend(). With the timeout at 0, the first teardown command is posted and abandoned. Every later admission in mana_hwc_try_get_msg_index() then returns -ENOTCONN:

    if (!mana_hwc_timeout_read(hwc) ||
        (u32)atomic_read(&hwc->abandoned_msgs) == r->size)
        err = -ENOTCONN;

As a result, most destroys in mana_remove()->mana_dealloc_queues() take these retain branches on every service reset. In the baseline those commands were posted, returned -ETIMEDOUT, and the memory was freed.

Is this unbounded per-reset leak intended? The commit message says:

"Preserve the baseline cleanup policy for commands that were actually posted and then timed out or received PF errors"

It does not mention that the cancellation in mana_serv_reset() turns most reset-time teardown into local rejection. If the objects have to be retained, could they be kept somewhere they can be reclaimed once the function has been reset, instead of being orphaned?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794751992.git.weh%40linux.microsoft.com
author
#13 lore raw

Re: [PATCH net-next v11 3/4] net: mana: support concurrent HWC requests

Quoted 2 lines · netdev-bot+sashiko

Can this leave a dangling CQ callback for kernel CQs, which then runs on freed memory?

Yes. ib_free_cq() can free the CQ even when destroy returns an error. I removed the v11 early return so the normal CQ teardown withdraws the callback. This doesn't fix the separate upstream race with a reader of the RDMA CQ table.

Quoted 2 lines

Can a rejected destroy here leave the driver tracking a QP that the RDMA core then frees anyway?

Yes. V12 also drops the QP early return: teardown removes the QP from the driver's table and CQ lists rather than relying on a retry.

Quoted 2 lines

Does this leak the GIC reference when the rejected command was not the EQ disable?

Yes. V12 restores the upstream EQ-create unwind. If creating the EQ fails, its caller drops the IRQ-context reference; it doesn't use the HWC error code to decide whether to keep it.

Quoted 1 line

What releases this retained GIC reference later?

V12 doesn't retain that extra reference on EQ teardown. The last mana_gd_put_gic() unregisters the handler before freeing a dynamic MSI-X vector.

Quoted 1 line

After the continue, what still points to the retained tx_qp[i]?

Nothing in v11 once the parent is freed. V12 keeps the upstream Ethernet TX, RX and EQ teardown instead of retaining those queues.

At the normal response timeout of a posted HWC command, the PF has drained DMA to the old queues and packet buffers, as well as interrupt writes. Unanswered commands haven't taken effect. V12 stops posting on that HWC and won't accept a handle from a late reply. A reset notice, a failed post or a wait for a free slot gives no such guarantee. The HWC's own rings and buffers still require a DESTROY_HWC ack.

Thanks,
Wei

pw-bot: cr

author
#14 lore raw

PATCH v11 4/4 net: mana: add dynamic HWC queue depth with reinit path

In reply to Wei Hu

From: Long Li <[email protected]>

The HWC starts with depth-one bootstrap queues. Treat the PF-reported depth as a maximum and rebuild the channel exactly for reports from 2 through
128. Keep the untouched bootstrap queues for depth one and reports above 128, and require a rebuilt channel to repeat the selected depth.

Treat the reported request and response sizes as directional maxima. Rebuild only when both reports equal the 4096-byte bootstrap allocation. Keep allocation strides separate from these limits, and share the effective host-to-PF request budget with the GDMA and RDMA request builders. Bound RDMA CREATE and ADD_PAGES batches by that budget, checking that the headers and at least one page address fit before subtracting their sizes.

Require nonzero depth, request-size and response-size reports before deciding whether to keep the bootstrap queues. Apply the same validation to a restored bootstrap channel. A missing or zero required report fails with -EPROTO, even at depth one; do not silently substitute guessed limits.

Reject oversized messages before acquiring a slot or publishing caller storage. A retained, stopped channel still returns -ENODEV rather than reporting a size error against uninitialized negotiated limits.

Keep each candidate private through queue creation, establishment and the direct EQ test. Publish only the final tested channel. If a rebuild fails, including its functional test, tear it down and restore fresh, tested bootstrap queues. Stop if teardown is not acknowledged; never reuse PF-owned mappings. Restore the previous live timeout budget before the fallback so a failed test's fail-fast reduction does not poison the retry, without reviving terminal cancellation.

Invalidate the previous HWC doorbell before every ESTABLISH_HWC. Validate the BAR0 page geometry and reported index before accepting a new doorbell, and suppress MMIO while it is invalid. The original driver accepted an unchecked device-supplied index in its MMIO address calculation; this also fixes that existing out-of-bounds MMIO path. Backports need the complete ownership and validation dependencies, not the entire feature stack by default. A malformed doorbell completes initialization with -EPROTO without relying on later INIT_DONE events that might require re-arming through that doorbell.

Use the initial PF report to select the queue geometry. The PF directs this choice; the absence of VF size fields in ESTABLISH_HWC does not require keeping the bootstrap geometry. Driver-version advertisement occurs after HWC establishment and cannot negotiate behavior needed during creation.

Copilot-Session: 8c2361e6-c0f4-4b0c-bf01-b5e4cdacec50

---
 drivers/infiniband/hw/mana/main.c             |  19 +-
 .../net/ethernet/microsoft/mana/gdma_main.c   |  26 +-
 .../net/ethernet/microsoft/mana/hw_channel.c  | 316 +++++++++++++++---
 include/net/mana/gdma.h                       |   2 +
 include/net/mana/hw_channel.h                 |  19 +-
 5 files changed, 317 insertions(+), 65 deletions(-)
drivers/infiniband/hw/mana/main.c +13 -6
index 7d5a8fc7380d..6e036a25a9f7 100644
@@ -427,28 +427,38 @@ static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem
 	unsigned int create_req_msg_size;
 	struct hw_channel_context *hwc;
 	struct ib_block_iter biter;
-	size_t max_pgs_add_cmd = 0;
+	size_t max_pgs_add_cmd;
 	size_t max_pgs_create_cmd;
 	struct gdma_context *gc;
 	size_t num_pages_total;
 	unsigned int tail = 0;
+	u32 req_limit;
 	u64 *page_addr_list;
 	void *request_buf;
 	int err = 0;
 
 	gc = mdev_to_gc(dev);
 	hwc = gc->hwc.driver_data;
+	req_limit = mana_hwc_get_max_req_size(hwc);
+	if (req_limit < struct_size(create_req, page_addr_list, 1) ||
+	    req_limit < struct_size(add_req, page_addr_list, 1)) {
+		ibdev_dbg(&dev->ib_dev,
+			  "HWC request budget %u is too small for DMA region commands\n",
+			  req_limit);
+		return -EMSGSIZE;
+	}
 
 	num_pages_total = ib_umem_num_dma_blocks(umem, page_sz);
 
 	max_pgs_create_cmd =
-		(hwc->max_req_msg_size - sizeof(*create_req)) / sizeof(u64);
+		(req_limit - sizeof(*create_req)) / sizeof(u64);
+	max_pgs_add_cmd = (req_limit - sizeof(*add_req)) / sizeof(u64);
 	num_pages_to_handle =
 		min_t(size_t, num_pages_total, max_pgs_create_cmd);
 	create_req_msg_size =
 		struct_size(create_req, page_addr_list, num_pages_to_handle);
 
-	request_buf = kzalloc(hwc->max_req_msg_size, GFP_KERNEL);
+	request_buf = kzalloc(req_limit, GFP_KERNEL);
 	if (!request_buf)
 		return -ENOMEM;
 
@@ -491,9 +501,6 @@ static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem
 			if (err)
 				goto out;
 
-			max_pgs_add_cmd = (hwc->max_req_msg_size -
-				sizeof(*add_req)) / sizeof(u64);
-
 			add_req = request_buf;
 			add_req->dma_region_handle = *gdma_region;
 			add_req->reserved3 = 0;
drivers/net/ethernet/microsoft/mana/gdma_main.c +17 -9
index 0160ad55a21f..6d766d84ec05 100644
@@ -589,12 +589,26 @@ static int mana_gd_disable_queue(struct gdma_queue *queue)
 #define DOORBELL_OFFSET_EQ	0xFF8
 #define DOORBELL_OFFSET_DIM	0x820
 
+bool mana_gd_is_valid_doorbell(struct gdma_context *gc, u32 db_id)
+{
+	if (!gc->db_page_size || gc->db_page_off >= gc->bar0_size)
+		return false;
+
+	return gc->db_page_off +
+	       gc->db_page_size * ((u64)db_id + 1) <= gc->bar0_size;
+}
+
 static void mana_gd_ring_doorbell(struct gdma_context *gc, u32 db_index,
 				  enum gdma_queue_type q_type, u32 qid,
 				  u32 tail_ptr, u8 num_req, u8 client_offset)
 {
-	void __iomem *addr = gc->db_page_base + gc->db_page_size * db_index;
 	union gdma_doorbell_entry e = {};
+	void __iomem *addr;
+
+	if (unlikely(db_index == INVALID_DOORBELL))
+		return;
+
+	addr = gc->db_page_base + gc->db_page_size * db_index;
 
 	addr += client_offset;
 
@@ -1348,7 +1362,7 @@ static int mana_gd_create_dma_region(struct gdma_dev *gd,
 	/* The caller must keep the HWC alive throughout queue creation. */
 	hwc = gc->hwc.driver_data;
 	req_msg_size = struct_size(req, page_addr_list, num_page);
-	if (req_msg_size > hwc->max_req_msg_size)
+	if (req_msg_size > mana_hwc_get_max_req_size(hwc))
 		return -EINVAL;
 
 	req = kzalloc(req_msg_size, GFP_KERNEL);
@@ -1637,13 +1651,7 @@ int mana_gd_register_device(struct gdma_dev *gd)
 		return err ? err : -EPROTO;
 	}
 
-	/* Validate that doorbell page for db_id is within the BAR0 region.
-	 * In mana_gd_ring_doorbell(), the address is calculated as:
-	 *   addr = db_page_base + db_page_size * db_id
-	 *        = (bar0_va + db_page_off) + (db_page_size * db_id)
-	 * So we need: db_page_off + db_page_size * (db_id + 1) <= bar0_size
-	 */
-	if (gc->db_page_off + gc->db_page_size * ((u64)resp.db_id + 1) > gc->bar0_size) {
+	if (!mana_gd_is_valid_doorbell(gc, resp.db_id)) {
 		dev_err(gc->dev, "Doorbell ID %u out of range\n", resp.db_id);
 		return -EPROTO;
 	}
drivers/net/ethernet/microsoft/mana/hw_channel.c +267 -49

438 lines not on this page · raw message

include/net/mana/gdma.h +2 -0
index 2e60e401b2e6..e4934c357c29 100644
@@ -621,6 +621,8 @@ void mana_gd_fence_eq(struct gdma_context *gc, struct gdma_queue *queue);
 
 int mana_gd_poll_cq(struct gdma_queue *cq, struct gdma_comp *comp, int num_cqe);
 
+bool mana_gd_is_valid_doorbell(struct gdma_context *gc, u32 db_id);
+
 void mana_gd_ring_cq(struct gdma_queue *cq, u8 arm_bit);
 
 ssize_t mana_gd_read_ring(struct gdma_queue *q, char __user *buf,
include/net/mana/hw_channel.h +18 -1
index 8f2ac3d37770..fd6d04e1e5cb 100644
@@ -5,6 +5,7 @@
 #define _HW_CHANNEL_H
 
 #include <linux/atomic.h>
+#include <linux/minmax.h>
 
 #define DEFAULT_LOG2_THROTTLING_FOR_ERROR_EQ  4
 
@@ -13,6 +14,9 @@
 
 #define HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH 1
 
+/* Largest supported rebuild depth; larger reports retain bootstrap queues. */
+#define HW_CHANNEL_MAX_QUEUE_DEPTH 128
+
 #define HWC_INIT_DATA_CQID		1
 #define HWC_INIT_DATA_RQID		2
 #define HWC_INIT_DATA_SQID		3
@@ -200,12 +204,18 @@ struct hw_channel_context {
 
 	u16 num_inflight_msg;
 	u32 max_req_msg_size;
+	u32 max_resp_msg_size;
+	/* Immutable reported maxima for the final RQ and SQ directions. */
+	u32 rx_msg_size_limit;
+	u32 tx_msg_size_limit;
 
-	u16 hwc_init_q_depth_max;
+	u32 hwc_init_q_depth_max;
 	u32 hwc_init_max_req_msg_size;
 	u32 hwc_init_max_resp_msg_size;
 	u32 hwc_init_max_num_cqs;
 	u32 hwc_init_cq_id;
+	bool hwc_init_doorbell;
+	int hwc_init_error;
 
 	struct completion hwc_init_eqe_comp;
 
@@ -240,6 +250,13 @@ struct hw_channel_context {
 	struct hwc_caller_ctx *caller_ctx;
 };
 
+/* Host-to-PF requests are bounded by the negotiated TX limit and SQ stride. */
+static inline u32
+mana_hwc_get_max_req_size(const struct hw_channel_context *hwc)
+{
+	return min(hwc->tx_msg_size_limit, hwc->max_resp_msg_size);
+}
+
 int mana_hwc_create_channel(struct gdma_context *gc);
 void mana_hwc_destroy_channel(struct gdma_context *gc);
 void mana_hwc_free_retained_channel(struct gdma_context *gc);
Signature · 1 line
2.43.0
#15 lore raw

Re: [PATCH net-next v11 4/4] net: mana: add dynamic HWC queue depth with reinit path

Quoted 81 lines · Wei Hu

From: Long Li <[email protected]>

The HWC starts with depth-one bootstrap queues. Treat the PF-reported depth as a maximum and rebuild the channel exactly for reports from 2 through
128. Keep the untouched bootstrap queues for depth one and reports above 128, and require a rebuilt channel to repeat the selected depth.

Treat the reported request and response sizes as directional maxima. Rebuild only when both reports equal the 4096-byte bootstrap allocation. Keep allocation strides separate from these limits, and share the effective host-to-PF request budget with the GDMA and RDMA request builders. Bound RDMA CREATE and ADD_PAGES batches by that budget, checking that the headers and at least one page address fit before subtracting their sizes.

Require nonzero depth, request-size and response-size reports before deciding whether to keep the bootstrap queues. Apply the same validation to a restored bootstrap channel. A missing or zero required report fails with -EPROTO, even at depth one; do not silently substitute guessed limits.

Reject oversized messages before acquiring a slot or publishing caller storage. A retained, stopped channel still returns -ENODEV rather than reporting a size error against uninitialized negotiated limits.

Keep each candidate private through queue creation, establishment and the direct EQ test. Publish only the final tested channel. If a rebuild fails, including its functional test, tear it down and restore fresh, tested bootstrap queues. Stop if teardown is not acknowledged; never reuse PF-owned mappings. Restore the previous live timeout budget before the fallback so a failed test's fail-fast reduction does not poison the retry, without reviving terminal cancellation.

Invalidate the previous HWC doorbell before every ESTABLISH_HWC. Validate the BAR0 page geometry and reported index before accepting a new doorbell, and suppress MMIO while it is invalid. The original driver accepted an unchecked device-supplied index in its MMIO address calculation; this also fixes that existing out-of-bounds MMIO path. Backports need the complete ownership and validation dependencies, not the entire feature stack by default. A malformed doorbell completes initialization with -EPROTO without relying on later INIT_DONE events that might require re-arming through that doorbell.

Use the initial PF report to select the queue geometry. The PF directs this choice; the absence of VF size fields in ESTABLISH_HWC does not require keeping the bootstrap geometry. Driver-version advertisement occurs after HWC establishment and cannot negotiate behavior needed during creation.

Copilot-Session: 8c2361e6-c0f4-4b0c-bf01-b5e4cdacec50

---
 drivers/infiniband/hw/mana/main.c             |  19 +-
 .../net/ethernet/microsoft/mana/gdma_main.c   |  26 +-
 .../net/ethernet/microsoft/mana/hw_channel.c  | 316 +++++++++++++++---
 include/net/mana/gdma.h                       |   2 +
 include/net/mana/hw_channel.h                 |  19 +-
 5 files changed, 317 insertions(+), 65 deletions(-)
drivers/infiniband/hw/mana/main.c +2 -1
index 7d5a8fc7380d..6e036a25a9f7 100644
@@ -427,28 +427,38 @@ static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem
 	unsigned int create_req_msg_size;
 	struct hw_channel_context *hwc;
 	struct ib_block_iter biter;
-	size_t max_pgs_add_cmd = 0;
+	size_t max_pgs_add_cmd;
 	size_t max_pgs_create_cmd;
 	struct gdma_context *gc;
 	size_t num_pages_total;
 	unsigned int tail = 0;
+	u32 req_limit;
 	u64 *page_addr_list;
 	void *request_buf;
 	int err = 0;
 

drivers/infiniband/hw/mana/main.c static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem · line 449

Quoted 10 lines
drivers/infiniband/hw/mana/main.c +8 -0
 	gc = mdev_to_gc(dev);
 	hwc = gc->hwc.driver_data;
+	req_limit = mana_hwc_get_max_req_size(hwc);
+	if (req_limit < struct_size(create_req, page_addr_list, 1) ||
+	    req_limit < struct_size(add_req, page_addr_list, 1)) {
+		ibdev_dbg(&dev->ib_dev,
+			  "HWC request budget %u is too small for DMA region commands\n",
+			  req_limit);
+		return -EMSGSIZE;
+	}

No. Make sure you also call mana_ib_gd_create_dma_region() with valid parameters.

Thanks

author
#16 lore raw

Re: [PATCH net-next v11 4/4] net: mana: add dynamic HWC queue depth with reinit path

Quoted 2 lines · Leon Romanovsky

No. Make sure you also call mana_ib_gd_create_dma_region() with valid parameters.

Both callers already reject unsupported page sizes. The guard you quoted checks the HWC's capacity, not an argument from either caller. Before RDMA probe, the channel has already carried a 640-byte version request. With one page address, CREATE needs 72 bytes and ADD_PAGES needs 64.

I dropped the redundant guard and its debug message in v12. Both commands still limit their batch size to what the channel negotiated.

Thanks,
Wei

#17 lore raw

Re: [PATCH net-next v11 4/4] net: mana: add dynamic HWC queue depth with reinit path

In reply to Wei Hu
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] net: mana: swapped HWC request/response limits in mana_hwc_finish_channel() - [Medium] net: mana…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] net: mana: swapped HWC request/response limits in mana_hwc_finish_channel()
- [Medium] net: mana: duplicate mana_hwc_teardown_queues() on HWC rebuild failure
--

commit 3fabf9cbfe8a174f5953b462e57e3b1f0fcf54f1
Author: Long Li <[email protected]>

net: mana: add dynamic HWC queue depth with reinit path

This commit adds support for dynamically rebuilding the MANA hardware channel queues to the PF-reported queue depth (up to 128), validating reported message size limits and doorbells, and falling back to bootstrap queues if rebuilding fails.

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0 -0
index 8c2495ce5f526..cb73d0725206e 100644

[ ... ]

Quoted 38 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +33 -1
@@ -1175,32 +1256,169 @@ void mana_hwc_free_retained_channel(struct gdma_context *gc)
 	gc->hwc.gdma_context = NULL;
 }
 
-static int mana_hwc_create_bootstrap_channel(struct hw_channel_context *hwc)
+static int
+mana_hwc_validate_report(struct hw_channel_context *hwc,
+			 const struct mana_hwc_init_report *report,
+			 u32 expected_depth, bool check_depth,
+			 bool require_exact_msg_sizes)
+{
+	if (!report->queue_depth || !report->max_req_msg_size ||
+	    !report->max_resp_msg_size) {
+		dev_err(hwc->dev,
+			"HWC: invalid maxima depth=%u req=%u resp=%u\n",
+			report->queue_depth, report->max_req_msg_size,
+			report->max_resp_msg_size);
+		return -EPROTO;
+	}
+
+	if (require_exact_msg_sizes &&
+	    (report->max_req_msg_size != HW_CHANNEL_MAX_REQUEST_SIZE ||
+	     report->max_resp_msg_size != HW_CHANNEL_MAX_RESPONSE_SIZE)) {
+		dev_err(hwc->dev,
+			"HWC: rebuilt message maxima req=%u resp=%u, expected %u/%u\n",
+			report->max_req_msg_size, report->max_resp_msg_size,
+			HW_CHANNEL_MAX_REQUEST_SIZE,
+			HW_CHANNEL_MAX_RESPONSE_SIZE);
+		return -EPROTO;
+	}
+
+	if (check_depth && report->queue_depth != expected_depth) {
+		dev_err(hwc->dev, "HWC: rebuilt depth %u, expected %u\n",
+			report->queue_depth, expected_depth);
+		return -EPROTO;
+	}
+
+	return 0;

drivers/net/ethernet/microsoft/mana/hw_channel.c void mana_hwc_free_retained_channel(struct gdma_context *gc) · line 1301

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +10 -0
+}
+
+static int mana_hwc_finish_channel(struct hw_channel_context *hwc,
+				   const struct mana_hwc_init_report *report)
+{
+	int err;
+
+	/* MAX_REQUEST sizes the RQ; MAX_RESPONSE sizes the SQ. */
+	hwc->rx_msg_size_limit = report->max_req_msg_size;
+	hwc->tx_msg_size_limit = report->max_resp_msg_size;

[Severity: Medium]
Are rx_msg_size_limit and tx_msg_size_limit swapped here?

On the HWC, the host sends requests over hwc->txq (GDMA_SQ) in mana_hwc_send_request() and receives responses over hwc->rxq (GDMA_RQ) in mana_hwc_rx_event_handler(). Because tx_msg_size_limit is populated from report->max_resp_msg_size and rx_msg_size_limit from report->max_req_msg_size, mana_hwc_get_max_req_size() and mana_hwc_get_msg_index() check outgoing req_len against the PF-reported response limit and incoming resp_len against the request limit.

When the PF reports asymmetric HWC_INIT_DATA_MAX_REQUEST and HWC_INIT_DATA_MAX_RESPONSE values (where mana_hwc_prepare_channel() keeps the bootstrap queues), a smaller MAX_RESPONSE will cause outgoing requests such as mana_gd_create_dma_region() and mana_ib_gd_create_dma_region() to be capped or rejected with -EMSGSIZE or -EINVAL against the response limit.

Quoted 7 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +7 -0
+
+	err = mana_hwc_test_channel(hwc);
+	if (err)
+		dev_err(hwc->dev, "Failed to test HWC: %d\n", err);
+
+	return err;
+}

[ ... ]

Quoted 28 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +28 -0
+static int mana_hwc_rebuild_channel(struct hw_channel_context *hwc,
+				    u16 q_depth,
+				    struct mana_hwc_init_report *report)
+{
+	u32 timeout_ms = mana_hwc_timeout_read(hwc);
+	int cleanup_err;
+	int err;
+
+	err = mana_hwc_teardown_queues(hwc);
+	if (err)
+		return err;
+
+	err = mana_hwc_build_channel(hwc, q_depth, report);
+	if (!err)
+		err = mana_hwc_validate_report(hwc, report, q_depth,
+					       true, true);
+	if (!err)
+		err = mana_hwc_finish_channel(hwc, report);
+	if (!err)
+		return 0;
+
+	dev_warn(hwc->dev,
+		 "HWC depth %u rebuild failed, restoring bootstrap: %d\n",
+		 q_depth, err);
+
+	cleanup_err = mana_hwc_teardown_queues(hwc);
+	if (cleanup_err)
+		return cleanup_err;

[ ... ]

drivers/net/ethernet/microsoft/mana/hw_channel.c int mana_hwc_create_channel(struct gdma_context *gc) · line 1457

Quoted 9 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +1 -1
@@ -1233,7 +1451,7 @@ int mana_hwc_create_channel(struct gdma_context *gc)
 	gd->pdid = INVALID_PDID;
 	gd->doorbell = INVALID_DOORBELL;
 
-	err = mana_hwc_create_bootstrap_channel(hwc);
+	err = mana_hwc_prepare_channel(hwc);
 	if (err) {
 		mana_hwc_release_channel(hwc);
 		return err;

[Severity: Medium]
Does failing inside mana_hwc_teardown_queues() during mana_hwc_rebuild_channel() cause mana_hwc_release_channel() to run mana_hwc_teardown_queues() a second time on the same active channel?

When mana_smc_teardown_hwc() fails in mana_hwc_teardown_queues(), hwc->setup_active remains true and the channel is fenced, and that error is returned through mana_hwc_prepare_channel() to mana_hwc_create_channel(). mana_hwc_release_channel() then calls mana_hwc_teardown_queues() again while hwc->setup_active is still true, issuing a second SMC teardown transaction that can stall in mana_smc_poll_register() for another 20 to 40 seconds or send a duplicate SMC_MSG_TYPE_DESTROY_HWC if the PF completed the first teardown right after it timed out.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#18 lore raw

Re: [PATCH net-next v11 4/4] net: mana: add dynamic HWC queue depth with reinit path

In reply to Wei Hu
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

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

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

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] The only defect fix in this commit is the HWC doorbell validation and MMIO suppression: mana_gd_is_valid_doorbell(), the…
- [Medium] The rebuilt HWC gives the PF rings much larger than the bootstrap rings, but ESTABLISH_HWC carries no size information.
- [Medium] mana_hwc_finish_channel() maps the PF's HWC_INIT_DATA_MAX_REQUEST report to the VF receive direction…
- [Low] mana_hwc_rebuild_channel() saves timeout_ms = mana_hwc_timeout_read(hwc) on entry.

--

net: mana: add dynamic HWC queue depth with reinit path

The HWC starts on depth-one bootstrap queues. This commit rebuilds it at the depth the PF reports (2 through 128), falling back to fresh bootstrap queues if the rebuild fails. It also applies the PF-reported message sizes as admission limits shared with the GDMA and RDMA request builders. It validates the device-supplied HWC doorbell index against BAR0 and skips doorbell MMIO while the doorbell is invalid.

Quoted 5 lines

and suppress MMIO while it is invalid. The original driver accepted an unchecked device-supplied index in its MMIO address calculation; this also fixes that existing out-of-bounds MMIO path. Backports need the complete ownership and validation dependencies, not the entire feature stack by default.

[ ... ]

Quoted 1 line
Fixes ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")

[Severity: Medium]
Should this be split into two patches?

As far as I can tell, the only defect fix here is the HWC doorbell validation:

- mana_gd_is_valid_doorbell()
- the GDMA_EQE_HWC_INIT_EQ_ID_DB check in mana_hwc_init_event_handler()
- the INVALID_DOORBELL early return in mana_gd_ring_doorbell()
- invalidating gc->hwc.doorbell before every ESTABLISH_HWC

Everything else is new behaviour:

- the depth rebuild in mana_hwc_prepare_channel() and mana_hwc_rebuild_channel()
- the new -EMSGSIZE admission check in mana_hwc_get_msg_index()
- the new request budget in mana_gd_create_dma_region() and mana_ib_gd_create_dma_region()
- power-of-two rounding in mana_hwc_alloc_dma_buf()
- new -EPROTO probe failures from mana_hwc_validate_report() when the QUEUE_DEPTH, MAX_REQUEST or MAX_RESPONSE report is zero or missing, even at depth one

Before this patch, mana_hwc_establish_channel() read those reported values but nothing used them.

With the Fixes: tag on this commit, stable selection could pull the whole feature into stable kernels, including the new probe failures. The commit message says the feature stack should not be backported by default. However, the fix can't be taken on its own while both are in one commit.

Could the doorbell validation go into its own patch with the Fixes: tag, and the dynamic depth work be sent without one?

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0 -0
index 8c2495ce5f526..cb73d0725206e 100644

[ ... ]

Quoted 1 line
drivers/net/ethernet/microsoft/mana/hw_channel.c +0 -0
@@ -1175,32 +1256,169 @@ void mana_hwc_free_retained_channel(struct gdma_context *gc)

[ ... ]

drivers/net/ethernet/microsoft/mana/hw_channel.c void mana_hwc_free_retained_channel(struct gdma_context *gc) · line 1301

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +8 -0
+static int mana_hwc_finish_channel(struct hw_channel_context *hwc,
+				   const struct mana_hwc_init_report *report)
+{
+	int err;
+
+	/* MAX_REQUEST sizes the RQ; MAX_RESPONSE sizes the SQ. */
+	hwc->rx_msg_size_limit = report->max_req_msg_size;
+	hwc->tx_msg_size_limit = report->max_resp_msg_size;

[Severity: Medium]
Are these two limits applied in the right directions?

mana_hwc_get_max_req_size() returns:

	return min(hwc->tx_msg_size_limit, hwc->max_resp_msg_size);

So the PF's MAX_RESPONSE report caps outgoing VF-to-PF requests in mana_hwc_get_msg_index(), mana_gd_create_dma_region() and mana_ib_gd_create_dma_region(). MAX_REQUEST caps the response buffers.

Before this patch, mana_gd_create_dma_region() and mana_ib_gd_create_dma_region() bounded outgoing requests by hwc->max_req_msg_size.

The comment here seems to follow the stride naming in mana_hwc_init_queues(), where the RQ is created with HW_CHANNEL_MAX_REQUEST_SIZE. The old code never used the reported sizes, so nothing in the tree shows which direction the PF means.

If the PF reports different sizes, the bootstrap channel is kept and these limits are used:

- MAX_REQUEST=2048 and MAX_RESPONSE=4096 would let the VF send 4096-byte requests the PF said it can't accept.
- MAX_REQUEST=4096 and MAX_RESPONSE=2048 would make CREATE_DMA_REGION for larger queues fail with -EINVAL, and would shrink the RDMA ADD_PAGES batches.

Can the PF meaning of MAX_REQUEST and MAX_RESPONSE be confirmed here?

Quoted 2 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +2 -0
+
+	err = mana_hwc_test_channel(hwc);

[ ... ]

drivers/net/ethernet/microsoft/mana/hw_channel.c void mana_hwc_free_retained_channel(struct gdma_context *gc) · line 1363

Quoted 13 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +13 -0
+static int mana_hwc_rebuild_channel(struct hw_channel_context *hwc,
+				    u16 q_depth,
+				    struct mana_hwc_init_report *report)
+{
+	u32 timeout_ms = mana_hwc_timeout_read(hwc);
+	int cleanup_err;
+	int err;
+
+	err = mana_hwc_teardown_queues(hwc);
+	if (err)
+		return err;
+
+	err = mana_hwc_build_channel(hwc, q_depth, report);

[Severity: Medium]
Does the PF know that the rebuilt rings are larger than the bootstrap rings?

mana_smc_setup_hwc_locked() packs only these into the 256-bit aperture, with no size fields:

- four page frame numbers (EQ, CQ, RQ, SQ)
- the EQ MSI-X index
- the protocol header

The ring sizes grow with q_depth (mana_hwc_init_queues() passes q_depth * 2 for the CQ):

mana_hwc_create_cq():

	cq_size = roundup_pow_of_two(GDMA_CQE_SIZE * q_depth);

mana_hwc_create_wq():

	if (q_type == GDMA_RQ)
		queue_size = roundup_pow_of_two(GDMA_MAX_RQE_SIZE * q_depth);
	else
		queue_size = roundup_pow_of_two(GDMA_MAX_SQE_SIZE * q_depth);

At depth 128 that gives a 16 KiB CQ, a 32 KiB RQ and a 64 KiB SQ. Every bootstrap ring is 4 KiB.

The same ESTABLISH_HWC message, with no sizes, is used three times: for the bootstrap, the rebuild, and the restored bootstrap.

Existing kernels have run long-lived traffic on 4 KiB bootstrap rings while the PF reported a larger QUEUE_DEPTH. So the PF must already work with 4 KiB rings.

If the PF keeps that geometry, would it disagree with the rebuilt rings after the first wrap?

If the PF does change geometry on the rebuild, could the restore path in mana_hwc_restore_bootstrap() let the device write EQEs or CQEs past the 4 KiB coherent allocations?

mana_hwc_test_channel() posts N RX WQEs and raises one EQ test event. No ring wraps before the channel is published, so the test would not catch a mismatch.

The commit message says:

the absence of VF size fields in ESTABLISH_HWC does not require keeping the bootstrap geometry.

Is there a documented PF or firmware contract, or a capability bit, that backs this up?

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +8 -0
+	if (!err)
+		err = mana_hwc_validate_report(hwc, report, q_depth,
+					       true, true);
+	if (!err)
+		err = mana_hwc_finish_channel(hwc, report);
+	if (!err)
+		return 0;
+

drivers/net/ethernet/microsoft/mana/hw_channel.c void mana_hwc_free_retained_channel(struct gdma_context *gc) · line 1381

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +10 -0
+	dev_warn(hwc->dev,
+		 "HWC depth %u rebuild failed, restoring bootstrap: %d\n",
+		 q_depth, err);
+
+	cleanup_err = mana_hwc_teardown_queues(hwc);
+	if (cleanup_err)
+		return cleanup_err;
+
+	/* Do not carry the failed test's reduced wait into the retry. */
+	mana_hwc_timeout_update(hwc, timeout_ms);

[Severity: Low]
Can this overwrite a timeout that the PF set during the rebuild?

timeout_ms is saved on entry to mana_hwc_rebuild_channel(). Once the rebuilt channel is established, its EQ is live with mana_hwc_init_event_handler() as the callback. A HWC_DATA_CFG_HWC_TIMEOUT reconfig event arriving then would do:

	case HWC_DATA_CFG_HWC_TIMEOUT:
		mana_hwc_timeout_update(hwc, val);

If the establish validation or mana_hwc_test_channel() then fails, this unconditional update writes the old saved value over the firmware value.

mana_hwc_timeout_update() only refuses to revive 0. It can't tell the fail-fast value of 1 set by mana_hwc_timeout_reduce() apart from a firmware update.

The comment on hwc_timeout in struct hw_channel_context also says:

	/* Zero permanently cancels waits for this channel instance. Firmware
	 * and query updates may replace a live nonzero value; fail-fast may
	 * only reduce a live value to one millisecond.
	 */

A driver-internal restore of an older value isn't one of the writers listed there.

The effect looks limited, because mana_gd_verify_vf_version() queries the timeout again later when GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG is set.

Quoted 3 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +3 -0
+
+	return mana_hwc_restore_bootstrap(hwc, report);
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794751992.git.weh%40linux.microsoft.com
author
#19 lore raw

Re: [PATCH net-next v11 4/4] net: mana: add dynamic HWC queue depth with reinit path

Quoted 2 lines · netdev-bot+sashiko

Could the doorbell validation go into its own patch with the Fixes: tag, and the dynamic depth work be sent without one?

Yes. Doorbell validation is patch 1 in v12 and carries the Fixes: tag. The depth change is patch 5 and has no Fixes: tag.

Quoted 1 line

Can the PF meaning of MAX_REQUEST and MAX_RESPONSE be confirmed here?

Yes. MAX_RESPONSE limits what the VF sends; MAX_REQUEST limits what the VF receives. With MAX_REQUEST=2048 and MAX_RESPONSE=4096, the VF may send a 4096-byte request. I've kept that direction in v12.

Quoted 2 lines

Does the PF know that the rebuilt rings are larger than the bootstrap rings?

They aren't larger in v12. The PF uses the same 4 KiB descriptor rings after rebuild. The reported depth changes how many requests can be outstanding, not where the rings wrap. If the reported depth would require a larger ring, v12 keeps the bootstrap channel.

Quoted 1 line

Can this overwrite a timeout that the PF set during the rebuild?

Yes, restoring the saved timeout in v11 could overwrite a newer value. V12 doesn't shorten the timeout for the private EQ test, so there's no saved value to restore. If the candidate fails, v12 tears it down before rebuilding and testing a depth-one channel. If teardown isn't acknowledged, it keeps the HWC resources and returns the error without trying the same destroy again on the way out.

Thanks,
Wei

#20 lore raw
In reply to Wei Hu
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.