* [PATCH v2 1/2] scsi: bsg: report synchronous data copyback failures
2026-10-23 16:23 [PATCH v2 0/2] scsi: bsg: report data copyback failures Yingjie Wang
@ 2026-10-23 16:23 ` Yingjie Wang
2026-10-23 16:23 ` [PATCH v2 2/2] scsi: bsg: report io_uring " Yingjie Wang
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Yingjie Wang @ 2026-10-23 16:23 UTC (permalink / raw)
To: linux-scsi@vger.kernel.org
Cc: Martin K . Petersen, James E . J . Bottomley, Bart Van Assche,
Jens Axboe, Yang Xiuwei, linux-kernel@vger.kernel.org,
Yingjie Wang, stable@vger.kernel.org
scsi_bsg_sg_io_fn() ignores the result of blk_rq_unmap_user(). For a
data-in command that uses a bounce buffer, unmapping copies the completed
data to userspace. If that copy fails, SG_IO can report success despite
the copyback failure.
Capture the unmap status. Preserve an earlier sense-buffer copy error and
otherwise return the data copyback error. This matches the error
precedence used by scsi_complete_sghdr_rq().
On x86_64, a virtio-scsi INQUIRY with an unaligned PROT_NONE destination
made ioctl() return 0 in 20/20 runs before this change and return -1 with
errno EFAULT in 20/20 runs afterward. Writable controls succeeded in
20/20 runs on both kernels.
Fixes: 10e8855b9451 ("bsg: add SG_IO to SG v4")
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
drivers/scsi/scsi_bsg.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/scsi_bsg.c b/drivers/scsi/scsi_bsg.c
index 5eec248a77a6b..37393a8dedd84 100644
--- a/drivers/scsi/scsi_bsg.c
+++ b/drivers/scsi/scsi_bsg.c
@@ -199,7 +199,7 @@ 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;
- int ret;
+ int ret, unmap_ret;
if (hdr->protocol != BSG_PROTOCOL_SCSI ||
hdr->subprotocol != BSG_SUB_PROTOCOL_SCSI_CMD)
@@ -273,7 +273,9 @@ static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
else
hdr->dout_resid = scmd->resid_len;
- blk_rq_unmap_user(bio);
+ unmap_ret = blk_rq_unmap_user(bio);
+ if (!ret)
+ ret = unmap_ret;
out_put_request:
blk_mq_free_request(rq);
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 2/2] scsi: bsg: report io_uring data copyback failures
2026-10-23 16:23 [PATCH v2 0/2] scsi: bsg: report data copyback failures Yingjie Wang
2026-10-23 16:23 ` [PATCH v2 1/2] scsi: bsg: report synchronous " Yingjie Wang
@ 2026-10-23 16:23 ` Yingjie Wang
2026-10-26 1:06 ` [PATCH v2 0/2] scsi: bsg: report " Yang Xiuwei
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Yingjie Wang @ 2026-10-23 16:23 UTC (permalink / raw)
To: linux-scsi@vger.kernel.org
Cc: Martin K . Petersen, James E . J . Bottomley, Bart Van Assche,
Jens Axboe, Yang Xiuwei, linux-kernel@vger.kernel.org,
Yingjie Wang, stable@vger.kernel.org
scsi_bsg_uring_task_cb() discards the result of blk_rq_unmap_user(). For a
data-in command that uses a bounce buffer, the task work can therefore
post a CQE with res == 0 despite a copyback failure.
Use the unmap result as the CQE status. A later sense-buffer copy failure
continues to take precedence.
On x86_64, a raw BSG INQUIRY into an unaligned anonymous PROT_NONE
mapping posted a CQE with res == 0 in 20/20 runs before this change and
res == -EFAULT in 20/20 runs afterward. Writable controls succeeded in
20/20 runs on both kernels.
Fixes: 7b6d3255e7f8 ("scsi: bsg: add io_uring passthrough handler")
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
drivers/scsi/scsi_bsg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi_bsg.c b/drivers/scsi/scsi_bsg.c
index 37393a8dedd84..e4a65d7a23742 100644
--- a/drivers/scsi/scsi_bsg.c
+++ b/drivers/scsi/scsi_bsg.c
@@ -41,7 +41,7 @@ static void scsi_bsg_uring_task_cb(struct io_tw_req tw_req, io_tw_token_t tw)
u8 sense_len_wr = 0;
if (pdu->bio)
- blk_rq_unmap_user(pdu->bio);
+ ret = blk_rq_unmap_user(pdu->bio);
if (scsi_status_is_check_condition(scmd->result)) {
driver_status = DRIVER_SENSE;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2 0/2] scsi: bsg: report data copyback failures
2026-10-23 16:23 [PATCH v2 0/2] scsi: bsg: report data copyback failures Yingjie Wang
2026-10-23 16:23 ` [PATCH v2 1/2] scsi: bsg: report synchronous " Yingjie Wang
2026-10-23 16:23 ` [PATCH v2 2/2] scsi: bsg: report io_uring " Yingjie Wang
@ 2026-10-26 1:06 ` Yang Xiuwei
2026-10-26 17:47 ` Bart Van Assche
2026-10-31 1:08 ` Martin K. Petersen
4 siblings, 0 replies; 6+ messages in thread
From: Yang Xiuwei @ 2026-10-26 1:06 UTC (permalink / raw)
To: x-professor
Cc: linux-scsi, mkp, James.Bottomley, bvanassche, axboe, linux-kernel,
Yang Xiuwei
Hi Yingjie,
On Fri, 23 Oct 2026, Yingjie Wang wrote:
> Propagate the unmap result while preserving existing sense-copy error
> precedence. The two fixes are independent and can be applied separately.
For the series:
Reviewed-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] scsi: bsg: report data copyback failures
2026-10-23 16:23 [PATCH v2 0/2] scsi: bsg: report data copyback failures Yingjie Wang
` (2 preceding siblings ...)
2026-10-26 1:06 ` [PATCH v2 0/2] scsi: bsg: report " Yang Xiuwei
@ 2026-10-26 17:47 ` Bart Van Assche
2026-10-31 1:08 ` Martin K. Petersen
4 siblings, 0 replies; 6+ messages in thread
From: Bart Van Assche @ 2026-10-26 17:47 UTC (permalink / raw)
To: Yingjie Wang, linux-scsi@vger.kernel.org
Cc: Martin K . Petersen, James E . J . Bottomley, Jens Axboe,
Yang Xiuwei, linux-kernel@vger.kernel.org
On 10/23/26 9:23 AM, Yingjie Wang wrote:
> [ ... ]
For the series:
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2 0/2] scsi: bsg: report data copyback failures
2026-10-23 16:23 [PATCH v2 0/2] scsi: bsg: report data copyback failures Yingjie Wang
` (3 preceding siblings ...)
2026-10-26 17:47 ` Bart Van Assche
@ 2026-10-31 1:08 ` Martin K. Petersen
4 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2026-10-31 1:08 UTC (permalink / raw)
To: Yingjie Wang
Cc: linux-scsi@vger.kernel.org, Martin K . Petersen,
James E . J . Bottomley, Bart Van Assche, Jens Axboe, Yang Xiuwei,
linux-kernel@vger.kernel.org
Yingjie,
> The synchronous and io_uring SCSI BSG completion paths discard the
> return value from blk_rq_unmap_user(). For data-in commands that use a
> bounce buffer, unmapping copies the completed data back to userspace.
> A failure during that copyback is then lost, so SG_IO can return
> success and io_uring can post a CQE with res == 0 despite the copyback
> failure.
Applied to 7.4/scsi-staging, thanks!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 6+ messages in thread