QEMU CPU Topology for macOS guests

Hi guys,

First time poster here. I was wondering if this community can help me with a minor issue with qemu/kvm.
I’m running a macOS (Mojave) guest inside a QEMU/KVM Virtual Machine. Host is debian 10 buster, Ryzen 1700, 32GB RAM, X370 board etc. I’m passing through a USB Controller and a Radeon RX 560 (that, by the way, does not appear to suffer from the ominous reset bug) and everything works actually pretty damn well.

The one thing that doesn’t work, however, is CPU topology. Currently, I pass through 16 CPU sockets / 1 Core / 1 Thread. As soon as I set the number of cores or threads > 1 I get kernel panic when booting.

Question: Do I even need to bother? Cinebench R20 shows the same score as for a reference Ryzen 1700X. If no, fine. If yes, how can I properly set the CPU topology?

FWIW, setting the CPU topology works fine under windows. Furthermore, I use Haswell Fake CPU ID in Clover.

Any help or idea is greatly appreciated.


Here’s my VM’s xml:

<domain type='kvm' id='25' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <memory unit='KiB'>25165824</memory>
  <currentMemory unit='KiB'>25165824</currentMemory>
  <vcpu placement='static'>16</vcpu>
    <type arch='x86_64' machine='pc-q35-3.1'>hvm</type>
    <loader readonly='yes' type='pflash'>/home/libvirt/osx/firmware/OVMF_CODE.fd</loader>
    <vmport state='off'/>
  <cpu mode='custom' match='exact' check='full'>
    <model fallback='forbid'>EPYC</model>
    <feature policy='disable' name='pclmuldq'/>
    <feature policy='disable' name='monitor'/>
    <feature policy='disable' name='fma'/>
    <feature policy='disable' name='pcid'/>
    <feature policy='require' name='x2apic'/>
    <feature policy='disable' name='movbe'/>
    <feature policy='disable' name='f16c'/>
    <feature policy='disable' name='rdrand'/>
    <feature policy='require' name='hypervisor'/>
    <feature policy='disable' name='arat'/>
    <feature policy='disable' name='fsgsbase'/>
    <feature policy='disable' name='bmi1'/>
    <feature policy='disable' name='smep'/>
    <feature policy='disable' name='bmi2'/>
    <feature policy='disable' name='rdseed'/>
    <feature policy='disable' name='adx'/>
    <feature policy='disable' name='smap'/>
    <feature policy='disable' name='clflushopt'/>
    <feature policy='disable' name='sha-ni'/>
    <feature policy='disable' name='xsavec'/>
    <feature policy='disable' name='xgetbv1'/>
    <feature policy='disable' name='mmxext'/>
    <feature policy='disable' name='fxsr_opt'/>
    <feature policy='disable' name='pdpe1gb'/>
    <feature policy='disable' name='rdtscp'/>
    <feature policy='disable' name='svm'/>
    <feature policy='disable' name='cr8legacy'/>
    <feature policy='disable' name='abm'/>
    <feature policy='disable' name='sse4a'/>
    <feature policy='disable' name='misalignsse'/>
    <feature policy='disable' name='3dnowprefetch'/>
    <feature policy='disable' name='osvw'/>
    <feature policy='require' name='invtsc'/>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/home/libvirt/osx/ESP.qcow2'/>
      <target dev='sda' bus='sata'/>
      <boot order='1'/>
      <alias name='sata0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/home/libvirt/osx/BaseSystem.img'/>
      <target dev='sdb' bus='sata'/>
      <alias name='sata0-0-1'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/home/libvirt/osx/osx.img'/>
      <target dev='sdc' bus='sata'/>
      <alias name='sata0-0-2'/>
      <address type='drive' controller='0' bus='0' target='0' unit='2'/>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x7'/>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <alias name='usb'/>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x0' multifunction='on'/>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <alias name='usb'/>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x1'/>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <alias name='usb'/>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x2'/>
    <controller type='sata' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
    <controller type='pci' index='0' model='pcie-root'>
      <alias name='pcie.0'/>
    <controller type='pci' index='1' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='1' port='0x8'/>
      <alias name='pci.1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/>
    <controller type='pci' index='2' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='2' port='0x9'/>
      <alias name='pci.2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    <controller type='pci' index='3' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='3' port='0xa'/>
      <alias name='pci.3'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    <interface type='network'>
      <mac address='52:54:00:92:d4:7b'/>
      <source network='default' bridge='virbr0'/>
      <target dev='vnet0'/>
      <model type='e1000-82545em'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    <input type='mouse' bus='usb'>
      <alias name='input0'/>
      <address type='usb' bus='0' port='1'/>
    <input type='keyboard' bus='usb'>
      <alias name='input1'/>
      <address type='usb' bus='0' port='2'/>
    <input type='mouse' bus='ps2'>
      <alias name='input2'/>
    <input type='keyboard' bus='ps2'>
      <alias name='input3'/>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
        <address domain='0x0000' bus='0x08' slot='0x00' function='0x0'/>
      <alias name='hostdev0'/>
      <rom bar='on' file='/root/radeon560.rom'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
        <address domain='0x0000' bus='0x08' slot='0x00' function='0x1'/>
      <alias name='hostdev1'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
        <address domain='0x0000' bus='0x09' slot='0x00' function='0x3'/>
      <alias name='hostdev2'/>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
    <memballoon model='none'/>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <qemu:arg value='-cpu'/>
    <qemu:arg value='Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+pcid,+ssse3,+sse4.2,+popcnt,+avx2,+avx,+aes,+xsave,+xsaveopt,check'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc'/>
    <qemu:arg value='-smbios'/>
    <qemu:arg value='type=2'/>
1 Like

I set this up earlier this year but don’t remember off hand what the socket/thread config was. I believe the way you have it set up is correct. I think this is the most recent post we have about it.

I saw somewhere that it was possible to use i440fx instead of q35, but I was never able to get it working.

So fun thing about macos being based on basd is that you don’t see a lot of multi-socket conflicts when it comes to running it on a VM. What you will see occasionally, more often from and chips than Intel, is some guff over cores. You’ve seen that already. However, setting up multiple sockets, at least to macos in a VM, is just the same as having multiple cores. So if you wanted to throw 10 threads / “sockets” to a VM, it’ll treat it the same way.

I’ve been playing with qemu recently and that’s my understanding of it. Don’t hold me to authority though as I’m only just starting to play with qemu at all.

1 Like

Thanks. I’ll look into it. I don’t really have any solid background knowledge on QEMU I’m afraid, but this post is a good start.

1 Like

I am not sure whether or not it is worth bothering. I’ve read forum posts that stated that Ryzen’s internal latencies are bad, especially for gaming (which I’m not doing on a macos VM) and exacerbated if the CPU configuration is not optimized.
The only thing I can tell is that my macOS VM feels significantly snappier than my 2015 MBP (Core I7 4770HQ, 16GB RAM, 256GB NVMe storage) but I’m still a bit uncertain whether or not I’m sacrificing a significant amount of performance due to unoptimized configuration.

1 Like

It’s difficult to know without a solid reference point, but if it’s feeling significantly snappier than your mbp, you must be on the right track.

What is the use case for the VM?

What is the use case for the VM?

Software development and casual/leisure use. I have a 15" MBP (the one I mentioned in my previous post) at work but I don’t want to carry it around, hence the VM, and sometimes I want to work from home.

Generally, the VM actually feels great! USB 3.0 works like a charm, so does the GPU, I have loads of RAM & fast storage and more CPU cores than I need to build and run my projects. It’s also very reliable and stable. I can reset/shutdown/turn off the VM, start another Windows VM (that uses a different GPU), kill that one, reboot the Mac VM etc. all without rebooting the host. I’m honestly impressed by the current state of Linux/KVM.

You can see here for further information.
topology panic when using cpu generation newer than Penryn

This is closed as it is outside the revived thread guidelines. Feel free to create a fresh topic, or PM me or one of the Leaders if you think this was incorrectly closed. See here for more info.