-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
qemu: add usb host passthrough #20540
qemu: add usb host passthrough #20540
Conversation
@ashley-cui, do you think this is a good way of implementing this feature? /cc @beriberikix (for knowledge) |
Thanks for the contribution! Ah, this seems to get past the issue I was running into when looking at this, which was the host perms. I'd prefer the syntax like |
Thanks for the review!
No problem, I'll change it. Questions that I have:
(Asking also to know podman machine scope!) |
fee662d
to
a71b0c6
Compare
I think we would prefer things to be as easy as possible for the user. I've been doing experiments with USB passthrough for the past week and discovered that even if the user changes the permissions of the usb device on /dev/bus/usb, on sleeps, the USB permissions revert. This might end up meaning that we need to let the user deal with perms, since we can't really constantly monitor the device.
I think we should definitely consider hotplugging, but I suppose this isn't an initial requirement. At the very least, I think --usb should also be plumbed through |
One possibility is to interact with udev, but that's a linux only solution. I'm sure Window's would have its own APIs in a way that we can manage permissions as well. I don't see podman using udev as of now so we might want to do it as a follow up. My question was also related to the expectations wrt permissions. We agree that the least the user has to do, the better.
Ok
Ok, I'll start working on it then. |
RE: windows & hotplugging - I think that's a can of worms 🪱 A neat tool usbipd-win had to essentially implement a udev-like thing in Windows. Instead of the native WinUSB stack they opted to leverage the VirtualBox drivers. More discussion here. |
if this PR is only for qemu, then we should try to fence off the option by provider or error out in every other provider. |
98abb42
to
cb80399
Compare
Makes sense to me. Any suggestions on how to do that? I plan to use a conditional |
Ephemeral COPR build failed. @containers/packit-build please check. |
I think in the Init() functions in |
cb80399
to
c0aaa0f
Compare
c0aaa0f
to
1520609
Compare
I need some more time for the e2e test. I need to mock a USB or run the e2e test in VM, not sure what is easier. |
Emulating a USB on Linux is pretty trivial, depending on how much you need to emulate. In the past I've used USB/IP with a little hackery but quick bit of research led me to this neat tool:https://github.com/jtornosm/USBIP-Virtual-USB-Device (details here.) |
1520609
to
78dc8cd
Compare
Nothing fancy, just to show in the
I'm not familiar with podman's ci yet, we need to check if kernel has the right flags and it is fine to modprobe those drivers in the host. In the KubeVirt feature I was working, we solved this with device emulation in QEMU as the CI was running in a VM, we just added an emulated storage to that VM (see kubevirt/kubevirtci#996) Again, not 100% sure what the best course is for the tests. Mocking with umockdev might be best but I'm open to suggestions. |
af6f9cf
to
99b56ce
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ashley-cui, victortoso The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
c7b20a3
to
b3b8715
Compare
hm, CI is failing but it seems to be on quay.io side. |
b3b8715
to
a2fc3a3
Compare
Cockpit tests failed for commit a2fc3a3ef4da811a2a1af9b2e0ea69ee12ddea64. @martinpitt, @jelly, @mvollmer please check. |
QEMU usb-host driver which is the one for passthrough, supports two options for selecting an USB devices in the host to provide it to the VM: - Bus and Device number the device is plugged - Vendor and Product information of the USB devices https://qemu-project.gitlab.io/qemu/system/devices/usb.html This commit allows a user to configure podman machine with either of options, with new --usb command line option for podman machine init. Examples podman machine init tosovm4 --usb vendor=13d3,product=5406 podman machine init tosovm3 --usb bus=1,devnum=4 --usb bus=1,devnum=3 This commit also allows a user to change the USBs configured with --usb command line option for podman machine set. Note that this commit does not handle host device permissions nor verify that the USB devices exists. Signed-off-by: Victor Toso <[email protected]>
a2fc3a3
to
c23963d
Compare
Ephemeral COPR build failed. @containers/packit-build please check. |
/lgtm |
|
||
vendor, err := strconv.ParseInt(vendorStr, 16, 0) | ||
if err != nil { | ||
return configs, fmt.Errorf("fail to convert vendor of %s: %s", str, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think usb:
adds more context and consistent with other error message.
return configs, fmt.Errorf("fail to convert vendor of %s: %s", str, err) | |
return configs, fmt.Errorf("usb: fail to convert vendor of %s: %s", str, err) |
|
||
product, err := strconv.ParseInt(productStr, 16, 0) | ||
if err != nil { | ||
return configs, fmt.Errorf("fail to convert product of %s: %s", str, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
return configs, fmt.Errorf("fail to convert product of %s: %s", str, err) | |
return configs, fmt.Errorf("usb: fail to convert product of %s: %s", str, err) |
7dd33b3
into
containers:main
option := "" | ||
if (left[0] == "bus" && right[0] == "devnum") || | ||
(right[0] == "bus" && left[0] == "devnum") { | ||
option = "bus_devnum" | ||
} | ||
if (left[0] == "vendor" && right[0] == "product") || | ||
(right[0] == "vendor" && left[0] == "product") { | ||
option = "vendor_product" | ||
} | ||
|
||
switch option { | ||
case "bus_devnum": | ||
bus, devnumber := left[1], right[1] | ||
if right[0] == "bus" { | ||
bus, devnumber = devnumber, bus | ||
} | ||
|
||
configs = append(configs, machine.USBConfig{ | ||
Bus: bus, | ||
DevNumber: devnumber, | ||
}) | ||
case "vendor_product": | ||
vendorStr, productStr := left[1], right[1] | ||
if right[0] == "vendor" { | ||
vendorStr, productStr = productStr, vendorStr | ||
} | ||
|
||
vendor, err := strconv.ParseInt(vendorStr, 16, 0) | ||
if err != nil { | ||
return configs, fmt.Errorf("fail to convert vendor of %s: %s", str, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be simplified
option := left[0] +"_"+left[1] // and switch can be match against "vendor_product" and "product_vendor" both.
switch
Created a PR #20678 |
Some comments from containers#20540 [NO NEW TESTS NEEDED] Signed-off-by: Aditya R <[email protected]>
@n1hility WDYT? |
@beriberikix you should probably open a new issue for WSL |
Does Podman on Windows support QEMU or only WSL? USB support on WSL is complicated , so targeting QEMU would be ideal! |
We support hyperV and WSL no QEMU |
Hi,
This PR is a WIP related to the request in #16707
At this moment, the PR works for
QEMU
hypervisor and allows multiple USB devices to be passthrough topodman machine
.Example using
vendor:product
Example using
bus-device_number
Note that this PR does not handle device permissions from the host. Both devices are under my user group, that is:
Disclaimer: This is my first contribution to Podman. Please do feel free to point out anything that I might be doing wrong.
Does this PR introduce a user-facing change?
Yes, it adds a new -usb command line option to
podman machine init
.