target/i386: add support for VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE
RFC PATCH v2 1/1 target/i386: add support for VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE
Current QEMU can expose waitpkg to guests when it is available. However, VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE is still not recognized and masked by QEMU. This can lead to an unexpected situation when a L1 hypervisor wants to expose waitpkg to a L2 guest. The L1 hypervisor can assume that VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE exists as waitpkg is available. The L1 hypervisor then can accidentally expose waitpkg to the L2 guest. This will cause invalid opcode exception in the L2 guest when it executes waitpkg related instructions.
This patch adds VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE support, and sets up dependency between the bit and CPUID_7_0_ECX_WAITPKG. QEMU should not expose waitpkg feature if VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE is not available to avoid unexpected invalid opcode exception in L2 guests.
---
v2:
- Fix typo in the patch header (targer -> target)
v1:
https://lists.gnu.org/archive/html/qemu-devel/2023-08/msg01048.html
target/i386/cpu.c | 6 +++++- target/i386/cpu.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)
target/i386/cpu.c +5 -1
@@ -1228,7 +1228,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"vmx-invpcid-exit" ,"vmx-vmfunc" ,"vmx-shadow-vmcs" ,"vmx-encls-exit" ,"vmx-rdseed-exit" ,"vmx-pml" ,NULL ,NULL ,"vmx-xsaves" ,NULL ,NULL ,NULL , -NULL ,"vmx-tsc-scaling" ,NULL ,NULL , +NULL ,"vmx-tsc-scaling" ,"vmx-enable-user-wait-pause" ,NULL , NULL, NULL, NULL, NULL, }, .msr = {
@@ -1545,6 +1545,10 @@ static FeatureDep feature_dependencies[] = { .from = { FEAT_8000_0001_ECX, CPUID_EXT3_SVM }, .to = { FEAT_SVM, ~0ull }, }, + { + .from = { FEAT_VMX_SECONDARY_CTLS, VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE }, + .to = { FEAT_7_0_ECX, CPUID_7_0_ECX_WAITPKG }, + }, }; typedef struct X86RegisterInfo32 {
target/i386/cpu.h +1 -0
@@ -1111,6 +1111,7 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,#define VMX_SECONDARY_EXEC_ENABLE_PML 0x00020000#define VMX_SECONDARY_EXEC_XSAVES 0x00100000#define VMX_SECONDARY_EXEC_TSC_SCALING 0x02000000 +#define VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE 0x04000000#define VMX_PIN_BASED_EXT_INTR_MASK 0x00000001#define VMX_PIN_BASED_NMI_EXITING 0x00000008
Signature · 1 line
2.41.0
Quoted 41 lines · Ake Koomsin
Current QEMU can expose waitpkg to guests when it is available. However,
VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSEis still not recognized and masked by QEMU. This can lead to an unexpected situation when a L1 hypervisor wants to expose waitpkg to a L2 guest. The L1 hypervisor can assume thatVMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSEexists as waitpkg is available. The L1 hypervisor then can accidentally expose waitpkg to the L2 guest. This will cause invalid opcode exception in the L2 guest when it executes waitpkg related instructions.This patch adds
VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSEsupport, and sets up dependency between the bit andCPUID_7_0_ECX_WAITPKG. QEMU should not expose waitpkg feature ifVMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSEis not available to avoid unexpected invalid opcode exception in L2 guests.Signed-off-by Ake Koomsin <[email protected]>---
v2:
- Fix typo in the patch header (targer -> target)v1:
https://lists.gnu.org/archive/html/qemu-devel/2023-08/msg01048.htmltarget/i386/cpu.c | 6 +++++- target/i386/cpu.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)target/i386/cpu.c +1
-1@@ -1228,7 +1228,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"vmx-invpcid-exit" ,"vmx-vmfunc" ,"vmx-shadow-vmcs" ,"vmx-encls-exit" ,"vmx-rdseed-exit" ,"vmx-pml" ,NULL ,NULL ,"vmx-xsaves" ,NULL ,NULL ,NULL , -NULL ,"vmx-tsc-scaling" ,NULL ,NULL , +NULL ,"vmx-tsc-scaling" ,"vmx-enable-user-wait-pause" ,NULL , NULL, NULL, NULL, NULL, }, .msr = {
target/i386/cpu.c static FeatureDep feature_dependencies[] = { · line 1551
Quoted 7 lines
target/i386/cpu.c +4
-0@@ -1545,6 +1545,10 @@ static FeatureDep feature_dependencies[] = { .from = { FEAT_8000_0001_ECX, CPUID_EXT3_SVM }, .to = { FEAT_SVM, ~0ull }, }, + { + .from = { FEAT_VMX_SECONDARY_CTLS, VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE }, + .to = { FEAT_7_0_ECX, CPUID_7_0_ECX_WAITPKG }, + },
Is this what we really want?
It prevents us from exposing WAITPKG to the guest when we don't want to expose VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE.
An easy example is that, we want to launch a VM without virtualization capability. And this VM cannot have WAITPKG?
Quoted 15 lines
target/i386/cpu.c +0
-0}; typedef struct X86RegisterInfo32 {target/i386/cpu.h +1
-0@@ -1111,6 +1111,7 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,#define VMX_SECONDARY_EXEC_ENABLE_PML 0x00020000#define VMX_SECONDARY_EXEC_XSAVES 0x00100000#define VMX_SECONDARY_EXEC_TSC_SCALING 0x02000000 +#define VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE 0x04000000#define VMX_PIN_BASED_EXT_INTR_MASK 0x00000001#define VMX_PIN_BASED_NMI_EXITING 0x00000008