foxlet / macOS-Simple-KVM

Tools to set up a quick macOS VM in QEMU, accelerated by KVM.
13.66k stars 1.14k forks source link

USB redirection using Spice #297

Open dJani97 opened 4 years ago

dJani97 commented 4 years ago

Hi!

I am trying to pass through an iPhone device to the VM. The steps I have tried:

1) I set up Spice in basic.sh:

    -spice port=3001,disable-ticketing \
    -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,multifunction=on \
    -device ich9-usb-uhci2,masterbus=usb.0,firstport=2 \
    -device ich9-usb-uhci3,masterbus=usb.0,firstport=4 \
    -chardev spicevmc,name=usbredir,id=usbredirchardev1 -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1 \
    -chardev spicevmc,name=usbredir,id=usbredirchardev2 -device usb-redir,chardev=usbredirchardev2,id=usbredirdev2 \
    -chardev spicevmc,name=usbredir,id=usbredirchardev3 -device usb-redir,chardev=usbredirchardev3,id=usbredirdev3 \

Ref: usbredir

2) I launch the Spice client

using the remote-viewer command, and successfully connect to spice://localhost:3001. I can see my Mac now using Spice :)

3) I try redirecting a USB device

I go to File -> USB device selection, and select a device. But when I'm trying to redirect any actual USB device (let it be my iPhone, or a simple USB mouse or keyboard) I get the following error on the remote-viewer console:

(remote-viewer:226968): GSpice-CRITICAL **: 21:16:48.394: file usb-device-manager.c: line 1708 (probe_isochronous_endpoint): should not be reached
libusb: error [udev_hotplug_event] ignoring udev action bind

I am not insisting on using Spice, I just want to get my iPhone connected with the VM, and this seemed like a nice way to achieve this.

Can anybody help with this?

ghost commented 4 years ago

Is the VM using the USB Controller version 3.0?

reinismu commented 4 years ago

I haven't seen anyone you have managed to passthrough iPhone without passing whole USB controller. If you manage to achieve it with spice, let us know :)

dJani97 commented 4 years ago

I haven't seen anyone you have managed to passthrough iPhone without passing whole USB controller. If you manage to achieve it with spice, let us know :)

Thank you!

Is it possible to pass through my USB controller if I only have a single one? I'm trying to achieve this from a laptop. It's not a problem that it won't be available to the host OS during this time.

reinismu commented 4 years ago

It is possible, but you will lose your keyboard/mouse. You could write script that does it all and you get control of Mac. From Mac ssh into host and have script ready to switch controller back. Tho it would be a pain. I just realized my work laptop has 2 USB controllers. So happy (razer blade 13)

dJani97 commented 4 years ago

It is possible, but you will lose your keyboard/mouse. You could write script that does it all and you get control of Mac. From Mac ssh into host and have script ready to switch controller back. Tho it would be a pain. I just realized my work laptop has 2 USB controllers. So happy (razer blade 13)

To me, hwinfo --short gives the following:

usb controller:
                       Intel 7 Series/C216 Chipset Family USB Enhanced Host Controller #2
                       Intel 7 Series/C216 Chipset Family USB Enhanced Host Controller #1
                       Intel 7 Series/C210 Series Chipset Family USB xHCI Host Controller

Does it mean that I also have two controllers? It's a pretty large machine (Dell Inspiron 7720), I wouldn't be surprised.

Edit: I also checked the result of lsusb, not sure if it's relevant:

Bus 003 Device 003: ID 8087:07da Intel Corp. 
Bus 003 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 0c45:648d Microdia 
Bus 001 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 1038:1720 SteelSeries ApS 
Bus 002 Device 006: ID 258a:0001  
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
reinismu commented 4 years ago

Can you run lspci | grep "USB"

I get

00:0d.0 USB controller: Intel Corporation Ice Lake Thunderbolt 3 USB Controller (rev 03)
00:14.0 USB controller: Intel Corporation Ice Lake-LP USB 3.1 xHCI Host Controller (rev 30)

So I just move all my needed stuff to Thunderbolt 3 USB Controller and map USB 3.1 controller to mac. (Well I still have to do it. Just finishing installing mac kvm)

dJani97 commented 4 years ago

Can you run lspci | grep "USB"

It gives a very similar result:

00:14.0 USB controller: Intel Corporation 7 Series/C210 Series Chipset Family USB xHCI Host Controller (rev 04)
00:1a.0 USB controller: Intel Corporation 7 Series/C216 Chipset Family USB Enhanced Host Controller #2 (rev 04)
00:1d.0 USB controller: Intel Corporation 7 Series/C216 Chipset Family USB Enhanced Host Controller #1 (rev 04)
reinismu commented 4 years ago

Then ye you are all good just find out which usb is controlled by which controller. https://www.reddit.com/r/hackintosh/comments/f31wx0/macos_on_kvm_and_xcode_and_iphone_usb_passthrough/ pretty good guide here. Tho as I have seen osx is picky with PCIs

ghost commented 4 years ago

Keep in mind that macOS on VMs does not work with USB 3.0.

reinismu commented 4 years ago

Yup I failed at my attempt :/