From nobody Mon Apr 20 07:30:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B536FC43334 for ; Tue, 21 Jun 2022 11:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349951AbiFULmt (ORCPT ); Tue, 21 Jun 2022 07:42:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349833AbiFULmo (ORCPT ); Tue, 21 Jun 2022 07:42:44 -0400 Received: from mx.kernkonzept.com (serv1.kernkonzept.com [IPv6:2a01:4f8:1c1c:b490::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC00BE28 for ; Tue, 21 Jun 2022 04:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=NDivncQ+nuA5i32alXvrHtKC02tI1GI+RHIHBVYRB/E=; b=hXHGyMDjJg+VL/rIFAAXJdBHgI RJYQU6mjIuvTot4/qNH0FhpOlsCqkjzUAZGf5JLMtAJLRqF8MAP/XBYcltUhDoFc3uyGdAxX1RV2x Ox/mDIyhhrDeIHIASMKqkQ36De0fXKPzCVJ+pMWS1jOxPfXLyZ3IroY3nK+6FqD7HNPlVzgXHAOob OVJHQinxQD4JHYpGRU2jBwHhwcOjS4cK1wE1CK1xYhdmH+fPEsXEb0sDJdyGmBSn0lIe4qSlTk8VF K9zwb5vTxTzvx+nRp9+vEAM4UhgIGFjqxhqcKlukX7q+y0AadfflJYxrbD9BaNNCWlC1yeeIxcs2l fkPYZH/w==; Received: from [10.22.3.24] (helo=kernkonzept.com) by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) id 1o3blo-005hKr-U0; Tue, 21 Jun 2022 13:10:08 +0200 From: Stephan Gerhold To: "Michael S. Tsirkin" , Jason Wang Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Stephan Gerhold Subject: [PATCH 1/2] virtio_mmio: Add missing PM calls to freeze/restore Date: Tue, 21 Jun 2022 13:06:20 +0200 Message-Id: <20220621110621.3638025-2-stephan.gerhold@kernkonzept.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220621110621.3638025-1-stephan.gerhold@kernkonzept.com> References: <20220621110621.3638025-1-stephan.gerhold@kernkonzept.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Most virtio drivers provide freeze/restore callbacks to finish up device usage before suspend and to reinitialize the virtio device after resume. However, these callbacks are currently only called when using virtio_pci. virtio_mmio does not have any PM ops defined. This causes problems for example after suspend to disk (hibernation), since the virtio devices might lose their state after the VMM is restarted. Calling virtio_device_freeze()/restore() ensures that the virtio devices are re-initialized correctly. Fix this by implementing the dev_pm_ops for virtio_mmio, similar to virtio_pci_common. Signed-off-by: Stephan Gerhold --- drivers/virtio/virtio_mmio.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index c9bec3813e94..980dffd69586 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include @@ -556,6 +557,25 @@ static const struct virtio_config_ops virtio_mmio_conf= ig_ops =3D { .synchronize_cbs =3D vm_synchronize_cbs, }; =20 +#ifdef CONFIG_PM_SLEEP +static int virtio_mmio_freeze(struct device *dev) +{ + struct virtio_mmio_device *vm_dev =3D dev_get_drvdata(dev); + + return virtio_device_freeze(&vm_dev->vdev); +} + +static int virtio_mmio_restore(struct device *dev) +{ + struct virtio_mmio_device *vm_dev =3D dev_get_drvdata(dev); + + return virtio_device_restore(&vm_dev->vdev); +} + +static const struct dev_pm_ops virtio_mmio_pm_ops =3D { + SET_SYSTEM_SLEEP_PM_OPS(virtio_mmio_freeze, virtio_mmio_restore) +}; +#endif =20 static void virtio_mmio_release_dev(struct device *_d) { @@ -799,6 +819,9 @@ static struct platform_driver virtio_mmio_driver =3D { .name =3D "virtio-mmio", .of_match_table =3D virtio_mmio_match, .acpi_match_table =3D ACPI_PTR(virtio_mmio_acpi_match), +#ifdef CONFIG_PM_SLEEP + .pm =3D &virtio_mmio_pm_ops, +#endif }, }; =20 --=20 2.30.2 From nobody Mon Apr 20 07:30:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D31BEC433EF for ; Tue, 21 Jun 2022 11:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349993AbiFULmx (ORCPT ); Tue, 21 Jun 2022 07:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349833AbiFULmu (ORCPT ); Tue, 21 Jun 2022 07:42:50 -0400 Received: from mx.kernkonzept.com (serv1.kernkonzept.com [IPv6:2a01:4f8:1c1c:b490::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FF37E48 for ; Tue, 21 Jun 2022 04:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LcqlgrS7zj13sDDduNZ2hZFqVURpCBy3Ki4wyCilt+Q=; b=kMBGSmVw3QnKKa6d3FhfEYQw75 2TAOzLxlIbjHi+qMYl0ePadqRiBOW4EcqIx5L2SrHR1B8lj/fPJEVvekkzbYSukNRj1j25DrNvF0q eC5LFrhAHq5CWgg1WNhPFmFFbPCQRrmrx9HEF5B1qbiFYNKgSt1RhtdxbmV7GNKQT/G16S1WhG57U GkxwmduqFmF9D+XpnWQuemMZlZavWU5fitl4ODVsDtF7uyAKMtEc0INWvLcgyGTJunsoHTqwUUykO 5tdz2Xxm+Yvl9Am12r3J5g223E7lMCjMmnmqPLXTyN2Zcpn2dWyLZmWtJx9q6B/3MVZqUFyE9jmHP VyVJT99A==; Received: from [10.22.3.24] (helo=kernkonzept.com) by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) id 1o3blp-005hKr-CO; Tue, 21 Jun 2022 13:10:09 +0200 From: Stephan Gerhold To: "Michael S. Tsirkin" , Jason Wang Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Stephan Gerhold Subject: [PATCH 2/2] virtio_mmio: Restore guest page size on resume Date: Tue, 21 Jun 2022 13:06:21 +0200 Message-Id: <20220621110621.3638025-3-stephan.gerhold@kernkonzept.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220621110621.3638025-1-stephan.gerhold@kernkonzept.com> References: <20220621110621.3638025-1-stephan.gerhold@kernkonzept.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Virtio devices might lose their state when the VMM is restarted after a suspend to disk (hibernation) cycle. This means that the guest page size register must be restored for the virtio_mmio legacy interface, since otherwise the virtio queues are not functional. This is particularly problematic for QEMU that currently still defaults to using the legacy interface for virtio_mmio. Write the guest page size register again in virtio_mmio_restore() to make legacy virtio_mmio devices work correctly after hibernation. Signed-off-by: Stephan Gerhold --- drivers/virtio/virtio_mmio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index 980dffd69586..083ff1eb743d 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -569,6 +569,9 @@ static int virtio_mmio_restore(struct device *dev) { struct virtio_mmio_device *vm_dev =3D dev_get_drvdata(dev); =20 + if (vm_dev->version =3D=3D 1) + writel(PAGE_SIZE, vm_dev->base + VIRTIO_MMIO_GUEST_PAGE_SIZE); + return virtio_device_restore(&vm_dev->vdev); } =20 --=20 2.30.2