Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2457138pxb; Tue, 23 Feb 2021 07:31:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIGlJ52Qmj1H0sPg54dCN6Q+xlPvGHOa5+pedWDIjbA+KgW5+UAwktQ0ayf5ZHLA2abgem X-Received: by 2002:a17:906:780b:: with SMTP id u11mr26829272ejm.492.1614094290397; Tue, 23 Feb 2021 07:31:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614094290; cv=none; d=google.com; s=arc-20160816; b=YzdjdsVwkkXqAsZJIA/JuvP9Vvr10gpPBlfoAQKxHogt2QKy3ZM9Js/eBr5y97jP/U U85n8XjwusRoiMW/vvLqd1Hh/gIbSddw8ROi0tCPXPtnr+g2FdUXGOQz2Xs7tkBU5rm6 YumjqIe/yvo/zWCmNto0SsybdAKlrzM5zUyf+Foota8hwgigfJVb6GUxubSGtDzWSJvd 9DcnTdBiRcjs5x5mIvZquHB9QDHoSONeljJMWhRUnp1aOZWATHxDXBFuaBh65iiR8G+B oTaMzUIX7CHNfGqrqzqSO7TMLiQSgAZE7nCr+zWDmN082cJNzb0SxpGNc7ZHveYWu2r7 BhAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bF0J4pgtpIsknu5XKj9Adg5R/580RkgGa0+9QvpBQuU=; b=NfXNV5Q2VA4+x6ixuOBOouen9wY/VvV6N6QIHMPuRBLcUhE1wl54/7jJYQVvGz2P2q 24wg7L+9tGggXfu6u5WP6ZG8W/DUQQusBZcZtTncbeOROeVvRdsYIK7dvApr2bXmQz1J DHE6od08SgwXc7FXFejFkkDq3cc4uq39P39hNWB1/VtNcoeDo7Snt6CJi8C2mEQfLi4I Hjxj1dW2qXv/9Aa0Vo4Mz5x5uYEGczUnnCbEPPStVxyXpmrlo3QIcjDIh7QfBgNKQNF/ AQbIlWWZHaifIdDewJF76ck8kYEQjok3Z3UP3o5sE1P6TfvGt+7Mv5+VGYkQXI8i3561 nFEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b15si15220490edz.486.2021.02.23.07.30.58; Tue, 23 Feb 2021 07:31:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233284AbhBWP3A (ORCPT + 99 others); Tue, 23 Feb 2021 10:29:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbhBWP2o (ORCPT ); Tue, 23 Feb 2021 10:28:44 -0500 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6756BC061794 for ; Tue, 23 Feb 2021 07:27:15 -0800 (PST) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94) (envelope-from ) id 1lEZaj-007R3T-HR; Tue, 23 Feb 2021 16:27:13 +0100 From: Johannes Berg To: linux-um@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Arnd Bergmann , Johannes Berg Subject: [PATCH 7/7] um: virtio/pci: enable suspend/resume Date: Tue, 23 Feb 2021 16:27:07 +0100 Message-Id: <20210223161449.b8aeac19b66e.I2e9caf8b2083e2a8d0c76799179db35d08032aa1@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210223152707.408995-1-johannes@sipsolutions.net> References: <20210223152707.408995-1-johannes@sipsolutions.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Berg The UM virtual PCI devices currently cannot be suspended properly since the virtio driver already disables VQs well before the PCI bus's suspend_noirq wants to complete the transition by writing to PCI config space. After trying around for a long time with moving the devices on the DPM list, trying to create dependencies between them, etc. I gave up and instead added UML specific cross-driver API that lets the virt-pci code enable not suspending/resuming VQs for its devices. This then allows the PCI bus suspend_noirq to still talk to the device, and suspend/resume works properly. Signed-off-by: Johannes Berg --- arch/um/drivers/virt-pci.c | 7 ++++++ arch/um/drivers/virtio_uml.c | 40 ++++++++++++++++++++++-------- arch/um/include/linux/virtio-uml.h | 13 ++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 arch/um/include/linux/virtio-uml.h diff --git a/arch/um/drivers/virt-pci.c b/arch/um/drivers/virt-pci.c index dd85f36197aa..e5d57ec8ada6 100644 --- a/arch/um/drivers/virt-pci.c +++ b/arch/um/drivers/virt-pci.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -550,6 +551,12 @@ static int um_pci_virtio_probe(struct virtio_device *vdev) device_set_wakeup_enable(&vdev->dev, true); + /* + * In order to do suspend-resume properly, don't allow VQs + * to be suspended. + */ + virtio_uml_set_no_vq_suspend(vdev, true); + um_pci_rescan(); return 0; error: diff --git a/arch/um/drivers/virtio_uml.c b/arch/um/drivers/virtio_uml.c index 91ddf74ca888..4412d6febade 100644 --- a/arch/um/drivers/virtio_uml.c +++ b/arch/um/drivers/virtio_uml.c @@ -56,6 +56,7 @@ struct virtio_uml_device { u8 status; u8 registered:1; u8 suspended:1; + u8 no_vq_suspend:1; u8 config_changed_irq:1; uint64_t vq_irq_vq_map; @@ -1098,6 +1099,19 @@ static void virtio_uml_release_dev(struct device *d) kfree(vu_dev); } +void virtio_uml_set_no_vq_suspend(struct virtio_device *vdev, + bool no_vq_suspend) +{ + struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); + + if (WARN_ON(vdev->config != &virtio_uml_config_ops)) + return; + + vu_dev->no_vq_suspend = no_vq_suspend; + dev_info(&vdev->dev, "%sabled VQ suspend\n", + no_vq_suspend ? "dis" : "en"); +} + /* Platform device */ static int virtio_uml_probe(struct platform_device *pdev) @@ -1302,13 +1316,16 @@ MODULE_DEVICE_TABLE(of, virtio_uml_match); static int virtio_uml_suspend(struct platform_device *pdev, pm_message_t state) { struct virtio_uml_device *vu_dev = platform_get_drvdata(pdev); - struct virtqueue *vq; - virtio_device_for_each_vq((&vu_dev->vdev), vq) { - struct virtio_uml_vq_info *info = vq->priv; + if (!vu_dev->no_vq_suspend) { + struct virtqueue *vq; - info->suspended = true; - vhost_user_set_vring_enable(vu_dev, vq->index, false); + virtio_device_for_each_vq((&vu_dev->vdev), vq) { + struct virtio_uml_vq_info *info = vq->priv; + + info->suspended = true; + vhost_user_set_vring_enable(vu_dev, vq->index, false); + } } if (!device_may_wakeup(&vu_dev->vdev.dev)) { @@ -1322,13 +1339,16 @@ static int virtio_uml_suspend(struct platform_device *pdev, pm_message_t state) static int virtio_uml_resume(struct platform_device *pdev) { struct virtio_uml_device *vu_dev = platform_get_drvdata(pdev); - struct virtqueue *vq; - virtio_device_for_each_vq((&vu_dev->vdev), vq) { - struct virtio_uml_vq_info *info = vq->priv; + if (!vu_dev->no_vq_suspend) { + struct virtqueue *vq; + + virtio_device_for_each_vq((&vu_dev->vdev), vq) { + struct virtio_uml_vq_info *info = vq->priv; - info->suspended = false; - vhost_user_set_vring_enable(vu_dev, vq->index, true); + info->suspended = false; + vhost_user_set_vring_enable(vu_dev, vq->index, true); + } } vu_dev->suspended = false; diff --git a/arch/um/include/linux/virtio-uml.h b/arch/um/include/linux/virtio-uml.h new file mode 100644 index 000000000000..2f652fa90f04 --- /dev/null +++ b/arch/um/include/linux/virtio-uml.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2021 Intel Corporation + * Author: Johannes Berg + */ + +#ifndef __VIRTIO_UML_H__ +#define __VIRTIO_UML_H__ + +void virtio_uml_set_no_vq_suspend(struct virtio_device *vdev, + bool no_vq_suspend); + +#endif /* __VIRTIO_UML_H__ */ -- 2.26.2