From: Yuho Choi <oss.patchbox@gmail.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowangio@gmail.com>
Cc: "Eugenio Pérez" <eperezma@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
"Yuho Choi" <oss.patchbox@gmail.com>
Subject: [PATCH v3] vdpa/vp_vdpa: Wait for device reset to complete
Date: Thu, 3 Dec 2026 15:24:50 +0000 [thread overview]
Message-ID: <20261203152530.1953781-2-oss.patchbox@gmail.com> (raw)
vp_vdpa_reset() writes 0 to device_status and returns at once, but the
virtio spec requires the driver to wait until device_status reads back
0. With a device that takes time to reset, the vDPA bus driver can set
the device up again before the reset is done, and the late reset then
wipes that setup; the device may also still use the old rings. Wait for
the read-back, as vp_reset() does.
Fixes: 64b9f64f80a6 ("vdpa: introduce virtio pci driver")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
I used an LLM to write and run the test below.
v3:
- Tested in QEMU/KVM, including a QEMU that completes the reset 1 to
100 ms late, which shows the bug (see below).
- Shorter changelog that describes what the test shows. No code change.
v2: https://lore.kernel.org/r/20261116030152.1704527-2-oss.patchbox@gmail.com
v1: https://lore.kernel.org/r/20260926211507.1330179-1-oss.patchbox@gmail.com
Tested on d06ce6f1eb5e with KASAN guests in QEMU/KVM (q35, intel-iommu)
and a modern-only virtio-net-pci device bound to vp_vdpa, using it
through virtio_vdpa (vdpa dev add, traffic, vdpa dev del) and through
vhost_vdpa (VHOST_VDPA_SET_STATUS 0, then read the status back):
1. Stock QEMU 6.2 completes a reset at once, so device_status reads 0 at
the first poll. Both kernels pass 20 cycles of each.
2. A QEMU v11.2.0-rc1 with a test-only change completes the reset 1, 2,
5, 10, 20 or 100 ms after the write of 0, as a slower device might.
Without this patch every boot failed, 3 of 3 at each delay: the late
reset wipes the setup that follows it. Depending on the delay, the
virtio_net probe fails with -95, no packets are received, vdpa dev
del never returns, or vhost_vdpa reads the old status right after
SET_STATUS 0 or fails its next setup with -EINVAL. At 100 ms:
WARNING: drivers/pci/msi/msi.c:816 at __pci_enable_msix_range+0xb3d/0xdc0
WARNING: drivers/vdpa/virtio_pci/vp_vdpa.c:224 at vp_vdpa_set_status+0x412/0x630
WARNING: drivers/virtio/virtio.c:380 at virtio_dev_remove+0x182/0x1e0
With this patch: 10 of 10 cycles of each at every delay, no warnings,
3 of 3 boots each.
Like vp_reset(), the loop has no bound, so a surprise-removed device
that reads back all ones keeps it spinning (pointed out on v1). I kept
it the same as vp_reset().
drivers/vdpa/virtio_pci/vp_vdpa.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index 646efd9384fb..eba82ff253ea 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -8,6 +8,7 @@
* Based on virtio_pci_modern.c.
*/
+#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/pci.h>
@@ -236,6 +237,9 @@ static int vp_vdpa_reset(struct vdpa_device *vdpa)
u8 s = vp_vdpa_get_status(vdpa);
vp_modern_set_status(mdev, 0);
+ /* Wait for the reset to complete */
+ while (vp_modern_get_status(mdev))
+ fsleep(1000);
if (s & VIRTIO_CONFIG_S_DRIVER_OK)
vp_vdpa_free_irq(vp_vdpa);
base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
--
2.56.1
next reply other threads:[~2026-12-03 15:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 15:24 Yuho Choi [this message]
2026-12-03 15:40 ` [PATCH v3] vdpa/vp_vdpa: Wait for device reset to complete sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203152530.1953781-2-oss.patchbox@gmail.com \
--to=oss.patchbox@gmail.com \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.