mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
RDMA/irdma: Use robust udata helper for QP creation
Replace the manual udata input copy and validation during QP creation with the robust helper. The irdma driver is backwards compatible with the legacy i40iw userspace provider. The current create_qp ABI contains two 8 byte fields. The legacy i40iw ABI was the same but also contained two additional fields which were never actually used. Furthermore, the i40iw userspace provider never explicitly zero-initialized those extra fields, so there is a chance that existing binaries are passing non-zero garbage values down to the kernel. Previously, the irdma driver only copied out the first 16 bytes and did not have any check for the rest of the buffer being zero, so that additional garbage didn't matter. By switching to ib_copy_validate_udata_in(), we will now be checking to ensure that data beyond the kernel's definition of the request is all zero. In order to avoid breaking legacy binaries, we therefore need to increase the request structure size to cover those garbage fields. - Legacy binaries will continue to pass down a 32 byte request, with the driver copying the entire 32 bytes out but ignoring the second 16 bytes, just as before. - Newer binaries will pass down the normal 16 byte request. The ib_copy_validate_udata_in() call will allow this to succeed because we use user_compl_ctx as our minimum length (16 bytes). - If the request is ever extended, the new fields would be added after the "don't use" fields and would work as per the normal uAPI mechanism. Signed-off-by: Jacob Moroni <jmoroni@google.com> Link: https://patch.msgid.link/20260713171257.3131493-5-jmoroni@google.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
This commit is contained in:
committed by
Leon Romanovsky
parent
aa5967095c
commit
173fc2b8dc
@@ -631,37 +631,29 @@ static void irdma_setup_virt_qp(struct irdma_device *iwdev,
|
||||
|
||||
/**
|
||||
* irdma_setup_umode_qp - setup sq and rq size in user mode qp
|
||||
* @udata: udata
|
||||
* @ucontext: user context
|
||||
* @req: user request pointer
|
||||
* @iwdev: iwarp device
|
||||
* @iwqp: qp ptr (user or kernel)
|
||||
* @info: initialize info to return
|
||||
* @init_attr: Initial QP create attributes
|
||||
*/
|
||||
static int irdma_setup_umode_qp(struct ib_udata *udata,
|
||||
static int irdma_setup_umode_qp(struct irdma_ucontext *ucontext,
|
||||
struct irdma_create_qp_req *req,
|
||||
struct irdma_device *iwdev,
|
||||
struct irdma_qp *iwqp,
|
||||
struct irdma_qp_init_info *info,
|
||||
struct ib_qp_init_attr *init_attr)
|
||||
{
|
||||
struct irdma_ucontext *ucontext = rdma_udata_to_drv_context(udata,
|
||||
struct irdma_ucontext, ibucontext);
|
||||
struct irdma_qp_uk_init_info *ukinfo = &info->qp_uk_init_info;
|
||||
struct irdma_create_qp_req req;
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
|
||||
ret = ib_copy_from_udata(&req, udata,
|
||||
min(sizeof(req), udata->inlen));
|
||||
if (ret) {
|
||||
ibdev_dbg(&iwdev->ibdev, "VERBS: ib_copy_from_data fail\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
iwqp->ctx_info.qp_compl_ctx = req.user_compl_ctx;
|
||||
iwqp->ctx_info.qp_compl_ctx = req->user_compl_ctx;
|
||||
iwqp->user_mode = 1;
|
||||
|
||||
spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
|
||||
iwqp->iwpbl = irdma_get_pbl((unsigned long)req.user_wqe_bufs,
|
||||
iwqp->iwpbl = irdma_get_pbl((unsigned long)req->user_wqe_bufs,
|
||||
&ucontext->qp_reg_mem_list);
|
||||
spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
|
||||
|
||||
@@ -988,6 +980,7 @@ static int irdma_create_qp(struct ib_qp *ibqp,
|
||||
struct irdma_uk_attrs *uk_attrs = &dev->hw_attrs.uk_attrs;
|
||||
struct irdma_qp_init_info init_info = {};
|
||||
struct irdma_qp_host_ctx_info *ctx_info;
|
||||
struct irdma_create_qp_req ureq = {};
|
||||
struct irdma_srq *iwsrq;
|
||||
bool srq_valid = false;
|
||||
u32 srq_id = 0;
|
||||
@@ -1005,9 +998,14 @@ static int irdma_create_qp(struct ib_qp *ibqp,
|
||||
if (err_code)
|
||||
return err_code;
|
||||
|
||||
if (udata && (udata->inlen < IRDMA_CREATE_QP_MIN_REQ_LEN ||
|
||||
udata->outlen < IRDMA_CREATE_QP_MIN_RESP_LEN))
|
||||
return -EINVAL;
|
||||
if (udata) {
|
||||
if (udata->outlen < IRDMA_CREATE_QP_MIN_RESP_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
err_code = ib_copy_validate_udata_in(udata, ureq, user_compl_ctx);
|
||||
if (err_code)
|
||||
return err_code;
|
||||
}
|
||||
|
||||
init_info.vsi = &iwdev->vsi;
|
||||
init_info.qp_uk_init_info.uk_attrs = uk_attrs;
|
||||
@@ -1066,9 +1064,14 @@ static int irdma_create_qp(struct ib_qp *ibqp,
|
||||
init_waitqueue_head(&iwqp->mod_qp_waitq);
|
||||
|
||||
if (udata) {
|
||||
struct irdma_ucontext *ucontext =
|
||||
rdma_udata_to_drv_context(udata,
|
||||
struct irdma_ucontext,
|
||||
ibucontext);
|
||||
|
||||
init_info.qp_uk_init_info.abi_ver = iwpd->sc_pd.abi_ver;
|
||||
err_code = irdma_setup_umode_qp(udata, iwdev, iwqp, &init_info,
|
||||
init_attr);
|
||||
err_code = irdma_setup_umode_qp(ucontext, &ureq, iwdev, iwqp,
|
||||
&init_info, init_attr);
|
||||
} else {
|
||||
INIT_DELAYED_WORK(&iwqp->dwork_flush, irdma_flush_worker);
|
||||
init_info.qp_uk_init_info.abi_ver = IRDMA_ABI_VER;
|
||||
|
||||
@@ -88,6 +88,7 @@ struct irdma_create_srq_resp {
|
||||
struct irdma_create_qp_req {
|
||||
__aligned_u64 user_wqe_bufs;
|
||||
__aligned_u64 user_compl_ctx;
|
||||
__aligned_u64 legacy_dontuse[2];
|
||||
};
|
||||
|
||||
struct irdma_mem_reg_req {
|
||||
|
||||
Reference in New Issue
Block a user