From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 F247E2777FC for ; Sat, 16 May 2026 01:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778896747; cv=none; b=oq/YqyTRw86iR1YuuMD8eTupPS+eh7vhD3w+wYz917DwWPmlNmqwdQjPR3G5YJOsUaDYnHqKO0KSH4kwoO2ZSe92TN1CeTE0vBR+CG9nS0pv9LsDdGkGiWT6Ro3j0g2EH2GIJABo9Mdn8igGc0umUXL0j0hrplKjBJHr9jyisCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778896747; c=relaxed/simple; bh=+mP6J0GmpPt2dHq9MQGkUGMiaPx2jIw8pRw/8IFhHsM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qs2eTrwKn0TbcghQNvLCMS8Ct1cAKpZ+oWNbLdd8IAy6lYWVOb+aMAfgWM06mdyx8hjriNrkBKz35dHIWoJY3sG9p2+yW5AppJhQTReakOWwn8wh6W/3mt/afX9gZwQ+xeXLnawKdfHrQDf4IqgDcvIn1T4oM5r21VcnS4+2kmU= 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=oyz5euQc; arc=none smtp.client-ip=209.85.215.178 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="oyz5euQc" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-c8021c8c42fso138636a12.3 for ; Fri, 15 May 2026 18:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778896745; x=1779501545; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dnydI41OQ3430HCEfE0IbCU2csloNYwU26T/5pTPuPE=; b=oyz5euQc6SV8ZZrpXMh7pjUrNO98G8r0xp0D5cowbGTsbU5dGmZv3xS+XkwGWp0op8 zDLSHqr0y02jJUPMfpydSxULB/qqx5fy9otsCTw6bwdTd823zgMruRJC78sOqemY6pUl ZbbRAAx4K5Vx+bOUhNEvFlbEd+hevjAdNf6JZFUY1kxYknPQ7KrDaHMnK6cnBr5/3H8v MN7zsVQkIDgBVqvNMqEoONJnNF45etdYpu86v2u5cOUiA2lvi0icLVOxGa52OfcQh0oU O7nS0+JjIvAiyWlkApUhmjA9lrMk/AZK45ku76eHz1xoz++OMg/ID8puoSYP3VuOFDtQ +MAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778896745; x=1779501545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dnydI41OQ3430HCEfE0IbCU2csloNYwU26T/5pTPuPE=; b=FGHFJ//DS8PykKPbuPrzryXV6Q/9yvYZfTZyMsg7LPYxTmheHLih5zwaofcyMzJ9vK 8VXMkn01xxsJor5OtODitdaY+ovtOs+ph7GHYK3AWZDLoX9u3zoFGuG6QBj7TDLzSO9b 6pmf/hMWBLJ0AyNeFWoqMCptXdGTJFu0yMz9QMFpsxYJ7HGFvzvZtjOn4TRc8pMCg9b6 D70Vyq76v2Bj/84SKXF1bikmldLFwP3Aq87ySZqstmnEU2cRI0t+F67+er1bxdQERi6r goaDOlDFQCEBBdIskZyvSeYmJW3d9bNN4M6G451rqAlmqYBFYp3+9CLP7ooNo+ji0uBE LThA== X-Forwarded-Encrypted: i=1; AFNElJ9gmE7XamU4u/iCk/8KC84FD/4CrlBFBm/782YJuHjrLoifzNwixiXO1OlkD8svEXdZS1WLJoGkDsZqJHg=@vger.kernel.org X-Gm-Message-State: AOJu0YxRk7AAA366tR/YOKf+boi8OBz/dP+hSv9rUb+BQTtzSSTp/sup bDW/fGetdDCZMrf9YD0ag0PAOWmcoAwMoXg6EWr03BiraQN1kARntDpy X-Gm-Gg: Acq92OG1Zg5fn9EDLLKjSccHO8VT9YBXBXljEG9sd9L9hlfdD5mOQ/tHlme6ofBOTpb eIiINQH6dy00dSShVXE6x4Rse37gvyvqx0ZAJ9bVHRIzKNS/mLQE1nFQts3UHQnW3WPrLxxj98z PY1HxDrALIWg5Bi/imsOXksVL1C5tnPkvICj55rCtqXu8qB11nHCJEnJtEklvdNUlNk7J+MqNSb gDdhCWwXxtgu+2awXtiisw/GqsqeYNcJx+yZw6udHE231y6gy6A+82v/3ednAJFIxtRxPjyUALc WEhjlTwykwJl3RhejncAPlrBbXErVUNSQIbWMBZVLMb4WLyn7VaUtY5eDQXRv0zVSqxfviB0zS8 FuFYmz34DQCCHGDRVD+fufytQ2rtHbkOpq4kK6wy4iQQcNDgPFAg/p8rh4Rn0tlVYfPCoGqrreT ELkJSzQOG1nwK7Z7Sjyi8PnhqO9G5Xt3mEHaf8Vy4tjpZlqp0eavlP83UMbP5I4xtlQoxClTl20 4TMi7Vc2hWBf59G7i/KjxsTm/qYCJbWZmekLg== X-Received: by 2002:a05:6a20:7294:b0:3a2:f7bd:a9a5 with SMTP id adf61e73a8af0-3b22ec73c64mr7355013637.38.1778896745059; Fri, 15 May 2026 18:59:05 -0700 (PDT) Received: from baver-zenith.localdomain ([124.49.88.131]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c82bb07b007sm6605080a12.11.2026.05.15.18.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 18:59:04 -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: [RFC PATCH v9 1/5] virtio-mmio: move guest page size setting into vm_reset() Date: Sat, 16 May 2026 10:57:52 +0900 Message-Id: <20260516015756.20948-2-baver.bae@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260516015756.20948-1-baver.bae@gmail.com> References: <20260516015756.20948-1-baver.bae@gmail.com> 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.34.1