Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yang Xiuwei" <yangxiuwei@kylinos.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 2/2] scsi: bsg: release io_uring requests from end-I/O
Date: Thu, 19 Nov 2026 03:44:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-222409@kernel.org> (raw)
In-Reply-To: <20261119031751.3471968-3-yangxiuwei@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] scsi: bsg: IRQ-unsafe pool->lock in scsi_bsg_uring_cmd_done()
--

commit 90faa38e4aa3fb704f223fae5379944821b9aa28
Author: Yang Xiuwei <yangxiuwei@kylinos.cn>

scsi: bsg: release io_uring requests from end-I/O

This commit snapshots the SCSI completion status and sense data in the
request end-I/O callback using the per-device BSG completion buffer pool
and returns RQ_END_IO_FREE so the request tag is released before task work
runs.

> diff --git a/drivers/scsi/scsi_bsg.c b/drivers/scsi/scsi_bsg.c
> index e4a65d7a23742..739778244f420 100644
> --- a/drivers/scsi/scsi_bsg.c
> +++ b/drivers/scsi/scsi_bsg.c
[ ... ]
> @@ -70,9 +83,38 @@ static enum rq_end_io_ret scsi_bsg_uring_cmd_done(struct request *req,
>  						  const struct io_comp_batch *iocb)
>  {
>  	struct io_uring_cmd *ioucmd = req->end_io_data;
> +	struct scsi_bsg_uring_cmd_pdu *pdu = scsi_bsg_uring_cmd_pdu(ioucmd);
> +	struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
> +	u8 driver_status = 0;
> +	u8 sense_len = 0;
> +
> +	if (scsi_status_is_check_condition(scmd->result)) {
> +		driver_status = DRIVER_SENSE;
> +		if (pdu->response_addr) {
> +			sense_len = min_t(unsigned int, pdu->max_response_len,
> +					  scmd->sense_len);
> +			if (sense_len)
> +				memcpy(pdu->sense_buffer, scmd->sense_buffer,
> +				       sense_len);
> +		}
> +	}
> +
> +	pdu->res2 = bsg_scsi_res2_build(status_byte(scmd->result),
> +					driver_status, host_byte(scmd->result),
> +					sense_len, scmd->resid_len);
> +
> +	/*
> +	 * No sense to deliver: return the pool buffer now so other commands
> +	 * can use it while this one waits for task work.  Task work only puts
> +	 * when sense_buffer is still set.
> +	 */
> +	if (!sense_len && pdu->sense_buffer) {
> +		bsg_uring_cmd_put_completion_buf(ioucmd, pdu->sense_buffer);
> +		pdu->sense_buffer = NULL;
> +	}

[Severity: High]
Can calling bsg_uring_cmd_put_completion_buf() from
scsi_bsg_uring_cmd_done() self-deadlock on pool->lock?

Both bsg_uring_cmd_get_completion_buf() and
bsg_uring_cmd_put_completion_buf() acquire pool->lock with plain
spin_lock().  scsi_bsg_uring_cmd() and scsi_bsg_uring_task_cb() call
them from process context with interrupts and softirqs enabled, while
scsi_bsg_uring_cmd_done() is the req->end_io callback and runs in
hardirq or BLOCK_SOFTIRQ context:

scsi_bsg_uring_cmd()
  bsg_uring_cmd_get_completion_buf()
    spin_lock(&pool->lock)
    <softirq / hardirq>
      ...
        scsi_bsg_uring_cmd_done()
          bsg_uring_cmd_put_completion_buf()
            spin_lock(&pool->lock)  <-- spins forever

If a command that provided a response buffer completes without check
condition on the same CPU while process context holds pool->lock, the
CPU deadlocks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119031751.3471968-2-yangxiuwei@kylinos.cn?part=2

      reply	other threads:[~2026-11-19  3:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 15:37 [PATCH v4 0/2] scsi: bsg: release io_uring requests from end-I/O Yingjie Wang
2026-11-18 15:37 ` [PATCH v4 1/2] block: bsg: add a per-file pool of uring_cmd completion buffers Yingjie Wang
2026-11-18 15:37 ` [PATCH v4 2/2] scsi: bsg: release io_uring requests from end-I/O Yingjie Wang
2026-11-19  3:17 ` [PATCH v4 0/2] " Yang Xiuwei
2026-11-19  3:17   ` [PATCH 1/2] block: bsg: add a per-device pool of uring_cmd completion buffers Yang Xiuwei
2026-11-19  3:28     ` sashiko-bot
2026-11-19  4:02     ` Yang Xiuwei
2026-11-19  3:17   ` [PATCH 2/2] scsi: bsg: release io_uring requests from end-I/O Yang Xiuwei
2026-11-19  3:44     ` sashiko-bot [this message]

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=sashiko-outbox-222409@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yangxiuwei@kylinos.cn \
    /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