From: Yingjie Wang <x-professor@outlook.com>
To: "Martin K. Petersen" <mkp@kernel.org>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.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>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH v5 4/4] scsi: bsg: Release synchronous request before user copyback
Date: Sat, 21 Nov 2026 08:27:23 +0000 [thread overview]
Message-ID: <scsi-sync-v5.1795249365940711260.4.x-professor@outlook.com> (raw)
In-Reply-To: <scsi-sync-v5.1795249365940711260.0.x-professor@outlook.com>
The synchronous SCSI BSG ioctl copies sense data and unmaps its user
data buffer while retaining the completed request. Copyback can fault
and need I/O from the same queue, which cannot progress when completed
requests retain the available tags.
Fill the kernel-resident output fields and save the bounded sense data
before releasing the request. Perform both user copies afterward, using
the original BIO chain saved at mapping time. Preserve the copyback
error precedence established by commit a52f2ad45726 ("scsi: bsg: Report
synchronous data copyback failures").
The SG_IO v4 implementation predates scsi-mq. The finite number of request
tags introduced by scsi-mq creates this dependency; moving the callback
into scsi_bsg.c did not change its ownership ordering.
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>
---
No functional changes from v4. Clarify the tag dependency and name the
existing copyback-error fix.
drivers/scsi/scsi_bsg.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/scsi/scsi_bsg.c b/drivers/scsi/scsi_bsg.c
index 3cf1caad02f7..c17cad798326 100644
--- a/drivers/scsi/scsi_bsg.c
+++ b/drivers/scsi/scsi_bsg.c
@@ -207,6 +207,8 @@ static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
struct scsi_cmnd *scmd;
struct request *rq;
struct bio *bio;
+ u8 sense_buffer[SCSI_SENSE_BUFFERSIZE];
+ unsigned int sense_len = 0;
int ret, unmap_ret;
if (hdr->protocol != BSG_PROTOCOL_SCSI ||
@@ -266,14 +268,9 @@ static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
hdr->response_len = 0;
if (scmd->sense_len && hdr->response) {
- int len = min_t(unsigned int, hdr->max_response_len,
- scmd->sense_len);
-
- if (copy_to_user(uptr64(hdr->response), scmd->sense_buffer,
- len))
- ret = -EFAULT;
- else
- hdr->response_len = len;
+ sense_len = min3(hdr->max_response_len, scmd->sense_len,
+ sizeof(sense_buffer));
+ memcpy(sense_buffer, scmd->sense_buffer, sense_len);
}
if (rq_data_dir(rq) == READ)
@@ -281,9 +278,19 @@ static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
else
hdr->dout_resid = scmd->resid_len;
+ blk_mq_free_request(rq);
+
+ if (sense_len) {
+ if (copy_to_user(uptr64(hdr->response), sense_buffer, sense_len))
+ ret = -EFAULT;
+ else
+ hdr->response_len = sense_len;
+ }
+
unmap_ret = blk_rq_unmap_user(bio);
if (!ret)
ret = unmap_ret;
+ return ret;
out_put_request:
blk_mq_free_request(rq);
--
2.43.0
prev parent reply other threads:[~2026-11-21 8:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 8:27 [PATCH v5 0/4] scsi: Release completed passthrough requests " Yingjie Wang
2026-11-21 8:27 ` [PATCH v5 1/4] scsi: core: Release SG_IO request " Yingjie Wang
2026-11-21 8:27 ` [PATCH v5 2/4] scsi: core: Release legacy ioctl " Yingjie Wang
2026-11-21 8:27 ` [PATCH v5 3/4] scsi: sr: Release CDDA " Yingjie Wang
2026-11-21 8:27 ` Yingjie Wang [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=scsi-sync-v5.1795249365940711260.4.x-professor@outlook.com \
--to=x-professor@outlook.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=bvanassche@acm.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®