Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp163760pxb; Mon, 13 Sep 2021 16:00:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfluX9/tyIck4c4khwNbOwCv2zNYZUDtBMzsTgXRNg55JcEmu5c0c1twxaOK0feMkWIY/7 X-Received: by 2002:a17:906:f24f:: with SMTP id gy15mr12948875ejb.226.1631574034268; Mon, 13 Sep 2021 16:00:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631574034; cv=none; d=google.com; s=arc-20160816; b=MLyWfxvLHrUOIgs9m7cKD0Pb53yVWY2akcxX0YP2mWSdiNaMsnLILIOYbkSs12+5Vn r2AZvNETbi5TXFT75i+oGTNSmWBd9D9MmrdU8SsLOLP1V2vo3vU1BPaY/fGJqRY39r+a nv7+YS+VBbYQFeOOE2J+nVTgBZnHFJP6LieSUb7ehH5CAvpmab6k7PmlYnpkxFYCbjbV pZ5EigjpUxVdLUeRb+S+ZPV4V3oWch0JkedGsrLGbuopwfS6M/oyWmz+0pmvQAiuCV26 7UxcR6dmOMgsvSt8a5lwzAHIuT5WN5ClmRutT2WORKC9qKfbuDHO0CnukkqwiLRa0Zqy 01Lg== 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=M/BQ95jSURkz9BhoAHSFAjQM/OLy/tmLF1SOmDpSbkA=; b=Ki9EgVgI+YlmEXkN+poFFQDbk6hrCcIfGl2vRQZmcvTUfLN/TAVOW8eFqOyZxpKQTn bcVCwweF7F/7T9gYg6PAu53KW48kSTn7aXB3808uJWwTmrJ1a1vNk+YqZIFzj6UAg9nR PcFGg1ZmsRjVsw/bqqnKtBJBMjK5t9n3A8R+8FvmOxPHsS/9JeJ/NwMxKv019G5k/czZ hf3RTLkbGFu4Oux9u47hsKcvELAUA99Fq42JVHdecLIGe15X7KY/wh/KmqgT/q9FE6o/ C0PmCPEarsCAOxx4jm4awVi1DL9p2IWV52rLN0LMehBQsmDqhfRewy9HH7q6P3KqmX84 M0Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rEtKQShC; 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 w10si10631576ejv.754.2021.09.13.16.00.09; Mon, 13 Sep 2021 16:00:34 -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=rEtKQShC; 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 S1344822AbhIMOg7 (ORCPT + 99 others); Mon, 13 Sep 2021 10:36:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:51244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345301AbhIMObQ (ORCPT ); Mon, 13 Sep 2021 10:31:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E6EEE61BB3; Mon, 13 Sep 2021 13:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631541109; bh=16CFAAOKxWPjXsMJMbgncOT45e9FSjHBloffI6zDXL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rEtKQShCAicNzuFYuxMcp0harL9H2f9lj/qOAMeQe1PFl/VyiTDnRNzURDQAwYojL d6Pg6tNEihTEaKCsZvh9pcvUpdWum2akQgxGfLsz9VnvM/CfyuYZ6XTxxpUhH7TdKC 89qW6q3Rjxwt9Vny0oSJlHPTihkV2DVYsPqKi1e4= 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.14 165/334] PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently Date: Mon, 13 Sep 2021 15:13:39 +0200 Message-Id: <20210913131118.918628086@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131113.390368911@linuxfoundation.org> References: <20210913131113.390368911@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 aacf575c15cf..28bac63525b2 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2599,16 +2599,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