Opened 3 years ago

Closed 14 months ago

#17238 closed bug (fixed)

[virtio] Support modern virtio v2 PCI virtio block

Reported by: kallisti5 Owned by: nobody
Priority: normal Milestone: R1/beta5
Component: Drivers/Disk/Virtio Version: R1/beta3
Keywords: virtio virtio_block Cc:
Blocked By: Blocking:
Platform: All

Description (last modified by kallisti5)

It looks like a newer "modern" virtio v2 design is now in use which our drivers don't work with. The PCI device ID's are higher.

Seen on a vultr vm trying to boot Haiku R1/beta3

src/add-ons/kernel/drivers/disk/virtual/virtio_block/virtio_block.cpp likely needs some code path to attach to a "virtio bus" or a "pci bus"

Attachments (1)

virtio_block.png (114.1 KB ) - added by kallisti5 3 years ago.
example

Download all attachments as: .zip

Change History (11)

by kallisti5, 3 years ago

Attachment: virtio_block.png added

example

comment:1 by kallisti5, 3 years ago

target is R1/Beta4 because if we ever want to run haikuporter builders in cloud environments, solid virtio block support will be critical.

comment:3 by kallisti5, 3 years ago

Oddly looking at these devices.. our virtio_pci bus driver checks for the virtio vendor and a device in the ranges:

#define VIRTIO_PCI_VENDORID     0x1AF4
#define VIRTIO_PCI_DEVICEID_MIN 0x1000
#define VIRTIO_PCI_DEVICEID_MAX 0x103F

The virtio block device in this VM is 1af4:1042 which is outside of that MIN/MAX range :-| Does that guide the user to attach directly, or does the min/max need expanded to pick up the devices?

comment:4 by kallisti5, 3 years ago

Here's what linux looks for:

/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */
static const struct pci_device_id virtio_pci_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_ANY_ID) },
        { 0 }
};

maybe we're artificially limiting our device id's too much?

comment:5 by kallisti5, 3 years ago

ah ha.

FreeBSD: sys/dev/virtio/pci/virtio_pci_legacy.c

        if (pci_get_vendor(dev) != VIRTIO_PCI_VENDORID)
                return (ENXIO);

        if (pci_get_device(dev) < VIRTIO_PCI_DEVICEID_MIN ||
            pci_get_device(dev) > VIRTIO_PCI_DEVICEID_LEGACY_MAX)
                return (ENXIO);

Freebsd sys/dev/virtio/pci/virtio_pci_modern.c

       if (pci_get_vendor(dev) != VIRTIO_PCI_VENDORID)
                return (ENXIO);

        if (pci_get_device(dev) < VIRTIO_PCI_DEVICEID_MIN ||
            pci_get_device(dev) > VIRTIO_PCI_DEVICEID_MODERN_MAX)
                return (ENXIO);

        if (pci_get_device(dev) < VIRTIO_PCI_DEVICEID_MODERN_MIN) {
                if (!vtpci_modern_transitional)
                        return (ENXIO);
                devid = pci_get_subdevice(dev);
        } else
                devid = pci_get_device(dev) - VIRTIO_PCI_DEVICEID_MODERN_MIN;
sys/dev/virtio/pci/virtio_pci_var.h:#define VIRTIO_PCI_DEVICEID_MIN	0x1000
sys/dev/virtio/pci/virtio_pci_var.h:#define VIRTIO_PCI_DEVICEID_LEGACY_MAX	0x103F
sys/dev/virtio/pci/virtio_pci_var.h:#define VIRTIO_PCI_DEVICEID_MODERN_MIN	0x1040
sys/dev/virtio/pci/virtio_pci_var.h:#define VIRTIO_PCI_DEVICEID_MODERN_MAX	0x107F

So..

  • deviceid 0x1000 - 0x103F is "Virtio Legacy"
  • deviceid 0x1040 - 0x107F is "Virtio Modern"

ugh.

comment:6 by kallisti5, 3 years ago

Per this... it appears qemu may have a way to enable the "modern, virtio v2" interface..

https://lists.sr.ht/~philmd/qemu/patches/8154

For this reason, the v2 personality is disabled, keeping the legacy
behavior as default. Machine types willing to use v2, can enable it
using MachineClass's compat_props.

I'm guessing this is what Vultr has enabled for some reason.

comment:7 by kallisti5, 3 years ago

Description: modified (diff)
Summary: [virtio] Support "direct attach" PCI virtio block[virtio] Support modern virtio v2 PCI virtio block

comment:8 by kallisti5, 3 years ago

see https://review.haiku-os.org/c/haiku/+/4420 for an early "quick" solution. It fixes the missing virtio devices for me locally.

This appears to be a change of default functionality in qemu-6.1.0? I've been surfing the qemu changes but don't see a reference.

comment:9 by pulkomandy, 3 years ago

Milestone: R1/beta4Unscheduled

Moving various tickets out of the beta4 milestone because no one is actively working on them.

comment:10 by korli, 14 months ago

Milestone: UnscheduledR1/beta5
Resolution: fixed
Status: newclosed

fixed in hrev57329

Note: See TracTickets for help on using tickets.