[PATCH kvmtool v2] virtio: 9p: Order used ring updates before notifications
Xie Bo <[email protected]> Mon, 3 Aug 2026 09:32:26 +0800
| Newsgroups | org.kernel.vger.kvm |
|---|---|
| Message-ID | <[email protected]> |
virtio_p9_do_io() signals the guest immediately after adding each
request to the used ring. Unlike the block and net backends, it bypasses
virtio_queue__should_signal(), which provides the full memory barrier
needed between publishing used->idx and injecting the interrupt.
On weakly ordered architectures, the guest can therefore handle the
interrupt before the updated used->idx becomes visible. If it observes
the old index and goes back to sleep, the completed request can remain
stuck indefinitely because no further interrupt is generated.
This was observed on RISC-V with two 9p RPCs blocked while the host
used->idx was two entries ahead of the guest's last_used_idx.
Process all available requests first, then use
virtio_queue__should_signal() before notifying the guest. Besides
providing the required ordering, this also honors the driver's
notification suppression request.
Fixes: 1c7850f95903 ("kvm tools: Add virtio-9p")
Signed-off-by: Xie Bo <[email protected]>
---
Changes in v2:
- Drop the completed flag and rely directly on
virtio_queue__should_signal(), as suggested by Will Deacon.
virtio/9p.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/virtio/9p.c b/virtio/9p.c
index e6f669c..100926a 100644
--- a/virtio/9p.c
+++ b/virtio/9p.c
@@ -1375,8 +1375,10 @@ static void virtio_p9_do_io(struct kvm *kvm, void *param)
while (virt_queue__available(vq)) {
virtio_p9_do_io_request(kvm, job);
- p9dev->vdev.ops->signal_vq(kvm, &p9dev->vdev, vq - p9dev->vqs);
}
+
+ if (virtio_queue__should_signal(vq))
+ p9dev->vdev.ops->signal_vq(kvm, &p9dev->vdev, vq - p9dev->vqs);
}
static u8 *get_config(struct kvm *kvm, void *dev)
--
2.54.0