Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH v2] vhost-scsi: flush backend after device ioctls
  2026-07-21  7:36 [PATCH] " Jia Jia
@ 2026-07-24  6:09 ` Jia Jia
  2026-08-04  3:22   ` Michael S. Tsirkin
  0 siblings, 1 reply; 4+ messages in thread
From: Jia Jia @ 2026-07-24  6:09 UTC (permalink / raw)
  To: michael.christie, mst, jasowangio
  Cc: pbonzini, stefanha, eperezma, virtualization, kvm

vhost-scsi translates guest response descriptors into userspace iovecs
when commands are submitted.  Target-core completes those commands
asynchronously, so VHOST_SET_MEM_TABLE can replace the memory table while
an in-flight command still retains response iovecs translated through the
old table.

If the old mapping is reused after VHOST_SET_MEM_TABLE returns, command
completion can write the response to an unrelated userspace object.

Flush the vhost-scsi backend after vhost_dev_ioctl() handles a device
ioctl.  This waits for in-flight commands that can still use the old
response iovecs before the ioctl returns.

Changes in v2:
- Shorten the changelog and remove investigation details.

Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
 drivers/vhost/scsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 9a1253b9d8c5..c3e8f1a0b2d4 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -2424,10 +2424,11 @@ vhost_scsi_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
 	default:
 		mutex_lock(&vs->dev.mutex);
 		r = vhost_dev_ioctl(&vs->dev, ioctl, argp);
-		/* TODO: flush backend after dev ioctl. */
 		if (r == -ENOIOCTLCMD)
 			r = vhost_vring_ioctl(&vs->dev, ioctl, argp);
+		else
+			vhost_scsi_flush(vs);
 		mutex_unlock(&vs->dev.mutex);
 		return r;
 	}
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] vhost-scsi: flush backend after device ioctls
  2026-07-24  6:09 ` [PATCH v2] " Jia Jia
@ 2026-08-04  3:22   ` Michael S. Tsirkin
  2026-08-04  4:06     ` Jia Jia
  0 siblings, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2026-08-04  3:22 UTC (permalink / raw)
  To: Jia Jia
  Cc: michael.christie, jasowangio, pbonzini, stefanha, eperezma,
	virtualization, kvm

On Fri, Jul 24, 2026 at 02:09:19PM +0800, Jia Jia wrote:
> vhost-scsi translates guest response descriptors into userspace iovecs
> when commands are submitted.  Target-core completes those commands
> asynchronously, so VHOST_SET_MEM_TABLE can replace the memory table while
> an in-flight command still retains response iovecs translated through the
> old table.
> 
> If the old mapping is reused after VHOST_SET_MEM_TABLE returns, command
> completion can write the response to an unrelated userspace object.
> 
> Flush the vhost-scsi backend after vhost_dev_ioctl() handles a device
> ioctl.  This waits for in-flight commands that can still use the old
> response iovecs before the ioctl returns.
> 
> Changes in v2:
> - Shorten the changelog and remove investigation details.

fyi changelog should go after ---


can you pls answer mike's question on v1?
Also pls do not post v2 as response to v1

> Signed-off-by: Jia Jia <physicalmtea@gmail.com>
> ---
>  drivers/vhost/scsi.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index 9a1253b9d8c5..c3e8f1a0b2d4 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c
> @@ -2424,10 +2424,11 @@ vhost_scsi_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
>  	default:
>  		mutex_lock(&vs->dev.mutex);
>  		r = vhost_dev_ioctl(&vs->dev, ioctl, argp);
> -		/* TODO: flush backend after dev ioctl. */
>  		if (r == -ENOIOCTLCMD)
>  			r = vhost_vring_ioctl(&vs->dev, ioctl, argp);
> +		else
> +			vhost_scsi_flush(vs);
>  		mutex_unlock(&vs->dev.mutex);
>  		return r;
>  	}
>  }
> -- 
> 2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] vhost-scsi: flush backend after device ioctls
  2026-08-04  3:22   ` Michael S. Tsirkin
@ 2026-08-04  4:06     ` Jia Jia
  0 siblings, 0 replies; 4+ messages in thread
From: Jia Jia @ 2026-08-04  4:06 UTC (permalink / raw)
  To: mst
  Cc: michael.christie, jasowangio, pbonzoni, stefanha, eperezma,
	virtualization, kvm, pbonzini

If you mean Mike's question on v1, I already answered it in:

<20260723105451.1563439-1-physicalmtea@gmail.com>

Thanks for the reminder. I'll put the changelog after `---` and post the next version as a new thread.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] vhost-scsi: flush backend after device ioctls
@ 2026-08-04  6:06 Jia Jia
  0 siblings, 0 replies; 4+ messages in thread
From: Jia Jia @ 2026-08-04  6:06 UTC (permalink / raw)
  To: michael.christie, mst, jasowangio
  Cc: pbonzoni, stefanha, eperezma, virtualization, kvm

vhost-scsi translates guest response descriptors into userspace iovecs
when commands are submitted.  Target-core completes those commands
asynchronously, so VHOST_SET_MEM_TABLE can replace the memory table while
an in-flight command still retains response iovecs translated through the
old table.

If the old mapping is reused after VHOST_SET_MEM_TABLE returns, command
completion can write the response to an unrelated userspace object.

Flush the vhost-scsi backend after vhost_dev_ioctl() handles a device
ioctl.  This waits for in-flight commands that can still use the old
response iovecs before the ioctl returns.

Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
Changes in v2:
- Shorten the changelog and remove investigation details.

 drivers/vhost/scsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 9a1253b9d8c5..c3e8f1a0b2d4 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -2424,10 +2424,11 @@ vhost_scsi_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
 	default:
 		mutex_lock(&vs->dev.mutex);
 		r = vhost_dev_ioctl(&vs->dev, ioctl, argp);
-		/* TODO: flush backend after dev ioctl. */
 		if (r == -ENOIOCTLCMD)
 			r = vhost_vring_ioctl(&vs->dev, ioctl, argp);
+		else
+			vhost_scsi_flush(vs);
 		mutex_unlock(&vs->dev.mutex);
 		return r;
 	}
 }
-- 
2.43.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-04  6:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-04  6:06 [PATCH v2] vhost-scsi: flush backend after device ioctls Jia Jia
  -- strict thread matches above, loose matches on Subject: below --
2026-07-21  7:36 [PATCH] " Jia Jia
2026-07-24  6:09 ` [PATCH v2] " Jia Jia
2026-08-04  3:22   ` Michael S. Tsirkin
2026-08-04  4:06     ` Jia Jia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox