FAILED: patch "[PATCH] vhost-scsi: zero misaligned I/O bounce pages" failed to apply to 6.6-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 01c3a5fa6d641c93c7cef4fb25c5f12938316e18
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 01c3a5fa6d641c93c7cef4fb25c5f12938316e18 Mon Sep 17 00:00:00 2001
From: Shubham Antil <[email protected]>
Date: Tue, 20 Oct 2026 16:25:03 +0530
Subject: [PATCH] vhost-scsi: zero misaligned I/O bounce pages
The misaligned I/O fallback copies the full bounce scatterlist to the request buffer during completion. If a data-in command transfers less than requested, part of a newly allocated bounce page can remain unwritten.
Allocate bounce pages with __GFP_ZERO so all bytes copied during completion have a defined value. This path is already the slow fallback for misaligned I/O, so the added initialization cost is acceptable.
Found during an LLM-assisted source audit and validated with a QEMU/KVM vhost-scsi target using misaligned data-in commands.
Message-ID: <[email protected]>
--- drivers/vhost/scsi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/vhost/scsi.c +6 -1
@@ -944,7 +944,12 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter, }for_each_sgtable_sg (sg_table, sg, i) { - page =alloc_page (GFP_KERNEL ); +/* +* Completion copies the full bounce buffer, including bytes the +* target did not write. This is already the slow fallback for +* misaligned I/O, so zeroing is acceptable here. +*/ + page =alloc_page (GFP_KERNEL | __GFP_ZERO);if (!page) { ret = -ENOMEM ; goto err;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/3 vhost-scsi: Reduce mem use by moving upages to per queue
From: Mike Christie <[email protected]>
[ Upstream commit 4c1f3a7d74277903b290dd989cbd2ea8627fc925 ]
Each worker thread can process 1 command at a time so there's no need to allocate a upages array per cmd. This patch moves it to per queue. Even a small device with 128 cmds and 1 queue this brings mem use for the array from
2 MB = 8 bytes per page pointer * 2048 pointers * 128 cmds
to
16K = 8 bytes per pointer * 2048 * 1 queue
Message-Id: <[email protected]>
Stable-dep-of: 01c3a5fa6d64 ("vhost-scsi: zero misaligned I/O bounce pages")
--- drivers/vhost/scsi.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/vhost/scsi.c +10 -14
@@ -83,7 +83,6 @@ struct vhost_scsi_cmd {/* Pointer to the SGL formatted memory from virtio-scsi */ struct scatterlist *tvc_sgl;struct scatterlist *tvc_prot_sgl; -struct page **tvc_upages;/* Pointer to response header iovec */ struct iovec *tvc_resp_iov;/* Pointer to vhost_scsi for our device */
@@ -187,6 +186,7 @@ struct vhost_scsi_virtqueue {struct vhost_scsi_cmd *scsi_cmds;struct sbitmap scsi_tags;int max_cmds; +struct page **upages;struct vhost_work completion_work;struct llist_head completion_list;
@@ -613,7 +613,6 @@ vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,struct vhost_scsi_nexus *tv_nexus;struct scatterlist *sg, *prot_sg;struct iovec *tvc_resp_iov; -struct page **pages;int tag; tv_nexus = tpg->tpg_nexus;
@@ -631,12 +630,10 @@ vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg, cmd = &svq->scsi_cmds[tag]; sg = cmd->tvc_sgl; prot_sg = cmd->tvc_prot_sgl; - pages = cmd->tvc_upages; tvc_resp_iov = cmd->tvc_resp_iov;memset (cmd,0 ,sizeof (*cmd)); cmd->tvc_sgl = sg; cmd->tvc_prot_sgl = prot_sg; - cmd->tvc_upages = pages; cmd->tvc_se_cmd.map_tag = tag; cmd->tvc_tag = scsi_tag; cmd->tvc_lun = lun;
@@ -663,7 +660,9 @@ vhost_scsi_map_to_sgl(struct vhost_scsi_cmd *cmd, struct scatterlist *sgl, bool is_prot) { -struct page **pages = cmd->tvc_upages; +struct vhost_scsi_virtqueue *svq =container_of (cmd->tvc_vq, + struct vhost_scsi_virtqueue, vq); +struct page **pages = svq->upages;struct scatterlist *sg = sgl;ssize_t bytes, mapped_bytes;size_t offset, mapped_offset;
@@ -1596,11 +1595,11 @@ static void vhost_scsi_destroy_vq_cmds(struct vhost_virtqueue *vq)kfree (tv_cmd->tvc_sgl);kfree (tv_cmd->tvc_prot_sgl); -kfree (tv_cmd->tvc_upages);kfree (tv_cmd->tvc_resp_iov); }sbitmap_free (&svq->scsi_tags); +kfree (svq->upages);kfree (svq->scsi_cmds); svq->scsi_cmds =NULL ; }
@@ -1626,6 +1625,11 @@ static int vhost_scsi_setup_vq_cmds(struct vhost_virtqueue *vq, int max_cmds)return -ENOMEM ; } + svq->upages =kcalloc (VHOST_SCSI_PREALLOC_UPAGES ,sizeof (struct page *), +GFP_KERNEL ); +if (!svq->upages) + goto out; +for (i =0 ; i < max_cmds; i++) { tv_cmd = &svq->scsi_cmds[i];
@@ -1637,14 +1641,6 @@ static int vhost_scsi_setup_vq_cmds(struct vhost_virtqueue *vq, int max_cmds) goto out; } - tv_cmd->tvc_upages =kcalloc (VHOST_SCSI_PREALLOC_UPAGES , -sizeof (struct page *), -GFP_KERNEL ); -if (!tv_cmd->tvc_upages) { -pr_err ("Unable to allocate tv_cmd->tvc_upages\n" ); - goto out; - } - tv_cmd->tvc_resp_iov =kcalloc (UIO_MAXIOV ,sizeof (struct iovec ),GFP_KERNEL );
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 vhost-scsi: Allocate T10 PI structs only when enabled
From: Mike Christie <[email protected]>
[ Upstream commit bf2d650391be508dd8b5e188b65ed32300cf3489 ]
T10 PI is not a widely used feature. This has us only allocate the structs for it if the feature has been enabled. For a common small setup where you have 1 virtqueue and 128 commands per queue, this saves:
8MB = 32 bytes per sg * 2048 entries * 128 commands
per vhost-scsi device.
Message-Id: <[email protected]>
Stable-dep-of: 01c3a5fa6d64 ("vhost-scsi: zero misaligned I/O bounce pages")
--- drivers/vhost/scsi.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/vhost/scsi.c +8 -6
@@ -1649,12 +1649,14 @@ static int vhost_scsi_setup_vq_cmds(struct vhost_virtqueue *vq, int max_cmds) goto out; } - tv_cmd->tvc_prot_sgl =kcalloc (VHOST_SCSI_PREALLOC_PROT_SGLS , -sizeof (struct scatterlist ), -GFP_KERNEL ); -if (!tv_cmd->tvc_prot_sgl) { -pr_err ("Unable to allocate tv_cmd->tvc_prot_sgl\n" ); - goto out; +if (vhost_has_feature (vq,VIRTIO_SCSI_F_T10_PI )) { + tv_cmd->tvc_prot_sgl =kcalloc (VHOST_SCSI_PREALLOC_PROT_SGLS , +sizeof (struct scatterlist ), +GFP_KERNEL ); +if (!tv_cmd->tvc_prot_sgl) { +pr_err ("Unable to allocate tv_cmd->tvc_prot_sgl\n" ); + goto out; + } } }return 0 ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 vhost-scsi: zero misaligned I/O bounce pages
In reply to Sasha LevinFrom: Shubham Antil <[email protected]>
[ Upstream commit 01c3a5fa6d641c93c7cef4fb25c5f12938316e18 ]
The misaligned I/O fallback copies the full bounce scatterlist to the request buffer during completion. If a data-in command transfers less than requested, part of a newly allocated bounce page can remain unwritten.
Allocate bounce pages with __GFP_ZERO so all bytes copied during completion have a defined value. This path is already the slow fallback for misaligned I/O, so the added initialization cost is acceptable.
Found during an LLM-assisted source audit and validated with a QEMU/KVM vhost-scsi target using misaligned data-in commands.
Message-ID: <[email protected]>
--- drivers/vhost/scsi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/vhost/scsi.c +6 -1
@@ -760,7 +760,12 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter, }for (i =0 ; i < sg_count; i++) { - page =alloc_page (GFP_KERNEL ); +/* +* Completion copies the full bounce buffer, including bytes the +* target did not write. This is already the slow fallback for +* misaligned I/O, so zeroing is acceptable here. +*/ + page =alloc_page (GFP_KERNEL | __GFP_ZERO);if (!page) { i--; ret = -ENOMEM ;
Signature · 1 line
2.53.0