Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6368010rdb; Thu, 14 Dec 2023 17:01:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcYblg8kJ333G7XFqQA039bBfg9kHNijubKwJpHKLVecGRS5hziu9FqZaKfQVHs0r+Jdu7 X-Received: by 2002:a17:90b:310d:b0:28b:f28:c281 with SMTP id gc13-20020a17090b310d00b0028b0f28c281mr1196512pjb.67.1702602061258; Thu, 14 Dec 2023 17:01:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702602061; cv=none; d=google.com; s=arc-20160816; b=S0rTBH9IINT3PWtsfWB82M1ohIJDCczTd6aTfGEYeROlPh64he59zXKOjmk+LblO2x PdUkFwzJygQm9LmtfKXPa7YuZT5Q1tzSwZf2zycehbefRrt/g2lqOO5XfQRJ57x8CE6G qJili3By+6O5+0WjYv6/oA8VEBZ/SeR2HlLVD74fqNcyyC27EwCDlxK9vVETF4tud+2m p1uxqWhLvPz4bAvMzNtnx2CVxKEkzmcyPtvoed+jQGj7B4H3nA8c3Ay2XWA6I8lL05+5 cfBdsgkBjJxBGYpojfAQ3irdZ7dfvK56sjViB18nOe6trC8fVDCsKQrYEDZcCZIVqO6a phIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=aeaw3ji0pg6zC2peZEVGQL9hjW+bOoI/oOULSseP2eQ=; fh=TsRb96obmB+s7e2RzQf7Mb36FLuHh0uO+sFIcgj2aw8=; b=krmYw2LmMMJF0VAaKNfNE4CRVD0o7GvVIei5Rq7aOtSHmQo+6tmgP9Uq4P61QFoneL CuS8p9OWlpN2h0bTF1Huemi0ERU6SfiKrILwKm5vm2hg26mMbZhohjtCn195bVPBMxH6 49hEKoDZYvrabYa+kJRNRUGvdkPuZ+jOnnh4wkkDud35ibhHmmbkoeBrhIgg2asgCcUY 4Wvo1MqyD2sWV4a7Uf6m+6Pbx7D4NyPANONB6WIFw1jv2eYakKff7JoSqem224PRHojk H39JmRhAMnskx4aOUusZwgrqqvy4D/+aUzvbnWLvok+mZ13sjr7j07Ma7z/79RAVkD4y MLPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hzwGOXol; spf=pass (google.com: domain of linux-kernel+bounces-299-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ju7-20020a170903428700b001d374f40162si1253040plb.570.2023.12.14.17.01.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 17:01:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-299-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hzwGOXol; spf=pass (google.com: domain of linux-kernel+bounces-299-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E78B4283DBD for ; Fri, 15 Dec 2023 01:01:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B61267E4; Fri, 15 Dec 2023 01:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hzwGOXol" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 31A8620F8 for ; Fri, 15 Dec 2023 01:00:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50bce78f145so112177e87.0 for ; Thu, 14 Dec 2023 17:00:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702602052; x=1703206852; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aeaw3ji0pg6zC2peZEVGQL9hjW+bOoI/oOULSseP2eQ=; b=hzwGOXolsVPC0dvo+rMI6/6DbZNOpzCbDFsy8Q1N97iUNkAxp+/zDGRvG21GzRYOKV /ACl2C9fDnUApnTEIANxgLjO5S0DW+bkv+adKveHNsGHTgllbHU8HmL/8yDcWSepsRB4 6NM7/Fsew/9IT1ckPHDjfXsGV6FaLkI8RDzqA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702602052; x=1703206852; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aeaw3ji0pg6zC2peZEVGQL9hjW+bOoI/oOULSseP2eQ=; b=ukJwMRmajAZQr9hi+b6epAwE1k8hoPn9hv6KpkJwqCzJAw6eHycwBTFGBL4QTd1/VJ WYp9gTupvcQ3z0PCjq0hvTOjpW0j+BkC0wRYALXX9mNUfuDJECVXs9npJaLr8VLqCWqR Mwqf3q8JKNJhzwUD1dxsXlWdqtgR5swcBqcBiTb8WOlcaDMDkhpoiQyc3PZojKPGx+i/ mFbOtUVYRB7RABQBRVkEwzf+nSXadeLdMoN3DQRXEPfcirYpXZvfPqTeHgmplikD9cKW j3Zp3H+Jb1lr8WzkQebbrdVsjV027tLIj0k6XnJC3cQJlirlE7t3NXYXKeYcbAea72r5 U/dQ== X-Gm-Message-State: AOJu0Yz648y/AcoS6KbvsKUGiq4kwcV/UdrrOSJpKiTchvAJdfoIl9op hK/K1bXLpBwl9Twl/3P+kpHihBAwff/tTbtUuGMZqQ== X-Received: by 2002:a05:6512:3b8d:b0:50d:1487:8d11 with SMTP id g13-20020a0565123b8d00b0050d14878d11mr3154911lfv.144.1702602052113; Thu, 14 Dec 2023 17:00:52 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231208070754.3132339-1-stevensd@chromium.org> <9fb51bfc-576a-4c7b-92c2-c161e7f08ae7@redhat.com> In-Reply-To: <9fb51bfc-576a-4c7b-92c2-c161e7f08ae7@redhat.com> From: David Stevens Date: Fri, 15 Dec 2023 10:00:41 +0900 Message-ID: Subject: Re: [PATCH v2] virtio: Add support for no-reset virtio PCI PM To: David Hildenbrand Cc: "Michael S . Tsirkin" , Jason Wang , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Dec 14, 2023 at 6:47=E2=80=AFPM David Hildenbrand wrote: > > On 08.12.23 08:07, David Stevens wrote: > > If a virtio_pci_device supports native PCI power management and has the > > No_Soft_Reset bit set, then skip resetting and reinitializing the devic= e > > when suspending and restoring the device. This allows system-wide low > > power states like s2idle to be used in systems with stateful virtio > > devices that can't simply be re-initialized (e.g. virtio-fs). > > > > Signed-off-by: David Stevens > > --- > > v1 -> v2: > > - Check the No_Soft_Reset bit > > > > drivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++= - > > 1 file changed, 33 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio= _pci_common.c > > index c2524a7207cf..3a95ecaf12dc 100644 > > --- a/drivers/virtio/virtio_pci_common.c > > +++ b/drivers/virtio/virtio_pci_common.c > > @@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev) > > return virtio_device_restore(&vp_dev->vdev); > > } > > > > +static bool vp_supports_pm_no_reset(struct device *dev) > > +{ > > + struct pci_dev *pci_dev =3D to_pci_dev(dev); > > + u16 pmcsr; > > + > > + if (!pci_dev->pm_cap) > > + return false; > > + > > + pci_read_config_word(pci_dev, pci_dev->pm_cap + PCI_PM_CTRL, &pmc= sr); > > + if (PCI_POSSIBLE_ERROR(pmcsr)) { > > + dev_err(dev, "Unable to query pmcsr"); > > + return false; > > + } > > + > > + return pmcsr & PCI_PM_CTRL_NO_SOFT_RESET; > > +} > > + > > +static int virtio_pci_suspend(struct device *dev) > > +{ > > + return vp_supports_pm_no_reset(dev) ? 0 : virtio_pci_freeze(dev); > > +} > > + > > +static int virtio_pci_resume(struct device *dev) > > +{ > > + return vp_supports_pm_no_reset(dev) ? 0 : virtio_pci_restore(dev)= ; > > +} > > + > > static const struct dev_pm_ops virtio_pci_pm_ops =3D { > > - SET_SYSTEM_SLEEP_PM_OPS(virtio_pci_freeze, virtio_pci_restore) > > + .suspend =3D virtio_pci_suspend, > > + .resume =3D virtio_pci_resume, > > + .freeze =3D virtio_pci_freeze, > > + .thaw =3D virtio_pci_restore, > > + .poweroff =3D virtio_pci_freeze, > > + .restore =3D virtio_pci_restore, > > }; > > #endif > > > > Am I correct with my assumption that this will make s2idle work with virt= io-mem-pci as well? > > Right now, all suspending is disabled, but really only s4/hibernate is pr= oblematic. > > [root@vm-0 ~]# echo "s2idle" > /sys/power/mem_sleep > [root@vm-0 ~]# echo "mem" > /sys/power/state > [ 101.822991] PM: suspend entry (s2idle) > [ 101.828978] Filesystems sync: 0.004 seconds > [ 101.831618] Freezing user space processes > [ 101.834569] Freezing user space processes completed (elapsed 0.001 sec= onds) > [ 101.836915] OOM killer disabled. > [ 101.838072] Freezing remaining freezable tasks > [ 101.841054] Freezing remaining freezable tasks completed (elapsed 0.00= 1 seconds) > [ 101.843538] printk: Suspending console(s) (use no_console_suspend to d= ebug) > [ 101.957676] virtio_mem virtio0: save/restore not supported. > [ 101.957683] virtio-pci 0000:00:02.0: PM: pci_pm_suspend(): virtio_pci_= freeze+0x0/0x50 returns -1 > [ 101.957702] virtio-pci 0000:00:02.0: PM: dpm_run_callback(): pci_pm_su= spend+0x0/0x170 returns -1 > [ 101.957718] virtio-pci 0000:00:02.0: PM: failed to suspend async: erro= r -1 QEMU's virtio-pci devices don't advertise no_soft_reset, so this patch won't affect vanilla QEMU. But if you add PCI_PM_CTRL_NO_SOFT_RESET to the capability, then it should work. I'm working with crosvm, which doesn't have virtio-mem implemented, but this patch makes virtio-fs work with no extra kernel changes. -David