Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH v2 00/12] KVM: SVM: Add support for AMD LBR Extension v2
@ 2026-10-19 21:05 Shivansh Dhiman
  2026-10-19 21:05 ` [PATCH v2 01/12] KVM: SVM: Add VMCB fields for LBRv2 virtualization Shivansh Dhiman
                   ` (11 more replies)
  0 siblings, 12 replies; 21+ messages in thread
From: Shivansh Dhiman @ 2026-10-19 21:05 UTC (permalink / raw)
  To: seanjc, pbonzini, tglx, mingo
  Cc: peterz, acme, kvm, x86, yosry, jmattson, thomas.lendacky,
	nikunj.dadhania, sandipan.das, shivansh.dhiman

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/20260724195040.630468-1-shivansh.dhiman@amd.com/

Related QEMU patchset:
https://lore.kernel.org/kvm/20261019201314.269798-1-shivansh.dhiman@amd.com/

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
-- 
2.43.0


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2026-10-19 23:26 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 21:05 [PATCH v2 00/12] KVM: SVM: Add support for AMD LBR Extension v2 Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 01/12] KVM: SVM: Add VMCB fields for LBRv2 virtualization Shivansh Dhiman
2026-10-19 22:09   ` Jim Mattson
2026-10-19 21:05 ` [PATCH v2 02/12] KVM: SVM: Add the LbrExtV2 CPUID feature bit Shivansh Dhiman
2026-10-19 22:15   ` Jim Mattson
2026-10-19 21:05 ` [PATCH v2 03/12] KVM: SVM: Emulate guest accesses to LBRv2 MSRs Shivansh Dhiman
2026-10-19 23:26   ` Jim Mattson
2026-10-19 21:05 ` [PATCH v2 04/12] KVM: SVM: Enable hardware-assisted LBRv2 virtualization Shivansh Dhiman
2026-10-19 21:33   ` sashiko-bot
2026-10-19 21:05 ` [PATCH v2 05/12] KVM: x86: Add support for Live Migration Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 06/12] perf/x86: Expose the LBR stack depth via x86_pmu_capability Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 07/12] KVM: SVM: Advertise LbrExtV2 to userspace Shivansh Dhiman
2026-10-19 21:27   ` sashiko-bot
2026-10-19 21:05 ` [PATCH v2 08/12] KVM: SVM: Support LBRv2 virtualization for SEV-ES guests Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 09/12] KVM: nSVM: Propagate LBRv2 state across nested transitions Shivansh Dhiman
2026-10-19 21:31   ` sashiko-bot
2026-10-19 21:05 ` [PATCH v2 10/12] KVM: nSVM: Pass through LBRv2 MSRs to L2 Shivansh Dhiman
2026-10-19 21:36   ` sashiko-bot
2026-10-19 21:05 ` [PATCH v2 11/12] KVM: SVM: Add LBR/PMC freeze support Shivansh Dhiman
2026-10-19 21:27   ` sashiko-bot
2026-10-19 21:05 ` [PATCH v2 12/12] KVM: x86: Use SCATTERED_F() for PERFMON_V2 Shivansh Dhiman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox