[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 46/47] accel/tcg: Handle false negative lookup in page_check_range
From: |
Richard Henderson |
Subject: |
[PULL 46/47] accel/tcg: Handle false negative lookup in page_check_range |
Date: |
Thu, 29 Dec 2022 16:02:20 -0800 |
As in page_get_flags, we need to try again with the mmap
lock held if we fail a page lookup.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/user-exec.c | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c
index 2c5c10d2e6..a8eb63ab96 100644
--- a/accel/tcg/user-exec.c
+++ b/accel/tcg/user-exec.c
@@ -525,6 +525,8 @@ void page_set_flags(target_ulong start, target_ulong end,
int flags)
int page_check_range(target_ulong start, target_ulong len, int flags)
{
target_ulong last;
+ int locked; /* tri-state: =0: unlocked, +1: global, -1: local */
+ int ret;
if (len == 0) {
return 0; /* trivial length */
@@ -535,42 +537,67 @@ int page_check_range(target_ulong start, target_ulong
len, int flags)
return -1; /* wrap around */
}
+ locked = have_mmap_lock();
while (true) {
PageFlagsNode *p = pageflags_find(start, last);
int missing;
if (!p) {
- return -1; /* entire region invalid */
+ if (!locked) {
+ /*
+ * Lockless lookups have false negatives.
+ * Retry with the lock held.
+ */
+ mmap_lock();
+ locked = -1;
+ p = pageflags_find(start, last);
+ }
+ if (!p) {
+ ret = -1; /* entire region invalid */
+ break;
+ }
}
if (start < p->itree.start) {
- return -1; /* initial bytes invalid */
+ ret = -1; /* initial bytes invalid */
+ break;
}
missing = flags & ~p->flags;
if (missing & PAGE_READ) {
- return -1; /* page not readable */
+ ret = -1; /* page not readable */
+ break;
}
if (missing & PAGE_WRITE) {
if (!(p->flags & PAGE_WRITE_ORG)) {
- return -1; /* page not writable */
+ ret = -1; /* page not writable */
+ break;
}
/* Asking about writable, but has been protected: undo. */
if (!page_unprotect(start, 0)) {
- return -1;
+ ret = -1;
+ break;
}
/* TODO: page_unprotect should take a range, not a single page. */
if (last - start < TARGET_PAGE_SIZE) {
- return 0; /* ok */
+ ret = 0; /* ok */
+ break;
}
start += TARGET_PAGE_SIZE;
continue;
}
if (last <= p->itree.last) {
- return 0; /* ok */
+ ret = 0; /* ok */
+ break;
}
start = p->itree.last + 1;
}
+
+ /* Release the lock if acquired locally. */
+ if (locked < 0) {
+ mmap_unlock();
+ }
+ return ret;
}
void page_protect(tb_page_addr_t address)
--
2.34.1
- [PULL 29/47] tcg: Replace TCG_TARGET_CALL_ALIGN_ARGS with TCG_TARGET_CALL_ARG_I64, (continued)
- [PULL 29/47] tcg: Replace TCG_TARGET_CALL_ALIGN_ARGS with TCG_TARGET_CALL_ARG_I64, Richard Henderson, 2022/12/29
- [PULL 39/47] tcg: Convert typecode_to_ffi from array to function, Richard Henderson, 2022/12/29
- [PULL 28/47] tcg: Introduce TCGCallReturnKind and TCGCallArgumentKind, Richard Henderson, 2022/12/29
- [PULL 32/47] accel/tcg/plugin: Don't search for the function pointer index, Richard Henderson, 2022/12/29
- [PULL 24/47] tcg: Simplify calls to temp_sync vs mem_coherent, Richard Henderson, 2022/12/29
- [PULL 30/47] tcg: Replace TCG_TARGET_EXTEND_ARGS with TCG_TARGET_CALL_ARG_I32, Richard Henderson, 2022/12/29
- [PULL 38/47] tcg: Reorg function calls, Richard Henderson, 2022/12/29
- [PULL 42/47] tcg/aarch64: Merge tcg_out_callr into tcg_out_call, Richard Henderson, 2022/12/29
- [PULL 40/47] tcg: Factor init_ffi_layouts() out of tcg_context_init(), Richard Henderson, 2022/12/29
- [PULL 41/47] tcg: Move ffi_cif pointer into TCGHelperInfo, Richard Henderson, 2022/12/29
- [PULL 46/47] accel/tcg: Handle false negative lookup in page_check_range,
Richard Henderson <=
- [PULL 44/47] accel/tcg: Fix tb_invalidate_phys_page_unwind, Richard Henderson, 2022/12/29
- [PULL 45/47] accel/tcg: Use g_free_rcu for user-exec interval trees, Richard Henderson, 2022/12/29
- [PULL 47/47] tests/tcg/multiarch: add vma-pthread.c, Richard Henderson, 2022/12/29
- [PULL 43/47] tcg: Add TCGHelperInfo argument to tcg_out_call, Richard Henderson, 2022/12/29