Skip to contentSkip to conversation

usbip: Accept arbitrarily long scatter-gather list

PATCH In review Jason Long 2 participants 2 messages Dec 18, 2024 – Dec 20, 2024

Subsystems (2)
lore
Share & tools
lore

Jason Long

author
#0 lore raw

PATCH 1/1 usbip: Accept arbitrarily long scatter-gather list

Fixes issue where memory will fail to be allocated for larger bulk transfers, ~1 MB or more. This occurs because userland libraries, such as libusb, send the entire USB data buffer when SG support is detected. The assumption is that the driver knows how to properly split the data up before sending it out.

By hardcoding a limit, bigger transfers that exceed the SG tablesize limit of 32 will be unable to use SG. This results in an attempt to allocate contiguous pages which, unsurprisingly, will fail too and returns an ENOMEM. It looks like other drivers that support SG allow for any length of SG lists. Accepting any SG size allows the driver to properly handle large bulk transfer situations.

Tested bulk read and write operations using the following devices:

- Logitech Webcam Pro 9000 - USB 2.0
- SanDisk Ultra - USB 3.0
- Logitech M500s Mouse

---
 drivers/usb/usbip/vhci_hcd.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/usb/usbip/vhci_hcd.c +2 -6
index b03e5021c..2f722849d 100644
@@ -1161,12 +1161,8 @@ static int vhci_setup(struct usb_hcd *hcd)
 		hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS;
 	}
 
-	/*
-	 * Support SG.
-	 * sg_tablesize is an arbitrary value to alleviate memory pressure
-	 * on the host.
-	 */
-	hcd->self.sg_tablesize = 32;
+	/* accept arbitrarily long scatter-gather lists */
+	hcd->self.sg_tablesize = ~0;
 	hcd->self.no_sg_constraint = 1;
 
 	return 0;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Jason Long

Fixes issue where memory will fail to be allocated for larger bulk transfers, ~1 MB or more. This occurs because userland libraries, such as libusb, send the entire USB data buffer when SG support is detected. The assumption is that the driver knows how to properly split the data up before sending it out.

By hardcoding a limit, bigger transfers that exceed the SG tablesize limit of 32 will be unable to use SG. This results in an attempt to allocate contiguous pages which, unsurprisingly, will fail too and returns an ENOMEM. It looks like other drivers that support SG allow for any length of SG lists. Accepting any SG size allows the driver to properly handle large bulk transfer situations.

Tested bulk read and write operations using the following devices:

- Logitech Webcam Pro 9000 - USB 2.0
- SanDisk Ultra - USB 3.0
- Logitech M500s Mouse

---
  drivers/usb/usbip/vhci_hcd.c | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
drivers/usb/usbip/vhci_hcd.c +0 -1
index b03e5021c..2f722849d 100644
@@ -1161,12 +1161,8 @@ static int vhci_setup(struct usb_hcd *hcd)
  		hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS;
  	}
 
-	/*

drivers/usb/usbip/vhci_hcd.c static int vhci_setup(struct usb_hcd *hcd) · line 1168

Quoted 10 lines
drivers/usb/usbip/vhci_hcd.c +2 -5
-	 * Support SG.
-	 * sg_tablesize is an arbitrary value to alleviate memory pressure
-	 * on the host.
-	 */
-	hcd->self.sg_tablesize = 32;
+	/* accept arbitrarily long scatter-gather lists */
+	hcd->self.sg_tablesize = ~0;
  	hcd->self.no_sg_constraint = 1;
 
  	return 0;

Looks good to me. We have other drivers that do the same.

Greg, please pick this up.

thanks,
-- Shuah