linux-user/aarch64: Reset target data on MADV_DONTNEED
PATCH 1/1 linux-user/aarch64: Reset target data on MADV_DONTNEED
aarch64 stores MTE tags in target_date, and they should be reset by MADV_DONTNEED.
Signed-off-by Vitaly Buka <[email protected]>
--- accel/tcg/translate-all.c | 24 ++++++++++++++++++++++++ include/exec/cpu-all.h | 1 + linux-user/mmap.c | 2 ++ 3 files changed, 27 insertions(+)
accel/tcg/translate-all.c +24 -0
@@ -2314,6 +2314,30 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) } } +void page_reset_target_data (target_ulong start,target_ulong end) +{ +target_ulong addr, len; + +/* This function should never be called with addresses outside the +guest address space. If this assert fires, it probably indicates +a missing call to h2g_valid. */ +assert (end -1 <=GUEST_ADDR_MAX ); +assert (start < end); +assert_memory_lock (); + + start = start &TARGET_PAGE_MASK ; + end =TARGET_PAGE_ALIGN (end); + +for (addr = start, len = end - start; + len !=0 ; + len -=TARGET_PAGE_SIZE , addr +=TARGET_PAGE_SIZE ) { +PageDesc *p =page_find_alloc (addr >>TARGET_PAGE_BITS ,1 ); + +g_free (p->target_data); + p->target_data =NULL ; + } +} +void *page_get_target_data (target_ulong address) {PageDesc *p =page_find (address >>TARGET_PAGE_BITS );
include/exec/cpu-all.h +1 -0
@@ -271,6 +271,7 @@ int walk_memory_regions(void *, walk_memory_regions_fn);int page_get_flags (target_ulong address);void page_set_flags (target_ulong start,target_ulong end,int flags); +void page_reset_target_data (target_ulong start,target_ulong end);int page_check_range (target_ulong start,target_ulong len,int flags);/**
linux-user/mmap.c +2 -0
@@ -894,6 +894,8 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)if ((advice &MADV_DONTNEED ) &&can_passthrough_madv_dontneed (start, end)) { ret =get_errno (madvise (g2h_untagged (start), len,MADV_DONTNEED )); +if (ret ==0 ) +page_reset_target_data (start, start + len); }mmap_unlock ();
Signature · 1 line
2.37.0.144.g8ac04bfd2-goog
Quoted 9 lines · Vitaly Buka
aarch64 stores MTE tags in
target_date, and they should be reset byMADV_DONTNEED.Signed-off-by Vitaly Buka <[email protected]>--- accel/tcg/translate-all.c | 24 ++++++++++++++++++++++++ include/exec/cpu-all.h | 1 + linux-user/mmap.c | 2 ++ 3 files changed, 27 insertions(+)
Reviewed-by Richard Henderson <[email protected]>
r~
Quoted 61 lines
accel/tcg/translate-all.c +24
-0@@ -2314,6 +2314,30 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) } } +void page_reset_target_data (target_ulong start,target_ulong end) +{ +target_ulong addr, len; + +/* This function should never be called with addresses outside the +guest address space. If this assert fires, it probably indicates +a missing call to h2g_valid. */ +assert (end -1 <=GUEST_ADDR_MAX ); +assert (start < end); +assert_memory_lock (); + + start = start &TARGET_PAGE_MASK ; + end =TARGET_PAGE_ALIGN (end); + +for (addr = start, len = end - start; + len !=0 ; + len -=TARGET_PAGE_SIZE , addr +=TARGET_PAGE_SIZE ) { +PageDesc *p =page_find_alloc (addr >>TARGET_PAGE_BITS ,1 ); + +g_free (p->target_data); + p->target_data =NULL ; + } +} +void *page_get_target_data (target_ulong address) {PageDesc *p =page_find (address >>TARGET_PAGE_BITS );include/exec/cpu-all.h +1
-0@@ -271,6 +271,7 @@ int walk_memory_regions(void *, walk_memory_regions_fn);int page_get_flags (target_ulong address);void page_set_flags (target_ulong start,target_ulong end,int flags); +void page_reset_target_data (target_ulong start,target_ulong end);int page_check_range (target_ulong start,target_ulong len,int flags);/** linux-user/mmap.c +2
-0@@ -894,6 +894,8 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)if ((advice &MADV_DONTNEED ) &&can_passthrough_madv_dontneed (start, end)) { ret =get_errno (madvise (g2h_untagged (start), len,MADV_DONTNEED )); +if (ret ==0 ) +page_reset_target_data (start, start + len); }mmap_unlock ();