Received: by 10.192.165.148 with SMTP id m20csp1123930imm; Thu, 10 May 2018 06:05:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrlUMh/9APk7ER+p4CLuDq2i4zomh6rxcOXn/51fAiKPLIM7ZmD5kHPwgMHKIvv2QSyLyKh X-Received: by 2002:a62:f24a:: with SMTP id y10-v6mr1352322pfl.75.1525957558751; Thu, 10 May 2018 06:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525957558; cv=none; d=google.com; s=arc-20160816; b=sxWEmf4d5mC56MVF4b/5A2p408tXxtZCM0Al9aJbqXc8GtLG1A0vZTL3CyDUSIunKT 4cp610+hf2cSHfc/vc5mMqk8HfTqZMhSHBI0iQBZCLfCEuZXJYN2lrVeAgJnhxsoJax/ R/L+TEfqbw1ifqdtk0TWn5MCQ1+CqNOZ7BXErM1pJXh6u26z2kVPDvp7lQJEMnNvu/Vn 104qdMZMzun8QpnsTGMlxHpbbd/SsQTb2to9Rvo8WNIy6RVH2Dqqevpb2qqHEFKU/Tom gnIlm77hQLEYIG6c5yf6XuNboz3GWnlYe+USE7WttlDD/vwsYJl12k3b+fOQ9MfrkcWy Rx0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=KuQTU1dHyOAgOcqK7QWsC+ADxaxyYXo4aKi4mXvPSPw=; b=jnxJU+0AkKvjEfD5Vv13cJXZ7XwXc/M7TbwyGXXaHXT6Z/BDIn+Ko40NgJDXRQVnqr TyZBJVVFh8mG5ZlLmxDGl+bI+mKnhXpSNhRcSb921SNMgCbQs2C57cLdeMYWBM3c1eF/ p5xEdZBsWRoNdiUjYQm84n00PmEYbNfm5ZA8Py5NJAtvdHESNhgQouDpeZr+OYMApaC6 u5ZjMWqx9+547Kj7kjMZJ4kvllCrTb2XzryLBkbdrsJvH79jWVF9PQsu4RjVr77YzwYq i3m33jXuXwv89gbwvaFmSRUUI+MnmVOvgcLTIfHio88ZzBSikXKgzuVbowRVthFGOdcO UB2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D+lQXsPv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id a92-v6si769189pla.291.2018.05.10.06.05.39; Thu, 10 May 2018 06:05:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D+lQXsPv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S964963AbeEJNDr (ORCPT + 99 others); Thu, 10 May 2018 09:03:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:41626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934380AbeEJNDp (ORCPT ); Thu, 10 May 2018 09:03:45 -0400 Received: from localhost (50-81-62-164.client.mchsi.com [50.81.62.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B72A921784; Thu, 10 May 2018 13:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1525957425; bh=1sBEYy5kseTHQ193L2rmyiP1GcKWRngCrj2Viuj0IKk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=D+lQXsPv8wqtga/h3qtRmZ4mKiOXtQtdsDcefL2YW7hFHr7XumC8P6KfXvh/gJZl6 SMLxjBUh9VrlGPcPFyqDlmnxPGQMGp/u0ic1U5gE9M+1xSs9VfG2LCi2F1uEuwMreJ 134lf9IaT4ONW1cLKbKPZDuzk+8lluDfX5XoYMCs= Date: Thu, 10 May 2018 08:03:43 -0500 From: Bjorn Helgaas To: "Rafael J. Wysocki" Cc: Joseph Salisbury , bhelgaas@google.com, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, "linux-kernel@vger.kernel.org" , 1745646@bugs.launchpad.net, Mika Westerberg Subject: Re: [PATCH] PCI / PM: Check device_may_wakeup() in pci_enable_wake() Message-ID: <20180510130343.GA173327@bhelgaas-glaptop.roam.corp.google.com> References: <56a8953c-d833-837c-57d5-fe758d4db02a@canonical.com> <1823373.ea0yBGqyI6@aspire.rjw.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1823373.ea0yBGqyI6@aspire.rjw.lan> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 09, 2018 at 12:18:32AM +0200, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > Commit 0847684cfc5f0 (PCI / PM: Simplify device wakeup settings code) > went too far and dropped the device_may_wakeup() check from > pci_enable_wake() which causes wakeup to be enabled during system > suspend, hibernation or shutdown for some PCI devices that are not > allowed by user space to wake up the system from sleep (or power off). > > As a result of this excessive power is drawn by some of the affected > systems while in sleep states or off. > > Restore the device_may_wakeup() check in pci_enable_wake(), but make > sure that the PCI bus type's runtime suspend callback will not call > device_may_wakeup() which is about system wakeup from sleep and not > about device wakeup from runtime suspend. > > Fixes: 0847684cfc5f0 (PCI / PM: Simplify device wakeup settings code) > Reported-by: Joseph Salisbury > Signed-off-by: Rafael J. Wysocki Acked-by: Bjorn Helgaas 0847684cfc5f0 appeared in v4.13, which raises the question of whether this problem is important enough for a stable backport. Up to you :) > --- > drivers/pci/pci.c | 29 +++++++++++++++++++++++------ > 1 file changed, 23 insertions(+), 6 deletions(-) > > Index: linux-pm/drivers/pci/pci.c > =================================================================== > --- linux-pm.orig/drivers/pci/pci.c > +++ linux-pm/drivers/pci/pci.c > @@ -1910,7 +1910,7 @@ void pci_pme_active(struct pci_dev *dev, > EXPORT_SYMBOL(pci_pme_active); > > /** > - * pci_enable_wake - enable PCI device as wakeup event source > + * __pci_enable_wake - enable PCI device as wakeup event source > * @dev: PCI device affected > * @state: PCI state from which device will issue wakeup events > * @enable: True to enable event generation; false to disable > @@ -1928,7 +1928,7 @@ EXPORT_SYMBOL(pci_pme_active); > * Error code depending on the platform is returned if both the platform and > * the native mechanism fail to enable the generation of wake-up events > */ > -int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable) > +static int __pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable) > { > int ret = 0; > > @@ -1969,6 +1969,23 @@ int pci_enable_wake(struct pci_dev *dev, > > return ret; > } > + > +/** > + * pci_enable_wake - change wakeup settings for a PCI device > + * @pci_dev: Target device > + * @state: PCI state from which device will issue wakeup events > + * @enable: Whether or not to enable event generation > + * > + * If @enable is set, check device_may_wakeup() for the device before calling > + * __pci_enable_wake() for it. > + */ > +int pci_enable_wake(struct pci_dev *pci_dev, pci_power_t state, bool enable) > +{ > + if (enable && !device_may_wakeup(&pci_dev->dev)) > + return -EINVAL; > + > + return __pci_enable_wake(pci_dev, state, enable); > +} > EXPORT_SYMBOL(pci_enable_wake); > > /** > @@ -1981,9 +1998,9 @@ EXPORT_SYMBOL(pci_enable_wake); > * should not be called twice in a row to enable wake-up due to PCI PM vs ACPI > * ordering constraints. > * > - * This function only returns error code if the device is not capable of > - * generating PME# from both D3_hot and D3_cold, and the platform is unable to > - * enable wake-up power for it. > + * This function only returns error code if the device is not allowed to wake > + * up the system from sleep or it is not capable of generating PME# from both > + * D3_hot and D3_cold and the platform is unable to enable wake-up power for it. > */ > int pci_wake_from_d3(struct pci_dev *dev, bool enable) > { > @@ -2114,7 +2131,7 @@ int pci_finish_runtime_suspend(struct pc > > dev->runtime_d3cold = target_state == PCI_D3cold; > > - pci_enable_wake(dev, target_state, pci_dev_run_wake(dev)); > + __pci_enable_wake(dev, target_state, pci_dev_run_wake(dev)); > > error = pci_set_power_state(dev, target_state); > >