Skip to content

Commit

Permalink
accel/tcg: Pass last not end to page_reset_target_data
Browse files Browse the repository at this point in the history
Pass the address of the last byte to be changed, rather than
the first address past the last byte.  This avoids overflow
when the last page of the address space is involved.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Mar 28, 2023
1 parent 49840a4 commit 10310cb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions accel/tcg/user-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void page_set_flags(target_ulong start, target_ulong last, int flags)
}

if (!flags || reset) {
page_reset_target_data(start, last + 1);
page_reset_target_data(start, last);
inval_tb |= pageflags_unset(start, last);
}
if (flags) {
Expand Down Expand Up @@ -814,15 +814,14 @@ typedef struct TargetPageDataNode {

static IntervalTreeRoot targetdata_root;

void page_reset_target_data(target_ulong start, target_ulong end)
void page_reset_target_data(target_ulong start, target_ulong last)
{
IntervalTreeNode *n, *next;
target_ulong last;

assert_memory_lock();

start = start & TARGET_PAGE_MASK;
last = TARGET_PAGE_ALIGN(end) - 1;
start &= TARGET_PAGE_MASK;
last |= ~TARGET_PAGE_MASK;

for (n = interval_tree_iter_first(&targetdata_root, start, last),
next = n ? interval_tree_iter_next(n, start, last) : NULL;
Expand Down Expand Up @@ -885,7 +884,7 @@ void *page_get_target_data(target_ulong address)
return t->data[(page - region) >> TARGET_PAGE_BITS];
}
#else
void page_reset_target_data(target_ulong start, target_ulong end) { }
void page_reset_target_data(target_ulong start, target_ulong last) { }
#endif /* TARGET_PAGE_DATA_SIZE */

/* The softmmu versions of these helpers are in cputlb.c. */
Expand Down
2 changes: 1 addition & 1 deletion include/exec/cpu-all.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,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 last, int flags);
void page_reset_target_data(target_ulong start, target_ulong end);
void page_reset_target_data(target_ulong start, target_ulong last);
int page_check_range(target_ulong start, target_ulong len, int flags);

/**
Expand Down
2 changes: 1 addition & 1 deletion linux-user/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
if (can_passthrough_madvise(start, end)) {
ret = get_errno(madvise(g2h_untagged(start), len, advice));
if ((advice == MADV_DONTNEED) && (ret == 0)) {
page_reset_target_data(start, start + len);
page_reset_target_data(start, start + len - 1);
}
}
}
Expand Down

0 comments on commit 10310cb

Please sign in to comment.