[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9f19a5eb-3eb0-58a2-e4ee-612f3298ba82@redhat.com>
Date: Tue, 10 May 2022 17:51:03 +0200
From: Paolo Bonzini <pbonzini@...hat.com>
To: Yang Weijiang <weijiang.yang@...el.com>, jmattson@...gle.com,
seanjc@...gle.com, kan.liang@...ux.intel.com,
like.xu.linux@...il.com, vkuznets@...hat.com, wei.w.wang@...el.com,
kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v11 14/16] KVM: x86/vmx: Flip Arch LBREn bit on guest
state change
On 5/6/22 05:33, Yang Weijiang wrote:
> Per spec:"IA32_LBR_CTL.LBREn is saved and cleared on #SMI, and restored
> on RSM. On a warm reset, all LBR MSRs, including IA32_LBR_DEPTH, have their
> values preserved. However, IA32_LBR_CTL.LBREn is cleared to 0, disabling
> LBRs." So clear Arch LBREn bit on #SMI and restore it on RSM manully, also
> clear the bit when guest does warm reset.
>
> Signed-off-by: Yang Weijiang <weijiang.yang@...el.com>
> ---
> arch/x86/kvm/vmx/vmx.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 6d6ee9cf82f5..b38f58868905 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -4593,6 +4593,8 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
> if (!init_event) {
> if (static_cpu_has(X86_FEATURE_ARCH_LBR))
> vmcs_write64(GUEST_IA32_LBR_CTL, 0);
> + } else {
> + flip_arch_lbr_ctl(vcpu, false);
> }
> }
>
> @@ -7704,6 +7706,7 @@ static int vmx_enter_smm(struct kvm_vcpu *vcpu, char *smstate)
> vmx->nested.smm.vmxon = vmx->nested.vmxon;
> vmx->nested.vmxon = false;
> vmx_clear_hlt(vcpu);
> + flip_arch_lbr_ctl(vcpu, false);
> return 0;
> }
>
> @@ -7725,6 +7728,7 @@ static int vmx_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)
> vmx->nested.nested_run_pending = 1;
> vmx->nested.smm.guest_mode = false;
> }
> + flip_arch_lbr_ctl(vcpu, true);
> return 0;
> }
>
This is incorrect, you hare not saving/restoring the actual value of
LBREn (which is "lbr_desc->event != NULL"). Therefore, a migration
while in SMM would lose the value of LBREn = true.
Instead of using flip_arch_lbr_ctl, SMM should save the value of the MSR
in kvm_x86_ops->enter_smm, and restore it in kvm_x86_ops->leave_smm
(feel free to do it only if guest_cpuid_has(vcpu, X86_FEATURE_LM), i.e.
the 32-bit case can be ignored).
Paolo
Powered by blists - more mailing lists