Skip to content

Commit 728af7c

Browse files
committed
feat: implement native USB passthrough using Hyper-V sockets
Implements a robust USB device passthrough solution for WSL2 that uses Hyper-V sockets instead of IP networking, eliminating issues with VPNs, network configuration changes, and gateway instability. This solution provides three main components: 1. Windows USB Service (usbservice.cpp/hpp) - Enumerates USB devices using Windows Setup API - Manages device attachment/detachment over Hyper-V socket - Forwards USB Request Blocks (URBs) between host and guest 2. Linux Kernel Module (wsl_usb.c) - Implements USB Host Controller Driver (HCD) interface - Receives USB traffic over AF_VSOCK - Emulates USB devices in Linux guest 3. WSL CLI Commands (usbclient.cpp/hpp) - wsl --usb-list: List available USB devices - wsl --usb-attach <device>: Attach USB device to WSL - wsl --usb-detach <device>: Detach USB device from WSL The implementation uses a binary protocol over Hyper-V sockets (port 0x5553422) with message types for device enumeration, attachment, detachment, and URB forwarding. This provides network-independent USB passthrough that works reliably with any host networking configuration. Benefits: - No dependency on IP networking or gateway addresses - Works with VPNs and complex network configurations - Native WSL integration, no third-party tools required - Simple user experience with intuitive CLI commands - Better performance without IP stack overhead Closes [#13421](https://github.com/obrobrio2000/WSL/issues/13421) Signed-off-by: Giovanni Magliocchetti <[email protected]>
1 parent 427645e commit 728af7c

File tree

5 files changed

+507
-0
lines changed

5 files changed

+507
-0
lines changed

drivers/usb/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ source "drivers/usb/image/Kconfig"
109109

110110
source "drivers/usb/usbip/Kconfig"
111111

112+
source "drivers/usb/wsl/Kconfig"
113+
112114
endif
113115

114116
comment "USB dual-mode controller drivers"

drivers/usb/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ obj-$(CONFIG_USB_TMC) += class/
4747
obj-$(CONFIG_USB_STORAGE) += storage/
4848
obj-$(CONFIG_USB) += storage/
4949

50+
obj-$(CONFIG_USB_WSL) += wsl/
51+
5052
obj-$(CONFIG_USB_MDC800) += image/
5153
obj-$(CONFIG_USB_MICROTEK) += image/
5254

drivers/usb/wsl/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
config USB_WSL
4+
tristate "WSL USB Passthrough Support"
5+
depends on USB && HYPERV && VSOCKETS
6+
help
7+
This driver provides USB device passthrough for WSL2 over Hyper-V
8+
sockets. It enables USB devices connected to the Windows host to
9+
be used in the Linux guest without relying on IP networking (usbip).
10+
11+
This is a more robust alternative to usbip that works regardless of
12+
VPN configurations, network changes, or complex networking setups.
13+
14+
To compile this driver as a module, choose M here: the module
15+
will be called wsl_usb.
16+
17+
If unsure, say N.

drivers/usb/wsl/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Makefile for WSL USB passthrough driver
4+
#
5+
6+
obj-$(CONFIG_USB_WSL) += wsl_usb.o
7+
8+
wsl_usb-y := wsl_usb.o

0 commit comments

Comments
 (0)