From patchwork Tue Jun 26 07:55:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 934705 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dEmNGMyA"; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41FJJ316Rvz9s2R; Tue, 26 Jun 2018 17:55:47 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1fXipA-00032g-Lo; Tue, 26 Jun 2018 07:55:40 +0000 Received: from mail-pf0-f193.google.com ([209.85.192.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1fXip8-00032M-6R for kernel-team@lists.ubuntu.com; Tue, 26 Jun 2018 07:55:38 +0000 Received: by mail-pf0-f193.google.com with SMTP id a22-v6so7713173pfo.12 for ; Tue, 26 Jun 2018 00:55:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=7GF1B9iJYNiR247EjdrRGCa4UegoDXGqngjBSOGopnI=; b=dEmNGMyAeHNGpnLRwXqTVLmQzxBgk2ST833hKjk/QSkVHGhnOxET2wKBoqbwxCXAGT GewffJsa8o1mTlUoN3xctcq8dtJSt7D8UkEllqOzgKTD7jL1GIcoY5G6dXWini8rugbE SN8BbBDhbIsJ/XV+puDOjoeYnwI7eqkf/fHBdd0KL3cdue5jd75n6zstbz24tKFGP93t jZHApwkjbvud2pX8z7ZmyHUl6tjmahj1WFRX11xXq/87sG949AzJTStikYxsKdrwjoaP taZkTt9F1q4Q7vVfJ0c5VPPsx7WYQwYoZGx9QSShmWqpBcs4njySKywDAuAhJwY6FZFq o+TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=7GF1B9iJYNiR247EjdrRGCa4UegoDXGqngjBSOGopnI=; b=bMOvM69flRqsjJywUQt7/V/Y/H1avj+2G/Akycffv0v9016ZYNXQ2cpZJAHhSz9c/T 4RYT11oHmM61vHzAqYtEEPHafLNL0/cHHCtPdnF1hdbVEPUfMCNXA8YIRohfkiCGXXts EiKu+8DN2Uo6Hg481BbRIujR3SHXxwGUBGifFkMXmJ4thFmTkxjf/+jmJmCiNO4PcpBy +ODUR3FrT9jVucvFEbObLmN5gfrBu61iFPQkzPE+CQn7PfbSSlLj3YskX7kUGJXDGC6p IJy9gdLjgRlw5ivCkCqPM0WeohmIdvgnyP9aRiVn0BXTaI9WXUC+CJT4XOttejlcTlWq iz1A== X-Gm-Message-State: APt69E20LalF1RghIo/uWUi2bHJltIzRbOX7+Kvz7T+09PSiTyK4x+8P jcRtty6VR1JlDu1U3mhqadxVvtf5 X-Google-Smtp-Source: AAOMgpcovj46FDdDLtngH66wssS0evc0W2aplqCL9rH6umVYKex6DWmW7+qOvJibowIFsG0xieKoGQ== X-Received: by 2002:a62:90db:: with SMTP id q88-v6mr495761pfk.186.1529999736329; Tue, 26 Jun 2018 00:55:36 -0700 (PDT) Received: from localhost ([175.41.48.77]) by smtp.gmail.com with ESMTPSA id g12-v6sm1579546pfh.164.2018.06.26.00.55.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Jun 2018 00:55:35 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/1][SRU][Bionic] PCI: Restore config space on runtime resume despite being unbound Date: Tue, 26 Jun 2018 15:55:30 +0800 Message-Id: <20180626075530.9200-2-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626075530.9200-1-acelan.kao@canonical.com> References: <20180626075530.9200-1-acelan.kao@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/1778658 We leave PCI devices not bound to a driver in D0 during runtime suspend. But they may have a parent which is bound and can be transitioned to D3cold at runtime. Once the parent goes to D3cold, the unbound child may go to D3cold as well. When the child goes to D3cold, its internal state, including configuration of BARs, MSI, ASPM, MPS, etc., is lost. One example are recent hybrid graphics laptops which cut power to the discrete GPU when the root port above it goes to ACPI power state D3. Users may provoke this by unbinding the GPU driver and allowing runtime PM on the GPU via sysfs: The PM core will then treat the GPU as "suspended", which in turn allows the root port to runtime suspend, causing the power resources listed in its _PR3 object to be powered off. The GPU's BARs will be uninitialized when a driver later probes it. Another example are hybrid graphics laptops where the GPU itself (rather than the root port) is capable of runtime suspending to D3cold. If the GPU's integrated HDA controller is not bound and the GPU's driver decides to runtime suspend to D3cold, the HDA controller's BARs will be uninitialized when a driver later probes it. Fix by saving and restoring config space over a runtime suspend cycle even if the device is not bound. Acked-by: Bjorn Helgaas Tested-by: Peter Wu # Nvidia Optimus Tested-by: Lukas Wunner # MacBook Pro Signed-off-by: Rafael J. Wysocki [lukas: add commit message, bikeshed code comments for clarity] Signed-off-by: Lukas Wunner Link: https://patchwork.freedesktop.org/patch/msgid/92fb6e6ae2730915eb733c08e2f76c6a313e3860.1520068884.git.lukas@wunner.de (cherry picked from commit 5775b843a619b3c93f946e2b55a208d9f0f48b59) Signed-off-by: AceLan Kao Acked-by: Kleber Sacilotto de Souza --- drivers/pci/pci-driver.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index d79dbc377b9c..8ed242a668c8 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -1226,11 +1226,14 @@ static int pci_pm_runtime_suspend(struct device *dev) int error; /* - * If pci_dev->driver is not set (unbound), the device should - * always remain in D0 regardless of the runtime PM status + * If pci_dev->driver is not set (unbound), we leave the device in D0, + * but it may go to D3cold when the bridge above it runtime suspends. + * Save its config space in case that happens. */ - if (!pci_dev->driver) + if (!pci_dev->driver) { + pci_save_state(pci_dev); return 0; + } if (!pm || !pm->runtime_suspend) return -ENOSYS; @@ -1278,16 +1281,18 @@ static int pci_pm_runtime_resume(struct device *dev) const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; /* - * If pci_dev->driver is not set (unbound), the device should - * always remain in D0 regardless of the runtime PM status + * Restoring config space is necessary even if the device is not bound + * to a driver because although we left it in D0, it may have gone to + * D3cold when the bridge above it runtime suspended. */ + pci_restore_standard_config(pci_dev); + if (!pci_dev->driver) return 0; if (!pm || !pm->runtime_resume) return -ENOSYS; - pci_restore_standard_config(pci_dev); pci_fixup_device(pci_fixup_resume_early, pci_dev); pci_enable_wake(pci_dev, PCI_D0, false); pci_fixup_device(pci_fixup_resume, pci_dev);