From: Xiaoyao Li <xiaoyao.li@intel.com>
To: EwanHai <ewanhai-oc@zhaoxin.com>,
pbonzini@redhat.com, mtosatti@redhat.com, kvm@vger.kernel.org,
zhao1.liu@intel.com
Cc: qemu-devel@nongnu.org, cobechen@zhaoxin.com, ewanhai@zhaoxin.com
Subject: Re: [PATCH v2] target/i386/kvm: Refine VMX controls setting for backward compatibility
Date: Tue, 20 Feb 2024 16:32:03 +0800 [thread overview]
Message-ID: <b041fdb3-5b08-4a85-913a-ebb3c7dfbe1d@intel.com> (raw)
In-Reply-To: <20231127034326.257596-1-ewanhai-oc@zhaoxin.com>
On 11/27/2023 11:43 AM, EwanHai wrote:
> 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(<5.3) 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>
> ---
> In response to the suggestions from ZhaoLiu(zhao1.liu@intel.com),
> the following changes have been implemented in v2:
> - Adjusted some punctuation in the commit message as per the
> suggestions.
> - Added comments to the newly added code to indicate that it is a
> compatibility fix.
>
> v1 link:
> https://lore.kernel.org/all/20230925071453.14908-1-ewanhai-oc@zhaoxin.com/
> ---
> target/i386/kvm/kvm.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index 11b8177eff..c8f6c0b531 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -2296,6 +2296,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;
> @@ -2330,6 +2331,19 @@ static int kvm_get_supported_feature_msrs(KVMState *s)
> return ret;
> }
>
> + /*
> + * Compatibility fix:
> + * Older Linux kernels(<5.3) include the MSR_IA32_VMX_PROCBASED_CTLS2
we can be more accurate, that kernel version 4.17 to 5.2, reports
MSR_IA32_VMX_PROCBASED_CTLS2 in KVM_GET_MSR_FEATURE_INDEX_LIST but not
KVM_GET_MSR_INDEX_LIST.
> + * only in feature msr list, but not in regular msr list. This lead to
> + * an issue in older kernel versions where QEMU, through the regular
> + * MSR list check, assumes the kernel doesn't maintain this msr,
> + * resulting in incorrect settings by QEMU for this msr.
> + */
> + 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;
> + }
> + }
I'm wondering should we move all the initialization of has_msr_*, that
associated with feature MSRs, to here. e.g., has_msr_arch_capabs,
has_msr_vmx_vmfunc,...
> return 0;
> }
>
next prev parent reply other threads:[~2024-02-20 8:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 3:43 [PATCH v2] target/i386/kvm: Refine VMX controls setting for backward compatibility EwanHai
2024-02-19 7:54 ` PING: " Ewan Hai
2024-02-20 8:32 ` Xiaoyao Li [this message]
2024-02-20 11:07 ` Ewan Hai
2024-02-23 3:13 ` Ewan Hai
2024-06-18 9:17 ` Ewan Hai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b041fdb3-5b08-4a85-913a-ebb3c7dfbe1d@intel.com \
--to=xiaoyao.li@intel.com \
--cc=cobechen@zhaoxin.com \
--cc=ewanhai-oc@zhaoxin.com \
--cc=ewanhai@zhaoxin.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).