From: Manali Shukla <manali.shukla@amd.com>
To: <kvm@vger.kernel.org>, <linux-perf-users@vger.kernel.org>,
<linux-doc@vger.kernel.org>
Cc: <seanjc@google.com>, <pbonzini@redhat.com>, <nikunj@amd.com>,
<manali.shukla@amd.com>, <bp@alien8.de>, <peterz@infradead.org>,
<mingo@redhat.com>, <mizhang@google.com>,
<thomas.lendacky@amd.com>, <ravi.bangoria@amd.com>,
<Sandipan.Das@amd.com>
Subject: [PATCH v2 00/12] Implement support for IBS virtualization
Date: Mon, 1 Sep 2025 10:46:44 +0530 [thread overview]
Message-ID: <20250901051656.209083-1-manali.shukla@amd.com> (raw)
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 (This is needed because AVIC can change its
state while the guest is running). 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@amd.com/
Since then, the mediated PMU patches [4] 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 host \ ..
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 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 12hrs, no softlockups or unknown NMIs were
seen.
- Ran xapic_ipi_test and xapic_state_test to verify there was no
regression after changes were made to the APIC register mask
to accommodate extended APIC registers.
TO-DO:
-----------------------------------
Enable IBS virtualization on SEV-ES and SEV-SNP guests.
base-commit:
https://github.com/sean-jc/linux.git tags/mediated-vpmu-v5
[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/463a0265-e854-4677-92f2-be17e46a3426@linux.intel.com/T/#t
v1->v2
- Incorporated review comments from Mi Dapeng
- Change the name of kvm_lapic_state_w_extapic to kvm_ext_lapic_state.
- Refactor APIC register mask handling in order to support extended
APIC registers.
- Miscellaneous changes
v1: https://lore.kernel.org/kvm/afafc865-b42f-4a9d-82d7-a72de16bb47b@amd.com/T/
Manali Shukla (7):
perf/amd/ibs: Fix race condition in IBS
KVM: x86: Refactor APIC register mask handling to support extended
ranges
KVM: Add KVM_GET_EXT_LAPIC and KVM_SET_EXT_LAPIC 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 | 152 +++++++++++++++++++++--------
arch/x86/kvm/lapic.h | 9 +-
arch/x86/kvm/reverse_cpuid.h | 16 +++
arch/x86/kvm/svm/avic.c | 4 +
arch/x86/kvm/svm/svm.c | 98 +++++++++++++++++++
arch/x86/kvm/vmx/vmx.c | 9 +-
arch/x86/kvm/x86.c | 37 +++++--
include/uapi/linux/kvm.h | 10 ++
16 files changed, 359 insertions(+), 61 deletions(-)
base-commit: 196d9e72c4b0bd68b74a4ec7f52d248f37d0f030
next reply other threads:[~2025-09-01 5:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-01 5:16 Manali Shukla [this message]
2025-09-01 5:19 ` [PATCH v2 01/12] perf/amd/ibs: Fix race condition in IBS Manali Shukla
2025-09-01 5:21 ` [PATCH v2 02/12] KVM: x86: Refactor APIC register mask handling to support extended APIC registers Manali Shukla
2025-09-01 5:21 ` [PATCH v2 03/12] KVM: Add KVM_GET_EXT_LAPIC and KVM_SET_EXT_LAPIC for extapic Manali Shukla
2025-09-01 5:22 ` [PATCH v2 04/12] x86/cpufeatures: Add CPUID feature bit for Extended LVT Manali Shukla
2025-09-08 13:39 ` Naveen N Rao
2025-09-17 15:34 ` Manali Shukla
2025-09-01 5:22 ` [PATCH v2 05/12] KVM: x86: Add emulation support for Extented LVT registers Manali Shukla
2025-09-08 13:41 ` Naveen N Rao
2025-09-17 12:57 ` Manali Shukla
2025-09-01 5:23 ` [PATCH v2 06/12] x86/cpufeatures: Add CPUID feature bit for VIBS in SVM/SEV guests Manali Shukla
2025-09-10 13:01 ` Nikunj A Dadhania
2025-09-17 15:40 ` Manali Shukla
2025-09-01 5:23 ` [PATCH v2 07/12] KVM: x86/cpuid: Add a KVM-only leaf for IBS capabilities Manali Shukla
2025-09-01 5:24 ` [PATCH v2 08/12] KVM: x86: Extend CPUID range to include new leaf Manali Shukla
2025-09-01 5:24 ` [PATCH v2 09/12] KVM: SVM: Extend VMCB area for virtualized IBS registers Manali Shukla
2025-09-01 5:25 ` [PATCH v2 10/12] KVM: SVM: Add support for IBS Virtualization Manali Shukla
2025-09-01 5:26 ` [PATCH v2 11/12] perf/x86/amd: Enable VPMU passthrough capability for IBS PMU Manali Shukla
2025-09-01 5:26 ` [PATCH v2 12/12] perf/x86/amd: Remove exclude_guest check from perf_ibs_init() Manali Shukla
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250901051656.209083-1-manali.shukla@amd.com \
--to=manali.shukla@amd.com \
--cc=Sandipan.Das@amd.com \
--cc=bp@alien8.de \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mizhang@google.com \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).