tiiuae / ghaf

TII SSRC Secure Technologies: Ghaf Framework
https://tiiuae.github.io/ghaf/
Apache License 2.0
35 stars 56 forks source link

Add support for USB hot plugging #686

Closed nesteroff closed 1 week ago

nesteroff commented 2 months ago

Description of changes

This adds a service that runs on the host and listens for device add and remove events using libudev. When a new USB device is attached, it is automatically assigned to the designated virtual machine using the official qemu.qmp library."

Checklist for things done

Testing

Input Devices:

Audio Devices:

If a bug is found or if something is not working as expected, please collect the vhotplug service logs from journalctl on the host.

mbssrc commented 1 month ago

This is great. Tested this briefly and worked fine. Let me know what your test results with the other usb devices are! If you could add ID_INPUT_TOUCHSCREEN etc. (https://github.com/tiiuae/ghaf/blob/main/packages/hardware-scan/hardware-scan.sh#L242) as well, it would also support touchscreens.

Generally (maybe not as part of this PR) we could use a static configuration file as general policy based on device type and VM, and later add-on user defined passthrough for switcheroo between VMs.

nesteroff commented 1 month ago

This is great. Tested this briefly and worked fine. Let me know what your test results with the other usb devices are! If you could add ID_INPUT_TOUCHSCREEN etc. (https://github.com/tiiuae/ghaf/blob/main/packages/hardware-scan/hardware-scan.sh#L242) as well, it would also support touchscreens.

Thanks. I added touchscreens to the list as well.

Generally (maybe not as part of this PR) we could use a static configuration file as general policy based on device type and VM, and later add-on user defined passthrough for switcheroo between VMs.

Sure. I tried to keep this app simple but in future versions we will need to improve the configuration to implement more complicated rules, add exclusions, support for the cloud hypervisor and so on.

I’ve tested this with input devices, audio headsets, removable disks, and ethernet adapters. It seems to work fine but I left network devices disabled by default because attaching them to the net-vm breaks remote nixos-rebuild with target-host. Also hot-plugging of disk devices is disabled until we have a storage vm or something like that. Do you know if there are any other device types that we need to support?

mbssrc commented 1 month ago

Perhaps the yubikey and gps devices, so we can get rid of the static external device definition?

nesteroff commented 1 month ago

Perhaps the yubikey and gps devices, so we can get rid of the static external device definition?

Sure, I'll look into it.

nesteroff commented 4 weeks ago

Recent updates:

nesteroff commented 2 weeks ago

Updated to make hot-plugged devices survive suspend and resume.

milva-unikie commented 1 week ago

Tested on Lenovo-X1 (lenovo-x1-carbon-gen11-debug on USB SSD)

No issues found!