Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp444075pxb; Thu, 9 Sep 2021 04:44:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1zhDeaoHSuQYcPObkYOG1ENKXeOZ3ldCrh465mXuzmxTXnLTxIRNcjEuYWceI7IeWdOUu X-Received: by 2002:a5d:8a0e:: with SMTP id w14mr2240831iod.94.1631187863662; Thu, 09 Sep 2021 04:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631187863; cv=none; d=google.com; s=arc-20160816; b=wcezHubP6jSqX5Y9LsgJ1VgNzENUyTt6hBsm7+tBlT5cYkb8JTzvcNF9yRAj4brSmZ iInnO+O8/I8i1GS8DQucrZ1Fd2Oecbymp8OQ0GkpunvS/TH6Vb7kogzY4gLlJhWrEVs/ H5ReevxLFyFPBVXNdbDgdQc++i/gQ9y7aD8iT+RGYsShUBL/Gxh0Vj8cXVvAi9f5stv7 Q2OdM8ZPsIP3tw3gCT+J1TbeNIHu6PUq03Xj8cW7Ll5Ohk2cxGRIhxdWL5LtGTvI0zP1 aXrIxnvlLI1E4AkVp6K6LbaVw0pG36RN7zvNueon/BzhLrgLeWYTRRdYsi8CCJLuHNxQ ohdQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hbkHP5keBqjROxHNS0KbFT6p3Jo5voJGxR7zhX04KsA=; b=KHISu5mnapdVZD/hFwg+vOFhTzKg0j5wbU8YcxUsFW+AMQQNv7Pa9MMslbC8FzfiQj 10YFNC89AZcWS45GKazop4FXjBvpQyvv6fNHcPHTy09YVXyv7AnYECArIzIXNVkgZrfV IUe+ChrCAVqe8EujjgIJgW3AMKglqTNsCdJAdOM3GlLLm4v1ak0PuTEqBqCsp47FVFEv cLntbUE19gTR4jxurAz+/ixuV3MdE1DDRDyYfHfvZkJ3Yi/OHRdWlp2H2kojRuCwqXnh q5TbKmk7CGearzFpqvsrwIuEb+C+/JveduXloS3V0F069q74rF7oCW1fBB0UvAKT35bs w8Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mz4BAoLR; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si1392156ilm.138.2021.09.09.04.44.12; Thu, 09 Sep 2021 04:44:23 -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=@kernel.org header.s=k20201202 header.b=mz4BAoLR; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238860AbhIILnu (ORCPT + 99 others); Thu, 9 Sep 2021 07:43:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:46218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236880AbhIILmo (ORCPT ); Thu, 9 Sep 2021 07:42:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AEB0C600AA; Thu, 9 Sep 2021 11:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187694; bh=eJ+0Z+Qy9lkosvtqT6qKeWiN6BcKO7cj0ZFRvHyGApY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mz4BAoLRUU22If6bvQwoNMxfHEtd66Ox1Dxe8evdke1f/DOplX9ebVojhWtR+de1w ciBPBzEhWUcZ3XH/h4OfBpMy0u24lWXhI3NMuuFLfKaIQPg5zgwcee/8VO0RH2kOAH whPVJZUjTgw0XbMNHNx+dCAlqfdeSmnNDFEcC2Uq+4UH7wkhyFRefDQRoYmp2y3icG Kp+lGUdiJdolITUiYwHUnJFpDIIE8UPCf5bs3Y59YVao24tVBUsOKsXLA0llpI+aAs M6PLqNfV9RjGAMSMUj/IY53H6KCECts5gFegr9+si9V0LBwYYJVVB19hCGYV3le2OW j55+3yZKZFESw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Rafael J. Wysocki" , Maximilian Luz , Sasha Levin , linux-pci@vger.kernel.org Subject: [PATCH AUTOSEL 5.14 021/252] PCI: Use pci_update_current_state() in pci_enable_device_flags() Date: Thu, 9 Sep 2021 07:37:15 -0400 Message-Id: <20210909114106.141462-21-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 aacf575c15cf..375d298659a4 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