From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, "Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 12/15] linux-user/arm: Take more care allocating commpage
Date: Tue, 28 Mar 2023 15:58:03 -0700 [thread overview]
Message-ID: <20230328225806.2278728-13-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230328225806.2278728-1-richard.henderson@linaro.org>
User setting of -R reserved_va can lead to an assertion
failure in page_set_flags. Sanity check the value of
reserved_va and print an error message instead. Do not
allocate a commpage at all for m-profile cpus.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f1370a7a8b..b96b3e566b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -423,12 +423,32 @@ enum {
static bool init_guest_commpage(void)
{
- abi_ptr commpage = HI_COMMPAGE & -qemu_host_page_size;
- void *want = g2h_untagged(commpage);
- void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
+ ARMCPU *cpu = ARM_CPU(thread_cpu);
+ abi_ptr want = HI_COMMPAGE & TARGET_PAGE_MASK;
+ abi_ptr addr;
- if (addr == MAP_FAILED) {
+ /*
+ * M-profile allocates maximum of 2GB address space, so can never
+ * allocate the commpage. Skip it.
+ */
+ if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
+ return true;
+ }
+
+ /*
+ * If reserved_va does not cover the commpage, we get an assert
+ * in page_set_flags. Produce an intelligent error instead.
+ */
+ if (reserved_va != 0 && want + TARGET_PAGE_SIZE - 1 > reserved_va) {
+ error_report("Allocating guest commpage: -R 0x%" PRIx64 " too small",
+ (uint64_t)reserved_va + 1);
+ exit(EXIT_FAILURE);
+ }
+
+ addr = target_mmap(want, TARGET_PAGE_SIZE, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
+
+ if (addr == -1) {
perror("Allocating guest commpage");
exit(EXIT_FAILURE);
}
@@ -437,15 +457,12 @@ static bool init_guest_commpage(void)
}
/* Set kernel helper versions; rest of page is 0. */
- __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu));
+ put_user_u32(5, 0xffff0ffcu);
- if (mprotect(addr, qemu_host_page_size, PROT_READ)) {
+ if (target_mprotect(addr, qemu_host_page_size, PROT_READ | PROT_EXEC)) {
perror("Protecting guest commpage");
exit(EXIT_FAILURE);
}
-
- page_set_flags(commpage, commpage | ~qemu_host_page_mask,
- PAGE_READ | PAGE_EXEC | PAGE_VALID);
return true;
}
--
2.34.1
next prev parent reply other threads:[~2023-03-28 23:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 22:57 [PULL 00/15] tcg patch queue Richard Henderson
2023-03-28 22:57 ` [PULL 01/15] util: import GTree as QTree Richard Henderson
2023-03-28 22:57 ` [PULL 02/15] tcg: use QTree instead of GTree Richard Henderson
2023-03-28 22:57 ` [PULL 03/15] linux-user: Diagnose misaligned -R size Richard Henderson
2023-03-28 22:57 ` [PULL 04/15] accel/tcg: Pass last not end to page_set_flags Richard Henderson
2023-03-28 22:57 ` [PULL 05/15] accel/tcg: Pass last not end to page_reset_target_data Richard Henderson
2023-03-28 22:57 ` [PULL 06/15] accel/tcg: Pass last not end to PAGE_FOR_EACH_TB Richard Henderson
2023-03-28 22:57 ` [PULL 07/15] accel/tcg: Pass last not end to page_collection_lock Richard Henderson
2023-03-28 22:57 ` [PULL 08/15] accel/tcg: Pass last not end to tb_invalidate_phys_page_range__locked Richard Henderson
2023-03-28 22:58 ` [PULL 09/15] accel/tcg: Pass last not end to tb_invalidate_phys_range Richard Henderson
2023-03-28 22:58 ` [PULL 10/15] linux-user: Pass last not end to probe_guest_base Richard Henderson
2023-03-28 22:58 ` [PULL 11/15] include/exec: Change reserved_va semantics to last byte Richard Henderson
2023-05-11 11:48 ` Laurent Vivier
2023-05-11 13:24 ` Richard Henderson
2023-03-28 22:58 ` Richard Henderson [this message]
2023-03-28 22:58 ` [PULL 13/15] softmmu: Restrict cpu_check_watchpoint / address_matches to TCG accel Richard Henderson
2023-03-28 22:58 ` [PULL 14/15] softmmu/watchpoint: Add missing 'qemu/error-report.h' include Richard Henderson
2023-03-28 22:58 ` [PULL 15/15] softmmu: Restore use of CPU watchpoint for all accelerators Richard Henderson
2023-03-29 13:01 ` [PULL 00/15] tcg patch queue Peter Maydell
2023-03-30 10:37 ` Joel Stanley
2023-03-31 17:20 ` Richard Henderson
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=20230328225806.2278728-13-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=peter.maydell@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).