From: Sungho Bae <baver.bae@gmail.com>
To: mst@redhat.com, jasowang@redhat.com
Cc: xuanzhuo@linux.alibaba.com, eperezma@redhat.com,
stephan.gerhold@kernkonzept.com, virtualization@lists.linux.dev,
linux-kernel@vger.kernel.org, Sungho Bae <baver.bae@lge.com>
Subject: [RFC PATCH v9 1/5] virtio-mmio: move guest page size setting into vm_reset()
Date: Sat, 16 May 2026 10:57:52 +0900 [thread overview]
Message-ID: <20260516015756.20948-2-baver.bae@gmail.com> (raw)
In-Reply-To: <20260516015756.20948-1-baver.bae@gmail.com>
From: Sungho Bae <baver.bae@lge.com>
The virtio-mmio legacy spec (Section 4.2.4) requires the driver to
write the guest page size "during initialization, before any queues
are used". Reset is step 1 of the initialization sequence
(Section 3.1), so setting GuestPageSize immediately after the status
register reset in vm_reset() is more proper.
Currently the GuestPageSize write lives in two separate call sites:
- virtio_mmio_probe(), before register_virtio_device()
- virtio_mmio_restore(), before virtio_device_restore()
Both of these write the value *before* the reset that happens inside
register_virtio_device()/virtio_device_restore(), so a device
implementation that clears GuestPageSize on reset would lose the
value. QEMU's virtio_mmio_reset() for example zeroes guest_page_shift
on a full device reset.
The current code happens to work because the Linux driver triggers
only a "soft reset" (STATUS register write of 0), and QEMU's
soft-reset path does not clear guest_page_shift. But relying on
this is fragile and not guaranteed by the spec.
Move the GuestPageSize write into vm_reset(), right after the status
reset. This ensures the value is set:
- at the correct point in the initialization sequence per spec,
- after every reset (probe, restore, or any future path), and
- exactly once, removing the duplication.
Fixes: e0c2ce821795 ("virtio_mmio: Restore guest page size on resume")
Signed-off-by: Sungho Bae <baver.bae@lge.com>
---
drivers/virtio/virtio_mmio.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 595c2274fbb5..daa65b269a36 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -254,6 +254,16 @@ static void vm_reset(struct virtio_device *vdev)
/* 0 status means a reset. */
writel(0, vm_dev->base + VIRTIO_MMIO_STATUS);
+
+ /*
+ * The virtio-mmio legacy spec requires the driver to write the
+ * guest page size during initialization, before any queues are
+ * used. Since reset is step 1 of initialization (Section 3.1),
+ * set it here so it is always in place for subsequent queue setup
+ * in every code path (probe, restore, etc.).
+ */
+ if (vm_dev->version == 1)
+ writel(PAGE_SIZE, vm_dev->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
}
@@ -547,9 +557,6 @@ static int virtio_mmio_restore(struct device *dev)
{
struct virtio_mmio_device *vm_dev = dev_get_drvdata(dev);
- if (vm_dev->version == 1)
- writel(PAGE_SIZE, vm_dev->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
-
return virtio_device_restore(&vm_dev->vdev);
}
@@ -619,8 +626,6 @@ static int virtio_mmio_probe(struct platform_device *pdev)
vm_dev->vdev.id.vendor = readl(vm_dev->base + VIRTIO_MMIO_VENDOR_ID);
if (vm_dev->version == 1) {
- writel(PAGE_SIZE, vm_dev->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
-
rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
/*
* In the legacy case, ensure our coherently-allocated virtio
--
2.34.1
next prev parent reply other threads:[~2026-05-16 1:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-16 1:57 [RFC PATCH v9 0/5] virtio: add noirq system sleep PM callbacks for virtio-mmio Sungho Bae
2026-05-16 1:57 ` Sungho Bae [this message]
2026-05-16 1:57 ` [RFC PATCH v9 2/5] virtio: separate PM restore and reset_done paths Sungho Bae
2026-05-16 1:57 ` [RFC PATCH v9 3/5] virtio_ring: export virtqueue_reinit_vring() for noirq restore Sungho Bae
2026-05-16 1:57 ` [RFC PATCH v9 4/5] virtio: add noirq system sleep PM infrastructure Sungho Bae
2026-05-16 1:57 ` [RFC PATCH v9 5/5] virtio-mmio: wire up noirq system sleep PM callbacks Sungho Bae
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=20260516015756.20948-2-baver.bae@gmail.com \
--to=baver.bae@gmail.com \
--cc=baver.bae@lge.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=stephan.gerhold@kernkonzept.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.