Skip to content

Implement support for IBS virtualization

Manali Shukla kvm linux-doc linux-perf-users 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest13 patches 18 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13KVM: Add KVM_GET_LAPIC_W_EXTAPIC and KVM_SET_LAPIC_W_EXTAPIC for extapicDocumentation/virt/kvm/api.rst arch/x86/include/uapi/asm/kvm.h arch/x86/kvm/lapic.c +3 more+62 -181 reply
2/13x86/cpufeatures: Add CPUID feature bit for Extended LVTarch/x86/include/asm/cpufeatures.h+1 -00 replies
3/13KVM: x86: Add emulation support for Extented LVT registersarch/x86/include/asm/apicdef.h arch/x86/kvm/lapic.c arch/x86/kvm/lapic.h +1 more+83 -21 reply
4/13x86/cpufeatures: Add CPUID feature bit for virtualized IBSarch/x86/include/asm/cpufeatures.h+1 -00 replies
5/13KVM: x86/cpuid: Add a KVM-only leaf for IBS capabilitiesarch/x86/kvm/reverse_cpuid.h+15 -00 replies
6/13KVM: x86: Extend CPUID range to include new leafarch/x86/kvm/cpuid.c+11 -01 reply
7/13KVM: SVM: Extend VMCB area for virtualized IBS registersarch/x86/include/asm/svm.h+15 -11 reply
8/13perf/x86/amd: Add framework to save/restore host IBS statearch/x86/events/amd/Makefile arch/x86/events/amd/ibs.c arch/x86/events/amd/vibs.c +1 more+152 -11 reply
9/13KVM: SVM: add support for IBS virtualization for non SEV-ES guestsarch/x86/kvm/svm/svm.c arch/x86/kvm/svm/svm.h+173 -33 replies
10/13x86/cpufeatures: Add CPUID feature bit for VIBS in SEV-ES guestarch/x86/include/asm/cpufeatures.h+1 -00 replies
11/13KVM: SVM: Add support for IBS virtualization for SEV-ES guestsarch/x86/include/asm/svm.h arch/x86/kvm/svm/sev.c arch/x86/kvm/svm/svm.c+25 -71 reply
12/13KVM: SVM: Enable IBS virtualization on non SEV-ES and SEV-ES guestsarch/x86/include/asm/svm.h arch/x86/kvm/svm/sev.c arch/x86/kvm/svm/svm.c+33 -22 replies
13/13KVM: x86: nSVM: Implement support for nested IBS virtualizationarch/x86/kvm/governed_features.h arch/x86/kvm/svm/nested.c arch/x86/kvm/svm/svm.c +1 more+43 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 00/13] Implement support for IBS virtualization

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.

VIBS requires the use of AVIC or NMI virtualization for delivery of a virtualized interrupt from IBS hardware in the guest [1].

While IBS collects data for IBS fetch/op block for the sampled interval, VIBS hardware signals a VNMI, but the source of VNMI is different in both AVIC enabled/disabled case.
- When AVIC is disabled, virtual NMI is HW accelerated.
- When AVIC is enabled, virtual NMI is accelerated 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].

Note that, since IBS registers are swap type C [2], the hypervisor is responsible for saving and restoring of IBS host state. Hypervisor does so only when IBS is active on the host to avoid unnecessary rdmsrs/wrmsrs. 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.

[1]: https://bugzilla.kernel.org/attachment.cgi?id=304653
AMD64 Architecture Programmer’s Manual, Vol 2, Section 15.38 Instruction-Based Sampling Virtualization.

[2]: https://bugzilla.kernel.org/attachment.cgi?id=304653
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=304653
AMD64 Architecture Programmer’s Manual, Vol 2, Section 16.4.5 Extended Interrupts.

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

- Following Nested guests combinations were tested manually
----------------------------
| Collected IBS Samples in |
----------------------------
| L0 | L1 | L2 |
----------------------------

  |   Y    |   Y    |   Y    |
  |   Y    |   Y    |   N    |
  |   Y    |   N    |   Y    |
  |   Y    |   N    |   N    |
  |   N    |   Y    |   Y    |
  |   N    |   Y    |   N    |
  |   N    |   N    |   Y    |

----------------------------

Qemu changes can be found at below location:
https://github.com/Kullu14/qemu/tree/qemu_vibs_branch

Qemu commandline to enable IBS virtualization: qemu-system-x86_64 -enable-kvm -cpu EPYC-Genoa,+svm,+ibs,+extapic,+extlvt,+vibs \ ..

base-commit: 3b2ac85b3d2954b583dc2039825ad76eda8516a9 (kvm_x86 misc)

On top of base commit,
https://lore.kernel.org/all/[email protected]
patch is applied, then VIBS patch series is applied

Manali Shukla (8):
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: Add framework to save/restore host IBS state x86/cpufeatures: Add CPUID feature bit for VIBS in SEV-ES guest
KVM: SVM: Add support for IBS virtualization for SEV-ES guests
KVM: SVM: Enable IBS virtualization on non SEV-ES and SEV-ES guests
KVM: x86: nSVM: Implement support for nested IBS virtualization

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 virtualized IBS
KVM: SVM: Extend VMCB area for virtualized IBS registers
KVM: SVM: add support for IBS virtualization for non SEV-ES guests

 Documentation/virt/kvm/api.rst     |  23 ++++
 arch/x86/events/amd/Makefile       |   2 +-
 arch/x86/events/amd/ibs.c          |  23 ++++
 arch/x86/events/amd/vibs.c         | 101 ++++++++++++++
 arch/x86/include/asm/apicdef.h     |  14 ++
 arch/x86/include/asm/cpufeatures.h |   3 +
 arch/x86/include/asm/perf_event.h  |  27 ++++
 arch/x86/include/asm/svm.h         |  34 ++++-
 arch/x86/include/uapi/asm/kvm.h    |   5 +
 arch/x86/kvm/cpuid.c               |  11 ++
 arch/x86/kvm/governed_features.h   |   1 +
 arch/x86/kvm/lapic.c               |  78 ++++++++++-
 arch/x86/kvm/lapic.h               |   7 +-
 arch/x86/kvm/reverse_cpuid.h       |  15 +++
 arch/x86/kvm/svm/avic.c            |   4 +
 arch/x86/kvm/svm/nested.c          |  23 ++++
 arch/x86/kvm/svm/sev.c             |  10 ++
 arch/x86/kvm/svm/svm.c             | 207 +++++++++++++++++++++++++++++
 arch/x86/kvm/svm/svm.h             |   5 +-
 arch/x86/kvm/x86.c                 |  24 ++--
 include/uapi/linux/kvm.h           |  10 ++
 21 files changed, 603 insertions(+), 24 deletions(-)
 create mode 100644 arch/x86/events/amd/vibs.c
Signature · 1 line
2.34.1