Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp454356pxv; Thu, 8 Jul 2021 06:26:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx0FmM+gde2NgnT8EOuGMIyWhj8GFwl0UEN4bsKLFSg2T3IbFEi6zTo4+Db4d2CM9n22Sm X-Received: by 2002:a05:6602:3403:: with SMTP id n3mr24267580ioz.165.1625750785660; Thu, 08 Jul 2021 06:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625750785; cv=none; d=google.com; s=arc-20160816; b=U38k5O15OGsQcoxHFp7N7ybd/PVwjfMJUrb/rDxmxKYITz10poodc3L5K+T3Js482o VEXyamLX1NshIF9uGhNq+fe/P0F1Oh2DtQVNObnN9d+gCvijyZ/cWYpqyixhM5fiumyr JZV56jEJ1QgTVGw5i/EhzoiJSUINQwJs8r6uDvIA8gnyHd8vofe2U2pylmns2cCH+wTB n+q0AaIXHpIX5dQASASHDQB8Uw85dbzxdbfGLlICah5rSwl9I2/GU7hTjM8v0x0HqfNi j6cBHFH6DKNGk3/ffRWa3XjV8VZPootogwTC0xwlu+iCh2wulOA7prZmR361QDmHctKc 8MmA== 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 :message-id:date:subject:cc:to:from; bh=u+QK3l7hv8cj0nTJkhRUYtGgtMQZkRaLvbMgilH7beM=; b=N3MVFKuUWx5GiOrhse2KdGnfn2yq4K0QONumYqhGr3hMlyhuBmJiyBBS7kUSMX6VaJ Trm85YEt9cLFOvVlCiak3/PwuR0Q1D6PdN2h6NGkpqpG1PSCB4XdkVNZpKaLpVFfRVfX W5wlRpCQ9D/HTKqTJLWBHBQWxsqMkAN/PZKn3B7t+NWbeudaHjP6jTBIzpKZAU0wlFEJ JuCI4DWFZ0MIOyxXmUDeVZncEvTthmqDIlaGUESg+SioeoJMiOcFcqKPevzYFHhDJ1Bs /8DBS9+nAtmRj5q+VaAVpO7qTKwepENAEiMbQ2JhmQliFbXmvjZk8GNTMUyETA9dSDua PWdQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si2235300jaj.94.2021.07.08.06.26.13; Thu, 08 Jul 2021 06:26:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231742AbhGHN1v (ORCPT + 99 others); Thu, 8 Jul 2021 09:27:51 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:54244 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229901AbhGHN1u (ORCPT ); Thu, 8 Jul 2021 09:27:50 -0400 Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 2.1.0) id cece774477dad180; Thu, 8 Jul 2021 15:25:07 +0200 Received: from kreacher.localnet (89-64-81-140.dynamic.chello.pl [89.64.81.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 981EA669C1D; Thu, 8 Jul 2021 15:25:06 +0200 (CEST) From: "Rafael J. Wysocki" To: Maximilian Luz Cc: Linux PCI , LKML , Linux PM , Bjorn Helgaas , Mika Westerberg Subject: [PATCH][RFT] PCI: Use pci_update_current_state() in pci_enable_device_flags() Date: Thu, 08 Jul 2021 15:25:06 +0200 Message-ID: <4327888.LvFx2qVVIh@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 89.64.81.140 X-CLIENT-HOSTNAME: 89-64-81-140.dynamic.chello.pl X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvtddrtdeggdeivdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkfgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdevgfetueetheekudeuvdduteelvefftdfftdejjeeukeffteeikefgiefghedunecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepkeelrdeigedrkedurddugedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepkeelrdeigedrkedurddugedtpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhrtghpthhtoheplhhuiihmrgigihhmihhlihgrnhesghhmrghilhdrtghomhdprhgtphhtthhopehlihhnuhigqdhptghisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthht ohephhgvlhhgrggrsheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhikhgrrdifvghsthgvrhgsvghrgheslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki 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 --- Hi Maximilian, Because commit 4514d991d992 ("PCI: PM: Do not read power state in pci_enable_device_flags()"), the issue addressed by it is back, so we need an alternative way to address it. Can you please check if this patch makes that issue go away? Thanks! --- drivers/pci/pci.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) Index: linux-pm/drivers/pci/pci.c =================================================================== --- linux-pm.orig/drivers/pci/pci.c +++ linux-pm/drivers/pci/pci.c @@ -1906,11 +1906,7 @@ static int pci_enable_device_flags(struc * 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 */