Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1824602pxb; Mon, 13 Sep 2021 06:23:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1AzsYbro/h8RuyyE6WwCWvt1ZTRkDpNlUzkKVjQ7bvtoTJOsz1cX6EmN7Fdu6KS/YJ8RA X-Received: by 2002:a92:6904:: with SMTP id e4mr8062809ilc.311.1631539420518; Mon, 13 Sep 2021 06:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631539420; cv=none; d=google.com; s=arc-20160816; b=ELanW6N9nwdVkPP/qZnwVaUwXPHtLUzmSlKFbKPreaC5QVLLKIAcLsQHT2sBl06/MW 02a7bNyAGGhXLgyZpCFhIaNv08kXD56AMCAT9urMYwcEGH6PASczaI5Hu8rZtPFQgp3g 2iGMV8MLtweAQQgAlC+v4zG2CQMDw8fFeHqCV+APpnd7pKpq5WZqXYusMwsN4KWbtkm+ z72fOpp01MXG+ASsC5RF2YkihdusvokUM7ZM944qRDKQxxKrJdwcrc/QkL9EhXBKLeg0 MFtVRf3IS8rENKQjbYnEL04mYivJdR2uoPU3AND0ovTtbmxxETDXJ6hpUTw1ZOjmXutY 0/Uw== 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=Pc3r27RHSBxqL+MMft9Zna4GWmI1uCNHK5IEIsIG6L8=; b=A3PrrJpE8krr/cmVBcP+5aOwuhSLgkgRhzjxp8qV8l75ihjbRsuY9YI4/jGk+h0v9M yZM/dx7Qy+HBaYylO1a1quLIwroIxBwpKNBJyDWnQR2IFWui0LwckoqhTtuLV6jkajm7 fNsaR2ydFVNVN7PKJiURRCxM/fybEuQVVFmART5I8nm4cjM6QMK4OcxrQjDvzDIBNwmA GaVzTu9KYZbtb1RwtIW/lvGjtcYOT4p89nctPfs+bqQQ8MNNHV5MF2YyBTjLzbDjciMy jljyp+JfisC/xEzAdIOQS84m5C9gOzObPtZ4pNKeE12V2cn7Y+3xib8GyPyn+7MUlHeD wwxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VtfAQNbf; 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 w7si4268146jad.86.2021.09.13.06.23.28; Mon, 13 Sep 2021 06:23:40 -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=VtfAQNbf; 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 S240484AbhIMNXQ (ORCPT + 99 others); Mon, 13 Sep 2021 09:23:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:34836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240633AbhIMNVW (ORCPT ); Mon, 13 Sep 2021 09:21:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A691610A6; Mon, 13 Sep 2021 13:19:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539196; bh=vXc3gyTdGJmyCAXTxuIj6VefI1hdzzklojm1S/kS3us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VtfAQNbf3DOUNrNztfEZRl9ev4wIhsr8m8PjGMWqtpon5qTi4VxiVzH1Hpp9vtr4z 04M6QhmhiORcr/0TbEQiAsytYX7nsSwolDUH6QRsA3k1zbAdKblzdKiR10H7hapXQP s8WPhueImnz2W3yLIdasDNMwqDYwRcJLE6XgQdnY= 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.4 077/144] PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently Date: Mon, 13 Sep 2021 15:14:18 +0200 Message-Id: <20210913131050.544649976@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@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 3c3bc9f58498..9c4ac6face3b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2357,16 +2357,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