unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Chris Marusich <cmmarusich@gmail.com>
To: help-guix@gnu.org
Subject: QEMU USB pass-through
Date: Sat, 19 Oct 2019 13:13:14 -0700	[thread overview]
Message-ID: <87v9skcx45.fsf@gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2019-10-19 20:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-19 20:13 Chris Marusich [this message]
2019-10-19 20:46 ` QEMU USB pass-through Oleg Pykhalov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v9skcx45.fsf@gmail.com \
    --to=cmmarusich@gmail.com \
    --cc=help-guix@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).