Skip to contentSkip to conversation

MIPS patches for 2022-03-29

GIT PULL Applied Philippe Mathieu-Daudé 2 participants 5 messages Mar 29, 2022 exec and binfmt

lore
Share & tools
lore
#0 lore raw

From: Philippe Mathieu-Daudé <[email protected]>

The following changes since commit 27fc9f365d6f60ff86c2e2be57289bb47a2be882:

Merge tag 'pull-ppc-20220326' of https://github.com/legoater/qemu into staging (2022-03-28 10:16:33 +0100)

are available in the Git repository at:

https://github.com/philmd/qemu.git tags/mips-20220329

for you to fetch changes up to 77d119dd335f910c7f953a265726e3753c69a0bb:

qemu-binfmt-conf.sh: mips: allow nonzero EI_ABIVERSION, distinguish o32 and n32 (2022-03-29 00:51:55 +0200)

----------------------------------------------------------------
MIPS patches queue

- ABI fixes (Xuerui, Andreas)
- Memory API alias fix (David)

----------------------------------------------------------------

Andreas K. Hüttel (1):
qemu-binfmt-conf.sh: mips: allow nonzero EI_ABIVERSION, distinguish

    o32 and n32

David Hildenbrand (1):
memory: Make memory_region_readd_subregion() properly handle mapped
aliases

WANG Xuerui (1):
target/mips: Fix address space range declaration on n32

 scripts/qemu-binfmt-conf.sh | 20 ++++++++++----------
 softmmu/memory.c            |  3 +--
 target/mips/cpu-param.h     |  2 +-
 3 files changed, 12 insertions(+), 13 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

[PULL 3/3] qemu-binfmt-conf.sh: mips: allow nonzero EI_ABIVERSION, distinguish o32 and n32

From: Andreas K. Hüttel <[email protected]>

With the command line flag -mplt and a recent toolchain, ELF binaries generated by gcc can obtain EI_ABIVERSION=1, which makes, e.g., gcc three-stage bootstrap in a mips-unknown-linux-gnu qemu-user chroot fail since the binfmt-misc magic does not match anymore. Also other values are technically possible. qemu executes these binaries just fine, so relax the mask for the EI_ABIVERSION byte at offset 0x08.

In addition, extend magic string to distinguish mips o32 and n32 ABI. This information is given by the EF_MIPS_ABI2 (0x20) bit in the e_flags field of the ELF header (a 4-byte value at offset 0x24 for the here applicable ELFCLASS32).

See-also: ace3d65459

Message-Id: <[email protected]>

---
 scripts/qemu-binfmt-conf.sh | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
scripts/qemu-binfmt-conf.sh +10 -10
index e9bfeb94d3..9cb723f443 100755
@@ -60,28 +60,28 @@ m68k_family=m68k
 
 # FIXME: We could use the other endianness on a MIPS host.
 
-mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20'
 mips_family=mips
 
-mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00'
 mipsel_family=mips
 
-mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20'
+mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20'
 mipsn32_family=mips
 
-mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00'
+mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00'
 mipsn32el_family=mips
 
 mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
 mips64_family=mips
 
 mips64el_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
 mips64el_family=mips
 
 sh4_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00'
Signature · 1 line
2.35.1
#2 lore raw

[PULL 1/3] memory: Make memory_region_readd_subregion() properly handle mapped aliases

In reply to Philippe Mathieu-Daudé

From: David Hildenbrand <[email protected]>

memory_region_readd_subregion() wants to readd a region by first removing it and then readding it. For readding, it doesn't use one of the memory_region_add_*() variants, which is why fail to re-increment the mr->mapped_via_alias counters, resulting in the assert(alias->mapped_via_alias >= 0) in memory_region_del_subregion() triggering the next time we call memory_region_readd_subregion().

Fix it by using memory_region_add_subregion_common() for readding the region.

Fixes 5ead62185d23 ("memory: Make memory_region_is_mapped() succeed when mapped via an alias")
Cc Paolo Bonzini <[email protected]>
Cc Peter Xu <[email protected]>
Cc "Philippe Mathieu-Daudé" <[email protected]>

Message-Id: <[email protected]>

---
 softmmu/memory.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
softmmu/memory.c +1 -2
index 8060c6de78..bfa5d5178c 100644
@@ -2626,8 +2626,7 @@ static void memory_region_readd_subregion(MemoryRegion *mr)
         memory_region_transaction_begin();
         memory_region_ref(mr);
         memory_region_del_subregion(container, mr);
-        mr->container = container;
-        memory_region_update_container_subregions(mr);
+        memory_region_add_subregion_common(container, mr->addr, mr);
         memory_region_unref(mr);
         memory_region_transaction_commit();
     }
Signature · 1 line
2.35.1
#3 lore raw

[PULL 2/3] target/mips: Fix address space range declaration on n32

In reply to Philippe Mathieu-Daudé

From: WANG Xuerui <[email protected]>

This bug is probably lurking there for so long, I cannot even git-blame my way to the commit first introducing it.

Anyway, because n32 is also TARGET_MIPS64, the address space range cannot be determined by looking at TARGET_MIPS64 alone. Fix this by only declaring 48-bit address spaces for n64, or the n32 user emulation will happily hand out memory ranges beyond the 31-bit limit and crash.

Confirmed to make the minimal reproducing example in the linked issue behave.

Message-Id: <[email protected]>

---
 target/mips/cpu-param.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/mips/cpu-param.h +1 -1
index 9c4a6ea45e..1aebd01df9 100644
@@ -12,7 +12,7 @@
 #else
 # define TARGET_LONG_BITS 32
 #endif
-#ifdef TARGET_MIPS64
+#ifdef TARGET_ABI_MIPSN64
 #define TARGET_PHYS_ADDR_SPACE_BITS 48
 #define TARGET_VIRT_ADDR_SPACE_BITS 48
 #else
Signature · 1 line
2.35.1
#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 25 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

The following changes since commit 27fc9f365d6f60ff86c2e2be57289bb47a2be882:

Merge tag 'pull-ppc-20220326' of https://github.com/legoater/qemu into staging (2022-03-28 10:16:33 +0100)

are available in the Git repository at:

https://github.com/philmd/qemu.git tags/mips-20220329

for you to fetch changes up to 77d119dd335f910c7f953a265726e3753c69a0bb:

qemu-binfmt-conf.sh: mips: allow nonzero EI_ABIVERSION, distinguish o32 and n32 (2022-03-29 00:51:55 +0200)

----------------------------------------------------------------
MIPS patches queue

- ABI fixes (Xuerui, Andreas)
- Memory API alias fix (David)

----------------------------------------------------------------

Andreas K. Hüttel (1):
qemu-binfmt-conf.sh: mips: allow nonzero EI_ABIVERSION, distinguish

Quoted 9 lines
    o32 and n32

David Hildenbrand (1):
memory: Make memory_region_readd_subregion() properly handle mapped
aliases

WANG Xuerui (1):
target/mips: Fix address space range declaration on n32

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/7.0
for any user-visible changes.

-- PMM