Tuning QEMU/KVM CPU Models and Topoext Flags on AMD EPYC Hypervisors

Technical architecture diagram illustrating AMD EPYC KVM Topoext Flags
Verified Answer

To expose accurate AMD EPYC L3 cache boundaries and SMT sibling pairs to KVM guests, enable the topoext CPUID flag (0x8000001E) alongside cache passthrough mode and a generation-matched CPU model like EPYC-Genoa or host-passthrough. Restoring true CCX topology prevents guest schedulers from bouncing threads across Infinity Fabric, improving database and build throughput by 12%–28%.

Quick Takeaway: Exposing True AMD EPYC L3 & SMT Topology to KVM Guests

Out of the box, QEMU/KVM presents virtualized CPUs as flat cores stripped of AMD Core Complex (CCX) L3 cache masks and Simultaneous Multithreading (SMT) sibling pairs. Enabling topoext (CPUID leaf 0x8000001E) alongside <cache mode='passthrough'/> and a generation-matched CPU model (EPYC-Genoa, EPYC-Milan, or host-passthrough) restores accurate die, CCD, and L3 boundaries to the guest Linux scheduler—eliminating cross-CCX bouncing and boosting multi-threaded database and build throughput by 12–28%.

Hypervisor Scope: AMD EPYC 7003 (Milan), 9004 (Genoa), & 9005 (Turin), QEMU 8.2+, libvirt 10.0+, Linux KVM 6.6+

Default QEMU/KVM CPU models strip away AMD cache topology and SMT sibling masks, leaving guest Linux schedulers blind to physical CCD boundaries. That missing visibility causes cross-CCX thread bouncing and degraded multi-threaded VM performance. Below, we configure topoext, compare CPU models, and check live migration.

Flat Virtual Topology Loss

Generic KVM processor models hide L3 cache sharing and SMT pairs, forcing guest schedulers into cross-CCX bouncing.

Migration vs Passthrough Tradeoff

Using host-passthrough maximizes ISA and cache accuracy, whereas named EPYC-Genoa models preserve live migration across mixed hosts.

Libvirt XML and CPUID Checks

Add topoext and passthrough cache attributes in libvirt XML, then verify CPUID leaf 0x8000001E inside the guest.

1. Why Default QEMU CPU Models Break AMD EPYC Cache Locality

To understand why guest performance degrades under default QEMU settings, inspect how the Linux scheduler makes placement decisions. During guest boot, the kernel queries CPUID leaves to build its scheduling domains: SMT (thread siblings), MC (multi-core / L3 cache sharing), DIE, and NUMA. On AMD processors, the hardware exposes SMT sibling IDs, Core IDs, and Compute Unit / Node IDs via extended CPUID leaf 0x8000001E—gated by the topoext feature bit in CPUID 0x80000001:ECX[22].

When QEMU launches a VM with qemu64 or without topoext, CPUID 0x8000001E is zeroed out or omitted, and QEMU’s default cache model reports a separate, private L3 cache for every single vCPU. As a result, a 16-vCPU database VM running PostgreSQL or Kafka assumes there is zero cache-sharing benefit to keeping worker threads on vCPUs 0–7 versus migrating them to vCPUs 8–15. If those vCPUs span two physical CCDs on the host, every thread migration invalidates 32 MB of warm L3 cache and forces cross-die cache coherency probes across the I/O Die (IOD).

Hypervisor Prerequisites: SVM, IOMMU, and Host NUMA Alignment

Before tuning guest XML definitions, confirm three host-level prerequisites on your bare-metal AMD EPYC hypervisor:

  • BIOS SVM & IOMMU Enablement: Verify that SVM Mode (Secure Virtual Machine) and IOMMU are enabled in BIOS, and confirm kvm_amd is loaded on the host kernel.
  • NPS Mode Alignment: If your hypervisor hosts multi-CCD VMs, align BIOS NUMA-Per-Socket (NPS1, NPS2, or NPS4) with your VM sizing strategy. Review our AMD EPYC NPS1, NPS2, and NPS4 NUMA Tuning guide and Infinity Fabric CCD-to-IOD Latency Analysis for exact memory-to-core mapping.
  • QEMU 8.1+ & Libvirt 9.6+: Older QEMU releases lack the EPYC-Genoa named model and cannot expose Zen 4/5 AVX-512 flags cleanly without host-passthrough.

2. QEMU CPU Model Comparison: host-passthrough vs. EPYC-Genoa vs. EPYC-Milan

Selecting the right QEMU CPU mode is a trade-off between exposing maximum silicon instructions (AVX-512, VNNI, SEV-SNP, INVLPGB) and maintaining live-migration compatibility across a fleet of servers with different EPYC generations or AGESA firmware revisions.

QEMU / Libvirt CPU Mode Exposed ISA & Topology Flags Live Migration Scope Best-Fit Production Workload
host-passthrough + topoext 100% host CPUID, AVX-512, BF16, invtsc Identical CPU SKU, stepping, and AGESA only Pinned single-node DBs, AI inference, HPC
EPYC-Genoa (QEMU 8.1+) Zen 4 baseline, AVX-512, VNNI, topoext Cross-host EPYC 9004 & 9005 Turin clusters Mixed Genoa/Turin KVM HA clusters
EPYC-Milan Zen 3 baseline, PCID, INVLPGB, topoext EPYC 7003, 9004, and 9005 hypervisors Heterogeneous multi-gen live migration pools
host-model Libvirt-detected baseline (often drops new flags) Hosts matching libvirt CPU map Avoid if EPYC-Genoa / host-passthrough works
qemu64 (Default fallback) Generic x86_64, no AVX2/AVX-512, no topoext Universal (even cross-vendor) Emergency rescue images only

Note a subtle libvirt gotcha: host-model relies on libvirt’s static XML CPU database (/usr/share/libvirt/cpu_map/), which often lags behind newly released kernel KVM features and silently strips topoext or AVX-512 sub-flags. Always prefer explicit host-passthrough for maximum performance or named EPYC-Genoa / EPYC-Milan models for deterministic live migration.

3. Step-by-Step: Libvirt XML for topoext, Cache Passthrough, and CCD Pinning

To give a guest VM true bare-metal cache locality on an AMD EPYC host, you must align three layers in the libvirt domain XML: the CPU model and topoext feature flag, the <topology> and <cache mode='passthrough'/> elements, and 1:1 <vcpupin> bindings that map guest vCPUs onto a single physical host CCD.

For example, on a 32-core EPYC 9354 (4 CCDs of 8 physical cores / 16 threads each), a 16-vCPU VM fits cleanly inside CCD 0 (physical cores 0–7 and their SMT siblings 32–39). Pinning all 16 vCPUs to CCD 0 while isolating QEMU emulator/vhost threads onto a separate core eliminates cross-CCD Infinity Fabric hops entirely.

Terminal / Bash

<!-- Snapshot existing XML first: virsh dumpxml vm-prod-01 > /root/vm-prod-01.backup.xml -->
<vcpu placement='static'>16</vcpu>

<cputune>
  <!-- Pin 16 vCPUs (8 physical cores + 8 SMT siblings) strictly to CCD 0 -->
  <vcpupin vcpu='0' cpuset='0'/>
  <vcpupin vcpu='1' cpuset='32'/>
  <vcpupin vcpu='2' cpuset='1'/>
  <vcpupin vcpu='3' cpuset='33'/>
  <vcpupin vcpu='4' cpuset='2'/>
  <vcpupin vcpu='5' cpuset='34'/>
  <vcpupin vcpu='6' cpuset='3'/>
  <vcpupin vcpu='7' cpuset='35'/>
  <vcpupin vcpu='8' cpuset='4'/>
  <vcpupin vcpu='9' cpuset='36'/>
  <vcpupin vcpu='10' cpuset='5'/>
  <vcpupin vcpu='11' cpuset='37'/>
  <vcpupin vcpu='12' cpuset='6'/>
  <vcpupin vcpu='13' cpuset='38'/>
  <vcpupin vcpu='14' cpuset='7'/>
  <vcpupin vcpu='15' cpuset='39'/>
  <!-- Isolate QEMU I/O & vhost emulation threads off CCD 0 -->
  <emulatorpin cpuset='8,40'/>
</cputune>

<cpu mode='host-passthrough' check='none' migratable='off'>
  <topology sockets='1' dies='1' clusters='1' cores='8' threads='2'/>
  <cache mode='passthrough'/>
  <feature policy='require' name='topoext'/>
  <feature policy='require' name='invtsc'/>
</cpu>

If your VM requires more than 8 physical cores (for instance, a 32-vCPU guest spanning two CCDs on a single socket), set clusters='2' cores='8' threads='2' in QEMU 8.1+ (-smp 32,clusters=2,cores=8,threads=2) so the guest kernel builds two separate 8-core L3 scheduling domains instead of assuming all 32 vCPUs share one L3 cache.

Pairing vCPU Pinning with NUMA Memory Binding and 1 GB HugePages

Exposing topoext fixes L3 cache scheduling inside the guest, but if QEMU allocates guest RAM across remote NUMA nodes or relies on 4 KB standard pages, Nested Page Table (NPT) TLB misses will still throttle database and virtualization throughput. On multi-NUMA EPYC servers running NPS2 or NPS4, pair <vcpupin> with <numatune> strict memory binding to the exact host NUMA node housing your pinned CCD, and back guest memory with 2 MB or 1 GB HugePages.

Allocating 1 GB HugePages reduces NPT two-dimensional page-walk overhead dramatically during random-access workloads like Redis, PostgreSQL, or Java heaps. Additionally, for VMs equipped with SR-IOV VF NICs or NVMe-oF pass-through controllers, always pin the guest onto the NUMA node whose PCIe Root Complex directly owns that physical slot—eliminating cross-socket or cross-quadrant Infinity Fabric DMA traversal.

4. Verifying Guest CPUID Leaf 0x8000001E and L3 Masks via Linux CLI

Never assume libvirt passed your CPU flags through unaltered. Before deploying production workloads, inspect the host’s physical CCD-to-L3 mapping and then verify the resulting topology inside the booted guest VM.

SQL / Query

# --- Run on the KVM Hypervisor Host ---
# 1. Map physical cores, SMT siblings, and L3 cache IDs to plan vcpupin
lscpu -e=CPU,NODE,SOCKET,CORE,L3

# 2. Confirm KVM supports topoext, nonstop_tsc, and AVX-512 on host
grep -oE 'topoext|nonstop_tsc|avx512f' /proc/cpuinfo | sort -u

# 3. List supported EPYC CPU models in installed QEMU binary
qemu-system-x86_64 -cpu help | grep -i EPYC

# --- Run Inside the Guest VM ---
# 4. Verify all 16 vCPUs share L3=0 and show paired CORE IDs (0,0 .. 7,7)
lscpu -e=CPU,CORE,L3

# 5. Inspect raw CPUID leaf 0x8000001E (requires cpuid package)
cpuid -1 -l 0x8000001e | head -n 18

In the guest output of lscpu -e=CPU,CORE,L3, a properly tuned 16-vCPU single-CCD VM will show all 16 logical CPUs sharing L3=0, with consecutive pairs sharing the same CORE ID (0,0, 1,1, …, 7,7). If you instead see 16 distinct L3 IDs (0 through 15), <cache mode='passthrough'/> or topoext was stripped by QEMU or libvirt.

Validating SMT Sibling Placement and x2APIC Interrupt Delivery

Once lscpu confirms accurate L3 and core pairing inside the guest, verify that the guest kernel also sees x2apic and avic (AMD Advanced Virtual Interrupt Controller) when supported by your host kernel and QEMU version. Hardware-accelerated AVIC / x2APIC reduces VM-exit overhead during high-frequency inter-processor interrupts (IPIs) and virtio-blk / virtio-net queue notifications. You can benchmark the improvement directly using perf stat -e kvm:* on the hypervisor host while running sysbench cpu or pgbench inside the guest: properly pinned, topoext-enabled guests consistently show fewer cross-core IPIs, lower LLC-load-misses, and tighter P99 query latency.

5. Troubleshooting Live Migration Blockers and Safe XML Rollback

Enabling host-passthrough, topoext, and invtsc can trigger startup errors or live-migration rejections if cluster nodes differ slightly in firmware or QEMU versions. Use the diagnostics below to resolve the two most frequent blockers.

invtsc Blocking Live Migration

invtsc requires migratable='off' because TSC frequency can vary across motherboards. For live-migratable clusters, remove invtsc, switch to <cpu mode='custom' match='exact'><model fallback='allow'>EPYC-Genoa</model>, and keep topoext.

Guest Boot Error on Nested SVM

If a nested hypervisor guest fails to initialize topoext, verify cat /sys/module/kvm_amd/parameters/nested returns 1 on the L0 host and confirm svm is not explicitly disabled in the L1 domain XML.

Safe Libvirt XML Rollback Procedure

Always snapshot a VM’s domain XML before modifying CPU topology or feature flags. Because CPUID changes do not alter virtual disk blocks, rolling back is instantaneous and non-destructive:

Terminal / Bash

# Shut down the guest cleanly if a new CPU model causes boot or migration issues
virsh shutdown vm-prod-01

# Restore the pre-change domain XML baseline and restart
virsh define /root/vm-prod-01.backup.xml
virsh start vm-prod-01

Continue optimizing your virtualization stack on our AMD Dedicated Server Hosting pillar hub, and read AMD Nested Page Tables (NPT / RVI) Virtualization Performance and Isolating Confidential VMs on Bare Metal with AMD SEV-SNP Memory Encryption.

Frequently Asked Questions

Does enabling topoext in QEMU/KVM require a guest reboot?

Yes. CPUID leaves, SMT sibling masks, and L3 cache topology are parsed by the guest Linux or Windows kernel during early boot initialization, so a full guest shutdown and virsh start is required for changes to take effect.

Can I use topoext with EPYC-Milan or EPYC-Genoa if I need live migration?

Yes. QEMU’s named EPYC-Milan and EPYC-Genoa CPU models support topoext while enforcing a deterministic CPUID baseline, allowing safe live migration across hosts with matching or newer EPYC silicon.

Why does lscpu inside my KVM guest show 16 separate L3 caches?

This occurs when <cache mode='passthrough'/> or topoext is missing from the domain XML, causing QEMU to synthesize a private L3 cache for each vCPU. Adding both directives restores accurate shared CCX L3 boundaries.

Should I pin vCPUs across multiple AMD EPYC CCDs for a single VM?

Only when the VM requires more physical cores than a single CCD provides (8 cores on Zen 3/4/5). For VMs larger than one CCD, configure QEMU clusters topology so the guest scheduler keeps communicating threads within the same L3 domain.

Does host-passthrough expose AMD SEV-SNP or AVX-512 to KVM guests automatically?

host-passthrough exposes AVX-512, VNNI, and BF16 automatically on Zen 4 and Zen 5 hosts. Confidential computing features like SEV-SNP additionally require explicit <launchSecurity type='sev-snp'/> configuration in libvirt and OVMF UEFI firmware.

Build High-Density KVM Clusters on Bare-Metal AMD EPYC Hosts

Exposing accurate L3 cache boundaries and SMT topology via topoext prevents cross-CCX scheduling stalls in dense KVM deployments. Configure an AMD EPYC bare-metal server with full SVM, IOMMU, and NVMe storage for your hypervisors.

Configure AMD KVM Hypervisors