KVM: SVM: Add support for AMD LBR Extension v2
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest12 patches 31 repliesIn review
- v17 patches 5 repliesSuperseded
Changes in v2 from the cover letter
* Rebased on kvm-x86-next-2026.10.13. Use newly added functions svm_get_supported_debugctl() and svm_need_lbr_virtualization().
* New patch to report the LBRv2 MSRs for live migration (patch 5).
* New patch to support LBRv2 for SEV-ES/SNP guests (patch 8).
* New patches to support LBRv2 for nested SVM (patches 9 and 10).
* Split v1 patch 2 into the CPUID feature bit (patch 2) and the perf change (patch 6). Fix authorship.
* Advertise LbrExtV2 only with a 16-entry host LBR stack, and removed the per-vCPU clear of the feature.
* Use KVM_BUG_ON() for an out-of-range LBR stack index.
* Do not mark the VMCB dirty on LBRv2 MSR writes.
* Updated commit messages.
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/12 | KVM: SVM: Add VMCB fields for LBRv2 virtualizationarch/ | +11 | 2 replies | |
| 2/12 | KVM: SVM: Add the LbrExtV2 CPUID feature bitarch/ | +2 | 2 replies | |
| 3/12 | KVM: SVM: Emulate guest accesses to LBRv2 MSRsarch/ arch/ arch/ | +74 | 2 replies | |
| 4/12 | KVM: SVM: Enable hardware-assisted LBRv2 virtualizationarch/ arch/ | +45 | 5 replies | |
| 5/12 | KVM: x86: Add support for Live Migrationarch/ | +26 | 2 replies | |
| 6/12 | perf/x86: Expose the LBR stack depth via x86_pmu_capabilityarch/ arch/ | +2 | 2 replies | |
| 7/12 | KVM: SVM: Advertise LbrExtV2 to userspacearch/ arch/ | +15 | 5 replies | |
| 8/12 | KVM: SVM: Support LBRv2 virtualization for SEV-ES guestsarch/ arch/ | +22 | 2 replies | |
| 9/12 | KVM: nSVM: Propagate LBRv2 state across nested transitionsarch/ arch/ | +45 | 1 reply | |
| 10/12 | KVM: nSVM: Pass through LBRv2 MSRs to L2arch/ | +22 | 2 replies | |
| 11/12 | KVM: SVM: Add LBR/PMC freeze supportarch/ arch/ arch/ | +9 | 1 reply | |
| 12/12 | KVM: x86: Use SCATTERED_F() for PERFMON_V2arch/ | +1 | 2 replies |
Reviews trailers per patch
5 of 12 patches have a Reviewed-by or Acked-by.
| Patch | Jim Mattson |
|---|---|
| 1/12 | R-b |
| 2/12 | R-b |
| 3/12 | |
| 4/12 | |
| 5/12 | R-b |
| 6/12 | R-b |
| 7/12 | |
| 8/12 | |
| 9/12 | |
| 10/12 | |
| 11/12 | |
| 12/12 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v2 00/12] KVM: SVM: Add support for AMD LBR Extension v2
This series adds SVM support for virtualizing AMD's Last Branch Record Extension Version 2 (LbrExtV2) in KVM.
Background
----------
LbrExtV2, introduced on Zen 4, is a branch sampling facility. It records the last taken branches in a 16-entry stack of dedicated MSRs:
* MSR 0xC000010E - Last Branch Stack Select (LBR_SELECT)
* MSR 0xC000010F - Debug Extension Control (DBG_EXTN_CFG)
* MSR 0xC0010300..0xC001031F - 16 LBR FROM/TO MSR pairs
AMD hardware extends the VMCB save area with fields for these MSRs. When V_LBR (VMCB.MISC_CTL2.LBR_VIRTUALIZATION_ENABLE) is set, the CPU saves and restores the guest's LbrExtV2 state on VMRUN/#VMEXIT. Thus, the guest can use LBRv2 without interception.
V_LBR is enabled lazily. KVM enables LBR virtualization only when the guest sets DBG_EXTN_CFG.LBRV2EN (bit 6) to record branches. Thus, there is no save/restore cost on VMRUN/#VMEXIT while the guest does not use LBRv2. The series also adds the dependent LBR and PMC freeze-on-PMI feature.
Major changes in v2
-------------------
* Added LBRv2 support for SEV-ES/SNP guests.
* Added LBRv2 support for nested SVM.
* Added live migration support for the LBRv2 MSRs.
Testing
-------
Disable the NMI watchdog on the host and enable the mediated PMU before the test:
$ echo 0 | sudo tee /proc/sys/kernel/nmi_watchdog $ sudo modprobe kvm_amd enable_mediated_pmu=1
Testing has been done by running perf LBR test inside the guest:
$ ./tools/perf/perf test -vvvv "LBR"
Links
-----
v1: https://lore.kernel.org/kvm/[email protected]/
Related QEMU patchset:
https://lore.kernel.org/kvm/[email protected]/
Regards,
Shivansh
---
Changelog:
v1 -> v2:
* Rebased on kvm-x86-next-2026.10.13. Use newly added functions svm_get_supported_debugctl() and svm_need_lbr_virtualization().
* New patch to report the LBRv2 MSRs for live migration (patch 5).
* New patch to support LBRv2 for SEV-ES/SNP guests (patch 8).
* New patches to support LBRv2 for nested SVM (patches 9 and 10).
* Split v1 patch 2 into the CPUID feature bit (patch 2) and the perf change (patch 6). Fix authorship.
* Advertise LbrExtV2 only with a 16-entry host LBR stack, and removed the per-vCPU clear of the feature.
* Use KVM_BUG_ON() for an out-of-range LBR stack index.
* Do not mark the VMCB dirty on LBRv2 MSR writes.
* Updated commit messages.
---
Sandipan Das (3):
KVM: SVM: Add VMCB fields for LBRv2 virtualization
KVM: SVM: Add the LbrExtV2 CPUID feature bit perf/x86: Expose the LBR stack depth via x86_pmu_capability
Shivansh Dhiman (9):
KVM: SVM: Emulate guest accesses to LBRv2 MSRs
KVM: SVM: Enable hardware-assisted LBRv2 virtualization
KVM: x86: Add support for Live Migration
KVM: SVM: Advertise LbrExtV2 to userspace
KVM: SVM: Support LBRv2 virtualization for SEV-ES guests
KVM: nSVM: Propagate LBRv2 state across nested transitions
KVM: nSVM: Pass through LBRv2 MSRs to L2
KVM: SVM: Add LBR/PMC freeze support
KVM: x86: Use SCATTERED_F() for PERFMON_V2
arch/x86/events/core.c | 1 + arch/x86/include/asm/perf_event.h | 1 + arch/x86/include/asm/svm.h | 28 ++++-- arch/x86/kvm/cpuid.c | 6 +- arch/x86/kvm/msrs.c | 26 ++++++ arch/x86/kvm/reverse_cpuid.h | 6 +- arch/x86/kvm/svm/nested.c | 51 ++++++++++- arch/x86/kvm/svm/svm.c | 137 +++++++++++++++++++++++++++++- arch/x86/kvm/svm/svm.h | 26 ++++++ 9 files changed, 271 insertions(+), 11 deletions(-)
base-commit: dea4f6380f4ec96e8f3b0aaf2343764bd0d25ef4
Signature · 1 line
2.43.0