Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6209794pxv; Thu, 29 Jul 2021 08:56:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5qaZhqBkMNh1oF3kigz43V3O7Mnfo552ImQz8J0FUvDrzNVcHl94NusOXwXHyMVo6OwDi X-Received: by 2002:a05:6402:291a:: with SMTP id ee26mr6924015edb.220.1627574187751; Thu, 29 Jul 2021 08:56:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627574187; cv=none; d=google.com; s=arc-20160816; b=k38nvCwm9oxLQ31O8B33LtGC3ljmE3nj05kOSHacoZ4LhEkOkWu/VEYhqcICQDqMTC MLhwJg6z8nXpIywcLGNKV4dqNw/sFRujauINRz5YM5tiolX7qeWC5g7tKEU+UAJTVlu+ wALFCmXDTg3kTwXMAikdcUMDoGXVMKlDS2r4Px+mif8drz79xsG0870eBc5VlT1DXl8F aS0rgcJ/x3sPCROqMx7jHhUigw4BETSjP2ZoEjf1aEZ13IB/3Xce0Y+rXoOJY2TqhUNQ ja70mQUgrqGSV8+VfPF/F+u5CbY9WIAoRx5B9VmODBE9tUeql4JiPaXaRAzOlEk2Yo0T /cZg== 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; bh=w9fCFGiPirtbub6T9c5z3213dbIoM9WBIUErKCvKGNs=; b=RDZkW5HXf4ulV2YFuk9w/LOExMwSgU+eZw8vFhGBJPnrr0GqqaTVdbZd/HVu04ZTyo ZS+jEQrzQ8suHDPrnswNIdgmlvPPsLO96eWOr6gNYVES4jowuivs22KGdXfTufkfseHo Y+pXch8lbDGWlcslagZN3Jsd/JJhWNuJggCa0zcs/Sb1HnKjSkQ58UOlNmsEYkRNHPa1 b4WpineTWqUcHpm8jEgVLsYRv5kTz4MBRHPVH4Di+vDakzhGDlGoX+1gOtMivDhgvl9d 5gHNJmoRIj7BsYv5itbyRMKrZEiBovNrbwr67YXKwJf4dNW1iu6w59TcbnGWDfpwwJ27 Mc1g== 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 z15si3228169ejp.76.2021.07.29.08.56.02; Thu, 29 Jul 2021 08:56:27 -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 S237987AbhG2Pyg (ORCPT + 99 others); Thu, 29 Jul 2021 11:54:36 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:60716 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237875AbhG2Pyf (ORCPT ); Thu, 29 Jul 2021 11:54:35 -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 3.0.0) id fea072fe12c31b53; Thu, 29 Jul 2021 17:54:30 +0200 Received: from kreacher.localnet (89-64-80-223.dynamic.chello.pl [89.64.80.223]) (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 564DC669F29; Thu, 29 Jul 2021 17:54:29 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PCI , Mika Westerberg Cc: Linux ACPI , Linux PM , LKML , Bjorn Helgaas , Kai-Heng Feng , Utkarsh H Patel , Koba Ko Subject: [PATCH v1.1 1/2] PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently Date: Thu, 29 Jul 2021 17:54:28 +0200 Message-ID: <2593738.mvXUDI8C0e@kreacher> In-Reply-To: <2207145.ElGaqSPkdT@kreacher> References: <4668274.31r3eYUQgx@kreacher> <2207145.ElGaqSPkdT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 89.64.80.223 X-CLIENT-HOSTNAME: 89-64-80-223.dynamic.chello.pl X-VADE-SPAMSTATE: spam:low X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvtddrheefgdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegoufhprghmkfhpucdlfedttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepteeggfelteegudehueegieekveduleeuledvueefjeefffegfeejudfgteefhefhnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepkeelrdeigedrkedtrddvvdefnecuufhprghmkfhppeekledrieegrdektddrvddvfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekledrieegrdektddrvddvfedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedprhgtphhtthhopehlihhnuhigqdhptghisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhikhgrrdifvghsthgvrhgsvghrgheslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgv lhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehhvghlghgrrghssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrghirdhhvghnghdrfhgvnhhgsegtrghnohhnihgtrghlrdgtohhmpdhrtghpthhtohepuhhtkhgrrhhshhdrhhdrphgrthgvlhesihhnthgvlhdrtghomhdprhgtphhtthhopehkohgsrgdrkhhosegtrghnohhnihgtrghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=9 Fuz1=9 Fuz2=9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki It is inconsistent to return PCI_D0 from pci_target_state() instead of the original target state if 'wakeup' is true and the device cannot signal PME from D0. This only happens when the device cannot signal PME from the original target state and any shallower power states (including D0) and that case is effectively equivalent to the one in which PME singaling is not supported at all. Since the original target state is returned in the latter case, make the function do that in the former one too. Link: https://lore.kernel.org/linux-pm/3149540.aeNJFYEL58@kreacher/ Fixes: 666ff6f83e1d ("PCI/PM: Avoid using device_may_wakeup() for runtime PM") Reported-by: Mika Westerberg Reported-by: Utkarsh H Patel Reported-by: Koba Ko Signed-off-by: Rafael J. Wysocki --- v1 -> v1.1 * Resend under a suitable subject. --- drivers/pci/pci.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) Index: linux-pm/drivers/pci/pci.c =================================================================== --- linux-pm.orig/drivers/pci/pci.c +++ linux-pm/drivers/pci/pci.c @@ -2595,16 +2595,20 @@ static pci_power_t pci_target_state(stru if (dev->current_state == PCI_D3cold) target_state = PCI_D3cold; - if (wakeup) { + if (wakeup && dev->pme_support) { + pci_power_t state = target_state; + /* * Find the deepest state from which the device can generate * PME#. */ - if (dev->pme_support) { - while (target_state - && !(dev->pme_support & (1 << target_state))) - target_state--; - } + while (state && !(dev->pme_support & (1 << state))) + state--; + + if (state) + return state; + else if (dev->pme_support & 1) + return PCI_D0; } return target_state;