Skip to content

Add support for the Bus Lock Threshold

Manali Shukla kvm linux-kselftest 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest5 patches 11 repliesIn review
  2. v45 patches 16 repliesSuperseded
  3. v34 patches 8 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v2 RFC5 patches4 repliesSuperseded
v1 RFC4 patches21 repliesSuperseded

Changes in v5 from the cover letter

- Incorporated review comments from Sean, Boris and Xiaoyao Li.
- Massage commit messages and documentation based on review comments.
- Removed bus_lock_rip from vcpu_svm and modified the implementation to continue running bus_lock_counter across the nested traslations accordingly.
- Removed pr_info which says "Buslock Threshold is supported"

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5KVM: x86: Make kvm_pio_request.linear_rip a common field for user exitsarch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c+5 -50 replies
2/5x86/cpufeatures: Add CPUID feature bit for the Bus Lock Thresholdarch/x86/include/asm/cpufeatures.h+1 -01 reply
3/5KVM: SVM: Enable Bus lock threshold exitarch/x86/include/asm/svm.h arch/x86/include/uapi/asm/svm.h+7 -20 replies
4/5KVM: SVM: Add support for KVM_CAP_X86_BUS_LOCK_EXIT on SVM CPUsDocumentation/virt/kvm/api.rst arch/x86/kvm/svm/nested.c arch/x86/kvm/svm/svm.c +1 more+78 -04 replies
5/5KVM: selftests: Add bus lock exit testtools/testing/selftests/kvm/Makefile.kvm tools/testing/selftests/kvm/x86/kvm_buslock_test.c+136 -02 replies

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchBorislav Petkov (AMD)
1/5
2/5R-b
3/5
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH v5 0/5] Add support for the Bus Lock Threshold

Misbehaving guests can cause bus locks to degrade the performance of a system. Non-WB (write-back) and misaligned locked RMW (read-modify-write) instructions are referred to as "bus locks" and require system wide synchronization among all processors to guarantee the atomicity. The bus locks can impose notable performance penalties for all processors within the system.

Support for the Bus Lock Threshold is indicated by CPUID Fn8000_000A_EDX[29] BusLockThreshold=1, the VMCB provides a Bus Lock Threshold enable bit and an unsigned 16-bit Bus Lock Threshold count.

VMCB intercept bit

    VMCB Offset     Bits    Function
    14h             5       Intercept bus lock operations

Bus lock threshold count

    VMCB Offset     Bits    Function
    120h            15:0    Bus lock counter

During VMRUN, the bus lock threshold count is fetched and stored in an internal count register. Prior to executing a bus lock within the guest, the processor verifies the count in the bus lock register. If the count is greater than zero, the processor executes the bus lock, reducing the count. However, if the count is zero, the bus lock operation is not performed, and instead, a Bus Lock Threshold #VMEXIT is triggered to transfer control to the Virtual Machine Monitor (VMM).

A Bus Lock Threshold #VMEXIT is reported to the VMM with VMEXIT code 0xA5h, VMEXIT_BUSLOCK. EXITINFO1 and EXITINFO2 are set to 0 on a VMEXIT_BUSLOCK. On a #VMEXIT, the processor writes the current value of the Bus Lock Threshold Counter to the VMCB.

Note: Currently, virtualizing the Bus Lock Threshold feature for L1 guest is not supported.

More details about the Bus Lock Threshold feature can be found in AMD APM [1].

v4 -> v5
- Incorporated review comments from Sean, Boris and Xiaoyao Li.
- Massage commit messages and documentation based on review comments.
- Removed bus_lock_rip from vcpu_svm and modified the implementation to continue running bus_lock_counter across the nested traslations accordingly.
- Removed pr_info which says "Buslock Threshold is supported"

v3 -> v4
- Incorporated Sean's review comments
- Added a preparatory patch to move linear_rip out of kvm_pio_request, so that it can be used by the bus lock threshold patches.
- Added complete_userspace_buslock() function to reload bus_lock_counter to '1' only if the usespace has not changed the RIP.
- Added changes to continue running bus_lock_counter across the nested transitions.

v2 -> v3
- Drop parch to add virt tag in /proc/cpuinfo.
- Incorporated Tom's review comments.

v1 -> v2
- Incorporated misc review comments from Sean.
- Removed bus_lock_counter module parameter.
- Set the value of bus_lock_counter to zero by default and reload the value by 1 in bus lock exit handler.
- Add documentation for the behavioral difference for KVM_EXIT_BUS_LOCK.
- Improved selftest for buslock to work on SVM and VMX.
- Rewrite the commit messages.

Patches are prepared on kvm-next/svm (bb5081f4abf2).

Testing done:
- Tested the Bus Lock Threshold functionality on normal, SEV, SEV-ES and SEV-SNP guests.
- Tested the Bus Lock Threshold functionality on nested guests.

[1]: AMD64 Architecture Programmer's Manual Pub. 24593, April 2024,

     Vol 2, 15.14.5 Bus Lock Threshold.
     https://bugzilla.kernel.org/attachment.cgi?id=306250

---
v1: https://lore.kernel.org/kvm/[email protected]/T/
v2: https://lore.kernel.org/kvm/[email protected]/T/
v3: https://lore.kernel.org/kvm/[email protected]/T/
v4: https://lore.kernel.org/kvm/[email protected]/

Manali Shukla (3):
KVM: x86: Make kvm_pio_request.linear_rip a common field for user
exits
x86/cpufeatures: Add CPUID feature bit for the Bus Lock Threshold
KVM: SVM: Add support for KVM_CAP_X86_BUS_LOCK_EXIT on SVM CPUs

Nikunj A Dadhania (2):
KVM: SVM: Enable Bus lock threshold exit
KVM: selftests: Add bus lock exit test

 Documentation/virt/kvm/api.rst                |   5 +
 arch/x86/include/asm/cpufeatures.h            |   1 +
 arch/x86/include/asm/kvm_host.h               |   2 +-
 arch/x86/include/asm/svm.h                    |   7 +-
 arch/x86/include/uapi/asm/svm.h               |   2 +
 arch/x86/kvm/svm/nested.c                     |  35 +++++
 arch/x86/kvm/svm/svm.c                        |  38 +++++
 arch/x86/kvm/svm/svm.h                        |   1 +
 arch/x86/kvm/x86.c                            |   8 +-
 tools/testing/selftests/kvm/Makefile.kvm      |   1 +
 .../selftests/kvm/x86/kvm_buslock_test.c      | 135 ++++++++++++++++++
 11 files changed, 228 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86/kvm_buslock_test.c

14,521 lines not shown · raw message

Part of this message is not shown here. View the raw message.