Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2567497lkm; Mon, 20 Sep 2021 18:55:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzedAEyVnndx5JjZTxIEAQ88o+dhai5vrdHpoqiCjMwSWZUjuXOJzDAUvc+WE8DxtamSLF/ X-Received: by 2002:a05:6638:2588:: with SMTP id s8mr21738304jat.43.1632189313231; Mon, 20 Sep 2021 18:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189313; cv=none; d=google.com; s=arc-20160816; b=xJkrQ46FLP8YJodMRcQi2j+xLWcQFOa5wgGhgQglqJd/0H/psm9A6ocHTRcTD6/T7i bAisnASzuOH3tgW3NPsr9UYLv+jOC+PDbUggIlnpDJAtDMvUbg4ESK8Gw9FYQkuVq6fu zJ91w2VSJnpeTVrNuZjfXKFQ8sS30tbG2VqZwcC2MRF9f75pRIjak66MVduaXnNcCGq9 HjfS5CeeDtSbkcXzhQivqCe7jkGs3OrxI0hwXpuYBOd+UNb69Xtk64561ulcb0nKyz/A ZAj2saxw+VA9sxvVR9olLbn3JEvXWkoPrEU5OD+yCYZygfhhMuEaAlyYv99wxue8DVX4 4EAw== 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=BDj/+iQB6B/0c8gahKQmisy18xpm9EyO9jozdUNpJWs=; b=q8vkWMWIgxNnFHMQUYHKO6WRcRnv1k4Bb+6yL136Uzj9TcGMtTVzFlEM9icfxAM+QW e3MyLuGm7Zak1kC2EltVbGMMSpLWyW5msAt4e/hE+yxdQA9j5dvmPdy1wpwAwIf4OOZb aJ5JSfcA827lw4UtAjvl5XJWEn7vzzrbIiIbI5w1ui73xS7DvOeKh+EnX4HUqtPpswCp ragYlsg2IX2m69gNge4DBd4Q/873wv/JdFYeLly3NVN91FoqRciShF/HGBHiOy0EJBLV /4P/q1p8SNOOkwOCK+/RMhOb8/0tKs8Bis8uopNMM8DNNwH4u7dh9mQVBTb3C5vEHxoQ 8G3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZQD4mizz; 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 d10si13586802ios.58.2021.09.20.18.55.02; Mon, 20 Sep 2021 18:55:13 -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=ZQD4mizz; 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 S1377513AbhITSTS (ORCPT + 99 others); Mon, 20 Sep 2021 14:19:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:33072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358096AbhITSF0 (ORCPT ); Mon, 20 Sep 2021 14:05:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 82E79619F8; Mon, 20 Sep 2021 17:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158265; bh=nvB+kxdE2/bCuWP15cGyfj9DM+8pzf5lSucXuRagoMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZQD4mizzZG+dtA3Fa4y9eJHr+wfaKeL80rzyNYJKugjpzefa4JMr+Tb4V25qjVjPL MSOkxR7E4TU7zxefKRiLeN/AXsEELZC9lJyutfeiPkgJU8S7VBbS/pT8CplKlmzLnD dgCoyYCcaiyTiBEmUXJcJQgan44840H0Nv19OlrM= 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.4 076/260] PCI: Use pci_update_current_state() in pci_enable_device_flags() Date: Mon, 20 Sep 2021 18:41:34 +0200 Message-Id: <20210920163933.718936840@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 58c33b65d451..91b2733ded17 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1672,11 +1672,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