From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63CAD8472 for ; Tue, 30 Jun 2026 06:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782799247; cv=none; b=Ij6W7ySm5Z+2xpUGRgIok4JTVNapIyI+iFHthX+VibyBrqxea6nz6cguHkTi2wA7bGwArFhqm/aHAvwaEjd7ipf7N7L/5SevZ9A8BIdI01LaNipWp6SFiZSWJSOsgmd00o8iTEG3WHvp+t9Fkg0eBO60NJ6l2MxLoo2Dko2FPL4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782799247; c=relaxed/simple; bh=C3a1uuIZmSQ8ER44ipUBv95Jspkk36dOUXVOrhiYPNI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ix2B0uMIbjiNq53oeeakBPbx9wjz9/JWNKE2PdeJ2K2787sI8HiYg81qlhQKP43T7T2rwns8Xdvfc5I7bEdUUHqXeIPzYVCBcNB7/D8gE3+YpY6IrQA6ZN/canjCbA9z6bENH8ZJCx+V6OsfCUrhU6Tr8vUj8NiyQVxLJXB9fDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=piXO5mcB; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="piXO5mcB" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-845e363246aso1916023b3a.1 for ; Mon, 29 Jun 2026 23:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782799245; x=1783404045; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=x2WnmB43eNouYPrpSpods0e3jWSS1paq4XSGWlb6g4w=; b=piXO5mcB0n9ooF9kGeIrmd9b8l8asUoe3L9BKsc2YYk4iRedsXccVZF3eqoIapbzWi 6c6gcOiY5cjN9WCWCX24jXkGG3Airqlj/FtFkarDPWyarB30dm0qk37H/lwYWPTUt0fG zOCO8kMtQOnhnEmDxrmbdF5dcNwpzRJhvy5aervDQYZ423GQcNqaV93fwJxjbfzylMVh 5kz1SpvEaureUNxJeWMMc4vjcG61Oev2EIwAt8dOrvU7WntOXsO7rddYUEwyIFrKgGQC HqaQ/mXePotKwPs5MInr2bbeX6rcjodSyOJjMjZp5ioo22iAFMHlP1v6Qwgf5BHifNbL Q/+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782799245; x=1783404045; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=x2WnmB43eNouYPrpSpods0e3jWSS1paq4XSGWlb6g4w=; b=tQPZVQWMUyC7w41lr+3PESkvP6kXW07aAiYQ4vnBqQDwRW87i99FW80mRqGpxy0Reg 9A7Ql3SgGL1F3apSOU6IDHbgq//ZNlmrSy7xvE2V9ovT6h2UJcNdtVzmek202Gy1yggA n6BgLrxxbPmBT9LIqPRvcdzibH5Lem8cuLafS85IRYrIoVHrYZGleinq7QF2UX+tn5zW /g76aR6ikJfB/JwV3n0UEFyPXIE5Rq2EjutEppEtOpAamX/SwNrMjHmQzlNn8m6W9SFU +2UfQdzt7XCiMgeVR3d/MU1VOcjYcUcQlczzxTCbP1CDeSPS6wA6miGC1SLcHPT0Usuq 5Czg== X-Forwarded-Encrypted: i=1; AHgh+Rr+0J8S6MbmVvYnOPkCkWd02x7XpDPJdXwo3Q6EyXFqLkVZpNdbUvgDLn/YZdy4az9bqz58JlhkFN0XtU4=@vger.kernel.org X-Gm-Message-State: AOJu0YwLlJ4dV4EDgTOKQ4LIenZT3/ZbRaqX/P6IMjERzzsna1U0horH 5PE8p8/U7mwkQMBmiYgvFu4vDPnni6O1Va7kY9ltbllS8UJIbGr0ohAD X-Gm-Gg: AfdE7ckOzntDj66Z5bLSfvL8Yc0W3mNmDKIwsmfEI3dV/lUyRYQiQtt+KVzKy2ouQGP e5fBycidrjc7o4tv1aKcA6Nf5wrKsdeVci66xrtMSHlIYZWUmvbrAz51ry4twNGU8s4FKacDS76 XAHc0EW7Yo+Yikyd1Tp4zLeyUjJKZsDngWZXiF99em+63jc5OggdFg6EaD82328th5bww8ygQJG nb6+7BPRUppRKTQQRcvGnoCYa8JPseLiXZd8gjsB9Cl+zyFU4YqZaxF67TYmnGMDBrn1hH2fqZO csR4oHa6fVmM1sz8XRgblrz77gPNVuhVqS9M/XdLhqb/zY+Z7LHOf74nMYPE0rTbZha8tQjtuhh X7N1SQmuqmVFa7m2S85Q6co7PrIOfOEAZllFa/cnkYFOhC4xNtRJDU3VKBdhzMEu58qtfcHhVTE 8ecj4NWa0mt1SE6A1Ii5q8BeZzQdQuPffj X-Received: by 2002:a05:6a00:4143:b0:846:8b21:6304 with SMTP id d2e1a72fcca58-8479f118f9bmr1954287b3a.14.1782799245397; Mon, 29 Jun 2026 23:00:45 -0700 (PDT) Received: from haichao.tail057a43.ts.net ([2001:da8:e000:1206:1d46:59be:9028:62d2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847a03a6fd5sm1095685b3a.57.2026.06.29.23.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2026 23:00:44 -0700 (PDT) From: Ruoyu Wang To: Bernard Metzler Cc: Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Ruoyu Wang Subject: [PATCH v4] RDMA/siw: publish QP after initialization Date: Tue, 30 Jun 2026 14:00:40 +0800 Message-ID: <20260630060040.966461-1-ruoyuw560@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit siw_create_qp() currently calls siw_qp_add() before the queues, CQ pointers, state, completion, and device list entry are ready. A QPN lookup can therefore reach a QP that is still being constructed. Move siw_qp_add() to the end of siw_create_qp(), after QP initialization and before adding the QP to the siw device list. Fixes: f29dd55b0236 ("rdma/siw: queue pair methods") Suggested-by: Bernard Metzler Signed-off-by: Ruoyu Wang --- Changes in v4: - Move `if (udata->outlen < sizeof(uresp))` into the second `if (udata)` clause, right before ib_copy_to_udata() (Bernard Metzler). - Move INIT_LIST_HEAD(&qp->devq) to just before spin_lock_irqsave(), close to list_add_tail() where it logically belongs (Bernard Metzler). Changes in v3: - Move siw_qp_add()/xa_alloc() to the end of siw_create_qp(). - Drop the QPN reservation helper from v2. drivers/infiniband/sw/siw/siw_verbs.c | 57 ++++++++++++++++---------- 1 file changed, 35 insertions(+), 22 deletions(-) --- a/drivers/infiniband/sw/siw/siw_verbs.c +++ b/drivers/infiniband/sw/siw/siw_verbs.c @@ -316,6 +316,7 @@ struct siw_ucontext *uctx = rdma_udata_to_drv_context(udata, struct siw_ucontext, base_ucontext); + struct siw_uresp_create_qp uresp = {}; unsigned long flags; int num_sqe, num_rqe, rv = 0; size_t length; @@ -369,11 +370,6 @@ spin_lock_init(&qp->rq_lock); spin_lock_init(&qp->orq_lock); - rv = siw_qp_add(sdev, qp); - if (rv) - goto err_atomic; - - /* All queue indices are derived from modulo operations * on a free running 'get' (consumer) and 'put' (producer) * unsigned counter. Having queue sizes at power of two @@ -391,14 +387,14 @@ if (qp->sendq == NULL) { rv = -ENOMEM; - goto err_out_xa; + goto err_out; } if (attrs->sq_sig_type != IB_SIGNAL_REQ_WR) { if (attrs->sq_sig_type == IB_SIGNAL_ALL_WR) qp->attrs.flags |= SIW_SIGNAL_ALL_WR; else { rv = -EINVAL; - goto err_out_xa; + goto err_out; } } qp->pd = pd; @@ -424,7 +420,7 @@ if (qp->recvq == NULL) { rv = -ENOMEM; - goto err_out_xa; + goto err_out; } qp->attrs.rq_size = num_rqe; } @@ -439,11 +435,8 @@ qp->attrs.state = SIW_QP_STATE_IDLE; if (udata) { - struct siw_uresp_create_qp uresp = {}; - uresp.num_sqe = num_sqe; uresp.num_rqe = num_rqe; - uresp.qp_id = qp_id(qp); if (qp->sendq) { length = num_sqe * sizeof(struct siw_sqe); @@ -452,7 +445,7 @@ length, &uresp.sq_key); if (!qp->sq_entry) { rv = -ENOMEM; - goto err_out_xa; + goto err_out; } } @@ -464,9 +457,23 @@ if (!qp->rq_entry) { uresp.sq_key = SIW_INVAL_UOBJ_KEY; rv = -ENOMEM; - goto err_out_xa; + goto err_out; } } + } + qp->tx_cpu = siw_get_tx_cpu(sdev); + if (qp->tx_cpu < 0) { + rv = -EINVAL; + goto err_out; + } + init_completion(&qp->qp_free); + + rv = siw_qp_add(sdev, qp); + if (rv) + goto err_out_tx; + + if (udata) { + uresp.qp_id = qp_id(qp); if (udata->outlen < sizeof(uresp)) { rv = -EINVAL; @@ -476,22 +483,19 @@ if (rv) goto err_out_xa; } - qp->tx_cpu = siw_get_tx_cpu(sdev); - if (qp->tx_cpu < 0) { - rv = -EINVAL; - goto err_out_xa; - } + INIT_LIST_HEAD(&qp->devq); spin_lock_irqsave(&sdev->lock, flags); list_add_tail(&qp->devq, &sdev->qp_list); spin_unlock_irqrestore(&sdev->lock, flags); - init_completion(&qp->qp_free); - return 0; err_out_xa: xa_erase(&sdev->qp_xa, qp_id(qp)); +err_out_tx: + siw_put_tx_cpu(qp->tx_cpu); +err_out: if (uctx) { rdma_user_mmap_entry_remove(qp->sq_entry); rdma_user_mmap_entry_remove(qp->rq_entry); -- 2.51.0