Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1530330pxb; Thu, 16 Sep 2021 09:19:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGW2bO2gdP90uobb2pb/vvfe9JBpN8abi+Frjf+q4iGioTehPRau/ELpJjhbuTVGxg0gJS X-Received: by 2002:a17:906:b0c8:: with SMTP id bk8mr7301220ejb.412.1631809178847; Thu, 16 Sep 2021 09:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809178; cv=none; d=google.com; s=arc-20160816; b=uuIechnPZW9xRflLpxDH/3LT3EG8uRh3NCanz5n7tJnZjkt3sKOZBtwow+7bQsGqdu 2TyvU+cv2lXYBQcY9hvL1yZPozHUdjRx0HSYUgWhiHi22mJ3c9hzIiXwReZ2pidKBQwI 7O1j8M87ndrdJpcVTdFu66jF7aQ1f/jLSKgemMKKw6iUWb7FhhwgrXHFDztjABuiLgkq JWMe6po3sU0Vrbfn+UryJXWvBFLakfs6pgTkcQqdBRW1ZMwCM9KtLhflAmprsISyvWcW frurq9K2N1ePFvYqc+TlMOGCyfJ68Dz4ajmQNE8hmIwBO57C0fGpYQ/p9as0ve+YsEWL P+eg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/v+QeJ/oh7Ozv/8E7uVSOcBx8vb8Mg2dm6ddfYGNqDA=; b=Nr4v2O5l+jyAzXNbfDlNvId9F3CU+lRY5QeOLFVRzUK+yZEDDPnsvW9lBM8qOPIqzr QOEI5gYXa6Y90Mv7ULdsJpRVwQxopTp1Bs/tb9XkBGeHjK6naKv0IaJ3pP8SlZ9SNh6l Qkftqr3DY+emXqIv4AqtTbc+3F9wz/9ILB+YPkrCyVmVlvs19NfxHtZCm9rogyH8A//g OB1rMoG9RHVYe0g0wx879rZaP4CLlnvD0SopQWmtPfzQ1rRfyJwvJOBmbvG880FinKtP OHVro/6hE2mtdbH8RfZZwP/98O8RlM2iV7UCvtBQ8kDw8wdJw2V7IBzOKfRofI1Q1O3g jOOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1u31975S; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t26si3825750eds.588.2021.09.16.09.19.15; Thu, 16 Sep 2021 09:19:38 -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=@linuxfoundation.org header.s=korg header.b=1u31975S; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234178AbhIPQSI (ORCPT + 99 others); Thu, 16 Sep 2021 12:18:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:48012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232867AbhIPQKb (ORCPT ); Thu, 16 Sep 2021 12:10:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EFB6F61263; Thu, 16 Sep 2021 16:08:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808506; bh=nUWogYyAQnIGP9PhkABR991SIxEYKSuFnYvAG0oKips=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1u31975SvNTOhZ1iHiMIMzuaVr1dBXFnYBPmLEJHvfUMoO8arRaKbxScnhoFM38D2 xo/4Vi00W73s28Ss/H9ZsbUkofQnKtC9VNCqg9tQoeETXwn83PGEv1e23Iui8ouBXN x1TrA7OWGEOQn6MiWHnAT6GH/LanNjMY3CfQY2Bo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maximilian Luz , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.10 117/306] PCI: Use pci_update_current_state() in pci_enable_device_flags() Date: Thu, 16 Sep 2021 17:57:42 +0200 Message-Id: <20210916155758.056539337@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki [ Upstream commit 14858dcc3b3587f4bb5c48e130ee7d68fc2b0a29 ] Updating the current_state field of struct pci_dev the way it is done in pci_enable_device_flags() before calling do_pci_enable_device() may not work. For example, if the given PCI device depends on an ACPI power resource whose _STA method initially returns 0 ("off"), but the config space of the PCI device is accessible and the power state retrieved from the PCI_PM_CTRL register is D0, the current_state field in the struct pci_dev representing that device will get out of sync with the power.state of its ACPI companion object and that will lead to power management issues going forward. To avoid such issues, make pci_enable_device_flags() call pci_update_current_state() which takes ACPI device power management into account, if present, to retrieve the current power state of the device. Link: https://lore.kernel.org/lkml/20210314000439.3138941-1-luzmaximilian@gmail.com/ Reported-by: Maximilian Luz Signed-off-by: Rafael J. Wysocki Tested-by: Maximilian Luz Signed-off-by: Sasha Levin --- drivers/pci/pci.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 05a84f095fe7..eae6a9fdd33d 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1880,11 +1880,7 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) * 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); - } + pci_update_current_state(dev, dev->current_state); if (atomic_inc_return(&dev->enable_cnt) > 1) return 0; /* already enabled */ -- 2.30.2