History

RDMA/uverbs: Add CQ buffer UMEM attribute and driver helpers

Add UVERBS_ATTR_CREATE_CQ_BUF_UMEM and two driver-facing wrappers, ib_umem_get_cq_buf() and ib_umem_get_cq_buf_or_va(), that pin a CQ buffer umem from it. The wrappers reuse the existing legacy CQ buffer-attr filler.

Jiri Pirko committed 5 months ago

Commit f6d2e531 parent 057bb704 files · +79 −1Browse files

Unified · Split

4 files
  1. drivers/infiniband/core/umem.c +56 −1
  2. drivers/infiniband/core/uverbs_std_types_cq.c +2 −0
  3. include/rdma/ib_umem.h +20 −0
  4. include/uapi/rdma/ib_user_ioctl_cmds.h +1 −0
drivers/infiniband/core/umem.c+56−1
@@ -497,7 +497,7 @@ struct ib_umem *ib_umem_get_attr_or_va(struct ib_device *device, · 496 unmodified lines
497497 }
498498 EXPORT_SYMBOL(ib_umem_get_attr_or_va);
499499
500−static int uverbs_create_cq_get_buffer_desc(struct uverbs_attr_bundle *attrs,
500+static int uverbs_create_cq_get_buffer_desc(const struct uverbs_attr_bundle *attrs,
501501 struct ib_uverbs_buffer_desc *desc)
502502 {
503503 struct ib_device *ib_dev = attrs->context->device;
@@ -547,6 +547,61 @@ static int uverbs_create_cq_get_buffer_desc(struct uverbs_attr_bundle *attrs, · 43 unmodified lines
547547 return -ENODATA;
548548 }
549549
550+/**
551+ * ib_umem_get_cq_buf - Pin a CQ buffer umem from per-command attributes.
552+ * @device: IB device.
553+ * @attrs: uverbs attribute bundle (may be NULL).
554+ * @size: minimum required CQ buffer length.
555+ * @access: IB access flags.
556+ *
557+ * Resolves the CQ buffer from the new UMEM attribute or the legacy
558+ * CQ buffer attributes. There is no UHW VA fallback, so the caller
559+ * must arrange its own backing (typically an in-kernel allocation)
560+ * when no source is available.
561+ *
562+ * Return: caller-owned umem on success; NULL when no source supplied
563+ * a buffer; ERR_PTR(...) on error.
564+ */
565+struct ib_umem *ib_umem_get_cq_buf(struct ib_device *device,
566+ const struct uverbs_attr_bundle *attrs,
567+ size_t size, int access)
568+{
569+ return ib_umem_get_from_attrs(device, attrs,
570+ UVERBS_ATTR_CREATE_CQ_BUF_UMEM,
571+ uverbs_create_cq_get_buffer_desc,
572+ size, access);
573+}
574+EXPORT_SYMBOL(ib_umem_get_cq_buf);
575+
576+/**
577+ * ib_umem_get_cq_buf_or_va - Pin a CQ buffer umem with UHW VA fallback.
578+ * @device: IB device.
579+ * @attrs: uverbs attribute bundle (may be NULL).
580+ * @addr: UHW user VA used when no per-command attribute matched.
581+ * @size: on the attr / legacy paths, the minimum required umem length
582+ * validated post-pin; on the VA fallback path, the length to pin.
583+ * @access: IB access flags.
584+ *
585+ * Like ib_umem_get_cq_buf(), but pins @addr/@size when neither the
586+ * UMEM attribute nor the legacy CQ buffer attributes are supplied.
587+ *
588+ * See ib_umem_get_attr_or_va() for the note on @size's dual role and
589+ * the migration path for drivers that would distinguish a user-supplied
590+ * length from a driver-computed minimum.
591+ *
592+ * Return: caller-owned umem on success, ERR_PTR(...) on error.
593+ */
594+struct ib_umem *ib_umem_get_cq_buf_or_va(struct ib_device *device,
595+ const struct uverbs_attr_bundle *attrs,
596+ u64 addr, size_t size, int access)
597+{
598+ return ib_umem_get_from_attrs_or_va(device, attrs,
599+ UVERBS_ATTR_CREATE_CQ_BUF_UMEM,
600+ uverbs_create_cq_get_buffer_desc,
601+ addr, size, access);
602+}
603+EXPORT_SYMBOL(ib_umem_get_cq_buf_or_va);
604+
550605 /**
551606 * ib_umem_get_cq_tmp - Temporary CQ buffer umem getter.
552607 * @device: IB device.
drivers/infiniband/core/uverbs_std_types_cq.c+2−0
@@ -215,6 +215,8 @@ DECLARE_UVERBS_NAMED_METHOD( · 214 unmodified lines
215215 UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_CQ_BUFFER_OFFSET,
216216 UVERBS_ATTR_TYPE(u64),
217217 UA_OPTIONAL),
218+ UVERBS_ATTR_UMEM(UVERBS_ATTR_CREATE_CQ_BUF_UMEM,
219+ UA_OPTIONAL),
218220 UVERBS_ATTR_UHW());
219221
220222 static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(
include/rdma/ib_umem.h+20−0
@@ -90,6 +90,12 @@ struct ib_umem *ib_umem_get_attr_or_va(struct ib_device *device, · 89 unmodified lines
9090 const struct uverbs_attr_bundle *attrs,
9191 u16 attr_id, u64 addr, size_t size,
9292 int access);
93+struct ib_umem *ib_umem_get_cq_buf(struct ib_device *device,
94+ const struct uverbs_attr_bundle *attrs,
95+ size_t size, int access);
96+struct ib_umem *ib_umem_get_cq_buf_or_va(struct ib_device *device,
97+ const struct uverbs_attr_bundle *attrs,
98+ u64 addr, size_t size, int access);
9399 struct ib_umem *ib_umem_get_cq_tmp(struct ib_device *device,
94100 struct uverbs_attr_bundle *attrs);
95101
@@ -210,6 +216,20 @@ ib_umem_get_attr_or_va(struct ib_device *device, · 114 unmodified lines
210216 return ERR_PTR(-EOPNOTSUPP);
211217 }
212218 static inline struct ib_umem *
219+ib_umem_get_cq_buf(struct ib_device *device,
220+ const struct uverbs_attr_bundle *attrs, size_t size,
221+ int access)
222+{
223+ return ERR_PTR(-EOPNOTSUPP);
224+}
225+static inline struct ib_umem *
226+ib_umem_get_cq_buf_or_va(struct ib_device *device,
227+ const struct uverbs_attr_bundle *attrs, u64 addr,
228+ size_t size, int access)
229+{
230+ return ERR_PTR(-EOPNOTSUPP);
231+}
232+static inline struct ib_umem *
213233 ib_umem_get_cq_tmp(struct ib_device *device, struct uverbs_attr_bundle *attrs)
214234 {
215235 return ERR_PTR(-EOPNOTSUPP);
include/uapi/rdma/ib_user_ioctl_cmds.h+1−0
@@ -117,6 +117,7 @@ enum uverbs_attrs_create_cq_cmd_attr_ids { · 116 unmodified lines
117117 UVERBS_ATTR_CREATE_CQ_BUFFER_LENGTH,
118118 UVERBS_ATTR_CREATE_CQ_BUFFER_FD,
119119 UVERBS_ATTR_CREATE_CQ_BUFFER_OFFSET,
120+ UVERBS_ATTR_CREATE_CQ_BUF_UMEM,
120121 };
121122
122123 enum uverbs_attrs_destroy_cq_cmd_attr_ids {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t