Re: [PATCH] blk-mq: always clear rq->bio in blk_complete_request()
From: Michael Liang
Date: Thu Dec 18 2025 - 11:37:26 EST
On Thu, Dec 18, 2025 at 12:51:14AM -0800, Christoph Hellwig wrote:
> On Wed, Dec 17, 2025 at 10:18:53AM -0700, Michael Liang wrote:
> > Commit ab3e1d3bbab9 ("block: allow end_io based requests in the
> > completion batch handling") changed blk_complete_request() so that
> > rq->bio and rq->__data_len are only cleared when ->end_io is NULL.
> >
> > This conditional clearing is incorrect. The block layer guarantees that
> > all bios attached to the request are fully completed and released before
> > blk_complete_request() is called. Leaving rq->bio pointing to already
> > completed bios results in stale pointers that may be reused immediately
> > by a bioset allocator.
>
> Passthrough commands keep an extra reference on the bio and need the
> pointer to call blk_rq_unmap_user from the completion handler.
>
Are you referring to nvme_uring_cmd_io() and nvme_submit_user_cmd()?
>From what I see req->bio is cached in both cases and from the comment in
nvmme_uring_cmd_io() it actually expects req->bio is NULL after I/O
completion. Anyway my point is to me blk_complete_request() is functionally
similar to blk_update_request(), and in blk_update_request() req->bio is
updated and if all I/Os are completed it's cleared to NULL. So I think
it makes sense to keep the logic consistent here. But anyway let me know
if I miss something here.
Thanks,
Michael