* [PATCH v2] vhost/user: clear ring addresses when getting vring base
@ 2024-11-25 3:42 Jianping Zhao
2024-11-25 3:45 ` [PATCH v3] " Jianping Zhao
0 siblings, 1 reply; 3+ messages in thread
From: Jianping Zhao @ 2024-11-25 3:42 UTC (permalink / raw)
To: dev; +Cc: stable, maxime.coquelin, chenbo.xia, Jianping Zhao
Clear ring addresses during vring base retrieval to handle guest reboot
scenarios correctly. This is particularly important for vdpa-blk devices
where the following issue occurs:
When a guest OS with vdpa-blk device reboots, during UEFI stage, only
one vring is actually used and configured. However, QEMU still sends
enable messages for all configured queues. The remaining queues retain
their addresses from before reboot, which reference invalid memory
mappings in the rebooted guest.
The issue manifests in vq_is_ready():
static bool
vq_is_ready(struct virtio_net *dev, struct vhost_virtqueue *vq)
{
/* Only checks pointer validity, not address freshness */
rings_ok = vq->desc && vq->avail && vq->used;
...
}
vq_is_ready() incorrectly considers these queues as ready because it
only checks if desc/avail/used pointers are non-NULL, but cannot
detect that these addresses are stale from the previous boot.
Clear the ring addresses in vhost_user_get_vring_base() to force
the guest driver to reconfigure them before use. This ensures that
vq_is_ready() will return false for queues with stale addresses
until they are properly reconfigured by the guest driver.
Fixes: 3ea7052f4b1b ("vhost: postpone rings addresses translation")
Signed-off-by: Jianping Zhao <zhao305149619@gmail.com>
---
lib/vhost/vhost_user.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 6d92ad904e..52d8078d7c 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2277,6 +2277,7 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
rte_rwlock_write_lock(&vq->access_lock);
vring_invalidate(dev, vq);
+ memset(&vq->ring_addrs, 0, sizeof(struct vhost_vring_addr));
rte_rwlock_write_unlock(&vq->access_lock);
return RTE_VHOST_MSG_RESULT_REPLY;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3] vhost/user: clear ring addresses when getting vring base
2024-11-25 3:42 [PATCH v2] vhost/user: clear ring addresses when getting vring base Jianping Zhao
@ 2024-11-25 3:45 ` Jianping Zhao
2024-11-27 2:03 ` [PATCH v4] " Jianping Zhao
0 siblings, 1 reply; 3+ messages in thread
From: Jianping Zhao @ 2024-11-25 3:45 UTC (permalink / raw)
To: dev; +Cc: stable, maxime.coquelin, chenbo.xia, Jianping Zhao
Clear ring addresses during vring base retrieval to handle guest reboot
scenarios correctly. This is particularly important for vdpa-blk devices
where the following issue occurs:
When a guest OS with vdpa-blk device reboots, during UEFI stage, only
one vring is actually used and configured. However, QEMU still sends
enable messages for all configured queues. The remaining queues retain
their addresses from before reboot, which reference invalid memory
mappings in the rebooted guest.
The issue manifests in vq_is_ready():
static bool
vq_is_ready(struct virtio_net *dev, struct vhost_virtqueue *vq)
{
/* Only checks pointer validity, not address freshness */
rings_ok = vq->desc && vq->avail && vq->used;
...
}
vq_is_ready() incorrectly considers these queues as ready because it
only checks if desc/avail/used pointers are non-NULL, but cannot
detect that these addresses are stale from the previous boot.
Clear the ring addresses in vhost_user_get_vring_base() to force
the guest driver to reconfigure them before use. This ensures that
vq_is_ready() will return false for queues with stale addresses
until they are properly reconfigured by the guest driver.
Fixes: 3ea7052f4b1b ("vhost: postpone rings addresses translation")
Signed-off-by: Jianping Zhao <zhao305149619@gmail.com>
---
lib/vhost/vhost_user.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 6d92ad904e..52d8078d7c 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2277,6 +2277,7 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
rte_rwlock_write_lock(&vq->access_lock);
vring_invalidate(dev, vq);
+ memset(&vq->ring_addrs, 0, sizeof(struct vhost_vring_addr));
rte_rwlock_write_unlock(&vq->access_lock);
return RTE_VHOST_MSG_RESULT_REPLY;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v4] vhost/user: clear ring addresses when getting vring base
2024-11-25 3:45 ` [PATCH v3] " Jianping Zhao
@ 2024-11-27 2:03 ` Jianping Zhao
0 siblings, 0 replies; 3+ messages in thread
From: Jianping Zhao @ 2024-11-27 2:03 UTC (permalink / raw)
To: maxime.coquelin; +Cc: dev, Jianping Zhao
Clear ring addresses during vring base retrieval to handle guest reboot
scenarios correctly. This is particularly important for vdpa-blk devices
where the following issue occurs:
When a guest OS with vdpa-blk device reboots, during UEFI stage, only
one vring is actually used and configured. However, QEMU still sends
enable messages for all configured queues. The remaining queues retain
their addresses from before reboot, which reference invalid memory
mappings in the rebooted guest.
The issue manifests in vq_is_ready():
static bool
vq_is_ready(struct virtio_net *dev, struct vhost_virtqueue *vq)
{
/* Only checks pointer validity, not address freshness */
rings_ok = vq->desc && vq->avail && vq->used;
...
}
vq_is_ready() incorrectly considers these queues as ready because it
only checks if desc/avail/used pointers are non-NULL, but cannot
detect that these addresses are stale from the previous boot.
Clear the ring addresses in vhost_user_get_vring_base() to force
the guest driver to reconfigure them before use. This ensures that
vq_is_ready() will return false for queues with stale addresses
until they are properly reconfigured by the guest driver.
Fixes: 3ea7052f4b1b ("vhost: postpone rings addresses translation")
Signed-off-by: Jianping Zhao <zhao305149619@gmail.com>
---
lib/vhost/vhost_user.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 6d92ad904e..52d8078d7c 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2277,6 +2277,7 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
rte_rwlock_write_lock(&vq->access_lock);
vring_invalidate(dev, vq);
+ memset(&vq->ring_addrs, 0, sizeof(struct vhost_vring_addr));
rte_rwlock_write_unlock(&vq->access_lock);
return RTE_VHOST_MSG_RESULT_REPLY;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-27 2:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-25 3:42 [PATCH v2] vhost/user: clear ring addresses when getting vring base Jianping Zhao
2024-11-25 3:45 ` [PATCH v3] " Jianping Zhao
2024-11-27 2:03 ` [PATCH v4] " Jianping Zhao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).