snmalloc icon indicating copy to clipboard operation
snmalloc copied to clipboard

Loongarch Support

Open SchrodingerZhu opened this issue 3 years ago • 7 comments

QEMU 7.1 will begin loongarch support: https://wiki.qemu.org/ChangeLog/7.1#LoongArch.

Currently, everything works but all check variants:

qemu-loongarch64 -strace /home/schrodinger/Downloads/loongarch64-clfs-6.0-cross-tools-gcc_and_clang-full/cross-tools/target/usr/lib64/ld-linux-loongarch-lp64d.so.1 --library-path /home/schrodinger/Downloads/loongarch64-clfs-6.0-cross-tools-gcc_and_clang-full/cross-tools/target/usr/lib64 ./func-thread_alloc_external-check

image

SchrodingerZhu avatar Aug 22 '22 15:08 SchrodingerZhu

So I tried

diff --git a/src/snmalloc/pal/pal_posix.h b/src/snmalloc/pal/pal_posix.h
index 8ad7995..22314db 100644
--- a/src/snmalloc/pal/pal_posix.h
+++ b/src/snmalloc/pal/pal_posix.h
@@ -233,7 +233,10 @@ namespace snmalloc
         is_aligned_block<OS::page_size>(p, size) || (zero_mem == NoZero));
 
       if constexpr (PalEnforceAccess)
-        mprotect(p, size, PROT_READ | PROT_WRITE);
+      {
+        int val = mprotect(p, size, PROT_READ | PROT_WRITE);
+        SNMALLOC_ASSERT_MSG(val == 0, "mprotect is expected to succeed, address: {}, page size: {}", p, ::sysconf(_SC_PAGESIZE));
+      }
       else
       {
         UNUSED(p, size);

And it reported

assert fail: val == 0 in /home/schrodinger/Downloads/snmalloc/src/snmalloc/backend_helpers/../mem/../ds/../pal/pal_posix.h on 238 mprotect is expected to succeed, address: 0x5c24cdd000, page size: 16384

Seems that it is a problem of page size detection.

SchrodingerZhu avatar Aug 22 '22 21:08 SchrodingerZhu

On PowerPC, qemu user mode defaults to 4 KiB pages, which confuses snmalloc, which expects 64 KiB pages. We have some ugly hacks to work around this in CI. You might need to explicitly tell qemu to use 16 KiB pages for LoongArch.

davidchisnall avatar Aug 23 '22 10:08 davidchisnall

any specific guide on adding qemu pipelines?

SchrodingerZhu avatar Aug 23 '22 23:08 SchrodingerZhu

image

@mjp41 Is 7.1.0 available in our pipeline?

SchrodingerZhu avatar Sep 06 '22 15:09 SchrodingerZhu

image

@mjp41 Is 7.1.0 available in our pipeline?

Not convinced. You can try, maybe we can build a docker image with it in?

mjp41 avatar Sep 06 '22 15:09 mjp41

Last time we used Docker, it added a lot to our end-to-end test times. Is there an unofficial apt repo that has newer builds of qemu that we can use?

davidchisnall avatar Sep 07 '22 08:09 davidchisnall

help wanted

SchrodingerZhu avatar Oct 05 '22 01:10 SchrodingerZhu