Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp55374pxb; Mon, 13 Sep 2021 12:47:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXJeJGYhxHPsrSlTtYn0D5HGJ7jf3Vm/gPEl3Cixz6KLi1NFJyuZVMv/x9zykltIVbj5pv X-Received: by 2002:a17:906:2691:: with SMTP id t17mr14277482ejc.522.1631562433345; Mon, 13 Sep 2021 12:47:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631562433; cv=none; d=google.com; s=arc-20160816; b=b9qAMxjvjg65v339KVXuPlv2oN2DKPEqQDj6fbGpm47r/oEhNK5nYfBG0LqFXIoycV 5nR/YeEzuM055kM/CfMhAr3pEj+LoCKWngMkudxm+qJt978r12xYWiOHtHmC4qKH+KJY NpAJ+XVyI2gCmKdx2fLfdaZoyXA4hWNBc/jao4i6JARXd/sMeJthGHle2+LUv210Pggi AHXzcY9ApV8nE2IJO2zrv39LeqgHOFs3HY11AXIHqYtkTuG2OMRU2nwQZu7YZseEFXRO PY2BQXBNsxWLEtmkANkrUnWfSYDtTfPf5HVhY44ofRfnr5UKQFaWxh9cQs35mxmm7Rin NZMQ== 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=ofaXjDNJbD35tjfOzYUsmVSrkX+MAsjp9tfdyIB4ZjI=; b=0uNq51OU/AzM2EjCI9CQD8ok4aUoYh83jxf2MfaAYXAy1BAlrGL9RTB7KGi1o+ZojM 0MCPEP1jez3ZALjtBqHffO4jr7Hb6YZ6Jx1aYID6kZRC4W7uBxf4t/YZ758Fw4eiToJr DRCwKb4WzuuFrjIrLatlaBoPZl6xPjirMArVje5jvdaPZvzssI3mekKEzq+URRTt+9lO FnVPCG6GSA1krNXKPgmZ3KWh70Lp7e2Vl2LefoozelyADF27EFgqwA1YNjm6xUpjuhEv dZUOGrX48aaOzkNzR9uaaT48kvgA6rtxnxMHJXEWEoR40Bnb0ug3ykQlW5jHCDk/TJTe s5+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2DX3Yu4c; 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 v4si11682168edj.423.2021.09.13.12.46.48; Mon, 13 Sep 2021 12:47: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=2DX3Yu4c; 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 S242670AbhIMNnX (ORCPT + 99 others); Mon, 13 Sep 2021 09:43:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:37704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243121AbhIMNiS (ORCPT ); Mon, 13 Sep 2021 09:38:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8607F61251; Mon, 13 Sep 2021 13:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539699; bh=vsG4H9Q4RZutASu32BAUDE4PphSf7wHTU9Z9KiHYfaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2DX3Yu4cFGAzYazYTNVRopwOuJfpLWZ3bxQo3XkfE/n/E8pqCqljPTmG2ChbF6fsj NRdw13p62XWQDKkNNqxCUDshU/Wdo3ZPfT7XtwHwE7L4zOp/DhWiBq1XS1L6mHpjsg 1KrVPfIrNY4hN/sdLRCtNZEUQu9VkkSxxqI0U5W4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mika Westerberg , Utkarsh H Patel , Koba Ko , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.10 125/236] PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently Date: Mon, 13 Sep 2021 15:13:50 +0200 Message-Id: <20210913131104.609822932@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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 da9f2150684ea684a7ddd6d7f0e38b2bdf43dcd8 ] 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 Reviewed-by: Mika Westerberg Tested-by: Mika Westerberg Signed-off-by: Sasha Levin --- drivers/pci/pci.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 9e971fffeb6a..d864f964bcae 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2573,16 +2573,20 @@ static pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup) 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; -- 2.30.2