From: Leon Romanovsky <leon@kernel.org>
To: Bart Van Assche <bvanassche@acm.org>
Cc: kensanya@163.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org,
target-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
TanZheng <tanzheng@kylinos.cn>
Subject: Re: [PATCH v2] RDMA/srpt: Fix srpt_alloc_rw_ctxs() unwind counters
Date: Thu, 16 Jul 2026 21:22:00 +0300 [thread overview]
Message-ID: <20260716182200.GA110966@unreal> (raw)
In-Reply-To: <e29b0d9f-177f-431d-9411-66057f536bf1@acm.org>
On Thu, Jul 16, 2026 at 10:37:39AM -0700, Bart Van Assche wrote:
> On 7/15/26 3:15 AM, kensanya@163.com wrote:
> > From: TanZheng <tanzheng@kylinos.cn>
> >
> > 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 <tanzheng@kylinos.cn>
> > ---
> > v2:
> > - After kfree(), set rw_ctxs to NULL instead of &s_rw_ctx
> > (Leon Romanovsky)
> >
> > drivers/infiniband/ulp/srpt/ib_srpt.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> > index f66cfd70c263..a9c4995af7a3 100644
> > --- a/drivers/infiniband/ulp/srpt/ib_srpt.c
> > +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> > @@ -1014,8 +1014,12 @@ static int srpt_alloc_rw_ctxs(struct srpt_send_ioctx *ioctx,
> > ctx->sg, ctx->nents, dir);
> > target_free_sgl(ctx->sg, ctx->nents);
> > }
> > - if (ioctx->rw_ctxs != &ioctx->s_rw_ctx)
> > + if (ioctx->rw_ctxs != &ioctx->s_rw_ctx) {
> > kfree(ioctx->rw_ctxs);
> > + ioctx->rw_ctxs = NULL;
> > + }
> > + ioctx->n_rw_ctx = 0;
> > + ioctx->n_rdma = 0;
> > return ret;
> > }
>
> The above looks wrong to me. In the error path ioctx->n_rw_ctx should be
> restored to the value it had at the start of the function instead of
> resetting it to zero.
Does this patch address your concerns?
https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git/commit/?h=wip/leon-for-next&id=f65ababb556ae0110d14294747dd6df5dcb8f597
Thanks
>
> Bart.
next prev parent reply other threads:[~2026-07-16 18:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 10:15 [PATCH v2] RDMA/srpt: Fix srpt_alloc_rw_ctxs() unwind counters kensanya
2026-07-16 8:53 ` Leon Romanovsky
2026-07-16 17:37 ` Bart Van Assche
2026-07-16 18:22 ` Leon Romanovsky [this message]
2026-07-16 18:24 ` Leon Romanovsky
2026-07-16 18:46 ` Bart Van Assche
2026-07-17 2:00 ` kensanya
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260716182200.GA110966@unreal \
--to=leon@kernel.org \
--cc=bvanassche@acm.org \
--cc=jgg@ziepe.ca \
--cc=kensanya@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=tanzheng@kylinos.cn \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox