usb: core: stop USB enumeration if too many retries
PATCH RESEND v4 1/1 usb: core: stop USB enumeration if too many retries
When a broken USB accessory connects to a USB host, usbcore might keep doing enumeration retries. If the host has a watchdog mechanism, the kernel panic will happen on the host.
This patch provides an attribute early_stop to limit the numbers of retries for each port of a hub. If a port was marked with early_stop attribute, unsuccessful connection attempts will fail quickly. In addition, if an early_stop port has failed to initialize, it will ignore all future connection events until early_stop attribute is clear.
--- Documentation/ABI/testing/sysfs-bus-usb | 11 +++++ drivers/usb/core/hub.c | 59 +++++++++++++++++++++++++ drivers/usb/core/hub.h | 4 ++ drivers/usb/core/port.c | 27 +++++++++++ 4 files changed, 101 insertions(+)
Documentation/ABI/testing/sysfs-bus-usb +11 -0
@@ -264,6 +264,17 @@ Description: attached to the port will not be detected, initialized, or enumerated. +What: /sys/bus/usb/devices/.../<hub_interface>/port<X>/early_stop +Date: Sep 2022 +Contact: Ray Chi <[email protected]> +Description: + Some USB hosts have some watchdog mechanisms so that the device + may enter ramdump if it takes a long time during port initialization. + This attribute allows each port just has two attempts so that the + port initialization will be failed quickly. In addition, if a port + which is marked with early_stop has failed to initialize, it will ignore + all future connections until this attribute is clear. + What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout Date: May 2013 Contact: Mathias Nyman <[email protected]>
drivers/usb/core/hub.c +59 -0
95 lines not on this page · raw message
drivers/usb/core/hub.h +4 -0
@@ -90,6 +90,8 @@ struct usb_hub {* @is_superspeed cache super-speed status * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted. * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted. +* @early_stop: whether port initialization will be stopped earlier. +* @ignore_event: whether events of the port are ignored. */ struct usb_port {struct usb_device *child;
@@ -103,6 +105,8 @@ struct usb_port {u32 over_current_count;u8 portnum;u32 quirks; + unsigned int early_stop:1; + unsigned int ignore_event:1; unsigned int is_superspeed:1; unsigned int usb3_lpm_u1_permit:1; unsigned int usb3_lpm_u2_permit:1;
drivers/usb/core/port.c +27 -0
@@ -17,6 +17,32 @@ static int usb_port_block_power_off;static const struct attribute_group *port_dev_group[]; +static ssize_t early_stop_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct usb_port *port_dev =to_usb_port (dev); + +return sysfs_emit (buf,"%s\n" , port_dev->early_stop ?"yes" :"no" ); +} + +static ssize_t early_stop_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct usb_port *port_dev =to_usb_port (dev); +bool value; + +if (kstrtobool (buf, &value)) +return -EINVAL ; + +if (value) + port_dev->early_stop =1 ; +else + port_dev->early_stop =0 ; + +return count; +} +static DEVICE_ATTR_RW (early_stop); +static ssize_t disable_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -236,6 +262,7 @@ static struct attribute *port_dev_attrs[] = { &dev_attr_quirks.attr, &dev_attr_over_current_count.attr, &dev_attr_disable.attr, + &dev_attr_early_stop.attr, NULL, };
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Greg KH
maintainerQuoted 10 lines · Ray Chi
When a broken USB accessory connects to a USB host, usbcore might keep doing enumeration retries. If the host has a watchdog mechanism, the kernel panic will happen on the host.
This patch provides an attribute
early_stopto limit the numbers of retries for each port of a hub. If a port was marked withearly_stopattribute, unsuccessful connection attempts will fail quickly. In addition, if anearly_stopport has failed to initialize, it will ignore all future connection events untilearly_stopattribute is clear.
Quoted 8 lines
Signed-off-by Ray Chi <[email protected]>--- Documentation/ABI/testing/sysfs-bus-usb | 11 +++++ drivers/usb/core/hub.c | 59 +++++++++++++++++++++++++ drivers/usb/core/hub.h | 4 ++ drivers/usb/core/port.c | 27 +++++++++++ 4 files changed, 101 insertions(+)
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/SubmittingPatches for what needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot