hw/vmapple: boot macOS 27 guests: virtio capabilities in address order

macOS 27's virtio PCI transport never starts a device whose capability
list runs from high offsets to low, as QEMU links it (MSI-X at 0x98,
then 0x84, 0x70 and on down): its cached and its fallback capability
lookups disagree on such a list. Each virtio device of a macOS 27.0.1
(26A434) guest read the PCI_CFG capability at 0x84, then the notify
capability at 0x70 and BAR 4's type, then started over, about 100,000
config reads a second. No device's status left 0, the root disk saw no
I/O, and the kernel never reached its GPU driver: a black screen. macOS
26 walks the same list once and goes on.

Relink the capabilities in ascending address order, keeping each one's
offset and contents: always on vmapple-virtio-blk-pci, and on
virtio-net-pci when x-ascending-capabilities is on (off by default).
vmapple-virtio-blk-pci also states subsystem ID 0x1100, the value it
already had, and gains Apple's vendor capability: virtio cfg_type 9,
vendor 0x106b, 14 bytes, with its transport encryption disabled flag
set. The patch's author found a non-FileVault root disk needs it; that
was not isolated from the reordering.

With both, a macOS 27.0.1 guest mounts its root volume, its virtio
devices reach DRIVER_OK, and it reaches Setup Assistant.

Not for upstream: written with an AI assistant, which QEMU's policy on
AI-generated content (docs/devel/code-provenance.rst) declines.

Co-authored-by: Jesus Martínez <jesse_m@naver.com>
This commit is contained in:
Anees IqbalandJesus Martínez committed 2026-11-15 01:57:09 -08:00
1 parent 83de566436
commit 4a39ef8d54
2 files changed
+64

No files matched your search

+25
View File
@@ -36,9 +36,12 @@ DECLARE_INSTANCE_CHECKER(VirtIONetPCI, VIRTIO_NET_PCI,
struct VirtIONetPCI {
VirtIOPCIProxy parent_obj;
VirtIONet vdev;
bool ascending_capabilities;
};
static const Property virtio_net_properties[] = {
DEFINE_PROP_BOOL("x-ascending-capabilities", VirtIONetPCI,
ascending_capabilities, false),
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
@@ -61,6 +64,28 @@ static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
virtio_net_set_netclient_name(&dev->vdev, qdev->id,
object_get_typename(OBJECT(qdev)));
qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
if (dev->ascending_capabilities && qdev_is_realized(vdev)) {
uint8_t *config = vpci_dev->pci_dev.config;
bool capabilities[PCI_CONFIG_SPACE_SIZE] = { false };
unsigned offset, previous = PCI_CAPABILITY_LIST;
/* Local Golden Gate workaround: its cached and fallback capability
* lookups revisit PCI_CFG and NOTIFY forever on descending lists.
* Keep capability contents and offsets; only reorder the links. */
for (offset = config[PCI_CAPABILITY_LIST]; offset;
offset = config[offset + PCI_CAP_LIST_NEXT]) {
capabilities[offset] = true;
}
for (offset = PCI_CONFIG_HEADER_SIZE; offset < PCI_CONFIG_SPACE_SIZE;
offset++) {
if (capabilities[offset]) {
config[previous] = offset;
previous = offset + PCI_CAP_LIST_NEXT;
}
}
config[previous] = 0;
}
}
static void virtio_net_pci_class_init(ObjectClass *klass, const void *data)
+39
View File
@@ -16,6 +16,7 @@
*/
#include "qemu/osdep.h"
#include "hw/pci/pci.h"
#include "hw/vmapple/vmapple.h"
#include "hw/virtio/virtio-blk.h"
#include "hw/virtio/virtio-pci.h"
@@ -44,6 +45,8 @@ typedef struct VMAppleVirtIOBlk {
OBJECT_DECLARE_SIMPLE_TYPE(VMAppleVirtIOBlkPCI, VMAPPLE_VIRTIO_BLK_PCI)
#define VIRTIO_BLK_T_APPLE_BARRIER 0x10000
#define VMAPPLE_PCI_VNDR_SIZE 14
#define VMAPPLE_PCI_VNDR_DISABLE_ENCRYPTION 1
static bool vmapple_virtio_blk_handle_unknown_request(VirtIOBlockReq *req,
MultiReqBuffer *mrb,
@@ -125,6 +128,10 @@ static void vmapple_virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **err
VMAppleVirtIOBlkPCI *dev = VMAPPLE_VIRTIO_BLK_PCI(vpci_dev);
DeviceState *vdev = DEVICE(&dev->vdev);
VirtIOBlkConf *conf = &dev->vdev.parent_obj.conf;
int offset;
uint8_t capabilities[PCI_CONFIG_SPACE_SIZE] = { 0 };
uint8_t *config = vpci_dev->pci_dev.config;
int previous = PCI_CAPABILITY_LIST;
if (dev->variant == VM_APPLE_VIRTIO_BLK_VARIANT_UNSPECIFIED) {
error_setg(errp, "vmapple virtio block device variant unspecified");
@@ -162,6 +169,38 @@ static void vmapple_virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **err
pci_config_set_vendor_id(vpci_dev->pci_dev.config, PCI_VENDOR_ID_APPLE);
pci_config_set_device_id(vpci_dev->pci_dev.config,
PCI_DEVICE_ID_APPLE_VIRTIO_BLK);
pci_set_word(vpci_dev->pci_dev.config + PCI_SUBSYSTEM_ID, 0x1100);
/* A non-FileVault Golden Gate root disk requires Apple's vendor
* capability to advertise that transport encryption is disabled. */
offset = pci_add_capability(&vpci_dev->pci_dev, PCI_CAP_ID_VNDR, 0,
VMAPPLE_PCI_VNDR_SIZE, errp);
if (offset < 0) {
return;
}
pci_set_byte(vpci_dev->pci_dev.config + offset + 2,
VMAPPLE_PCI_VNDR_SIZE);
pci_set_byte(vpci_dev->pci_dev.config + offset + 3, 9);
pci_set_word(vpci_dev->pci_dev.config + offset + 4, PCI_VENDOR_ID_APPLE);
pci_set_byte(vpci_dev->pci_dev.config + offset + 6,
VMAPPLE_PCI_VNDR_DISABLE_ENCRYPTION);
/* Golden Gate's cached capability lookup and its fallback disagree on
* descending lists: the storage probe alternates between the final
* vendor capability and VIRTIO_PCI_CAP_PCI_CFG forever. Keep the same
* capabilities and offsets, but enumerate them in address order. */
for (offset = config[PCI_CAPABILITY_LIST]; offset;
offset = config[offset + PCI_CAP_LIST_NEXT]) {
capabilities[offset] = 1;
}
for (offset = PCI_CONFIG_HEADER_SIZE; offset < PCI_CONFIG_SPACE_SIZE;
offset++) {
if (capabilities[offset]) {
config[previous] = offset;
previous = offset + PCI_CAP_LIST_NEXT;
}
}
config[previous] = 0;
}
static void vmapple_virtio_blk_pci_class_init(ObjectClass *klass,