Re: [PATCH rdma-next v3 09/13] RDMA/core: create a queue pair ready to send
From: Michael Margolin
Date: Mon Nov 16 2026 - 09:54:15 EST
On Mon, Nov 09, 2026 at 08:00:42PM -0800, Eric Davis wrote:
> 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.
>
> Signed-off-by: Eric Davis <eric.davis@xxxxxxxxxxxx>
> ---
> 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(-)
>
> diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
> index 65a217bf65b5..59015a7a52f6 100644
> --- a/drivers/infiniband/core/uverbs.h
> +++ b/drivers/infiniband/core/uverbs.h
> @@ -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?
> 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,
> diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
> index 140f1cf91527..afe891e7b42d 100644
> --- a/drivers/infiniband/core/uverbs_cmd.c
> +++ b/drivers/infiniband/core/uverbs_cmd.c
> @@ -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) {
> diff --git a/drivers/infiniband/core/uverbs_std_types_qp.c b/drivers/infiniband/core/uverbs_std_types_qp.c
> index 30fc20fb251f..249206d2992f 100644
> --- a/drivers/infiniband/core/uverbs_std_types_qp.c
> +++ b/drivers/infiniband/core/uverbs_std_types_qp.c
> @@ -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)
> +{
> + 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
> +
> + 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;
> + }
> +