Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319205pxb; Mon, 20 Sep 2021 18:42:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK9hHwaQMpSRm9n747u3E+9NsEtSr78jtBa3Ix871btRAfJE0i2NB8Jm/oEppLzW3h3m+W X-Received: by 2002:a6b:ce17:: with SMTP id p23mr21145947iob.90.1632188528265; Mon, 20 Sep 2021 18:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188528; cv=none; d=google.com; s=arc-20160816; b=B3GT5/e7SIMFJrav+G64A6PpwzdlyAgAk55slBZLeBPxzx+X0L7SLyfSDcw9vyNW1k DN4aR3dL7kFbLHCF8bJIAoO99bDe2zWr3hdzfGES9yCSqI6Tah1T/4opyrKBdvuPO9vI LnVmgt/YrsDReBvSjcZH7col3fPlkJGk7uso579Sf8JELTHYYGUeCZh7EJm5sAF0PORO 0VqNwaPO6aSucm3zdsz5N6Z/MnmlG4UNpnxtnuQUqFGZiU0PH4CS15s3ZfSVTMPbf9R3 epoceZOhTtRHNv7Pgz2I+d8uxNuflH0ZE3ldRZcCxlu4h8TknJFexbnY3JGs/zUZLsla 28uw== 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=figa4bYR6LayPpjxuS5e5CPVl52qy/FVFT/s0tYgS+4=; b=LtJ5HTfS3I+/eJktGISFItTHW1KPUqHvtfhHvL8doxZDw3Pk5hSPVkyQH6mL0Gk84X HgpJW12p090YXWJOiaszQDQ5HwM9RG7xiEKc26fwj/KNkC53O4k9HEKmmYXDvZcMkAH4 c/9I359CtG+Z/EA0K1Dn2Fw1oeV28WS4bD686deUMiBoCRCWAg9TMolCT+RQkWsE9Tzk GPqvDes+oEbG2Roqiq92iA85TuUZxeWmvDQ2jA3OqKn+ZnqeVXQQ9HH7Ytkx4cesMppb nQtlvtwM+0sfdn1j9m5BZ2KlBsDEiJVnIWk01NIWiKLsHuVfM4C78vkJMNXNsyNIt6NV hWcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gCNlWH+v; 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 b97si14760832jai.49.2021.09.20.18.41.57; Mon, 20 Sep 2021 18:42:08 -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=gCNlWH+v; 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 S245077AbhITQwZ (ORCPT + 99 others); Mon, 20 Sep 2021 12:52:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:38768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243931AbhITQtq (ORCPT ); Mon, 20 Sep 2021 12:49:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8818F611C2; Mon, 20 Sep 2021 16:48:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156500; bh=YmPQRvdcUn6aW+VEsVWSB85956OEFjMlJbqwezH0VDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gCNlWH+vaaIHeZE5GJZeeCqV3JwsLOdzY5xqW7vqlue2fR54EvvfDhYeUSUZ/YEHl qjU8HCI64Py2kK1owrQbrvnLmPUd6q5204+gfqAHCNVIWgF2+rKvNzZbxygTryPwsj 0IkGbw5MfKrqoLWrgckRmUELVcQoCrfDyM5t8NtI= 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 4.4 086/133] PCI: Use pci_update_current_state() in pci_enable_device_flags() Date: Mon, 20 Sep 2021 18:42:44 +0200 Message-Id: <20210920163915.461221923@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 216a1c880924..21ad9fea7878 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1334,11 +1334,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