devctl: Failed to detach pci0:1:0:0: Device not configured

From: Mario Marietto <marietto2008_at_gmail.com>
Date: Fri, 27 Jan 2023 00:54:49 UTC
Hello FreeBSD Virtualization Team.

I've created this bhyve script that suits my needs,but unfortunately it
does not work properly. Can someone help me to understand where the error
is ?

*./20-Ubuntu-2004-Focal-Stable-Diffusion-vm20.sh*

#!/bin/sh

vms="$(ls /dev/vmm/*)"
vncs="vm$(ps ax | awk '/vncviewer [0]/{print $6}')"
echo "*** checkpoint 1"
echo "*** checkpoint 1"
echo "*** checkpoint 1"
ls /dev/vmm
pciconf -l | grep 0:1:0:
for vm in $vms; do
                session="${vm##*/}"
                echo "bhyve session = $session"
                echo "vnc session = $vncs"
                if ! printf '%s\n' "${vncs}" | grep "${session}"; then
                                printf 'VNC session not found,destroying
ghost vms\n'
                                bhyvectl --vm=$session --destroy
#devctl detach pci0:1:0:0
#devctl detach pci0:1:0:1
#devctl set driver pci0:1:0:0 ppt
#devctl set driver pci0:1:0:1 ppt
echo "*** checkpoint 2"
echo "*** checkpoint 2"
echo "*** checkpoint 2"
ls /dev/vmm
pciconf -l | grep 0:1:0:
#sleep 999
                else
                                printf 'Found VNC session %s\n'
"${session},no ghost vms found,not destroying them"
                                #devctl detach pci0:1:0:0
                                #devctl detach pci0:1:0:1
                                #devctl set driver pci0:1:0:0 ppt
                                #devctl set driver pci0:1:0:1 ppt
                                echo "*** checkpoint 3"
                                echo "*** checkpoint 3"
                                echo "*** checkpoint 3"
ls /dev/vmm
pciconf -l | grep 0:1:0:
#sleep 999
                fi
done

echo "*** checkpoint 4"
echo "*** checkpoint 4"
echo "*** checkpoint 4"
ls /dev/vmm
pciconf -l | grep 0:1:0:

vmdisk0=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (NM13N4CZ)/
&& d{print d}'`
echo "Seagate M3 Portable 1.8 TB ; $vmdisk0"

vmdisk1=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(2015020204055E)/ && d{print d}'`
echo "TOSHIBA External USB 1.8 TB ; $vmdisk1"

vmdisk2=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(2022285F1175)/ && d{print d}'`
echo "CT1000P1SSD8 ; $vmdisk2"

vmdisk3=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(20130506005976F)/ && d{print d}'`
echo "TOSHIBA External USB 932GB ; echo $vmdisk3"

vmdisk4=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(BE0191500218)/ && d{print d}'`
echo "G-DISK ; $vmdisk4"

vmdisk5=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(38434B4237354B45)/ && d{print d}'`
echo "Elements ; $vmdisk5"

vmdisk6=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(WD-WCAV2X597309)/ && d{print d}'`
echo "WDC WD3200AAJS-00L7A0-298GB ; $vmdisk6"

vmdisk7=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(0774911DDC4200A6)/ && d{print d}'`
echo "SanDisk Cruzer-15GB ; $vmdisk7"

vmdisk8=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(60A44C4138D8F311190A0149)/ && d{print d}'`
echo "Kingston DataTraveler 2.0 ; $vmdisk8"

vmdisk9=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(20140100006C)/ && d{print d}'`
echo "SAMSUNG HM320JI ; $vmdisk9"

vmdisk10=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
(1924E20B2AE5)/ && d{print d}'`
echo "CT500MX500SSD4 ; $vmdisk10"

mount -t ufs /dev/$vmdisk1'p2' /mnt/$vmdisk1'p2'

echo "*** checkpoint 5"
echo "*** checkpoint 5"
echo "*** checkpoint 5"
ls /dev/vmm
pciconf -l | grep 0:1:0:
devctl detach pci0:1:0:0
devctl detach pci0:1:0:1
devctl set driver pci0:1:0:0 ppt
devctl set driver pci0:1:0:1 ppt

bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s
1,virtio-blk,/mnt/$vmdisk0'p2'/bhyve/img/Linux/focal-stable-diffusion.img,bootindex=1
\
-s 2,virtio-blk,/dev/$vmdisk3 \
-s 8:0,passthru,1/0/0 \
-s 8:1,passthru,1/0/1 \
-s 11,virtio-net,tap20 \
-s 12,virtio-9p,sharename=/ \
-s 13,hda,play=/dev/dsp,rec=/dev/dsp \
-s 29,fbuf,tcp=0.0.0.0:5920,w=1600,h=950 \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_BHF_CODE.fd \
vm0:20 < /dev/null & sleep 2 && vncviewer 0:20

echo "*** checkpoint 6"
echo "*** checkpoint 6"
echo "*** checkpoint 6"
ls /dev/vmm
pciconf -l | grep 0:1:0:
sleep 999

This is what happens when I launch it,regularly,but not always :

root@marietto:/usr/home/marietto/bhyve #
./20-Ubuntu-2004-Focal-Stable-Diffusion-vm20.sh

*** checkpoint 1
*** checkpoint 1
*** checkpoint 1

vm0:20
pcib1@pci0:0:1:0:       class=0x060400 rev=0x0d hdr=0x01 vendor=0x8086
device=0x1901 subvendor=0x1458 subdevice=0x5000
ppt0@pci0:1:0:0:        class=0x030000 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x1c02 subvendor=0x19da subdevice=0x2438
ppt1@pci0:1:0:1:        class=0x040300 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x10f1 subvendor=0x19da subdevice=0x2438
bhyve session = vm0:20
vnc session = vm
VNC session not found,destroying ghost vms

*** checkpoint 2
*** checkpoint 2
*** checkpoint 2

ls: /dev/vmm: No such file or directory
pcib1@pci0:0:1:0:       class=0x060400 rev=0x0d hdr=0x01 vendor=0x8086
device=0x1901 subvendor=0x1458 subdevice=0x5000
ppt0@pci0:1:0:0:        class=0x030000 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x1c02 subvendor=0x19da subdevice=0x2438
ppt1@pci0:1:0:1:        class=0x040300 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x10f1 subvendor=0x19da subdevice=0x2438

*** checkpoint 4
*** checkpoint 4
*** checkpoint 4

ls: /dev/vmm: No such file or directory
pcib1@pci0:0:1:0:       class=0x060400 rev=0x0d hdr=0x01 vendor=0x8086
device=0x1901 subvendor=0x1458 subdevice=0x5000
ppt0@pci0:1:0:0:        class=0x030000 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x1c02 subvendor=0x19da subdevice=0x2438
ppt1@pci0:1:0:1:        class=0x040300 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x10f1 subvendor=0x19da subdevice=0x2438

Seagate M3 Portable 1.8 TB ; da5
TOSHIBA External USB 1.8 TB ; da4
CT1000P1SSD8 ; nvd0
TOSHIBA External USB 932GB ; echo da2
G-DISK ;
Elements ; da3
WDC WD3200AAJS-00L7A0-298GB ; ada2
SanDisk Cruzer-15GB ;
Kingston DataTraveler 2.0 ;
SAMSUNG HM320JI ;
CT500MX500SSD4 ; ada0
mount: /dev/da4p2: Device busy

*** checkpoint 5
*** checkpoint 5
*** checkpoint 5

ls: /dev/vmm: No such file or directory
pcib1@pci0:0:1:0:       class=0x060400 rev=0x0d hdr=0x01 vendor=0x8086
device=0x1901 subvendor=0x1458 subdevice=0x5000
ppt0@pci0:1:0:0:        class=0x030000 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x1c02 subvendor=0x19da subdevice=0x2438
ppt1@pci0:1:0:1:        class=0x040300 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x10f1 subvendor=0x19da subdevice=0x2438

-----> devctl: Failed to detach pci0:1:0:0: Device not configured
-----> devctl: Failed to detach pci0:1:0:1: Device not configured
-----> bhyve: PCI device at 1/0/0 is not using the ppt(4) driver

device emulation initialization error: No such file or directory

TigerVNC Viewer 64-bit v1.12.0
Built on: 2021-11-23 05:59
Copyright (C) 1999-2021 TigerVNC Team and many others (see README.rst)
See https://www.tigervnc.org for information on TigerVNC.

Fri Jan 27 01:38:17 2023
 DecodeManager: Detected 16 CPU core(s)
 DecodeManager: Creating 4 decoder thread(s)
 CConn:       unable to connect to socket: Connection refused (61)

*** checkpoint 6
*** checkpoint 6
*** checkpoint 6

vm0:20
pcib1@pci0:0:1:0:       class=0x060400 rev=0x0d hdr=0x01 vendor=0x8086
device=0x1901 subvendor=0x1458 subdevice=0x5000
ppt0@pci0:1:0:0:        class=0x030000 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x1c02 subvendor=0x19da subdevice=0x2438
ppt1@pci0:1:0:1:        class=0x040300 rev=0xa1 hdr=0x00 vendor=0x10de
device=0x10f1 subvendor=0x19da subdevice=0x2438

^C = sleep 999

As you can see this error : "devctl: Failed to detach pci0:1:0:0: Device
not configured" is preventing me from running the VM. I've also tried to
don't detach pci0:1:0:0 and detach pci0:1:0:1,but in this case,the error is
: "bhyve: PCI device at 1/0/0 is not using the ppt(4) driver". I'm sure
that you will understand fast and that you can know how to replicate the
experiment using the values according to your system.

Thanks.

-- 
Mario.