verbs: Don't add VA UMEM attrs from fill_attr_in_buf_umem()
Extending fill_attr_in_buf_umem() for VA-backed buffers made it always
add a mandatory UMEM attribute, even for non-dmabuf buffers. Generic
callers such as create CQ then fail with EOPNOTSUPP on kernels older
than v7.2, with no fallback to the write command.
Restore the dmabuf-only behavior and move VA handling into a new
fill_attr_in_buf_umem_va() helper, used by the bnxt_re direct verbs
callers.
Fixes: 8c17f5926802 ("verbs: Extend fill_attr_in_buf_umem() for VA-backed descriptors")
Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com>
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
index 711450c..3507999 100644
--- a/libibverbs/driver.h
+++ b/libibverbs/driver.h
@@ -873,32 +873,53 @@
}
/**
- * In case the length is 0, the buffer size is used. Handles both
- * dmabuf-backed and plain user virtual address buffers.
+ * In case the length is 0, the buffer size is used.
*/
static inline void
fill_attr_in_buf_umem(struct ibv_command_buffer *cmdb, uint16_t attr_id,
struct ib_uverbs_buffer_desc *storage,
struct ibv_buf *buf, void *addr, size_t length)
{
+ if (!buf || buf->dmabuf_fd == -1)
+ return;
+
+ *storage = (struct ib_uverbs_buffer_desc){
+ .type = IB_UVERBS_BUFFER_TYPE_DMABUF,
+ .fd = buf->dmabuf_fd,
+ .addr = addr ? (uintptr_t)addr - (uintptr_t)buf->addr : 0,
+ .length = length ? length : buf->size,
+ };
+ fill_attr_in_ptr(cmdb, attr_id, storage);
+ cmdb->fallback_ioctl_only = 1;
+}
+
+/**
+ * Like fill_attr_in_buf_umem(), but also describes plain user virtual
+ * address buffers (IB_UVERBS_BUFFER_TYPE_VA). The attribute is always added
+ * and is mandatory, so only use it where the caller requires UMEM attribute
+ * support from the kernel (e.g. direct verbs), never on generic paths.
+ * In case the length is 0, the buffer size is used.
+ */
+static inline void
+fill_attr_in_buf_umem_va(struct ibv_command_buffer *cmdb, uint16_t attr_id,
+ struct ib_uverbs_buffer_desc *storage,
+ struct ibv_buf *buf, void *addr, size_t length)
+{
if (!buf)
return;
if (buf->dmabuf_fd != -1) {
- *storage = (struct ib_uverbs_buffer_desc){
- .type = IB_UVERBS_BUFFER_TYPE_DMABUF,
- .fd = buf->dmabuf_fd,
- .addr = addr ? (uintptr_t)addr - (uintptr_t)buf->addr : 0,
- .length = length ? length : buf->size,
- };
- } else {
- *storage = (struct ib_uverbs_buffer_desc){
- .type = IB_UVERBS_BUFFER_TYPE_VA,
- .fd = -1,
- .addr = (uintptr_t)(addr ? addr : buf->addr),
- .length = length ? length : buf->size,
- };
+ fill_attr_in_buf_umem(cmdb, attr_id, storage, buf, addr,
+ length);
+ return;
}
+
+ *storage = (struct ib_uverbs_buffer_desc){
+ .type = IB_UVERBS_BUFFER_TYPE_VA,
+ .fd = -1,
+ .addr = (uintptr_t)(addr ? addr : buf->addr),
+ .length = length ? length : buf->size,
+ };
fill_attr_in_ptr(cmdb, attr_id, storage);
cmdb->fallback_ioctl_only = 1;
}
diff --git a/providers/bnxt_re/dv.c b/providers/bnxt_re/dv.c
index b165a55..5be9a62 100644
--- a/providers/bnxt_re/dv.c
+++ b/providers/bnxt_re/dv.c
@@ -145,9 +145,9 @@
buf_addr = (uint8_t *)cq_buf->addr + offset;
cmd.cq_va = (uintptr_t)buf_addr;
- fill_attr_in_buf_umem(driver_attrs, UVERBS_ATTR_CREATE_CQ_BUF_UMEM,
- &cq_buf_umem_desc, cq_buf,
- buf_addr, size);
+ fill_attr_in_buf_umem_va(driver_attrs, UVERBS_ATTR_CREATE_CQ_BUF_UMEM,
+ &cq_buf_umem_desc, cq_buf,
+ buf_addr, size);
cq_attr_ex.cqe = cq_attr->ncqe;
cq_attr_ex.comp_mask = 0;
@@ -304,9 +304,9 @@
req.sq_slots = dv_qp_attr->sq_slots;
req.sq_npsn = dv_qp_attr->sq_npsn;
buf_addr = (uint8_t *)sq_buf->addr + offset;
- fill_attr_in_buf_umem(driver_attrs, UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM,
- &sq_buf_umem_desc, sq_buf,
- buf_addr, size);
+ fill_attr_in_buf_umem_va(driver_attrs, UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM,
+ &sq_buf_umem_desc, sq_buf,
+ buf_addr, size);
/* Keep qpsva as fallback for kernels without SQ_BUF_UMEM support */
req.qpsva = (uintptr_t)buf_addr;
@@ -319,10 +319,10 @@
return -EINVAL;
buf_addr = (uint8_t *)rq_buf->addr + offset;
- fill_attr_in_buf_umem(driver_attrs,
- UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM,
- &rq_buf_umem_desc, rq_buf,
- buf_addr, size);
+ fill_attr_in_buf_umem_va(driver_attrs,
+ UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM,
+ &rq_buf_umem_desc, rq_buf,
+ buf_addr, size);
/* Keep qprva as fallback for kernels without RQ_BUF_UMEM support */
req.qprva = (uintptr_t)buf_addr;
}