Skip to content

bnxt_re/lib: Support direct verbs - #1654

Open
sbasavapatna wants to merge 10 commits into
linux-rdma:masterfrom
sbasavapatna:dv-upstream
Open

bnxt_re/lib: Support direct verbs#1654
sbasavapatna wants to merge 10 commits into
linux-rdma:masterfrom
sbasavapatna:dv-upstream

Conversation

@sbasavapatna

@sbasavapatna sbasavapatna commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Hi,

This patchset supports Direct Verbs in the bnxt_re library.

This is required by vendor specific applications that need to manage
the HW resources directly and to implement the datapath in the
application.

To support this, the library and the driver are being enhanced to
provide Direct Verbs using which the application can allocate and
manage the HW resources (Queues, Doorbell etc) . The Direct Verbs
enable the application to implement the control path.

Patch#1 Update kernel headers
Patch#2 Add a helper for VA-backed buffer descriptors
Patch#3 Add ibv_buf APIs for user allocated memory
Patch#4 Export HSI file
Patch#5 Support DBR verbs
Patch#6 Update bnxt_re_cq to include struct verbs_cq
Patch#7 Support CQ verbs
Patch#8 Support QP verbs
Patch#9 Add man pages

Thanks,
-Harsha

@jgunthorpe

Copy link
Copy Markdown
Member

Please take the debug_file stuff out of here, I'm not keen on every driver implementing their own stuff. We already have tracing frameworks supported, why not use one?

Comment thread providers/bnxt_re/bnxt_re_dv.h Outdated
struct bnxt_re_dv_db_region_attr *attr);
int bnxt_re_dv_get_default_db_region(struct ibv_context *ibvctx,
struct bnxt_re_dv_db_region_attr *out);
void *bnxt_re_dv_umem_reg(struct ibv_context *ibvctx,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void *? That shouldn't be. Why do you have these functions when there is no kernel side?

@sbasavapatna

sbasavapatna commented Dec 24, 2025 via email

Copy link
Copy Markdown
Contributor Author

@sbasavapatna

sbasavapatna commented Dec 24, 2025 via email

Copy link
Copy Markdown
Contributor Author

@jgunthorpe

Copy link
Copy Markdown
Member

So give it an opaque type, don't just randomly use void *s.

Again,why is this stuff here when there is no kernel side for umems?

@sbasavapatna

sbasavapatna commented Jan 8, 2026 via email

Copy link
Copy Markdown
Contributor Author

@sbasavapatna

Copy link
Copy Markdown
Contributor Author

On Thu, Jan 8, 2026 at 1:28 AM Jason Gunthorpe @.> wrote: jgunthorpe left a comment (linux-rdma/rdma-core#1654) <#1654 (comment)> So give it an opaque type, don't just randomly use void s.
Are you suggesting to use a pointer to the forward declaration of that structure? Is that what you meant by "give it an opaque type"? Please clarify.
Again,why is this stuff here when there is no kernel side for umems?
The application registers the addr and the total size of the memory area with the library, initially using this API. Later during each object creation, the library uses this information to provide the actual va (base-addr + offset) for mapping/pinning, to the kernel driver. This has been captured in the kernel driver review thread: @.
/

— Reply to this email directly, view it on GitHub <#1654 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGTY2BIR6EFHFZXC2CENTI34FVQP5AVCNFSM6AAAAACK7AEXQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTOMRQGUZTOMBUGI . You are receiving this because you authored the thread.Message ID: @.
**>

Here's the pointer to the kernel review thread for reference:
https://lore.kernel.org/linux-rdma/CAHHeUGXGTfsK66DOGdE6Y5VYVaOR=1YA6b2inds6_EkPSwTBuA@mail.gmail.com/

@jgunthorpe

Copy link
Copy Markdown
Member

Just have some 'struct bnxt_umem' as a forward declaration that never sees an actual definition. It is now an opaque type you can use instead of void.

You also need to write man pages for these functions, see providers/mlx5/man/mlx5dv_devx_umem_reg.3.md for instance.

@sbasavapatna

sbasavapatna commented Jan 13, 2026 via email

Copy link
Copy Markdown
Contributor Author

@sbasavapatna

Copy link
Copy Markdown
Contributor Author

While looking into changes needed in the bnxt_re kernel driver to process DBR passed through driver specific attributes (during QP creation), I noticed that the corresponding libibverbs support seems to be missing in cmd_qp.c.
That is, ibv_cmd_create_qp_ex() doesn't support "ibv_command_buffer *driver" arg that should be linked to the main command buffer that it creates. This is supported in CQ creation command though (ibv_cmd_create_cq_ex2()).

@jgunthorpe

Copy link
Copy Markdown
Member

As the first user you'd need to do a similar thing as CQ.

@sbasavapatna

sbasavapatna commented Jan 17, 2026 via email

Copy link
Copy Markdown
Contributor Author

@sbasavapatna
sbasavapatna force-pushed the dv-upstream branch 2 times, most recently from 294a076 to 3d8c351 Compare February 3, 2026 05:11
@sbasavapatna
sbasavapatna force-pushed the dv-upstream branch 2 times, most recently from d43117e to 362804c Compare February 11, 2026 12:59
@sbasavapatna sbasavapatna reopened this Apr 7, 2026
@sbasavapatna
sbasavapatna force-pushed the dv-upstream branch 3 times, most recently from 7a10dd5 to 24a1e0f Compare April 8, 2026 08:33
@sbasavapatna
sbasavapatna requested a review from jgunthorpe April 8, 2026 08:34
@sbasavapatna sbasavapatna reopened this Jun 17, 2026
@sbasavapatna
sbasavapatna force-pushed the dv-upstream branch 4 times, most recently from 530f887 to 28d4255 Compare June 17, 2026 10:16
@sbasavapatna sbasavapatna reopened this Jul 3, 2026
Comment thread libibverbs/driver.h
fill_attr_in_ptr(cmdb, attr_id, storage);
cmdb->fallback_ioctl_only = 1;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not make sense to have this as separate helper. Your caller checks "buf->fd ==-1". You can do the check inside fill_attr_in_buf_umem and fill up things (like type) appropriately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, will update it in the next version.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks okay to me now.

Comment thread providers/bnxt_re/bnxt_re_dv.h Outdated
};

struct bnxt_re_dv_umem_reg_attr {
void *addr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates the layout of struct ibv_buf. Why you can't use it directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a user facing structure and we don't want to change it as it would impact applications that are already using it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This puzzles me. How an application can use this struct if you are only introducing it now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOB solution which already exists is being upstreamed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, you say that you form the API of a feature currently being pushed upon some out of tree code and use it as argument the API can't be changed? I have troubles to understand that reasoning, sorry.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure layouts are slightly different. We have added a comp_mask for vendor specific extensions.

struct bnxt_re_dv_umem_reg_attr {
void *addr;
size_t size;
uint64_t comp_mask;
int dmabuf_fd;
};
struct ibv_buf {
void *addr;
size_t size;
struct ibv_pd *pd;
int dmabuf_fd;
};

Also, since this is a Direct Verb to the user application, we want to maintain the same ABI for both our inbox and out-of-tree libraries, so that the applications can work seamlessly on both installations. So unless you see a design level issue here, we would prefer to keep this as-is and avoid any impact to existing customers that are using out-of-tree packages.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you have comp_mask here is a mystery. Not needed (and if really, really need it, you can embed ibv_buf - so no argument). Basically they are same structures. Don't screw-up the API in a name of out-of-tree code. That is fundamentally wrong. Please fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Jiri, we have ibv_buf now that is the user facing API surface for a dmabuf or a VA or whatever, you should add some API to allow the user to create an ibv_buf from other things and consistently use that in your here in DV. Get rid of the umem here, it completely duplicates what ibv_buf is trying to do.

You guys choose to do the OOT thing, the broken ABIs are all your problem to deal with.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a couple of APIs as suggested to associate/disassociate an ibv_buf with user allocated memory. This ibv_buf will then be passed to bnxt_re_dv_create_cq/qp APIs.

Comment thread providers/bnxt_re/dv.c Outdated

ret = execute_ioctl(ibvctx, cmd);
if (ret) {
fprintf(stderr, "%s: execute_ioctl() failed: %d\n", __func__, ret);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not print errors from libraries like this, remove them all

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove these error prints.

Comment thread providers/bnxt_re/verbs.c
(struct ibv_create_cq_ex *)&cmd.ibv_cmd,
sizeof(cmd),
(struct ib_uverbs_ex_create_cq_resp *)&resp.ibv_resp,
sizeof(resp), 0))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all the casts here? It shouldn't have casts if written properly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix this.

Comment thread providers/bnxt_re/verbs.c Outdated

if (ibv_cmd_create_qp_ex(ibvctx, &qp->vqp, attr,
&req.ibv_cmd, sizeof(req), &resp.ibv_resp, sizeof(resp)))
&req.ibv_cmd, sizeof(req), &resp.ibv_resp, sizeof(resp)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray whitespace?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept.

Comment thread providers/bnxt_re/dv.c
(struct verbs_cq *)&cq->ibvcq,
(struct ibv_create_cq_ex *)&cmd.ibv_cmd, sizeof(cmd),
(struct ib_uverbs_ex_create_cq_resp *)&resp->ibv_resp,
sizeof(*resp), 0, driver_attrs);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why casts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be fixed.

Comment thread providers/bnxt_re/bnxt_re_dv.h Outdated
};

struct bnxt_re_dv_umem_reg_attr {
void *addr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Jiri, we have ibv_buf now that is the user facing API surface for a dmabuf or a VA or whatever, you should add some API to allow the user to create an ibv_buf from other things and consistently use that in your here in DV. Get rid of the umem here, it completely duplicates what ibv_buf is trying to do.

You guys choose to do the OOT thing, the broken ABIs are all your problem to deal with.

Comment thread providers/bnxt_re/dv.c Outdated
dst->ah_attr.grh.flow_label = src->ah_attr.grh.flow_label;
}

int bnxt_re_dv_query_qp(struct ibv_qp *ibvqp, struct ib_uverbs_qp_attr *qp_attr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type ib_uverbs_qp_attr should not be returned from a library interface, it is a kernel facing type

I don't even understand why this function exists in the first place

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this; in the next version this will be restored to standard bnxt_re_query_qp() and the dv function will be removed.

Comment thread providers/bnxt_re/dv.c Outdated

rc = ibv_cmd_query_qp(ibvqp, &attr, qp_attr->qp_attr_mask, &init_attr,
&cmd, sizeof(cmd));
if (!rc) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

success oriented flow

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function itself won't be there in the next version.

registration, aligned to the device page size; **ncqe** is the requested number
of CQEs.

This path requires **IB_UVERBS_CORE_SUPPORT_ROBUST_UDATA** (robust udata) on the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like something the user needs to know. You could write 'this call requires linux kernel version >= 'xyz

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

```c
#include <infiniband/bnxt_re_dv.h>

int bnxt_re_dv_destroy_qp(struct ibv_qp *ibvqp);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this exist? What is wrong with the normal QP destruction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DV variants of QP functions - destroy, query and modify will be removed; they were mostly wrappers. Similarly dv_destroy_cq will also be removed.

struct bnxt_re_dv_db_region_attr {
uint32_t handle; /* kernel handle for this doorbell region */
uint32_t dpi; /* doorbell page index */
uint64_t umdbr; /* unmapped doorbell BAR offset */

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intended flow for using umdbr? Does unmapped mean not mapped into application virtual address space?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the raw PCI-BAR/physical-address of the doorbell register page.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How user space can use this field?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not meant for normal user-space applications. It is intended to support future extensions for peer devices like GPUs that may need to directly write to the Doorbell BAR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it supposed to be used somehow with DMA buf then? https://www.kernel.org/doc/html/latest/driver-api/dma-buf.html

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? You cannot expose a physical address to userspace. Send a kernel patch to take this away please.

@Aswin5005 Aswin5005 Aug 24, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass a File Descriptor with help of dma-buf framework to user space instead of returning raw Physical address ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? You cannot expose a physical address to userspace. Send a kernel patch to take this away please.

Since the ABI structure is already in released kernels (7.1, 7.2), we can't remove the field right? I have a patch that changes it to a reserved field and avoids setting it. If that's ok, I can send out that patch, let me know.

@sbasavapatna sbasavapatna reopened this Aug 21, 2026
@sbasavapatna
sbasavapatna force-pushed the dv-upstream branch 2 times, most recently from 35fcb9e to 1732e14 Compare August 24, 2026 18:01
sbasavapatna and others added 10 commits September 9, 2026 11:27
To commit: 23d7e03a52ec ("RDMA/bnxt_re: Avoid exposing umdbr to
userspace").

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
fill_attr_in_buf_umem() only handles dmabuf-backed buffers.
Extend it for user virtual address buffers.

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
ibv_alloc_buf() only allocates library memory and initializes an ibv_buf
for it; there's no way to associate an ibv_buf with memory the application
already owns. Add ibv_alloc_user_buf()/ibv_free_user_buf() so providers
can do that (VA or dmabuf) for direct consumption by driver-specific
control-buffer (e.g queue memory) descriptors.

Applications will call this to associate their own CQ/QP buffers as an
ibv_buf. The resulting ibv_buf is then passed to the CQ/QP creation
Direct Verb APIs added later in this series.

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Extract HSI definitions (WQE/CQE structures and enums) from
bnxt_re-abi.h into a standalone bnxt_re-hsi.h and add it to
publish_headers() so it is installed under infiniband/.

This will make HSI definitions available to DV applications,
that implement their own datapath.

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Reviewed-by: Selvin Xavier <selvin.xavier@broadcom.com>
The following Direct Verb (DV) APIs have been implemented in
this patch.

Doorbell Region Direct Verbs:

- bnxt_re_dv_alloc_db_region():
  This will allow the appliation to create extra doorbell regions
  and use the associated doorbell page index in dv_create_qp() and
  use the associated DB address while ringing the doorbell.

- bnxt_re_dv_free_db_region():
  Free the allocated doorbell region.

- bnxt_re_dv_get_default_db_region():
  Return the default doorbell page index and doorbell page address
  associated with the ucontext.

Co-developed-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Selvin Xavier <selvin.xavier@broadcom.com>
The next patch in this series switches to ibv_cmd_create_cq_ex()/_ex2(),
which take a struct verbs_cq as an argument instead of ibv_cq. So update
bnxt_re_cq to replace ibv_cq with verbs_cq.

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
The following Direct Verb (DV) API has been implemented in
this patch, by enhancing the driver specific udata in the
existing verb.

- bnxt_re_dv_create_cq():
  Create a CQ of requested size (cqe). The application must have
  already associated this memory with an ibv_buf using
  ibv_alloc_user_buf(). The CQ's umem_handle and umem_offset
  provided by the application are translated into an address for
  mapping and passed to the driver.

Note:
Some applications might want to allocate memory for all CQs in one big
chunk and associate that entire memory with a single ibv_buf using
ibv_alloc_user_buf(). At the time of creating each individual resource,
the application should pass a specific offset/length within that
memory.

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Co-developed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Selvin Xavier <selvin.xavier@broadcom.com>
The following Direct Verb (DV) API has been implemented in
this patch, by enhancing the driver specific udata in the
existing verb.

- bnxt_re_dv_create_qp():
  Create a QP using specified params (struct bnxt_re_dv_qp_init_attr).
  The application must have already associated SQ/RQ memory with an
  ibv_buf using ibv_alloc_user_buf(). The SQ/RQ umem_handle and umem_offset
  provided by the application are translated into an address for mapping
  and passed to the driver.

Note:
Some applications might want to allocate memory for all QPs in one big
chunk and associate that entire memory with a single ibv_buf using
ibv_alloc_user_buf(). At the time of creating each individual resource,
the application should pass a specific offset/length within that memory.

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Reviewed-by: Selvin Xavier <selvin.xavier@broadcom.com>
Document direct verbs (DV) feature and related DV APIs.
The man page describes these DV APIs:
- Doorbell regions (db)
- Completion Queues (cq)
- Queue pairs (qp)

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Reviewed-by: Selvin Xavier <selvin.xavier@broadcom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants