]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
RDMA/core: Do not compile ib_core_uverbs without USER_ACCESS
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 26 May 2026 01:22:37 +0000 (22:22 -0300)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 26 May 2026 13:07:25 +0000 (10:07 -0300)
Remove the entire ib_core_uverbs.c from the build if
CONFIG_INFINIBAND_USER_ACCESS is not set. These functions are only used to
support uverbs and are never callable even if they happen to get linked
in.

Provide inlines for the missing ones to return errors to further push code
elimination in drivers.

Link: https://patch.msgid.link/r/1-v3-43aba1969751+1988-ib_uverbs_support_ko_jgg@nvidia.com
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/Kconfig
drivers/infiniband/core/Makefile
drivers/infiniband/core/ib_core_uverbs.c
drivers/infiniband/core/rdma_core.h
include/rdma/ib_verbs.h
include/rdma/uverbs_ioctl.h

index a7e3f29dc037f46bb313831212aa22212bc50fc2..086195758a8ac83bd978960f1fc4caec4cbc57d5 100644 (file)
@@ -37,6 +37,10 @@ config INFINIBAND_USER_ACCESS
          libibverbs, libibcm and a hardware driver library from
          rdma-core <https://github.com/linux-rdma/rdma-core>.
 
+config INFINIBAND_USER_ACCESS_CORE
+       bool
+       default y if INFINIBAND_USER_ACCESS != n
+
 config INFINIBAND_USER_MEM
        bool
        depends on INFINIBAND_USER_ACCESS != n
index dce798d8cfe67b74b18837cf0f9e86e2ff5db3ca..8c2ba2ce0351760d38b7f6ceb69008887df5bdc1 100644 (file)
@@ -11,13 +11,14 @@ ib_core-y :=                        packer.o ud_header.o verbs.o cq.o rw.o sysfs.o \
                                device.o cache.o netlink.o \
                                roce_gid_mgmt.o mr_pool.o addr.o sa_query.o \
                                multicast.o mad.o smi.o agent.o mad_rmpp.o \
-                               nldev.o restrack.o counters.o ib_core_uverbs.o \
+                               nldev.o restrack.o counters.o \
                                trace.o lag.o iter.o frmr_pools.o
 
 ib_core-$(CONFIG_SECURITY_INFINIBAND) += security.o
 ib_core-$(CONFIG_CGROUP_RDMA) += cgroup.o
 ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o umem_dmabuf.o
 ib_core-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += umem_odp.o
+ib_core-$(CONFIG_INFINIBAND_USER_ACCESS_CORE) += ib_core_uverbs.o
 
 ib_cm-y :=                     cm.o cm_trace.o
 
index 8a0e6fa2a528372f8bb1abd983445e3a74eb83c6..0acb0d4967cb6ba81c265ec57c6a4fe4ca47cc89 100644 (file)
@@ -398,7 +398,7 @@ EXPORT_SYMBOL(rdma_user_mmap_entry_insert);
  * 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)
+static struct ib_device *rdma_udata_to_dev(struct ib_udata *udata)
 {
        struct uverbs_attr_bundle *bundle =
                rdma_udata_to_uverbs_attr_bundle(udata);
@@ -415,10 +415,9 @@ struct ib_device *rdma_udata_to_dev(struct ib_udata *udata)
        return srcu_dereference(bundle->ufile->device->ib_dev,
                                &bundle->ufile->device->disassociate_srcu);
 }
-EXPORT_SYMBOL(rdma_udata_to_dev);
 
-#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
-uverbs_api_ioctl_handler_fn uverbs_get_handler_fn(struct ib_udata *udata)
+typedef int (*uverbs_api_ioctl_handler_fn)(struct uverbs_attr_bundle *attrs);
+static uverbs_api_ioctl_handler_fn uverbs_get_handler_fn(struct ib_udata *udata)
 {
        struct uverbs_attr_bundle *bundle =
                rdma_udata_to_uverbs_attr_bundle(udata);
@@ -502,4 +501,3 @@ err_fault:
        return -EFAULT;
 }
 EXPORT_SYMBOL(_ib_respond_udata);
-#endif
index 269b393799abbcf673e5a6798561973143c2d846..55f1e3558856f129d125d44011fe2837130bb457 100644 (file)
@@ -151,9 +151,6 @@ void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm,
                              unsigned int num_attrs);
 void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile);
 
-typedef int (*uverbs_api_ioctl_handler_fn)(struct uverbs_attr_bundle *attrs);
-uverbs_api_ioctl_handler_fn uverbs_get_handler_fn(struct ib_udata *udata);
-
 extern const struct uapi_definition uverbs_def_obj_async_fd[];
 extern const struct uapi_definition uverbs_def_obj_counters[];
 extern const struct uapi_definition uverbs_def_obj_cq[];
index 9dd76f489a0ba4c580854e87bb985a7027626d72..01e0eea0703f9d60eaf5bc77da08bd5e57743b9c 100644 (file)
@@ -3101,6 +3101,7 @@ void  ib_set_client_data(struct ib_device *device, struct ib_client *client,
 void ib_set_device_ops(struct ib_device *device,
                       const struct ib_device_ops *ops);
 
+#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
 int rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma,
                      unsigned long pfn, unsigned long size, pgprot_t prot,
                      struct rdma_user_mmap_entry *entry);
@@ -3112,13 +3113,7 @@ int rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
                                      size_t length, u32 min_pgoff,
                                      u32 max_pgoff);
 
-#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
 void rdma_user_mmap_disassociate(struct ib_device *device);
-#else
-static inline void rdma_user_mmap_disassociate(struct ib_device *device)
-{
-}
-#endif
 
 static inline int
 rdma_user_mmap_entry_insert_exact(struct ib_ucontext *ucontext,
@@ -3138,6 +3133,66 @@ rdma_user_mmap_entry_get(struct ib_ucontext *ucontext,
 void rdma_user_mmap_entry_put(struct rdma_user_mmap_entry *entry);
 
 void rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry);
+#else
+static inline int rdma_user_mmap_io(struct ib_ucontext *ucontext,
+                                   struct vm_area_struct *vma,
+                                   unsigned long pfn, unsigned long size,
+                                   pgprot_t prot,
+                                   struct rdma_user_mmap_entry *entry)
+{
+       return -EINVAL;
+}
+
+static inline int
+rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
+                           struct rdma_user_mmap_entry *entry, size_t length)
+{
+       return -EINVAL;
+}
+
+static inline int
+rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
+                                 struct rdma_user_mmap_entry *entry,
+                                 size_t length, u32 min_pgoff, u32 max_pgoff)
+{
+       return -EINVAL;
+}
+
+static inline void rdma_user_mmap_disassociate(struct ib_device *device)
+{
+}
+
+static inline int
+rdma_user_mmap_entry_insert_exact(struct ib_ucontext *ucontext,
+                                 struct rdma_user_mmap_entry *entry,
+                                 size_t length, u32 pgoff)
+{
+       return -EINVAL;
+}
+
+static inline struct rdma_user_mmap_entry *
+rdma_user_mmap_entry_get_pgoff(struct ib_ucontext *ucontext,
+                              unsigned long pgoff)
+{
+       return NULL;
+}
+
+static inline struct rdma_user_mmap_entry *
+rdma_user_mmap_entry_get(struct ib_ucontext *ucontext,
+                        struct vm_area_struct *vma)
+{
+       return NULL;
+}
+
+static inline void rdma_user_mmap_entry_put(struct rdma_user_mmap_entry *entry)
+{
+}
+
+static inline void
+rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry)
+{
+}
+#endif
 
 static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
 {
index c89428030d61aebf20510fcc6cf14d3a5f2bdab6..9d7575d999e121e1ab4fb7987f2f6cf8129c2e0e 100644 (file)
@@ -668,8 +668,6 @@ 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,
@@ -902,6 +900,8 @@ int uverbs_copy_to_struct_or_zero(const struct uverbs_attr_bundle *bundle,
 int _ib_copy_validate_udata_in(struct ib_udata *udata, void *req,
                               size_t kernel_size, size_t minimum_size);
 int _ib_respond_udata(struct ib_udata *udata, const void *src, size_t len);
+int _ib_copy_validate_udata_cm_fail(struct ib_udata *udata, u64 req_cm,
+                                   u64 valid_cm);
 #else
 static inline int
 uverbs_get_flags64(u64 *to, const struct uverbs_attr_bundle *attrs_bundle,
@@ -971,6 +971,12 @@ static inline int _ib_respond_udata(struct ib_udata *udata, const void *src,
 {
        return -EINVAL;
 }
+
+static inline int _ib_copy_validate_udata_cm_fail(struct ib_udata *udata,
+                                                 u64 req_cm, u64 valid_cm)
+{
+       return -EINVAL;
+}
 #endif
 
 #define uverbs_get_const_signed(_to, _attrs_bundle, _idx)                      \
@@ -1051,9 +1057,6 @@ uverbs_get_raw_fd(int *to, const struct uverbs_attr_bundle *attrs_bundle,
        _ib_copy_validate_udata_in(_udata, &(_req), sizeof(_req), \
                                   offsetofend(typeof(_req), _end_member))
 
-int _ib_copy_validate_udata_cm_fail(struct ib_udata *udata, u64 req_cm,
-                                   u64 valid_cm);
-
 /**
  * ib_copy_validate_udata_in_cm - Copy the req structure and check the comp_mask
  * @_udata: The system calls ib_udata struct