lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 19 Jul 2023 17:37:56 +0000
From: Alexandru Gagniuc <alexandru.gagniuc@...com>
To: linux-usb@...r.kernel.org,
	netdev@...r.kernel.org
Cc: davem@...emloft.net,
	edumazet@...gle.com,
	kuba@...nel.org,
	pabeni@...hat.com,
	hayeswang@...ltek.com,
	jflf_kernel@....com,
	bjorn@...k.no,
	svenva@...omium.org,
	linux-kernel@...r.kernel.org,
	eniac-xw.zhang@...com,
	Alexandru Gagniuc <alexandru.gagniuc@...com>,
	stable@...r.kernel.org
Subject: [PATCH v2] r8152: Suspend USB device before shutdown when WoL is enabled

For Wake-on-LAN to work from S5 (shutdown), the USB link must be put
in U3 state. If it is not, and the host "disappears", the chip will
no longer respond to WoL triggers.

To resolve this, add a notifier block and register it as a reboot
notifier. When WoL is enabled, work through the usb_device struct to
get to the suspend function. Calling this function puts the link in
the correct state for WoL to function.

Fixes: 21ff2e8976b1 ("r8152: support WOL")
Cc: stable@...r.kernel.org
Signed-off-by: Alexandru Gagniuc <alexandru.gagniuc@...com>
---
Changes since v1:
    * Add "Fixes:" tag to commit message

 drivers/net/usb/r8152.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 0738baa5b82e..abb82a80d262 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -20,6 +20,7 @@
 #include <net/ip6_checksum.h>
 #include <uapi/linux/mdio.h>
 #include <linux/mdio.h>
+#include <linux/reboot.h>
 #include <linux/usb/cdc.h>
 #include <linux/suspend.h>
 #include <linux/atomic.h>
@@ -876,6 +877,7 @@ struct r8152 {
 	struct delayed_work schedule, hw_phy_work;
 	struct mii_if_info mii;
 	struct mutex control;	/* use for hw setting */
+	struct notifier_block reboot_notifier;
 #ifdef CONFIG_PM_SLEEP
 	struct notifier_block pm_notifier;
 #endif
@@ -9610,6 +9612,25 @@ static bool rtl8152_supports_lenovo_macpassthru(struct usb_device *udev)
 	return 0;
 }
 
+/* Suspend realtek chip before system shutdown
+ *
+ * For Wake-on-LAN to work from S5, the USB link must be put in U3 state. If
+ * the host otherwise "disappears", the chip will not respond to WoL triggers.
+ */
+static int rtl8152_notify(struct notifier_block *nb, unsigned long code,
+			  void *unused)
+{
+	struct r8152 *tp = container_of(nb, struct r8152, reboot_notifier);
+	struct device *dev = &tp->udev->dev;
+
+	if (code == SYS_POWER_OFF) {
+		if (tp->saved_wolopts && dev->type->pm->suspend)
+			dev->type->pm->suspend(dev);
+	}
+
+	return NOTIFY_DONE;
+}
+
 static int rtl8152_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
@@ -9792,6 +9813,9 @@ static int rtl8152_probe(struct usb_interface *intf,
 	else
 		device_set_wakeup_enable(&udev->dev, false);
 
+	tp->reboot_notifier.notifier_call = rtl8152_notify;
+	register_reboot_notifier(&tp->reboot_notifier);
+
 	netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION);
 
 	return 0;
@@ -9812,6 +9836,7 @@ static void rtl8152_disconnect(struct usb_interface *intf)
 	if (tp) {
 		rtl_set_unplug(tp);
 
+		unregister_reboot_notifier(&tp->reboot_notifier);
 		unregister_netdev(tp->netdev);
 		tasklet_kill(&tp->tx_tl);
 		cancel_delayed_work_sync(&tp->hw_phy_work);
-- 
2.39.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ