]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: nSVM: Always recalculate LBR MSR intercepts in svm_update_lbrv()
authorYosry Ahmed <yosry.ahmed@linux.dev>
Sat, 8 Nov 2025 00:45:20 +0000 (00:45 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Sun, 9 Nov 2025 07:49:52 +0000 (08:49 +0100)
commitfbe5e5f030c22ae717ee422aaab0e00ea84fab5e
tree4868c2c722fc5487190202a8aa34245241171271
parentdc55b3c3f61246e483e50c85d8d5366f9567e188
KVM: nSVM: Always recalculate LBR MSR intercepts in svm_update_lbrv()

svm_update_lbrv() is called when MSR_IA32_DEBUGCTLMSR is updated, and on
nested transitions where LBRV is used. It checks whether LBRV enablement
needs to be changed in the current VMCB, and if it does, it also
recalculate intercepts to LBR MSRs.

However, there are cases where intercepts need to be updated even when
LBRV enablement doesn't. Example scenario:
- L1 has MSR_IA32_DEBUGCTLMSR cleared.
- L1 runs L2 without LBR_CTL_ENABLE (no LBRV).
- L2 sets DEBUGCTLMSR_LBR in MSR_IA32_DEBUGCTLMSR, svm_update_lbrv()
  sets LBR_CTL_ENABLE in VMCB02 and disables intercepts to LBR MSRs.
- L2 exits to L1, svm_update_lbrv() is not called on this transition.
- L1 clears MSR_IA32_DEBUGCTLMSR, svm_update_lbrv() finds that
  LBR_CTL_ENABLE is already cleared in VMCB01 and does nothing.
- Intercepts remain disabled, L1 reads to LBR MSRs read the host MSRs.

Fix it by always recalculating intercepts in svm_update_lbrv().

Fixes: 1d5a1b5860ed ("KVM: x86: nSVM: correctly virtualize LBR msrs when L2 is running")
Cc: stable@vger.kernel.org
Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Link: https://patch.msgid.link/20251108004524.1600006-3-yosry.ahmed@linux.dev
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/svm.c