Skip to content

verbs: Add parent-domain ibv_buf allocators for dma-buf - #1862

Open
abhijitG-xlnx wants to merge 7 commits into
linux-rdma:masterfrom
abhijitG-xlnx:alloc_buf_ionic
Open

abhijitG-xlnx wants to merge 7 commits into
linux-rdma:masterfrom
abhijitG-xlnx:alloc_buf_ionic

Conversation

@abhijitG-xlnx

Copy link
Copy Markdown
Contributor

Summary

A parent-domain allocator can return only a raw pointer. A queue ring that lives in a dma-buf also needs the dma-buf fd, the byte offset of that ring inside the dma-buf, and a way for the application to recover its own record from the handle. Without those, several rings cannot share one dma-buf, and the provider cannot hand the kernel an ib_uverbs_buffer_desc.

libibverbs grows an ibv_buf parent-domain allocator that carries the fd, the offset, and an application context. The ionic provider uses that handle for CQ, SQ, and RQ rings, and passes it to the kernel as a buffer descriptor when the kernel advertises support.

libibverbs

struct ibv_buf is what the provider gives the kernel. These changes make one handle enough to describe either a plain virtual address or a dma-buf slice, including a slice that does not start at byte 0 of the dma-buf.

  • ibv_alloc_user_buf_ex() stores dmabuf_offset and an opaque context on a private ibv_buf. ibv_buf_get_context() returns that pointer. ibv_alloc_user_buf() stays in IBVERBS_1.19 and stores offset 0 and a NULL context. The new symbols are IBVERBS_1.20. The private provider ABI moves to 67 because mlx5 embeds struct ibv_buf.
  • fill_attr_in_buf_umem() writes a IB_UVERBS_BUFFER_TYPE_DMABUF descriptor whose address is dmabuf_offset plus the distance from buf->addr to the requested slice. Each ring can have its own handle and its own offset in one dma-buf. A handle with no dma-buf fd is described as IB_UVERBS_BUFFER_TYPE_VA.
  • ibv_alloc_parent_domain() gains alloc_buf and free_buf, selected by IBV_PARENT_DOMAIN_INIT_ATTR_BUF_ALLOCATORS. alloc_buf returns an ibv_buf, NULL on failure, or IBV_BUF_ALLOCATOR_USE_DEFAULT to decline. Both callbacks are required when the bit is set. The existing alloc and free pointers are unchanged. mlx5 rejects the new bit.

ionic

ionic takes the handle from alloc_buf and, when the kernel can accept it, sends the ring as a buffer descriptor instead of only as a raw address.

  • Mapping a CQ, SQ, RQ, or RCQ ring tries alloc_buf, then the existing void * allocator, then an anonymous mapping. The ibv_buf is kept on the queue and passed to free_buf when the queue is destroyed.
  • Kernel headers gain IONIC_CTX_CMASK_CQ_QP_BUF_UMEM and IONIC_IB_ATTR_CREATE_CQ_BUF_UMEM_0 and _1.
  • When the capability bit is set, each enabled CQ ring is passed to ibv_cmd_create_cq_ex2() as a buffer descriptor. SQ and RQ rings are passed to ibv_cmd_create_qp_ex2() as UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM and UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM. Only rings the QP has are described. Ring geometry stays in the existing ionic request.
  • A handle with a dma-buf fd becomes a dma-buf descriptor at dmabuf_offset, and the request ring address is 0 so the kernel takes the ring from the descriptor. A handle without a dma-buf fd stays a virtual-address descriptor. If the kernel does not advertise the capability, a dma-buf handle is freed and queue creation fails with EOPNOTSUPP.
  • ionicdv(7) documents dma-buf rings, the parent-domain allocator, the kernel capability, the required CPU mapping, and sharing one dma-buf through dmabuf_offset.

ibv_alloc_user_buf() stays IBVERBS_1.19. Add ibv_alloc_user_buf_ex()
and ibv_buf_get_context() so an application can recover its own record
from the handle without a side table or container_of. The ex function
also stores a dma-buf offset, which fill_attr_in_buf_umem() adds when
it builds a dma-buf descriptor. The new fields are private, and mlx5
embeds struct ibv_buf, so the provider ABI moves to 67.

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
Append alloc_buf and free_buf to ibv_parent_domain_init_attr, gated by
IBV_PARENT_DOMAIN_INIT_ATTR_BUF_ALLOCATORS. Existing alloc and free
pointers stay where they are. alloc_buf returns an ibv_buf, NULL, or
IBV_BUF_ALLOCATOR_USE_DEFAULT. Both callbacks are required when the bit
is set.

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
Try alloc_buf when mapping a queue ring, then the existing void* alloc,
then the anonymous map. Unmap calls free_buf with the saved handle when
that is how the ring was mapped. The bit is stored only when it is set.

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
To commit: ("RDMA/ionic: Accept CQ ring buffers as ioctl umem attributes").

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
Add a per-UDMA-pipeline driver attribute for create_cq so each enabled
CQ ring can be passed to the kernel as a struct ib_uverbs_buffer_desc
instead of only as a raw address in the ionic_cq_req payload.

The kernel advertises support through IONIC_CTX_CMASK_CQ_QP_BUF_UMEM in
the get_context comp_mask. When the bit is set, the CQ is created with
ibv_cmd_create_cq_ex2() and one IONIC_IB_ATTR_CREATE_CQ_BUF_UMEM_<n>
attribute per set UDMA mask bit. When the bit is clear, the existing
ibv_cmd_create_cq() write path is used unchanged.

ionic_cq_req and ionic_cq_resp are not changed. The ring address,
depth, stride and mask are still filled in the request so that older
kernels keep working and the kernel can read the ring geometry.

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
When IONIC_CTX_CMASK_CQ_QP_BUF_UMEM is set, pass the send and receive
rings to ibv_cmd_create_qp_ex2() as UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM
and UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM virtual address descriptors.
Describe only the rings the QP has.

Without the capability bit, create the QP as before, with no driver
attributes.

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
When the parent-domain alloc_buf callback returns an ibv_buf that
carries a dma-buf fd, pass the CQ, SQ and RQ rings to the kernel as
IB_UVERBS_BUFFER_TYPE_DMABUF descriptors. The descriptor offset is the
handle's dmabuf_offset, so several rings can share one dma-buf. Handles
without a dma-buf fd are passed as virtual address descriptors.

Set the ring address in ionic_cq_req and ionic_qp_req to zero for
dma-buf rings, so the kernel takes the ring from the descriptor.

dma-buf rings require IONIC_CTX_CMASK_CQ_QP_BUF_UMEM. Without it, free
the handle and fail queue creation with EOPNOTSUPP.

Document dma-buf rings in ionicdv(7).

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.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.

1 participant