qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/i386/kvm: Refine VMX controls setting for backward compatibility
@ 2023-09-25  7:14 EwanHai
  2023-10-13  2:21 ` [PATCH] target/i386/kvm: Refine VMX controls setting for backward EwanHai
  2023-10-26  3:20 ` [PATCH] target/i386/kvm: Refine VMX controls setting for backward compatibility Zhao Liu
  0 siblings, 2 replies; 8+ messages in thread
From: EwanHai @ 2023-09-25  7:14 UTC (permalink / raw)
  To: pbonzini, mtosatti, kvm; +Cc: qemu-devel

Commit 4a910e1 ("target/i386: do not set unsupported VMX secondary
execution controls") implemented a workaround for hosts that have
specific CPUID features but do not support the corresponding VMX
controls, e.g., hosts support RDSEED but do not support RDSEED-Exiting.

In detail, commit 4a910e1 introduced a flag `has_msr_vmx_procbased_clts2`.
If KVM has `MSR_IA32_VMX_PROCBASED_CTLS2` in its msr list, QEMU would
use KVM's settings, avoiding any modifications to this MSR.

However, this commit (4a910e1) didn’t account for cases in older Linux
kernels(e.g., linux-4.19.90) where `MSR_IA32_VMX_PROCBASED_CTLS2` is
in `kvm_feature_msrs`—obtained by ioctl(KVM_GET_MSR_FEATURE_INDEX_LIST),
but not in `kvm_msr_list`—obtained by ioctl(KVM_GET_MSR_INDEX_LIST).
As a result,it did not set the `has_msr_vmx_procbased_clts2` flag based
on `kvm_msr_list` alone, even though KVM maintains the value of this MSR.

This patch supplements the above logic, ensuring that
`has_msr_vmx_procbased_clts2` is correctly set by checking both MSR
lists, thus maintaining compatibility with older kernels.

Signed-off-by: EwanHai <ewanhai-oc@zhaoxin.com>
---
 target/i386/kvm/kvm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index af101fcdf6..6299284de4 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2343,6 +2343,7 @@ void kvm_arch_do_init_vcpu(X86CPU *cpu)
 static int kvm_get_supported_feature_msrs(KVMState *s)
 {
     int ret = 0;
+    int i;
 
     if (kvm_feature_msrs != NULL) {
         return 0;
@@ -2377,6 +2378,11 @@ static int kvm_get_supported_feature_msrs(KVMState *s)
         return ret;
     }
 
+    for (i = 0; i < kvm_feature_msrs->nmsrs; i++) {
+        if (kvm_feature_msrs->indices[i] == MSR_IA32_VMX_PROCBASED_CTLS2) {
+            has_msr_vmx_procbased_ctls2 = true;
+        }
+    }
     return 0;
 }
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-24 14:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-25  7:14 [PATCH] target/i386/kvm: Refine VMX controls setting for backward compatibility EwanHai
2023-10-13  2:21 ` [PATCH] target/i386/kvm: Refine VMX controls setting for backward EwanHai
2023-10-26  3:20 ` [PATCH] target/i386/kvm: Refine VMX controls setting for backward compatibility Zhao Liu
2023-10-27  3:50   ` Ewan Hai
2023-10-27  6:08     ` Ewan Hai
2023-11-24  3:01       ` PING: VMX controls setting patch " Ewan Hai
2023-11-24 15:02         ` Zhao Liu
2023-11-24 15:00       ` [PATCH] target/i386/kvm: Refine VMX controls setting " Zhao Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).