net: mana: concurrent HWC requests
Subsystems (5)
v12 cover net: mana: concurrent HWC requests
The MANA hardware channel starts with room for one request. This series lets the driver use the depth reported by the PF. It tests the new channel before publishing it and keeps the depth-one channel when the reported geometry cannot be used.
Changes since v11:
- Split doorbell validation into a standalone fix. Once ESTABLISH_HWC has submitted queue addresses, retain the HWC mappings until the PF acknowledges DESTROY_HWC. Bound automatic PCI reprobes after an unacknowledged teardown; a still-bound device can retry in place.
- Drop the v11 early returns from CQ and QP destruction. RDMA core can release these objects on process exit; the driver must still remove its callbacks and release the backing. PD, MR/MW and DM destruction can finish locally after a normal posted-command timeout. At that boundary the PF has drained old client DMA and invalidated outstanding requests. An unposted request or a reset notification is not such a guarantee.
- Publish a batch of requests with one SQ doorbell. Do not post the next batch until the previous one finishes. Check posted deadlines before accepting or returning a reply so a late CREATE cannot supply a handle. A queued caller can detect the timeout even if the sender has not run.
- Check the full-width depth against the 4 KiB descriptor rings. Enforce the negotiated transmit and receive limits and remove the redundant RDMA minimum-size check. Restore a tested depth-one channel only after acknowledged teardown of the failed candidate.
Validation: targeted GCC and Clang W=1 builds and strict 80-column checkpatch on the series. Bounded host tests cover a two-request batch, replies before, at and after deadline, RDMA cleanup, unacknowledged HWC teardown, depth fallback and request sizing. No new hardware, performance or full-kernel test is claimed.
Previous revision:
https://lore.kernel.org/all/[email protected]/
Long Li (5):
net: mana: validate the HWC doorbell before ringing it
net: mana: keep HWC queues until the PF acknowledges teardown
net: mana: protect the HWC response buffer until the sender returns
net: mana: support concurrent HWC requests
net: mana: use the reported HWC queue depth
drivers/infiniband/hw/mana/main.c | 15 +- drivers/infiniband/hw/mana/mr.c | 6 +- .../net/ethernet/microsoft/mana/gdma_cdx.c | 6 +- .../net/ethernet/microsoft/mana/gdma_main.c | 165 ++- .../net/ethernet/microsoft/mana/gdma_pci.c | 144 ++- .../net/ethernet/microsoft/mana/hw_channel.c | 1081 +++++++++++++---- drivers/net/ethernet/microsoft/mana/mana_en.c | 4 +- .../net/ethernet/microsoft/mana/shm_channel.c | 58 +- include/net/mana/gdma.h | 19 + include/net/mana/hw_channel.h | 66 +- include/net/mana/shm_channel.h | 10 +- 11 files changed, 1240 insertions(+), 334 deletions(-)
base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
PATCH v12 1/5 net: mana: validate the HWC doorbell before ringing it
From: Long Li <[email protected]>
Date: Mon, 24 Aug 2026 20:04:01 +0000
The HWC gets its doorbell page from an initialization event. Unlike a registered device, it uses that page without checking that it fits in BAR0. The EQ can also try to rearm before a page has been assigned.
Check the page before storing it and skip doorbell writes until a page is available. Fail setup on a bad page rather than waiting for another event on an EQ that cannot be rearmed.
--- .../net/ethernet/microsoft/mana/gdma_main.c | 25 +++++++++++++------ .../net/ethernet/microsoft/mana/hw_channel.c | 19 ++++++++++++++ include/net/mana/gdma.h | 1 + include/net/mana/hw_channel.h | 1 + 4 files changed, 38 insertions(+), 8 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_main.c +17 -8
@@ -547,13 +547,28 @@ 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; + +/* The page size comes from a 16-bit register field. */ +return db_id !=INVALID_DOORBELL && + gc->db_page_size * ((u64 )db_id +1 ) <= + gc->bar0_size - gc->db_page_off; +} +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;switch (q_type) {
@@ -1533,13 +1548,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 +19 -0
@@ -123,6 +123,15 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,switch (event->type) {case GDMA_EQE_HWC_INIT_EQ_ID_DB : eq_db.as_uint32 = event->details[0 ]; +if (!mana_gd_is_valid_doorbell (gd->gdma_context, + eq_db.doorbell)) { +dev_err (hwc->dev,"Invalid HWC doorbell %u\n" , + eq_db.doorbell); +WRITE_ONCE (hwc->hwc_init_error, -EPROTO ); +complete (&hwc->hwc_init_eqe_comp); +break ; + } + hwc->cq->gdma_eq->id = eq_db.eq_id; gd->doorbell = eq_db.doorbell;break ;
@@ -182,6 +191,10 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,break ;case GDMA_EQE_HWC_INIT_DONE : +if (gd->doorbell ==INVALID_DOORBELL ) { +dev_err (hwc->dev,"Missing HWC doorbell\n" ); +WRITE_ONCE (hwc->hwc_init_error, -EPROTO ); + }complete (&hwc->hwc_init_eqe_comp);break ;
@@ -676,6 +689,8 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,struct gdma_queue *cq = hwc->cq->gdma_cq;int err; + gc->hwc.doorbell =INVALID_DOORBELL ; +WRITE_ONCE (hwc->hwc_init_error,0 );init_completion (&hwc->hwc_init_eqe_comp); err = mana_smc_setup_hwc(&gc->shm_channel, false,
@@ -690,6 +705,10 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,if (!wait_for_completion_timeout (&hwc->hwc_init_eqe_comp,60 *HZ ))return -ETIMEDOUT ; + err =READ_ONCE (hwc->hwc_init_error); +if (err) +return err; + *q_depth = hwc->hwc_init_q_depth_max; *max_req_msg_size = hwc->hwc_init_max_req_msg_size; *max_resp_msg_size = hwc->hwc_init_max_resp_msg_size;
include/net/mana/gdma.h +1 -0
@@ -1179,6 +1179,7 @@ int mana_gd_post_and_ring(struct gdma_queue *queue,int mana_gd_alloc_res_map (u32 res_avail,struct gdma_resource *r);void mana_gd_free_res_map (struct gdma_resource *r); +bool mana_gd_is_valid_doorbell (struct gdma_context *gc,u32 db_id);void mana_gd_wq_ring_doorbell (struct gdma_context *gc,struct gdma_queue *queue); void mana_gd_wq_ring_doorbell_ext(struct gdma_context *gc, struct gdma_queue *queue,
include/net/mana/hw_channel.h +1 -0
@@ -186,6 +186,7 @@ struct hw_channel_context {u32 hwc_init_max_req_msg_size;u32 hwc_init_max_resp_msg_size; +int hwc_init_error;struct completion hwc_init_eqe_comp;struct hwc_wq *rxq;
PATCH v12 2/5 net: mana: keep HWC queues until the PF acknowledges teardown
In reply to Wei HuFrom: Long Li <[email protected]>
Date: Mon, 7 Sep 2026 20:51:55 -0700
Once ESTABLISH_HWC submits queue addresses, a failed response does not give the memory back to the driver. Serialize setup and teardown on the shared mailbox. If DESTROY_HWC fails, stop IRQ callbacks and keep the queues for another destroy attempt rather than freeing their DMA.
On teardown, withdraw the CQ table and wait for readers before freeing the HWC queues. Use the same table bound for allocation and dispatch.
A failed PCI probe has no context left to retry the destroy. Do not start another automatic probe that could lose another set of coherent allocations. A failed resume can keep the binding and retry in place.
--- .../net/ethernet/microsoft/mana/gdma_cdx.c | 4 +- .../net/ethernet/microsoft/mana/gdma_main.c | 41 +++- .../net/ethernet/microsoft/mana/gdma_pci.c | 132 +++++++++---- .../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 | 8 + include/net/mana/shm_channel.h | 10 +- 9 files changed, 369 insertions(+), 79 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_cdx.c +2 -2
@@ -279,7 +279,7 @@ unmap_bar: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 +91 -41
237 lines not on this page · raw message
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
@@ -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
@@ -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 +8 -0
@@ -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;int hwc_init_error;struct completion hwc_init_eqe_comp;
@@ -200,11 +202,17 @@ struct hw_channel_context {u32 dest_vrcq_id;u32 hwc_timeout; +/* Once ESTABLISH_HWC submits the queue addresses, a setup error +* does not release them. The PF may still use the rings and buffers +* until it acknowledges DESTROY_HWC. +*/ +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
@@ -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 */
[email protected]
AI reviewRe: [PATCH net-next v12 2/5] net: mana: keep HWC queues until the PF acknowledges teardown
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 5 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] After this patch, a DESTROY_HWC that the PF does not acknowledge leaves the NIC bound but permanently dead, and nothing in…
- [Medium] The unbound-sibling veto on the FPGA path of mana_serv_rescan() is too broad.
- [Medium] On the FPGA path, mana_serv_rescan() now calls pci_walk_bus(target->subordinate, mana_check_unbound, ...) while…
- [Medium] The unbound-sibling check in mana_serv_rescan() is not atomic with the bridge removal it is meant to guard.
- [Medium] The patch treats every failed DESTROY_HWC as "the PF may still DMA into these buffers", even when the function is gone.
- [Low] The commit message does not describe several user-visible changes to PCI service and recovery in gdma_pci.c and gdma_main.c: -…
- [Low] The comment on the new prototype in include/net/mana/gdma.h says mana_gd_fence_eq() "Remove[s] an EQ from interrupt dispatch without…
- [Low] Two new functions mix scope-based cleanup with goto-based cleanup labels, which include/linux/cleanup.h and the subsystem guide say not…
--
net: mana: keep HWC queues until the PF acknowledges teardown
This patch serializes HWC setup and teardown over the shared memory channel. When DESTROY_HWC fails, it fences the HWC EQ and keeps the queues and their DMA memory instead of freeing them. It also changes how the cq_table is published and torn down, and changes PCI probe, resume and service recovery so that a function with a retained HWC is not probed again.
Quoted 3 lines
A failed PCI probe has no context left to retry the destroy. Do not start another automatic probe that could lose another set of coherent allocations. A failed resume can keep the binding and retry in place.
[Severity: Low]
The changelog doesn't mention several behaviour changes in gdma_pci.c and gdma_main.c:
- mana_serv_fpga() is folded into mana_serv_rescan(). FPGA-reconfig recovery is now skipped entirely when any MANA-ID function under the upstream bridge has no driver bound.
- The new global mana_rescan_task lets mana_gd_remove() veto the pci_rescan_bus() that follows removal. When the veto fires, the removed device is never re-enumerated. On the FPGA path that is the whole bridge subtree.
- Both service paths now take the device lock.
- mana_gd_process_eqe() drops the WARN_ON_ONCE() checks for an out-of-range cq_id and for a NULL cq. This applies to every CQ, not only the HWC, so those EQEs are now silently discarded.
Could the changelog describe these as well?
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +0
-0
[ ... ]
drivers/net/ethernet/microsoft/mana/gdma_pci.c static struct mana_dev_recovery_work { · line 56
Quoted 9 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +6
-2+static int mana_check_unbound (struct pci_dev *pdev,void *data) +{ +bool *unbound = data; -pci_stop_and_remove_bus_device (pdev); -pci_rescan_bus (parent); +if (READ_ONCE (pdev->driver) || + !pci_match_id (mana_driver.id_table, pdev)) +return 0 ;
[Severity: Medium]
Is this check atomic with the bridge removal it guards? mana_check_unbound() reads each sibling's pdev->driver while holding only pci_rescan_remove_lock and the serviced device's device lock. It does not hold the sibling's device lock.
local_pci_probe() sets pdev->driver before calling ->probe() and clears it if the probe fails:
drivers/pci/pci-driver.c:local_pci_probe() {
...
pci_dev->driver = pci_drv;
rc = pci_drv->probe(pci_dev, ddi->id);
...
}Sysfs bind and async probing don't take pci_rescan_remove_lock. So a sibling that is still inside mana_gd_probe() looks bound to this walk.
Suppose that probe then fails with a retained HWC and returns -ENOTRECOVERABLE. The sibling ends up unbound. When pci_stop_and_remove_bus_device(target) reaches it, there is no driver, so no ->remove() runs to clear mana_rescan_task. pci_rescan_bus() then probes the sibling again.
Doesn't that start the extra automatic probe that the commit message says must be avoided? That probe could abandon another set of HWC coherent allocations.
[ ... ]
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +5
-3-static void mana_serv_fpga (struct pci_dev *pdev) +static void mana_serv_rescan (struct pci_dev *pdev, +enum mana_rescan_reason reason) { -struct pci_bus *bus, *parent; +struct pci_dev *target = pdev; +struct pci_bus *parent; +bool unbound = false;pci_lock_rescan_remove (); -
drivers/net/ethernet/microsoft/mana/gdma_pci.c static struct mana_dev_recovery_work { · line 76
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +6
-3- bus = pdev->bus; -if (!bus) { -dev_err (&pdev->dev,"MANA service: no bus\n" ); +if (!device_is_registered (&pdev->dev)) goto out; + + scoped_guard(device, &pdev->dev) { +if (reason ==MANA_RESCAN_PROBE ) { +if (pdev->dev.driver) + goto out;
[Severity: Low]
This isn't a bug, but this function and mana_serv_reset() both mix guard()/scoped_guard() with goto-based cleanup labels. include/linux/cleanup.h asks to avoid that.
Here pci_lock_rescan_remove() is taken by hand and the device lock is a scoped_guard. Three goto out exits leave the guard to reach pci_unlock_rescan_remove() at the label.
In mana_serv_reset(), guard(device) is at function scope. Its out label runs clear_bit(GC_IN_SERVICE, &gc->flags), and the early return false and return true exits skip that label.
Would it be clearer to convert each function to a single style? That would make it obvious which exits unlock and which clear GC_IN_SERVICE.
drivers/net/ethernet/microsoft/mana/gdma_pci.c static struct mana_dev_recovery_work { · line 88
Quoted 12 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +12
-0+ }else if (pdev->driver != &mana_driver) { + goto out; + }else if (reason ==MANA_RESCAN_FPGA ) { +struct gdma_context *gc =pci_get_drvdata (pdev); + +/* An unbound sibling cannot veto the bridge rescan in +* ->remove(). Its last probe may have lost HWC DMA. +*/ + target =pci_upstream_bridge (pdev); +if (target) +pci_walk_bus (target->subordinate, + mana_check_unbound, &unbound);
[Severity: Medium]
Can this deadlock against PCIe error recovery? pci_walk_bus() takes down_read(&pci_bus_sem) while scoped_guard(device, &pdev->dev) holds the MANA device lock.
AER recovery takes the two locks in the opposite order:
pcie_do_recovery()
pci_walk_bridge()
pci_walk_bus() <- pci_bus_sem held for read
report_frozen_detected()
report_error_detected()
device_lock(&dev->dev)
rwsem readers queue behind a waiting writer. Some pci_bus_sem writers don't take pci_rescan_remove_lock. One example is pci_register_host_bridge(), reached through pci_scan_root_bus_bridge() from create_root_hv_pci_bus() in pci-hyperv.c.
With such a writer queued:
AER thread: holds pci_bus_sem (read), waits for the MANA device lock writer: waits in down_write(&pci_bus_sem) for the AER reader MANA service: holds the device lock, waits in down_read() behind writer
Lockdep won't report this, because device mutexes are novalidate. The old code never held a device lock across a bus walk.
pci_rescan_remove_lock is already held at this point. Could the walk be done outside the device lock?
drivers/net/ethernet/microsoft/mana/gdma_pci.c static struct mana_dev_recovery_work { · line 94
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +6
-0+if (unbound) { +dev_err (&pdev->dev, +"Unbound MANA function, skipping bridge rescan\n" ); +clear_bit (GC_IN_SERVICE , &gc->flags); + goto out; + }
[Severity: Medium]
Is this veto broader than intended? mana_check_unbound() flags any MANA-ID function under the upstream bridge that has no driver. It can't tell a function whose probe lost HWC DMA from one that is unbound for other reasons, for example:
- an administrator unbound it through sysfs
- SR-IOV VFs that weren't autoprobed, or whose probe failed
- a sibling whose probe failed with -ENOMEM or a DMA mask error
- a sibling that failed with -ETIMEDOUT or -EPROTO and is waiting for the delayed recovery re-probe
pci_walk_bus() also descends into VF virtual buses, so PF hosts with unbound VFs can hit this.
In each of these cases, a GDMA_EQE_HWC_FPGA_RECONFIG event on a bound function now logs, clears GC_IN_SERVICE and returns. mana_serv_fpga() always did the bridge remove, sleep and rescan here.
Doesn't that leave the bound function with stale hardware state after the FPGA reconfiguration, with nothing retrying recovery?
Quoted 17 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +8
-3+ } } - parent = bus->parent; -if (!parent) { +if (!target || !target->bus) {dev_err (&pdev->dev,"MANA service: no parent bus\n" ); goto out; } -pci_stop_and_remove_bus_device (bus->self); + parent = target->bus; +WRITE_ONCE (mana_rescan_task, current); +pci_stop_and_remove_bus_device (target); +if (!READ_ONCE (mana_rescan_task)) + goto out; +WRITE_ONCE (mana_rescan_task,NULL );
[ ... ]
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +1
-0@@ -682,11 +723,16 @@ static void mana_gd_remove(struct pci_dev *pdev)mana_gd_cleanup (gc); +if (gc->hwc.driver_data &&READ_ONCE (mana_rescan_task) == current) {
drivers/net/ethernet/microsoft/mana/gdma_pci.c static void mana_gd_remove(struct pci_dev *pdev) · line 735
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +5
-1+dev_err (gc->dev,"HWC teardown failed, skipping PCI rescan\n" ); +WRITE_ONCE (mana_rescan_task,NULL ); + } +xa_destroy (&gc->irq_contexts);pci_iounmap (pdev, gc->bar0_va); -vfree (gc); +mana_gd_free_context (gc);
[Severity: Medium]
What happens here when the function has been surprise removed, or is otherwise unreachable?
Every SMC read returns 0xFFFFFFFF, and mana_smc_teardown_hwc() is called with reset_vf=false. mana_smc_poll_register() therefore spins for the whole poll window (20-40 seconds) before DESTROY fails.
mana_gd_free_context() then calls mana_hwc_free_retained_channel(), which only frees the software wrappers:
mana_hwc_free_retained_wq() {
...
kfree(wq->msg_buf);
kfree(wq->gdma_wq);
kfree(wq);
}Doesn't that permanently leak the coherent DMA allocations for the EQ/CQ/RQ/SQ rings and the message buffers? A disconnected device can't DMA into them, but nothing checks pci_dev_is_disconnected() or pci_channel_offline() before deciding to keep them.
On the FPGA_RECONFIG path, the same failure clears mana_rescan_task here. mana_serv_rescan() then takes this exit:
if (!READ_ONCE(mana_rescan_task)) goto out;
That skips both the reconfiguration wait and pci_rescan_bus(). Would the reconfigured function, and every sibling under the removed bridge, then stay gone until a manual rescan or a reboot?
[ ... ]
drivers/net/ethernet/microsoft/mana/gdma_pci.c static int mana_gd_resume(struct pci_dev *pdev) · line 782
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c +4
-0@@ -728,6 +774,10 @@ static int mana_gd_resume(struct pci_dev *pdev) cleanup_gd:mana_gd_cleanup (gc); +check_hwc: +/* Keep the binding and DMA handles for a later DESTROY retry. */ +if (gc->hwc.driver_data) +return -ENOTRECOVERABLE ;return err; }
[Severity: Medium]
Is anything left to do the "retry in place"?
Only a successful DESTROY response clears hwc->setup_active. Teardown passes reset_vf=false, so during a reset an all-ones aperture is treated as PF ownership until mana_smc_poll_register() times out.
For a GDMA_EQE_HWC_RESET_REQUEST where DESTROY is not acknowledged:
mana_serv_reset()
mana_gd_suspend()
mana_gd_cleanup()
mana_hwc_destroy_channel() <- fails, fences HWC EQ, keeps hwc
msleep(10 s)
mana_gd_resume()
mana_gd_setup()
mana_hwc_create_channel()
mana_hwc_destroy_channel() <- single retry fails, -ETIMEDOUT
gc->bus_ops->remove_irqs()
check_hwc: return -ENOTRECOVERABLE
mana_serv_reset() only escalates on these errors:
if (ret == -ETIMEDOUT || ret == -EPROTO) {so it just logs and clears GC_IN_SERVICE. Before this patch, this path went on to mana_serv_rescan() and re-enumerated the function.
No IRQs are registered now, so no later RESET_REQUEST or FPGA_RECONFIG event can arrive. No work item or timer retries DESTROY either. Does the NIC then stay bound but dead until a PM cycle, a manual unbind or a reboot?
The probe path is similar. The free_gc label in mana_gd_probe() turns -ETIMEDOUT/-EPROTO into -ENOTRECOVERABLE. So the delayed recovery work, which the comment below reserves for the case where "Hardware could be in recovery mode", is never scheduled.
[ ... ]
include/net/mana/gdma.h int mana_gd_create_mana_wq_cq(struct gdma_dev *gd, · line 604
Quoted 10 lines
include/net/mana/gdma.h +2
-0@@ -600,6 +600,9 @@ int mana_gd_create_mana_wq_cq(struct gdma_dev *gd,void mana_gd_destroy_queue (struct gdma_context *gc,struct gdma_queue *queue); +/* Remove an EQ from interrupt dispatch without freeing its queue memory. */ +void mana_gd_fence_eq (struct gdma_context *gc,struct gdma_queue *queue);
[Severity: Low]
This doesn't break anything today, but does the comment match what mana_gd_fence_eq() does? The function is just mana_gd_destroy_eq(gc, false, queue), and that does more than remove the EQ from dispatch:
- It sets queue->eq.msix_index to INVALID_PCI_MSIX_INDEX. A later mana_gd_destroy_queue() on the same EQ then returns early.
- It calls mana_gd_disable_queue() when queue->eq.disable_needed is set.
disable_needed is true for every EQ created through mana_gd_create_hw_eq(), which covers all the data-path EQs. Both current callers pass HWC EQs, where disable_needed is false, so the mismatch is latent for now. A future caller that relies on the comment would disable the hardware EQ without meaning to.
Could the comment say what the helper actually does?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/hwc-v12.91ec3eff9cb647d5bc5cc932b3c6f60c.0%40linux.microsoft.com
PATCH v12 3/5 net: mana: protect the HWC response buffer until the sender returns
In reply to Wei HuFrom: Long Li <[email protected]>
Date: Mon, 7 Sep 2026 20:51:56 -0700
A response can race with a sender that has timed out. Clear the output pointer under the same lock used to copy the response, so the handler cannot write to the caller's buffer after the sender returns.
Reset the completion and result under that lock when assigning a slot. If the response wins the race with timeout, return its result. This does not change admission or prevent reuse of the message ID.
--- .../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
@@ -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 @@ out: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,
@@ -709,8 +727,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;
@@ -1019,6 +1039,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) {
@@ -1026,26 +1077,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)
@@ -1067,11 +1124,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);
@@ -1080,27 +1150,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
@@ -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; };
PATCH v12 4/5 net: mana: support concurrent HWC requests
In reply to Wei HuFrom: Long Li <[email protected]>
Date: Mon, 7 Sep 2026 20:51:57 -0700
Queue competing callers and publish their SQ entries with one doorbell. Wait for that batch's replies and senders before posting the next. No new request can reach the PF after an unanswered command's deadline, even if its sender hasn't run yet. Do not reuse the ID or TX buffer until the sender has finished and the reply has arrived.
On normal response timeout the PF drains old client DMA and invalidates outstanding commands. Check for an unanswered command's deadline under the slot lock before accepting or consuming a reply. This lets a queued caller detect the timeout even when the owner hasn't run. Stop posting, wake the senders and discard their unconsumed replies.
Allow RDMA teardown of old objects to finish locally without a destroy reply. Neither a failed post nor an external reset request establishes DMA quiescence.
Drain senders before destroying the channel. Keep the HWC mappings until the PF acknowledges teardown.
--- drivers/infiniband/hw/mana/main.c | 3 +- drivers/infiniband/hw/mana/mr.c | 6 +- .../net/ethernet/microsoft/mana/gdma_cdx.c | 2 + .../net/ethernet/microsoft/mana/gdma_main.c | 97 ++- .../net/ethernet/microsoft/mana/gdma_pci.c | 12 +- .../net/ethernet/microsoft/mana/hw_channel.c | 710 ++++++++++++------ include/net/mana/gdma.h | 14 + include/net/mana/hw_channel.h | 43 +- 8 files changed, 604 insertions(+), 283 deletions(-)
drivers/infiniband/hw/mana/main.c +2 -1
@@ -100,7 +100,8 @@ static int mana_gd_destroy_pd(struct mana_ib_dev *mdev, u64 pd_handle) req.pd_handle = pd_handle; -return mana_gd_send_request (mdev_to_gc (mdev),sizeof (req), &req,sizeof (resp), &resp); +return mana_gd_send_teardown_request (mdev_to_gc (mdev),sizeof (req), + &req,sizeof (resp), &resp); }int mana_ib_alloc_pd (struct ib_pd *ibpd,struct ib_udata *udata)
drivers/infiniband/hw/mana/mr.c +4 -2
@@ -94,7 +94,8 @@ static int mana_ib_gd_destroy_mr(struct mana_ib_dev *dev, u64 mr_handle) req.mr_handle = mr_handle; -return mana_gd_send_request (gc,sizeof (req), &req,sizeof (resp), &resp); +return mana_gd_send_teardown_request (gc,sizeof (req), &req, +sizeof (resp), &resp); } struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 length,
@@ -428,7 +429,8 @@ static int mana_ib_gd_destroy_dm(struct mana_ib_dev *mdev, struct mana_ib_dm *dmmana_gd_init_req_hdr (&req.hdr,GDMA_DESTROY_DM ,sizeof (req),sizeof (resp)); req.dm_handle = dm->dm_handle; -return mana_gd_send_request (gc,sizeof (req), &req,sizeof (resp), &resp); +return mana_gd_send_teardown_request (gc,sizeof (req), &req, +sizeof (resp), &resp); }int mana_ib_dealloc_dm (struct ib_dm *ibdm,struct uverbs_attr_bundle *attrs)
drivers/net/ethernet/microsoft/mana/gdma_cdx.c +2 -0
@@ -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 +77 -20
182 lines not on this page · raw message
drivers/net/ethernet/microsoft/mana/gdma_pci.c +6 -6
@@ -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;
@@ -119,7 +118,6 @@ out:/* Return true if recovery needs to escalate to PCI re-enumeration. */ static bool mana_serv_reset (struct pci_dev *pdev) { -struct hw_channel_context *hwc;struct gdma_context *gc;int ret;
@@ -128,14 +126,14 @@ static bool mana_serv_reset(struct pci_dev *pdev)return false; gc =pci_get_drvdata (pdev); - hwc = gc->hwc.driver_data; -if (!hwc) { +if (!gc->hwc.driver_data) {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 ; +/* A service notification is not a DMA fence. Keep the normal HWC +* response window for cleanup, including when all slots are in use. +*/ dev_info (&pdev->dev,"MANA reset cycle start\n" );
@@ -616,6 +614,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 );
drivers/net/ethernet/microsoft/mana/hw_channel.c +464 -246
891 lines not on this page · raw message
include/net/mana/gdma.h +14 -0
@@ -548,6 +548,12 @@ 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 HWC publication and active sender references. */ +spinlock_t hwc_lock; +/* Azure network adapter */ struct gdma_dev mana;
@@ -1197,6 +1203,14 @@ 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); +/* For software teardown of an object whose lifetime excludes HWC replacement. +* A posted response timeout retires that generation. Return zero for local +* cleanup in that case, without filling resp or implying a PF response. +* Callers needing response fields must use mana_gd_send_request(). +*/ +int mana_gd_send_teardown_request (struct gdma_context *gc,u32 req_len, +const void *req,u32 resp_len,void *resp); +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 +35 -8
74 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH net-next v12 4/5] net: mana: support concurrent HWC requests
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: 2 · Medium: 1 · 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).
- [High] After an HWC timeout, RDMA DESTROY_MR, DESTROY_DM and DESTROY_PD report success even if the PF never received them, and the callers…
- [High] mana_hwc_check_deadlines() runs before a reply is accepted (at the top of mana_hwc_handle_resp(), under r->lock) and before…
- [Medium] When any pending slot in a batch passes its deadline, mana_hwc_fail_pending(hwc, HWC_DMA_DRAINED) overwrites ctx->error on…
- [Low] The new comment on mana_need_log() says it suppresses only follow-on failures ("Once admission is closed, follow-on request…
--
net: mana: support concurrent HWC requests
This patch replaces the HWC semaphore and per-slot locks with a submission list. Competing callers are batched behind one SQ doorbell, and replies are tracked under the inflight map lock. When a posted command passes a host-side deadline, the channel moves to HWC_TIMED_OUT and later requests fail without being posted. A new mana_gd_send_teardown_request() lets RDMA destroy paths report success in that state.
Quoted 23 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +4
-5@@ -142,22 +142,21 @@ int mana_gd_init_registers(struct gdma_context *gc)return mana_gd_init_vf_regs (gc); } -/* Suppress logging when we set timeout to zero */ +/* Once admission is closed, follow-on request failures are expected. */ bool mana_need_log (struct gdma_context *gc,int err) {struct hw_channel_context *hwc; +unsigned long flags; +bool log; -if (err != -ETIMEDOUT ) -return true; - -if (!gc) +if (!gc || (err != -ETIMEDOUT && err != -ENODEV ))return true;
drivers/net/ethernet/microsoft/mana/gdma_main.c int mana_gd_init_registers(struct gdma_context *gc) · line 160
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +4
-4+spin_lock_irqsave (&gc->hwc_lock, flags); hwc = gc->hwc.driver_data; -if (hwc && hwc->hwc_timeout ==0 ) -return false; - -return true; + log = hwc &&READ_ONCE (hwc->state) ==HWC_READY ; +spin_unlock_irqrestore (&gc->hwc_lock, flags); +return log; }
[Severity: Low]
Does this also hide the first timeout, the one that triggers the state change? The comment says only follow-on failures are suppressed.
mana_hwc_check_deadlines() sets HWC_TIMED_OUT before the sender whose deadline expired returns -ETIMEDOUT. That error then reaches callers such as mana_gd_disable_queue(), mana_gd_destroy_dma_region(), mana_gd_deregister_device() or mana_gd_destroy_eq(). By then mana_need_log() sees a non-READY state, so their dev_err() is skipped.
This patch also removes the "Command 0x%x timed out: %u ms" message from mana_hwc_send_request(). The only log left is:
dev_err(hwc->dev, "HWC request %u timed out\n", i);
It prints a slot index rather than the opcode. Before this patch the first timeout always logged the command. Could the opcode of the command that timed out still be logged somewhere?
[ ... ]
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0@@ -6,61 +6,103 @@
[ ... ]
Quoted 16 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +8
-6-static void mana_hwc_put_msg_index (struct hw_channel_context *hwc,u16 msg_id) +static void mana_hwc_fail_pending (struct hw_channel_context *hwc,int result) {struct gdma_resource *r = &hwc->inflight_msg_res; -unsigned long flags; - -spin_lock_irqsave (&r->lock, flags); -bitmap_clear (hwc->inflight_msg_res.map, msg_id,1 ); -spin_unlock_irqrestore (&r->lock, flags); +unsigned int i; + +lockdep_assert_held (&r->lock); +for_each_set_bit (i, r->map, r->size) { +struct hwc_caller_ctx *ctx = &hwc->caller_ctx[i]; + +/* Retirement also invalidates a reply not yet consumed. An
drivers/net/ethernet/microsoft/mana/hw_channel.c line 42
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +10
-0+* ordinary stop has no such guarantee: keep a completed reply. +*/ +if (!ctx->sender) +continue ; +if (ctx->error != -EINPROGRESS && result !=HWC_DMA_DRAINED ) +continue ; + ctx->error = result; +complete (&ctx->comp_event); + } +}
[Severity: Medium]
Can this throw away a reply the PF has already sent?
When result is HWC_DMA_DRAINED, the -EINPROGRESS check is skipped. A slot whose reply has arrived and been stored (ctx->error == 0 and ctx->reply set), but not yet consumed by its sender, gets overwritten. mana_hwc_wait_for_response() then skips the memcpy into resp. The caller gets -ETIMEDOUT, or 0 for a teardown request even if the PF returned a failure status.
The commit message only says "Unanswered commands have no effect". An answered CREATE_DMA_REGION, CREATE_MR or CREATE_PD did take effect on the PF.
Would its handle be lost, leaving an orphaned PF object while the caller's error path frees the backing gmi buffer or umem?
At this commit the bootstrap depth is 1, so a batch holds one entry and this cannot trigger. The next patch in the series, "net: mana: use the reported HWC queue depth", allows batches larger than one, and this logic is unchanged at the end of the series.
The sequence would be:
1. Command A is answered and its reply is stored.
2. Command B's deadline expires before A's sender takes r->lock again.
[ ... ]
Quoted 1 line
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0@@ -86,44 +128,60 @@ static int mana_hwc_post_rx_wqe(const struct hwc_wq *hwc_rxq,
[ ... ]
Quoted 33 lines
static void mana_hwc_handle_resp(struct
hw_channel_context*hwc, u32resp_len,drivers/net/ethernet/microsoft/mana/hw_channel.c +10
-15struct hwc_work_request *rx_req, u16 msg_id) { -const struct gdma_resp_hdr *resp_msg = rx_req->buf_va; +struct gdma_resource *r = &hwc->inflight_msg_res;struct hwc_caller_ctx *ctx; -int err; -if (!test_bit (msg_id, hwc->inflight_msg_res.map)) { -dev_err (hwc->dev,"hwc_rx: invalid msg_id = %u\n" , msg_id); -mana_hwc_post_rx_wqe (hwc->rxq, rx_req); -return ; +spin_lock (&r->lock); +mana_hwc_check_deadlines (hwc); +if (msg_id >= r->size || !test_bit (msg_id, r->map)) { +dev_err_ratelimited (hwc->dev,"Unexpected HWC response ID %u\n" , + msg_id); + goto repost; } - ctx = hwc->caller_ctx + msg_id; - -spin_lock (&ctx->lock); -if (!ctx->output_buf) { -spin_unlock (&ctx->lock); -mana_hwc_post_rx_wqe (hwc->rxq, rx_req); -return ; - } + ctx = &hwc->caller_ctx[msg_id]; +if (!ctx->pending) + goto repost; - err =mana_hwc_verify_resp_msg (ctx, resp_msg, resp_len);
drivers/net/ethernet/microsoft/mana/hw_channel.c static int mana_hwc_post_rx_wqe(const struct hwc_wq *hwc_rxq, · line 166
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +6
-3-if (!err) { - ctx->status_code = resp_msg->status; -memcpy (ctx->output_buf, resp_msg, resp_len); + ctx->pending = false; +if (!ctx->sender) { +__clear_bit (msg_id, r->map); + goto repost; } +if (ctx->error != -EINPROGRESS ) + goto repost;
[Severity: High]
Should mana_hwc_check_deadlines() run before the reply in hand has been accepted?
The deadline check uses only host jiffies:
if (time_after_eq(now, ctx->deadline)) {
WRITE_ONCE(hwc->state, HWC_TIMED_OUT);
mana_hwc_fail_pending(hwc, HWC_DMA_DRAINED);The deadline is set from the host doorbell write in mana_hwc_post_batch(). Suppose the device wrote the reply within its window, but the host handled it late (EQ interrupt latency, a descheduled vCPU, steal time). This call then marks the channel timed out and sets ctx->error. The reply being handled fails the -EINPROGRESS check above and is reposted.
mana_hwc_wait_for_response() has the same ordering:
for (;;) {
remaining = mana_hwc_check_deadlines(hwc);
if (ctx->error != -EINPROGRESS)
break;A waiter woken by wait_for_completion_timeout() at the deadline can declare a timeout while the CQE is already in the ring but not yet polled.
In that case the PF never reached its own timeout. By the commit message's reasoning, it has not drained DMA or invalidated anything, yet the driver treats the generation as drained.
Would non-teardown callers then get -ETIMEDOUT for commands the PF executed, for example an answered CREATE_MR whose caller unwinds and frees the umem? And would every later teardown request return 0 without being posted, unpinning memory behind live PF objects?
HWC_DATA_CFG_HWC_TIMEOUT lets the PF shorten hwc_timeout for later batches, so replies landing close to the deadline may not be unusual.
[ ... ]
Quoted 1 line
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0@@ -1058,108 +1201,183 @@ static int mana_hwc_response_status(struct hw_channel_context *hwc,
[ ... ]
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +7
-2+ remaining =mana_hwc_check_deadlines (hwc); +if (hwc->state ==HWC_READY ) +return remaining; - tx_wr->msg_size = req_len; - command = req_msg->req.msg_type; + sub->err = hwc->state ==HWC_TIMED_OUT ?HWC_DMA_DRAINED : -ENODEV ; +list_del_init (&sub->entry); +return 0 ; +}
[ ... ]
drivers/net/ethernet/microsoft/mana/hw_channel.c static int mana_hwc_response_status(struct hw_channel_context *hwc, · line 1383
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +9
-0+finish_wait (&hwc->admission_waitq, &wait); + err = sub.err; +if (!err) + err =mana_hwc_wait_for_response (hwc, sub.id, hdr->req.msg_type, + resp_len, resp); + +if (err ==HWC_DMA_DRAINED ) +return teardown ?0 : -ETIMEDOUT ; +return err; }
[Severity: High]
Can this report a DESTROY_MR, DESTROY_DM or DESTROY_PD as successful when the PF never received it?
Once mana_hwc_check_deadlines() moves the channel to HWC_TIMED_OUT, mana_hwc_admit() gives every queued or new submission HWC_DMA_DRAINED without staging it on the SQ. For teardown requests that turns into 0 here. So mana_ib_gd_destroy_mr(), mana_ib_gd_destroy_dm() and mana_gd_destroy_pd() report success for a destroy that was never posted.
The callers then release memory the device can still reach:
drivers/infiniband/hw/mana/mr.c:mana_ib_dereg_mr() {
...
err = mana_ib_gd_destroy_mr(dev, mr->mr_handle);
if (err)
return err;
if (mr->umem)
ib_umem_release(mr->umem);
...
}drivers/infiniband/hw/mana/mr.c:mana_ib_dealloc_dm() {
...
err = mana_ib_gd_destroy_dm(dev, dm);
if (err)
return err;
kfree(dm);
...
}mana_ib_dealloc_mw() also goes through mana_ib_gd_destroy_mr().
One reachable path starts with any HWC response timeout followed by reset recovery. For example, mana_gf_stats_work_handler() sees -ETIMEDOUT and schedules GDMA_EQE_HWC_RESET_REQUEST. Recovery then runs mana_rdma_remove()->ib_unregister_device()->mana_ib_dereg_mr().
Before this patch a timed-out destroy returned an error and the pages stayed pinned.
The only justification in the commit message is:
"On normal response timeout the PF drains old client DMA and invalidates outstanding commands."
Even taken as given, that covers in-flight DMA and outstanding commands. Does it also cover MR, DM or PD objects that were created and acknowledged earlier, and whose DESTROY was never posted?
The HWC teardown path in this same patch does not seem to rely on such a guarantee. It keeps the HWC buffers mapped until DESTROY_HWC is acknowledged. It also still expects late replies after HWC_TIMED_OUT, through the pending and refill_needed tracking.
Is there a PF specification that could be cited for this? If not, could teardown requests that were never posted keep returning an error?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/hwc-v12.91ec3eff9cb647d5bc5cc932b3c6f60c.0%40linux.microsoft.com
Wei Hu
maintainerRE: [EXTERNAL] Re: [PATCH net-next v12 4/5] net: mana: support concurrent HWC requests
Quoted 1 line · On Sat, Nov 28, 2026, [email protected] wrote:
Can this throw away a reply the PF has already sent?
Yes. V12 can overwrite a reply the VF already stored if another request times out before the sender runs. I'll fix that in v13 so the sender gets the original reply, including any error from the PF.
Quoted 2 lines
Should
mana_hwc_check_deadlines()run before the reply in hand has been accepted?
Yes. The deadline is the full PF response timeout as seen by the VF. If it expires before the VF accepts a posted command's reply, the PF guarantees that old client DMA has stopped, even if the PF wrote the reply on time and the VF serviced the interrupt late.
Quoted 2 lines
Can this report a
DESTROY_MR,DESTROY_DMorDESTROY_PDas successful when the PF never received it?
Yes. Once that timeout covers all posts on the channel, zero means the teardown helper can finish local cleanup, not that the PF acked the destroy. Ordinary requests get -ETIMEDOUT. A failed post or a wait for a free slot gives no such guarantee. The HWC buffers still need a DESTROY_HWC ack before they can be freed.
Thanks,
Wei
pw-bot: cr
PATCH v12 5/5 net: mana: use the reported HWC queue depth
In reply to Wei HuFrom: Long Li <[email protected]>
Date: Mon, 24 Aug 2026 20:04:01 +0000
The bootstrap channel handles one request at a time. Rebuild it at the depth reported by the PF if all four descriptor rings still fit in 4 KiB and the message sizes match the bootstrap allocations. Otherwise keep the bootstrap queues and enforce the reported transmit and receive limits.
Test the new channel before publishing it. If the test fails, restore and test a depth-one channel without changing the firmware timeout. Do not reuse the queues if the PF did not acknowledge teardown.
--- drivers/infiniband/hw/mana/main.c | 12 +- .../net/ethernet/microsoft/mana/gdma_main.c | 2 +- .../net/ethernet/microsoft/mana/hw_channel.c | 286 +++++++++++++++--- include/net/mana/hw_channel.h | 16 +- 4 files changed, 260 insertions(+), 56 deletions(-)
drivers/infiniband/hw/mana/main.c +6 -6
@@ -415,28 +415,31 @@ static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umemunsigned 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); 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 ;
@@ -479,9 +482,6 @@ static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umemif (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 +1 -1
@@ -1347,7 +1347,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 );
drivers/net/ethernet/microsoft/mana/hw_channel.c +238 -48
409 lines not on this page · raw message
include/net/mana/hw_channel.h +15 -1
@@ -4,6 +4,8 @@#ifndef _HW_CHANNEL_H#define _HW_CHANNEL_H +#include <linux/minmax.h> +#define DEFAULT_LOG2_THROTTLING_FOR_ERROR_EQ 4#define HW_CHANNEL_MAX_REQUEST_SIZE 0x1000
@@ -195,8 +197,12 @@ 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;
@@ -226,6 +232,7 @@ struct hw_channel_context {* until it acknowledges DESTROY_HWC. */ bool setup_active; +bool teardown_failed;/* mana_gd_send_request() callers, including waiters; under hwc_lock. */ unsigned int active_senders;
@@ -233,6 +240,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);
[email protected]
AI reviewRe: [PATCH net-next v12 5/5] net: mana: use the reported HWC queue depth
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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 patch may apply each firmware-reported HWC message limit to the wrong direction.
--
net: mana: use the reported HWC queue depth
This commit rebuilds the HWC at the PF-reported queue depth when all four descriptor rings fit in 4 KiB and the reported message sizes match the bootstrap allocations. Otherwise it keeps the bootstrap queues and enforces the reported transmit and receive limits. It also tests the rebuilt channel and restores a depth-one channel if that test fails.
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0@@ -1097,32 +1138,177 @@ 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 1183
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +5
-3+static int mana_hwc_finish_channel (struct hw_channel_context *hwc, +const struct mana_hwc_init_report *report) { -u32 max_req_msg_size, max_resp_msg_size; -u16 q_depth_max;int err; - err = mana_hwc_init_queues(hwc, HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH, +/* 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 to the right directions?
HWC_INIT_DATA_MAX_REQUEST is stored as rx_msg_size_limit, and HWC_INIT_DATA_MAX_RESPONSE as tx_msg_size_limit. The tx limit then bounds every host-to-PF request, first in mana_hwc_get_max_req_size():
return min(hwc->tx_msg_size_limit, hwc->max_resp_msg_size);
and then in mana_hwc_stage():
if (sub->len > min(hwc->tx_msg_size_limit, tx->buf_len) ||
sub->resp_len > min(hwc->rx_msg_size_limit, hwc->max_req_msg_size))
return -EMSGSIZE;Before this patch, mana_gd_create_dma_region() and mana_ib_gd_create_dma_region() bounded outgoing requests by hwc->max_req_msg_size. So the request maximum was treated as the bound for requests.
The comment "MAX_REQUEST sizes the RQ; MAX_RESPONSE sizes the SQ" follows the driver's own buffer naming in mana_hwc_init_queues(). Nothing in the tree says what the PF means by these two values.
Suppose MAX_REQUEST is the largest request the PF accepts. Then on the keep-bootstrap path in mana_hwc_prepare_channel(), wouldn't each direction get the other direction's limit? For example:
If the PF reports MAX_REQUEST=2048 and MAX_RESPONSE=4096, the driver sends CREATE_DMA_REGION and ADD_PAGES messages of up to 4 KiB to a PF that accepts only 2 KiB.
If the PF reports MAX_REQUEST=4096 and MAX_RESPONSE=1024, requests are capped at 1 KiB. mana_gd_create_dma_region() then returns -EINVAL for queue buffers that need more than about 120 page entries. The RDMA max_pgs_create_cmd and max_pgs_add_cmd batches also shrink.
The rebuild path requires both values to be 4096. So this only matters when the bootstrap queues are kept and the PF reports other sizes.
The commit message says "enforce the reported transmit and receive limits", but it does not say which report maps to which direction.
Could the mapping be checked against the firmware definition and documented?
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 4 lines
include/net/mana/hw_channel.h +0
-0
[ ... ]
Quoted 10 lines
include/net/mana/hw_channel.h +6
-0@@ -233,6 +240,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); +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/hwc-v12.91ec3eff9cb647d5bc5cc932b3c6f60c.0%40linux.microsoft.com
[email protected]
AI reviewThis 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.
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.
Wei Hu
maintainerQuoted 9 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Tuesday, November 24, 2026 11:45 PM
To: Wei Hu <[email protected]>
Hi!This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Quoted 8 lines
- 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.
Patch 1/5 is the standalone fix. We found it during AI-assisted review of HWC initialization: the driver used the doorbell page index from the device without checking that the page was inside BAR0. The rest of the series supports concurrent HWC requests.
We didn't reproduce an out-of-range MMIO write on hardware and have
no production report or kernel trace. In a userspace test, we passed an invalid doorbell index to the driver's initialization code and confirmed that the fix rejects it with -EPROTO. The test did not perform an MMIO write.
Wei
[email protected]
AI reviewSashiko has reviewed this 5-patch series and found no issues.
Sashiko has reviewed this 5-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]