KVM calls svm_update_lbrv() to check if virtual LBR (i.e. SVM_MISC2_ENABLE_V_LBR) needs to be enabled in the VMCB and update the intercepts accordingly on nested transitions, and when MSR_IA32_DEBUGCTLMSR is updated. During live migration, if MSR_IA32_DEBUGCTLMSR is restored before nested state, and the vCPU is restored into guest mode, svm_update_lbrv() is not called again to recompute virtual LBR state after vmcb02 is updated (e.g. to account for L1 enabling/disabling virtual LBR). Call svm_update_lbrv() after updating vmcb02 in the restore path to set up virtual LBR accordingly. Fixes: 8a4821412cf2 ("KVM: nSVM: Fix and simplify LBR virtualization handling with nested") Cc: stable@vger.kernel.org Reported-by: Ulfar Erlingsson Reported-by: Sean Christopherson Closes: https://lore.kernel.org/kvm/atpGGKVAL3bAnmnk@google.com/ Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 81d768ec82419..c5a572b58be07 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -2091,6 +2091,12 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, nested_vmcb02_prepare_control(svm); + /* + * Update virtual LBR state after setting up vmcb02's control area in + * case DEBUGCTLMSR was already restored. + */ + svm_update_lbrv(vcpu); + /* * Any previously restored state (e.g. KVM_SET_SREGS) would mark fields * dirty in vmcb01 instead of vmcb02, so mark all of vmcb02 dirty here. -- 2.56.1.987.g2ec0ab4260-goog