From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Like Xu <like.xu.linux@gmail.com>
Subject: Re: [PATCH v2 03/21] KVM: x86: Add macros to track first...last VMX feature MSRs
Date: Wed, 15 Feb 2023 11:20:39 +0800 [thread overview]
Message-ID: <953949b9-02fc-af3f-d7fe-6c15635a2ee8@intel.com> (raw)
In-Reply-To: <20230210003148.2646712-4-seanjc@google.com>
On 2/10/2023 8:31 AM, Sean Christopherson wrote:
> Add macros to track the range of VMX feature MSRs that are emulated by
> KVM to reduce the maintenance cost of extending the set of emulated MSRs.
>
> Note, KVM doesn't necessarily emulate all known/consumed VMX MSRs, e.g.
> PROCBASED_CTLS3 is consumed by KVM to enable IPI virtualization, but is
> not emulated as KVM doesn't emulate/virtualize IPI virtualization for
> nested guests.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
> arch/x86/kvm/svm/svm.c | 2 +-
> arch/x86/kvm/vmx/vmx.c | 8 ++++----
> arch/x86/kvm/x86.h | 8 ++++++++
> 3 files changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index b43775490074..a5b9ebd6f2c5 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -4107,7 +4107,7 @@ static bool svm_has_emulated_msr(struct kvm *kvm, u32 index)
> {
> switch (index) {
> case MSR_IA32_MCG_EXT_CTL:
> - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
> + case KVM_FIRST_EMULATED_VMX_MSR ... KVM_LAST_EMULATED_VMX_MSR:
> return false;
> case MSR_IA32_SMBASE:
> if (!IS_ENABLED(CONFIG_KVM_SMM))
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 47abd9101e68..ee86db130519 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -1945,7 +1945,7 @@ static inline bool is_vmx_feature_control_msr_valid(struct vcpu_vmx *vmx,
> static int vmx_get_msr_feature(struct kvm_msr_entry *msr)
> {
> switch (msr->index) {
> - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
> + case KVM_FIRST_EMULATED_VMX_MSR ... KVM_LAST_EMULATED_VMX_MSR:
> if (!nested)
> return 1;
> return vmx_get_vmx_msr(&vmcs_config.nested, msr->index, &msr->data);
> @@ -2030,7 +2030,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> msr_info->data = to_vmx(vcpu)->msr_ia32_sgxlepubkeyhash
> [msr_info->index - MSR_IA32_SGXLEPUBKEYHASH0];
> break;
> - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
> + case KVM_FIRST_EMULATED_VMX_MSR ... KVM_LAST_EMULATED_VMX_MSR:
> if (!nested_vmx_allowed(vcpu))
> return 1;
> if (vmx_get_vmx_msr(&vmx->nested.msrs, msr_info->index,
> @@ -2366,7 +2366,7 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> vmx->msr_ia32_sgxlepubkeyhash
> [msr_index - MSR_IA32_SGXLEPUBKEYHASH0] = data;
> break;
> - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
> + case KVM_FIRST_EMULATED_VMX_MSR ... KVM_LAST_EMULATED_VMX_MSR:
> if (!msr_info->host_initiated)
> return 1; /* they are read-only */
> if (!nested_vmx_allowed(vcpu))
> @@ -6960,7 +6960,7 @@ static bool vmx_has_emulated_msr(struct kvm *kvm, u32 index)
> * real mode.
> */
> return enable_unrestricted_guest || emulate_invalid_guest_state;
> - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
> + case KVM_FIRST_EMULATED_VMX_MSR ... KVM_LAST_EMULATED_VMX_MSR:
> return nested;
> case MSR_AMD64_VIRT_SPEC_CTRL:
> case MSR_AMD64_TSC_RATIO:
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 754190af1791..4bc483d082ee 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -40,6 +40,14 @@ void kvm_spurious_fault(void);
> failed; \
> })
>
> +/*
> + * The first...last VMX feature MSRs that are emulated by KVM. This may or may
> + * not cover all known VMX MSRs, as KVM doesn't emulate an MSR until there's an
> + * associated feature that KVM supports for nested virtualization.
> + */
> +#define KVM_FIRST_EMULATED_VMX_MSR MSR_IA32_VMX_BASIC
> +#define KVM_LAST_EMULATED_VMX_MSR MSR_IA32_VMX_VMFUNC
> +
> #define KVM_DEFAULT_PLE_GAP 128
> #define KVM_VMX_DEFAULT_PLE_WINDOW 4096
> #define KVM_DEFAULT_PLE_WINDOW_GROW 2
next prev parent reply other threads:[~2023-02-15 3:20 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 0:31 [PATCH v2 00/21] KVM: x86: Disallow writes to feature MSRs post-KVM_RUN Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 01/21] KVM: x86: Rename kvm_init_msr_list() to clarify it inits multiple lists Sean Christopherson
2023-02-14 6:34 ` Xiaoyao Li
2023-02-10 0:31 ` [PATCH v2 02/21] KVM: x86: Add a helper to query whether or not a vCPU has ever run Sean Christopherson
2023-02-14 6:35 ` Xiaoyao Li
2023-02-10 0:31 ` [PATCH v2 03/21] KVM: x86: Add macros to track first...last VMX feature MSRs Sean Christopherson
2023-02-14 10:48 ` Like Xu
2023-02-14 18:51 ` Sean Christopherson
2023-02-15 3:20 ` Xiaoyao Li [this message]
2023-02-10 0:31 ` [PATCH v2 04/21] KVM: x86: Generate set of VMX feature MSRs using first/last definitions Sean Christopherson
2023-02-14 6:36 ` Xiaoyao Li
2023-02-10 0:31 ` [PATCH v2 05/21] KVM: x86: Disallow writes to immutable feature MSRs after KVM_RUN Sean Christopherson
2023-02-10 13:01 ` Yu Zhang
2023-02-10 16:31 ` Sean Christopherson
2023-02-14 6:39 ` Xiaoyao Li
2023-02-14 11:39 ` Like Xu
2023-02-15 22:36 ` Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 06/21] KVM: x86/pmu: WARN and bug the VM if PMU is refreshed after vCPU has run Sean Christopherson
2023-02-15 11:53 ` Like Xu
2023-02-15 15:20 ` Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 07/21] KVM: x86/pmu: Zero out LBR capabilities during PMU refresh Sean Christopherson
2023-02-15 12:00 ` Like Xu
2023-02-15 15:17 ` Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 08/21] KVM: selftests: Split PMU caps sub-tests to avoid writing MSR after KVM_RUN Sean Christopherson
2023-02-14 7:27 ` Like Xu
2023-02-14 17:42 ` Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 09/21] KVM: selftests: Move 0/initial value PERF_CAPS checks to dedicated sub-test Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 10/21] KVM: selftests: Assert that full-width PMC writes are supported if PDCM=1 Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 11/21] KVM: selftests: Print out failing MSR and value in vcpu_set_msr() Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 12/21] KVM: selftests: Verify KVM preserves userspace writes to "durable" MSRs Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 13/21] KVM: selftests: Drop now-redundant checks on PERF_CAPABILITIES writes Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 14/21] KVM: selftests: Test all fungible features in PERF_CAPABILITIES Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 15/21] KVM: selftests: Test all immutable non-format bits " Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 16/21] KVM: selftests: Expand negative testing of guest writes to PERF_CAPABILITIES Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 17/21] KVM: selftests: Test post-KVM_RUN " Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 18/21] KVM: selftests: Drop "all done!" printf() from PERF_CAPABILITIES test Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 19/21] KVM: selftests: Refactor LBR_FMT test to avoid use of separate macro Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 20/21] KVM: selftests: Add negative testcase for PEBS format in PERF_CAPABILITIES Sean Christopherson
2023-02-10 0:31 ` [PATCH v2 21/21] KVM: selftests: Verify LBRs are disabled if vPMU is disabled Sean Christopherson
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=953949b9-02fc-af3f-d7fe-6c15635a2ee8@intel.com \
--to=xiaoyao.li@intel.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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
all inboxes | Powered by JetHome®