qemu64 CPU 模型为什么有 svm?兼容性模型的指令集设计

qemu64 是 qemu 的默认兼容性 CPU 模型,指令集很基础。但查看它的定义,居然包含 svm 这类虚拟化指令,这背后是 TCG 与 KVM 两种支持场景的差异。 现象 查看 qemu64 CPU 模型定义: cat /usr/share/libvirt/cpu_map/x86_qemu64.xml <cpus> <model name='qemu64'> <decode host='on' guest='on'/> <!-- These are supported only by TCG. KVM supports them only if the host does. So we leave them out: <feature name='abm'/> <feature name='lahf_lm'/> <feature name='popcnt'/> <feature name='sse4a'/> --> <feature name='apic'/> <feature name='clflush'/> <feature name='cmov'/> <feature name='cx16'/> <feature name='cx8'/> <feature name='de'/> <feature name='fpu'/> <feature name='fxsr'/> <feature name='lm'/> <feature name='mca'/> <feature name='mce'/> <feature name='mmx'/> <feature name='msr'/> <feature name='mtrr'/> <feature name='nx'/> <feature name='pae'/> <feature name='pat'/> <feature name='pge'/> <feature name='pni'/> <feature name='pse'/> <feature name='pse36'/> <feature name='sep'/> <feature name='sse'/> <feature name='sse2'/> <feature name='svm'/> <feature name='syscall'/> <feature name='tsc'/> </model> </cpus> 分析 qemu64 是 qemu 为了兼容性提供的默认 CPU 模型,指令集非常基础。 但有意思的是,它居然包含了 svm(AMD 的虚拟化扩展指令)。 ...

July 12, 2026 · 1 min · 158 words · 文叨叨

为什么新系统跑不起来?默认 qemu 指令集不够用

新系统跑不起来,报 “CPU does not support x86-64-v2”,根因是现代 OS 默认按较新指令集编译,而默认的 qemu64 模型只提供最基础指令。给虚拟机配上合适的 CPU 指令集就能解决。 现象 一台 primusos2403sp1x64 的虚拟机,没有配置 CPU 指令集的情况下,运行僵死。配置指令集后,就能正常运行了。 排查 用 virsh reset vm-example && virsh console vm-example 可以看到 glibc 打印的错误: [ 1.536627][ T1] Run /init as init process Fatal glibc error: CPU does not support x86-64-v2 [ 1.538855][ T1] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00007f00 [ 1.540681][ T1] CPU: 6 PID: 1 Comm: init Not tainted 6.6.0-103.0.0.106.oe2403sp1.x86_64 #1 [ 1.542633][ T1] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014 [ 1.545203][ T1] Call Trace: [ 1.545959][ T1] <TASK> [ 1.546568][ T1] dump_stack_lvl+0x32/0x50 [ 1.547593][ T1] panic+0x304/0x340 [ 1.548411][ T1] do_exit+0x3f4/0x410 [ 1.549284][ T1] do_group_exit+0x2d/0x80 [ 1.550272][ T1] __x64_sys_exit_group+0x14/0x20 [ 1.551151][ T1] do_syscall_64+0x55/0x100 [ 1.551963][ T1] entry_SYSCALL_64_after_hwframe+0x78/0xe2 [ 1.553370][ T1] RIP: 0033:0x7f40667d3db5 [ 1.557729][ T1] RSP: 002b:00007ffcb3db2f68 EFLAGS: 00000202 ORIG_RAX: 00000000000000e7 [ 1.559088][ T1] RAX: ffffffffffffffda RBX: 00007f40667cf490 RCX: 00007f40667d3db5 [ 1.560108][ T1] RDX: 0000000000000000 RSI: 00007ffcb3db2630 RDI: 000000000000007f [ 1.561078][ T1] RBP: 00007ffcb3db3140 R08: 0000000000000010 R09: 0000000000000000 [ 1.562048][ T1] R10: 0000000000000001 R11: 0000000000000202 R12: 00007f40667e2ab0 [ 1.563025][ T1] R13: 0000000000000000 R14: 0000000000000000 R15: 00007f40667b4000 [ 1.563990][ T1] </TASK> [ 1.564790][ T1] Kernel Offset: 0x38c00000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) [ 1.566210][ T1] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00007f00 ]--- 根因 这是已知问题:现代操作系统都开启了指令集优化,纯 qemu 的模拟指令无法满足运行的基本要求,必须配上指令集才能运行。 ...

June 7, 2026 · 2 min · 280 words · 文叨叨

libvirt CPU feature 的 disable 和 forbid 有什么区别?

libvirt CPU feature 的 policy 有 force、require、optional、disable、forbid 五种。disable 是虚拟 CPU 不支持该特性,forbid 是宿主机支持该特性时创建会失败。 现象 在 libvirt XML 中配置 CPU feature: <cpu> <model>EPYC</model> <feature name="pclmuldq" policy="disable"/> <feature name="aes" policy="disable"/> <feature name="sha-ni" policy="disable"/> <feature name="monitor" policy="disable"/> <feature name="svm" policy="disable"/> <feature name="npt" policy="disable"/> 【物理机支撑 npt 的】 <topology cores="1" sockets="1" threads="1"/> </cpu> 物理 CPU 是有 npt 的,virsh create 的时候就报错,而且这是 disable 也报错。 足以说明,不是 CPU 问题,而是 libvirt 不支持问题: 2025-06-24 12:50:13,539 WARNING -140207347541760- cmd [virsh create /data/vmxml/vm-example.xml] on [local] failed: ret[1] out[] err[error: Failed to create domain from /data/vmxml/vm-example.xml error: unsupported configuration: unknown CPU feature: npt]. exec_time is [0.089]s 排查 在 commandline 中禁用 npt 是可以创建虚拟机的 <qemu:commandline> <qemu:arg value="-cpu"/> <qemu:arg value="EPYC,vendor=AuthenticAMD,model_id=Example CPU 7380 32-core Processor,-x2apic,-hypervisor,-topoext,-npt,-nrip-save,-monitor,-svm"/> </qemu:commandline> 说明什么? ...

January 31, 2026 · 2 min · 267 words · 文叨叨

ARM 架构下 CPU 模型设置为什么失效?只有 passthrough

在 ARM(aarch64)架构下,libvirt/QEMU 的 CPU 模型与特性禁用设置不生效,虚拟机看到的 CPU 依然是透传的物理 CPU。所以 ARM 架构下,别探索什么指令集、热迁移了,全部用 passthrough。 现象 将虚拟机 CPU 设置为 custom 模式,指定 Kunpeng-920 指令集,并通过 <feature policy="disable"> 禁用 asimddp、asimdfhm 两个 CPU 特性。 对比宿主机与虚拟机内的 lscpu / /proc/cpuinfo 输出,发现设置未生效。 尽管 QEMU 进程命令行已携带 -cpu Kunpeng-920,asimddp=off,asimdfhm=off,虚拟机内部看到的 CPU 依然是透传的物理 CPU(特性、implementer、part 号与宿主机完全一致)。 排查 测试环境 项目 值 宿主机架构 aarch64 (ARM64) 宿主机 CPU HUAWEI Kunpeng 920 3210 (HiSilicon) 虚拟机架构 aarch64, machine virt-4.1 QEMU qemu-system-aarch64 (4.1.0.2) 虚拟化 KVM (accel=kvm) 虚拟机内存/CPU 1024 MiB / 1 vCPU 虚拟机 XML 的 CPU 部分 <cpu mode="custom" match="exact"> <model>Kunpeng-920</model> <feature policy="disable" name="asimddp"/> <feature policy="disable" name="asimdfhm"/> <topology sockets="1" cores="1" threads="1"></topology> <numa> <cell id="0" cpus="0" memory="1048576" unit="KiB" discard="yes"></cell> </numa> </cpu> QEMU 进程的 -cpu 参数 虚拟机启动后,QEMU 进程实际命令行中的 CPU 相关参数: ...

January 4, 2026 · 2 min · 414 words · 文叨叨