]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
RDMA/core: Add rdma_udata_to_dev()
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 3 Mar 2026 19:49:59 +0000 (15:49 -0400)
committerJason Gunthorpe <jgg@nvidia.com>
Sun, 8 Mar 2026 10:20:24 +0000 (06:20 -0400)
Get an ib_device out of a udata so it can be used for debug prints.

Link: https://patch.msgid.link/r/2-v3-bd56dd443069+49-bnxt_re_uapi_jgg@nvidia.com
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/ib_core_uverbs.c
include/rdma/uverbs_ioctl.h

index d3836a62a00495a9ae0c9fdbb0fe827f36df1710..bfe37a9c8a72bf1f5ee94e52fea1621dccea24c0 100644 (file)
@@ -389,3 +389,30 @@ int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
                                                 U32_MAX);
 }
 EXPORT_SYMBOL(rdma_user_mmap_entry_insert);
+
+/**
+ * rdma_udata_to_dev - Get a ib_device from a udata
+ * @udata: The system calls ib_udata struct
+ *
+ * The struct ib_device that is handling the uverbs call. Must not be called if
+ * udata is NULL. The result can be NULL.
+ */
+struct ib_device *rdma_udata_to_dev(struct ib_udata *udata)
+{
+       struct uverbs_attr_bundle *bundle =
+               rdma_udata_to_uverbs_attr_bundle(udata);
+
+       lockdep_assert_held(&bundle->ufile->device->disassociate_srcu);
+
+       if (bundle->context)
+               return bundle->context->device;
+
+       /*
+        * If the context hasn't been created yet use the ufile's dev, but it
+        * might be NULL if we are racing with disassociate.
+        */
+       return srcu_dereference(bundle->ufile->device->ib_dev,
+                               &bundle->ufile->device->disassociate_srcu);
+}
+EXPORT_SYMBOL(rdma_udata_to_dev);
+
index e6c0de227fad3d0587b486076713bd5f9b2f1d3f..bb86d8ae8a834b34e2b0c5e70690ddee2aec5bf3 100644 (file)
@@ -667,6 +667,8 @@ rdma_udata_to_uverbs_attr_bundle(struct ib_udata *udata)
        (udata ? container_of(rdma_udata_to_uverbs_attr_bundle(udata)->context, \
                              drv_dev_struct, member) : (drv_dev_struct *)NULL)
 
+struct ib_device *rdma_udata_to_dev(struct ib_udata *udata);
+
 #define IS_UVERBS_COPY_ERR(_ret)               ((_ret) && (_ret) != -ENOENT)
 
 static inline const struct uverbs_attr *uverbs_attr_get(const struct uverbs_attr_bundle *attrs_bundle,