arch/x86/kvm/kvm_emulate.h

Source file repositories/reference/linux-study-clean/arch/x86/kvm/kvm_emulate.h

File Facts

System
Linux kernel
Corpus path
arch/x86/kvm/kvm_emulate.h
Extension
.h
Size
19119 bytes
Lines
577
Domain
Architecture Layer
Bucket
arch/x86
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

struct x86_exception {
	u8 vector;
	bool error_code_valid;
	u64 error_code;
	bool nested_page_fault;
	union {
		u64 address; /* cr2 or nested page fault gpa */
		unsigned long dr6;
		u64 payload;
	};
	u8 async_page_fault;
	unsigned long exit_qualification;
};

/*
 * This struct is used to carry enough information from the instruction
 * decoder to main KVM so that a decision can be made whether the
 * instruction needs to be intercepted or not.
 */
struct x86_instruction_info {
	u8  intercept;          /* which intercept                      */
	u8  rep_prefix;         /* rep prefix?                          */
	u8  modrm_mod;		/* mod part of modrm			*/
	u8  modrm_reg;          /* index of register used               */
	u8  modrm_rm;		/* rm part of modrm			*/
	u64 src_val;            /* value of source operand              */
	u64 dst_val;            /* value of destination operand         */
	u8  src_bytes;          /* size of source operand               */
	u8  dst_bytes;          /* size of destination operand          */
	u8  src_type;		/* type of source operand		*/
	u8  dst_type;		/* type of destination operand		*/
	u8  ad_bytes;           /* size of src/dst address              */
	u64 rip;		/* rip of the instruction		*/
	u64 next_rip;           /* rip following the instruction        */
};

/*
 * x86_emulate_ops:
 *
 * These operations represent the instruction emulator's interface to memory.
 * There are two categories of operation: those that act on ordinary memory
 * regions (*_std), and those that act on memory regions known to require
 * special treatment or emulation (*_emulated).
 *
 * The emulator assumes that an instruction accesses only one 'emulated memory'
 * location, that this location is the given linear faulting address (cr2), and
 * that this is one of the instruction's data operands. Instruction fetches and
 * stack operations are assumed never to access emulated memory. The emulator
 * automatically deduces which operand of a string-move operation is accessing
 * emulated memory, and assumes that the other operand accesses normal memory.
 *
 * NOTES:
 *  1. The emulator isn't very smart about emulated vs. standard memory.
 *     'Emulated memory' access addresses should be checked for sanity.
 *     'Normal memory' accesses may fault, and the caller must arrange to
 *     detect and handle reentrancy into the emulator via recursive faults.
 *     Accesses may be unaligned and may cross page boundaries.
 *  2. If the access fails (cannot emulate, or a standard access faults) then
 *     it is up to the memop to propagate the fault to the guest VM via
 *     some out-of-band mechanism, unknown to the emulator. The memop signals
 *     failure by returning X86EMUL_PROPAGATE_FAULT to the emulator, which will
 *     then immediately bail.
 *  3. Valid access sizes are 1, 2, 4 and 8 bytes. On x86/32 systems only
 *     cmpxchg8b_emulated need support 8-byte accesses.
 *  4. The emulator cannot handle 64-bit mode emulation on an x86/32 system.
 */
/* Access completed successfully: continue emulation as normal. */
#define X86EMUL_CONTINUE        0
/* Access is unhandleable: bail from emulation and return error to caller. */
#define X86EMUL_UNHANDLEABLE    1
/* Terminate emulation but return success to the caller. */
#define X86EMUL_PROPAGATE_FAULT 2 /* propagate a generated fault to guest */
#define X86EMUL_RETRY_INSTR     3 /* retry the instruction for some reason */
#define X86EMUL_CMPXCHG_FAILED  4 /* cmpxchg did not see expected value */
#define X86EMUL_IO_NEEDED       5 /* IO is needed to complete emulation */
#define X86EMUL_INTERCEPTED     6 /* Intercepted by nested VMCB/VMCS */
/* Emulation during event vectoring is unhandleable. */
#define X86EMUL_UNHANDLEABLE_VECTORING	7

/* x86-specific emulation flags */
#define X86EMUL_F_WRITE			BIT(0)
#define X86EMUL_F_FETCH			BIT(1)
#define X86EMUL_F_IMPLICIT		BIT(2)
#define X86EMUL_F_INVLPG		BIT(3)
#define X86EMUL_F_MSR			BIT(4)
#define X86EMUL_F_DT_LOAD		BIT(5)

struct x86_emulate_ops {
	void (*vm_bugged)(struct x86_emulate_ctxt *ctxt);
	/*

Annotation

Implementation Notes