From dd90eccc25fcc750b2645364b9d227d3b70f1364 Mon Sep 17 00:00:00 2001 From: Zide Chen Date: Fri, 23 Apr 2021 10:04:23 -0700 Subject: [PATCH] hv: move invvpid and invept helper code from mmu.c to mmu.h moving invvpid and invept helper code from mmu.c to mmu.h, so that they can be accessed by the nested virtualization code. No logical changes. Tracked-On: #5923 Signed-off-by: Zide Chen Signed-off-by: Sainath Grandhi Acked-by: Eddie Dong --- hypervisor/arch/x86/mmu.c | 46 --------------------------- hypervisor/include/arch/x86/asm/mmu.h | 45 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index ca9d1ce58..e88ba5454 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -102,41 +102,6 @@ static const struct pgtable ppt_pgtable = { .recover_exe_right = ppt_nop_recover_exe_right, }; -#define INVEPT_TYPE_SINGLE_CONTEXT 1UL -#define INVEPT_TYPE_ALL_CONTEXTS 2UL -#define VMFAIL_INVALID_EPT_VPID \ - " jnc 1f\n" \ - " mov $1, %0\n" /* CF: error = 1 */ \ - " jmp 3f\n" \ - "1: jnz 2f\n" \ - " mov $2, %0\n" /* ZF: error = 2 */ \ - " jmp 3f\n" \ - "2: mov $0, %0\n" \ - "3:" - -struct invvpid_operand { - uint32_t vpid : 16; - uint32_t rsvd1 : 16; - uint32_t rsvd2 : 32; - uint64_t gva; -}; - -struct invept_desc { - uint64_t eptp; - uint64_t res; -}; - -static inline int32_t asm_invvpid(const struct invvpid_operand operand, uint64_t type) -{ - int32_t error; - asm volatile ("invvpid %1, %2\n" - VMFAIL_INVALID_EPT_VPID - : "=r" (error) - : "m" (operand), "r" (type) - : "memory"); - return error; -} - /* * @pre: the combined type and vpid is correct */ @@ -149,17 +114,6 @@ static inline void local_invvpid(uint64_t type, uint16_t vpid, uint64_t gva) } } -static inline int32_t asm_invept(uint64_t type, struct invept_desc desc) -{ - int32_t error; - asm volatile ("invept %1, %2\n" - VMFAIL_INVALID_EPT_VPID - : "=r" (error) - : "m" (desc), "r" (type) - : "memory"); - return error; -} - /* * @pre: the combined type and EPTP is correct */ diff --git a/hypervisor/include/arch/x86/asm/mmu.h b/hypervisor/include/arch/x86/asm/mmu.h index ffb749326..1ec018a61 100644 --- a/hypervisor/include/arch/x86/asm/mmu.h +++ b/hypervisor/include/arch/x86/asm/mmu.h @@ -55,6 +55,51 @@ /* IA32E Paging constants */ #define IA32E_REF_MASK ((get_pcpu_info())->physical_address_mask) +#define INVEPT_TYPE_SINGLE_CONTEXT 1UL +#define INVEPT_TYPE_ALL_CONTEXTS 2UL +#define VMFAIL_INVALID_EPT_VPID \ + " jnc 1f\n" \ + " mov $1, %0\n" /* CF: error = 1 */ \ + " jmp 3f\n" \ + "1: jnz 2f\n" \ + " mov $2, %0\n" /* ZF: error = 2 */ \ + " jmp 3f\n" \ + "2: mov $0, %0\n" \ + "3:" + +struct invvpid_operand { + uint32_t vpid : 16; + uint32_t rsvd1 : 16; + uint32_t rsvd2 : 32; + uint64_t gva; +}; + +static inline int32_t asm_invvpid(const struct invvpid_operand operand, uint64_t type) +{ + int32_t error; + asm volatile ("invvpid %1, %2\n" + VMFAIL_INVALID_EPT_VPID + : "=r" (error) + : "m" (operand), "r" (type) + : "memory"); + return error; +} + +struct invept_desc { + uint64_t eptp; + uint64_t res; +}; + +static inline int32_t asm_invept(uint64_t type, struct invept_desc desc) +{ + int32_t error; + asm volatile ("invept %1, %2\n" + VMFAIL_INVALID_EPT_VPID + : "=r" (error) + : "m" (desc), "r" (type) + : "memory"); + return error; +} struct acrn_vcpu; static inline uint64_t round_page_up(uint64_t addr)