From owner-svn-src-head@freebsd.org Thu Apr 16 16:50:34 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 243762C1A8B; Thu, 16 Apr 2020 16:50:34 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4934wV0CRNz3Gkv; Thu, 16 Apr 2020 16:50:34 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 026CEBF9C; Thu, 16 Apr 2020 16:50:34 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03GGoX2D063603; Thu, 16 Apr 2020 16:50:33 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03GGoXWg063602; Thu, 16 Apr 2020 16:50:33 GMT (envelope-from cem@FreeBSD.org) Message-Id: <202004161650.03GGoXWg063602@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Thu, 16 Apr 2020 16:50:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360012 - in head/sys/amd64: include vmm X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: in head/sys/amd64: include vmm X-SVN-Commit-Revision: 360012 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Apr 2020 16:50:34 -0000 Author: cem Date: Thu Apr 16 16:50:33 2020 New Revision: 360012 URL: https://svnweb.freebsd.org/changeset/base/360012 Log: vmm(4): Expose instruction decode to userspace build Permit instruction decoding logic to be compiled outside of the kernel for rapid iteration and validation. Reviewed by: grehan Differential Revision: https://reviews.freebsd.org/D24439 Modified: head/sys/amd64/include/vmm_instruction_emul.h head/sys/amd64/vmm/vmm_instruction_emul.c Modified: head/sys/amd64/include/vmm_instruction_emul.h ============================================================================== --- head/sys/amd64/include/vmm_instruction_emul.h Thu Apr 16 16:00:21 2020 (r360011) +++ head/sys/amd64/include/vmm_instruction_emul.h Thu Apr 16 16:50:33 2020 (r360012) @@ -103,6 +103,7 @@ int vm_gla2gpa(struct vm *vm, int vcpuid, struct vm_gu */ 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 @@ void vie_init(struct vie *vie, const char *inst_bytes, * 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_ */ Modified: head/sys/amd64/vmm/vmm_instruction_emul.c ============================================================================== --- head/sys/amd64/vmm/vmm_instruction_emul.c Thu Apr 16 16:00:21 2020 (r360011) +++ head/sys/amd64/vmm/vmm_instruction_emul.c Thu Apr 16 16:50:33 2020 (r360012) @@ -50,9 +50,14 @@ __FBSDID("$FreeBSD$"); #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 @@ vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum vm_r return (0); } -#ifdef _KERNEL void vie_init(struct vie *vie, const char *inst_bytes, int inst_length) { @@ -1915,6 +1919,7 @@ vie_init(struct vie *vie, const char *inst_bytes, int } } +#ifdef _KERNEL static int pf_error_code(int usermode, int prot, int rsvd, uint64_t pte) { @@ -2189,6 +2194,7 @@ vmm_fetch_instruction(struct vm *vm, int vcpuid, struc vie->num_valid = inst_length; return (0); } +#endif /* _KERNEL */ static int vie_peek(struct vie *vie, uint8_t *x) @@ -2611,6 +2617,7 @@ decode_moffset(struct vie *vie) 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 @@ verify_gla(struct vm *vm, int cpuid, uint64_t gla, str 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 @@ vmm_decode_instruction(struct vm *vm, int cpuid, uint6 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 */