qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

i386: Mask SVM features if nested SVM is disabled

QEMU incorrectly validates FEAT_SVM feature flags against
GET_SUPPORTED_CPUID even if SVM features are being masked out by
cpu_x86_cpuid(). This can make QEMU print warnings on most AMD
CPU models, even when SVM nesting is disabled (which is the
default).

This bug was never detected before because of a Linux KVM bug:
until Linux v5.6, KVM was not filtering out SVM features in
GET_SUPPORTED_CPUID when nested was disabled. This KVM bug was
fixed in Linux v5.7-rc1, on Linux commit a50718cc3f43 ("KVM:
nSVM: Expose SVM features to L1 iff nested is enabled").

Fix the problem by adding a CPUID_EXT3_SVM dependency to all
FEAT_SVM feature flags in the feature_dependencies table.

Reported-by: Yanan Fu <yfu@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20200623230116.277409-1-ehabkost@redhat.com>
[Fix testcase. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Eduardo Habkost and committed by
Paolo Bonzini
730319ae c8d7fd05

+6 -2
+4
target/i386/cpu.c
··· 1404 1404 .from = { FEAT_VMX_SECONDARY_CTLS, VMX_SECONDARY_EXEC_ENABLE_VMFUNC }, 1405 1405 .to = { FEAT_VMX_VMFUNC, ~0ull }, 1406 1406 }, 1407 + { 1408 + .from = { FEAT_8000_0001_ECX, CPUID_EXT3_SVM }, 1409 + .to = { FEAT_SVM, ~0ull }, 1410 + }, 1407 1411 }; 1408 1412 1409 1413 typedef struct X86RegisterInfo32 {
+2 -2
tests/qtest/test-x86-cpuid-compat.c
··· 256 256 "-cpu 486,+invtsc", "xlevel", 0x80000007); 257 257 /* CPUID[8000_000A].EDX: */ 258 258 add_cpuid_test("x86/cpuid/auto-xlevel/486/npt", 259 - "-cpu 486,+npt", "xlevel", 0x8000000A); 259 + "-cpu 486,+svm,+npt", "xlevel", 0x8000000A); 260 260 /* CPUID[C000_0001].EDX: */ 261 261 add_cpuid_test("x86/cpuid/auto-xlevel2/phenom/xstore", 262 262 "-cpu phenom,+xstore", "xlevel2", 0xC0000001); ··· 348 348 "-machine pc-i440fx-2.4 -cpu SandyBridge,", 349 349 "xlevel", 0x80000008); 350 350 add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on", 351 - "-machine pc-i440fx-2.4 -cpu SandyBridge,+npt", 351 + "-machine pc-i440fx-2.4 -cpu SandyBridge,+svm,+npt", 352 352 "xlevel", 0x80000008); 353 353 354 354 /* Test feature parsing */