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 7CEB8372EDE; Sat, 12 Sep 2026 07:47:29 +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=1789199250; cv=none; b=Dxogfo6pAhnw1pRaml8fKBlC6gIqnLQlHkAPJ6QhbVHzYgIuk8LrNBBVtnaCNynYHc91mM+9fzrUrMuSHXmFG4WXoskmQoC7Jn90a4Xi15aNNGnFVsp8nsrwK6vchjw1zyGXiKg1mDiinshOkawDtuDM4cQa1KfZdmMmZwivTes= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789199250; c=relaxed/simple; bh=OXMj9DL0TbRmFETBNFTfytUtgHSRULbldD9O2aHheXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NQaQeiYkMSn8bx5YFwJRCdzNKvM095cutEyxMbTo69tp8wxdC5l3PmYnYA0P5ci6m7lXSFLkSezsePTS5RuWlNozmUoEHInOlj2sVdL/qEkeo/9sK4B9zREHMeVzho3F5jVDM9MbTbaHyAVF8hsUxWui9Fg3Zb23kfK/IpuYS70= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NmxmKJSY; 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="NmxmKJSY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E89A11F000FF; Sat, 12 Sep 2026 07:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789199249; bh=O/i8Set42fbWGZTkvXfOSlqYIO3/RlHJUUUrg7bn1Ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NmxmKJSYo1c9GR/XJ+Rr8Ksb1IVFEUqSaqM0DVYKUMRlyLD8JWKhZY44mIKS5DRNr pGyk6E5+YUJ0URvzMKbKTk+0XSZSLlx3UqzNW21ReymnXd3Xc4z9D2OzW1kwK+d3al bOb035iVy3pwZj/GLFD5zH3aMTu8b0J30aojPDhc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, TanZheng , Leon Romanovsky , Sasha Levin Subject: [PATCH 7.2 0544/1815] RDMA/srpt: Fix srpt_alloc_rw_ctxs() unwind counters Date: Sat, 12 Sep 2026 08:38:14 +0200 Message-ID: <20260912065701.653701830@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@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 7.2-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 f66cfd70c2636..7471dfee50dbb 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -960,6 +960,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) { @@ -970,6 +971,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); @@ -1016,6 +1020,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