Index: head/sys/amd64/include/vmm_instruction_emul.h =================================================================== --- head/sys/amd64/include/vmm_instruction_emul.h +++ head/sys/amd64/include/vmm_instruction_emul.h @@ -103,6 +103,7 @@ */ int vm_gla2gpa_nofault(struct vm *vm, int vcpuid, struct vm_guest_paging *paging, uint64_t gla, int prot, uint64_t *gpa, int *is_fault); +#endif /* _KERNEL */ void vie_init(struct vie *vie, const char *inst_bytes, int inst_length); @@ -117,9 +118,17 @@ * To skip the 'gla' verification for this or any other reason pass * in VIE_INVALID_GLA instead. */ +#ifdef _KERNEL #define VIE_INVALID_GLA (1UL << 63) /* a non-canonical address */ int vmm_decode_instruction(struct vm *vm, int cpuid, uint64_t gla, enum vm_cpu_mode cpu_mode, int csd, struct vie *vie); +#else /* !_KERNEL */ +/* + * Permit instruction decoding logic to be compiled outside of the kernel for + * rapid iteration and validation. No GLA validation is performed, obviously. + */ +int vmm_decode_instruction(enum vm_cpu_mode cpu_mode, int csd, + struct vie *vie); #endif /* _KERNEL */ #endif /* _VMM_INSTRUCTION_EMUL_H_ */ Index: head/sys/amd64/vmm/vmm_instruction_emul.c =================================================================== --- head/sys/amd64/vmm/vmm_instruction_emul.c +++ head/sys/amd64/vmm/vmm_instruction_emul.c @@ -50,9 +50,14 @@ #include +#include #include +#include +#include +#include #include #define KASSERT(exp,msg) assert((exp)) +#define panic(...) errx(4, __VA_ARGS__) #endif /* _KERNEL */ #include @@ -1896,7 +1901,6 @@ return (0); } -#ifdef _KERNEL void vie_init(struct vie *vie, const char *inst_bytes, int inst_length) { @@ -1915,6 +1919,7 @@ } } +#ifdef _KERNEL static int pf_error_code(int usermode, int prot, int rsvd, uint64_t pte) { @@ -2189,6 +2194,7 @@ vie->num_valid = inst_length; return (0); } +#endif /* _KERNEL */ static int vie_peek(struct vie *vie, uint8_t *x) @@ -2611,6 +2617,7 @@ return (0); } +#ifdef _KERNEL /* * Verify that the 'guest linear address' provided as collateral of the nested * page table fault matches with our instruction decoding. @@ -2702,10 +2709,15 @@ return (0); } +#endif /* _KERNEL */ int +#ifdef _KERNEL vmm_decode_instruction(struct vm *vm, int cpuid, uint64_t gla, enum vm_cpu_mode cpu_mode, int cs_d, struct vie *vie) +#else +vmm_decode_instruction(enum vm_cpu_mode cpu_mode, int cs_d, struct vie *vie) +#endif { if (decode_prefixes(vie, cpu_mode, cs_d)) @@ -2729,13 +2741,14 @@ if (decode_moffset(vie)) return (-1); +#ifdef _KERNEL if ((vie->op.op_flags & VIE_OP_F_NO_GLA_VERIFICATION) == 0) { if (verify_gla(vm, cpuid, gla, vie, cpu_mode)) return (-1); } +#endif vie->decoded = 1; /* success */ return (0); } -#endif /* _KERNEL */