From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9428D36AF6 for ; Thu, 7 May 2026 18:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778179121; cv=none; b=UgKMLCcZe5NKZjcI3laM2vTjHROeoMqkszy+MCspH2wfQNjnn3s+w0pJ0/M7613QB13kZObGi98Gvcm5dqPGnRBzZTv6Jt0EfZ/NhcdhjI0N2lHfhpoVxct276dW84uoKOLqsU/awCPzIPszy9LMjxloTHhk7wzfRtA+l5pU+Ig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778179121; c=relaxed/simple; bh=4GrsCCPahhxyGz9IfFdXG4lPM39+qQCAQa6kwwfmcoE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=raIe97q76D9NhYqKP83kEm5wDKvLuQctorAeGdh2aHGNWi4uiyMh/RE9APCLrpipgC8dpvqMX7/K3oWhfhrrTh8ZxSXPZYmqqdKB6l/mYf0OTNeyLoeYlp5aL0S1AR/2JkpKiDMmrYh2a8ZOTDE2H2QZNOPM/G+I14iwiVbsxdI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RJh9biNH; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RJh9biNH" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-8353dfdad62so826677b3a.1 for ; Thu, 07 May 2026 11:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778179120; x=1778783920; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=csDUDl+objecmrzJgOYyRiiDYmfFHBJwcWFBOaJXMVM=; b=RJh9biNHubgTuT8Qmu8e2cFz9fZSzpMLeMypzyERq0QPe+8K1oKL5Ypde+FsbzCwhb UQMnkMe9w4fNnKlE43I3AnYmvqmoV6YVA9gXENlPzfQ9t8ojQqYPbdFRY1WHk4POtdAn p5I4/UazEXtVpnuI11KC1i/7NMpkZJi6YNWpWSQgGzrJhUjVctdNbZtgKj4Wj1W+K8DB SG5FfU5gNLFwhMI5kI+Vk5K2w4JQAOycsu5+7GDIcHR2EKf+pq9LfnU4tUCVLrmWJ1+a iuQgoOl94vg1iT+RDQ2xYrp2Jn3WLvZvi/9504bLSudi4C0dx8snYbVOm2Ta/H0zOcpO F1zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778179120; x=1778783920; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=csDUDl+objecmrzJgOYyRiiDYmfFHBJwcWFBOaJXMVM=; b=Br5DB6BpuIkhU2teHH2yv9eaIi0VqPzI+D6OjABxHaVjd8obRaLqxaj1u2hu55pB93 mGMKOYPFjGmxh50RRlbvgRn3wo5berEIdPZnl8mNXFkyU5cfwCFlnlMY4Gy+7sfYC5gx 6sTTXHIY/2InZMBFMQEwUzYsfIIXx0VQExCGCnQdPOwhqa2VM8GAMdA7YRGZRi470tJL N/DpTLuKTLAfK9LVI3OM2S29Ynqa5ASewo/q6/Mz9czO/PTJsotlaOwYERdfwMSS1VwG ve/zNUi6Uv5cAtcguD9MZfOnN5ineStSK3jv4JZ5/IXX2rR5CXbvUOWLaIaDl4kuxYKU L5LA== X-Forwarded-Encrypted: i=1; AFNElJ+98x3rXywaVErFET4wDB6wGP1eke29Geo4NgtH7VxAqOb6O1DvHE8qQtOQE0u2ziPoQGOW23B3GBp2pwY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0FVWAjHuFgDnnNMwds5OEWIQRDyRuBWg2QAi5RfSyNzbWbaXw 9nbSMFhp7sjRoegafWU8MtdQY+249VivPM38E+e0EiiXMfSvYY4vA9h3 X-Gm-Gg: AeBDiesjp3MPpb5XdgdzFLwyh+pU2Ces0YjU+rUjBGpxN4lH/D6MsGeg0CiXu8Xyvva Fr26lEbzEY8/GKucOjbG6HJbqTxIc/pcjv1j8Xe1CKQbp4rQJEgIwS3qIY7mDB2MeKMsnrzw8pX 4AGD33+0N0AZHaLqugxgWc5Q5hXRMFHDWEuDETWORpqElMh9m/GChl7FsD76Z881b0+2VgE3eSQ s1m6B/d/0FmUbFXWpuyeHOdl88Qg5zoYWS8Q1uXDrFFAKa6bENmAUH6Kx34cWruEB+ErQ9GE3p2 mFZwt1hZFLF5D/MHoqsCAcmybQ55eOJPOe3E31mDHKJ6Ayhyj2I7T9GAkJfYntG2TQxTUuMt+jJ Z2UCxCHidlqCjwmvRKx/HUvOtexXkihoUGYv/0neEfhUFuSEO66d6T3bDXnLCeVAltvjM2jf121 3SlTqeID3iy4HPMDWXrqKDJIfraua18gkxPeK+OqmQ+TCtbgda+DjVX3Lvu8N9t0IdgAFy9aL5X f0/wCjnCIp8a48h8tgeiTTFRd8= X-Received: by 2002:a05:6a00:2e87:b0:82f:5034:77a4 with SMTP id d2e1a72fcca58-83a5c4be2eemr9265031b3a.21.1778179119797; Thu, 07 May 2026 11:38:39 -0700 (PDT) Received: from baver-zenith.localdomain ([124.49.88.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83967dbcf16sm11272744b3a.40.2026.05.07.11.38.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 11:38:39 -0700 (PDT) From: Sungho Bae 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 Subject: [PATCH] virtio-mmio: move guest page size setting into vm_reset() Date: Fri, 8 May 2026 03:38:07 +0900 Message-Id: <20260507183807.22007-1-baver.bae@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Sungho Bae 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 --- 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.43.0