XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login
    1. Home
    2. ScottyXCPNG
    S
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 9
    • Groups 0

    ScottyXCPNG

    @ScottyXCPNG

    Hobbyist XCP-NG user

    4
    Reputation
    3
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online
    Location Scottyland

    ScottyXCPNG Unfollow Follow

    Best posts made by ScottyXCPNG

    • RE: USB passthrough test reports in 7.5RC1

      Update: I haven't been able to figure out how to tell qemu to use a USB1.x interface instead of USB2.x (EHCI) which would let me pass the device through, but I've found a different work around. The device I'm trying to pass through appears as a USB serial device. After I stumbled upon a page mentioning that you could tie an emulated serial port to a TCP socket I dug further and found that you can do

      xe vm-param-add uuid=<uuid> param-name=platform hvm_serial=/dev/ttyACM0
      

      and hey presto your /dev/ttyS0 in the guest is now tied to the device on the hypervisor

      I may still poke around and try and find a better solution but for now my needs appear to be satisfied.

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      A slightly less hacky work around for USB v1 passthrough based on the issue I created:

      --- /opt/xensource/libexec/usb_scan.py     2019-11-04 10:03:02.000000000 +0000
      +++ /tmp/usb_scan.py    2020-03-01 17:32:29.266317478 +0000
      @@ -152,10 +152,11 @@
           _CLASS = "bDeviceClass"
           _CONF_VALUE = "bConfigurationValue"
           _NUM_INTERFACES = "bNumInterfaces"
      +    _USB_SPEED = "speed"
       
           _PRODUCT_DESC = [_DESC_VENDOR, _DESC_PRODUCT]
           _PRODUCT_DETAILS = [_VERSION, _ID_VENDOR, _ID_PRODUCT, _BCD_DEVICE, _SERIAL,
      -                        _CLASS, _CONF_VALUE, _NUM_INTERFACES]
      +                        _CLASS, _CONF_VALUE, _NUM_INTERFACES, _USB_SPEED]
           _PROPS = _PRODUCT_DESC + _PRODUCT_DETAILS
           _PROPS_NONABLE = _PRODUCT_DESC + [_SERIAL]
       
      @@ -590,7 +591,10 @@
       
           pusb["path"] = device.get_node()
           # strip the leading space of "version"
      -    pusb["version"] = device[UsbDevice._VERSION].strip()
      +    if int(device[UsbDevice._USB_SPEED]) <= 12:
      +        pusb["version"] = "1.00"
      +    else:
      +        pusb["version"] = device[UsbDevice._VERSION].strip()
           pusb["vendor-id"] = device[UsbDevice._ID_VENDOR]
           pusb["product-id"] = device[UsbDevice._ID_PRODUCT]
           pusb["vendor-desc"] = device[UsbDevice._DESC_VENDOR]
      

      in theory any deice which is "low" or "full" speed (i.e. USB1) will have it's version number changed to 1.00 which forces xenopsd to use a USB1 bus. It may have side effects if the driver in the guest relies on the version number so caveat emptor.

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      @olivierlambert created https://github.com/xcp-ng/xcp/issues/342 under xcp project. Thanks!

      ScottyGuy created this issue in xcp-ng/xcp

      closed Please create test packages to help with USB support (related to CA-328130 ) #342

      posted in Development
      S
      ScottyXCPNG

    Latest posts made by ScottyXCPNG

    • RE: USB passthrough test reports in 7.5RC1

      A slightly less hacky work around for USB v1 passthrough based on the issue I created:

      --- /opt/xensource/libexec/usb_scan.py     2019-11-04 10:03:02.000000000 +0000
      +++ /tmp/usb_scan.py    2020-03-01 17:32:29.266317478 +0000
      @@ -152,10 +152,11 @@
           _CLASS = "bDeviceClass"
           _CONF_VALUE = "bConfigurationValue"
           _NUM_INTERFACES = "bNumInterfaces"
      +    _USB_SPEED = "speed"
       
           _PRODUCT_DESC = [_DESC_VENDOR, _DESC_PRODUCT]
           _PRODUCT_DETAILS = [_VERSION, _ID_VENDOR, _ID_PRODUCT, _BCD_DEVICE, _SERIAL,
      -                        _CLASS, _CONF_VALUE, _NUM_INTERFACES]
      +                        _CLASS, _CONF_VALUE, _NUM_INTERFACES, _USB_SPEED]
           _PROPS = _PRODUCT_DESC + _PRODUCT_DETAILS
           _PROPS_NONABLE = _PRODUCT_DESC + [_SERIAL]
       
      @@ -590,7 +591,10 @@
       
           pusb["path"] = device.get_node()
           # strip the leading space of "version"
      -    pusb["version"] = device[UsbDevice._VERSION].strip()
      +    if int(device[UsbDevice._USB_SPEED]) <= 12:
      +        pusb["version"] = "1.00"
      +    else:
      +        pusb["version"] = device[UsbDevice._VERSION].strip()
           pusb["vendor-id"] = device[UsbDevice._ID_VENDOR]
           pusb["product-id"] = device[UsbDevice._ID_PRODUCT]
           pusb["vendor-desc"] = device[UsbDevice._DESC_VENDOR]
      

      in theory any deice which is "low" or "full" speed (i.e. USB1) will have it's version number changed to 1.00 which forces xenopsd to use a USB1 bus. It may have side effects if the driver in the guest relies on the version number so caveat emptor.

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      OK, this is rather amusing. I've got USB passthrough working for my USB 1.0 device.

      [15:28 xcp-ng-bywirlgr log]# diff -u /opt/xensource/libexec/usb_scan.py.orig /opt/xensource/libexec/usb_scan.py
      --- /opt/xensource/libexec/usb_scan.py.orig     2019-11-04 10:03:02.000000000 +0000
      +++ /opt/xensource/libexec/usb_scan.py  2020-03-01 15:20:53.323512746 +0000
      @@ -590,7 +590,8 @@
       
           pusb["path"] = device.get_node()
           # strip the leading space of "version"
      -    pusb["version"] = device[UsbDevice._VERSION].strip()
      +    #pusb["version"] = device[UsbDevice._VERSION].strip()
      +    pusb["version"] = "1.00"
           pusb["vendor-id"] = device[UsbDevice._ID_VENDOR]
           pusb["product-id"] = device[UsbDevice._ID_PRODUCT]
           pusb["vendor-desc"] = device[UsbDevice._DESC_VENDOR]
      

      I do NOT recommend this AT ALL. It is a gross hack. Apparently the xenopsd relies on the version number returned by the device to dictate the USB bus type of the controller it attaches to. I have no idea in what universe that makes sense.

      The above only works for me as that is the only USB device attached to the HV. I guess I could make the code a little smarter by looking for a particular device ID and only over-riding the version then

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      @olivierlambert created https://github.com/xcp-ng/xcp/issues/342 under xcp project. Thanks!

      ScottyGuy created this issue in xcp-ng/xcp

      closed Please create test packages to help with USB support (related to CA-328130 ) #342

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      Further update: I've found the USB device is added to qemu after the vm has started through hot plugging. It seems this is done in xenopsd. It even has explicit code to support USB v1 devices in there

      According to xenopsd sources from 0.101.0 from the XCP-NG 8.0 SRPM, the code is

      let vusb_plug ~xs ~privileged ~domid ~id ~hostbus ~hostport ~version =
        debug "vusb_plug: plug VUSB device %s" id;
        let get_bus v =
          if String.startswith "1" v then
            "usb-bus.0"
          else begin
            (* Here plug usb controller according to the usb version*)
            let usb_controller_driver = "usb-ehci" in
            let driver_id = "ehci" in
            vusb_controller_plug ~xs ~domid ~driver:usb_controller_driver ~driver_id;
            Printf.sprintf "%s.0" driver_id;
          end
        in
        if Qemu.is_running ~xs domid then
          begin
            (* Need to reset USB device before passthrough to vm according to CP-24616.
               Also need to do deprivileged work in usb_reset script if QEMU is deprivileged.
            *)
            begin match Qemu.pid ~xs domid with
              | Some pid -> usb_reset_attach ~hostbus ~hostport ~domid ~pid ~privileged
              | _ -> raise (Xenopsd_error (Internal_error (Printf.sprintf "qemu pid does not exist for vm %d" domid)))
            end;
            let cmd = Qmp.(Device_add Device.(
                           { driver = "usb-host";
                             device = USB {
                               USB.id = id;
                               params = Some USB.({bus = get_bus version; hostbus; hostport})
                             }
                           }
                        ))
            in qmp_send_cmd domid cmd |> ignore
          end
      

      unfortunately I cannot find where the mysterious "version" parameter is that needs to be set to "1" to enable the use of USB bus 0 in the guest, which is USB 1. I'm wondering if it's stupidly reading the version string of the USB device itself rather than something else

      I note that the latest code in the upstream xapi-project/xenopsd device.ml line 1818 is radically different and now has a "speed" parameter. This was added in commit ab15e6c3b1b06b2eac4f2a8be724eac50c9d4b22 in Oct 2019 for CA-328130 (whatever that is). It looks like code was also added to the upstream xapi-project/xenapi to add the "speed" parameter to the data model there. So there may be a fix in a future version of XCP-NG if they pull in these fixes. I haven't looked at 8.1-beta but I suspect it's too late to go making wholesale changes there if the code hasn't already been merged.

      ok, just downloaded the SRPM from 8.1 xenopsd and it still has the old code for vusb plug, so I'm guessing 8.1 doesn't have this fixed (yet)

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      @axiom00 yes, once I dug further I had the same issues. I don't have anything to pair with my stick yet, I was trying to get it working before splashing out on zigbee devices. I'm not sure why it's having issues. If you look at the Conbee serial protocol it's all done via binary commands sent over 38400 baud serial, so it should work OK. I also had an issue where my stick disconnected/reconnected after about an hour and came up with a different path in /dev so it didn't attach any more. I suspect this was because qemu was holding the original device open.

      To remove the device from the vm again do

      xe vm-param-remove vm-param-add uuid=<uuid> param-name=platform param-key=hvm_serial
      

      else it won't start if the serial device isn't present.

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      Bonus: I just tried and snapshot/backup still works with the serial port tied in that way

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      Update: I haven't been able to figure out how to tell qemu to use a USB1.x interface instead of USB2.x (EHCI) which would let me pass the device through, but I've found a different work around. The device I'm trying to pass through appears as a USB serial device. After I stumbled upon a page mentioning that you could tie an emulated serial port to a TCP socket I dug further and found that you can do

      xe vm-param-add uuid=<uuid> param-name=platform hvm_serial=/dev/ttyACM0
      

      and hey presto your /dev/ttyS0 in the guest is now tied to the device on the hypervisor

      I may still poke around and try and find a better solution but for now my needs appear to be satisfied.

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      Hi,

      Thanks for the reply @stormi

      I've kind of hit a roadblock in my own probing so far. I was trying to figure out how the VUSB parameters got passed into qemu. The daemon.log shows it's run by forkexecd, but comparing the command of the same vm run with and without VUSB shows no real differences, so there must be a configuration file or other metadata being passed in with the VUSB passthrough configuration. I tried poking at the xenapi and quickly got lost in the ocaml code which I can't really read.

      I've also found that a VM with a VUSB attached cannot be snapshotted and backed up, which is really unfortunate. I'm not entirely sure why that restriction exists. Surely if the VM is rolled back to the snapshot then the system can treat it the same as if the USB device vanishes? It seems that the system removes the VUSB attachment if the device vanishes so I would have thought the same could be done from snapshots or backups?

      Thanks,

      Gary

      posted in Development
      S
      ScottyXCPNG
    • RE: USB passthrough test reports in 7.5RC1

      Hi,

      I have XCP-NG 8.0 loaded onto an Intel NUC and I'm trying to pass a USB device through to a guest V.M. Although the setup using the CLI seems to go OK, the guest never sees the device. I've tried 2 different guests with no success

      Digging into the logs a bit more I found this:

      Feb 15 14:20:49 xcp-ng-bywirlgr qemu-dm-17[18527]: qemu-dm-17: Warning: speed mismatch trying to attach usb device "ConBee II" (full speed) to bus "ehci.0", port "1" (high speed)
      

      This seems to come from qemu-dp/hw/usb/bus.c:usb_check_attach() which sets the warning if the speed of the probed USB device is different to the speed of the emulated USB controller in the guest (at least that's what I think it does)

      Despite the fact that it is classed as a warning, it appears to abort the attachment of the device to the guest in qemu-dp/hw/usb/bus.c:usb_device_attach() if the warning has been generated.

      • is it possible to use one of the "xe vusb-param-*" commands to set the emulated USB bus to USB 1.x instead of 2.x (ehci)? I haven't been able to trace back where the bus is created yet

      • if not, is it possible to comment out that check and see what happens? To be honest, the check puzzles me. It is perfectly valid to plug a FULL speed (USB1.x) device into a HIGH speed (USB2.x) or SUPER speed (USB3.x) bus and have it work normally. There might be some magic have to happen at the port level to make it work, but it works just fine as the USB 1.x device I'm trying to use is plugged into a USB 2.x port on my NUC

      Any ideas?

      Thanks,

      Gary

      posted in Development
      S
      ScottyXCPNG