From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C8043451C8; Sat, 12 Sep 2026 19:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242656; cv=none; b=uudpigjqUeVSMsrGYOMcTMsHfdHBUIWf74PuNOLCr9k1yvxKm5wp5KFGKA5zDdWB6MCWeJUeOBuDRjA8lep4bN6qr4JE4R7VTVw+IWYeFl/Z38VRz6OUzHUp2jyypL2yIcIQhUAq2Tlz0tV853Vu3r6xtjIVxPmbtxzYBOI2i3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242656; c=relaxed/simple; bh=1Ht1LWZ9EWNqukbUd5AMgM9J4n/Qe0oywHQKyPTlhXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ICKYEOHw/OLsDHqNzCs8gAF/PqnZsdsXCVCGGEnyNX79giksY3UDWH+kWjsvWsnJe6EHj30WVjfEejNgw7R4CKuEq6RSpQ/3jze5PHZuPDVEzgNaUl3z7J9uRHzPipFjv4IqTp17GgSwp2EHwVP7BQaKOvWrHVjEnVdkrvjJEGA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Gn4Y/HKW; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Gn4Y/HKW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 266811F000FF; Sat, 12 Sep 2026 19:50:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789242654; bh=hZMPoANQlV2HG71aeeDlDM7mGMKVazjz/PowDQI3T84=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Gn4Y/HKWGJR2BjApPNsTQ1+gbhU+GNAE5eP9dxNEiOBp4hRWE1sRWJ6HJlNqoKM1o DZhVcR1hDrTWyKt79f679WkOQX5Qz8Nddcc7vElPhq+KmGApnI2KRTDaiwgTTqrPJs h7oTY9bFBGHO1VqDBi5NhajXvHORTIqJMKJkvYlM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, TanZheng , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.10 481/798] RDMA/srpt: Fix srpt_alloc_rw_ctxs() unwind counters Date: Sat, 12 Sep 2026 09:01:49 +0200 Message-ID: <20260912065528.166902854@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065516.948645775@linuxfoundation.org> References: <20260912065516.948645775@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: TanZheng [ Upstream commit b38f98e176050850f41bb6415f3a71400056623e ] When srpt_alloc_rw_ctxs() fails partway through a multi-buffer indirect descriptor, the unwind path destroys RDMA contexts but leaves stale n_rw_ctx and n_rdma values (and a dangling rw_ctxs pointer). Later sq_wr_avail accounting in srpt_queue_response() or srpt_write_pending() can then subtract the wrong number of send queue credits. Reset the counters and clear rw_ctxs after freeing the heap allocation before returning an error. Fixes: b99f8e4d7bcd ("IB/srpt: convert to the generic RDMA READ/WRITE API") Signed-off-by: TanZheng Link: https://patch.msgid.link/20260715101550.45345-1-kensanya@163.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/srpt/ib_srpt.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 5fce4cdb88eb4..d2cf5b9590fac 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -900,6 +900,7 @@ static int srpt_alloc_rw_ctxs(struct srpt_send_ioctx *ioctx, struct srpt_rdma_ch *ch = ioctx->ch; struct scatterlist *prev = NULL; unsigned prev_nents; + u8 n_rdma, n_rw_ctx; int ret, i; if (nbufs == 1) { @@ -911,6 +912,9 @@ static int srpt_alloc_rw_ctxs(struct srpt_send_ioctx *ioctx, return -ENOMEM; } + n_rw_ctx = ioctx->n_rw_ctx; + n_rdma = ioctx->n_rdma; + for (i = ioctx->n_rw_ctx; i < nbufs; i++, db++) { struct srpt_rw_ctx *ctx = &ioctx->rw_ctxs[i]; u64 remote_addr = be64_to_cpu(db->va); @@ -957,6 +961,9 @@ static int srpt_alloc_rw_ctxs(struct srpt_send_ioctx *ioctx, } if (ioctx->rw_ctxs != &ioctx->s_rw_ctx) kfree(ioctx->rw_ctxs); + ioctx->rw_ctxs = NULL; + ioctx->n_rw_ctx = n_rw_ctx; + ioctx->n_rdma = n_rdma; return ret; } -- 2.53.0