diff mbox series

[PULL,45/47] linux-user/arm: Do not allocate a commpage at all for M-profile CPUs

Message ID 20230715135317.7219-46-richard.henderson@linaro.org
State Accepted
Commit d713cf4d6c71076513a10528303b3e337b4d5998
Headers show
Series [PULL,01/47] linux-user: Reformat syscall_defs.h | expand

Commit Message

Richard Henderson July 15, 2023, 1:53 p.m. UTC
From: Philippe Mathieu-Daudé <philmd@linaro.org>

Since commit fbd3c4cff6 ("linux-user/arm: Mark the commpage
executable") executing bare-metal (linked with rdimon.specs)
cortex-M code fails as:

  $ qemu-arm -cpu cortex-m3 ~/hello.exe.m3
  qemu-arm: ../../accel/tcg/user-exec.c:492: page_set_flags: Assertion `last <= GUEST_ADDR_MAX' failed.
  Aborted (core dumped)

Commit 4f5c67f8df ("linux-user/arm: Take more care allocating
commpage") already took care of not allocating a commpage for
M-profile CPUs, however it had to be reverted as commit 6cda41daa2.

Re-introduce the M-profile fix from commit 4f5c67f8df.

Fixes: fbd3c4cff6 ("linux-user/arm: Mark the commpage executable")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1755
Reported-by: Christophe Lyon <christophe.lyon@linaro.org>
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230711153408.68389-1-philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

Comments

Michael Tokarev July 16, 2023, 6:13 p.m. UTC | #1
15.07.2023 16:53, Richard Henderson wrote:
> From: Philippe Mathieu-Daudé <philmd@linaro.org>
> 
> Since commit fbd3c4cff6 ("linux-user/arm: Mark the commpage
> executable") executing bare-metal (linked with rdimon.specs)
> cortex-M code fails as:
> 
>    $ qemu-arm -cpu cortex-m3 ~/hello.exe.m3
>    qemu-arm: ../../accel/tcg/user-exec.c:492: page_set_flags: Assertion `last <= GUEST_ADDR_MAX' failed.
>    Aborted (core dumped)
> 
> Commit 4f5c67f8df ("linux-user/arm: Take more care allocating
> commpage") already took care of not allocating a commpage for
> M-profile CPUs, however it had to be reverted as commit 6cda41daa2.
> 
> Re-introduce the M-profile fix from commit 4f5c67f8df.
> 
> Fixes: fbd3c4cff6 ("linux-user/arm: Mark the commpage executable")
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1755

This smells like a 8.0-stable material.  Please let me know if it is no.
Thanks,

/mjt
Richard Henderson July 17, 2023, 2:42 p.m. UTC | #2
On 7/16/23 19:13, Michael Tokarev wrote:
> 15.07.2023 16:53, Richard Henderson wrote:
>> From: Philippe Mathieu-Daudé <philmd@linaro.org>
>>
>> Since commit fbd3c4cff6 ("linux-user/arm: Mark the commpage
>> executable") executing bare-metal (linked with rdimon.specs)
>> cortex-M code fails as:
>>
>>    $ qemu-arm -cpu cortex-m3 ~/hello.exe.m3
>>    qemu-arm: ../../accel/tcg/user-exec.c:492: page_set_flags: Assertion `last <= 
>> GUEST_ADDR_MAX' failed.
>>    Aborted (core dumped)
>>
>> Commit 4f5c67f8df ("linux-user/arm: Take more care allocating
>> commpage") already took care of not allocating a commpage for
>> M-profile CPUs, however it had to be reverted as commit 6cda41daa2.
>>
>> Re-introduce the M-profile fix from commit 4f5c67f8df.
>>
>> Fixes: fbd3c4cff6 ("linux-user/arm: Mark the commpage executable")
>> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1755
> 
> This smells like a 8.0-stable material.  Please let me know if it is no.
> Thanks,

Seems reasonable.


r~
diff mbox series

Patch

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index d3d1352c4e..a26200d9f3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -424,10 +424,23 @@  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 commpage;
+    void *want;
+    void *addr;
+
+    /*
+     * 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;
+    }
+
+    commpage = HI_COMMPAGE & -qemu_host_page_size;
+    want = g2h_untagged(commpage);
+    addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE,
+                MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
 
     if (addr == MAP_FAILED) {
         perror("Allocating guest commpage");