unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* QEMU USB pass-through
@ 2019-10-19 20:13 Chris Marusich
  2019-10-19 20:46 ` Oleg Pykhalov
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Marusich @ 2019-10-19 20:13 UTC (permalink / raw)
  To: help-guix

[-- Attachment #1: Type: text/plain, Size: 6622 bytes --]

Hi,

I recently tried to pass through a USB flash drive to a VM using QEMU,
and I couldn't get it working.  Has anyone successfully used QEMU's USB
pass-through feature on a Guix system?

When I plug a USB flash drive into my Guix system using GNOME, GNOME
automatically mounts it for me.  So I unmounted by running "umount" as
root.  It didn't seem to get automatically re-mounted, which is good,
and by running "lsblk -f" I verified that it remained unmounted.

Based on the output of "lsusb", this flash drive uses bus address 001,
and device address 006.  I tried launching the VM like this:

  qemu-system-x86_64 \
      -net user,hostfwd=tcp:127.0.0.1:2222-:22 \
      -net nic,model=virtio \
      -enable-kvm \
      -m 512 \
      -smp 1 \
      -device virtio-blk,drive=myhd \
      -drive if=none,file=debian,id=myhd \
      -vga std \
      -usb \
      -device usb-host,hostbus=1,hostaddr=8 \
      -monitor stdio

Note that for QEMU to launch without errors, I had to give myself
read/write permissions on the USB device node:

  $ sudo setfacl -m u:marusich:rw /dev/bus/usb/001/008

QEMU launches the VM launches without errors.  Within it, I can see a
block device at /dev/sda (the virtual hard drive "myhd" shows up as
/dev/vda).  However, when I try to read from it, it doesn't work:

  marusich@debian:~$ sudo head --bytes=512 /dev/sda | hexdump -C
  [sudo] password for marusich: 
  head: error reading '/dev/sda': Input/output error

Meanwhile, in the host, dmesg says stuff like this.

First, right after I launch the VM:

  [169152.893485] udevd[215]: specified group 'plugdev' unknown
  [169152.973558] sd 4:0:0:0: [sdb] Synchronizing SCSI cache
  [169153.306104] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169155.074112] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169155.374116] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169167.054727] kvm [22097]: vcpu0, guest rIP: 0xffffffff9565db48 disabled perfctr wrmsr: 0xc2 data 0xffff
  [169167.265174] udevd[215]: specified group 'plugdev' unknown
  [169167.394116] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169170.006107] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169170.605105] udevd[215]: specified group 'plugdev' unknown
  [169170.718133] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169171.146116] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169176.759220] udevd[215]: specified group 'plugdev' unknown
  [169176.870112] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169178.838435] udevd[215]: specified group 'plugdev' unknown
  [169178.966118] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169180.438119] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169181.650113] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169183.564845] udevd[215]: specified group 'plugdev' unknown
  [169184.066115] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169185.446110] usb 1-1: reset high-speed USB device number 9 using ehci-pci

Even after I shut down the VM, the messages continue:

  [169186.776158] udevd[215]: specified group 'plugdev' unknown
  [169186.894128] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169187.594122] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169188.442126] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169189.194114] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169189.933640] udevd[215]: specified group 'plugdev' unknown
  [169190.058150] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169190.746120] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169191.566121] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169192.290112] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169193.158971] udevd[215]: specified group 'plugdev' unknown
  [169193.282121] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169193.706136] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169194.530116] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169194.954115] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169195.774120] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169196.194117] usb 1-1: reset high-speed USB device number 9 using ehci-pci

But eventually, the USB device stops getting reset, and it shows up
automatically in my host system again (GNOME proceeds to auto-mount it,
too):

  [169324.539442] udevd[215]: specified group 'plugdev' unknown
  [169324.654115] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169325.086114] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169325.898113] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169326.326106] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169327.142098] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169327.574131] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169327.754133] udevd[215]: specified group 'plugdev' unknown
  [169328.126102] usb 1-1: reset high-speed USB device number 9 using ehci-pci
  [169328.466887] usb-storage 1-1:1.0: USB Mass Storage device detected
  [169328.485130] scsi host4: usb-storage 1-1:1.0
  [169329.846284] scsi 4:0:0:0: Direct-Access     SMI      USB DISK         1100 PQ: 0 ANSI: 6
  [169329.847241] sd 4:0:0:0: Attached scsi generic sg1 type 0
  [169329.848630] sd 4:0:0:0: [sdb] 61440000 512-byte logical blocks: (31.5 GB/29.3 GiB)
  [169329.852458] sd 4:0:0:0: [sdb] Write Protect is off
  [169329.852460] sd 4:0:0:0: [sdb] Mode Sense: 43 00 00 00
  [169329.853665] sd 4:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
  [169329.860891]  sdb: sdb1 sdb2
  [169329.865264] sd 4:0:0:0: [sdb] Attached SCSI removable disk

This is pretty weird.  I tried all of the following, but I saw the same
results every time:

* Run QEMU as root.
* Unbind the ehci-pci driver (so Linux will use uhci_hcd instead)
* Pass additional -device options for the other USB devices, including a
  hub that shows up on the same bus.
* Try a different USB port.
* Try a different USB storage device.

If anyone has gotten USB pass-through working with QEMU on a Guix
system, please let me know what I'm doing wrong!

Thank you,

-- 
Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: QEMU USB pass-through
  2019-10-19 20:13 QEMU USB pass-through Chris Marusich
@ 2019-10-19 20:46 ` Oleg Pykhalov
  0 siblings, 0 replies; 2+ messages in thread
From: Oleg Pykhalov @ 2019-10-19 20:46 UTC (permalink / raw)
  To: Chris Marusich; +Cc: help-guix

[-- Attachment #1: Type: text/plain, Size: 656 bytes --]

Hi Chris,

I use the following command to get a USB device on VM:
--8<---------------cut here---------------start------------->8---
qemu-system-x86_64 \
     -daemonize \
     -m 4096 \
     -smp 2 \
     -enable-kvm \
     -hda /srv/virt/vm.qcow2 \
     -smb /srv/share \
     -M q35 \
     -usb \
     -device usb-host,hostbus=2,hostaddr=4 \
     -net 'user,hostfwd=tcp::3389-:3389,hostfwd=tcp::445-:445' \
     -net nic
--8<---------------cut here---------------end--------------->8---

I'm not sure I could help you with spotting the mistake though, because
I got this command almost randomly trying different flags and
suggestions on the internet :-)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-19 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-19 20:13 QEMU USB pass-through Chris Marusich
2019-10-19 20:46 ` Oleg Pykhalov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).