kvm: x86: Allow userspace to handle emulation errors
Add a fallback mechanism to the in-kernel instruction emulator that allows userspace the opportunity to process an instruction the emulator was unable to. When the in-kernel instruction emulator fails to process an instruction it will either inject a #UD into the guest or exit to userspace with exit reason KVM_INTERNAL_ERROR. This is because it does not know how to proceed in an appropriate manner. This feature lets userspace get involved to see if it can figure out a better path forward. Signed-off-by: Aaron Lewis <aaronlewis@google.com> Reviewed-by: David Edmondson <david.edmondson@oracle.com> Message-Id: <20210510144834.658457-2-aaronlewis@google.com> Reviewed-by: Jim Mattson <jmattson@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
committed by
Paolo Bonzini
parent
27de925044
commit
19238e75bd
@@ -280,6 +280,9 @@ struct kvm_xen_exit {
|
||||
/* Encounter unexpected vm-exit reason */
|
||||
#define KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON 4
|
||||
|
||||
/* Flags that describe what fields in emulation_failure hold valid data. */
|
||||
#define KVM_INTERNAL_ERROR_EMULATION_FLAG_INSTRUCTION_BYTES (1ULL << 0)
|
||||
|
||||
/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
|
||||
struct kvm_run {
|
||||
/* in */
|
||||
@@ -383,6 +386,25 @@ struct kvm_run {
|
||||
__u32 ndata;
|
||||
__u64 data[16];
|
||||
} internal;
|
||||
/*
|
||||
* KVM_INTERNAL_ERROR_EMULATION
|
||||
*
|
||||
* "struct emulation_failure" is an overlay of "struct internal"
|
||||
* that is used for the KVM_INTERNAL_ERROR_EMULATION sub-type of
|
||||
* KVM_EXIT_INTERNAL_ERROR. Note, unlike other internal error
|
||||
* sub-types, this struct is ABI! It also needs to be backwards
|
||||
* compatible with "struct internal". Take special care that
|
||||
* "ndata" is correct, that new fields are enumerated in "flags",
|
||||
* and that each flag enumerates fields that are 64-bit aligned
|
||||
* and sized (so that ndata+internal.data[] is valid/accurate).
|
||||
*/
|
||||
struct {
|
||||
__u32 suberror;
|
||||
__u32 ndata;
|
||||
__u64 flags;
|
||||
__u8 insn_size;
|
||||
__u8 insn_bytes[15];
|
||||
} emulation_failure;
|
||||
/* KVM_EXIT_OSI */
|
||||
struct {
|
||||
__u64 gprs[32];
|
||||
@@ -1088,6 +1110,7 @@ struct kvm_ppc_resize_hpt {
|
||||
#define KVM_CAP_EXIT_HYPERCALL 201
|
||||
#define KVM_CAP_PPC_RPT_INVALIDATE 202
|
||||
#define KVM_CAP_BINARY_STATS_FD 203
|
||||
#define KVM_CAP_EXIT_ON_EMULATION_FAILURE 204
|
||||
|
||||
#ifdef KVM_CAP_IRQ_ROUTING
|
||||
|
||||
|
||||
Reference in New Issue
Block a user