[Bug 265869] mmio_rb_lookup finds wrong entry, triggering assertion

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 16 Aug 2022 03:02:49 UTC

            Bug ID: 265869
           Summary: mmio_rb_lookup finds wrong entry, triggering assertion
           Product: Base System
           Version: CURRENT
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bhyve
          Assignee: virtualization@FreeBSD.org
          Reporter: harris.snyder@gmail.com

Hi all. While trying to pass a USB controller through to a VM via PCI
passthrough, I hit an assertion in unregister_mem (usr.sbin/bhyve/mem.c):

assert(mr->name == memp->name);

I hooked the process up to a debugger and printed out the two names, and
discovered that indeed: 

mr->name    =  "passthru-pci-22"
memp->name  =  "virtio-net-pci-2"

so clearly mmio_rb_lookup is returning the wrong memory range.

I'm not very knowledgeable about the internals of bhyve, and I don't yet have
any further insight into why this might be occurring, but even if this was
caused by user error, it is triggering an assertion and thus I feel is worth
treating as a bug. 

Here's my bhyve command:

bhyve -AHP -S -w -c sockets=1,cores=8 -m 16G \
        -s 0,amd_hostbridge \
        -s 31,lpc \
        -s 2,virtio-net,tap1,mac=00:A0:98:41:AC:CB \
        -s 3,virtio-net,tap12,mac=00:A0:98:88:6F:09,mtu=9000 \
        -s 13,ahci-hd,/dev/zvol/fast/vols/winvm1 \
        -s 7,virtio-rnd \
        -s 9,xhci,tablet \
        -s 22,passthru,35/0/3 \
        -l bootrom,/root/BHYVE_BHF_CODE.fd \

And here's the pciconf entry for the device I'm trying to pass through:

ppt0@pci0:35:0:3:       class=0x0c0330 rev=0x00 hdr=0x00 vendor=0x1022
device=0x148c subvendor=0x15d9 subdevice=0x145c
    vendor     = 'Advanced Micro Devices, Inc. [AMD]'
    device     = 'Starship USB 3.0 Host Controller'
    class      = serial bus
    subclass   = USB

You are receiving this mail because:
You are the assignee for the bug.