Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3599352pxv; Mon, 28 Jun 2021 08:17:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlUuiahC5sHGJkln7iPINhjwSR739jQX2Y1Fw6zgs3G0gPVefxgj5tSYhy7bzhBiTiqxdO X-Received: by 2002:a17:907:1c98:: with SMTP id nb24mr3846672ejc.316.1624893422469; Mon, 28 Jun 2021 08:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624893422; cv=none; d=google.com; s=arc-20160816; b=a91sB2dYovUVV+H80U/w5VpyW6JsY2oCeE8n2mVYimu14a49UufRUiUVA2X9ZfzcLo K5xeocKgo+0i4K78cx6t358usBCx93HQGKSed44YejliEe/9uCbte9yK3G+G/nkl3ENZ iIVz/lxk13+vbE5iNBhlK9+6YqdvkB0J9NVxNd1ob+MsRE3+TRUgJDheyRau3orFbfzm B7meZTjisrwHzhtATW6hmLztgZZuv2iS2VjH8ym8SCQJiEYqYEKRTVLmmul9yHlEKmzg Z8OYxIf/qK/+imn7gDU3PXUXG5peQaCjFQvk40806OEXDcMJ4zC9iYAJwoOttGawRfM1 FzbA== 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 :dkim-signature; bh=i921t957RlJoMIAx9V7gykVRa/aj/CF+fNbvV/LeCbs=; b=041jMwMXv6GYlnEvgrLNksFeNFHGj+R7T/PAPyMLjsBLsD0yQfpBpzzYsOwVPMgTQh 3oBPUDksBq30E9orrwVAejGHs4ng0SyUpy8O2SW5LB8PSWl8voeBUc23bdyAHbOrG84p MugHoT5bdOGsTNMXHQkZcoEMO6rZkzQ0tH4OFwBms3Q09hijkghz9dCYPXRrAqgtsu7p 1E0iOpP/gq+ge9T6QDhUnzfuSoNUR897l5ONDFcgebsJ2zT1nevUL8lVhrdVP5JAL9Et QjbvUVu/pYsIcK5Y/JMkO/z1h4gdOC+cGvwece1hR4NTfvNV3yucFWWiCi9jRBGAjocx zGow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UmIiC1UY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq14si14665059edb.313.2021.06.28.08.16.36; Mon, 28 Jun 2021 08:17:02 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UmIiC1UY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238030AbhF1PPP (ORCPT + 99 others); Mon, 28 Jun 2021 11:15:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:33262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234901AbhF1Ox5 (ORCPT ); Mon, 28 Jun 2021 10:53:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2AD9061CA9; Mon, 28 Jun 2021 14:37:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891051; bh=Vj2kfJcUEP9mSkBDfF3JGz4SP+s2eiib2xTQ3CR/biU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UmIiC1UYS7KyYfRlzQ7IYfEPyz9sMzF9FNSMnSYRTU5qAJ3k0v3VOytGfCjxvdwJu DWK7KzO20T59gVMS/dzNUnFZFiYneZWEPUz5BrrYweHtJhfzpzeVbAsmxSeucPdvKU WDoEUcozNJ6XMfCTU9THYZ/bPX6mSblpVmsO/VzcDd7SDTnsKG29zUVoKGVhogX0qQ 1TYzvYP0S9VYbqSnyie3uNagkr5IOg1KmOhx3uW+uNgiijkby5amw+KyGwdJ/KJqhY Ks4nwm8WKyrUaf6O5luva5tVxJ0REFlm7TttbO/JYvVyG4qwL9eTuEy9jlc3S7Z/2L iVCMauZPCg06A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Rafael J. Wysocki" , Michael , Salvatore Bonaccorso , Sasha Levin Subject: [PATCH 4.14 71/88] Revert "PCI: PM: Do not read power state in pci_enable_device_flags()" Date: Mon, 28 Jun 2021 10:36:11 -0400 Message-Id: <20210628143628.33342-72-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Rafael J. Wysocki" [ Upstream commit 4d6035f9bf4ea12776322746a216e856dfe46698 ] Revert commit 4514d991d992 ("PCI: PM: Do not read power state in pci_enable_device_flags()") that is reported to cause PCI device initialization issues on some systems. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=213481 Link: https://lore.kernel.org/linux-acpi/YNDoGICcg0V8HhpQ@eldamar.lan Reported-by: Michael Reported-by: Salvatore Bonaccorso Fixes: 4514d991d992 ("PCI: PM: Do not read power state in pci_enable_device_flags()") Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/pci/pci.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 1993e5e28ea7..c847b5554db6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1378,11 +1378,21 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) int err; int i, bars = 0; - if (atomic_inc_return(&dev->enable_cnt) > 1) { - pci_update_current_state(dev, dev->current_state); - return 0; /* already enabled */ + /* + * Power state could be unknown at this point, either due to a fresh + * boot or a device removal call. So get the current power state + * so that things like MSI message writing will behave as expected + * (e.g. if the device really is in D0 at enable time). + */ + if (dev->pm_cap) { + u16 pmcsr; + pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); + dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); } + if (atomic_inc_return(&dev->enable_cnt) > 1) + return 0; /* already enabled */ + bridge = pci_upstream_bridge(dev); if (bridge) pci_enable_bridge(bridge); -- 2.30.2