mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yingjie Wang <x-professor@outlook.com>
To: "Martin K . Petersen" <mkp@kernel.org>,
	"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
	Jens Axboe <axboe@kernel.dk>
Cc: Yingjie Wang <x-professor@outlook.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	Bart Van Assche <bvanassche@acm.org>,
	Yang Xiuwei <yangxiuwei@kylinos.cn>,
	James Houghton <jthoughton@google.com>,
	Pavel Begunkov <asml.silence@gmail.com>,
	"io-uring@vger.kernel.org" <io-uring@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH v3 1/6] scsi: core: release SG_IO request before user copyback
Date: Sat, 7 Nov 2026 09:50:23 +0000	[thread overview]
Message-ID: <a7a066c901218b5dde6586943b69947dbd9ab014.1794045010.git.x-professor@outlook.com> (raw)
In-Reply-To: <cover.1794045010.git.x-professor@outlook.com>

From: Yingjie Wang <x-professor@outlook.com>

The block-device SG_IO path retains its completed request while copying
sense data and unmapping the user data buffer. Either operation can fault.
If the fault needs I/O from the same queue and completed requests retain
the available tags, the nested I/O cannot make progress.

Fill the kernel-resident output header and save the bounded sense data
before releasing the request. Then perform the user copies and unmap the
original BIO chain, preserving the existing sense-copy error precedence.
The saved mapping owns its BIO references independently of the request.

The fixed request pool was introduced by scsi-mq; the later move of this
ioctl implementation into drivers/scsi did not introduce the dependency.

Fixes: d285203cf647 ("scsi: add support for a blk-mq based I/O path.")
Link: https://lore.kernel.org/r/20261022.scsi-copyback-review.31b8d6a70f4c@outlook.com
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
 drivers/scsi/scsi_ioctl.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index bf049d9cb719..b588aa9059e3 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -398,6 +398,8 @@ static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
 		struct bio *bio)
 {
 	struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
+	u8 sense_buffer[SCSI_SENSE_BUFFERSIZE];
+	unsigned int sense_len = 0;
 	int r, ret = 0;
 
 	/*
@@ -417,10 +419,16 @@ static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
 	hdr->sb_len_wr = 0;
 
 	if (scmd->sense_len && hdr->sbp) {
-		int len = min((unsigned int) hdr->mx_sb_len, scmd->sense_len);
+		sense_len = min3(hdr->mx_sb_len, scmd->sense_len,
+				 sizeof(sense_buffer));
+		memcpy(sense_buffer, scmd->sense_buffer, sense_len);
+	}
+
+	blk_mq_free_request(rq);
 
-		if (!copy_to_user(hdr->sbp, scmd->sense_buffer, len))
-			hdr->sb_len_wr = len;
+	if (sense_len) {
+		if (!copy_to_user(hdr->sbp, sense_buffer, sense_len))
+			hdr->sb_len_wr = sense_len;
 		else
 			ret = -EFAULT;
 	}
@@ -493,7 +501,7 @@ static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr,
 
 	hdr->duration = jiffies_to_msecs(jiffies - start_time);
 
-	ret = scsi_complete_sghdr_rq(rq, hdr, bio);
+	return scsi_complete_sghdr_rq(rq, hdr, bio);
 
 out_put_request:
 	blk_mq_free_request(rq);
-- 
2.43.0


  reply	other threads:[~2026-11-07  9:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07  9:50 [RFC PATCH v3 0/6] scsi: release completed passthrough requests " Yingjie Wang
2026-11-07  9:50 ` Yingjie Wang [this message]
2026-11-07  9:50 ` [RFC PATCH v3 2/6] scsi: core: release legacy ioctl request " Yingjie Wang
2026-11-07  9:50 ` [RFC PATCH v3 3/6] scsi: sr: release CDDA " Yingjie Wang
2026-11-07  9:50 ` [RFC PATCH v3 4/6] scsi: bsg: release synchronous " Yingjie Wang
2026-11-07  9:50 ` [RFC PATCH v3 5/6] io_uring/cmd: allow reusing SQE storage for completion data Yingjie Wang
2026-11-09  2:51   ` Yang Xiuwei
2026-11-10 12:24     ` Yingjie Wang
2026-11-11  0:36       ` Yang Xiuwei
2026-11-07  9:50 ` [RFC PATCH v3 6/6] scsi: bsg: release io_uring requests from end-I/O Yingjie Wang

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=a7a066c901218b5dde6586943b69947dbd9ab014.1794045010.git.x-professor@outlook.com \
    --to=x-professor@outlook.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=io-uring@vger.kernel.org \
    --cc=jthoughton@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --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

all inboxes | Powered by JetHome®