Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH v2] vhost-scsi: serialize completion notification with callfd updates
@ 2026-08-06  6:51 Jia Jia
  2026-08-12 18:48 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Jia Jia @ 2026-08-06  6:51 UTC (permalink / raw)
  To: mst, jasowang, michael.christie
  Cc: pbonzini, stefanha, eperezma, virtualization, kvm, netdev,
	linux-kernel

vhost_scsi_complete_cmd_work() drops the virtqueue mutex before calling
vhost_signal(). VHOST_SET_VRING_CALL replaces call_ctx.ctx and releases the
old eventfd_ctx while holding the same mutex. vhost_signal() reads the call
context before and after vhost_notify(), so a concurrent callfd update can
make it signal a freed context or NULL.

KASAN reported the use through:

	eventfd_signal_mask
	vhost_signal
	vhost_scsi_complete_cmd_work

The context was released through:

	eventfd_ctx_put
	vhost_vring_ioctl
	vhost_scsi_ioctl

Keep the mutex held through vhost_signal() so completion notification and
callfd updates are serialized.

Fixes: 057cbf49a1f0 ("tcm_vhost: Initial merge for vhost level target fabric driver")
Link: https://lore.kernel.org/r/20260720085306.1519294-1-physicalmtea@gmail.com
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
Changes since RFC:
- Send as a non-RFC v2.
- Add Fixes and Link tags.

 drivers/vhost/scsi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 9a1253b9d8c5..7f46bc0de3c2 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -735,10 +735,9 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
 		vhost_scsi_release_cmd_res(se_cmd);
 	}
 
-	mutex_unlock(&svq->vq.mutex);
-
 	if (signal)
 		vhost_signal(&svq->vs->dev, &svq->vq);
+	mutex_unlock(&svq->vq.mutex);
 }
 
 static struct vhost_scsi_cmd *
-- 
2.34.1

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

* Re: [PATCH v2] vhost-scsi: serialize completion notification with callfd updates
  2026-08-06  6:51 [PATCH v2] vhost-scsi: serialize completion notification with callfd updates Jia Jia
@ 2026-08-12 18:48 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2026-08-12 18:48 UTC (permalink / raw)
  To: Jia Jia
  Cc: mst, jasowang, michael.christie, pbonzini, eperezma,
	virtualization, kvm, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1207 bytes --]

On Thu, Aug 06, 2026 at 02:51:43PM +0800, Jia Jia wrote:
> vhost_scsi_complete_cmd_work() drops the virtqueue mutex before calling
> vhost_signal(). VHOST_SET_VRING_CALL replaces call_ctx.ctx and releases the
> old eventfd_ctx while holding the same mutex. vhost_signal() reads the call
> context before and after vhost_notify(), so a concurrent callfd update can
> make it signal a freed context or NULL.
> 
> KASAN reported the use through:
> 
> 	eventfd_signal_mask
> 	vhost_signal
> 	vhost_scsi_complete_cmd_work
> 
> The context was released through:
> 
> 	eventfd_ctx_put
> 	vhost_vring_ioctl
> 	vhost_scsi_ioctl
> 
> Keep the mutex held through vhost_signal() so completion notification and
> callfd updates are serialized.
> 
> Fixes: 057cbf49a1f0 ("tcm_vhost: Initial merge for vhost level target fabric driver")
> Link: https://lore.kernel.org/r/20260720085306.1519294-1-physicalmtea@gmail.com
> Signed-off-by: Jia Jia <physicalmtea@gmail.com>
> ---
> Changes since RFC:
> - Send as a non-RFC v2.
> - Add Fixes and Link tags.
> 
>  drivers/vhost/scsi.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2026-08-12 18:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06  6:51 [PATCH v2] vhost-scsi: serialize completion notification with callfd updates Jia Jia
2026-08-12 18:48 ` Stefan Hajnoczi

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