Как получить все поддерживаемые флаги ЦП в качестве флагов ЦП QEMU?

В моей виртуальной машине QEMU мне нужно использовать определенную модель ЦП, но с включенными флагами максимального ЦП (для производительности).

Для этого я хотел использовать /proc/cpuinfo и использовать grep и cut для получения флагов, но проблема в том, что QEMU использует разные имена (например, sse4_2 будет sse4.2).

Итак, как я могу получить флаги ЦП, а затем преобразовать их в действительные флаги ЦП QEMU?


person ShiningLea    schedule 19.02.2021    source источник
comment
Подходит ли вам решение, изменяющее код qemu?   -  person nevilad    schedule 19.02.2021
comment
Да пока работает   -  person ShiningLea    schedule 19.02.2021
comment
Вы работаете на хосте x86 и используете гостевую систему x86?   -  person nevilad    schedule 19.02.2021
comment
Да, если быть точным, хост Arch Linux и гость macOS.   -  person ShiningLea    schedule 19.02.2021


Ответы (2)


Чтобы перечислить все флаги:

qemu-system-x86_64 -enable-kvm -cpu help

И чтобы проверить, работает ли что-то (нажмите ctrl+c, чтобы закончить):

qemu-system-x86_64 -enable-kvm -cpu base,+vmx-entry-load-perf-global-ctrl -vga none -monitor stdio -vnc :999

check arg должен сообщать некоторый вывод, если он не поддерживается (но, кажется, ничего не меняет для меня) напр.

-cpu Nehalem,check

И тогда вы можете получить некоторые ошибки в выводе...

И я не знаю, имеет ли это какой-то смысл... но вот попытка добавить каждый флаг в базу:

allflags=$(qemu-system-x86_64 -cpu help | awk '/flags/ {y=1; getline}; y {print}' | tr ' ' '\n' | grep -Ev "^$" | sed -r 's|^|+|' | tr '\n' ',' | sed -r "s|,$||")

qemu-system-x86_64 -enable-kvm -cpu "base,check,${allflags}" -vga none -monitor stdio -vnc :999

И вывод на моем ryzen 1700X:

QEMU 6.0.0 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:EDX.pn [bit 18]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:EDX.ds [bit 21]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:EDX.acpi [bit 22]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:EDX.ss [bit 27]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:EDX.ht [bit 28]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:EDX.tm [bit 29]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:EDX.ia64 [bit 30]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:EDX.pbe [bit 31]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.dtes64 [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.monitor [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.ds-cpl [bit 4]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.smx [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.est [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.tm2 [bit 8]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.cid [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.xtpr [bit 14]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.pdcm [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.pcid [bit 17]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.01H:ECX.dca [bit 18]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.hle [bit 4]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.erms [bit 9]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.invpcid [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.rtm [bit 11]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.mpx [bit 14]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.avx512f [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.avx512dq [bit 17]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.avx512ifma [bit 21]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.pcommit [bit 22]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.clwb [bit 24]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.intel-pt [bit 25]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.avx512pf [bit 26]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.avx512er [bit 27]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.avx512cd [bit 28]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.avx512bw [bit 30]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EBX.avx512vl [bit 31]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.avx512vbmi [bit 1]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.umip [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.pku [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.waitpkg [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.avx512vbmi2 [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.gfni [bit 8]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.vaes [bit 9]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.vpclmulqdq [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.avx512vnni [bit 11]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.avx512bitalg [bit 12]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.avx512-vpopcntdq [bit 14]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.la57 [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.rdpid [bit 22]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.bus-lock-detect [bit 24]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.cldemote [bit 25]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.movdiri [bit 27]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.movdir64b [bit 28]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:ECX.pks [bit 31]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.avx512-4vnniw [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.avx512-4fmaps [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.fsrm [bit 4]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.avx512-vp2intersect [bit 8]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.md-clear [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.serialize [bit 14]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.tsx-ldtrk [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.avx512-fp16 [bit 23]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.spec-ctrl [bit 26]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.stibp [bit 27]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.core-capability [bit 30]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EDX.ssbd [bit 31]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.07H:EAX.avx512-bf16 [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:EDX.3dnowext [bit 30]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:EDX.3dnow [bit 31]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.extapic [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.ibs [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.xop [bit 11]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.skinit [bit 12]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.wdt [bit 13]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.lwp [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.fma4 [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.tce [bit 17]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.nodeid-msr [bit 19]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.tbm [bit 21]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.perfctr-nb [bit 24]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000008H:EBX.wbnoinvd [bit 9]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000008H:EBX.ibpb [bit 12]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000008H:EBX.ibrs [bit 14]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000008H:EBX.amd-stibp [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000008H:EBX.amd-ssbd [bit 24]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000008H:EBX.amd-no-ssb [bit 26]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.xstore [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.xstore-en [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.xcrypt [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.xcrypt-en [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.ace2 [bit 8]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.ace2-en [bit 9]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.phe [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.phe-en [bit 11]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.pmm [bit 12]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.C0000001H:EDX.pmm-en [bit 13]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.40000001H:EAX.kvm-mmu [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.40000001H:EAX.kvm-msi-ext-dest-id [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.lbrv [bit 1]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.svm-lock [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.tsc-scale [bit 4]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.vmcb-clean [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.flushbyasid [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.decodeassists [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.pause-filter [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.pfthreshold [bit 12]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.avic [bit 13]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.v-vmsave-vmload [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.vgif [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.8000000AH:EDX.svme-addr-chk [bit 28]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.0DH:EAX [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.0DH:EAX [bit 4]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.0DH:EAX [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.0DH:EAX [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.0DH:EAX [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.0DH:EAX [bit 9]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(10AH).ibrs-all [bit 1]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(10AH).rsba [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(10AH).ssb-no [bit 4]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(10AH).tsx-ctrl [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(10AH).taa-no [bit 8]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(CFH).split-lock-detect [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(345H).full-width-write [bit 13]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-vintr-pending [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-tsc-offset [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-hlt-exit [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-invlpg-exit [bit 9]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-mwait-exit [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-rdpmc-exit [bit 11]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-rdtsc-exit [bit 12]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-cr3-load-noexit [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-cr3-store-noexit [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-cr8-load-exit [bit 19]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-cr8-store-exit [bit 20]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-flexpriority [bit 21]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-vnmi-pending [bit 22]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-movdr-exit [bit 23]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-io-exit [bit 24]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-io-bitmap [bit 25]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-mtf [bit 27]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-msr-bitmap [bit 28]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-monitor-exit [bit 29]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-pause-exit [bit 30]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48EH).vmx-secondary-ctls [bit 31]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-apicv-xapic [bit 0]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-ept [bit 1]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-desc-exit [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-rdtscp-exit [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-apicv-x2apic [bit 4]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-vpid [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-wbinvd-exit [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-unrestricted-guest [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-apicv-register [bit 8]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-apicv-vid [bit 9]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-ple [bit 10]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-rdrand-exit [bit 11]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-invpcid-exit [bit 12]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-vmfunc [bit 13]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-shadow-vmcs [bit 14]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-encls-exit [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-rdseed-exit [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-pml [bit 17]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48BH).vmx-xsaves [bit 20]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48DH).vmx-intr-exit [bit 0]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48DH).vmx-nmi-exit [bit 3]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48DH).vmx-vnmi [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48DH).vmx-preemption-timer [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48DH).vmx-posted-intr [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-nosave-debugctl [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-load-perf-global-ctrl [bit 12]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-ack-intr [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-save-pat [bit 18]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-load-pat [bit 19]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-save-efer [bit 20]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-load-efer [bit 21]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-save-preemption-timer [bit 22]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-clear-bndcfgs [bit 23]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-clear-rtit-ctl [bit 25]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48FH).vmx-exit-load-pkrs [bit 29]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(490H).vmx-entry-noload-debugctl [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(490H).vmx-entry-ia32e-mode [bit 9]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(490H).vmx-entry-load-perf-global-ctrl [bit 13]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(490H).vmx-entry-load-pat [bit 14]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(490H).vmx-entry-load-efer [bit 15]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(490H).vmx-entry-load-bndcfgs [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(490H).vmx-entry-load-rtit-ctl [bit 18]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(490H).vmx-entry-load-pkrs [bit 22]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(485H).vmx-store-lma [bit 5]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(485H).vmx-activity-hlt [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(485H).vmx-activity-shutdown [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(485H).vmx-activity-wait-sipi [bit 8]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(485H).vmx-vmwrite-vmexit-fields [bit 29]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(485H).vmx-zero-len-inject [bit 30]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-ept-execonly [bit 0]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-page-walk-4 [bit 6]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-page-walk-5 [bit 7]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH) [bit 14]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-ept-2mb [bit 16]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-ept-1gb [bit 17]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-invept [bit 20]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-eptad [bit 21]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-ept-advanced-exitinfo [bit 22]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-invept-single-context [bit 25]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-invept-all-context [bit 26]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-invvpid [bit 32]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-invvpid-single-addr [bit 40]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-invept-single-context [bit 41]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-invvpid-all-context [bit 42]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(48CH).vmx-invept-single-context-noglobals [bit 43]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(480H).vmx-ins-outs [bit 54]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(480H).vmx-true-ctls [bit 55]
qemu-system-x86_64: warning: host doesn't support requested feature: MSR(491H).vmx-eptp-switching [bit 0]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.14H:ECX.intel-pt-lip [bit 31]
person Peter    schedule 07.07.2021

Я предполагаю, что вы используете qemu с опцией -cpu со старой моделью процессора, например Nehalem. Все примеры кода взяты из исходников qemu 5.0. Я предполагаю, что вы знакомы с инструкцией cpuid. В target\i386\cpu.c файле вы можете найти

static X86CPUDefinition builtin_x86_defs[] = {

массив с доступными моделями процессоров. Есть запись для Nehalem:

.name = "Nehalem",
        .features[FEAT_1_EDX] =
            CPUID_VME | CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |

Например, FEAT_1_EDX описывает значения, возвращаемые для выполнения процессора 1 в регистре edx для этой модели процессора. Вы также можете увидеть все остальные эмулированные коды.

При запуске qemu с ускорением kvm эти данные отправляются в kvm в функции target\i386\kvm.c in kvm_arch_init_vcpu. Эта функция инициализирует cpuid_data и вызывает kvm_vcpu_ioctl(cs, KVM_SET_CPUID2, &cpuid_data);.

Идея состоит в том, чтобы выполнить инструкцию cpuid для кодов, которые вы хотите настроить, и добавить доступные биты к соответствующим cpuid_data записям непосредственно перед отправкой их в kvm.

Например настройку cpuid 1 edx и ecx можно сделать так:

struct kvm_cpuid_entry2 *c = cpuid_find_entry(&cpuid_data.cpuid, 1, 0);
if (c) {
  c->ecx |= cpuid1_ecx;
  c->edx |= cpuid1_edx;
}

где cpuid1_ecx и cpuid1_edx — значения, возвращаемые в ecx и edx при выполнении cpuid 1 на вашем хосте. Поскольку биты функций возвращаются в разных функциях cpuid, вам нужно вручную выбрать, какие из них настроить. Хорошей отправной точкой было бы настроить все записи FEAT_xx, найденные в builtin_x86_defs, для вашего процессора.

Новые процессоры могут иметь больше записей о функциях, их моделирование сложно, но возможно.

person nevilad    schedule 19.02.2021
comment
Дело в том, что я хочу, чтобы это было динамическим, как изменение флагов для процессора. - person ShiningLea; 19.02.2021
comment
Вы имеете в виду изменение флагов процессора во время гостевого выполнения? - person nevilad; 19.02.2021
comment
Да, и иметь возможность поддерживать любой процессор (например, не жестко запрограммированные пользовательские флаги) - person ShiningLea; 19.02.2021
comment
Изменение характеристик процессора во время гостевого исполнения опасно, так как гость не ожидает такого поведения. Гостевая ОС может проверять cpuid при запуске, соответствующим образом настраивать себя и больше не проверять функции. Но если вы все еще этого хотите, вы можете поместить свои изменения в accel\kvm\kvm-all.c в int kvm_cpu_exec(CPUState *cpu) в цикле прямо перед вызовом run_ret = kvm_vcpu_ioctl(cpu, KVM_RUN, 0);. Вы должны вызвать kvm_vcpu_ioctl KVM_SET_CPUID2 с новыми функциями. В моем решении нет жесткого кодирования флагов. Все упомянутые флаги уже есть в исходниках qemu. - person nevilad; 19.02.2021