Skip to content

Commit c4f5519

Browse files
jsmattsonjrbonzini
authored andcommitted
kvm: x86: Introduce KVM_CAP_EXCEPTION_PAYLOAD
This is a per-VM capability which can be enabled by userspace so that the faulting linear address will be included with the information about a pending #PF in L2, and the "new DR6 bits" will be included with the information about a pending #DB in L2. With this capability enabled, the L1 hypervisor can now intercept #PF before CR2 is modified. Under VMX, the L1 hypervisor can now intercept #DB before DR6 and DR7 are modified. When userspace has enabled KVM_CAP_EXCEPTION_PAYLOAD, it should generally provide an appropriate payload when injecting a #PF or #DB exception via KVM_SET_VCPU_EVENTS. However, to support restoring old checkpoints, this payload is not required. Note that bit 16 of the "new DR6 bits" is set to indicate that a debug exception (#DB) or a breakpoint exception (#BP) occurred inside an RTM region while advanced debugging of RTM transactional regions was enabled. This is the reverse of DR6.RTM, which is cleared in this scenario. This capability also enables exception.pending in struct kvm_vcpu_events, which allows userspace to distinguish between pending and injected exceptions. Reported-by: Jim Mattson <jmattson@google.com> Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Jim Mattson <jmattson@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f10c729 commit c4f5519

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Documentation/virtual/kvm/api.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4568,7 +4568,7 @@ hpage module parameter is not set to 1, -EINVAL is returned.
45684568
While it is generally possible to create a huge page backed VM without
45694569
this capability, the VM will not be able to run.
45704570

4571-
7.14 KVM_CAP_MSR_PLATFORM_INFO
4571+
7.15 KVM_CAP_MSR_PLATFORM_INFO
45724572

45734573
Architectures: x86
45744574
Parameters: args[0] whether feature should be enabled or not
@@ -4591,6 +4591,31 @@ state). Enabling this capability on a VM depends on the CPU having
45914591
the necessary functionality and on the facility being enabled with a
45924592
kvm-hv module parameter.
45934593

4594+
7.17 KVM_CAP_EXCEPTION_PAYLOAD
4595+
4596+
Architectures: x86
4597+
Parameters: args[0] whether feature should be enabled or not
4598+
4599+
With this capability enabled, CR2 will not be modified prior to the
4600+
emulated VM-exit when L1 intercepts a #PF exception that occurs in
4601+
L2. Similarly, for kvm-intel only, DR6 will not be modified prior to
4602+
the emulated VM-exit when L1 intercepts a #DB exception that occurs in
4603+
L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or
4604+
#DB) exception for L2, exception.has_payload will be set and the
4605+
faulting address (or the new DR6 bits*) will be reported in the
4606+
exception_payload field. Similarly, when userspace injects a #PF (or
4607+
#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set
4608+
exception.has_payload and to put the faulting address (or the new DR6
4609+
bits*) in the exception_payload field.
4610+
4611+
This capability also enables exception.pending in struct
4612+
kvm_vcpu_events, which allows userspace to distinguish between pending
4613+
and injected exceptions.
4614+
4615+
4616+
* For the new DR6 bits, note that bit 16 is set iff the #DB exception
4617+
will clear DR6.RTM.
4618+
45944619
8. Other capabilities.
45954620
----------------------
45964621

arch/x86/kvm/x86.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
30153015
case KVM_CAP_IMMEDIATE_EXIT:
30163016
case KVM_CAP_GET_MSR_FEATURES:
30173017
case KVM_CAP_MSR_PLATFORM_INFO:
3018+
case KVM_CAP_EXCEPTION_PAYLOAD:
30183019
r = 1;
30193020
break;
30203021
case KVM_CAP_SYNC_REGS:
@@ -4500,6 +4501,10 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
45004501
kvm->arch.guest_can_read_msr_platform_info = cap->args[0];
45014502
r = 0;
45024503
break;
4504+
case KVM_CAP_EXCEPTION_PAYLOAD:
4505+
kvm->arch.exception_payload_enabled = cap->args[0];
4506+
r = 0;
4507+
break;
45034508
default:
45044509
r = -EINVAL;
45054510
break;

include/uapi/linux/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ struct kvm_ppc_resize_hpt {
964964
#define KVM_CAP_HYPERV_SEND_IPI 161
965965
#define KVM_CAP_COALESCED_PIO 162
966966
#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163
967+
#define KVM_CAP_EXCEPTION_PAYLOAD 164
967968

968969
#ifdef KVM_CAP_IRQ_ROUTING
969970

0 commit comments

Comments
 (0)