Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1917360pxb; Thu, 16 Sep 2021 20:11:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKmdzQv6Yi1/rDNBjc3ut6TjFCDVXDbw5JEAvGMX+qrD/2UcAXVnkiIgDIdhIrrPTcaXcC X-Received: by 2002:a17:906:fc09:: with SMTP id ov9mr9826560ejb.128.1631848307217; Thu, 16 Sep 2021 20:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631848307; cv=none; d=google.com; s=arc-20160816; b=W3UsfXnaTrcVEwMsEE0GHEIooLQd2M/TQIdtK3ZFjHrW4RHucN9e/Wg3+JXLvoEGWh tol82PNRkogrB+VjMqQSFl2m7tAtsd6EoE/xRrJd9kcQRKUDASFiTq1C2OeSkG65FoaI 8xKtIP9SRVEUAqbkUSUTOG7SmnOurCdRdC5hQW90/lXXtQlMusUuC0gCpX4J9AXK14aR E/2lfRfgCTmAwGGQd/xqKCVv7IT5Pqtcsp71OvCh1OOjYmc222PAa9H0mqyJVqHRq878 ltIA/zjwpc3Jm9cxljs2gqpezK6jpwKmmjRJ5gZZYhL2jyeYjUdH5Lu6dcPYSkoxKicu 885A== 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=8tdcqdmkN5+iYzyzMfLCzYYfhwxy3QO9a02PcwGLiPM=; b=ZlUxYPldjoBQuxswnUhfdsc8Jhnc/bWgiM7SVwZNoVsGx6jWiyFJwvsiCilJlfX9v8 NHDUra+w1iCy4wKCq/Mf64N0fIVqUacKNaqSlWj1/FybHosynwbYHPZwufImhhYF0+QG 0QOEvWTtAh8ermCEJDXjDXHnSWsHdzAf27EO8A925hr/glB1Q12wiFty5akrrnYxvYSH /S5IxQK0lvEjGxKMedFWyWZFajO8E6Jh/mXnVYMon2iVh0kw1bofHRkiPT7H9dHh2JSQ v/8sOtaIY+u5HP7rPd1mFIhRO0+hFEbAtwX0jnePkF0vxdWQtuLgwIwXjLqtnV065QDH kWOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IFe58i2M; 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 p15si6895616edj.97.2021.09.16.20.11.23; Thu, 16 Sep 2021 20:11:47 -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=IFe58i2M; 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 S1353182AbhIPRaJ (ORCPT + 99 others); Thu, 16 Sep 2021 13:30:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:44122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352142AbhIPRUn (ORCPT ); Thu, 16 Sep 2021 13:20:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4129A61248; Thu, 16 Sep 2021 16:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810531; bh=olzobrIKd4IoztYYkvCA6RqN5vIoPKI8Bnm1t9GKjBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IFe58i2MxZmESzrXQycVMEhRE1E79WBNgm2Lv6xaMynG8ejj6KdmPHyC6rYSsWvnh iF+3pUqvVrCWtELVJwHuFQ/QiFwCCeSe0qpflGXT0TRxAGj2wn2SDzf2wZsUulgwW6 9DcLOCv7zi6a4u6mCa1JOzLHeam3xcqGpHxg+XIk= 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.14 176/432] PCI: Use pci_update_current_state() in pci_enable_device_flags() Date: Thu, 16 Sep 2021 17:58:45 +0200 Message-Id: <20210916155816.708973673@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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 3f353572588d..a5e6759c407b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1906,11 +1906,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