Re: [PATCH rdma-next v6 3/4] RDMA/bnxt_re: Direct Verbs: Support DBR verbs

Jason Gunthorpe
2026-01-09T18:55:44Z

On Wed, Dec 24, 2025 at 09:56:01AM +0530, Sriharsha Basavapatna wrote:
> +static int UVERBS_HANDLER(BNXT_RE_METHOD_DBR_ALLOC)(struct uverbs_attr_bundle *attrs)
> +{
> + struct bnxt_re_dv_db_region dbr = {};
> + struct bnxt_re_alloc_dbr_obj *obj;
> + struct bnxt_re_ucontext *uctx;
> + struct ib_ucontext *ib_uctx;
> + struct bnxt_qplib_dpi *dpi;
> + struct bnxt_re_dev *rdev;
> + struct ib_uobject *uobj;
> + u64 mmap_offset;
> + int ret;
> +
> + ib_uctx = ib_uverbs_get_ucontext(attrs);
> + if (IS_ERR(ib_uctx))
> + return PTR_ERR(ib_uctx);
> +
> + uctx = container_of(ib_uctx, struct bnxt_re_ucontext, ib_uctx);
> + rdev = uctx->rdev;
> + uobj = uverbs_attr_get_uobject(attrs, BNXT_RE_DV_ALLOC_DBR_HANDLE);
> +
> + obj = kzalloc(sizeof(*obj), GFP_KERNEL);
> + if (!obj)
> + return -ENOMEM;
> +
> + dpi = &obj->dpi;
> + ret = bnxt_qplib_alloc_uc_dpi(&rdev->qplib_res, dpi);
> + if (ret)
> + goto free_mem;
> +
> + obj->entry = bnxt_re_mmap_entry_insert(uctx, 0, BNXT_RE_MMAP_UC_DB,
> + &mmap_offset);
> + if (!obj->entry) {
> + ret = -ENOMEM;
> + goto free_dpi;
> + }
> +
> + obj->rdev = rdev;
> + dbr.umdbr = dpi->umdbr;
> + dbr.dpi = dpi->dpi;
> +
> + ret = uverbs_copy_to_struct_or_zero(attrs, BNXT_RE_DV_ALLOC_DBR_ATTR,
> + &dbr, sizeof(dbr));
> + if (ret)
> + goto free_entry;
> +
> + ret = uverbs_copy_to(attrs, BNXT_RE_DV_ALLOC_DBR_OFFSET,
> + &mmap_offset, sizeof(mmap_offset));
> + if (ret)
> + goto free_entry;
> +
> + uobj->object = obj;
> + uverbs_finalize_uobj_create(attrs, BNXT_RE_DV_ALLOC_DBR_HANDLE);
> + hash_add(rdev->dpi_hash, &obj->hash_entry, dpi->dpi);

This is out of order, hash_del is done inside bnxt_re_dv_dbr_cleanup()
so it should be before finalize, but it isn't a bug.

It should probably be written like this:

uobj->object = obj;
hash_add(rdev->dpi_hash, &obj->hash_entry, dpi->dpi);
uverbs_finalize_uobj_create(attrs, BNXT_RE_DV_ALLOC_DBR_HANDLE);

ret = uverbs_copy_to_struct_or_zero(attrs, BNXT_RE_DV_ALLOC_DBR_ATTR,
&dbr, sizeof(dbr));
if (ret)
return ret;

ret = uverbs_copy_to(attrs, BNXT_RE_DV_ALLOC_DBR_OFFSET,
&mmap_offset, sizeof(mmap_offset));
if (ret)
return ret;
return 0;

Jason