Skip to contentSkip to conversation

RDMA/core: Ultra Ethernet transport verbs

PATCH In review Eric Davis 5 participants 42 messages Nov 10 – Nov 18 InfiniBand

lore
Share & tools
lore

Eric Davis

author
#0 lore raw

v3 cover RDMA/core: Ultra Ethernet transport verbs

Ultra Ethernet defines a reliable unconnected transport. A queue pair sends to any peer in its job without a connection, incoming traffic is demultiplexed on a JobID rather than on a connection, and what a device orders is far weaker than IB or RoCE and varies between devices. None of that has a home in the current uverbs ABI.

This series adds the generic half. The objects, methods, and attributes any UET device implements. No driver is part of it, though two already exist against this ABI. A reference device model that implements all of it, and HPE's Slingshot driver implementing a large subset. That is the argument for ib_core carrying this. What is device specific should come from private interfaces per vendor.

Patch 1 widens the uverbs object key. The three new core objects would otherwise leave drivers fewer object keys than mlx5 alone uses.

Patches 2-4 expose the transport. The two UET encapsulations as GID types, the capabilities and limits a device advertises, and IB_QPT_RU with its 32-bit queue pair number.

Patch 5 widens address handles, which an unconnected peer needs since it is named by both a network address and a queue pair number.

Patch 6 adds a query for what a queue pair type actually orders.

Patch 7 adds jobs and job keys, the objects an unconnected transport demultiplexes and authorizes on. A job can be exported to a file descriptor, so an unprivileged process can join one set up for it.

Patches 8-10 let a queue pair be created ready to send, since a transport with nothing to negotiate gains nothing from the modify sequence. Patch 8 is a no-functional-change refactor pulling the attribute copy out of modify_qp. Patch 9 lets create take those attributes. Patch 10 adds the attributes a reliable unconnected transport needs.

Patches 11-13 cover memory registration with a job binding, a chosen key, derived regions, 64-bit keys for devices whose keys do not fit in 32 bits, and attaching a region to one queue pair so the network reaches it only over that QP.

New attributes are optional, so existing userspace is unaffected and a device without a feature reports it absent rather than failing. The attributes that restrict access are sent mandatory by userspace, so a kernel that does not know one refuses the request rather than creating an object with less protection than was asked for.

Tested against a reference device implementing the ABI, and against rxe to confirm nothing already upstream regressed. The userspace half is a matching rdma-core series.

---
Changes in v3:
- Rebase on rdma for-next
- Never default RDMA-CM to a UET GID type (2)
- Refuse an RU QP whose number another QP on the device already has,
until restrack keys RU QPs by more than their number (4)
- Call uverbs_finalize_uobj_create() in AH_EX_CREATE (5), JOB_ALLOC
and JOB_IMPORT (7)
- Refuse reserved bits in a remote QPN (5, 7)
- Report only the semantics fields and bits uverbs defines, and refuse
the driver QP type (6)
- Keep a job's address entries on its port, and refuse an import once
the exporting context is gone (7)
- Release a queried address entry's sgid_attr when the query fails (7)
- Keep the early attr_mask check in ex_modify_qp (8)
- Refuse an RU QP on a device without RU support before any attribute
is read, and test only the QP type in the create helpers (9, 10)
- Limit a modify of an RU QP to its create attributes, and auto-bind
its counter on create (9)
- Check and copy only the QP semantics fields comp_mask selects (10)
- Refuse an ordering whose data-ordering size is given as 0 (10)
- Keep a derived region in its parent's job, and refuse a negative
dma-buf fd (11)
- Order the attached MR's usecnt decrement after clearing attached_qp
on QP destroy (13)
- Order the attach and detach usecnt updates before the MR's lock is released (13)
- Document driver duties for job lifetime, sgid_attr, JobID uniqueness, derived regions, rereg of 64-bit keys, unattached regions and QPN assignment (3, 4, 7, 11, 12, 13)
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Rebase on rdma for-next
- Refuse the write post_send and post_recv commands on an RU QP (4)
- Read the extended AH attribute with uverbs_copy_from_or_zero() (5, 7)
- Export a job as a uverbs FD object, import it through a raw fd, and
drop the job revoke on device removal (7)
- Drop the job and job key flags attributes, none was defined (7)
- Require the address table size at job allocation and check each
index against it (7)
- Use uverbs_finalize_uobj_create() in JKEY_CREATE and uverbs_copy_to_struct_or_zero() in JOB_ADDR_QUERY (7)
- Drop IS_ERR() checks on mandatory handles (5, 7)
- Simplify the REG_MR optional attribute handling (11, 12)
- Reword the commit messages of patches 1 and 6
- Link to v1: https://patch.msgid.link/[email protected]

---
Eric Davis (13):
RDMA/core: widen the uverbs object key
RDMA/core: add the UET GID types
RDMA/core: report the reliable unconnected device capabilities RDMA/core: add the reliable unconnected queue pair type RDMA/core: extended address handle attributes RDMA/core: query the semantics a queue pair type guarantees RDMA/core: job and job key objects
RDMA/uverbs: factor out the queue pair attribute copy RDMA/core: create a queue pair ready to send RDMA/core: queue pair attributes for unconnected transports RDMA/core: extended memory registration
RDMA/core: 64-bit memory keys
RDMA/core: attach a memory region to a queue pair

 drivers/infiniband/core/Makefile                  |   3 +-
 drivers/infiniband/core/cache.c                   |  12 +-
 drivers/infiniband/core/cma.c                     |   9 +-
 drivers/infiniband/core/device.c                  |  16 +-
 drivers/infiniband/core/nldev.c                   |  10 +
 drivers/infiniband/core/rdma_core.h               |   2 +
 drivers/infiniband/core/restrack.c                |  19 +-
 drivers/infiniband/core/roce_gid_mgmt.c           |   6 +-
 drivers/infiniband/core/user_mad.c                |   4 +-
 drivers/infiniband/core/uverbs.h                  |  35 ++
 drivers/infiniband/core/uverbs_cmd.c              | 266 +++++----
 drivers/infiniband/core/uverbs_std_types.c        |  74 ++-
 drivers/infiniband/core/uverbs_std_types_device.c |  90 ++-
 drivers/infiniband/core/uverbs_std_types_job.c    | 644 ++++++++++++++++++++++
 drivers/infiniband/core/uverbs_std_types_mr.c     | 226 +++++++-
 drivers/infiniband/core/uverbs_std_types_qp.c     | 363 +++++++++++-
 drivers/infiniband/core/uverbs_uapi.c             |   2 +
 drivers/infiniband/core/verbs.c                   | 130 ++++-
 include/rdma/ib_verbs.h                           | 245 +++++++-
 include/rdma/restrack.h                           |   8 +
 include/rdma/uverbs_ioctl.h                       |   6 +-
 include/uapi/rdma/ib_user_ioctl_cmds.h            | 115 ++++
 include/uapi/rdma/ib_user_ioctl_verbs.h           | 107 ++++
 include/uapi/rdma/ib_user_verbs.h                 |  27 +
 24 files changed, 2264 insertions(+), 155 deletions(-)

---
base-commit: e50525a486300e5ff8014c9985b8477b2fca0368
change-id: 20260929-uet-ib-core-d82e941f5e52

Best regards,

Signature · 1 line
Eric Davis <[email protected]>
author
#1 lore raw

PATCH v3 1/13 RDMA/core: widen the uverbs object key

Three more core objects would leave drivers nine object keys, and mlx5 alone uses ten. Add a bit to the object key.

---
 include/rdma/uverbs_ioctl.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/rdma/uverbs_ioctl.h +2 -2
index 1aaaadb8daf6..a920e57ce990 100644
@@ -108,7 +108,7 @@ struct uverbs_attr_spec {
  *  object_id, attr_id, method_id
  *
  * Which is a 48 bit value, with most of the bits guaranteed to be zero. Based
- * on the current kernel support this is compressed into 16 bit key for the
+ * on the current kernel support this is compressed into 17 bit key for the
  * radix tree. Since this compression is entirely internal to the kernel the
  * below limits can be revised if the kernel gains additional data.
  *
@@ -144,7 +144,7 @@ enum uapi_radix_data {
 		UVERBS_API_METHOD_KEY_BITS + UVERBS_API_METHOD_KEY_SHIFT - 1,
 		UVERBS_API_METHOD_KEY_SHIFT),
 
-	UVERBS_API_OBJ_KEY_BITS = 5,
+	UVERBS_API_OBJ_KEY_BITS = 6,
 	UVERBS_API_OBJ_KEY_SHIFT =
 		UVERBS_API_METHOD_KEY_BITS + UVERBS_API_METHOD_KEY_SHIFT,
 	UVERBS_API_OBJ_KEY_NUM_CORE = 20,
Signature · 1 line
2.56.0
author
#3 lore raw

PATCH v3 2/13 RDMA/core: add the UET GID types

In reply to Eric Davis

Ultra Ethernet runs over two encapsulations: UDP and IP. Each becomes a new GID type. A port can then hold both UET and RoCE GIDs, with the transport following from the GID a queue pair is given; the driver enforces that.

These UET ports build their GID table from a netdev, as RoCE does. Added rdma_port_gids_from_netdev() and use it where the code tested for RoCE alone. The CM has no use for a UET GID, so RDMA-CM never makes one a port's default GID type.

---
 drivers/infiniband/core/cache.c         | 12 +++++----
 drivers/infiniband/core/cma.c           |  9 ++++++-
 drivers/infiniband/core/device.c        |  2 +-
 drivers/infiniband/core/nldev.c         |  2 ++
 drivers/infiniband/core/roce_gid_mgmt.c |  6 +++--
 drivers/infiniband/core/verbs.c         |  4 +++
 include/rdma/ib_verbs.h                 | 48 ++++++++++++++++++++++++++++++---
 include/uapi/rdma/ib_user_ioctl_verbs.h |  2 ++
 8 files changed, 73 insertions(+), 12 deletions(-)
drivers/infiniband/core/cache.c +7 -5
index 647a547e2d7f..d5e17a36f186 100644
@@ -139,6 +139,8 @@ static const char * const gid_type_str[] = {
 	[IB_GID_TYPE_IB]	= "IB/RoCE v1",
 	[IB_GID_TYPE_ROCE]	= "IB/RoCE v1",
 	[IB_GID_TYPE_ROCE_UDP_ENCAP]	= "RoCE v2",
+	[IB_GID_TYPE_UET_UDP]		= "UET UDP",
+	[IB_GID_TYPE_UET_IP]		= "UET IP",
 };
 
 const char *ib_cache_gid_type_str(enum ib_gid_type gid_type)
@@ -392,10 +394,10 @@ static void del_gid(struct ib_device *ib_dev, u32 port,
 	write_lock_irq(&table->rwlock);
 	entry = table->data_vec[ix];
 	entry->state = GID_TABLE_ENTRY_PENDING_DEL;
-	/*
-	 * For non RoCE protocol, GID entry slot is ready to use.
+	/* Where the GID table is not derived from a netdev, the entry slot is
+	 * ready to use.
 	 */
-	if (!rdma_protocol_roce(ib_dev, port))
+	if (!rdma_port_gids_from_netdev(ib_dev, port))
 		table->data_vec[ix] = NULL;
 	write_unlock_irq(&table->rwlock);
 
@@ -447,7 +449,7 @@ static int add_modify_gid(struct ib_gid_table *table,
 	if (!entry)
 		return -ENOMEM;
 
-	if (rdma_protocol_roce(attr->device, attr->port_num)) {
+	if (rdma_port_gids_from_netdev(attr->device, attr->port_num)) {
 		ret = add_roce_gid(entry);
 		if (ret)
 			goto done;
@@ -1459,7 +1461,7 @@ ib_cache_update(struct ib_device *device, u32 port, bool update_gids,
 		goto err;
 	}
 
-	if (!rdma_protocol_roce(device, port) && update_gids) {
+	if (!rdma_port_gids_from_netdev(device, port) && update_gids) {
 		ret = config_non_roce_gid_cache(device, port,
 						tprops);
 		if (ret)
drivers/infiniband/core/cma.c +8 -1
index 337a49d1acf7..59cb526fe2a2 100644
@@ -293,6 +293,10 @@ int cma_set_default_gid_type(struct cma_device *cma_dev,
 	if (!rdma_is_port_valid(cma_dev->device, port))
 		return -EINVAL;
 
+	if (default_gid_type == IB_GID_TYPE_UET_UDP ||
+	    default_gid_type == IB_GID_TYPE_UET_IP)
+		return -EINVAL;
+
 	if (default_gid_type == IB_GID_TYPE_IB &&
 	    rdma_protocol_roce_eth_encap(cma_dev->device, port))
 		default_gid_type = IB_GID_TYPE_ROCE;
@@ -5425,10 +5429,13 @@ static int cma_add_one(struct ib_device *device)
 	rdma_for_each_port (device, i) {
 		supported_gids = roce_gid_type_mask_support(device, i);
 		WARN_ON(!supported_gids);
+		/* the CM has no use for a UET GID, so a UET-only port keeps 0 */
+		supported_gids &= ~(BIT(IB_GID_TYPE_UET_UDP) |
+				    BIT(IB_GID_TYPE_UET_IP));
 		if (supported_gids & (1 << CMA_PREFERRED_ROCE_GID_TYPE))
 			cma_dev->default_gid_type[i - rdma_start_port(device)] =
 				CMA_PREFERRED_ROCE_GID_TYPE;
-		else
+		else if (supported_gids)
 			cma_dev->default_gid_type[i - rdma_start_port(device)] =
 				find_first_bit(&supported_gids, BITS_PER_LONG);
 		cma_dev->default_roce_tos[i - rdma_start_port(device)] = 0;
drivers/infiniband/core/device.c +1 -1
index 29af9fe860e2..7c65a9373701 100644
@@ -2567,7 +2567,7 @@ void ib_enum_roce_netdev(struct ib_device *ib_dev,
 	u32 port;
 
 	rdma_for_each_port (ib_dev, port)
-		if (rdma_protocol_roce(ib_dev, port)) {
+		if (rdma_port_gids_from_netdev(ib_dev, port)) {
 			struct net_device *idev =
 				ib_device_get_netdev(ib_dev, port);
 
drivers/infiniband/core/nldev.c +2 -0
index 849a5db54e1c..91b7be84b15f 100644
@@ -350,6 +350,8 @@ static int fill_dev_info(struct sk_buff *msg, struct ib_device *device)
 		ret = nla_put_string(msg, RDMA_NLDEV_ATTR_DEV_PROTOCOL, "iw");
 	else if (rdma_protocol_roce(device, port))
 		ret = nla_put_string(msg, RDMA_NLDEV_ATTR_DEV_PROTOCOL, "roce");
+	else if (rdma_protocol_uet(device, port))
+		ret = nla_put_string(msg, RDMA_NLDEV_ATTR_DEV_PROTOCOL, "uet");
 	else if (rdma_protocol_usnic(device, port))
 		ret = nla_put_string(msg, RDMA_NLDEV_ATTR_DEV_PROTOCOL,
 				     "usnic");
drivers/infiniband/core/roce_gid_mgmt.c +4 -2
index 4a2a4638b476..214af921341a 100644
@@ -75,6 +75,8 @@ static const struct {
 } PORT_CAP_TO_GID_TYPE[] = {
 	{rdma_protocol_roce_eth_encap, IB_GID_TYPE_ROCE},
 	{rdma_protocol_roce_udp_encap, IB_GID_TYPE_ROCE_UDP_ENCAP},
+	{rdma_protocol_uet_udp, IB_GID_TYPE_UET_UDP},
+	{rdma_protocol_uet_ip, IB_GID_TYPE_UET_IP},
 };
 
 #define CAP_TO_GID_TABLE_SIZE	ARRAY_SIZE(PORT_CAP_TO_GID_TYPE)
@@ -84,7 +86,7 @@ unsigned long roce_gid_type_mask_support(struct ib_device *ib_dev, u32 port)
 	int i;
 	unsigned int ret_flags = 0;
 
-	if (!rdma_protocol_roce(ib_dev, port))
+	if (!rdma_port_gids_from_netdev(ib_dev, port))
 		return 1UL << IB_GID_TYPE_IB;
 
 	for (i = 0; i < CAP_TO_GID_TABLE_SIZE; i++)
@@ -526,7 +528,7 @@ void rdma_roce_rescan_port(struct ib_device *ib_dev, u32 port)
 {
 	struct net_device *ndev = NULL;
 
-	if (rdma_protocol_roce(ib_dev, port)) {
+	if (rdma_port_gids_from_netdev(ib_dev, port)) {
 		ndev = ib_device_get_netdev(ib_dev, port);
 		if (!ndev)
 			return;
drivers/infiniband/core/verbs.c +4 -0
index 7d52d3036208..1299125752d8 100644
@@ -862,6 +862,10 @@ int ib_init_ah_attr_from_wc(struct ib_device *device, u32 port_num,
 
 	might_sleep();
 
+	if (rdma_protocol_uet(device, port_num) &&
+	    !rdma_protocol_roce(device, port_num))
+		return -EPROTONOSUPPORT;
+
 	memset(ah_attr, 0, sizeof *ah_attr);
 	ah_attr->type = rdma_ah_find_type(device, port_num);
 	if (rdma_cap_eth_ah(device, port_num)) {
include/rdma/ib_verbs.h +45 -3

87 lines not on this page · raw message

include/uapi/rdma/ib_user_ioctl_verbs.h +2 -0
index 21f86cc7bb1f..ed72f48960f8 100644
@@ -263,6 +263,8 @@ enum ib_uverbs_gid_type {
 	IB_UVERBS_GID_TYPE_IB,
 	IB_UVERBS_GID_TYPE_ROCE_V1,
 	IB_UVERBS_GID_TYPE_ROCE_V2,
+	IB_UVERBS_GID_TYPE_UET_UDP,
+	IB_UVERBS_GID_TYPE_UET_IP,
 };
 
 struct ib_uverbs_gid_entry {
Signature · 1 line
2.56.0
author
#5 lore raw

PATCH v3 3/13 RDMA/core: report the reliable unconnected device capabilities

In reply to Eric Davis

Add the capability bits a device uses to advertise reliable unconnected support alongside additional features: the transport itself, 64-bit immediate data, 64-bit memory keys, caller-chosen keys, and the four memory region access restrictions.

Report the job, job key, and address table limits through the extended query_device response so userspace can size against them.

---
 drivers/infiniband/core/uverbs_cmd.c |  3 +++
 include/rdma/ib_verbs.h              | 14 ++++++++++++++
 include/uapi/rdma/ib_user_verbs.h    | 27 +++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)
drivers/infiniband/core/uverbs_cmd.c +3 -0
index aca7c6ab55cd..ed55fbbdfc18 100644
@@ -3597,6 +3597,9 @@ static int ib_uverbs_ex_query_device(struct uverbs_attr_bundle *attrs)
 	resp.cq_moderation_caps.max_cq_moderation_period =
 		attr.cq_caps.max_cq_moderation_period;
 	resp.max_dm_size = attr.max_dm_size;
+	resp.max_job_ids = attr.max_job_ids;
+	resp.max_job_keys = attr.max_job_keys;
+	resp.max_addr_entries = attr.max_addr_entries;
 	resp.response_length = uverbs_response_length(attrs, sizeof(resp));
 
 	return uverbs_response(attrs, &resp, sizeof(resp));
include/rdma/ib_verbs.h +14 -0
index 4e3a5c38cbe8..02f3312c7cf2 100644
@@ -278,6 +278,14 @@ enum ib_device_cap_flags {
 	IB_DEVICE_FLUSH_PERSISTENT = IB_UVERBS_DEVICE_FLUSH_PERSISTENT,
 	IB_DEVICE_ATOMIC_WRITE = IB_UVERBS_DEVICE_ATOMIC_WRITE,
 	IB_DEVICE_CC_DMA_BOUNCE = IB_UVERBS_DEVICE_CC_DMA_BOUNCE,
+	IB_DEVICE_RU = IB_UVERBS_DEVICE_RU,
+	IB_DEVICE_IMM64 = IB_UVERBS_DEVICE_IMM64,
+	IB_DEVICE_KEY64 = IB_UVERBS_DEVICE_KEY64,
+	IB_DEVICE_USER_RKEY = IB_UVERBS_DEVICE_USER_RKEY,
+	IB_DEVICE_MR_UNRESTRICTED = IB_UVERBS_DEVICE_MR_UNRESTRICTED,
+	IB_DEVICE_MR_JOB_RESTRICTED = IB_UVERBS_DEVICE_MR_JOB_RESTRICTED,
+	IB_DEVICE_MR_QP_RESTRICTED = IB_UVERBS_DEVICE_MR_QP_RESTRICTED,
+	IB_DEVICE_MR_QP_JOB_RESTRICTED = IB_UVERBS_DEVICE_MR_QP_JOB_RESTRICTED,
 };
 
 enum ib_kernel_cap_flags {
@@ -456,6 +464,12 @@ struct ib_device_attr {
 	u64			max_dm_size;
 	/* Max entries for sgl for optimized performance per READ */
 	u32			max_sgl_rd;
+	/* Jobs allocated at once, not the largest JobID */
+	u32			max_job_ids;
+	/* Job keys allocated at once */
+	u32			max_job_keys;
+	/* Largest address table a single job may have */
+	u32			max_addr_entries;
 };
 
 enum ib_mtu {
include/uapi/rdma/ib_user_verbs.h +27 -0
index 565301594634..df3e72aee9a8 100644
@@ -300,6 +300,10 @@ struct ib_uverbs_ex_query_device_resp {
 	__aligned_u64 max_dm_size;
 	__u32 xrc_odp_caps;
 	__u32 reserved;
+	__u32 max_job_ids; /* jobs allocated at once, not a JobID */
+	__u32 max_job_keys; /* job keys allocated at once */
+	__u32 max_addr_entries; /* largest address table of one job */
+	__u32 reserved2;
 };
 
 struct ib_uverbs_query_port {
@@ -1370,6 +1374,29 @@ enum ib_uverbs_device_cap_flags {
 	IB_UVERBS_DEVICE_ATOMIC_WRITE = 1ULL << 40,
 	/* CoCo guest with DMA bounce buffering required */
 	IB_UVERBS_DEVICE_CC_DMA_BOUNCE = 1ULL << 41,
+	/* Reliable unconnected QPs, jobs, job keys and address tables */
+	IB_UVERBS_DEVICE_RU = 1ULL << 42,
+	/* 64-bit immediate data on at least one QP type */
+	IB_UVERBS_DEVICE_IMM64 = 1ULL << 43,
+	/* An MR may carry 64-bit keys as a second name beside its 32-bit ones */
+	IB_UVERBS_DEVICE_KEY64 = 1ULL << 44,
+	/* MR registration with a caller-chosen rkey */
+	IB_UVERBS_DEVICE_USER_RKEY = 1ULL << 45,
+	/*
+	 * MR access restrictions, meaningful only with IB_UVERBS_DEVICE_RU.
+	 * Each names what an incoming request must match, and each is its own
+	 * match: supporting two does not imply their combination. A region in
+	 * a class the device does not advertise, such as one waiting to be
+	 * attached to a QP or detached from one, is reachable by no peer.
+	 */
+	/* PD: any QP */
+	IB_UVERBS_DEVICE_MR_UNRESTRICTED = 1ULL << 46,
+	/* PD and JobID: any QP, one job */
+	IB_UVERBS_DEVICE_MR_JOB_RESTRICTED = 1ULL << 47,
+	/* PD and QP: the QP the MR is attached to */
+	IB_UVERBS_DEVICE_MR_QP_RESTRICTED = 1ULL << 48,
+	/* PD, QP and JobID: the attached QP, one job */
+	IB_UVERBS_DEVICE_MR_QP_JOB_RESTRICTED = 1ULL << 49,
 };
 
 enum ib_uverbs_raw_packet_caps {
Signature · 1 line
2.56.0
author
#8 lore raw

PATCH v3 4/13 RDMA/core: add the reliable unconnected queue pair type

In reply to Eric Davis

Add IB_QPT_RU and its userspace counterpart, together with the field layout of a reliable unconnected queue pair number used by UET.

Such a number uses all 32 bits, unlike the 24-bit InfiniBand and RoCE one, so exempt it from the restrack assertion that no queue pair number sets the top byte.

A relative number is named within a job, so pairs in two jobs may share one, but restrack keys a queue pair by its number alone. Until it keys them by more, refuse the second such pair with -EADDRINUSE rather than leave it untracked.

The provider posts its work requests, so the write post_send and post_recv commands refuse such a queue pair.

---
 drivers/infiniband/core/restrack.c      | 15 ++++++++++++++-
 drivers/infiniband/core/uverbs_cmd.c    | 14 ++++++++++++++
 drivers/infiniband/core/verbs.c         | 13 +++++++++++++
 include/rdma/ib_verbs.h                 |  1 +
 include/uapi/rdma/ib_user_ioctl_verbs.h | 21 +++++++++++++++++++++
 5 files changed, 63 insertions(+), 1 deletion(-)
drivers/infiniband/core/restrack.c +14 -1
index a8b838fdc7b5..a75af79adf2c 100644
@@ -241,7 +241,20 @@ void rdma_restrack_add(struct rdma_restrack_entry *res)
 		/* Special case to ensure that LQPN points to right QP */
 		struct ib_qp *qp = container_of(res, struct ib_qp, res);
 
-		WARN_ONCE(qp->qp_num >> 24 || qp->port >> 8,
+		/* An InfiniBand/RoCE QP number is 24 bits and the top byte is
+		 * where the port is folded in for SMI and GSI. A reliable
+		 * unconnected pair is an exception as its QP number is a
+		 * full 32b wide, though of the top byte only the absolute bit
+		 * may be set. An absolute number whose low bits are 0 or 1
+		 * still conflicts SMI/GSI on port 128, which takes a device
+		 * with both RU and MADs on that many ports. Two RU pairs in
+		 * different jobs may also share a relative number, and
+		 * create_qp() refuses the second.
+		 */
+		WARN_ONCE(qp->port >> 8 ||
+			  (qp->qp_type != IB_QPT_RU && qp->qp_num >> 24) ||
+			  (qp->qp_type == IB_QPT_RU &&
+			   qp->qp_num & IB_UVERBS_QPN_UET_RESERVED_MASK),
 			  "QP number 0x%0X and port 0x%0X", qp->qp_num,
 			  qp->port);
 		res->id = qp->qp_num;
drivers/infiniband/core/uverbs_cmd.c +14 -0
index ed55fbbdfc18..e4fdfa0d9548 100644
@@ -2058,6 +2058,12 @@ static int ib_uverbs_post_send(struct uverbs_attr_bundle *attrs)
 		goto out;
 	}
 
+	/* reliable unconnected work requests are posted by the provider */
+	if (qp->qp_type == IB_QPT_RU) {
+		ret = -EOPNOTSUPP;
+		goto out_put;
+	}
+
 	is_ud = qp->qp_type == IB_QPT_UD;
 	sg_ind = 0;
 	last = NULL;
@@ -2335,6 +2341,14 @@ static int ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs)
 		goto out;
 	}
 
+	/* reliable unconnected work requests are posted by the provider */
+	if (qp->qp_type == IB_QPT_RU) {
+		rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
+					UVERBS_LOOKUP_READ);
+		ret = -EOPNOTSUPP;
+		goto out;
+	}
+
 	resp.bad_wr = 0;
 	ret = qp->device->ops.post_recv(qp->real_qp, wr, &bad_wr);
 
drivers/infiniband/core/verbs.c +13 -0
index 1299125752d8..ccdb08284432 100644
@@ -1333,10 +1333,23 @@ static struct ib_qp *create_qp(struct ib_device *dev, struct ib_pd *pd,
 		goto err_security;
 
 	rdma_restrack_add(&qp->res);
+
+	/* restrack keys a QP by its number alone, so an RU QP whose number
+	 * another QP has, as one in another job may, is refused rather than
+	 * left untracked
+	 */
+	if (qp->qp_type == IB_QPT_RU && !qp->res.valid) {
+		ret = -EADDRINUSE;
+		goto err_track;
+	}
+
 	return qp;
 
+err_track:
+	ib_destroy_qp_security_begin(qp->qp_sec);
 err_security:
 	qp->device->ops.destroy_qp(qp, uverbs_get_cleared_udata(uattrs));
+	ib_destroy_qp_security_end(qp->qp_sec);
 err_create:
 	rdma_restrack_put(&qp->res);
 	xa_destroy(&qp->comp_cntrs);
include/rdma/ib_verbs.h +1 -0
index 02f3312c7cf2..8d74ed4fc581 100644
@@ -1188,6 +1188,7 @@ enum ib_qp_type {
 	IB_QPT_RAW_PACKET = IB_UVERBS_QPT_RAW_PACKET,
 	IB_QPT_XRC_INI = IB_UVERBS_QPT_XRC_INI,
 	IB_QPT_XRC_TGT = IB_UVERBS_QPT_XRC_TGT,
+	IB_QPT_RU = IB_UVERBS_QPT_RU,
 	IB_QPT_MAX,
 	IB_QPT_DRIVER = IB_UVERBS_QPT_DRIVER,
 	/* Reserve a range for qp types internal to the low level driver.
include/uapi/rdma/ib_user_ioctl_verbs.h +21 -0
index ed72f48960f8..c568ed365c28 100644
@@ -91,6 +91,7 @@ enum ib_uverbs_qp_type {
 	IB_UVERBS_QPT_RAW_PACKET = 8,
 	IB_UVERBS_QPT_XRC_INI,
 	IB_UVERBS_QPT_XRC_TGT,
+	IB_UVERBS_QPT_RU,
 	IB_UVERBS_QPT_DRIVER = 0xFF,
 };
 
@@ -302,6 +303,26 @@ struct ib_uverbs_buffer_desc {
 	__aligned_u64 length;
 };
 
+/* A UET reliable unconnected queue pair number uses all 32 bits:
+ *
+ *	[ absolute 1b | reserved 7b | resource index 12b | PIDonFEP 12b ]
+ *
+ * An absolute pair is named by its number alone. A relative one is named
+ * within a job, so it must carry a job key when it is created, and a number
+ * the device picks is relative only for a pair that has one. The reserved
+ * bits are zero.
+ *
+ * Two pairs on one device can't yet share a number, even in different jobs,
+ * as the kernel tracks a pair by its number alone. Creating the second fails
+ * with EADDRINUSE.
+ */
+#define IB_UVERBS_QPN_UET_PID_ON_FEP_MASK	0x00000fff
+#define IB_UVERBS_QPN_UET_PID_ON_FEP_SHIFT	0
+#define IB_UVERBS_QPN_UET_RI_MASK		0x00fff000
+#define IB_UVERBS_QPN_UET_RI_SHIFT		12
+#define IB_UVERBS_QPN_UET_RESERVED_MASK		0x7f000000
+#define IB_UVERBS_QPN_UET_ABSOLUTE_ADDR_BIT	0x80000000
+
 enum ib_uverbs_comp_cntr_entry {
 	IB_UVERBS_COMP_CNTR_ENTRY_COMP,
 	IB_UVERBS_COMP_CNTR_ENTRY_ERR,
Signature · 1 line
2.56.0
author
#11 lore raw

PATCH v3 5/13 RDMA/core: extended address handle attributes

In reply to Eric Davis

An unconnected transport over UET resolves a peer by both its network address and its queue pair number. The write() create-AH command has no room for additional attributes. Add rdma_ah_attr_ex to carry new attributes, reach it through rdma_ah_init_attr, and add an ioctl method that supports it.

rdma_create_user_ah() now takes the init attributes rather than the address alone, so callers pass the wider set.

---
 drivers/infiniband/core/user_mad.c         |  4 +-
 drivers/infiniband/core/uverbs.h           |  3 ++
 drivers/infiniband/core/uverbs_cmd.c       | 60 ++++++++++++++----------
 drivers/infiniband/core/uverbs_std_types.c | 74 +++++++++++++++++++++++++++++-
 drivers/infiniband/core/verbs.c            | 43 +++++++++--------
 include/rdma/ib_verbs.h                    | 20 ++++++--
 include/uapi/rdma/ib_user_ioctl_cmds.h     |  7 +++
 include/uapi/rdma/ib_user_ioctl_verbs.h    |  9 ++++
 8 files changed, 173 insertions(+), 47 deletions(-)
drivers/infiniband/core/user_mad.c +3 -1
index c3ef9f85c7eb..05e2898f0a6a 100644
@@ -512,6 +512,7 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
 	struct ib_umad_packet *packet;
 	struct ib_mad_agent *agent;
 	struct rdma_ah_attr ah_attr;
+	struct rdma_ah_init_attr init_attr = {};
 	struct ib_ah *ah;
 	__be64 *tid;
 	int ret, hdr_len, copy_offset, rmpp_active;
@@ -569,7 +570,8 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
 		rdma_ah_set_dgid_raw(&ah_attr, packet->mad.hdr.gid);
 	}
 
-	ah = rdma_create_user_ah(agent->qp->pd, &ah_attr, NULL);
+	init_attr.ah_attr = &ah_attr;
+	ah = rdma_create_user_ah(agent->qp->pd, &init_attr, NULL);
 	if (IS_ERR(ah)) {
 		ret = PTR_ERR(ah);
 		goto err_up;
drivers/infiniband/core/uverbs.h +3 -0
index 728e09b41992..6aaac1c309f0 100644
@@ -236,6 +236,9 @@ int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd,
 int uverbs_dealloc_mw(struct ib_mw *mw);
 void ib_uverbs_detach_umcast(struct ib_qp *qp,
 			     struct ib_uqp_object *uobj);
+int copy_ah_attr_from_uverbs_ah(struct ib_device *dev,
+				struct rdma_ah_attr *rdma_attr,
+				const struct ib_uverbs_ah_attr *uverb_attr);
 
 struct bundle_alloc_head {
 	struct_group_tagged(bundle_alloc_head_hdr, hdr,
drivers/infiniband/core/uverbs_cmd.c +37 -23

85 lines not on this page · raw message

drivers/infiniband/core/uverbs_std_types.c +73 -1

86 lines not on this page · raw message

drivers/infiniband/core/verbs.c +25 -18

102 lines not on this page · raw message

include/rdma/ib_verbs.h +16 -4
index 8d74ed4fc581..68f7a271cf7a 100644
@@ -974,10 +974,14 @@ struct ib_mr_status {
  */
 __attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
 
+struct rdma_ah_attr_ex;
+
 struct rdma_ah_init_attr {
 	struct rdma_ah_attr *ah_attr;
 	u32 flags;
 	struct net_device *xmit_slave;
+	/* set to name a peer by both transport+network addresses */
+	struct rdma_ah_attr_ex *ah_attr_ex;
 };
 
 enum rdma_ah_attr_type {
@@ -1016,6 +1020,11 @@ struct rdma_ah_attr {
 	};
 };
 
+struct rdma_ah_attr_ex {
+	struct rdma_ah_attr	ah_attr;
+	u32			remote_qpn;
+};
+
 enum ib_wc_status {
 	IB_WC_SUCCESS,
 	IB_WC_LOC_LEN_ERR,
@@ -3893,16 +3902,18 @@ struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
  * rdma_create_user_ah - Creates an address handle for the given address vector.
  * It resolves destination mac address for ah attribute of RoCE type.
  * @pd: The protection domain associated with the address handle.
- * @ah_attr: The attributes of the address vector.
+ * @init_attr: The address vector, and for an extended handle the
+ *             attributes beyond it.
  * @udata: pointer to user's input output buffer information need by
  *         provider driver.
  *
- * It returns 0 on success and returns appropriate error code on error.
  * The address handle is used to reference a local or global destination
  * in all UD QP post sends.
+ *
+ * Return: the address handle, or an ERR_PTR on error.
  */
 struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
-				  struct rdma_ah_attr *ah_attr,
+				  struct rdma_ah_init_attr *init_attr,
 				  struct ib_udata *udata);
 /**
  * ib_get_gids_from_rdma_hdr - Get sgid and dgid from GRH or IPv4 header
@@ -4981,7 +4992,8 @@ static inline struct ib_global_route
 	return &attr->grh;
 }
 
-static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr, void *dgid)
+static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr,
+					const void *dgid)
 {
 	struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
 
include/uapi/rdma/ib_user_ioctl_cmds.h +7 -0
index 816b3107464f..40fcd4bd1b5e 100644
@@ -410,6 +410,13 @@ enum uverbs_attrs_xrcd_destroy_ids {
 
 enum uverbs_methods_ah {
 	UVERBS_METHOD_AH_DESTROY,
+	UVERBS_METHOD_AH_EX_CREATE,
+};
+
+enum uverbs_attrs_create_ah_ex_cmd_attr_ids {
+	UVERBS_ATTR_CREATE_AH_EX_HANDLE,
+	UVERBS_ATTR_CREATE_AH_EX_PD_HANDLE,
+	UVERBS_ATTR_CREATE_AH_EX_AH_ATTR_EX,
 };
 
 enum uverbs_attrs_ah_destroy_ids {
include/uapi/rdma/ib_user_ioctl_verbs.h +9 -0
index c568ed365c28..4975771290eb 100644
@@ -323,6 +323,15 @@ struct ib_uverbs_buffer_desc {
 #define IB_UVERBS_QPN_UET_RESERVED_MASK		0x7f000000
 #define IB_UVERBS_QPN_UET_ABSOLUTE_ADDR_BIT	0x80000000
 
+/* An address handle that names a peer using both transport+network addresses.
+ * Used for reliable unconnected QPs in both work request address handles and
+ * a Job address table.
+ */
+struct ib_uverbs_ah_attr_ex {
+	struct ib_uverbs_ah_attr ah_attr;
+	__u32 remote_qpn;
+};
+
 enum ib_uverbs_comp_cntr_entry {
 	IB_UVERBS_COMP_CNTR_ENTRY_COMP,
 	IB_UVERBS_COMP_CNTR_ENTRY_ERR,
Signature · 1 line
2.56.0
author
#14 lore raw

PATCH v3 6/13 RDMA/core: query the semantics a queue pair type guarantees

In reply to Eric Davis

An unconnected transport orders far less than a connected one, and how much varies by device. Add a device method that reports, for a queue pair type, which operations it orders against which and up to what size the data stays in that order, the largest packet it puts on the wire, how wide an immediate it carries, and whether that immediate consumes a posted receive.

---
 drivers/infiniband/core/device.c                  |  1 +
 drivers/infiniband/core/uverbs.h                  | 13 ++++
 drivers/infiniband/core/uverbs_std_types_device.c | 90 ++++++++++++++++++++++-
 include/rdma/ib_verbs.h                           | 15 ++++
 include/uapi/rdma/ib_user_ioctl_cmds.h            |  6 ++
 include/uapi/rdma/ib_user_ioctl_verbs.h           | 65 ++++++++++++++++
 6 files changed, 189 insertions(+), 1 deletion(-)
drivers/infiniband/core/device.c +1 -0
index 7c65a9373701..8b1563de4726 100644
@@ -3011,6 +3011,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
 	SET_DEVICE_OP(dev_ops, query_port);
 	SET_DEVICE_OP(dev_ops, query_port_speed);
 	SET_DEVICE_OP(dev_ops, query_qp);
+	SET_DEVICE_OP(dev_ops, query_qp_semantics);
 	SET_DEVICE_OP(dev_ops, query_srq);
 	SET_DEVICE_OP(dev_ops, query_ucontext);
 	SET_DEVICE_OP(dev_ops, rdma_netdev_get_params);
drivers/infiniband/core/uverbs.h +13 -0
index 6aaac1c309f0..2160985f18e9 100644
@@ -407,5 +407,18 @@ static inline void ib_uverbs_comp_dev(struct ib_uverbs_device *dev)
 	complete(&dev->comp);
 }
 
+/* the semantics fields, ordering bits and usage flags uverbs knows of */
+#define QP_SEMANTICS_MASK_ALL	((IB_UVERBS_QP_SEMANTICS_MASK_USAGE << 1) - 1)
+#define QP_ORDER_ALL		((IB_UVERBS_QP_ORDER_WAW << 1) - 1)
+#define QP_USAGE_ALL		IB_UVERBS_QP_USAGE_IMM_DATA_RQ
+
+/* the ordering bits each data-ordering size limits */
+#define QP_ORDER_RAW_SIZED	(IB_UVERBS_QP_ORDER_RDMA_RAW |	\
+				 IB_UVERBS_QP_ORDER_RAW)
+#define QP_ORDER_WAR_SIZED	(IB_UVERBS_QP_ORDER_RDMA_WAR |	\
+				 IB_UVERBS_QP_ORDER_WAR)
+#define QP_ORDER_WAW_SIZED	(IB_UVERBS_QP_ORDER_RDMA_WAW |	\
+				 IB_UVERBS_QP_ORDER_WAW)
+
 
 #endif /* UVERBS_H */
drivers/infiniband/core/uverbs_std_types_device.c +89 -1

102 lines not on this page · raw message

include/rdma/ib_verbs.h +15 -0
index 68f7a271cf7a..003b70424429 100644
@@ -2496,6 +2496,18 @@ struct ib_counters {
 	atomic_t	usecnt;
 };
 
+/* what a queue pair of a given type guarantees (query_qp_semantics) */
+struct ib_qp_semantics {
+	u32	comp_mask;		/* enum ib_uverbs_qp_semantics_mask */
+	u32	msg_order;		/* enum ib_uverbs_qp_msg_order */
+	u32	max_rdma_raw_size;
+	u32	max_rdma_war_size;
+	u32	max_rdma_waw_size;
+	u32	max_pdu;
+	u32	usage_flags;		/* enum ib_uverbs_qp_usage_flags */
+	u8	imm_data_size;		/* bits */
+};
+
 struct ib_counters_read_attr {
 	u64	*counters_buff;
 	u32	ncounters;
@@ -2751,6 +2763,9 @@ struct ib_device_ops {
 				       int mr_access_flags, struct ib_pd *pd,
 				       struct ib_udata *udata);
 	int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata);
+	int (*query_qp_semantics)(struct ib_device *device,
+				  enum ib_qp_type qp_type,
+				  struct ib_qp_semantics *sem);
 	struct ib_mr *(*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type,
 				  u32 max_num_sg);
 	struct ib_mr *(*alloc_mr_integrity)(struct ib_pd *pd,
include/uapi/rdma/ib_user_ioctl_cmds.h +6 -0
index 40fcd4bd1b5e..fb746257eb2c 100644
@@ -77,6 +77,12 @@ enum uverbs_methods_device {
 	UVERBS_METHOD_QUERY_GID_ENTRY,
 	UVERBS_METHOD_QUERY_PORT_SPEED,
 	UVERBS_METHOD_QUERY_COMP_CNTR_CAPS,
+	UVERBS_METHOD_QUERY_QP_SEMANTICS,
+};
+
+enum uverbs_attrs_query_qp_semantics_attr_ids {
+	UVERBS_ATTR_QUERY_QP_SEMANTICS_QP_TYPE,
+	UVERBS_ATTR_QUERY_QP_SEMANTICS_RESP,
 };
 
 enum uverbs_attrs_invoke_write_cmd_attr_ids {
include/uapi/rdma/ib_user_ioctl_verbs.h +65 -0

77 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#17 lore raw

PATCH v3 7/13 RDMA/core: job and job key objects

In reply to Eric Davis

An unconnected transport demultiplexes incoming traffic on a JobID rather than on a connection. Add two objects for it: a job, which owns that ID and a table of peer addresses reached from its port, and a job key, which ties a job to a protection domain and authorizes a queue pair to act within it.

A job can be exported to a file descriptor and imported elsewhere, so an unprivileged process can join a job that was set up for it.

---
 drivers/infiniband/core/Makefile               |   3 +-
 drivers/infiniband/core/device.c               |  10 +
 drivers/infiniband/core/nldev.c                |   8 +
 drivers/infiniband/core/rdma_core.h            |   2 +
 drivers/infiniband/core/restrack.c             |   4 +
 drivers/infiniband/core/uverbs.h               |   6 +
 drivers/infiniband/core/uverbs_std_types_job.c | 644 +++++++++++++++++++++++++
 drivers/infiniband/core/uverbs_uapi.c          |   2 +
 drivers/infiniband/core/verbs.c                |  37 ++
 include/rdma/ib_verbs.h                        |  65 +++
 include/rdma/restrack.h                        |   8 +
 include/rdma/uverbs_ioctl.h                    |   2 +-
 include/uapi/rdma/ib_user_ioctl_cmds.h         |  77 +++
 13 files changed, 866 insertions(+), 2 deletions(-)
drivers/infiniband/core/Makefile +2 -1
index 47ef6b0afd29..f169c1bfa8b8 100644
@@ -47,7 +47,8 @@ ib_uverbs-y :=			uverbs_main.o uverbs_cmd.o uverbs_marshall.o \
 				uverbs_std_types_async_fd.o \
 				uverbs_std_types_srq.o \
 				uverbs_std_types_wq.o \
-				uverbs_std_types_qp.o
+				uverbs_std_types_qp.o \
+				uverbs_std_types_job.o
 
 ib_uverbs_support-y :=		rdma_core.o \
 				ucaps.o \
drivers/infiniband/core/device.c +10 -0
index 8b1563de4726..cf2a59afcf76 100644
@@ -2915,6 +2915,14 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
 	SET_DEVICE_OP(dev_ops, counter_unbind_qp);
 	SET_DEVICE_OP(dev_ops, counter_update_stats);
 	SET_DEVICE_OP(dev_ops, create_ah);
+	SET_DEVICE_OP(dev_ops, alloc_job);
+	SET_DEVICE_OP(dev_ops, dealloc_job);
+	SET_DEVICE_OP(dev_ops, query_job);
+	SET_DEVICE_OP(dev_ops, job_addr_insert);
+	SET_DEVICE_OP(dev_ops, job_addr_remove);
+	SET_DEVICE_OP(dev_ops, job_addr_query);
+	SET_DEVICE_OP(dev_ops, create_jkey);
+	SET_DEVICE_OP(dev_ops, destroy_jkey);
 	SET_DEVICE_OP(dev_ops, create_counters);
 	SET_DEVICE_OP(dev_ops, create_cq);
 	SET_DEVICE_OP(dev_ops, create_comp_cntr);
@@ -3031,6 +3039,8 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
 
 	SET_OBJ_SIZE(dev_ops, ib_ah);
 	SET_OBJ_SIZE(dev_ops, ib_counters);
+	SET_OBJ_SIZE(dev_ops, ib_job);
+	SET_OBJ_SIZE(dev_ops, ib_jkey);
 	SET_OBJ_SIZE(dev_ops, ib_cq);
 	SET_OBJ_SIZE(dev_ops, ib_comp_cntr);
 	SET_OBJ_SIZE(dev_ops, ib_dmah);
drivers/infiniband/core/nldev.c +8 -0
index 91b7be84b15f..d1df9c6eecae 100644
@@ -454,6 +454,8 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device,
 		[RDMA_RESTRACK_CTX] = "ctx",
 		[RDMA_RESTRACK_SRQ] = "srq",
 		[RDMA_RESTRACK_COMP_CNTR] = "comp_cntr",
+		[RDMA_RESTRACK_JOB] = "job",
+		[RDMA_RESTRACK_JKEY] = "jkey",
 	};
 
 	struct ib_comp_cntr_caps comp_cntr_caps = {};
@@ -494,6 +496,12 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device,
 		case RDMA_RESTRACK_COMP_CNTR:
 			max = comp_cntr_caps.max_counters;
 			break;
+		case RDMA_RESTRACK_JOB:
+			max = device->attrs.max_job_ids;
+			break;
+		case RDMA_RESTRACK_JKEY:
+			max = device->attrs.max_job_keys;
+			break;
 		default:
 			max = 0;
 		}
drivers/infiniband/core/rdma_core.h +2 -0
index 9de14e625dd3..523a6f7d4439 100644
@@ -164,6 +164,8 @@ void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile);
 
 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_job[];
+extern const struct uapi_definition uverbs_def_obj_jkey[];
 extern const struct uapi_definition uverbs_def_obj_comp_cntr[];
 extern const struct uapi_definition uverbs_def_obj_cq[];
 extern const struct uapi_definition uverbs_def_obj_device[];
drivers/infiniband/core/restrack.c +4 -0
index a75af79adf2c..fa5b78e78331 100644
@@ -106,6 +106,10 @@ static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
 		return container_of(res, struct ib_dmah, res)->device;
 	case RDMA_RESTRACK_COMP_CNTR:
 		return container_of(res, struct ib_comp_cntr, res)->device;
+	case RDMA_RESTRACK_JOB:
+		return container_of(res, struct ib_job, res)->device;
+	case RDMA_RESTRACK_JKEY:
+		return container_of(res, struct ib_jkey, res)->device;
 	default:
 		WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type);
 		return NULL;
drivers/infiniband/core/uverbs.h +6 -0
index 2160985f18e9..e179cd924eba 100644
@@ -183,6 +183,12 @@ struct ib_uxrcd_object {
 	atomic_t		refcnt;
 };
 
+struct ib_ujob_object {
+	struct ib_uobject	uobject;
+	/* job keys created through this handle */
+	atomic_t		refcnt;
+};
+
 struct ib_usrq_object {
 	struct ib_uevent_object	uevent;
 	struct ib_uxrcd_object *uxrcd;
drivers/infiniband/core/uverbs_std_types_job.c new file +644 -0

644 lines not on this page · raw message

drivers/infiniband/core/uverbs_uapi.c +2 -0
index b67db3790f03..ee84be3061ea 100644
@@ -636,6 +636,8 @@ static const struct uapi_definition uverbs_core_api[] = {
 	UAPI_DEF_CHAIN(uverbs_def_obj_dmah),
 	UAPI_DEF_CHAIN(uverbs_def_obj_flow_action),
 	UAPI_DEF_CHAIN(uverbs_def_obj_intf),
+	UAPI_DEF_CHAIN(uverbs_def_obj_job),
+	UAPI_DEF_CHAIN(uverbs_def_obj_jkey),
 	UAPI_DEF_CHAIN(uverbs_def_obj_mr),
 	UAPI_DEF_CHAIN(uverbs_def_obj_qp),
 	UAPI_DEF_CHAIN(uverbs_def_obj_srq),
drivers/infiniband/core/verbs.c +37 -0
index 7e3cfebebf75..09b247462e65 100644
@@ -690,6 +690,43 @@ struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
 }
 EXPORT_SYMBOL(rdma_create_user_ah);
 
+/**
+ * rdma_job_addr_insert - Insert a peer into a job's address table
+ * @job: The job.
+ * @index: The entry in the job's address table.
+ * @ah_attr: The peer's address and queue pair.
+ *
+ * The address is resolved as rdma_create_user_ah() resolves an address
+ * handle's: the source GID attribute is filled in, and for an Ethernet
+ * address so is the destination MAC.
+ *
+ * Return: 0 on success, or a negative errno.
+ */
+int rdma_job_addr_insert(struct ib_job *job, u32 index,
+			 struct rdma_ah_attr_ex *ah_attr)
+{
+	struct rdma_ah_attr *attr = &ah_attr->ah_attr;
+	const struct ib_gid_attr *old_sgid_attr;
+	int ret;
+
+	ret = rdma_fill_sgid_attr(job->device, attr, &old_sgid_attr);
+	if (ret)
+		return ret;
+
+	if (attr->type == RDMA_AH_ATTR_TYPE_ROCE) {
+		ret = ib_resolve_eth_dmac(job->device, attr);
+		if (ret)
+			goto out;
+	}
+
+	ret = job->device->ops.job_addr_insert(job, index, ah_attr);
+
+out:
+	rdma_unfill_sgid_attr(attr, old_sgid_attr);
+	return ret;
+}
+EXPORT_SYMBOL(rdma_job_addr_insert);
+
 int ib_get_rdma_header_version(const union rdma_network_hdr *hdr)
 {
 	const struct iphdr *ip4h = (struct iphdr *)&hdr->roce4grh;
include/rdma/ib_verbs.h +65 -0

89 lines not on this page · raw message

include/rdma/restrack.h +8 -0
index 47fec3083d28..a7d53540da67 100644
@@ -64,6 +64,14 @@ enum rdma_restrack_type {
 	 * @RDMA_RESTRACK_COMP_CNTR: Completion Counter
 	 */
 	RDMA_RESTRACK_COMP_CNTR,
+	/**
+	 * @RDMA_RESTRACK_JOB: Transport job
+	 */
+	RDMA_RESTRACK_JOB,
+	/**
+	 * @RDMA_RESTRACK_JKEY: Job key
+	 */
+	RDMA_RESTRACK_JKEY,
 	/**
 	 * @RDMA_RESTRACK_MAX: Last entry, used for array dclarations
 	 */
include/rdma/uverbs_ioctl.h +1 -1
index a920e57ce990..b1fce07f02c4 100644
@@ -147,7 +147,7 @@ enum uapi_radix_data {
 	UVERBS_API_OBJ_KEY_BITS = 6,
 	UVERBS_API_OBJ_KEY_SHIFT =
 		UVERBS_API_METHOD_KEY_BITS + UVERBS_API_METHOD_KEY_SHIFT,
-	UVERBS_API_OBJ_KEY_NUM_CORE = 20,
+	UVERBS_API_OBJ_KEY_NUM_CORE = 23,
 	UVERBS_API_OBJ_KEY_NUM_DRIVER =
 		(1 << UVERBS_API_OBJ_KEY_BITS) - UVERBS_API_OBJ_KEY_NUM_CORE,
 	UVERBS_API_OBJ_KEY_MASK = GENMASK(31, UVERBS_API_OBJ_KEY_SHIFT),
include/uapi/rdma/ib_user_ioctl_cmds.h +77 -0

87 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#19 lore raw

PATCH v3 8/13 RDMA/uverbs: factor out the queue pair attribute copy

In reply to Eric Davis

modify_qp() validates a set of attributes that came from userspace and copies the ones its mask names into their kernel form. Queue pair creation needs the same work for a transport that is ready to send as soon as the pair exists, so move it into ib_uverbs_copy_qp_attr().

No functional change.

---
 drivers/infiniband/core/uverbs.h     |   6 ++
 drivers/infiniband/core/uverbs_cmd.c | 184 +++++++++++++++++++----------------
 2 files changed, 105 insertions(+), 85 deletions(-)
drivers/infiniband/core/uverbs.h +6 -0
index e179cd924eba..65a217bf65b5 100644
@@ -319,6 +319,12 @@ struct ib_uverbs_flow_spec {
 	};
 };
 
+int ib_uverbs_copy_qp_attr(struct uverbs_attr_bundle *attrs,
+			   struct ib_device *device,
+			   struct ib_qp_attr *attr,
+			   const struct ib_uverbs_ex_modify_qp *src,
+			   u32 mask);
+
 int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
 					  const void *kern_spec_mask,
 					  const void *kern_spec_val,
drivers/infiniband/core/uverbs_cmd.c +99 -85

210 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#21 lore raw

PATCH v3 9/13 RDMA/core: create a queue pair ready to send

In reply to Eric Davis

Some transports have nothing to negotiate, so a queue pair can be ready to send the moment it exists and the modify sequence carries no useful information. Let a reliable unconnected queue pair be created with the attributes that sequence would have supplied, in the same form the modify command uses, and apply them as that modify to RTS once the queue pair exists, so its checks run. A queue pair whose modify fails is destroyed, and a later modify may change no more than those attributes.

Note that the QP handle field is refused, since the create is what makes the handle.

---
 drivers/infiniband/core/uverbs.h              |  7 +++
 drivers/infiniband/core/uverbs_cmd.c          |  6 +++
 drivers/infiniband/core/uverbs_std_types_qp.c | 74 +++++++++++++++++++++++++++
 drivers/infiniband/core/verbs.c               |  7 ++-
 include/uapi/rdma/ib_user_ioctl_cmds.h        |  1 +
 5 files changed, 93 insertions(+), 2 deletions(-)
drivers/infiniband/core/uverbs.h +7 -0
index 65a217bf65b5..59015a7a52f6 100644
@@ -325,6 +325,13 @@ int ib_uverbs_copy_qp_attr(struct uverbs_attr_bundle *attrs,
 			   const struct ib_uverbs_ex_modify_qp *src,
 			   u32 mask);
 
+/* what a reliable unconnected QP is created ready to send with, and all a
+ * later modify may change
+ */
+#define QP_ATTR_RU_MASK		(IB_QP_STATE | IB_QP_PKEY_INDEX |	\
+				 IB_QP_PORT | IB_QP_ACCESS_FLAGS |	\
+				 IB_QP_PATH_MTU)
+
 int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
 					  const void *kern_spec_mask,
 					  const void *kern_spec_val,
drivers/infiniband/core/uverbs_cmd.c +6 -0
index 140f1cf91527..afe891e7b42d 100644
@@ -1913,6 +1913,12 @@ static int modify_qp(struct uverbs_attr_bundle *attrs,
 		goto out;
 	}
 
+	if (qp->qp_type == IB_QPT_RU &&
+	    (cmd->base.attr_mask & ~QP_ATTR_RU_MASK)) {
+		ret = -EINVAL;
+		goto release_qp;
+	}
+
 	if ((cmd->base.attr_mask & IB_QP_AV)) {
 		if (cmd->base.attr_mask & IB_QP_STATE &&
 		    cmd->base.qp_state == IB_QPS_RTR) {
drivers/infiniband/core/uverbs_std_types_qp.c +74 -0

104 lines not on this page · raw message

drivers/infiniband/core/verbs.c +5 -2
index 09b247462e65..3b551979e52f 100644
@@ -1973,10 +1973,13 @@ static int _ib_modify_qp(struct ib_qp *qp, struct ib_qp_attr *attr,
 
 	/*
 	 * Bind this qp to a counter automatically based on the rdma counter
-	 * rules. This only set in RST2INIT with port specified
+	 * rules. This only set in RST2INIT with port specified, or in the
+	 * RST2RTS an RU QP is created with
 	 */
 	if (!qp->counter && (attr_mask & IB_QP_PORT) &&
-	    ((attr_mask & IB_QP_STATE) && attr->qp_state == IB_QPS_INIT))
+	    (attr_mask & IB_QP_STATE) &&
+	    (attr->qp_state == IB_QPS_INIT ||
+	     (qp->qp_type == IB_QPT_RU && attr->qp_state == IB_QPS_RTS)))
 		rdma_counter_bind_qp_auto(qp, attr->port_num);
 
 	ret = ib_security_modify_qp(qp, attr, attr_mask, udata);
include/uapi/rdma/ib_user_ioctl_cmds.h +1 -0
index 70de1e4001c3..b2bf8ca92397 100644
@@ -179,6 +179,7 @@ enum uverbs_attrs_create_qp_cmd_attr_ids {
 	UVERBS_ATTR_CREATE_QP_BUF_UMEM,
 	UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM,
 	UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM,
+	UVERBS_ATTR_CREATE_QP_ATTR,
 };
 
 enum uverbs_attrs_destroy_qp_cmd_attr_ids {
Signature · 1 line
2.56.0
author
#24 lore raw

PATCH v3 10/13 RDMA/core: queue pair attributes for unconnected transports

In reply to Eric Davis

A queue pair on an unconnected transport is created with more than the connected attributes. A job key authorizing it to act within a job, the initiator identity it sends under, and the ordering guarantees the caller wants it to keep.

The QP holds a reference to its job key for as long as it lives, so the job cannot go away underneath it.

---
 drivers/infiniband/core/uverbs_std_types_qp.c | 173 ++++++++++++++++++++++++++
 drivers/infiniband/core/verbs.c               |   5 +
 include/rdma/ib_verbs.h                       |  14 +++
 include/uapi/rdma/ib_user_ioctl_cmds.h        |   3 +
 4 files changed, 195 insertions(+)
drivers/infiniband/core/uverbs_std_types_qp.c +173 -0
index 249206d2992f..a1112083fb73 100644
@@ -79,6 +79,157 @@ static void set_caps(struct ib_qp_init_attr *attr,
 	}
 }
 
+/* A QP may relax what its type guarantees on this device, but not ask for
+ * more than the device advertises for it.
+ */
+static int create_qp_semantics_check(struct ib_device *device,
+				     const struct ib_qp_semantics *req)
+{
+	struct ib_qp_semantics adv = {};
+	u32 m = req->comp_mask;
+	int ret;
+
+	if (!device->ops.query_qp_semantics)
+		return -EOPNOTSUPP;
+
+	ret = device->ops.query_qp_semantics(device, IB_QPT_RU, &adv);
+	if (ret)
+		return ret;
+
+	if (m & ~adv.comp_mask)
+		return -EINVAL;
+
+	if (((m & IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER) &&
+	     (req->msg_order & ~adv.msg_order)) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_RAW) &&
+	     req->max_rdma_raw_size > adv.max_rdma_raw_size) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_WAR) &&
+	     req->max_rdma_war_size > adv.max_rdma_war_size) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_WAW) &&
+	     req->max_rdma_waw_size > adv.max_rdma_waw_size) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_PDU) &&
+	     req->max_pdu > adv.max_pdu) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_IMM) &&
+	     req->imm_data_size > adv.imm_data_size) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_USAGE) &&
+	     (req->usage_flags & ~adv.usage_flags)))
+		return -EINVAL;
+
+	return 0;
+}
+
+/* Process the optional creation attributes. A job to act within, a source
+ * identity, a set of ordering guarantees to ask for. They and the checks on
+ * a requested QP number belong to a reliable unconnected QP.
+ */
+static int create_qp_opt_attrs(struct uverbs_attr_bundle *attrs,
+			       struct ib_device *device, struct ib_pd *pd,
+			       struct ib_qp_init_attr *attr,
+			       struct ib_qp_semantics *sem)
+{
+	struct ib_uverbs_qp_semantics usem = {};
+	struct ib_jkey *jkey;
+	bool has_semantics;
+	u32 m;
+	int ret;
+
+	has_semantics = uverbs_attr_is_valid(attrs,
+					     UVERBS_ATTR_CREATE_QP_SEMANTICS);
+
+	if (attr->qp_type != IB_QPT_RU) {
+		if (has_semantics ||
+		    uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_SRC_ID) ||
+		    uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_JOB_KEY))
+			return -EOPNOTSUPP;
+
+		return 0;
+	}
+
+	if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_SRC_ID)) {
+		ret = uverbs_copy_from(&attr->src_id, attrs,
+				       UVERBS_ATTR_CREATE_QP_SRC_ID);
+		if (ret)
+			return ret;
+	}
+
+	if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_JOB_KEY)) {
+		jkey = uverbs_attr_get_obj(attrs,
+					   UVERBS_ATTR_CREATE_QP_JOB_KEY);
+		if (IS_ERR(jkey))
+			return PTR_ERR(jkey);
+
+		/* a key acts within the PD it was made on */
+		if (jkey->pd != pd)
+			return -EINVAL;
+
+		attr->jkey = jkey;
+	}
+
+	if (attr->create_flags & IB_QP_CREATE_SOURCE_QPN) {
+		if (attr->source_qpn & IB_UVERBS_QPN_UET_RESERVED_MASK)
+			return -EINVAL;
+
+		/* a relative QP is named within a job, so it needs a key */
+		if (!(attr->source_qpn &
+		      IB_UVERBS_QPN_UET_ABSOLUTE_ADDR_BIT) &&
+		    !attr->jkey)
+			return -EINVAL;
+	}
+
+	if (has_semantics) {
+		ret = uverbs_copy_from_or_zero(&usem, attrs,
+					       UVERBS_ATTR_CREATE_QP_SEMANTICS);
+		if (ret)
+			return ret;
+
+		m = usem.comp_mask;
+		if ((m & ~QP_SEMANTICS_MASK_ALL) ||
+		    ((m & IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER) &&
+		     (usem.msg_order & ~QP_ORDER_ALL)) ||
+		    ((m & IB_UVERBS_QP_SEMANTICS_MASK_USAGE) &&
+		     (usem.usage_flags & ~QP_USAGE_ALL)) ||
+		    memchr_inv(usem.reserved, 0, sizeof(usem.reserved)))
+			return -EINVAL;
+
+		/* only the fields comp_mask selects reach the driver */
+		sem->comp_mask = m;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER)
+			sem->msg_order = usem.msg_order;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_RAW)
+			sem->max_rdma_raw_size = usem.max_rdma_raw_size;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_WAR)
+			sem->max_rdma_war_size = usem.max_rdma_war_size;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_WAW)
+			sem->max_rdma_waw_size = usem.max_rdma_waw_size;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_PDU)
+			sem->max_pdu = usem.max_pdu;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_USAGE)
+			sem->usage_flags = usem.usage_flags;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_IMM)
+			sem->imm_data_size = usem.imm_data_size;
+
+		/* nor an ordering whose data-ordering size it gives as 0 */
+		if (((m & IB_UVERBS_QP_SEMANTICS_MASK_RAW) &&
+		     !sem->max_rdma_raw_size &&
+		     (sem->msg_order & QP_ORDER_RAW_SIZED)) ||
+		    ((m & IB_UVERBS_QP_SEMANTICS_MASK_WAR) &&
+		     !sem->max_rdma_war_size &&
+		     (sem->msg_order & QP_ORDER_WAR_SIZED)) ||
+		    ((m & IB_UVERBS_QP_SEMANTICS_MASK_WAW) &&
+		     !sem->max_rdma_waw_size &&
+		     (sem->msg_order & QP_ORDER_WAW_SIZED)))
+			return -EINVAL;
+
+		ret = create_qp_semantics_check(device, sem);
+		if (ret)
+			return ret;
+
+		attr->qp_semantics = sem;
+	}
+
+	return 0;
+}
+
 /* The attributes the QP would be modified with via modify_qp calls. Used for
  * implementations that support having QPs be in RTS immediately after QP
  * creation. These attributes arrive in the same format the modify command
@@ -137,6 +288,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 	struct ib_qp_init_attr attr = {};
 	struct ib_qp_attr qp_attr = {};
 	u32 qp_attr_mask;
+	struct ib_qp_semantics qp_semantics = {};
 	struct ib_uverbs_qp_cap cap = {};
 	struct ib_rwq_ind_table *rwq_ind_tbl = NULL;
 	struct ib_qp *qp;
@@ -191,6 +343,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 	case IB_UVERBS_QPT_UC:
 	case IB_UVERBS_QPT_UD:
 	case IB_UVERBS_QPT_XRC_INI:
+	case IB_UVERBS_QPT_RU:
 	case IB_UVERBS_QPT_DRIVER:
 		if (uverbs_attr_is_valid(attrs,
 					 UVERBS_ATTR_CREATE_QP_XRCD_HANDLE) ||
@@ -242,6 +395,11 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 		return -EINVAL;
 	}
 
+	/* only a device that implements the transport takes an RU QP */
+	if (attr.qp_type == IB_QPT_RU &&
+	    !(device->attrs.device_cap_flags & IB_DEVICE_RU))
+		return -EOPNOTSUPP;
+
 	ret = uverbs_get_flags32(&attr.create_flags, attrs,
 			 UVERBS_ATTR_CREATE_QP_FLAGS,
 			 IB_UVERBS_QP_CREATE_BLOCK_MULTICAST_LOOPBACK |
@@ -265,6 +423,10 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 		attr.create_flags |= IB_QP_CREATE_SOURCE_QPN;
 	}
 
+	ret = create_qp_opt_attrs(attrs, device, pd, &attr, &qp_semantics);
+	if (ret)
+		return ret;
+
 	ret = create_qp_attr_set(attrs, device, &attr, &qp_attr,
 				 &qp_attr_mask);
 	if (ret)
@@ -395,6 +557,17 @@ DECLARE_UVERBS_NAMED_METHOD(
 	UVERBS_ATTR_FLAGS_IN(UVERBS_ATTR_CREATE_QP_FLAGS,
 			     enum ib_uverbs_qp_create_flags,
 			     UA_OPTIONAL),
+	UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_QP_SRC_ID,
+			   UVERBS_ATTR_TYPE(u32),
+			   UA_OPTIONAL),
+	UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_QP_SEMANTICS,
+			   UVERBS_ATTR_STRUCT(struct ib_uverbs_qp_semantics,
+					      imm_data_size),
+			   UA_OPTIONAL),
+	UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_QP_JOB_KEY,
+			UVERBS_OBJECT_JKEY,
+			UVERBS_ACCESS_READ,
+			UA_OPTIONAL),
 	UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_QP_ATTR,
 			   UVERBS_ATTR_STRUCT(struct ib_uverbs_ex_modify_qp,
 					      reserved),
drivers/infiniband/core/verbs.c +5 -0
index 3b551979e52f..9359318141b7 100644
@@ -1343,6 +1343,7 @@ static struct ib_qp *create_qp(struct ib_device *dev, struct ib_pd *pd,
 	qp->qp_type = attr->qp_type;
 	qp->rwq_ind_tbl = attr->rwq_ind_tbl;
 	qp->srq = attr->srq;
+	qp->jkey = attr->jkey;
 	qp->event_handler = __ib_qp_event_handler;
 	qp->registered_event_handler = attr->event_handler;
 	qp->port = attr->port_num;
@@ -1451,11 +1452,15 @@ void ib_qp_usecnt_inc(struct ib_qp *qp)
 		atomic_inc(&qp->srq->usecnt);
 	if (qp->rwq_ind_tbl)
 		atomic_inc(&qp->rwq_ind_tbl->usecnt);
+	if (qp->jkey)
+		atomic_inc(&qp->jkey->usecnt);
 }
 EXPORT_SYMBOL(ib_qp_usecnt_inc);
 
 void ib_qp_usecnt_dec(struct ib_qp *qp)
 {
+	if (qp->jkey)
+		atomic_dec(&qp->jkey->usecnt);
 	if (qp->rwq_ind_tbl)
 		atomic_dec(&qp->rwq_ind_tbl->usecnt);
 	if (qp->srq)
include/rdma/ib_verbs.h +14 -0
index ce6707160a12..8be766b80ce0 100644
@@ -1243,6 +1243,9 @@ enum ib_qp_create_flags {
  * callback to destroy the passed in QP.
  */
 
+struct ib_jkey;
+struct ib_qp_semantics;
+
 struct ib_qp_init_attr {
 	/* This callback occurs in workqueue context */
 	void                  (*event_handler)(struct ib_event *, void *);
@@ -1263,6 +1266,15 @@ struct ib_qp_init_attr {
 	u32			port_num;
 	struct ib_rwq_ind_table *rwq_ind_tbl;
 	u32			source_qpn;
+
+	/* The initiator ID this QP sends with, the caller's rank in its job.
+	 * UET lets the caller choose it; the JobID is what is trusted.
+	 */
+	u32			src_id;
+	/* the job this QP belongs to */
+	struct ib_jkey		*jkey;
+	/* what the caller asked the QP to guarantee, NULL if it didn't ask */
+	struct ib_qp_semantics	*qp_semantics;
 };
 
 struct ib_qp_open_attr {
@@ -2009,6 +2021,8 @@ struct ib_qp {
 	enum ib_qp_type		qp_type;
 	struct ib_rwq_ind_table *rwq_ind_tbl;
 	struct ib_qp_security  *qp_sec;
+	/* the job key this pair was created within, NULL if none */
+	struct ib_jkey	       *jkey;
 	u32			port;
 
 	bool			integrity_en;
include/uapi/rdma/ib_user_ioctl_cmds.h +3 -0
index b2bf8ca92397..1de6a1ffd92c 100644
@@ -179,6 +179,9 @@ enum uverbs_attrs_create_qp_cmd_attr_ids {
 	UVERBS_ATTR_CREATE_QP_BUF_UMEM,
 	UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM,
 	UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM,
+	UVERBS_ATTR_CREATE_QP_SRC_ID,
+	UVERBS_ATTR_CREATE_QP_SEMANTICS,
+	UVERBS_ATTR_CREATE_QP_JOB_KEY,
 	UVERBS_ATTR_CREATE_QP_ATTR,
 };
 
Signature · 1 line
2.56.0
author
#28 lore raw

PATCH v3 11/13 RDMA/core: extended memory registration

In reply to Eric Davis

Memory registration for an unconnected transport may take more than an address and an access mask. A job to bind the region to, a key the caller chose, or a region carved out of another. None of it fits the write() command, so add a device method that takes the wider set of attributes and reach it when the ioctl carries any of these new fields.

A region bound to a job holds a reference to its job key until it is deregistered.

---
 drivers/infiniband/core/device.c              |   1 +
 drivers/infiniband/core/uverbs_cmd.c          |   7 +-
 drivers/infiniband/core/uverbs_std_types_mr.c | 187 +++++++++++++++++++++++++-
 drivers/infiniband/core/verbs.c               |   9 ++
 include/rdma/ib_verbs.h                       |  46 +++++++
 include/uapi/rdma/ib_user_ioctl_cmds.h        |   5 +
 include/uapi/rdma/ib_user_ioctl_verbs.h       |  10 ++
 7 files changed, 260 insertions(+), 5 deletions(-)
drivers/infiniband/core/device.c +1 -0
index cf2a59afcf76..fd45decf9c4f 100644
@@ -3028,6 +3028,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
 	SET_DEVICE_OP(dev_ops, reg_dm_mr);
 	SET_DEVICE_OP(dev_ops, reg_user_mr);
 	SET_DEVICE_OP(dev_ops, reg_user_mr_dmabuf);
+	SET_DEVICE_OP(dev_ops, reg_user_mr_ex);
 	SET_DEVICE_OP(dev_ops, req_notify_cq);
 	SET_DEVICE_OP(dev_ops, rereg_user_mr);
 	SET_DEVICE_OP(dev_ops, resize_user_cq);
drivers/infiniband/core/uverbs_cmd.c +6 -1
index afe891e7b42d..fa9a02ef3070 100644
@@ -731,6 +731,7 @@ static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
 	mr->type    = IB_MR_TYPE_USER;
 	mr->dm	    = NULL;
 	mr->sig_attrs = NULL;
+	ib_mr_init_core_refs(mr);
 	mr->uobject = uobj;
 	atomic_inc(&pd->usecnt);
 	mr->iova = cmd.hca_va;
@@ -790,7 +791,10 @@ static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
 
 	mr = uobj->object;
 
-	if (mr->dm) {
+	/* A region bound to a job or to another region is re-created rather
+	 * than re-registered, so those bindings can't be lost or bypassed.
+	 */
+	if (mr->dm || mr->jkey || mr->parent || atomic_read(&mr->usecnt)) {
 		ret = -EINVAL;
 		goto put_uobjs;
 	}
@@ -838,6 +842,7 @@ static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
 		new_mr->device = new_pd->device;
 		new_mr->pd = new_pd;
 		new_mr->type = IB_MR_TYPE_USER;
+		ib_mr_init_core_refs(new_mr);
 		new_mr->uobject = uobj;
 		atomic_inc(&new_pd->usecnt);
 		new_uobj->object = new_mr;
drivers/infiniband/core/uverbs_std_types_mr.c +183 -4

257 lines not on this page · raw message

drivers/infiniband/core/verbs.c +9 -0
index 9359318141b7..a80d750777f4 100644
@@ -2374,6 +2374,7 @@ struct ib_mr *ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
 	mr->type = IB_MR_TYPE_USER;
 	mr->pd = pd;
 	mr->dm = NULL;
+	ib_mr_init_core_refs(mr);
 	atomic_inc(&pd->usecnt);
 	mr->iova =  virt_addr;
 	mr->length = length;
@@ -2405,6 +2406,8 @@ int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata)
 	struct ib_pd *pd = mr->pd;
 	struct ib_dm *dm = mr->dm;
 	struct ib_dmah *dmah = mr->dmah;
+	struct ib_jkey *jkey = mr->jkey;
+	struct ib_mr *parent = mr->parent;
 	struct ib_sig_attrs *sig_attrs = mr->sig_attrs;
 	int ret;
 
@@ -2417,6 +2420,10 @@ int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata)
 			atomic_dec(&dm->usecnt);
 		if (dmah)
 			atomic_dec(&dmah->usecnt);
+		if (jkey)
+			atomic_dec(&jkey->usecnt);
+		if (parent)
+			atomic_dec(&parent->usecnt);
 		kfree(sig_attrs);
 	}
 
@@ -2464,6 +2471,7 @@ struct ib_mr *ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
 	mr->need_inval = false;
 	mr->type = mr_type;
 	mr->sig_attrs = NULL;
+	ib_mr_init_core_refs(mr);
 
 	rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
 	rdma_restrack_parent_name(&mr->res, &pd->res);
@@ -2525,6 +2533,7 @@ struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
 	mr->need_inval = false;
 	mr->type = IB_MR_TYPE_INTEGRITY;
 	mr->sig_attrs = sig_attrs;
+	ib_mr_init_core_refs(mr);
 
 	rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
 	rdma_restrack_parent_name(&mr->res, &pd->res);
include/rdma/ib_verbs.h +46 -0

70 lines not on this page · raw message

include/uapi/rdma/ib_user_ioctl_cmds.h +5 -0
index 1de6a1ffd92c..fd8372c0c550 100644
@@ -369,6 +369,11 @@ enum uverbs_attrs_reg_mr_cmd_attr_ids {
 	UVERBS_ATTR_REG_MR_FD_OFFSET,
 	UVERBS_ATTR_REG_MR_RESP_LKEY,
 	UVERBS_ATTR_REG_MR_RESP_RKEY,
+	UVERBS_ATTR_REG_MR_FLAGS,
+	UVERBS_ATTR_REG_MR_JKEY_HANDLE,
+	UVERBS_ATTR_REG_MR_PARENT_MR_HANDLE,
+	UVERBS_ATTR_REG_MR_DERIVE_CNT,
+	UVERBS_ATTR_REG_MR_REQ_RKEY64,
 };
 
 enum uverbs_attrs_create_counters_cmd_attr_ids {
include/uapi/rdma/ib_user_ioctl_verbs.h +10 -0
index 9ae45f7d3dc0..c0532fa418a7 100644
@@ -303,6 +303,16 @@ struct ib_uverbs_buffer_desc {
 	__aligned_u64 length;
 };
 
+/* Extended memory registration, for devices whose memory keys are 64 bits
+ * wide and may be bound to a job. See UVERBS_ATTR_REG_MR_FLAGS.
+ */
+enum ib_uverbs_reg_mr_flags {
+	/* REQ_RKEY64 carries the key, rather than the device assigning one */
+	IB_UVERBS_REG_MR_USER_RKEY		= 1 << 0,
+	/* the region tolerates a replayed idempotent operation */
+	IB_UVERBS_REG_MR_IDEMPOTENT_SAFE	= 1 << 1,
+};
+
 /* A UET reliable unconnected queue pair number uses all 32 bits:
  *
  *	[ absolute 1b | reserved 7b | resource index 12b | PIDonFEP 12b ]
Signature · 1 line
2.56.0
author
#32 lore raw

PATCH v3 12/13 RDMA/core: 64-bit memory keys

In reply to Eric Davis

A device whose keys are wider than 32 bits has no way to name a region through lkey and rkey. Carry the wide pair on the region and return it from registration when userspace asks for it.

The attributes are optional in both directions, so a kernel that does not know them ignores the request, and a region without a wide key answers zero.

---
 drivers/infiniband/core/uverbs_std_types_mr.c | 39 ++++++++++++++++++++++++++-
 include/rdma/ib_verbs.h                       | 15 +++++++++--
 include/uapi/rdma/ib_user_ioctl_cmds.h        |  4 +++
 3 files changed, 55 insertions(+), 3 deletions(-)
drivers/infiniband/core/uverbs_std_types_mr.c +38 -1
index 8d281d13d210..5a617a705904 100644
@@ -185,6 +185,16 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_MR)(
 
 	ret = uverbs_copy_to(attrs, UVERBS_ATTR_QUERY_MR_RESP_IOVA,
 			     &mr->iova, sizeof(mr->iova));
+	if (IS_UVERBS_COPY_ERR(ret))
+		return ret;
+
+	ret = uverbs_copy_to(attrs, UVERBS_ATTR_QUERY_MR_RESP_LKEY64,
+			     &mr->lkey64, sizeof(mr->lkey64));
+	if (IS_UVERBS_COPY_ERR(ret))
+		return ret;
+
+	ret = uverbs_copy_to(attrs, UVERBS_ATTR_QUERY_MR_RESP_RKEY64,
+			     &mr->rkey64, sizeof(mr->rkey64));
 
 	return IS_UVERBS_COPY_ERR(ret) ? ret : 0;
 }
@@ -369,6 +379,10 @@ static int reg_mr_ex_attr(struct uverbs_attr_bundle *attrs, struct ib_pd *pd,
 		if (ret)
 			return ret;
 
+		/* zero names no wide key, so it can't be one */
+		if (!ex->req_rkey64)
+			return -EINVAL;
+
 		if (ex->req_rkey64 > U32_MAX && !(caps & IB_DEVICE_KEY64))
 			return -EOPNOTSUPP;
 	} else if (uverbs_attr_is_valid(attrs,
@@ -555,7 +569,18 @@ static int UVERBS_HANDLER(UVERBS_METHOD_REG_MR)(
 
 	ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_MR_RESP_RKEY,
 			     &mr->rkey, sizeof(mr->rkey));
-	return ret;
+	if (ret)
+		return ret;
+
+	ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_MR_RESP_LKEY64,
+			     &mr->lkey64, sizeof(mr->lkey64));
+	if (IS_UVERBS_COPY_ERR(ret))
+		return ret;
+
+	ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_MR_RESP_RKEY64,
+			     &mr->rkey64, sizeof(mr->rkey64));
+
+	return IS_UVERBS_COPY_ERR(ret) ? ret : 0;
 }
 
 DECLARE_UVERBS_NAMED_METHOD(
@@ -591,6 +616,12 @@ DECLARE_UVERBS_NAMED_METHOD(
 			    UVERBS_ATTR_TYPE(u64),
 			    UA_MANDATORY),
 	UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_MR_RESP_IOVA,
+			    UVERBS_ATTR_TYPE(u64),
+			    UA_OPTIONAL),
+	UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_MR_RESP_LKEY64,
+			    UVERBS_ATTR_TYPE(u64),
+			    UA_OPTIONAL),
+	UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_MR_RESP_RKEY64,
 			    UVERBS_ATTR_TYPE(u64),
 			    UA_OPTIONAL));
 
@@ -708,6 +739,12 @@ DECLARE_UVERBS_NAMED_METHOD(
 	UVERBS_ATTR_PTR_IN(UVERBS_ATTR_REG_MR_REQ_RKEY64,
 			   UVERBS_ATTR_TYPE(u64),
 			   UA_OPTIONAL),
+	UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_REG_MR_RESP_LKEY64,
+			    UVERBS_ATTR_TYPE(u64),
+			    UA_OPTIONAL),
+	UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_REG_MR_RESP_RKEY64,
+			    UVERBS_ATTR_TYPE(u64),
+			    UA_OPTIONAL),
 	UVERBS_ATTR_UHW());
 
 DECLARE_UVERBS_NAMED_METHOD_DESTROY(
include/rdma/ib_verbs.h +13 -2
index 07fd5731d458..3b2903b1c40d 100644
@@ -2084,6 +2084,12 @@ struct ib_mr {
 		struct list_head	qp_entry;	/* FR */
 	};
 
+	/* 64b keys, set by a driver reporting IB_DEVICE_KEY64, else zero. The
+	 * driver sets them on every registration path, rereg_user_mr included,
+	 * where it also keeps a caller-chosen rkey or fails.
+	 */
+	u64		   lkey64;
+	u64		   rkey64;
 	/* the job this region is restricted to, NULL if it is unrestricted */
 	struct ib_jkey	  *jkey;
 	/* the region this one was derived from, NULL if registered fresh */
@@ -4852,8 +4858,8 @@ static inline u32 ib_inc_rkey(u32 rkey)
 
 /**
  * ib_mr_init_core_refs - clears what core reads back when an MR is
- *   deregistered.
- * @mr: struct ib_mr pointer to initialize.
+ *   deregistered, and the wide keys of an MR on a device without them.
+ * @mr: struct ib_mr pointer to initialize, with its device set.
  *
  * A driver's MR need not be zeroed, so every path that makes an MR calls this.
  */
@@ -4862,6 +4868,11 @@ static inline void ib_mr_init_core_refs(struct ib_mr *mr)
 	mr->jkey = NULL;
 	mr->parent = NULL;
 	atomic_set(&mr->usecnt, 0);
+
+	if (!(mr->device->attrs.device_cap_flags & IB_DEVICE_KEY64)) {
+		mr->lkey64 = 0;
+		mr->rkey64 = 0;
+	}
 }
 
 /**
include/uapi/rdma/ib_user_ioctl_cmds.h +4 -0
index fd8372c0c550..bc2797fc37fe 100644
@@ -343,6 +343,8 @@ enum uverbs_attrs_query_mr_cmd_attr_ids {
 	UVERBS_ATTR_QUERY_MR_RESP_RKEY,
 	UVERBS_ATTR_QUERY_MR_RESP_LENGTH,
 	UVERBS_ATTR_QUERY_MR_RESP_IOVA,
+	UVERBS_ATTR_QUERY_MR_RESP_LKEY64,
+	UVERBS_ATTR_QUERY_MR_RESP_RKEY64,
 };
 
 enum uverbs_attrs_reg_dmabuf_mr_cmd_attr_ids {
@@ -374,6 +376,8 @@ enum uverbs_attrs_reg_mr_cmd_attr_ids {
 	UVERBS_ATTR_REG_MR_PARENT_MR_HANDLE,
 	UVERBS_ATTR_REG_MR_DERIVE_CNT,
 	UVERBS_ATTR_REG_MR_REQ_RKEY64,
+	UVERBS_ATTR_REG_MR_RESP_LKEY64,
+	UVERBS_ATTR_REG_MR_RESP_RKEY64,
 };
 
 enum uverbs_attrs_create_counters_cmd_attr_ids {
Signature · 1 line
2.56.0
author
#34 lore raw

PATCH v3 13/13 RDMA/core: attach a memory region to a queue pair

In reply to Eric Davis

A region registered against a protection domain is reachable from every QP in it. When a device can narrow that, let a region be attached to one QP and detached again, so the network only reaches the MR over that QP.

Which restrictions a device supports is reported through the memory region access capability bits.

---
 drivers/infiniband/core/device.c              |   2 +
 drivers/infiniband/core/uverbs_std_types_mr.c |   2 +-
 drivers/infiniband/core/uverbs_std_types_qp.c | 116 +++++++++++++++++++++++++-
 drivers/infiniband/core/verbs.c               |  12 +++
 include/rdma/ib_verbs.h                       |  13 ++-
 include/uapi/rdma/ib_user_ioctl_cmds.h        |  12 +++
 6 files changed, 154 insertions(+), 3 deletions(-)
drivers/infiniband/core/device.c +2 -0
index fd45decf9c4f..1b838bf3600d 100644
@@ -3018,6 +3018,8 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
 	SET_DEVICE_OP(dev_ops, query_pkey);
 	SET_DEVICE_OP(dev_ops, query_port);
 	SET_DEVICE_OP(dev_ops, query_port_speed);
+	SET_DEVICE_OP(dev_ops, qp_attach_mr);
+	SET_DEVICE_OP(dev_ops, qp_detach_mr);
 	SET_DEVICE_OP(dev_ops, query_qp);
 	SET_DEVICE_OP(dev_ops, query_qp_semantics);
 	SET_DEVICE_OP(dev_ops, query_srq);
drivers/infiniband/core/uverbs_std_types_mr.c +1 -1
index 5a617a705904..37e591002c75 100644
@@ -42,7 +42,7 @@ static int uverbs_free_mr(struct ib_uobject *uobject,
 {
 	struct ib_mr *mr = uobject->object;
 
-	/* regions derived from this one still use it */
+	/* regions derived from this one, or the QP it is attached to, use it */
 	if (atomic_read(&mr->usecnt))
 		return -EBUSY;
 
drivers/infiniband/core/uverbs_std_types_qp.c +115 -1

127 lines not on this page · raw message

drivers/infiniband/core/verbs.c +12 -0
index a80d750777f4..1b6f116c6072 100644
@@ -1351,6 +1351,7 @@ static struct ib_qp *create_qp(struct ib_device *dev, struct ib_pd *pd,
 
 	spin_lock_init(&qp->mr_lock);
 	xa_init(&qp->comp_cntrs);
+	xa_init_flags(&qp->attached_mrs, XA_FLAGS_ALLOC);
 	INIT_LIST_HEAD(&qp->rdma_mrs);
 	INIT_LIST_HEAD(&qp->sig_mrs);
 	init_completion(&qp->srq_completion);
@@ -1398,6 +1399,7 @@ static struct ib_qp *create_qp(struct ib_device *dev, struct ib_pd *pd,
 err_create:
 	rdma_restrack_put(&qp->res);
 	xa_destroy(&qp->comp_cntrs);
+	xa_destroy(&qp->attached_mrs);
 	kfree(qp);
 	return ERR_PTR(ret);
 
@@ -2228,6 +2230,7 @@ int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata)
 	struct ib_qp_security *sec;
 	struct ib_comp_cntr *cc;
 	unsigned long index;
+	struct ib_mr *mr;
 	int ret;
 
 	WARN_ON_ONCE(qp->mrs_used > 0);
@@ -2265,6 +2268,15 @@ int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata)
 		atomic_dec(&cc->usecnt);
 	xa_destroy(&qp->comp_cntrs);
 
+	/* the driver ended the bindings with the QP, release the regions */
+	xa_for_each(&qp->attached_mrs, index, mr) {
+		WRITE_ONCE(mr->attached_qp, NULL);
+		/* once usecnt reads zero the MR can be freed under us */
+		smp_mb__before_atomic();
+		atomic_dec(&mr->usecnt);
+	}
+	xa_destroy(&qp->attached_mrs);
+
 	ib_qp_usecnt_dec(qp);
 	if (sec)
 		ib_destroy_qp_security_end(sec);
include/rdma/ib_verbs.h +12 -1
index 3b2903b1c40d..6b36df1cf759 100644
@@ -2003,6 +2003,8 @@ struct ib_qp {
 	struct list_head	xrcd_list;
 	struct xarray		comp_cntrs; /* op_mask -> comp_cntr */
 	u32			comp_cntr_op_mask;
+	/* regions attached to this QP, each held until detach or destroy */
+	struct xarray		attached_mrs;
 
 	/* count times opened, mcast attaches, flow attaches */
 	atomic_t		usecnt;
@@ -2094,8 +2096,11 @@ struct ib_mr {
 	struct ib_jkey	  *jkey;
 	/* the region this one was derived from, NULL if registered fresh */
 	struct ib_mr	  *parent;
-	/* regions derived from this one that are still registered */
+	/* regions derived from this one, and an attachment, that hold it */
 	atomic_t	   usecnt;
+	/* the QP this region is attached to, NULL if none */
+	struct ib_qp	  *attached_qp;
+	u32		   attach_id; /* index in attached_qp->attached_mrs */
 
 	struct ib_dm      *dm;
 	struct ib_sig_attrs *sig_attrs; /* only for IB_MR_TYPE_INTEGRITY MRs */
@@ -2852,6 +2857,11 @@ struct ib_device_ops {
 					struct ib_mr_ex_attr *attr,
 					struct ib_udata *udata);
 	int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata);
+	/* attach/detach a region so it is bound to single QP (restricted).
+	 * destroy_qp ends the QP's bindings, then core releases the regions.
+	 */
+	int (*qp_attach_mr)(struct ib_qp *qp, struct ib_mr *mr);
+	int (*qp_detach_mr)(struct ib_qp *qp, struct ib_mr *mr);
 	int (*query_qp_semantics)(struct ib_device *device,
 				  enum ib_qp_type qp_type,
 				  struct ib_qp_semantics *sem);
@@ -4867,6 +4877,7 @@ static inline void ib_mr_init_core_refs(struct ib_mr *mr)
 {
 	mr->jkey = NULL;
 	mr->parent = NULL;
+	mr->attached_qp = NULL;
 	atomic_set(&mr->usecnt, 0);
 
 	if (!(mr->device->attrs.device_cap_flags & IB_DEVICE_KEY64)) {
include/uapi/rdma/ib_user_ioctl_cmds.h +12 -0
index bc2797fc37fe..8de110b8db34 100644
@@ -200,6 +200,18 @@ enum uverbs_methods_qp {
 	UVERBS_METHOD_QP_CREATE,
 	UVERBS_METHOD_QP_DESTROY,
 	UVERBS_METHOD_QP_ATTACH_COMP_CNTR,
+	UVERBS_METHOD_QP_ATTACH_MR,
+	UVERBS_METHOD_QP_DETACH_MR,
+};
+
+enum uverbs_attrs_qp_attach_mr_cmd_attr_ids {
+	UVERBS_ATTR_QP_ATTACH_MR_QP_HANDLE,
+	UVERBS_ATTR_QP_ATTACH_MR_MR_HANDLE,
+};
+
+enum uverbs_attrs_qp_detach_mr_cmd_attr_ids {
+	UVERBS_ATTR_QP_DETACH_MR_QP_HANDLE,
+	UVERBS_ATTR_QP_DETACH_MR_MR_HANDLE,
 };
 
 enum uverbs_attrs_create_srq_cmd_attr_ids {
Signature · 1 line
2.56.0
#2 lore raw

Re: [PATCH rdma-next v3 01/13] RDMA/core: widen the uverbs object key

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

From: Eric Davis <[email protected]>

Three more core objects would leave drivers nine object keys, and mlx5 alone uses ten. Add a bit to the object key.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

Re: [PATCH rdma-next v3 02/13] RDMA/core: add the UET GID types

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

From: Eric Davis <[email protected]>

Ultra Ethernet runs over two encapsulations: UDP and IP. Each becomes a new GID type. A port can then hold both UET and RoCE GIDs, with the transport following from the GID a queue pair is given; the driver enforces that.

Quoted 6 lines

These UET ports build their GID table from a netdev, as RoCE does. Added rdma_port_gids_from_netdev() and use it where the code tested for RoCE alone. The CM has no use for a UET GID, so RDMA-CM never makes one a port's default GID type.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH rdma-next v3 03/13] RDMA/core: report the reliable unconnected device capabilities

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

From: Eric Davis <[email protected]>

Add the capability bits a device uses to advertise reliable unconnected support alongside additional features: the transport itself, 64-bit immediate data, 64-bit memory keys, caller-chosen keys, and the four memory region access restrictions.

Report the job, job key, and address table limits through the extended query_device response so userspace can size against them.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#9 lore raw

Re: [PATCH rdma-next v3 04/13] RDMA/core: add the reliable unconnected queue pair type

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines

From: Eric Davis <[email protected]>

Add IB_QPT_RU and its userspace counterpart, together with the field layout of a reliable unconnected queue pair number used by UET.

Such a number uses all 32 bits, unlike the 24-bit InfiniBand and RoCE one, so exempt it from the restrack assertion that no queue pair number sets the top byte.

A relative number is named within a job, so pairs in two jobs may share one, but restrack keys a queue pair by its number alone. Until it keys them by more, refuse the second such pair with -EADDRINUSE rather than leave it untracked.

Quoted 4 lines

The provider posts its work requests, so the write post_send and post_recv commands refuse such a queue pair.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#12 lore raw

Re: [PATCH rdma-next v3 05/13] RDMA/core: extended address handle attributes

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

From: Eric Davis <[email protected]>

An unconnected transport over UET resolves a peer by both its network address and its queue pair number. The write() create-AH command has no room for additional attributes. Add rdma_ah_attr_ex to carry new attributes, reach it through rdma_ah_init_attr, and add an ioctl method that supports it.

Quoted 4 lines

rdma_create_user_ah() now takes the init attributes rather than the address alone, so callers pass the wider set.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#15 lore raw

Re: [PATCH rdma-next v3 06/13] RDMA/core: query the semantics a queue pair type guarantees

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

From: Eric Davis <[email protected]>

An unconnected transport orders far less than a connected one, and how much varies by device. Add a device method that reports, for a queue pair type, which operations it orders against which and up to what size the data stays in that order, the largest packet it puts on the wire, how wide an immediate it carries, and whether that immediate consumes a posted receive.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#18 lore raw

Re: [PATCH rdma-next v3 07/13] RDMA/core: job and job key objects

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

From: Eric Davis <[email protected]>

An unconnected transport demultiplexes incoming traffic on a JobID rather than on a connection. Add two objects for it: a job, which owns that ID and a table of peer addresses reached from its port, and a job key, which ties a job to a protection domain and authorizes a queue pair to act within it.

Quoted 4 lines

A job can be exported to a file descriptor and imported elsewhere, so an unprivileged process can join a job that was set up for it.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#20 lore raw

Re: [PATCH rdma-next v3 08/13] RDMA/uverbs: factor out the queue pair attribute copy

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

From: Eric Davis <[email protected]>

modify_qp() validates a set of attributes that came from userspace and copies the ones its mask names into their kernel form. Queue pair creation needs the same work for a transport that is ready to send as soon as the pair exists, so move it into ib_uverbs_copy_qp_attr().

No functional change.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#22 lore raw

Re: [PATCH rdma-next v3 09/13] RDMA/core: create a queue pair ready to send

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

From: Eric Davis <[email protected]>

Some transports have nothing to negotiate, so a queue pair can be ready to send the moment it exists and the modify sequence carries no useful information. Let a reliable unconnected queue pair be created with the attributes that sequence would have supplied, in the same form the modify command uses, and apply them as that modify to RTS once the queue pair exists, so its checks run. A queue pair whose modify fails is destroyed, and a later modify may change no more than those attributes.

Quoted 4 lines

Note that the QP handle field is refused, since the create is what makes the handle.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#25 lore raw

Re: [PATCH rdma-next v3 10/13] RDMA/core: queue pair attributes for unconnected transports

In reply to Eric Davis
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] RDMA/core: incomplete zero-size ordering check in create_qp_opt_attrs() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] RDMA/core: incomplete zero-size ordering check in create_qp_opt_attrs()
--

commit ab78e9acb0c6a04e98901cf4dece43df9ce37611
Author: Eric Davis <[email protected]>

RDMA/core: queue pair attributes for unconnected transports

This commit adds creation attributes for reliable unconnected (IB_QPT_RU) queue pairs, including initiator source ID, job key binding, and ordering semantics validation.

Quoted 4 lines
drivers/infiniband/core/uverbs_std_types_qp.c +0 -0
index 249206d2992f9..a1112083fb73f 100644

[ ... ]

Quoted 33 lines
drivers/infiniband/core/uverbs_std_types_qp.c +33 -0
+	if (has_semantics) {
+		ret = uverbs_copy_from_or_zero(&usem, attrs,
+					       UVERBS_ATTR_CREATE_QP_SEMANTICS);
+		if (ret)
+			return ret;
+
+		m = usem.comp_mask;
+		if ((m & ~QP_SEMANTICS_MASK_ALL) ||
+		    ((m & IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER) &&
+		     (usem.msg_order & ~QP_ORDER_ALL)) ||
+		    ((m & IB_UVERBS_QP_SEMANTICS_MASK_USAGE) &&
+		     (usem.usage_flags & ~QP_USAGE_ALL)) ||
+		    memchr_inv(usem.reserved, 0, sizeof(usem.reserved)))
+			return -EINVAL;
+
+		/* only the fields comp_mask selects reach the driver */
+		sem->comp_mask = m;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER)
+			sem->msg_order = usem.msg_order;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_RAW)
+			sem->max_rdma_raw_size = usem.max_rdma_raw_size;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_WAR)
+			sem->max_rdma_war_size = usem.max_rdma_war_size;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_WAW)
+			sem->max_rdma_waw_size = usem.max_rdma_waw_size;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_PDU)
+			sem->max_pdu = usem.max_pdu;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_USAGE)
+			sem->usage_flags = usem.usage_flags;
+		if (m & IB_UVERBS_QP_SEMANTICS_MASK_IMM)
+			sem->imm_data_size = usem.imm_data_size;
+
+		/* nor an ordering whose data-ordering size it gives as 0 */

drivers/infiniband/core/uverbs_std_types_qp.c static void set_caps(struct ib_qp_init_attr *attr, · line 221

Quoted 10 lines
drivers/infiniband/core/uverbs_std_types_qp.c +10 -0
+		if (((m & IB_UVERBS_QP_SEMANTICS_MASK_RAW) &&
+		     !sem->max_rdma_raw_size &&
+		     (sem->msg_order & QP_ORDER_RAW_SIZED)) ||
+		    ((m & IB_UVERBS_QP_SEMANTICS_MASK_WAR) &&
+		     !sem->max_rdma_war_size &&
+		     (sem->msg_order & QP_ORDER_WAR_SIZED)) ||
+		    ((m & IB_UVERBS_QP_SEMANTICS_MASK_WAW) &&
+		     !sem->max_rdma_waw_size &&
+		     (sem->msg_order & QP_ORDER_WAW_SIZED)))
+			return -EINVAL;

[Severity: Medium]
Can userspace bypass this zero-size ordering check by omitting IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER from comp_mask?

sem->msg_order is only populated when IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER is set in m, remaining 0 otherwise. If a caller sets IB_UVERBS_QP_SEMANTICS_MASK_RAW with max_rdma_raw_size == 0 and leaves IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER clear, sem->msg_order is 0 and this check passes even though the caller did not relax msg_order and the device default adv.msg_order still has QP_ORDER_RAW_SIZED set, passing inconsistent semantics in attr->qp_semantics to the driver. Should this check test against the effective msg_order (using adv.msg_order when IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER is not set, and conversely checking adv.max_rdma_*_size when a sized ordering bit is requested without its size mask)?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#29 lore raw

Re: [PATCH rdma-next v3 11/13] RDMA/core: extended memory registration

In reply to Eric Davis
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] RDMA/core: incomplete MR field initialization in ib_mr_init_core_refs() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] RDMA/core: incomplete MR field initialization in ib_mr_init_core_refs()
--

commit 4855334c45cbf4ca7471642a328bba73a433c013
Author: Eric Davis <[email protected]>

RDMA/core: extended memory registration

This commit adds the reg_user_mr_ex device operation and extended UVERBS_METHOD_REG_MR ioctl attributes to support registering memory regions bound to a job, derived from a parent MR, or using caller-chosen 64-bit keys.

Quoted 4 lines
drivers/infiniband/core/uverbs_std_types_mr.c +0 -0
index 0c72f801e0d32..8d281d13d2105 100644

[ ... ]

Quoted 13 lines
drivers/infiniband/core/uverbs_std_types_mr.c +3 -0
@@ -373,12 +521,26 @@ static int UVERBS_HANDLER(UVERBS_METHOD_REG_MR)(
 	mr->device = pd->device;
 	mr->pd = pd;
 	mr->type = IB_MR_TYPE_USER;
+	mr->iova = iova;
+	mr->length = length;
+	ib_mr_init_core_refs(mr);
 	mr->uobject = uobj;
 	atomic_inc(&pd->usecnt);
 	if (dmah) {
 		mr->dmah = dmah;
 		atomic_inc(&dmah->usecnt);
 	}

[ ... ]

Quoted 23 lines
drivers/infiniband/core/verbs.c +6 -0
index 9359318141b79..a80d750777f43 100644
@@ -2405,6 +2406,8 @@ int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata)
 	struct ib_pd *pd = mr->pd;
 	struct ib_dm *dm = mr->dm;
 	struct ib_dmah *dmah = mr->dmah;
+	struct ib_jkey *jkey = mr->jkey;
+	struct ib_mr *parent = mr->parent;
 	struct ib_sig_attrs *sig_attrs = mr->sig_attrs;
 	int ret;
 
@@ -2417,6 +2420,10 @@ int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata)
 			atomic_dec(&dm->usecnt);
 		if (dmah)
 			atomic_dec(&dmah->usecnt);
+		if (jkey)
+			atomic_dec(&jkey->usecnt);
+		if (parent)
+			atomic_dec(&parent->usecnt);
 		kfree(sig_attrs);
 	}

[ ... ]

Quoted 4 lines
include/rdma/ib_verbs.h +0 -0
index 8be766b80ce08..07fd5731d4587 100644

[ ... ]

Quoted 7 lines
include/rdma/ib_verbs.h +3 -0
@@ -4818,6 +4850,20 @@ static inline u32 ib_inc_rkey(u32 rkey)
 	return ((rkey + 1) & mask) | (rkey & ~mask);
 }
 
+/**
+ * ib_mr_init_core_refs - clears what core reads back when an MR is
+ *   deregistered.

include/rdma/ib_verbs.h static inline u32 ib_inc_rkey(u32 rkey) · line 4865

Quoted 10 lines
include/rdma/ib_verbs.h +10 -0
+ * @mr: struct ib_mr pointer to initialize.
+ *
+ * A driver's MR need not be zeroed, so every path that makes an MR calls this.
+ */
+static inline void ib_mr_init_core_refs(struct ib_mr *mr)
+{
+	mr->jkey = NULL;
+	mr->parent = NULL;
+	atomic_set(&mr->usecnt, 0);
+}

[Severity: Medium]
Does ib_mr_init_core_refs() leave mr->dm, mr->dmah, and mr->sig_attrs uninitialized when a driver returns a non-zeroed struct ib_mr?

The comment states that a driver's MR need not be zeroed and that ib_mr_init_core_refs() clears what the core reads back on deregistration. However, ib_dereg_mr_user() also reads mr->dm, mr->dmah, and mr->sig_attrs, while UVERBS_HANDLER(UVERBS_METHOD_REG_MR), UVERBS_HANDLER(UVERBS_METHOD_REG_DMABUF_MR), and ib_uverbs_rereg_mr() do not clear them (and UVERBS_METHOD_REG_MR only sets mr->dmah when dmah is non-NULL). If a driver implementing reg_user_mr_ex or reg_user_mr does not zero-initialize struct ib_mr, deregistering the MR will pass uninitialized pointers to atomic_dec(&dm->usecnt), atomic_dec(&dmah->usecnt), and kfree(sig_attrs), corrupting memory or crashing.

If ib_mr_init_core_refs() is updated to also clear mr->dm, mr->dmah, and mr->sig_attrs, note that UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG) and ib_alloc_mr_integrity() must call it before assigning mr->dm and mr->sig_attrs.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#33 lore raw

Re: [PATCH rdma-next v3 12/13] RDMA/core: 64-bit memory keys

In reply to Eric Davis
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

From: Eric Davis <[email protected]>

A device whose keys are wider than 32 bits has no way to name a region through lkey and rkey. Carry the wide pair on the region and return it from registration when userspace asks for it.

The attributes are optional in both directions, so a kernel that does not know them ignores the request, and a region without a wide key answers zero.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
#35 lore raw

Re: [PATCH rdma-next v3 13/13] RDMA/core: attach a memory region to a queue pair

In reply to Eric Davis
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] RDMA/core: mr->usecnt release ordering race in QP_DETACH_MR and destroy_qp --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] RDMA/core: mr->usecnt release ordering race in QP_DETACH_MR and destroy_qp
--

commit beeb942760f9f2e71c333c8b383858123a5c467f
Author: Eric Davis <[email protected]>

RDMA/core: attach a memory region to a queue pair

This commit adds uverbs methods and driver callbacks to attach a user memory region to a single RU queue pair and detach it again.

Quoted 12 lines
drivers/infiniband/core/uverbs_std_types_qp.c +4 -0
index a1112083fb73f..88a6050d1d046 100644
@@ -683,12 +683,126 @@ DECLARE_UVERBS_NAMED_METHOD(
 			     enum ib_uverbs_qp_attach_comp_cntr_op,
 			     UA_MANDATORY));
 
+/* bind a region to the QP that will use it */
+static int UVERBS_HANDLER(UVERBS_METHOD_QP_ATTACH_MR)(
+	struct uverbs_attr_bundle *attrs)
+{

[ ... ]

Quoted 37 lines
drivers/infiniband/core/uverbs_std_types_qp.c +37 -0
+	/* the QP holds the region until detach or its own destroy */
+	mr->attach_id = id;
+	atomic_inc(&mr->usecnt);
+	/* the MR's read lock drops with a relaxed atomic, order the hold
+	 * before it so a dereg that gets in next sees the region in use
+	 */
+	smp_mb__after_atomic();
+
+	return 0;
+
+err_xa:
+	xa_erase(&qp->attached_mrs, id);
+err_claim:
+	WRITE_ONCE(mr->attached_qp, NULL);
+	return ret;
+}
+
+static int UVERBS_HANDLER(UVERBS_METHOD_QP_DETACH_MR)(
+	struct uverbs_attr_bundle *attrs)
+{
+	struct ib_qp *qp =
+		uverbs_attr_get_obj(attrs, UVERBS_ATTR_QP_DETACH_MR_QP_HANDLE);
+	struct ib_mr *mr =
+		uverbs_attr_get_obj(attrs, UVERBS_ATTR_QP_DETACH_MR_MR_HANDLE);
+	int ret;
+
+	if (!qp->device->ops.qp_detach_mr)
+		return -EOPNOTSUPP;
+
+	if (qp->real_qp != qp)
+		return -EINVAL;
+
+	if (READ_ONCE(mr->attached_qp) != qp)
+		return -EINVAL;
+
+	ret = qp->device->ops.qp_detach_mr(qp, mr);
+	if (ret)

drivers/infiniband/core/uverbs_std_types_qp.c DECLARE_UVERBS_NAMED_METHOD( · line 774

Quoted 10 lines
drivers/infiniband/core/uverbs_std_types_qp.c +10 -0
+		return ret;
+
+	xa_erase(&qp->attached_mrs, mr->attach_id);
+	WRITE_ONCE(mr->attached_qp, NULL);
+	/* once usecnt reads zero the MR can be freed under us */
+	smp_mb__before_atomic();
+	atomic_dec(&mr->usecnt);
+
+	return 0;
+}

[Severity: Medium]
Can uverbs_free_mr() observe a stale non-zero mr->usecnt after UVERBS_METHOD_QP_DETACH_MR or ib_destroy_qp_user() detaches the region and spuriously fail with -EBUSY?

When UVERBS_METHOD_QP_DETACH_MR finishes, rdma_lookup_put_uobject() drops UVERBS_LOOKUP_READ on the MR with a relaxed atomic_dec(&uobj->usecnt). Because UVERBS_METHOD_QP_DETACH_MR places smp_mb__before_atomic() before atomic_dec(&mr->usecnt) instead of smp_mb__after_atomic() after it, the two relaxed atomic_dec() calls can be reordered on weakly-ordered architectures:

CPU0 CPU1
UVERBS_METHOD_QP_DETACH_MR
WRITE_ONCE(mr->attached_qp, NULL)
smp_mb__before_atomic()
[atomic_dec(&mr->usecnt) delayed]
rdma_lookup_put_uobject(mr_uobj)

    atomic_dec(&uobj->usecnt)
                                      uverbs_free_mr()
                                        rdma_lookup_get_uobject()
                                          atomic_cmpxchg(&uobj->usecnt, 0, -1)
                                        atomic_read(&mr->usecnt) -> 1
                                        return -EBUSY;  <-- spurious -EBUSY

atomic_dec(&mr->usecnt)

In addition, both UVERBS_METHOD_QP_DETACH_MR and ib_destroy_qp_user() clear mr->attached_qp before decrementing mr->usecnt. Once mr->attached_qp is NULL, another thread can attach the MR to a second QP (which only takes UVERBS_ACCESS_READ on the MR), detach it, and call uverbs_free_mr() before the first thread runs atomic_dec(&mr->usecnt), again seeing mr->usecnt == 1 and failing with -EBUSY.

Decrementing mr->usecnt with atomic_dec_return_release() before smp_store_release(&mr->attached_qp, NULL) in both detach paths, paired with smp_mb__after_atomic() in UVERBS_METHOD_QP_DETACH_MR, would close both windows.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
author
#26 lore raw

Re: [PATCH rdma-next v3 10/13] RDMA/core: queue pair attributes for unconnected transports

In reply to [email protected]
Quoted 2 lines · On Mon, Nov 9, 2026 at 9:29 PM <[email protected]> wrote:

Can userspace bypass this zero-size ordering check by omitting IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER from comp_mask?

Yes. The check reads the requested msg_order, which is 0 when it isn't selected, while the driver keeps its advertised order for an unselected field. Nothing is unsafe, but the driver can be handed an ordering with a size of 0. If there is another revision, it will test the effective order and size in create_qp_semantics_check(), taking the advertised value for whichever of the two isn't selected.

Quoted 2 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10

Thanks,
- eric

author
#30 lore raw

Re: [PATCH rdma-next v3 11/13] RDMA/core: extended memory registration

In reply to [email protected]
Quoted 2 lines · On Mon, Nov 9, 2026 at 9:55 PM <[email protected]> wrote:

Does ib_mr_init_core_refs() leave mr->dm, mr->dmah, and mr->sig_attrs uninitialized when a driver returns a non-zeroed struct ib_mr?

Those three are not new. The REG_MR and REG_DMABUF_MR handlers never set dm or sig_attrs, and set dmah only when one is given, so core already relies on a zeroed ib_mr from the driver for them. The helper covers the fields this series adds, which the extended paths and rereg read back. Its comment claims more than that; if there is another revision, it will say what the helper clears.

Quoted 2 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11

Thanks,
- eric

author
#36 lore raw

Re: [PATCH rdma-next v3 13/13] RDMA/core: attach a memory region to a queue pair

In reply to [email protected]
Quoted 3 lines · On Mon, Nov 9, 2026 at 10:20 PM <[email protected]> wrote:

Can uverbs_free_mr() observe a stale non-zero mr->usecnt after UVERBS_METHOD_QP_DETACH_MR or ib_destroy_qp_user() detaches the region and spuriously fail with -EBUSY?

It can, but only for a dereg racing the detach. That dereg has no way to know the detach finished, and -EBUSY is what it would get had it run a moment earlier. If userspace orders the dereg after the detach returns, whatever orders them also orders the decrement. Nothing is freed early: the detach holds the MR with READ for its whole run. Attach needs the barrier after its increment because there the other outcome, a dereg reading 0 for an attached region, frees it in use.

Quoted 2 lines

In addition, both UVERBS_METHOD_QP_DETACH_MR and ib_destroy_qp_user() clear mr->attached_qp before decrementing mr->usecnt.

On the destroy path this can happen, since QP destroy holds no lock on the MR. Again the outcome is a spurious -EBUSY in a race of the application with itself; the count never reads 0 early. Decrementing first would be worse there: once usecnt is 0 the region can be freed before attached_qp is cleared, the use-after-free found on v2.

Quoted 2 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13

Thanks,
- eric

#31 lore raw

Re: [PATCH rdma-next v3 11/13] RDMA/core: extended memory registration

In reply to Eric Davis
Quoted 10 lines · Eric Davis
Quoted 2 lines · On Mon, Nov 9, 2026 at 9:55 PM <[email protected]> wrote:

Does ib_mr_init_core_refs() leave mr->dm, mr->dmah, and mr->sig_attrs uninitialized when a driver returns a non-zeroed struct ib_mr?

Those three are not new. The REG_MR and REG_DMABUF_MR handlers never set dm or sig_attrs, and set dmah only when one is given, so core already relies on a zeroed ib_mr from the driver for them. The helper covers the fields this series adds, which the extended paths and rereg read back. Its comment claims more than that; if there is another revision, it will say what the helper clears.

You are adding fields that should be NULL, there is no need to set them and sashiko is right there.

Thanks

Quoted 6 lines
Quoted 3 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11

Thanks,
- eric

#37 lore raw
In reply to Eric Davis
Quoted 6 lines · Eric Davis

Ultra Ethernet defines a reliable unconnected transport. A queue pair sends to any peer in its job without a connection, incoming traffic is demultiplexed on a JobID rather than on a connection, and what a device orders is far weaker than IB or RoCE and varies between devices. None of that has a home in the current uverbs ABI.

Quoted 6 lines

This series adds the generic half. The objects, methods, and attributes any UET device implements. No driver is part of it, though two already exist against this ABI. A reference device model that implements all of it, and HPE's Slingshot driver implementing a large subset. That is the argument for ib_core carrying this. What is device specific should come from private interfaces per vendor.

Hey Eric,

Thanks for posting this. EFA's SRD is also a reliable unconnected transport (one QP reaches any peer, delivery isn't ordered), so we looked at the series as a possible second implementor of IB_QPT_RU that isn't a UET device. Other vendors might also want to support this interface in the future.

I prototyped it on EFA on top of v3 and the matching rdma-core PR. Send, send with immediate, RDMA read and RDMA write all work over an RU QP without jobs.

There are a few places where RU and UET seem tied together, please see my comments in the patches.

Michael

#7 lore raw

Re: [PATCH rdma-next v3 03/13] RDMA/core: report the reliable unconnected device capabilities

In reply to Eric Davis
Quoted 32 lines · Eric Davis

Add the capability bits a device uses to advertise reliable unconnected support alongside additional features: the transport itself, 64-bit immediate data, 64-bit memory keys, caller-chosen keys, and the four memory region access restrictions.

Report the job, job key, and address table limits through the extended query_device response so userspace can size against them.

---
 drivers/infiniband/core/uverbs_cmd.c |  3 +++
 include/rdma/ib_verbs.h              | 14 ++++++++++++++
 include/uapi/rdma/ib_user_verbs.h    | 27 +++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)
include/uapi/rdma/ib_user_verbs.h +4 -0
index 565301594634..df3e72aee9a8 100644
@@ -300,6 +300,10 @@ struct ib_uverbs_ex_query_device_resp {
 	__aligned_u64 max_dm_size;
 	__u32 xrc_odp_caps;
 	__u32 reserved;
+	__u32 max_job_ids; /* jobs allocated at once, not a JobID */
+	__u32 max_job_keys; /* job keys allocated at once */
+	__u32 max_addr_entries; /* largest address table of one job */
+	__u32 reserved2;
 };
 
 struct ib_uverbs_query_port {

include/uapi/rdma/ib_user_verbs.h enum ib_uverbs_device_cap_flags { · line 1378

Quoted 5 lines
include/uapi/rdma/ib_user_verbs.h +2 -0
@@ -1370,6 +1374,29 @@ enum ib_uverbs_device_cap_flags {
 	IB_UVERBS_DEVICE_ATOMIC_WRITE = 1ULL << 40,
 	/* CoCo guest with DMA bounce buffering required */
 	IB_UVERBS_DEVICE_CC_DMA_BOUNCE = 1ULL << 41,
+	/* Reliable unconnected QPs, jobs, job keys and address tables */
+	IB_UVERBS_DEVICE_RU = 1ULL << 42,

Does RU have to imply jobs? Leaving out the job ops works fine: the objects disappear and alloc_job returns EOPNOTSUPP. The only way userspace can tell is max_job_ids == 0, though.

Would a separate cap bit for jobs make sense, so IB_UVERBS_DEVICE_RU means just the QP type?

Michael

#10 lore raw

Re: [PATCH rdma-next v3 04/13] RDMA/core: add the reliable unconnected queue pair type

In reply to Eric Davis
Quoted 37 lines · Eric Davis

Add IB_QPT_RU and its userspace counterpart, together with the field layout of a reliable unconnected queue pair number used by UET.

Such a number uses all 32 bits, unlike the 24-bit InfiniBand and RoCE one, so exempt it from the restrack assertion that no queue pair number sets the top byte.

A relative number is named within a job, so pairs in two jobs may share one, but restrack keys a queue pair by its number alone. Until it keys them by more, refuse the second such pair with -EADDRINUSE rather than leave it untracked.

The provider posts its work requests, so the write post_send and post_recv commands refuse such a queue pair.

---
 drivers/infiniband/core/restrack.c      | 15 ++++++++++++++-
 drivers/infiniband/core/uverbs_cmd.c    | 14 ++++++++++++++
 drivers/infiniband/core/verbs.c         | 13 +++++++++++++
 include/rdma/ib_verbs.h                 |  1 +
 include/uapi/rdma/ib_user_ioctl_verbs.h | 21 +++++++++++++++++++++
 5 files changed, 63 insertions(+), 1 deletion(-)
drivers/infiniband/core/restrack.c +4 -1
index a8b838fdc7b5..a75af79adf2c 100644
@@ -241,7 +241,20 @@ void rdma_restrack_add(struct rdma_restrack_entry *res)
 		/* Special case to ensure that LQPN points to right QP */
 		struct ib_qp *qp = container_of(res, struct ib_qp, res);
 
-		WARN_ONCE(qp->qp_num >> 24 || qp->port >> 8,
+		/* An InfiniBand/RoCE QP number is 24 bits and the top byte is
+		 * where the port is folded in for SMI and GSI. A reliable
+		 * unconnected pair is an exception as its QP number is a
+		 * full 32b wide, though of the top byte only the absolute bit

drivers/infiniband/core/restrack.c void rdma_restrack_add(struct rdma_restrack_entry *res) · line 257

Quoted 10 lines
drivers/infiniband/core/restrack.c +10 -0
+		 * may be set. An absolute number whose low bits are 0 or 1
+		 * still conflicts SMI/GSI on port 128, which takes a device
+		 * with both RU and MADs on that many ports. Two RU pairs in
+		 * different jobs may also share a relative number, and
+		 * create_qp() refuses the second.
+		 */
+		WARN_ONCE(qp->port >> 8 ||
+			  (qp->qp_type != IB_QPT_RU && qp->qp_num >> 24) ||
+			  (qp->qp_type == IB_QPT_RU &&
+			   qp->qp_num & IB_UVERBS_QPN_UET_RESERVED_MASK),

The QPN checks here, and the EADDRINUSE on a duplicate RU QPN, seem to exist only because restrack keys QPs by their number. The nldev LQPN get and counter bind could find a QP by number and port without that key. Would allocating QP IDs like other objects work? Duplicate RU QPNs would still need some way to tell them apart in nldev, but that seems separate from the QPN layout.

Michael

Quoted 55 lines
drivers/infiniband/core/restrack.c +0 -0
 			  "QP number 0x%0X and port 0x%0X", qp->qp_num,
 			  qp->port);
 		res->id = qp->qp_num;
drivers/infiniband/core/uverbs_cmd.c +14 -0
index ed55fbbdfc18..e4fdfa0d9548 100644
@@ -2058,6 +2058,12 @@ static int ib_uverbs_post_send(struct uverbs_attr_bundle *attrs)
 		goto out;
 	}
 
+	/* reliable unconnected work requests are posted by the provider */
+	if (qp->qp_type == IB_QPT_RU) {
+		ret = -EOPNOTSUPP;
+		goto out_put;
+	}
+
 	is_ud = qp->qp_type == IB_QPT_UD;
 	sg_ind = 0;
 	last = NULL;
@@ -2335,6 +2341,14 @@ static int ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs)
 		goto out;
 	}
 
+	/* reliable unconnected work requests are posted by the provider */
+	if (qp->qp_type == IB_QPT_RU) {
+		rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
+					UVERBS_LOOKUP_READ);
+		ret = -EOPNOTSUPP;
+		goto out;
+	}
+
 	resp.bad_wr = 0;
 	ret = qp->device->ops.post_recv(qp->real_qp, wr, &bad_wr);
 
drivers/infiniband/core/verbs.c +10 -0
index 1299125752d8..ccdb08284432 100644
@@ -1333,10 +1333,23 @@ static struct ib_qp *create_qp(struct ib_device *dev, struct ib_pd *pd,
 		goto err_security;
 
 	rdma_restrack_add(&qp->res);
+
+	/* restrack keys a QP by its number alone, so an RU QP whose number
+	 * another QP has, as one in another job may, is refused rather than
+	 * left untracked
+	 */
+	if (qp->qp_type == IB_QPT_RU && !qp->res.valid) {
+		ret = -EADDRINUSE;
+		goto err_track;
+	}
+
 	return qp;
 
#13 lore raw

Re: [PATCH rdma-next v3 05/13] RDMA/core: extended address handle attributes

In reply to Eric Davis
Quoted 185 lines · Eric Davis

An unconnected transport over UET resolves a peer by both its network address and its queue pair number. The write() create-AH command has no room for additional attributes. Add rdma_ah_attr_ex to carry new attributes, reach it through rdma_ah_init_attr, and add an ioctl method that supports it.

rdma_create_user_ah() now takes the init attributes rather than the address alone, so callers pass the wider set.

---
 drivers/infiniband/core/user_mad.c         |  4 +-
 drivers/infiniband/core/uverbs.h           |  3 ++
 drivers/infiniband/core/uverbs_cmd.c       | 60 ++++++++++++++----------
 drivers/infiniband/core/uverbs_std_types.c | 74 +++++++++++++++++++++++++++++-
 drivers/infiniband/core/verbs.c            | 43 +++++++++--------
 include/rdma/ib_verbs.h                    | 20 ++++++--
 include/uapi/rdma/ib_user_ioctl_cmds.h     |  7 +++
 include/uapi/rdma/ib_user_ioctl_verbs.h    |  9 ++++
 8 files changed, 173 insertions(+), 47 deletions(-)
drivers/infiniband/core/user_mad.c +3 -1
index c3ef9f85c7eb..05e2898f0a6a 100644
@@ -512,6 +512,7 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
 	struct ib_umad_packet *packet;
 	struct ib_mad_agent *agent;
 	struct rdma_ah_attr ah_attr;
+	struct rdma_ah_init_attr init_attr = {};
 	struct ib_ah *ah;
 	__be64 *tid;
 	int ret, hdr_len, copy_offset, rmpp_active;
@@ -569,7 +570,8 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
 		rdma_ah_set_dgid_raw(&ah_attr, packet->mad.hdr.gid);
 	}
 
-	ah = rdma_create_user_ah(agent->qp->pd, &ah_attr, NULL);
+	init_attr.ah_attr = &ah_attr;
+	ah = rdma_create_user_ah(agent->qp->pd, &init_attr, NULL);
 	if (IS_ERR(ah)) {
 		ret = PTR_ERR(ah);
 		goto err_up;
drivers/infiniband/core/uverbs.h +3 -0
index 728e09b41992..6aaac1c309f0 100644
@@ -236,6 +236,9 @@ int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd,
 int uverbs_dealloc_mw(struct ib_mw *mw);
 void ib_uverbs_detach_umcast(struct ib_qp *qp,
 			     struct ib_uqp_object *uobj);
+int copy_ah_attr_from_uverbs_ah(struct ib_device *dev,
+				struct rdma_ah_attr *rdma_attr,
+				const struct ib_uverbs_ah_attr *uverb_attr);
 
 struct bundle_alloc_head {
 	struct_group_tagged(bundle_alloc_head_hdr, hdr,
drivers/infiniband/core/uverbs_cmd.c +37 -23
index e4fdfa0d9548..cca386b2c3f0 100644
@@ -1746,6 +1746,37 @@ static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
 	}
 }
 
+/* The ib_uverbs_ah_attr counterpart of copy_ah_attr_from_uverbs() below,
+ * which takes the modify QP layout. This one also rejects an invalid port.
+ */
+int copy_ah_attr_from_uverbs_ah(struct ib_device *dev,
+				struct rdma_ah_attr *rdma_attr,
+				const struct ib_uverbs_ah_attr *uverb_attr)
+{
+	if (!rdma_is_port_valid(dev, uverb_attr->port_num))
+		return -EINVAL;
+
+	rdma_attr->type = rdma_ah_find_type(dev, uverb_attr->port_num);
+	rdma_ah_set_make_grd(rdma_attr, false);
+	rdma_ah_set_dlid(rdma_attr, uverb_attr->dlid);
+	rdma_ah_set_sl(rdma_attr, uverb_attr->sl);
+	rdma_ah_set_path_bits(rdma_attr, uverb_attr->src_path_bits);
+	rdma_ah_set_static_rate(rdma_attr, uverb_attr->static_rate);
+	rdma_ah_set_port_num(rdma_attr, uverb_attr->port_num);
+
+	if (uverb_attr->is_global) {
+		rdma_ah_set_grh(rdma_attr, NULL, uverb_attr->grh.flow_label,
+				uverb_attr->grh.sgid_index,
+				uverb_attr->grh.hop_limit,
+				uverb_attr->grh.traffic_class);
+		rdma_ah_set_dgid_raw(rdma_attr, uverb_attr->grh.dgid);
+	} else {
+		rdma_ah_set_ah_flags(rdma_attr, 0);
+	}
+
+	return 0;
+}
+
 static void copy_ah_attr_from_uverbs(struct ib_device *dev,
 				     struct rdma_ah_attr *rdma_attr,
 				     struct ib_uverbs_qp_dest *uverb_attr)
@@ -2435,6 +2466,7 @@ static int ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs)
 	struct ib_pd			*pd;
 	struct ib_ah			*ah;
 	struct rdma_ah_attr		attr = {};
+	struct rdma_ah_init_attr	init_attr = {};
 	int ret;
 	struct ib_device *ib_dev;
 
@@ -2446,36 +2478,18 @@ static int ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs)
 	if (IS_ERR(uobj))
 		return PTR_ERR(uobj);
 
-	if (!rdma_is_port_valid(ib_dev, cmd.attr.port_num)) {
-		ret = -EINVAL;
-		goto err;
-	}
-
 	pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
 	if (IS_ERR(pd)) {
 		ret = PTR_ERR(pd);
 		goto err;
 	}
 
-	attr.type = rdma_ah_find_type(ib_dev, cmd.attr.port_num);
-	rdma_ah_set_make_grd(&attr, false);
-	rdma_ah_set_dlid(&attr, cmd.attr.dlid);
-	rdma_ah_set_sl(&attr, cmd.attr.sl);
-	rdma_ah_set_path_bits(&attr, cmd.attr.src_path_bits);
-	rdma_ah_set_static_rate(&attr, cmd.attr.static_rate);
-	rdma_ah_set_port_num(&attr, cmd.attr.port_num);
-
-	if (cmd.attr.is_global) {
-		rdma_ah_set_grh(&attr, NULL, cmd.attr.grh.flow_label,
-				cmd.attr.grh.sgid_index,
-				cmd.attr.grh.hop_limit,
-				cmd.attr.grh.traffic_class);
-		rdma_ah_set_dgid_raw(&attr, cmd.attr.grh.dgid);
-	} else {
-		rdma_ah_set_ah_flags(&attr, 0);
-	}
+	ret = copy_ah_attr_from_uverbs_ah(ib_dev, &attr, &cmd.attr);
+	if (ret)
+		goto err_put;
 
-	ah = rdma_create_user_ah(pd, &attr, &attrs->driver_udata);
+	init_attr.ah_attr = &attr;
+	ah = rdma_create_user_ah(pd, &init_attr, &attrs->driver_udata);
 	if (IS_ERR(ah)) {
 		ret = PTR_ERR(ah);
 		goto err_put;
drivers/infiniband/core/uverbs_std_types.c +28 -0
index e160786e1df1..856d85945393 100644
@@ -184,6 +184,77 @@ DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_MW,
 			    UVERBS_TYPE_ALLOC_IDR(uverbs_free_mw),
 			    &UVERBS_METHOD(UVERBS_METHOD_MW_DESTROY));
 
+/* Creating an address handle is still a write() command whose request
+ * struct cannot grow. A transport (reliable unconnected) that resolves a
+ * peer using both transport and network addresses requires additional
+ * fields in the address handle. Here the address handle create command is
+ * made available as an ioctl method, where additional attributes can be
+ * carried.
+ */
+static int UVERBS_HANDLER(UVERBS_METHOD_AH_EX_CREATE)(
+	struct uverbs_attr_bundle *attrs)
+{
+	struct ib_uobject *uobj = uverbs_attr_get_uobject(
+		attrs, UVERBS_ATTR_CREATE_AH_EX_HANDLE);
+	struct ib_pd *pd =
+		uverbs_attr_get_obj(attrs, UVERBS_ATTR_CREATE_AH_EX_PD_HANDLE);
+	struct ib_device *ib_dev = attrs->context->device;
+	struct ib_uverbs_ah_attr_ex uah;
+	struct rdma_ah_init_attr init_attr = {};
+	struct rdma_ah_attr_ex attr = {};
+	struct ib_ah *ah;
+	int ret;
+
+	/* Only a reliable unconnected device has a use for the extended
+	 * attributes.
+	 */
+	if (!(ib_dev->attrs.device_cap_flags & IB_DEVICE_RU))
+		return -EOPNOTSUPP;
+
+	ret = uverbs_copy_from_or_zero(&uah, attrs,

drivers/infiniband/core/uverbs_std_types.c DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_MW, · line 224

Quoted 10 lines
drivers/infiniband/core/uverbs_std_types.c +10 -0
+				       UVERBS_ATTR_CREATE_AH_EX_AH_ATTR_EX);
+	if (ret)
+		return ret;
+
+	ret = copy_ah_attr_from_uverbs_ah(ib_dev, &attr.ah_attr, &uah.ah_attr);
+	if (ret)
+		return ret;
+
+	if (uah.remote_qpn & IB_UVERBS_QPN_UET_RESERVED_MASK)
+		return -EINVAL;

This check seems to belong to the specific driver.

Quoted 9 lines
drivers/infiniband/core/uverbs_std_types.c +9 -0
+
+	attr.remote_qpn = uah.remote_qpn;
+
+	init_attr.ah_attr = &attr.ah_attr;
+	init_attr.ah_attr_ex = &attr;
+
+	ah = rdma_create_user_ah(pd, &init_attr, &attrs->driver_udata);
+	if (IS_ERR(ah))
+		return PTR_ERR(ah);

drivers/infiniband/core/uverbs_std_types.c DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_MW, · line 243

Quoted 10 lines
drivers/infiniband/core/uverbs_std_types.c +10 -0
+
+	ah->uobject = uobj;
+	uobj->object = ah;
+	uverbs_finalize_uobj_create(attrs, UVERBS_ATTR_CREATE_AH_EX_HANDLE);
+
+	return 0;
+}
+
+DECLARE_UVERBS_NAMED_METHOD(
+	UVERBS_METHOD_AH_EX_CREATE,

Since AH create has no ioctl method yet, would it work to add a general UVERBS_METHOD_AH_CREATE, with the remote QPN as an optional attribute? That would work for any device, keep the QPN optional, and leave room for other per-AH attributes without a new struct.

Quoted 225 lines
drivers/infiniband/core/uverbs_std_types.c +16 -1
+	UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_AH_EX_HANDLE,
+			UVERBS_OBJECT_AH,
+			UVERBS_ACCESS_NEW,
+			UA_MANDATORY),
+	UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_AH_EX_PD_HANDLE,
+			UVERBS_OBJECT_PD,
+			UVERBS_ACCESS_READ,
+			UA_MANDATORY),
+	UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_AH_EX_AH_ATTR_EX,
+			   UVERBS_ATTR_STRUCT(struct ib_uverbs_ah_attr_ex,
+					      remote_qpn),
+			   UA_MANDATORY),
+	UVERBS_ATTR_UHW());
+
 DECLARE_UVERBS_NAMED_METHOD_DESTROY(
 	UVERBS_METHOD_AH_DESTROY,
 	UVERBS_ATTR_IDR(UVERBS_ATTR_DESTROY_AH_HANDLE,
@@ -193,7 +264,8 @@ DECLARE_UVERBS_NAMED_METHOD_DESTROY(
 
 DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_AH,
 			    UVERBS_TYPE_ALLOC_IDR(uverbs_free_ah),
-			    &UVERBS_METHOD(UVERBS_METHOD_AH_DESTROY));
+			    &UVERBS_METHOD(UVERBS_METHOD_AH_DESTROY),
+			    &UVERBS_METHOD(UVERBS_METHOD_AH_EX_CREATE));
 
 DECLARE_UVERBS_NAMED_METHOD_DESTROY(
 	UVERBS_METHOD_FLOW_DESTROY,
drivers/infiniband/core/verbs.c +25 -18
index ccdb08284432..7e3cfebebf75 100644
@@ -561,24 +561,23 @@ rdma_update_sgid_attr(struct rdma_ah_attr *ah_attr,
 }
 
 static struct ib_ah *_rdma_create_ah(struct ib_pd *pd,
-				     struct rdma_ah_attr *ah_attr,
-				     u32 flags,
-				     struct ib_udata *udata,
-				     struct net_device *xmit_slave)
+				     struct rdma_ah_init_attr *init_attr,
+				     struct ib_udata *udata)
 {
-	struct rdma_ah_init_attr init_attr = {};
+	struct rdma_ah_attr *ah_attr = init_attr->ah_attr;
 	struct ib_device *device = pd->device;
 	struct ib_ah *ah;
 	int ret;
 
-	might_sleep_if(flags & RDMA_CREATE_AH_SLEEPABLE);
+	might_sleep_if(init_attr->flags & RDMA_CREATE_AH_SLEEPABLE);
 
 	if (!udata && !device->ops.create_ah)
 		return ERR_PTR(-EOPNOTSUPP);
 
 	ah = rdma_zalloc_drv_obj_gfp(
 		device, ib_ah,
-		(flags & RDMA_CREATE_AH_SLEEPABLE) ? GFP_KERNEL : GFP_ATOMIC);
+		(init_attr->flags & RDMA_CREATE_AH_SLEEPABLE) ? GFP_KERNEL :
+								GFP_ATOMIC);
 	if (!ah)
 		return ERR_PTR(-ENOMEM);
 
@@ -586,14 +585,12 @@ static struct ib_ah *_rdma_create_ah(struct ib_pd *pd,
 	ah->pd = pd;
 	ah->type = ah_attr->type;
 	ah->sgid_attr = rdma_update_sgid_attr(ah_attr, NULL);
-	init_attr.ah_attr = ah_attr;
-	init_attr.flags = flags;
-	init_attr.xmit_slave = xmit_slave;
 
 	if (udata)
-		ret = device->ops.create_user_ah(ah, &init_attr, udata);
+		ret = device->ops.create_user_ah(ah, init_attr, udata);
 	else
-		ret = device->ops.create_ah(ah, &init_attr, NULL);
+		ret = device->ops.create_ah(ah, init_attr, NULL);
+
 	if (ret) {
 		if (ah->sgid_attr)
 			rdma_put_gid_attr(ah->sgid_attr);
@@ -619,6 +616,7 @@ static struct ib_ah *_rdma_create_ah(struct ib_pd *pd,
 struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
 			     u32 flags)
 {
+	struct rdma_ah_init_attr init_attr = {};
 	const struct ib_gid_attr *old_sgid_attr;
 	struct net_device *slave;
 	struct ib_ah *ah;
@@ -634,7 +632,12 @@ struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
 		rdma_unfill_sgid_attr(ah_attr, old_sgid_attr);
 		return ERR_CAST(slave);
 	}
-	ah = _rdma_create_ah(pd, ah_attr, flags, NULL, slave);
+
+	init_attr.ah_attr = ah_attr;
+	init_attr.flags = flags;
+	init_attr.xmit_slave = slave;
+
+	ah = _rdma_create_ah(pd, &init_attr, NULL);
 	rdma_lag_put_ah_roce_slave(slave);
 	rdma_unfill_sgid_attr(ah_attr, old_sgid_attr);
 	return ah;
@@ -646,18 +649,21 @@ EXPORT_SYMBOL(rdma_create_ah);
  * given address vector.
  * It resolves destination mac address for ah attribute of RoCE type.
  * @pd: The protection domain associated with the address handle.
- * @ah_attr: The attributes of the address vector.
+ * @init_attr: The address vector, and for an extended handle the
+ *             attributes beyond it.
  * @udata: pointer to user's input output buffer information need by
  *         provider driver.
  *
- * It returns 0 on success and returns appropriate error code on error.
  * The address handle is used to reference a local or global destination
  * in all UD QP post sends.
+ *
+ * Return: the address handle, or an ERR_PTR on error.
  */
 struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
-				  struct rdma_ah_attr *ah_attr,
+				  struct rdma_ah_init_attr *init_attr,
 				  struct ib_udata *udata)
 {
+	struct rdma_ah_attr *ah_attr = init_attr->ah_attr;
 	const struct ib_gid_attr *old_sgid_attr;
 	struct ib_ah *ah;
 	int err;
@@ -674,8 +680,9 @@ struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
 		}
 	}
 
-	ah = _rdma_create_ah(pd, ah_attr, RDMA_CREATE_AH_SLEEPABLE,
-			     udata, NULL);
+	init_attr->flags |= RDMA_CREATE_AH_SLEEPABLE;
+
+	ah = _rdma_create_ah(pd, init_attr, udata);
 
 out:
 	rdma_unfill_sgid_attr(ah_attr, old_sgid_attr);
include/rdma/ib_verbs.h +16 -4
index 8d74ed4fc581..68f7a271cf7a 100644
@@ -974,10 +974,14 @@ struct ib_mr_status {
  */
 __attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
 
+struct rdma_ah_attr_ex;
+
 struct rdma_ah_init_attr {
 	struct rdma_ah_attr *ah_attr;
 	u32 flags;
 	struct net_device *xmit_slave;
+	/* set to name a peer by both transport+network addresses */
+	struct rdma_ah_attr_ex *ah_attr_ex;
 };
 
 enum rdma_ah_attr_type {
@@ -1016,6 +1020,11 @@ struct rdma_ah_attr {
 	};
 };
 
+struct rdma_ah_attr_ex {
+	struct rdma_ah_attr	ah_attr;
+	u32			remote_qpn;
+};
+
 enum ib_wc_status {
 	IB_WC_SUCCESS,
 	IB_WC_LOC_LEN_ERR,
@@ -3893,16 +3902,18 @@ struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
  * rdma_create_user_ah - Creates an address handle for the given address vector.
  * It resolves destination mac address for ah attribute of RoCE type.
  * @pd: The protection domain associated with the address handle.
- * @ah_attr: The attributes of the address vector.
+ * @init_attr: The address vector, and for an extended handle the
+ *             attributes beyond it.
  * @udata: pointer to user's input output buffer information need by
  *         provider driver.
  *
- * It returns 0 on success and returns appropriate error code on error.
  * The address handle is used to reference a local or global destination
  * in all UD QP post sends.
+ *
+ * Return: the address handle, or an ERR_PTR on error.
  */
 struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
-				  struct rdma_ah_attr *ah_attr,
+				  struct rdma_ah_init_attr *init_attr,
 				  struct ib_udata *udata);
 /**
  * ib_get_gids_from_rdma_hdr - Get sgid and dgid from GRH or IPv4 header
@@ -4981,7 +4992,8 @@ static inline struct ib_global_route
 	return &attr->grh;
 }
 
-static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr, void *dgid)
+static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr,
+					const void *dgid)
 {
 	struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
 
include/uapi/rdma/ib_user_ioctl_cmds.h +7 -0
index 816b3107464f..40fcd4bd1b5e 100644
@@ -410,6 +410,13 @@ enum uverbs_attrs_xrcd_destroy_ids {
 
 enum uverbs_methods_ah {
 	UVERBS_METHOD_AH_DESTROY,
+	UVERBS_METHOD_AH_EX_CREATE,
+};
+
+enum uverbs_attrs_create_ah_ex_cmd_attr_ids {
+	UVERBS_ATTR_CREATE_AH_EX_HANDLE,
+	UVERBS_ATTR_CREATE_AH_EX_PD_HANDLE,
+	UVERBS_ATTR_CREATE_AH_EX_AH_ATTR_EX,
 };
 
 enum uverbs_attrs_ah_destroy_ids {
include/uapi/rdma/ib_user_ioctl_verbs.h +0 -0
index c568ed365c28..4975771290eb 100644

include/uapi/rdma/ib_user_ioctl_verbs.h struct ib_uverbs_buffer_desc { · line 332

Quoted 10 lines
include/uapi/rdma/ib_user_ioctl_verbs.h +7 -0
@@ -323,6 +323,15 @@ struct ib_uverbs_buffer_desc {
 #define IB_UVERBS_QPN_UET_RESERVED_MASK		0x7f000000
 #define IB_UVERBS_QPN_UET_ABSOLUTE_ADDR_BIT	0x80000000
 
+/* An address handle that names a peer using both transport+network addresses.
+ * Used for reliable unconnected QPs in both work request address handles and
+ * a Job address table.
+ */
+struct ib_uverbs_ah_attr_ex {
+	struct ib_uverbs_ah_attr ah_attr;
+	__u32 remote_qpn;

With the remote QPN in the AH, a sender needs an AH per (address, QP) pair. That's N peers x M QPs AH objects, each a syscall and a kernel object. On UD and SRD the AH is the address, and the QPN and Q_Key go in the WR.

Is there something in UET that needs the QPN bound to the AH? Could the AH stay the network address, with the QPN given per WR, and an AH-level QPN left optional for the address table?

Michael

Quoted 9 lines
include/uapi/rdma/ib_user_ioctl_verbs.h +2 -0
+};
+
 enum ib_uverbs_comp_cntr_entry {
 	IB_UVERBS_COMP_CNTR_ENTRY_COMP,
 	IB_UVERBS_COMP_CNTR_ENTRY_ERR,
Signature · 2 lines
-- 
2.56.0
#38 lore raw
In reply to Michael Margolin
Quoted 14 lines · Michael Margolin
Quoted 6 lines · Eric Davis

Ultra Ethernet defines a reliable unconnected transport. A queue pair sends to any peer in its job without a connection, incoming traffic is demultiplexed on a JobID rather than on a connection, and what a device orders is far weaker than IB or RoCE and varies between devices. None of that has a home in the current uverbs ABI.

Quoted 6 lines

This series adds the generic half. The objects, methods, and attributes any UET device implements. No driver is part of it, though two already exist against this ABI. A reference device model that implements all of it, and HPE's Slingshot driver implementing a large subset. That is the argument for ib_core carrying this. What is device specific should come from private interfaces per vendor.

Quoted 7 lines

Hey Eric,

Thanks for posting this. EFA's SRD is also a reliable unconnected transport (one QP reaches any peer, delivery isn't ordered), so we looked at the series as a possible second implementor of IB_QPT_RU that isn't a UET device. Other vendors might also want to support this interface in the future.

I'm not sure about this. If you have exactly UET programming semantics, including the job, then sure.

But squeezing some EFA specific thing that doesn't follow the spec isn't a good way to build the APIs.. Persumably EFA has its own job-like mechanism for security that is different?

Jason

#16 lore raw

Re: [PATCH rdma-next v3 06/13] RDMA/core: query the semantics a queue pair type guarantees

In reply to Eric Davis
Quoted 223 lines · Eric Davis

An unconnected transport orders far less than a connected one, and how much varies by device. Add a device method that reports, for a queue pair type, which operations it orders against which and up to what size the data stays in that order, the largest packet it puts on the wire, how wide an immediate it carries, and whether that immediate consumes a posted receive.

---
 drivers/infiniband/core/device.c                  |  1 +
 drivers/infiniband/core/uverbs.h                  | 13 ++++
 drivers/infiniband/core/uverbs_std_types_device.c | 90 ++++++++++++++++++++++-
 include/rdma/ib_verbs.h                           | 15 ++++
 include/uapi/rdma/ib_user_ioctl_cmds.h            |  6 ++
 include/uapi/rdma/ib_user_ioctl_verbs.h           | 65 ++++++++++++++++
 6 files changed, 189 insertions(+), 1 deletion(-)
drivers/infiniband/core/device.c +1 -0
index 7c65a9373701..8b1563de4726 100644
@@ -3011,6 +3011,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
 	SET_DEVICE_OP(dev_ops, query_port);
 	SET_DEVICE_OP(dev_ops, query_port_speed);
 	SET_DEVICE_OP(dev_ops, query_qp);
+	SET_DEVICE_OP(dev_ops, query_qp_semantics);
 	SET_DEVICE_OP(dev_ops, query_srq);
 	SET_DEVICE_OP(dev_ops, query_ucontext);
 	SET_DEVICE_OP(dev_ops, rdma_netdev_get_params);
drivers/infiniband/core/uverbs.h +13 -0
index 6aaac1c309f0..2160985f18e9 100644
@@ -407,5 +407,18 @@ static inline void ib_uverbs_comp_dev(struct ib_uverbs_device *dev)
 	complete(&dev->comp);
 }
 
+/* the semantics fields, ordering bits and usage flags uverbs knows of */
+#define QP_SEMANTICS_MASK_ALL	((IB_UVERBS_QP_SEMANTICS_MASK_USAGE << 1) - 1)
+#define QP_ORDER_ALL		((IB_UVERBS_QP_ORDER_WAW << 1) - 1)
+#define QP_USAGE_ALL		IB_UVERBS_QP_USAGE_IMM_DATA_RQ
+
+/* the ordering bits each data-ordering size limits */
+#define QP_ORDER_RAW_SIZED	(IB_UVERBS_QP_ORDER_RDMA_RAW |	\
+				 IB_UVERBS_QP_ORDER_RAW)
+#define QP_ORDER_WAR_SIZED	(IB_UVERBS_QP_ORDER_RDMA_WAR |	\
+				 IB_UVERBS_QP_ORDER_WAR)
+#define QP_ORDER_WAW_SIZED	(IB_UVERBS_QP_ORDER_RDMA_WAW |	\
+				 IB_UVERBS_QP_ORDER_WAW)
+
 
 #endif /* UVERBS_H */
drivers/infiniband/core/uverbs_std_types_device.c +89 -1
index db65032e80b4..4fed4e79a3d2 100644
@@ -591,6 +591,93 @@ DECLARE_UVERBS_NAMED_METHOD(
 			    UVERBS_ATTR_TYPE(u32),
 			    UA_OPTIONAL));
 
+/* What a QP type guarantees on this device. Which operations it orders
+ * against, how large a packet it puts on the wire, how wide an immediate it
+ * carries.
+ */
+static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_QP_SEMANTICS)(
+	struct uverbs_attr_bundle *attrs)
+{
+	struct ib_uverbs_qp_semantics resp = {};
+	struct ib_qp_semantics sem = {};
+	struct ib_ucontext *ucontext;
+	struct ib_device *ib_dev;
+	enum ib_qp_type qp_type;
+	int ret;
+
+	ucontext = ib_uverbs_get_ucontext(attrs);
+	if (IS_ERR(ucontext))
+		return PTR_ERR(ucontext);
+	ib_dev = ucontext->device;
+
+	if (!ib_dev->ops.query_qp_semantics)
+		return -EOPNOTSUPP;
+
+	ret = uverbs_get_const(&qp_type, attrs,
+			       UVERBS_ATTR_QUERY_QP_SEMANTICS_QP_TYPE);
+	if (ret)
+		return ret;
+
+	/* only the types userspace can create, less the driver type, whose
+	 * subtypes one answer can't describe
+	 */
+	switch (qp_type) {
+	case IB_UVERBS_QPT_RC:
+	case IB_UVERBS_QPT_UC:
+	case IB_UVERBS_QPT_UD:
+	case IB_UVERBS_QPT_RAW_PACKET:
+	case IB_UVERBS_QPT_XRC_INI:
+	case IB_UVERBS_QPT_XRC_TGT:
+	case IB_UVERBS_QPT_RU:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	ret = ib_dev->ops.query_qp_semantics(ib_dev, qp_type, &sem);
+	if (ret)
+		return ret;
+
+	/* only the fields, bits and flags uverbs knows of reach userspace */
+	resp.comp_mask = sem.comp_mask & QP_SEMANTICS_MASK_ALL;
+	if (resp.comp_mask & IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER)
+		resp.msg_order = sem.msg_order & QP_ORDER_ALL;
+	if (resp.comp_mask & IB_UVERBS_QP_SEMANTICS_MASK_RAW)
+		resp.max_rdma_raw_size = sem.max_rdma_raw_size;
+	if (resp.comp_mask & IB_UVERBS_QP_SEMANTICS_MASK_WAR)
+		resp.max_rdma_war_size = sem.max_rdma_war_size;
+	if (resp.comp_mask & IB_UVERBS_QP_SEMANTICS_MASK_WAW)
+		resp.max_rdma_waw_size = sem.max_rdma_waw_size;
+	if (resp.comp_mask & IB_UVERBS_QP_SEMANTICS_MASK_PDU)
+		resp.max_pdu = sem.max_pdu;
+	if (resp.comp_mask & IB_UVERBS_QP_SEMANTICS_MASK_USAGE)
+		resp.usage_flags = sem.usage_flags & QP_USAGE_ALL;
+	if (resp.comp_mask & IB_UVERBS_QP_SEMANTICS_MASK_IMM)
+		resp.imm_data_size = sem.imm_data_size;
+
+	/* a pair whose data-ordering size is 0 is not ordered */
+	if (!resp.max_rdma_raw_size)
+		resp.msg_order &= ~QP_ORDER_RAW_SIZED;
+	if (!resp.max_rdma_war_size)
+		resp.msg_order &= ~QP_ORDER_WAR_SIZED;
+	if (!resp.max_rdma_waw_size)
+		resp.msg_order &= ~QP_ORDER_WAW_SIZED;
+
+	return uverbs_copy_to_struct_or_zero(
+		attrs, UVERBS_ATTR_QUERY_QP_SEMANTICS_RESP, &resp,
+		sizeof(resp));
+}
+
+DECLARE_UVERBS_NAMED_METHOD(
+	UVERBS_METHOD_QUERY_QP_SEMANTICS,
+	UVERBS_ATTR_CONST_IN(UVERBS_ATTR_QUERY_QP_SEMANTICS_QP_TYPE,
+			     enum ib_uverbs_qp_type,
+			     UA_MANDATORY),
+	UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_QP_SEMANTICS_RESP,
+			    UVERBS_ATTR_STRUCT(struct ib_uverbs_qp_semantics,
+					       imm_data_size),
+			    UA_MANDATORY));
+
 DECLARE_UVERBS_GLOBAL_METHODS(UVERBS_OBJECT_DEVICE,
 			      &UVERBS_METHOD(UVERBS_METHOD_GET_CONTEXT),
 			      &UVERBS_METHOD(UVERBS_METHOD_INVOKE_WRITE),
@@ -600,7 +687,8 @@ DECLARE_UVERBS_GLOBAL_METHODS(UVERBS_OBJECT_DEVICE,
 			      &UVERBS_METHOD(UVERBS_METHOD_QUERY_CONTEXT),
 			      &UVERBS_METHOD(UVERBS_METHOD_QUERY_GID_TABLE),
 			      &UVERBS_METHOD(UVERBS_METHOD_QUERY_GID_ENTRY),
-			      &UVERBS_METHOD(UVERBS_METHOD_QUERY_COMP_CNTR_CAPS));
+			      &UVERBS_METHOD(UVERBS_METHOD_QUERY_COMP_CNTR_CAPS),
+			      &UVERBS_METHOD(UVERBS_METHOD_QUERY_QP_SEMANTICS));
 
 const struct uapi_definition uverbs_def_obj_device[] = {
 	UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_DEVICE),
include/rdma/ib_verbs.h +15 -0
index 68f7a271cf7a..003b70424429 100644
@@ -2496,6 +2496,18 @@ struct ib_counters {
 	atomic_t	usecnt;
 };
 
+/* what a queue pair of a given type guarantees (query_qp_semantics) */
+struct ib_qp_semantics {
+	u32	comp_mask;		/* enum ib_uverbs_qp_semantics_mask */
+	u32	msg_order;		/* enum ib_uverbs_qp_msg_order */
+	u32	max_rdma_raw_size;
+	u32	max_rdma_war_size;
+	u32	max_rdma_waw_size;
+	u32	max_pdu;
+	u32	usage_flags;		/* enum ib_uverbs_qp_usage_flags */
+	u8	imm_data_size;		/* bits */
+};
+
 struct ib_counters_read_attr {
 	u64	*counters_buff;
 	u32	ncounters;
@@ -2751,6 +2763,9 @@ struct ib_device_ops {
 				       int mr_access_flags, struct ib_pd *pd,
 				       struct ib_udata *udata);
 	int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata);
+	int (*query_qp_semantics)(struct ib_device *device,
+				  enum ib_qp_type qp_type,
+				  struct ib_qp_semantics *sem);
 	struct ib_mr *(*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type,
 				  u32 max_num_sg);
 	struct ib_mr *(*alloc_mr_integrity)(struct ib_pd *pd,
include/uapi/rdma/ib_user_ioctl_cmds.h +6 -0
index 40fcd4bd1b5e..fb746257eb2c 100644
@@ -77,6 +77,12 @@ enum uverbs_methods_device {
 	UVERBS_METHOD_QUERY_GID_ENTRY,
 	UVERBS_METHOD_QUERY_PORT_SPEED,
 	UVERBS_METHOD_QUERY_COMP_CNTR_CAPS,
+	UVERBS_METHOD_QUERY_QP_SEMANTICS,
+};
+
+enum uverbs_attrs_query_qp_semantics_attr_ids {
+	UVERBS_ATTR_QUERY_QP_SEMANTICS_QP_TYPE,
+	UVERBS_ATTR_QUERY_QP_SEMANTICS_RESP,
 };
 
 enum uverbs_attrs_invoke_write_cmd_attr_ids {
include/uapi/rdma/ib_user_ioctl_verbs.h +5 -0
index 4975771290eb..9ae45f7d3dc0 100644
@@ -323,6 +323,52 @@ struct ib_uverbs_buffer_desc {
 #define IB_UVERBS_QPN_UET_RESERVED_MASK		0x7f000000
 #define IB_UVERBS_QPN_UET_ABSOLUTE_ADDR_BIT	0x80000000
 
+enum ib_uverbs_qp_semantics_mask {
+	IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER	= 1 << 0,
+	IB_UVERBS_QP_SEMANTICS_MASK_RAW		= 1 << 1,
+	IB_UVERBS_QP_SEMANTICS_MASK_WAR		= 1 << 2,
+	IB_UVERBS_QP_SEMANTICS_MASK_WAW		= 1 << 3,

include/uapi/rdma/ib_user_ioctl_verbs.h struct ib_uverbs_buffer_desc { · line 340

Quoted 10 lines
include/uapi/rdma/ib_user_ioctl_verbs.h +10 -0
+	IB_UVERBS_QP_SEMANTICS_MASK_PDU		= 1 << 4,
+	IB_UVERBS_QP_SEMANTICS_MASK_IMM		= 1 << 5,
+	IB_UVERBS_QP_SEMANTICS_MASK_USAGE	= 1 << 6,
+};
+
+/* Ordering guarantees between operations on one QP. "X after Y" means an
+ * X may not pass a Y posted before it. A bit that is clear means the pair
+ * does not order that combination, and an application that needs it must
+ * wait for the earlier completion.
+ */

These bits describe ordering at the target. Is completion order meant to be covered too? It can differ from placement order, and it can differ between the send queue (completions vs post order) and the receive queue (receive completions vs the sender's order). Would it make sense to report those separately, so an app knows whether it can rely on in-order send completions, for example for selective signaling?

Quoted 19 lines
include/uapi/rdma/ib_user_ioctl_verbs.h +19 -0
+enum ib_uverbs_qp_msg_order {
+	/* atomic after atomic */
+	IB_UVERBS_QP_ORDER_ATOMIC_RAR	= 1 << 0,
+	IB_UVERBS_QP_ORDER_ATOMIC_RAW	= 1 << 1,
+	IB_UVERBS_QP_ORDER_ATOMIC_WAR	= 1 << 2,
+	IB_UVERBS_QP_ORDER_ATOMIC_WAW	= 1 << 3,
+	/* rma after rma */
+	IB_UVERBS_QP_ORDER_RDMA_RAR	= 1 << 4,
+	IB_UVERBS_QP_ORDER_RDMA_RAW	= 1 << 5,
+	IB_UVERBS_QP_ORDER_RDMA_WAR	= 1 << 6,
+	IB_UVERBS_QP_ORDER_RDMA_WAW	= 1 << 7,
+	/* send against send, rma and atomic */
+	IB_UVERBS_QP_ORDER_RAS		= 1 << 8,
+	IB_UVERBS_QP_ORDER_SAR		= 1 << 9,
+	IB_UVERBS_QP_ORDER_SAS		= 1 << 10,
+	IB_UVERBS_QP_ORDER_SAW		= 1 << 11,
+	IB_UVERBS_QP_ORDER_WAS		= 1 << 12,
+	/* rma or atomic against rma or atomic, in any mix, so each also
+	 * covers its RDMA_ and ATOMIC_ bit

include/uapi/rdma/ib_user_ioctl_verbs.h struct ib_uverbs_buffer_desc { · line 369

Quoted 10 lines
include/uapi/rdma/ib_user_ioctl_verbs.h +10 -0
+	 */
+	IB_UVERBS_QP_ORDER_RAR		= 1 << 13,
+	IB_UVERBS_QP_ORDER_RAW		= 1 << 14,
+	IB_UVERBS_QP_ORDER_WAR		= 1 << 15,
+	IB_UVERBS_QP_ORDER_WAW		= 1 << 16,
+};
+
+enum ib_uverbs_qp_usage_flags {
+	/* immediate data consumes a posted receive */
+	IB_UVERBS_QP_USAGE_IMM_DATA_RQ	= 1 << 0,

Some devices can do either per QP: an RDMA write with immediate either consumes a posted receive or completes without one. With the subset check in 10, how would such a device advertise both, and how would an app ask for the mode that doesn't consume a receive? It seems more like a mode the QP is created with than a guarantee to relax. Would a separate create-time choice fit better, with the device reporting which modes it supports?

Michael

Quoted 35 lines
include/uapi/rdma/ib_user_ioctl_verbs.h +21 -0
+};
+
 /* An address handle that names a peer using both transport+network addresses.
  * Used for reliable unconnected QPs in both work request address handles and
  * a Job address table.
@@ -332,6 +378,25 @@ struct ib_uverbs_ah_attr_ex {
 	__u32 remote_qpn;
 };
 
+struct ib_uverbs_qp_semantics {
+	__u32 comp_mask;		/* enum ib_uverbs_qp_semantics_mask */
+	__u32 msg_order;		/* enum ib_uverbs_qp_msg_order */
+	/*
+	 * Data ordering: the largest transfer, in bytes, for which the target
+	 * memory reflects the order of the pair under its RDMA_ and plain
+	 * msg_order bits. 0 if not provided, and those bits are then clear.
+	 * The sizes don't limit the ATOMIC_ bits. There is no read-after-read
+	 * size, as two reads leave memory unchanged.
+	 */
+	__u32 max_rdma_raw_size;	/* read after write */
+	__u32 max_rdma_war_size;	/* write after read */
+	__u32 max_rdma_waw_size;	/* write after write */
+	__u32 max_pdu;			/* largest packet, bytes */
+	__u32 usage_flags;		/* enum ib_uverbs_qp_usage_flags */
+	__u8  imm_data_size;		/* widest immediate, in bits */
+	__u8  reserved[3];
+};
+
 enum ib_uverbs_comp_cntr_entry {
 	IB_UVERBS_COMP_CNTR_ENTRY_COMP,
 	IB_UVERBS_COMP_CNTR_ENTRY_ERR,
Signature · 2 lines
-- 
2.56.0
#23 lore raw

Re: [PATCH rdma-next v3 09/13] RDMA/core: create a queue pair ready to send

In reply to Eric Davis
Quoted 26 lines · Eric Davis

Some transports have nothing to negotiate, so a queue pair can be ready to send the moment it exists and the modify sequence carries no useful information. Let a reliable unconnected queue pair be created with the attributes that sequence would have supplied, in the same form the modify command uses, and apply them as that modify to RTS once the queue pair exists, so its checks run. A queue pair whose modify fails is destroyed, and a later modify may change no more than those attributes.

Note that the QP handle field is refused, since the create is what makes the handle.

---
 drivers/infiniband/core/uverbs.h              |  7 +++
 drivers/infiniband/core/uverbs_cmd.c          |  6 +++
 drivers/infiniband/core/uverbs_std_types_qp.c | 74 +++++++++++++++++++++++++++
 drivers/infiniband/core/verbs.c               |  7 ++-
 include/uapi/rdma/ib_user_ioctl_cmds.h        |  1 +
 5 files changed, 93 insertions(+), 2 deletions(-)
drivers/infiniband/core/uverbs.h +0 -0
index 65a217bf65b5..59015a7a52f6 100644

drivers/infiniband/core/uverbs.h int ib_uverbs_copy_qp_attr(struct uverbs_attr_bundle *attrs, · line 334

Quoted 10 lines
drivers/infiniband/core/uverbs.h +7 -0
@@ -325,6 +325,13 @@ int ib_uverbs_copy_qp_attr(struct uverbs_attr_bundle *attrs,
 			   const struct ib_uverbs_ex_modify_qp *src,
 			   u32 mask);
 
+/* what a reliable unconnected QP is created ready to send with, and all a
+ * later modify may change
+ */
+#define QP_ATTR_RU_MASK		(IB_QP_STATE | IB_QP_PKEY_INDEX |	\
+				 IB_QP_PORT | IB_QP_ACCESS_FLAGS |	\
+				 IB_QP_PATH_MTU)
+

Since this gates both the create attributes and every later modify, another RU implementation can't add an attribute it needs without changing core. Q_Key and RNR retry are examples for SRD. Would it work to have the mask list everything that could make sense for RU, and let each driver refuse what it doesn't support?

Quoted 39 lines
drivers/infiniband/core/uverbs.h +0 -0
 int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
 					  const void *kern_spec_mask,
 					  const void *kern_spec_val,
drivers/infiniband/core/uverbs_cmd.c +6 -0
index 140f1cf91527..afe891e7b42d 100644
@@ -1913,6 +1913,12 @@ static int modify_qp(struct uverbs_attr_bundle *attrs,
 		goto out;
 	}
 
+	if (qp->qp_type == IB_QPT_RU &&
+	    (cmd->base.attr_mask & ~QP_ATTR_RU_MASK)) {
+		ret = -EINVAL;
+		goto release_qp;
+	}
+
 	if ((cmd->base.attr_mask & IB_QP_AV)) {
 		if (cmd->base.attr_mask & IB_QP_STATE &&
 		    cmd->base.qp_state == IB_QPS_RTR) {
drivers/infiniband/core/uverbs_std_types_qp.c +11 -0
index 30fc20fb251f..249206d2992f 100644
@@ -79,6 +79,55 @@ static void set_caps(struct ib_qp_init_attr *attr,
 	}
 }
 
+/* The attributes the QP would be modified with via modify_qp calls. Used for
+ * implementations that support having QPs be in RTS immediately after QP
+ * creation. These attributes arrive in the same format the modify command
+ * uses so that converter serves both, and they are applied as that modify
+ * to RTS, once the QP exists.
+ */
+static int create_qp_attr_set(struct uverbs_attr_bundle *attrs,
+			      struct ib_device *device,
+			      struct ib_qp_init_attr *attr,
+			      struct ib_qp_attr *qp_attr, u32 *mask)
+{

drivers/infiniband/core/uverbs_std_types_qp.c static void set_caps(struct ib_qp_init_attr *attr, · line 102

Quoted 10 lines
drivers/infiniband/core/uverbs_std_types_qp.c +10 -0
+	struct ib_uverbs_ex_modify_qp uqpa = {};
+	int ret;
+
+	*mask = 0;
+
+	if (!uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_ATTR))
+		return 0;
+
+	if (attr->qp_type != IB_QPT_RU)
+		return -EOPNOTSUPP;

Could creating ready to send be driven by the attribute rather than the QP type, both in create_qp_attr_set() and in the RTS step after create? UD and other connectionless QPs don't need INIT/RTR to negotiate anything either. A driver that supports it for a type would accept it, and others would refuse it.

Michael

Quoted 70 lines
drivers/infiniband/core/uverbs_std_types_qp.c +49 -0
+
+	ret = uverbs_copy_from_or_zero(&uqpa, attrs,
+				       UVERBS_ATTR_CREATE_QP_ATTR);
+	if (ret)
+		return ret;
+
+	/* the create is what makes the handle, can't be one specified */
+	if (uqpa.base.qp_handle)
+		return -EINVAL;
+
+	if (uqpa.reserved || uqpa.base.reserved[0] || uqpa.base.reserved[1])
+		return -EINVAL;
+
+	if ((uqpa.base.attr_mask & ~QP_ATTR_RU_MASK) ||
+	    ((uqpa.base.attr_mask & IB_QP_STATE) &&
+	     uqpa.base.qp_state != IB_QPS_RTS))
+		return -EINVAL;
+
+	ret = ib_uverbs_copy_qp_attr(attrs, device, qp_attr, &uqpa,
+				     uqpa.base.attr_mask);
+	if (ret)
+		return ret;
+
+	*mask = uqpa.base.attr_mask;
+
+	return 0;
+}
+
 static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 	struct uverbs_attr_bundle *attrs)
 {
@@ -86,6 +135,8 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 		uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_QP_HANDLE),
 		typeof(*obj), uevent.uobject);
 	struct ib_qp_init_attr attr = {};
+	struct ib_qp_attr qp_attr = {};
+	u32 qp_attr_mask;
 	struct ib_uverbs_qp_cap cap = {};
 	struct ib_rwq_ind_table *rwq_ind_tbl = NULL;
 	struct ib_qp *qp;
@@ -214,6 +265,11 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 		attr.create_flags |= IB_QP_CREATE_SOURCE_QPN;
 	}
 
+	ret = create_qp_attr_set(attrs, device, &attr, &qp_attr,
+				 &qp_attr_mask);
+	if (ret)
+		return ret;
+
 	srq = uverbs_attr_get_obj(attrs,
 				  UVERBS_ATTR_CREATE_QP_SRQ_HANDLE);
 	if (!IS_ERR(srq)) {
@@ -264,6 +320,20 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 	obj->uevent.uobject.object = qp;
 	uverbs_finalize_uobj_create(attrs, UVERBS_ATTR_CREATE_QP_HANDLE);
 
+	/* A reliable unconnected QP is ready to send once created. What the
+	 * caller passed is applied as the modify to RTS it stands in for, so
+	 * the modify's checks run. A failure here destroys the QP.
+	 */
+	if (attr.qp_type == IB_QPT_RU) {
+		qp_attr.qp_state = IB_QPS_RTS;
+		/* the driver's data was for create, there is none for this */
+		ret = ib_modify_qp_with_udata(qp, &qp_attr,
+					      qp_attr_mask | IB_QP_STATE,
+					      uverbs_get_cleared_udata(attrs));
+		if (ret)
+			return ret;
+	}
+
#27 lore raw

Re: [PATCH rdma-next v3 10/13] RDMA/core: queue pair attributes for unconnected transports

In reply to Eric Davis
Quoted 109 lines · Eric Davis

A queue pair on an unconnected transport is created with more than the connected attributes. A job key authorizing it to act within a job, the initiator identity it sends under, and the ordering guarantees the caller wants it to keep.

The QP holds a reference to its job key for as long as it lives, so the job cannot go away underneath it.

---
 drivers/infiniband/core/uverbs_std_types_qp.c | 173 ++++++++++++++++++++++++++
 drivers/infiniband/core/verbs.c               |   5 +
 include/rdma/ib_verbs.h                       |  14 +++
 include/uapi/rdma/ib_user_ioctl_cmds.h        |   3 +
 4 files changed, 195 insertions(+)
drivers/infiniband/core/uverbs_std_types_qp.c +85 -0
index 249206d2992f..a1112083fb73 100644
@@ -79,6 +79,157 @@ static void set_caps(struct ib_qp_init_attr *attr,
 	}
 }
 
+/* A QP may relax what its type guarantees on this device, but not ask for
+ * more than the device advertises for it.
+ */
+static int create_qp_semantics_check(struct ib_device *device,
+				     const struct ib_qp_semantics *req)
+{
+	struct ib_qp_semantics adv = {};
+	u32 m = req->comp_mask;
+	int ret;
+
+	if (!device->ops.query_qp_semantics)
+		return -EOPNOTSUPP;
+
+	ret = device->ops.query_qp_semantics(device, IB_QPT_RU, &adv);
+	if (ret)
+		return ret;
+
+	if (m & ~adv.comp_mask)
+		return -EINVAL;
+
+	if (((m & IB_UVERBS_QP_SEMANTICS_MASK_MSG_ORDER) &&
+	     (req->msg_order & ~adv.msg_order)) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_RAW) &&
+	     req->max_rdma_raw_size > adv.max_rdma_raw_size) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_WAR) &&
+	     req->max_rdma_war_size > adv.max_rdma_war_size) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_WAW) &&
+	     req->max_rdma_waw_size > adv.max_rdma_waw_size) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_PDU) &&
+	     req->max_pdu > adv.max_pdu) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_IMM) &&
+	     req->imm_data_size > adv.imm_data_size) ||
+	    ((m & IB_UVERBS_QP_SEMANTICS_MASK_USAGE) &&
+	     (req->usage_flags & ~adv.usage_flags)))
+		return -EINVAL;
+
+	return 0;
+}
+
+/* Process the optional creation attributes. A job to act within, a source
+ * identity, a set of ordering guarantees to ask for. They and the checks on
+ * a requested QP number belong to a reliable unconnected QP.
+ */
+static int create_qp_opt_attrs(struct uverbs_attr_bundle *attrs,
+			       struct ib_device *device, struct ib_pd *pd,
+			       struct ib_qp_init_attr *attr,
+			       struct ib_qp_semantics *sem)
+{
+	struct ib_uverbs_qp_semantics usem = {};
+	struct ib_jkey *jkey;
+	bool has_semantics;
+	u32 m;
+	int ret;
+
+	has_semantics = uverbs_attr_is_valid(attrs,
+					     UVERBS_ATTR_CREATE_QP_SEMANTICS);
+
+	if (attr->qp_type != IB_QPT_RU) {
+		if (has_semantics ||
+		    uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_SRC_ID) ||
+		    uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_JOB_KEY))
+			return -EOPNOTSUPP;
+
+		return 0;
+	}
+
+	if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_SRC_ID)) {
+		ret = uverbs_copy_from(&attr->src_id, attrs,
+				       UVERBS_ATTR_CREATE_QP_SRC_ID);
+		if (ret)
+			return ret;
+	}
+
+	if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_QP_JOB_KEY)) {
+		jkey = uverbs_attr_get_obj(attrs,
+					   UVERBS_ATTR_CREATE_QP_JOB_KEY);
+		if (IS_ERR(jkey))
+			return PTR_ERR(jkey);
+
+		/* a key acts within the PD it was made on */
+		if (jkey->pd != pd)
+			return -EINVAL;
+
+		attr->jkey = jkey;
+	}

drivers/infiniband/core/uverbs_std_types_qp.c static void set_caps(struct ib_qp_init_attr *attr, · line 176

Quoted 10 lines
drivers/infiniband/core/uverbs_std_types_qp.c +10 -0
+
+	if (attr->create_flags & IB_QP_CREATE_SOURCE_QPN) {
+		if (attr->source_qpn & IB_UVERBS_QPN_UET_RESERVED_MASK)
+			return -EINVAL;
+
+		/* a relative QP is named within a job, so it needs a key */
+		if (!(attr->source_qpn &
+		      IB_UVERBS_QPN_UET_ABSOLUTE_ADDR_BIT) &&
+		    !attr->jkey)
+			return -EINVAL;

On a device without jobs, these two checks together mean a caller can only choose a QPN that has the absolute bit set. Is that rule meant for RU in general, or only for UET?

Michael

#39 lore raw
In reply to Jason Gunthorpe
Quoted 23 lines · Jason Gunthorpe
Quoted 14 lines · Michael Margolin
Quoted 6 lines · Eric Davis

Ultra Ethernet defines a reliable unconnected transport. A queue pair sends to any peer in its job without a connection, incoming traffic is demultiplexed on a JobID rather than on a connection, and what a device orders is far weaker than IB or RoCE and varies between devices. None of that has a home in the current uverbs ABI.

Quoted 6 lines

This series adds the generic half. The objects, methods, and attributes any UET device implements. No driver is part of it, though two already exist against this ABI. A reference device model that implements all of it, and HPE's Slingshot driver implementing a large subset. That is the argument for ib_core carrying this. What is device specific should come from private interfaces per vendor.

Quoted 7 lines

Hey Eric,

Thanks for posting this. EFA's SRD is also a reliable unconnected transport (one QP reaches any peer, delivery isn't ordered), so we looked at the series as a possible second implementor of IB_QPT_RU that isn't a UET device. Other vendors might also want to support this interface in the future.

Quoted 7 lines

I'm not sure about this. If you have exactly UET programming semantics, including the job, then sure.

But squeezing some EFA specific thing that doesn't follow the spec isn't a good way to build the APIs.. Persumably EFA has its own job-like mechanism for security that is different?

I see your point about trying to fit an API to a different use case it's not meant for, but I don't think this is the case here. EFA doesn't have a job-like mechanism, isolation is handled by the network, so jobs just don't apply there.

As I see it, RU can be (and this series gets quite close to this) just another QP type multiple vendors can support, with UET specifics like jobs being optional on top. I think that treating it this way during interface definition improves it.

Michael

Quoted 1 line

Jason

#40 lore raw
Quoted 32 lines · Michael Margolin
Quoted 23 lines · Jason Gunthorpe
Quoted 14 lines · Michael Margolin
Quoted 6 lines · Eric Davis

Ultra Ethernet defines a reliable unconnected transport. A queue pair sends to any peer in its job without a connection, incoming traffic is demultiplexed on a JobID rather than on a connection, and what a device orders is far weaker than IB or RoCE and varies between devices. None of that has a home in the current uverbs ABI.

Quoted 6 lines

This series adds the generic half. The objects, methods, and attributes any UET device implements. No driver is part of it, though two already exist against this ABI. A reference device model that implements all of it, and HPE's Slingshot driver implementing a large subset. That is the argument for ib_core carrying this. What is device specific should come from private interfaces per vendor.

Quoted 7 lines

Hey Eric,

Thanks for posting this. EFA's SRD is also a reliable unconnected transport (one QP reaches any peer, delivery isn't ordered), so we looked at the series as a possible second implementor of IB_QPT_RU that isn't a UET device. Other vendors might also want to support this interface in the future.

Quoted 7 lines

I'm not sure about this. If you have exactly UET programming semantics, including the job, then sure.

But squeezing some EFA specific thing that doesn't follow the spec isn't a good way to build the APIs.. Persumably EFA has its own job-like mechanism for security that is different?

Quoted 4 lines

I see your point about trying to fit an API to a different use case it's not meant for, but I don't think this is the case here. EFA doesn't have a job-like mechanism, isolation is handled by the network, so jobs just don't apply there.

That sounds like you are saying you have a job for the entire node. Which isn't the UET model at all.

I haven't looked at these patches, but I understood job should come from outside verbs as it is something an external entitiy is creating and then sharing across alot of processes.

If so then EFA could still have a singleton job object and that could be the deviation. One job only, and the job doesn't actually do anything to limit access.

Jason

author
#41 lore raw
Quoted 46 lines · Jason Gunthorpe
Quoted 32 lines · Michael Margolin
Quoted 23 lines · Jason Gunthorpe
Quoted 14 lines · Michael Margolin
Quoted 6 lines · Eric Davis

Ultra Ethernet defines a reliable unconnected transport. A queue pair sends to any peer in its job without a connection, incoming traffic is demultiplexed on a JobID rather than on a connection, and what a device orders is far weaker than IB or RoCE and varies between devices. None of that has a home in the current uverbs ABI.

Quoted 6 lines

This series adds the generic half. The objects, methods, and attributes any UET device implements. No driver is part of it, though two already exist against this ABI. A reference device model that implements all of it, and HPE's Slingshot driver implementing a large subset. That is the argument for ib_core carrying this. What is device specific should come from private interfaces per vendor.

Quoted 7 lines

Hey Eric,

Thanks for posting this. EFA's SRD is also a reliable unconnected transport (one QP reaches any peer, delivery isn't ordered), so we looked at the series as a possible second implementor of IB_QPT_RU that isn't a UET device. Other vendors might also want to support this interface in the future.

Quoted 7 lines

I'm not sure about this. If you have exactly UET programming semantics, including the job, then sure.

But squeezing some EFA specific thing that doesn't follow the spec isn't a good way to build the APIs.. Persumably EFA has its own job-like mechanism for security that is different?

Quoted 4 lines

I see your point about trying to fit an API to a different use case it's not meant for, but I don't think this is the case here. EFA doesn't have a job-like mechanism, isolation is handled by the network, so jobs just don't apply there.

That sounds like you are saying you have a job for the entire node. Which isn't the UET model at all.

I haven't looked at these patches, but I understood job should come from outside verbs as it is something an external entitiy is creating and then sharing across alot of processes.

Quoted 5 lines

If so then EFA could still have a singleton job object and that could be the deviation. One job only, and the job doesn't actually do anything to limit access.

Jason

In the UET spec v1.1, Sean Hefty and I contributed a new section defining the Verbs mapping over UET (if you're curious, it complements this patch series and is a short read).

One key design point for RU QPs is that we tried to separate them from the transport. Specifically the GID type selects the transport and an RU QP should work over any transport that supports reliable unconnected. Of course each supported transport may require different attributes to come from the QP configuration. I'm totally fine with making some attributes optional and requiring the provider driver to verify the given attributes.

Based on Michael's porting effort, minor tweaks may be needed in some cases. I will follow up in each of those patch threads.

Curious what others think about this direction...?

- eric