From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linux PCI <linux-pci@vger.kernel.org>,
Linux ACPI <linux-acpi@vger.kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 5/6] PCI / ACPI / PM: Avoid disabling wakeup for bridges too early
Date: Mon, 19 Jun 2017 23:36:21 +0200 [thread overview]
Message-ID: <374495495.9Wgi8cFFrW@aspire.rjw.lan> (raw)
In-Reply-To: <12296383.UdE5HVtyng@aspire.rjw.lan>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
If acpi_pci_propagate_wakeup() is used, it may trigger wakeup
configuration twice for the same bridge indirectly, when configuring
wakeup for two different PCI devices under that bridge. Actually,
however, the ACPI wakeup code can only be enabled to trigger wakeup
notifications for the bridge once in a row and there is no reference
counting in that code, so wakeup signaling on the bridge can be
disabled prematurely when it is disabled for the first of those
devices.
To prevent that from happening, add optional reference counting to
the ACPI device wakeup code and make acpi_pci_propagate_wakeup()
use if for bridges.
This works, because ACPI wakeup signaling for PCI bridges is only
set up by acpi_pci_propagate_wakeup(), so the reference counting
will only be used for them.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/device_pm.c | 35 +++++++++++++++++++++++++++++++----
drivers/pci/pci-acpi.c | 4 ++--
include/acpi/acpi_bus.h | 11 +++++++++--
3 files changed, 42 insertions(+), 8 deletions(-)
Index: linux-pm/drivers/acpi/device_pm.c
===================================================================
--- linux-pm.orig/drivers/acpi/device_pm.c
+++ linux-pm/drivers/acpi/device_pm.c
@@ -385,6 +385,7 @@ EXPORT_SYMBOL(acpi_bus_power_manageable)
#ifdef CONFIG_PM
static DEFINE_MUTEX(acpi_pm_notifier_lock);
+static DEFINE_MUTEX(acpi_wakeup_lock);
void acpi_pm_wakeup_event(struct device *dev)
{
@@ -724,11 +725,11 @@ static int acpi_device_wakeup(struct acp
}
/**
- * acpi_pm_device_wakeup - Enable/disable remote wakeup for given device.
+ * __acpi_pm_device_wakeup - Enable/disable remote wakeup for given device.
* @dev: Device to enable/disable to generate wakeup events.
* @enable: Whether to enable or disable the wakeup functionality.
*/
-int acpi_pm_device_wakeup(struct device *dev, bool enable)
+int __acpi_pm_device_wakeup(struct device *dev, bool enable, bool refcount)
{
struct acpi_device *adev;
int error;
@@ -742,13 +743,39 @@ int acpi_pm_device_wakeup(struct device
if (!acpi_device_can_wakeup(adev))
return -EINVAL;
+ if (refcount) {
+ mutex_lock(&acpi_wakeup_lock);
+
+ if (enable) {
+ if (++adev->wakeup.enable_count > 1)
+ goto out;
+ } else {
+ if (WARN_ON_ONCE(adev->wakeup.enable_count == 0))
+ goto out;
+
+ if (--adev->wakeup.enable_count > 0)
+ goto out;
+ }
+ }
error = acpi_device_wakeup(adev, acpi_target_system_state(), enable);
- if (!error)
+ if (error) {
+ if (refcount) {
+ if (enable)
+ adev->wakeup.enable_count--;
+ else
+ adev->wakeup.enable_count++;
+ }
+ } else {
dev_dbg(dev, "Wakeup %s by ACPI\n", enable ? "enabled" : "disabled");
+ }
+
+out:
+ if (refcount)
+ mutex_unlock(&acpi_wakeup_lock);
return error;
}
-EXPORT_SYMBOL(acpi_pm_device_wakeup);
+EXPORT_SYMBOL(__acpi_pm_device_wakeup);
/**
* acpi_dev_pm_low_power - Put ACPI device into a low-power state.
Index: linux-pm/include/acpi/acpi_bus.h
===================================================================
--- linux-pm.orig/include/acpi/acpi_bus.h
+++ linux-pm/include/acpi/acpi_bus.h
@@ -331,6 +331,7 @@ struct acpi_device_wakeup {
struct acpi_device_wakeup_context context;
struct wakeup_source *ws;
int prepare_count;
+ unsigned int enable_count;
};
struct acpi_device_physical_node {
@@ -603,7 +604,7 @@ acpi_status acpi_add_pm_notifier(struct
acpi_status acpi_remove_pm_notifier(struct acpi_device *adev);
bool acpi_pm_device_can_wakeup(struct device *dev);
int acpi_pm_device_sleep_state(struct device *, int *, int);
-int acpi_pm_device_wakeup(struct device *dev, bool enable);
+int __acpi_pm_device_wakeup(struct device *dev, bool enable, bool refcount);
#else
static inline void acpi_pm_wakeup_event(struct device *dev)
{
@@ -630,12 +631,18 @@ static inline int acpi_pm_device_sleep_s
return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ?
m : ACPI_STATE_D0;
}
-static inline int acpi_pm_device_wakeup(struct device *dev, bool enable)
+static inline int __acpi_pm_device_wakeup(struct device *dev, bool enable,
+ bool refcount)
{
return -ENODEV;
}
#endif
+static inline int acpi_pm_device_wakeup(struct device *dev, bool enable)
+{
+ return __acpi_pm_device_wakeup(dev, enable, false);
+}
+
#ifdef CONFIG_ACPI_SLEEP
u32 acpi_target_system_state(void);
#else
Index: linux-pm/drivers/pci/pci-acpi.c
===================================================================
--- linux-pm.orig/drivers/pci/pci-acpi.c
+++ linux-pm/drivers/pci/pci-acpi.c
@@ -574,7 +574,7 @@ static int acpi_pci_propagate_wakeup(str
{
while (bus->parent) {
if (acpi_pm_device_can_wakeup(&bus->self->dev))
- return acpi_pm_device_wakeup(&bus->self->dev, enable);
+ return __acpi_pm_device_wakeup(&bus->self->dev, enable, true);
bus = bus->parent;
}
@@ -582,7 +582,7 @@ static int acpi_pci_propagate_wakeup(str
/* We have reached the root bus. */
if (bus->bridge) {
if (acpi_pm_device_can_wakeup(bus->bridge))
- return acpi_pm_device_wakeup(bus->bridge, enable);
+ return __acpi_pm_device_wakeup(bus->bridge, enable, true);
}
return 0;
}
next prev parent reply other threads:[~2017-06-19 21:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-19 21:31 [PATCH 0/6] PM: Unify the handling of device wakeup settings Rafael J. Wysocki
2017-06-19 21:33 ` [PATCH 1/6] ACPI / PM: Drop run_wake from struct acpi_device_wakeup_flags Rafael J. Wysocki
2017-06-19 21:33 ` [PATCH 2/6] ACPI / PM: Consolidate device wakeup settings code Rafael J. Wysocki
2017-06-22 7:39 ` Mika Westerberg
2017-06-22 14:38 ` Rafael J. Wysocki
2017-06-23 1:05 ` Rafael J. Wysocki
2017-06-26 13:29 ` Mika Westerberg
2017-06-19 21:34 ` [PATCH 3/6] PCI / PM: Drop pme_interrupt flag from struct pci_dev Rafael J. Wysocki
2017-06-19 21:35 ` [PATCH 4/6] PCI / PM: Simplify device wakeup settings code Rafael J. Wysocki
2017-06-20 14:00 ` kbuild test robot
2017-06-20 16:16 ` kbuild test robot
2017-06-20 22:23 ` [Update][PATCH " Rafael J. Wysocki
2017-06-19 21:36 ` Rafael J. Wysocki [this message]
2017-06-20 12:38 ` [PATCH 5/6] PCI / ACPI / PM: Avoid disabling wakeup for bridges too early kbuild test robot
2017-06-20 22:24 ` [Update][PATCH " Rafael J. Wysocki
2017-06-19 21:37 ` [PATCH 6/6] PM / core: Drop run_wake flag from struct dev_pm_info Rafael J. Wysocki
2017-06-22 8:22 ` [PATCH 0/6] PM: Unify the handling of device wakeup settings Mika Westerberg
2017-06-23 23:50 ` [PATCH v2 0/5] " Rafael J. Wysocki
2017-06-23 23:53 ` [PATCH v2 1/5] ACPI / PM: Drop run_wake from struct acpi_device_wakeup_flags Rafael J. Wysocki
2017-06-23 23:54 ` [PATCH v2 2/5] ACPI / PM: Consolidate device wakeup settings code Rafael J. Wysocki
2017-06-23 23:56 ` [PATCH v2 3/5] PCI / PM: Drop pme_interrupt flag from struct pci_dev Rafael J. Wysocki
2017-06-23 23:57 ` [PATCH v2 4/5] PCI / PM: Simplify device wakeup settings code Rafael J. Wysocki
2017-06-23 23:58 ` [PATCH v2 5/5] PM / core: Drop run_wake flag from struct dev_pm_info Rafael J. Wysocki
2017-06-27 23:43 ` [PATCH v2 0/5] PM: Unify the handling of device wakeup settings Bjorn Helgaas
2017-06-27 23:49 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=374495495.9Wgi8cFFrW@aspire.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=bhelgaas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®