Re: [PATCH v1 00/11] Implement support for IBS virtualization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/27/2025 9:55 PM, Manali Shukla wrote:
> Add support for IBS virtualization (VIBS). VIBS feature allows the
> guest to collect IBS samples without exiting the guest.  There are
> 2 parts to it [1].
>  - Virtualizing the IBS register state.
>  - Ensuring the IBS interrupt is handled in the guest without exiting
>   the hypervisor.
> 
> To deliver virtualized IBS interrupts to the guest, VIBS requires either
> AVIC or Virtual NMI (VNMI) support [1]. During IBS sampling, the
> hardware signals a VNMI. The source of this VNMI depends on the AVIC
> configuration:
> 
>  - With AVIC disabled, the virtual NMI is hardware-accelerated.
>  - With AVIC enabled, the virtual NMI is delivered via AVIC using Extended LVT.
> 
> The local interrupts are extended to include more LVT registers, to
> allow additional interrupt sources, like instruction based sampling
> etc. [3].
> 
> Although IBS virtualization requires either AVIC or VNMI to be enabled
> in order to successfully deliver IBS NMIs to the guest, VNMI must be
> enabled to ensure reliable delivery. This requirement stems from the
> dynamic behavior of AVIC. While a guest is launched with AVIC enabled,
> AVIC can be inhibited at runtime. When AVIC is inhibited and VNMI is
> disabled, there is no mechanism to deliver IBS NMIs to the guest.
> Therefore, enabling VNMI is necessary to support IBS virtualization
> reliably.
> 
> Note that, since IBS registers are swap type C [2], the hypervisor is
> responsible for saving and restoring of IBS host state. Hypervisor needs
> to disable host IBS before saving the state and enter the guest. After a
> guest exit, the hypervisor needs to restore host IBS state and re-enable
> IBS.
> 
> The mediated PMU has the capability to save the host context when
> entering the guest by scheduling out all exclude_guest events, and to
> restore the host context when exiting the guest by scheduling in the
> previously scheduled-out events. This behavior aligns with the
> requirement for IBS registers being of swap type C. Therefore, the
> mediated PMU design can be leveraged to implement IBS virtualization.
> As a result, enabling the mediated PMU is a necessary requirement for
> IBS virtualization.
> 
> The initial version of this series has been posted here:
> https://lore.kernel.org/kvm/f98687e0-1fee-8208-261f-d93152871f00@xxxxxxx/
> 
> Since then, the mediated PMU patches [5] have matured significantly.
> This series is a resurrection of previous VIBS series and leverages the
> mediated PMU infrastructure to enable IBS virtualization.
> 
> How to enable VIBS?
> ----------------------------------------------
> sudo echo 0 | sudo tee /proc/sys/kernel/nmi_watchdog
> sudo modprobe -r kvm_amd
> sudo modprobe kvm_amd enable_mediated_pmu=1 vnmi=1
> 
> Qemu changes can be found at below location:
> ----------------------------------------------
> https://github.com/AMDESE/qemu/tree/vibs_v1
> 
> Qemu commandline to enable IBS virtualization:
> ------------------------------------------------
> qemu-system-x86_64 -enable-kvm -cpu EPYC-Genoa,+ibs,+extlvt,+extapic,+svm,+pmu \ ..
> 
> Testing done:
> ------------------------------------------------
> - Following tests were executed on guest
>   sudo perf record -e ibs_op// -c 100000 -a
>   sudo perf record -e ibs_op// -c 100000 -C 10
>   sudo perf record -e ibs_op/cnt_ctl=1/ -c 100000 -a
>   sudo perf record -e ibs_op/cnt_ctl=1/ -c 100000 -a --raw-samples
>   sudo perf record -e ibs_op/cnt_ctl=1,l3missonly=1/ -c 100000 -a
>   sudo perf record -e ibs_op/cnt_ctl=1/ -c 100000 -p 1234
>   sudo perf record -e ibs_op/cnt_ctl=1/ -c 100000 -- ls
>   sudo ./tools/perf/perf record -e ibs_op// -e ibs_fetch// -a --raw-samples -c 100000
>   sudo perf report
>   sudo perf script
>   sudo perf report -D | grep -P "LdOp 1.*StOp 0" | wc -l
>   sudo perf report -D | grep -P "LdOp 1.*StOp 0.*DcMiss 1" | wc -l
>   sudo perf report -D | grep -P "LdOp 1.*StOp 0.*DcMiss 1.*L2Miss 1" | wc -l
>   sudo perf report -D | grep -B1 -P "LdOp 1.*StOp 0.*DcMiss 1.*L2Miss 1" | grep -P "DataSrc ([02-9]|1[0-2])=" | wc -l
> - perf_fuzzer was run for 3hrs, no softlockups or unknown NMIs were
>   seen.
> 
> TO-DO: 
> -----------------------------------
> Enable IBS virtualization on SEV-ES and SEV-SNP guests.
> 
> base-commit (61374cc145f4) + [4] (Clean up KVM's MSR interception code)
> + [5] (Mediated vPMU 4.0 for x86). 
> 
> [1]: https://bugzilla.kernel.org/attachment.cgi?id=306250
>      AMD64 Architecture Programmer’s Manual, Vol 2, Section 15.38
>      Instruction-Based Sampling Virtualization.
> 
> [2]: https://bugzilla.kernel.org/attachment.cgi?id=306250
>      AMD64 Architecture Programmer’s Manual, Vol 2, Appendix B Layout
>      of VMCB, Table B-3 Swap Types.
> 
> [3]: https://bugzilla.kernel.org/attachment.cgi?id=306250
>      AMD64 Architecture Programmer’s Manual, Vol 2, Section 16.4.5
>      Extended Interrupts.
> 
> [4]: https://lore.kernel.org/kvm/20250610225737.156318-1-seanjc@xxxxxxxxxx/
> 
> [5]: https://lore.kernel.org/kvm/20250324173121.1275209-1-mizhang@xxxxxxxxxx/
> 
> Manali Shukla (6):
>   perf/amd/ibs: Fix race condition in IBS
>   KVM: Add KVM_GET_LAPIC_W_EXTAPIC and KVM_SET_LAPIC_W_EXTAPIC for
>     extapic
>   KVM: x86/cpuid: Add a KVM-only leaf for IBS capabilities
>   KVM: x86: Extend CPUID range to include new leaf
>   perf/x86/amd: Enable VPMU passthrough capability for IBS PMU
>   perf/x86/amd: Remove exclude_guest check from perf_ibs_init()
> 
> Santosh Shukla (5):
>   x86/cpufeatures: Add CPUID feature bit for Extended LVT
>   KVM: x86: Add emulation support for Extented LVT registers
>   x86/cpufeatures: Add CPUID feature bit for VIBS in SVM/SEV guests
>   KVM: SVM: Extend VMCB area for virtualized IBS registers
>   KVM: SVM: Add support for IBS Virtualization
> 
>  Documentation/virt/kvm/api.rst     | 23 +++++++
>  arch/x86/events/amd/ibs.c          |  8 ++-
>  arch/x86/include/asm/apicdef.h     | 17 ++++++
>  arch/x86/include/asm/cpufeatures.h |  2 +
>  arch/x86/include/asm/kvm_host.h    |  1 +
>  arch/x86/include/asm/svm.h         | 16 ++++-
>  arch/x86/include/uapi/asm/kvm.h    |  5 ++
>  arch/x86/kvm/cpuid.c               | 13 ++++
>  arch/x86/kvm/lapic.c               | 81 ++++++++++++++++++++++---
>  arch/x86/kvm/lapic.h               |  7 ++-
>  arch/x86/kvm/reverse_cpuid.h       | 16 +++++
>  arch/x86/kvm/svm/avic.c            |  4 ++
>  arch/x86/kvm/svm/svm.c             | 96 ++++++++++++++++++++++++++++++
>  arch/x86/kvm/x86.c                 | 37 ++++++++----
>  include/uapi/linux/kvm.h           | 10 ++++
>  15 files changed, 313 insertions(+), 23 deletions(-)
> 
> 
> base-commit: 61374cc145f4a56377eaf87c7409a97ec7a34041


A gentle reminder for the review.

-Manali




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux