stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Alan Stern <stern@rowland.harvard.edu>
Subject: [ 33/99] USB: global suspend and remote wakeup dont mix
Date: Fri,  2 Aug 2013 18:07:46 +0800	[thread overview]
Message-ID: <20130802100230.695179042@linuxfoundation.org> (raw)
In-Reply-To: <20130802100225.478715166@linuxfoundation.org>

3.10-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Alan Stern <stern@rowland.harvard.edu>

commit e583d9db9960cf40e0bc8afee4946baa9d71596e upstream.

The hub driver was recently changed to use "global" suspend for system
suspend transitions on non-SuperSpeed buses.  This means that we don't
suspend devices individually by setting the suspend feature on the
upstream hub port; instead devices all go into suspend automatically
when the root hub stops transmitting packets.  The idea was to save
time and to avoid certain kinds of wakeup races.

Now it turns out that many hubs are buggy; they don't relay wakeup
requests from a downstream port to their upstream port if the
downstream port's suspend feature is not set (depending on the speed
of the downstream port, whether or not the hub is enabled for remote
wakeup, and possibly other factors).

We can't have hubs dropping wakeup requests.  Therefore this patch
goes partway back to the old policy: It sets the suspend feature for a
port if the device attached to that port or any of its descendants is
enabled for wakeup.  People will still be able to benefit from the
time savings if they don't care about wakeup and leave it disabled on
all their devices.

In order to accomplish this, the patch adds a new field to the usb_hub
structure: wakeup_enabled_descendants is a count of how many devices
below a suspended hub are enabled for remote wakeup.  A corresponding
new subroutine determines the number of wakeup-enabled devices at or
below an arbitrary suspended USB device.

This should be applied to the 3.10 stable kernel.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-and-tested-by: Toralf Förster <toralf.foerster@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/usb/core/hub.c |   39 +++++++++++++++++++++++++++++++--------
 drivers/usb/core/hub.h |    3 +++
 2 files changed, 34 insertions(+), 8 deletions(-)

--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2855,6 +2855,15 @@ static int usb_disable_function_remotewa
 				USB_CTRL_SET_TIMEOUT);
 }
 
+/* Count of wakeup-enabled devices at or below udev */
+static unsigned wakeup_enabled_descendants(struct usb_device *udev)
+{
+	struct usb_hub *hub = usb_hub_to_struct_hub(udev);
+
+	return udev->do_remote_wakeup +
+			(hub ? hub->wakeup_enabled_descendants : 0);
+}
+
 /*
  * usb_port_suspend - suspend a usb device's upstream port
  * @udev: device that's no longer in active use, not a root hub
@@ -2895,8 +2904,8 @@ static int usb_disable_function_remotewa
  * Linux (2.6) currently has NO mechanisms to initiate that:  no khubd
  * timer, no SRP, no requests through sysfs.
  *
- * If Runtime PM isn't enabled or used, non-SuperSpeed devices really get
- * suspended only when their bus goes into global suspend (i.e., the root
+ * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get
+ * suspended until their bus goes into global suspend (i.e., the root
  * hub is suspended).  Nevertheless, we change @udev->state to
  * USB_STATE_SUSPENDED as this is the device's "logical" state.  The actual
  * upstream port setting is stored in @udev->port_is_suspended.
@@ -2967,15 +2976,21 @@ int usb_port_suspend(struct usb_device *
 	/* see 7.1.7.6 */
 	if (hub_is_superspeed(hub->hdev))
 		status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3);
-	else if (PMSG_IS_AUTO(msg))
-		status = set_port_feature(hub->hdev, port1,
-						USB_PORT_FEAT_SUSPEND);
+
 	/*
 	 * For system suspend, we do not need to enable the suspend feature
 	 * on individual USB-2 ports.  The devices will automatically go
 	 * into suspend a few ms after the root hub stops sending packets.
 	 * The USB 2.0 spec calls this "global suspend".
+	 *
+	 * However, many USB hubs have a bug: They don't relay wakeup requests
+	 * from a downstream port if the port's suspend feature isn't on.
+	 * Therefore we will turn on the suspend feature if udev or any of its
+	 * descendants is enabled for remote wakeup.
 	 */
+	else if (PMSG_IS_AUTO(msg) || wakeup_enabled_descendants(udev) > 0)
+		status = set_port_feature(hub->hdev, port1,
+				USB_PORT_FEAT_SUSPEND);
 	else {
 		really_suspend = false;
 		status = 0;
@@ -3010,15 +3025,16 @@ int usb_port_suspend(struct usb_device *
 		if (!PMSG_IS_AUTO(msg))
 			status = 0;
 	} else {
-		/* device has up to 10 msec to fully suspend */
 		dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n",
 				(PMSG_IS_AUTO(msg) ? "auto-" : ""),
 				udev->do_remote_wakeup);
-		usb_set_device_state(udev, USB_STATE_SUSPENDED);
 		if (really_suspend) {
 			udev->port_is_suspended = 1;
+
+			/* device has up to 10 msec to fully suspend */
 			msleep(10);
 		}
+		usb_set_device_state(udev, USB_STATE_SUSPENDED);
 	}
 
 	/*
@@ -3300,7 +3316,11 @@ static int hub_suspend(struct usb_interf
 	unsigned		port1;
 	int			status;
 
-	/* Warn if children aren't already suspended */
+	/*
+	 * Warn if children aren't already suspended.
+	 * Also, add up the number of wakeup-enabled descendants.
+	 */
+	hub->wakeup_enabled_descendants = 0;
 	for (port1 = 1; port1 <= hdev->maxchild; port1++) {
 		struct usb_device	*udev;
 
@@ -3310,6 +3330,9 @@ static int hub_suspend(struct usb_interf
 			if (PMSG_IS_AUTO(msg))
 				return -EBUSY;
 		}
+		if (udev)
+			hub->wakeup_enabled_descendants +=
+					wakeup_enabled_descendants(udev);
 	}
 
 	if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) {
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -59,6 +59,9 @@ struct usb_hub {
 	struct usb_tt		tt;		/* Transaction Translator */
 
 	unsigned		mA_per_port;	/* current for each child */
+#ifdef	CONFIG_PM
+	unsigned		wakeup_enabled_descendants;
+#endif
 
 	unsigned		limited_power:1;
 	unsigned		quiescing:1;



  parent reply	other threads:[~2013-08-02 10:07 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-02 10:07 [ 00/99] 3.10.5-stable review Greg Kroah-Hartman
2013-08-02 10:07 ` [ 01/99] mm: fix the TLB range flushed when __tlb_remove_page() runs out of slots Greg Kroah-Hartman
2013-08-02 10:07 ` [ 02/99] iser-target: Fix isert_put_reject payload buffer post Greg Kroah-Hartman
2013-08-02 10:07 ` [ 03/99] iscsi-target: Fix tfc_tpg_nacl_auth_cit configfs length overflow Greg Kroah-Hartman
2013-08-02 10:07 ` [ 04/99] iser-target: Fix session reset bug with RDMA_CM_EVENT_DISCONNECTED Greg Kroah-Hartman
2013-08-02 10:07 ` [ 05/99] iscsi-target: Fix ISCSI_OP_SCSI_TMFUNC handling for iser Greg Kroah-Hartman
2013-08-02 10:07 ` [ 06/99] USB: storage: Add MicroVault Flash Drive to unusual_devs Greg Kroah-Hartman
2013-08-02 10:07 ` [ 07/99] ALSA: hda - Yet another Dell headset mic quirk Greg Kroah-Hartman
2013-08-02 10:07 ` [ 08/99] ALSA: hda - Guess what, its two more Dell headset mic quirks Greg Kroah-Hartman
2013-08-02 10:07 ` [ 09/99] firewire: fix libdc1394/FlyCap2 iso event regression Greg Kroah-Hartman
2013-08-02 10:07 ` [ 10/99] ASoC: sglt5000: Fix the default value of CHIP_SSS_CTRL Greg Kroah-Hartman
2013-08-02 10:07 ` [ 11/99] ASoC: max98088 - fix element type of the register cache Greg Kroah-Hartman
2013-08-02 10:07 ` [ 12/99] ASoC: tegra: correct playback_dma_data setup Greg Kroah-Hartman
2013-08-02 10:07 ` [ 13/99] ASoC: wm8962: Remove remaining direct register cache accesses Greg Kroah-Hartman
2013-08-02 10:07 ` [ 14/99] ARM: 7722/1: zImage: Convert 32bits memory size and address from ATAG to 64bits DTB Greg Kroah-Hartman
2013-08-02 10:07 ` [ 15/99] SCSI: isci: Fix a race condition in the SSP task management path Greg Kroah-Hartman
2013-08-02 10:07 ` [ 16/99] SCSI: sd: fix crash when UA received on DIF enabled device Greg Kroah-Hartman
2013-08-02 10:07 ` [ 17/99] SCSI: qla2xxx: Properly set the tagging for commands Greg Kroah-Hartman
2013-08-02 10:07 ` [ 18/99] tracing: Fix error handling to ensure instances can always be removed Greg Kroah-Hartman
2013-08-02 10:07 ` [ 19/99] tracing: Miscellaneous fixes for trace_array ref counting Greg Kroah-Hartman
2013-08-02 10:07 ` [ 20/99] tracing: Kill the unbalanced tr->ref++ in tracing_buffers_open() Greg Kroah-Hartman
2013-08-02 10:07 ` [ 21/99] tracing: Remove locking trace_types_lock from tracing_reset_all_online_cpus() Greg Kroah-Hartman
2013-08-02 10:07 ` [ 22/99] usb: host: xhci: Enable XHCI_SPURIOUS_SUCCESS for all controllers with xhci 1.0 Greg Kroah-Hartman
2013-08-02 10:07 ` [ 23/99] xhci: fix null pointer dereference on ring_doorbell_for_active_rings Greg Kroah-Hartman
2013-08-02 10:07 ` [ 24/99] xhci: Avoid NULL pointer deref when host dies Greg Kroah-Hartman
2013-08-02 10:07 ` [ 25/99] USB: EHCI: Fix resume signalling on remote wakeup Greg Kroah-Hartman
2013-08-02 10:07 ` [ 26/99] USB: mos7840: fix memory leak in open Greg Kroah-Hartman
2013-08-02 10:07 ` [ 27/99] usb: dwc3: fix the error returned with usb3_phy failure Greg Kroah-Hartman
2013-08-02 10:07 ` [ 28/99] usb: dwc3: fix wrong bit mask in dwc3_event_type Greg Kroah-Hartman
2013-08-02 10:07 ` [ 29/99] usb: dwc3: gadget: dont prevent gadget from being probed if we fail Greg Kroah-Hartman
2013-08-02 10:07 ` [ 30/99] USB: ti_usb_3410_5052: fix dynamic-id matching Greg Kroah-Hartman
2013-08-02 10:07 ` [ 31/99] USB: misc: Add Manhattan Hi-Speed USB DVI Converter to sisusbvga Greg Kroah-Hartman
2013-08-02 10:07 ` [ 32/99] usb: Clear both buffers when clearing a control transfer TT buffer Greg Kroah-Hartman
2013-08-02 10:07 ` Greg Kroah-Hartman [this message]
2013-08-02 10:07 ` [ 34/99] staging: comedi: fix a race between do_cmd_ioctl() and read/write Greg Kroah-Hartman
2013-08-02 10:07 ` [ 35/99] staging: comedi: COMEDI_CANCEL ioctl should wake up read/write Greg Kroah-Hartman
2013-08-02 10:07 ` [ 36/99] staging: android: logger: Correct write offset reset on error Greg Kroah-Hartman
2013-08-02 10:07 ` [ 37/99] cpufreq / intel_pstate: Change to scale off of max P-state Greg Kroah-Hartman
2013-08-02 10:07 ` [ 38/99] Btrfs: fix wrong write offset when replacing a device Greg Kroah-Hartman
2013-08-02 10:07 ` [ 39/99] Btrfs: fix lock leak when resuming snapshot deletion Greg Kroah-Hartman
2013-08-02 10:07 ` [ 40/99] Btrfs: re-add root to dead root list if we stop dropping it Greg Kroah-Hartman
2013-08-02 10:07 ` [ 41/99] xen-netfront: pull on receive skb may need to happen earlier Greg Kroah-Hartman
2013-08-02 10:07 ` [ 42/99] xen/blkback: Check device permissions before allowing OP_DISCARD Greg Kroah-Hartman
2013-08-02 10:07 ` [ 43/99] x86, suspend: Handle CPUs which fail to #GP on RDMSR Greg Kroah-Hartman
2013-08-02 10:07 ` [ 44/99] x86: make sure IDT is page aligned Greg Kroah-Hartman
2013-08-02 10:07 ` [ 45/99] md: Remove recent change which allows devices to skip recovery Greg Kroah-Hartman
2013-08-02 10:07 ` [ 46/99] md/raid1: fix bio handling problems in process_checks() Greg Kroah-Hartman
2013-08-02 10:08 ` [ 47/99] md/raid5: fix interaction of replace and recovery Greg Kroah-Hartman
2013-08-02 10:08 ` [ 48/99] md/raid10: remove use-after-free bug Greg Kroah-Hartman
2013-08-02 10:08 ` [ 49/99] ata: Fix DVD not dectected at some platform with Wellsburg PCH Greg Kroah-Hartman
2013-08-02 10:08 ` [ 50/99] libata: make it clear that sata_inic162x is experimental Greg Kroah-Hartman
2013-08-02 10:08 ` [ 51/99] svcrdma: underflow issue in decode_write_list() Greg Kroah-Hartman
2013-08-02 10:08 ` [ 52/99] crypto: caam - Fixed the memory out of bound overwrite issue Greg Kroah-Hartman
2013-08-02 10:08 ` [ 53/99] powerpc/modules: Module CRC relocation fix causes perf issues Greg Kroah-Hartman
2013-08-02 10:08 ` [ 54/99] nfsd: nfsd_open: when dentry_open returns an error do not propagate as struct file Greg Kroah-Hartman
2013-08-02 10:08 ` [ 55/99] Tools: hv: KVP: Fix a bug in IPV6 subnet enumeration Greg Kroah-Hartman
2013-08-02 10:08 ` [ 56/99] Drivers: hv: balloon: Fix a bug in the hot-add code Greg Kroah-Hartman
2013-08-02 10:08 ` [ 57/99] Drivers: hv: balloon: Do not post pressure status if interrupted Greg Kroah-Hartman
2013-08-02 10:08 ` [ 58/99] regmap: cache: bail in regmap_async_complete() for bus-less maps Greg Kroah-Hartman
2013-08-02 10:08 ` [ 59/99] ACPI / scan: Always call acpi_bus_scan() for bus check notifications Greg Kroah-Hartman
2013-08-02 10:08 ` [ 60/99] ACPI / scan: Do not try to attach scan handlers to devices having them Greg Kroah-Hartman
2013-08-02 10:08 ` [ 61/99] ACPI / memhotplug: Fix a stale pointer in error path Greg Kroah-Hartman
2013-08-02 10:08 ` [ 62/99] ACPI / video: ignore BIOS initial backlight value for Fujitsu E753 Greg Kroah-Hartman
2013-08-02 10:08 ` [ 63/99] dm mpath: fix ioctl deadlock when no paths Greg Kroah-Hartman
2013-08-02 10:08 ` [ 64/99] dm ioctl: set noio flag to avoid __vmalloc deadlock Greg Kroah-Hartman
2013-08-02 10:08 ` [ 65/99] dm verity: fix inability to use a few specific devices sizes Greg Kroah-Hartman
2013-08-02 10:08 ` [ 66/99] drm/radeon/hdmi: make sure we have an afmt block assigned Greg Kroah-Hartman
2013-08-02 10:08 ` [ 67/99] drm/radeon: fix UVD fence emit Greg Kroah-Hartman
2013-08-02 10:08 ` [ 68/99] drm/radeon: allow selection of alignment in the sub-allocator Greg Kroah-Hartman
2013-08-02 10:08 ` [ 69/99] drm/radeon: fix endian issues with DP handling (v3) Greg Kroah-Hartman
2013-08-02 10:08 ` [ 70/99] drm/radeon: Another card with wrong primary dac adj Greg Kroah-Hartman
2013-08-02 10:08 ` [ 71/99] drm/radeon: fix combios tables on older cards Greg Kroah-Hartman
2013-08-02 10:08 ` [ 72/99] drm/radeon: improve dac adjust heuristics for legacy pdac Greg Kroah-Hartman
2013-08-02 10:08 ` [ 73/99] drm/i915: fix up ring cleanup for the i830/i845 CS tlb w/a Greg Kroah-Hartman
2013-08-02 10:08 ` [ 74/99] drm/i915: Fix write-read race with multiple rings Greg Kroah-Hartman
2013-08-02 10:08 ` [ 75/99] Partially revert "drm/i915: unconditionally use mt forcewake on hsw/ivb" Greg Kroah-Hartman
2013-08-02 10:08 ` [ 76/99] drm/i915: Fix incoherence with fence updates on Sandybridge+ Greg Kroah-Hartman
2013-08-02 10:08 ` [ 77/99] drm/i915: fix long-standing SNB regression in power consumption after resume v2 Greg Kroah-Hartman
2013-08-02 10:08 ` [ 78/99] drm/i915: Fix dereferencing invalid connectors in is_crtc_connector_off() Greg Kroah-Hartman
2013-08-02 10:08 ` [ 79/99] drm/i915: correctly restore fences with objects attached Greg Kroah-Hartman
2013-08-02 10:08 ` [ 80/99] drm/i915: quirk no PCH_PWM_ENABLE for Dell XPS13 backlight Greg Kroah-Hartman
2013-08-02 10:08 ` [ 81/99] drm/i915: Serialize almost all register access Greg Kroah-Hartman
2013-08-02 10:08 ` [ 82/99] drm/i915: fix up gt init sequence fallout Greg Kroah-Hartman
2013-08-02 10:08 ` [ 83/99] drm/i915: fix missed hunk after GT access breakage Greg Kroah-Hartman
2013-08-02 10:08 ` [ 84/99] drm/nouveau: fix semaphore dmabuf obj Greg Kroah-Hartman
2013-08-02 10:08 ` [ 85/99] drm/radeon: fix audio dto programming on DCE4+ Greg Kroah-Hartman
2013-08-02 10:08 ` [ 86/99] drm/radeon/atom: initialize more atom interpretor elements to 0 Greg Kroah-Hartman
2013-08-02 10:08 ` [ 87/99] rtlwifi: Initialize power-setting callback for USB devices Greg Kroah-Hartman
2013-08-02 10:08 ` [ 88/99] USB: serial: ftdi_sio: add more RT Systems ftdi devices Greg Kroah-Hartman
2013-08-02 10:08 ` [ 89/99] usb: gadget: udc-core: fix the typo of udc state attribute Greg Kroah-Hartman
2013-08-02 10:08 ` [ 90/99] mm: mempolicy: fix mbind_range() && vma_adjust() interaction Greg Kroah-Hartman
2013-08-02 10:08 ` [ 91/99] tty_port: Fix refcounting leak in tty_port_tty_hangup() Greg Kroah-Hartman
2013-08-02 10:08 ` [ 92/99] livelock avoidance in sget() Greg Kroah-Hartman
2013-08-02 10:08 ` [ 93/99] xen/evtchn: avoid a deadlock when unbinding an event channel Greg Kroah-Hartman
2013-08-02 10:08 ` [ 94/99] radeon kms: do not flush uninitialized hotplug work Greg Kroah-Hartman
2013-08-02 10:08 ` [ 95/99] iscsi-target: Fix iscsit_add_reject* usage for iser Greg Kroah-Hartman
2013-08-02 10:08 ` [ 96/99] iscsi-target: Fix iscsit_sequence_cmd reject handling " Greg Kroah-Hartman
2013-08-02 10:08 ` [ 97/99] perf tools: Revert regression in configuration of Python support Greg Kroah-Hartman
2013-08-02 10:08 ` [ 98/99] drm/i915: Correct obj->mm_list link to dev_priv->dev_priv->mm.inactive_list Greg Kroah-Hartman
2013-08-02 10:08 ` [ 99/99] x86: Fix /proc/mtrr with base/size more than 44bits Greg Kroah-Hartman
2013-08-02 19:57 ` [ 00/99] 3.10.5-stable review Shuah Khan
2013-08-02 21:24   ` Greg Kroah-Hartman
2013-08-02 22:05     ` Willy Tarreau
2013-08-03 14:02 ` Guenter Roeck
2013-08-03 23:03   ` Greg Kroah-Hartman

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=20130802100230.695179042@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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;
as well as URLs for NNTP newsgroup(s).