From: Sean Christopherson <seanjc@google.com>
To: Anirudh Rayabharam <anrayabh@linux.microsoft.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Ilias Stamatis <ilstam@amazon.com>,
Maxim Levitsky <mlevitsk@redhat.com>,
mail@anirudhrb.com, kumarpraveen@linux.microsoft.com,
wei.liu@kernel.org, robert.bradford@intel.com,
liuwe@microsoft.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: nVMX: Don't expose TSC scaling to L1 when on Hyper-V
Date: Mon, 13 Jun 2022 16:41:27 +0000 [thread overview]
Message-ID: <Yqdot/66J7RMRw2B@google.com> (raw)
In-Reply-To: <20220613161611.3567556-1-anrayabh@linux.microsoft.com>
On Mon, Jun 13, 2022, Anirudh Rayabharam wrote:
> As per the comments in arch/x86/kvm/vmx/evmcs.h, TSC multiplier field is
It's not just the comments, it's also the code. It would be helpful to call out
in the changelog that KVM clears unsupported controls via evmcs_sanitize_exec_ctrls()
when using eVMCS.
> currently not supported in EVMCS. As a result, there is no TSC scaling
> support when KVM is running on Hyper-V i.e. kvm_has_tsc_control is
> false.
>
> However, in nested_vmx_setup_ctls_msrs(), TSC scaling is exposed to L1.
> When L1 tries to launch an L2 guest, vmcs12 has TSC scaling enabled.
> This propagates to vmcs02. But KVM doesn't set the TSC multiplier value
> because kvm_has_tsc_control is false. Due to this, VM entry for L2 guest
> fails. (VM entry fails if "use TSC scaling" is 1 and TSC multiplier is 0.)
>
> To fix, expose TSC scaling to L1 only if kvm_has_tsc_control.
>
> Fixes: d041b5ea93352 ("KVM: nVMX: Enable nested TSC scaling")
> Signed-off-by: Anirudh Rayabharam <anrayabh@linux.microsoft.com>
> ---
> arch/x86/kvm/vmx/nested.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index f5cb18e00e78..d773ddc6422b 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -6656,6 +6656,9 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)
> msrs->secondary_ctls_low,
> msrs->secondary_ctls_high);
>
> + if (!kvm_has_tsc_control)
> + msrs->secondary_ctls_high &= ~SECONDARY_EXEC_TSC_SCALING;
I would much rather we fix the root of the problem and not play whack-a-mole,
e.g. all of the other controls that aren't supported by eVMCS have the same bug,.
nested_vmx_setup_ctls_msrs() should use vmcs_config to get the base MSR values,
not read the MSRs from hardware. And it's not just eVMCS, e.g. the manipulation
of VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL for a CPU errata isn't handled either.
> msrs->secondary_ctls_low = 0;
> msrs->secondary_ctls_high &=
> SECONDARY_EXEC_DESC |
> @@ -6667,8 +6670,7 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)
> SECONDARY_EXEC_RDRAND_EXITING |
> SECONDARY_EXEC_ENABLE_INVPCID |
> SECONDARY_EXEC_RDSEED_EXITING |
> - SECONDARY_EXEC_XSAVES |
> - SECONDARY_EXEC_TSC_SCALING;
> + SECONDARY_EXEC_XSAVES;
>
> /*
> * We can emulate "VMCS shadowing," even if the hardware
> --
> 2.34.1
>
next prev parent reply other threads:[~2022-06-13 19:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-13 16:16 [PATCH] KVM: nVMX: Don't expose TSC scaling to L1 when on Hyper-V Anirudh Rayabharam
2022-06-13 16:41 ` Sean Christopherson [this message]
2022-06-13 16:49 ` Paolo Bonzini
2022-06-13 16:57 ` Sean Christopherson
2022-06-14 15:28 ` Anirudh Rayabharam
2022-06-14 16:00 ` Sean Christopherson
2022-06-22 8:00 ` Vitaly Kuznetsov
2022-06-22 13:52 ` Anirudh Rayabharam
2022-06-22 14:35 ` Vitaly Kuznetsov
2022-06-22 16:19 ` Anirudh Rayabharam
2022-06-22 16:48 ` Vitaly Kuznetsov
2022-06-23 10:17 ` Anirudh Rayabharam
2022-06-23 11:49 ` Vitaly Kuznetsov
2022-06-28 10:30 ` Anirudh Rayabharam
2022-06-14 4:55 ` Anirudh Rayabharam
2022-06-14 12:16 ` Paolo Bonzini
2022-06-14 15:13 ` Anirudh Rayabharam
2022-06-14 17:28 ` Paolo Bonzini
2022-06-14 15:17 ` Anirudh Rayabharam
2022-06-14 12:12 ` Vitaly Kuznetsov
2022-06-14 12:19 ` Vitaly Kuznetsov
2022-06-14 15:01 ` Vitaly Kuznetsov
2022-06-15 11:30 ` Vitaly Kuznetsov
2022-06-14 17:20 ` Paolo Bonzini
2022-06-15 9:01 ` Anirudh Rayabharam
2022-06-15 9:36 ` Vitaly Kuznetsov
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=Yqdot/66J7RMRw2B@google.com \
--to=seanjc@google.com \
--cc=anrayabh@linux.microsoft.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=ilstam@amazon.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kumarpraveen@linux.microsoft.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuwe@microsoft.com \
--cc=mail@anirudhrb.com \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=robert.bradford@intel.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=wei.liu@kernel.org \
--cc=x86@kernel.org \
/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).