Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2446655imm; Mon, 28 May 2018 08:14:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrmY8Z5TauMBK25V1FCRgSGHV50mJRt0ELfg0CGCauzSnq6PraheG0YRbzjY9pNQign4DPz X-Received: by 2002:a63:ba56:: with SMTP id l22-v6mr10761663pgu.161.1527520458686; Mon, 28 May 2018 08:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527520458; cv=none; d=google.com; s=arc-20160816; b=hbABD5fSSd9Rl/BHYwaoIctazvgHyeIpLjDrezCJtLvua5b6ec4DM6RmXO6XgFh31I 1RIKYN5MHTWWuAZY5YLg0TJSwoPx4KaxqL5YyewTvs0pqjPrhDW7e/Asp3lE7TEA6kP5 vIQ8HjOIS2A1SlUulaTGhmmnJZcmPmMGic9A28/+FTFfy0WD8/g7dIaU8v3SwyPPXvwJ FLZToUd5HujJlzAJ8/48Ey1DQlABGYoIGfwhu68UzC4FeQNN/Ko5/kTgZUi2VkeVMw43 BG9qIF2Nxnxjkr4K6J5DhqOxK4MIgHFOPyI76j3SdMR+3rzmsliuVmXMysJfy7hCVw28 N4BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=DZJrUYtAjWUvojVkq3Yt+FzSk6+cP/NTTUSS8Y35ZR0=; b=hxgSFb93zB7eWwnXm2yjGzvyBGxiZ7vRzE9KQvSnuDFWqBWKPFIzG+Jy/nHbBBzOBa Zayzz26NtVUjEuAUw1PHQqqqfnBnurXFw0JhrEAxPfFkRdS8SqGXT0UPVtIqT13m8Yjd hyyhzh+HcqDfrE4ORGWHgzeODczlUvfwkw31aHcmAiw/jOiXsgnzr2QThX2i9PiX0mgp q7NvjdPK1MBKjZmHS5FGpV3DyMfbABxNMZCRBPedtkmFoP5IinEmYXUaqPMkvGdOIJ9c pKxzyl0e5KdunOXETs+O3LtEuFz9bmSul6vMcNajQSzyV7yHrne7iMKps5Zj4FkvFYB6 JjHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Hhgv2fdb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10-v6si24816953pge.596.2018.05.28.08.14.03; Mon, 28 May 2018 08:14:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Hhgv2fdb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033701AbeE1KXn (ORCPT + 99 others); Mon, 28 May 2018 06:23:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:42958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033286AbeE1KXf (ORCPT ); Mon, 28 May 2018 06:23:35 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7FE8B2088E; Mon, 28 May 2018 10:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527503015; bh=YJj4Iz3tY9rwcKJKaXmcgNAAeZB2Cv+u59hW28PKHoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hhgv2fdbfexw56apoFa+B9VC1wWZ3zO/altjGdatEiFxU1FSQ9a8XBFkWmd2dRQO8 OFwDuX8qzTdNMExP1u7TWO7bByh7e+zP/3NrI9b7Yw9fLW15NV1967ohmotlX93AJz WZMXOqsRnnRvwpvLqAzgiYpPMpkOVHorzphiSsKw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bjorn Helgaas , "Rafael J. Wysocki" , Lukas Wunner , Sasha Levin Subject: [PATCH 4.4 211/268] PCI: Restore config space on runtime resume despite being unbound Date: Mon, 28 May 2018 12:03:05 +0200 Message-Id: <20180528100226.090589268@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Rafael J. Wysocki" [ Upstream commit 5775b843a619b3c93f946e2b55a208d9f0f48b59 ] 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 Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pci/pci-driver.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -1140,11 +1140,14 @@ static int pci_pm_runtime_suspend(struct 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; @@ -1195,16 +1198,18 @@ static int pci_pm_runtime_resume(struct 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, true, false); pci_fixup_device(pci_fixup_resume, pci_dev);