🐛 Link virtio-sound-pci's capabilities in address order on vmapple
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): 4a39ef8d54 relinked vmapple-virtio-blk-pci's and,
through x-ascending-capabilities, virtio-net-pci's, but not
virtio-sound-pci's. On a macOS 27.2.1 (26B131) guest under KVM, each
virtio-sound-pci device's IOConfigThread spun in AppleVirtIO, reading the
PCI_CFG capability at 0x84 and the notify capability at 0x70 byte by byte
through IOPCIFamily, forever ("triggered fail-safe by spinning for at
least 1000000us at fixed priority"): its transport never registered, its
status stayed 0, and kernel_task took two of four vCPUs. In some boots the
spin stopped the boot before the root disk's driver started.
virtio-sound-pci gains x-ascending-capabilities, which relinks its list
in ascending address order after its realize, keeping each capability's
offset and contents, as virtio-net-pci's does; off by default, and on for
the vmapple machine.
With it, a 27.2.1 guest's two virtio-sound-pci devices (an output stream
alone and an input stream alone, on one pipewire audiodev) reach
DRIVER_OK, Core Audio lists two "Apple Virtual Sound Device"s, the
default output and the default input, and afplay's sound reaches the
host's speakers through PipeWire.
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: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
53e766304f
commit
5c42f3fce4
2 files changed
+27
No files matched your search
@@ -12,6 +12,7 @@
|
||||
#include "qom/object.h"
|
||||
#include "qapi/error.h"
|
||||
#include "hw/audio/model.h"
|
||||
#include "hw/pci/pci.h"
|
||||
#include "hw/virtio/virtio-pci.h"
|
||||
#include "hw/audio/virtio-snd.h"
|
||||
|
||||
@@ -25,12 +26,15 @@ struct VirtIOSoundPCI {
|
||||
VirtIOPCIProxy parent_obj;
|
||||
|
||||
VirtIOSound vdev;
|
||||
bool ascending_capabilities;
|
||||
};
|
||||
|
||||
static const Property virtio_snd_pci_properties[] = {
|
||||
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
|
||||
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
|
||||
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
|
||||
DEFINE_PROP_BOOL("x-ascending-capabilities", VirtIOSoundPCI,
|
||||
ascending_capabilities, false),
|
||||
};
|
||||
|
||||
static void virtio_snd_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
||||
@@ -40,6 +44,28 @@ static void virtio_snd_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
||||
|
||||
virtio_pci_force_virtio_1(vpci_dev);
|
||||
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;
|
||||
|
||||
/* macOS 27's virtio PCI transport revisits PCI_CFG and NOTIFY
|
||||
* forever on a descending list, as virtio-net-pci's does. 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_snd_pci_class_init(ObjectClass *klass, const void *data)
|
||||
|
||||
@@ -743,6 +743,7 @@ static GlobalProperty vmapple_compat_defaults[] = {
|
||||
* capabilities are linked from high offsets to low.
|
||||
*/
|
||||
{ "virtio-net-pci-base", "x-ascending-capabilities", "on" },
|
||||
{ "virtio-sound-pci", "x-ascending-capabilities", "on" },
|
||||
/*
|
||||
* macOS's virtio-net driver can miss the completion of its first control
|
||||
* command, which QEMU gives before the driver waits for it, and the
|
||||
|
||||
Reference in new issue
Block a user