From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: alex.bennee@linaro.org, philmd@linaro.org
Subject: [PATCH for-8.0 v2 07/12] accel/tcg: Pass last not end to page_collection_lock
Date: Mon, 27 Mar 2023 14:18:19 -0700 [thread overview]
Message-ID: <20230327211824.1785547-8-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230327211824.1785547-1-richard.henderson@linaro.org>
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.
Fixes a bug in the loop comparision where "<= end" would lock
one more page than required.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/tb-maint.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index 04d2751bb6..57da2feb2f 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -511,20 +511,20 @@ static gint tb_page_addr_cmp(gconstpointer ap, gconstpointer bp, gpointer udata)
}
/*
- * Lock a range of pages ([@start,@end[) as well as the pages of all
+ * Lock a range of pages ([@start,@last]) as well as the pages of all
* intersecting TBs.
* Locking order: acquire locks in ascending order of page index.
*/
static struct page_collection *page_collection_lock(tb_page_addr_t start,
- tb_page_addr_t end)
+ tb_page_addr_t last)
{
struct page_collection *set = g_malloc(sizeof(*set));
tb_page_addr_t index;
PageDesc *pd;
start >>= TARGET_PAGE_BITS;
- end >>= TARGET_PAGE_BITS;
- g_assert(start <= end);
+ last >>= TARGET_PAGE_BITS;
+ g_assert(start <= last);
set->tree = q_tree_new_full(tb_page_addr_cmp, NULL, NULL,
page_entry_destroy);
@@ -534,7 +534,7 @@ static struct page_collection *page_collection_lock(tb_page_addr_t start,
retry:
q_tree_foreach(set->tree, page_entry_lock, NULL);
- for (index = start; index <= end; index++) {
+ for (index = start; index <= last; index++) {
TranslationBlock *tb;
PageForEachNext n;
@@ -1154,7 +1154,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,
void tb_invalidate_phys_page(tb_page_addr_t addr)
{
struct page_collection *pages;
- tb_page_addr_t start, end;
+ tb_page_addr_t start, last;
PageDesc *p;
p = page_find(addr >> TARGET_PAGE_BITS);
@@ -1163,9 +1163,9 @@ void tb_invalidate_phys_page(tb_page_addr_t addr)
}
start = addr & TARGET_PAGE_MASK;
- end = start + TARGET_PAGE_SIZE;
- pages = page_collection_lock(start, end);
- tb_invalidate_phys_page_range__locked(pages, p, start, end, 0);
+ last = addr | ~TARGET_PAGE_MASK;
+ pages = page_collection_lock(start, last);
+ tb_invalidate_phys_page_range__locked(pages, p, start, last + 1, 0);
page_collection_unlock(pages);
}
@@ -1181,7 +1181,7 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end)
struct page_collection *pages;
tb_page_addr_t next;
- pages = page_collection_lock(start, end);
+ pages = page_collection_lock(start, end - 1);
for (next = (start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
start < end;
start = next, next += TARGET_PAGE_SIZE) {
@@ -1226,7 +1226,7 @@ void tb_invalidate_phys_range_fast(ram_addr_t ram_addr,
{
struct page_collection *pages;
- pages = page_collection_lock(ram_addr, ram_addr + size);
+ pages = page_collection_lock(ram_addr, ram_addr + size - 1);
tb_invalidate_phys_page_fast__locked(pages, ram_addr, size, retaddr);
page_collection_unlock(pages);
}
--
2.34.1
next prev parent reply other threads:[~2023-03-27 21:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-27 21:18 [PATCH for-8.0 v2 00/12] tcg patch queue Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 01/12] util: import GTree as QTree Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 02/12] tcg: use QTree instead of GTree Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 03/12] linux-user: Diagnose misaligned -R size Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 04/12] accel/tcg: Pass last not end to page_set_flags Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 05/12] accel/tcg: Pass last not end to page_reset_target_data Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 06/12] accel/tcg: Pass last not end to PAGE_FOR_EACH_TB Richard Henderson
2023-03-27 21:18 ` Richard Henderson [this message]
2023-03-27 21:18 ` [PATCH for-8.0 v2 08/12] accel/tcg: Pass last not end to tb_invalidate_phys_page_range__locked Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 09/12] accel/tcg: Pass last not end to tb_invalidate_phys_range Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 10/12] linux-user: Pass last not end to probe_guest_base Richard Henderson
2023-03-28 13:51 ` Philippe Mathieu-Daudé
2023-03-28 17:47 ` Richard Henderson
2023-03-28 17:53 ` Philippe Mathieu-Daudé
2023-03-27 21:18 ` [PATCH for-8.0 v2 11/12] include/exec: Change reserved_va semantics to last byte Richard Henderson
2023-03-27 21:18 ` [PATCH for-8.0 v2 12/12] linux-user/arm: Take more care allocating commpage Richard Henderson
2023-03-28 18:19 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230327211824.1785547-8-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).