From f81585eb3da0c50092b7ae32f82d200b618db802 Mon Sep 17 00:00:00 2001 From: Yuan Liu Date: Thu, 13 Jun 2019 18:03:53 +0800 Subject: [PATCH] HV: Add flush_address_space API. flush_address_space is used to flush address space by clflushopt instruction. Signed-off-by: Jack Ren Signed-off-by: Yuan Liu Reviewed-by: Li, Fei1 Acked-by: Eddie Dong --- hypervisor/arch/x86/mmu.c | 13 +++++++++++++ hypervisor/include/arch/x86/mmu.h | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index 9ba08511d..570359288 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -294,3 +294,16 @@ void init_paging(void) /* set ptep in sanitized_page point to itself */ sanitize_pte((uint64_t *)sanitized_page); } + +/* + * @pre: addr != NULL && size != 0 + */ +void flush_address_space(void *addr, uint64_t size) +{ + uint64_t n = 0UL; + + while (n < size) { + clflushopt((char *)addr + n); + n += CACHE_LINE_SIZE; + } +} diff --git a/hypervisor/include/arch/x86/mmu.h b/hypervisor/include/arch/x86/mmu.h index b6b7790b3..ce1a17a11 100644 --- a/hypervisor/include/arch/x86/mmu.h +++ b/hypervisor/include/arch/x86/mmu.h @@ -150,6 +150,18 @@ void flush_vpid_single(uint16_t vpid); * @return None */ void flush_vpid_global(void); + +/** + * @brief Flush address space + * + * @param[in] addr the specified virtual address + * + * @param[in] size the specified size to flush + * + * @return None + */ +void flush_address_space(void *addr, uint64_t size); + /** * @brief Guest-physical mappings and combined mappings invalidation *