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 */
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
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 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]