@@ -6483,9 +6483,12 @@ More architecture-specific flags detailing state of the VCPU that may
64836483affect the device's behavior. Current defined flags::
64846484
64856485 /* x86, set if the VCPU is in system management mode */
6486- #define KVM_RUN_X86_SMM (1 << 0)
6486+ #define KVM_RUN_X86_SMM (1 << 0)
64876487 /* x86, set if bus lock detected in VM */
6488- #define KVM_RUN_BUS_LOCK (1 << 1)
6488+ #define KVM_RUN_X86_BUS_LOCK (1 << 1)
6489+ /* x86, set if the VCPU is executing a nested (L2) guest */
6490+ #define KVM_RUN_X86_GUEST_MODE (1 << 2)
6491+
64896492 /* arm64, set for KVM_EXIT_DEBUG */
64906493 #define KVM_DEBUG_ARCH_HSR_HIGH_VALID (1 << 0)
64916494
@@ -7831,29 +7834,31 @@ Valid bits in args[0] are::
78317834 #define KVM_BUS_LOCK_DETECTION_OFF (1 << 0)
78327835 #define KVM_BUS_LOCK_DETECTION_EXIT (1 << 1)
78337836
7834- Enabling this capability on a VM provides userspace with a way to select
7835- a policy to handle the bus locks detected in guest. Userspace can obtain
7836- the supported modes from the result of KVM_CHECK_EXTENSION and define it
7837- through the KVM_ENABLE_CAP.
7837+ Enabling this capability on a VM provides userspace with a way to select a
7838+ policy to handle the bus locks detected in guest. Userspace can obtain the
7839+ supported modes from the result of KVM_CHECK_EXTENSION and define it through
7840+ the KVM_ENABLE_CAP. The supported modes are mutually-exclusive .
78387841
7839- KVM_BUS_LOCK_DETECTION_OFF and KVM_BUS_LOCK_DETECTION_EXIT are supported
7840- currently and mutually exclusive with each other. More bits can be added in
7841- the future.
7842+ This capability allows userspace to force VM exits on bus locks detected in the
7843+ guest, irrespective whether or not the host has enabled split-lock detection
7844+ (which triggers an #AC exception that KVM intercepts). This capability is
7845+ intended to mitigate attacks where a malicious/buggy guest can exploit bus
7846+ locks to degrade the performance of the whole system.
78427847
7843- With KVM_BUS_LOCK_DETECTION_OFF set, bus locks in guest will not cause vm exits
7844- so that no additional actions are needed. This is the default mode.
7848+ If KVM_BUS_LOCK_DETECTION_OFF is set, KVM doesn't force guest bus locks to VM
7849+ exit, although the host kernel's split-lock #AC detection still applies, if
7850+ enabled.
78457851
7846- With KVM_BUS_LOCK_DETECTION_EXIT set, vm exits happen when bus lock detected
7847- in VM. KVM just exits to userspace when handling them. Userspace can enforce
7848- its own throttling or other policy based mitigations.
7852+ If KVM_BUS_LOCK_DETECTION_EXIT is set, KVM enables a CPU feature that ensures
7853+ bus locks in the guest trigger a VM exit, and KVM exits to userspace for all
7854+ such VM exits, e.g. to allow userspace to throttle the offending guest and/or
7855+ apply some other policy-based mitigation. When exiting to userspace, KVM sets
7856+ KVM_RUN_X86_BUS_LOCK in vcpu-run->flags, and conditionally sets the exit_reason
7857+ to KVM_EXIT_X86_BUS_LOCK.
78497858
7850- This capability is aimed to address the thread that VM can exploit bus locks to
7851- degree the performance of the whole system. Once the userspace enable this
7852- capability and select the KVM_BUS_LOCK_DETECTION_EXIT mode, KVM will set the
7853- KVM_RUN_BUS_LOCK flag in vcpu-run->flags field and exit to userspace. Concerning
7854- the bus lock vm exit can be preempted by a higher priority VM exit, the exit
7855- notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons.
7856- KVM_RUN_BUS_LOCK flag is used to distinguish between them.
7859+ Note! Detected bus locks may be coincident with other exits to userspace, i.e.
7860+ KVM_RUN_X86_BUS_LOCK should be checked regardless of the primary exit reason if
7861+ userspace wants to take action on all detected bus locks.
78577862
785878637.23 KVM_CAP_PPC_DAWR1
78597864----------------------
@@ -8137,6 +8142,37 @@ error/annotated fault.
81378142
81388143See KVM_EXIT_MEMORY_FAULT for more information.
81398144
8145+ 7.35 KVM_CAP_X86_APIC_BUS_CYCLES_NS
8146+ -----------------------------------
8147+
8148+ :Architectures: x86
8149+ :Target: VM
8150+ :Parameters: args[0] is the desired APIC bus clock rate, in nanoseconds
8151+ :Returns: 0 on success, -EINVAL if args[0] contains an invalid value for the
8152+ frequency or if any vCPUs have been created, -ENXIO if a virtual
8153+ local APIC has not been created using KVM_CREATE_IRQCHIP.
8154+
8155+ This capability sets the VM's APIC bus clock frequency, used by KVM's in-kernel
8156+ virtual APIC when emulating APIC timers. KVM's default value can be retrieved
8157+ by KVM_CHECK_EXTENSION.
8158+
8159+ Note: Userspace is responsible for correctly configuring CPUID 0x15, a.k.a. the
8160+ core crystal clock frequency, if a non-zero CPUID 0x15 is exposed to the guest.
8161+
8162+ 7.36 KVM_CAP_X86_GUEST_MODE
8163+ ------------------------------
8164+
8165+ :Architectures: x86
8166+ :Returns: Informational only, -EINVAL on direct KVM_ENABLE_CAP.
8167+
8168+ The presence of this capability indicates that KVM_RUN will update the
8169+ KVM_RUN_X86_GUEST_MODE bit in kvm_run.flags to indicate whether the
8170+ vCPU was executing nested guest code when it exited.
8171+
8172+ KVM exits with the register state of either the L1 or L2 guest
8173+ depending on which executed at the time of an exit. Userspace must
8174+ take care to differentiate between these cases.
8175+
814081768. Other capabilities.
81418177======================
81428178
0 commit comments