How to upgrade virtio 0.9 to virtio 1.0 for bhyve

From: Mario Marietto <marietto2008_at_gmail.com>
Date: Mon, 30 Dec 2024 00:22:05 UTC
Hello.

I'm using FreeBSD 14.2 right now and I'm trying to use the virtio-input
parameter in bhyve to share one of my mouses within a Linux vm :

    From “man bhyve” (
https://www.freebsd.org/cgi/man.cgi...FreeBSD+14.0-CURRENT&arch=default&format=html
):

    Virtio input device backends:

    /dev/input/eventX

    Send input events of /dev/input/eventX to guest

    by VirtIO Input Interface.


I tried on my FreeBSD system :

[marietto@marietto ~]==> sudo libinput debug-events
Password:

-event0   DEVICE_ADDED            System keyboard multiplexer       seat0
default group1  cap:k
-event1   DEVICE_ADDED            System mouse                      seat0
default group2  cap:p left scroll-nat scroll-button
-event2   DEVICE_ADDED            Sleep Button                      seat0
default group3  cap:k
-event3   DEVICE_ADDED            Power Button                      seat0
default group4  cap:k
-event4   DEVICE_ADDED            AT keyboard                       seat0
default group5  cap:k
-event5   DEVICE_ADDED            ITE Tech. Inc. ITE Device(8595), class
0/0, rev 2.00/0.03, addr 8 seat0 default group6  cap:k
-event6   DEVICE_ADDED            SIGMACHIP Trust Keyboard, class 0/0, rev
1.10/1.01, addr 12 seat0 default group7  cap:k
-event7   DEVICE_ADDED            SIGMACHIP Trust Keyboard, class 0/0, rev
1.10/1.01, addr 24 seat0 default group8  cap:k
-event8   DEVICE_ADDED            Logitech USB Optical Mouse, class 0/0,
rev 2.00/72.00, addr 25 seat0 default group9  cap:p left scroll-nat
scroll-button
-event9   DEVICE_ADDED            vendor 0x04b3 USB Optical Mouse, class
0/0, rev 2.00/2.00, addr 26 seat0 default group10 cap:p left scroll-nat
scroll-button
 event9   POINTER_MOTION          +0.176s     -0.30/  0.00 ( -1.00/ +0.00)
 event9   POINTER_MOTION          +0.184s     -1.77/  0.88 ( -2.00/ +1.00)
 event9   POINTER_MOTION          +0.352s     -0.89/  0.00 ( -1.00/ +0.00)
 event9   POINTER_MOTION          +0.360s     -0.89/  0.89 ( -1.00/ +1.00)
 event9   POINTER_MOTION          +0.368s     -2.00/  1.00 ( -2.00/ +1.00)
 event9   POINTER_MOTION          +0.376s     -2.00/  0.00 ( -2.00/ +0.00)
 event9   POINTER_MOTION          +0.384s     -4.13/  2.06 ( -4.00/ +2.00)
 event9   POINTER_MOTION          +0.392s     -4.60/  1.15 ( -4.00/ +1.00)
 event9   POINTER_MOTION          +0.400s     -9.41/  2.69 ( -7.00/ +2.00)
 event9   POINTER_MOTION          +0.408s     -8.97/  2.99 ( -6.00/ +2.00)
 event9   POINTER_MOTION          +0.416s     -8.58/  2.86 ( -6.00/ +2.00)
 event9   POINTER_MOTION          +0.424s     -8.58/  2.86 ( -6.00/ +2.00)
 event9   POINTER_MOTION          +0.432s     -5.21/  2.60 ( -4.00/ +2.00)
 event9   POINTER_MOTION          +0.440s     -2.06/  0.00 ( -2.00/ +0.00)
 event9   POINTER_MOTION          +0.480s      1.93/  0.00 ( +2.00/ +0.00)
 event9   POINTER_MOTION          +0.488s      8.00/ -3.43 ( +7.00/ -3.00)
 event9   POINTER_MOTION          +0.496s     11.25/ -4.82 ( +7.00/ -3.00)
 event9   POINTER_MOTION          +0.504s     11.09/ -3.17 ( +7.00/ -2.00)
 event9   POINTER_MOTION          +0.512s     13.17/ -4.94 ( +8.00/ -3.00)
 event9   POINTER_MOTION          +0.520s     11.39/  0.00 ( +7.00/ +0.00)
 event9   POINTER_MOTION          +0.528s      6.93/  0.00 ( +5.00/ +0.00)
 event9   POINTER_MOTION          +0.536s      6.24/  0.00 ( +5.00/ +0.00)
 event9   POINTER_MOTION          +0.544s      2.14/  0.00 ( +2.00/ +0.00)
 event9   POINTER_MOTION          +0.552s      1.00/  0.00 ( +1.00/ +0.00)
 event9   POINTER_MOTION          +0.576s     -0.95/  0.00 ( -1.00/ +0.00)
 event9   POINTER_MOTION          +0.584s     -2.86/  0.00 ( -3.00/ +0.00)
 event9   POINTER_MOTION          +0.592s     -4.18/  0.00 ( -4.00/ +0.00)
 event9   POINTER_MOTION          +0.600s     -9.21/  0.00 ( -7.00/ +0.00)
 event9   POINTER_MOTION          +0.608s     -8.76/  1.46 ( -6.00/ +1.00)
 event9   POINTER_MOTION          +0.616s     -6.75/  2.70 ( -5.00/ +2.00)
 event9   POINTER_MOTION          +0.624s     -6.41/  1.28 ( -5.00/ +1.00)
 event9   POINTER_MOTION          +0.632s     -3.39/  1.13 ( -3.00/ +1.00)
 event9   POINTER_MOTION          +0.640s     -1.00/  1.00 ( -1.00/ +1.00)
 event9   POINTER_MOTION          +0.696s      0.91/  0.00 ( +1.00/ +0.00)
 event9   POINTER_MOTION          +0.704s      0.91/  0.00 ( +1.00/ +0.00)
-event0   KEYBOARD_KEY            +1.408s    *** (-1) pressed
 event0   KEYBOARD_KEY            +1.560s    *** (-1) pressed


The USB mouse that I want to pass is this :

-event9   DEVICE_ADDED            vendor 0x04b3 USB Optical Mouse, class
0/0, rev 2.00/2.00, addr 26 seat0 default group10 cap:p left scroll-nat
scroll-button


so,between the bhyve parameters I've added ---> "-s
10,virtio-input,/dev/input/event9"

/usr/sbin/./bhyve-lin -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,ahci-hd,/mnt/zroot2/zroot2/bhyve/img/Linux/Ubuntu2410.img,bootindex=1 \
-s 3,nvme,/dev/nda0 \
-s 8:0,passthru,2/0/0 \
-s 8:1,passthru,2/0/1 \
-s 8:2,passthru,2/0/2 \
-s 8:3,passthru,2/0/3 \
-s 9,passthru,1/0/0 \
-s 10,virtio-input,/dev/input/event9 \
-s 13,virtio-net,tap1 \
-s 14,virtio-9p,sharename=/ \
-s 29,fbuf,tcp=0.0.0.0:5901,w=1600,h=950,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd \
vm0:1 < /dev/null & sleep 2 && vncviewer 0:1


Unfortunately inside Ubuntu 24.04 the "0x04b3 USB Optical Mouse" does not
move at all. I know the reason. Bhyve only uses the virtio 0.9 protocol
yet. Unfortunately, Linux requires virtio 1.0. So. How can upgrade virtio
0.9 to virtio 1.0 to match the version used by Linux ?

-- 
Mario.