Skip to contentSkip to conversation

Add aarch64_be-linux-user target

PATCH Superseded Michael Weiser 4 participants 19 messages Dec 19, 2017 – Dec 21, 2017 exec and binfmt

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/5 linux-user: Add support for big-endian aarch64

In reply to Michael Weiser

Enable big-endian mode for data accesses on aarch64 for big-endian linux user mode. Activate it for all execution levels as documented by ARM:
Set the SCTLR EE bit for ELs 1 through 3. Additionally set bit E0E in EL1 to enable it in EL0 as well.

---
 linux-user/main.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/main.c +6 -0
index 2fd2a143ed..7ea863260d 100644
@@ -4611,6 +4611,12 @@ int main(int argc, char **argv, char **envp)
         }
         env->pc = regs->pc;
         env->xregs[31] = regs->sp;
+#ifdef TARGET_WORDS_BIGENDIAN
+        env->cp15.sctlr_el[1] |= SCTLR_E0E;
+        for (i = 1; i < 4; ++i) {
+            env->cp15.sctlr_el[i] |= SCTLR_EE;
+        }
+#endif
     }
 #elif defined(TARGET_ARM)
     {
Signature · 1 line
2.15.1
#7 lore raw

PATCH v2 3/5 linux-user: Fix endianess of aarch64 signal trampoline

In reply to Michael Weiser

Since for aarch64 the signal trampoline is synthesized directly into the signal frame we need to make sure the instructions end up little-endian. Otherwise the wrong endianness will cause a SIGILL upon return from the signal handler on big-endian targets.

---
 linux-user/signal.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
linux-user/signal.c +7 -3
index dae14d4a89..81b7fbeb1e 100644
@@ -1599,9 +1599,13 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
     if (ka->sa_flags & TARGET_SA_RESTORER) {
         return_addr = ka->sa_restorer;
     } else {
-        /* mov x8,#__NR_rt_sigreturn; svc #0 */
-        __put_user(0xd2801168, &frame->tramp[0]);
-        __put_user(0xd4000001, &frame->tramp[1]);
+        /*
+         * mov x8,#__NR_rt_sigreturn; svc #0
+         * Since these are instructions they need to be put as little-endian
+         * regardless of target default or current CPU endianness.
+         */
+        __put_user_e(0xd2801168, &frame->tramp[0], le);
+        __put_user_e(0xd4000001, &frame->tramp[1], le);
         return_addr = frame_addr + offsetof(struct target_rt_sigframe, tramp);
     }
     env->xregs[0] = usig;
Signature · 1 line
2.15.1
#2 lore raw

PATCH v2 2/5 linux-user: Add separate aarch64_be uname

In reply to Michael Weiser

Make big-endian aarch64 systems identify as aarch64_be as expected by big-endian userland and toolchains.

---
 linux-user/aarch64/target_syscall.h | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/aarch64/target_syscall.h +4 -0
index 1b62953eeb..604ab99b14 100644
@@ -8,7 +8,11 @@ struct target_pt_regs {
     uint64_t        pstate;
 };
 
+#if defined(TARGET_WORDS_BIGENDIAN)
+#define UNAME_MACHINE "aarch64_be"
+#else
 #define UNAME_MACHINE "aarch64"
+#endif
 #define UNAME_MINIMUM_RELEASE "3.8.0"
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ       2048
Signature · 1 line
2.15.1
#0 lore raw

v2 cover Add aarch64_be-linux-user target

Hello,

below patches add support for big-endian aarch64 to linux-user. Almost everything is already in place. The patches just set up the CPU flags as required for big-endianess, add a distinction in uname and make sure the instructions for the signal trampoline end up in memory little-endian. Finally, configure is extended to allow building of a aarch64_be-linux-user target and scripts/qemu-binfmt-conf.sh to include the binfmt magic for aarch64_be ELF files.

With this I am able to run individual aarch64_be binaries as well as chroot into a full-blown aarch64_be userland using binfmt_misc, running and compiling things (Gentoo crossdev/native).

v2:
- add binfmt magic to qemu-binfmt-conf.sh
- fix style problems (tab indenting)

Thanks,
Michael

Michael Weiser (5):
linux-user: Add support for big-endian aarch64
linux-user: Add separate aarch64_be uname
linux-user: Fix endianess of aarch64 signal trampoline
configure: Add aarch64_be-linux-user target
linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh

 configure                                 |  9 +++++----
 default-configs/aarch64_be-linux-user.mak |  1 +
 linux-user/aarch64/target_syscall.h       |  4 ++++
 linux-user/main.c                         |  6 ++++++
 linux-user/signal.c                       | 10 +++++++---
 scripts/qemu-binfmt-conf.sh               |  6 +++++-
 6 files changed, 28 insertions(+), 8 deletions(-)
 create mode 100644 default-configs/aarch64_be-linux-user.mak
Signature · 1 line
2.15.1
#11 lore raw

PATCH v2 5/5 linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh

As we now have a linux-user aarch64_be target, we can add it to the list of supported targets in qemu-binfmt-conf.sh

---
 scripts/qemu-binfmt-conf.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/qemu-binfmt-conf.sh +5 -1
index 8afc3eb5bb..d69953525c 100755
@@ -4,7 +4,7 @@
 
 qemu_target_list="i386 i486 alpha arm sparc32plus ppc ppc64 ppc64le m68k \
 mips mipsel mipsn32 mipsn32el mips64 mips64el \
-sh4 sh4eb s390x aarch64 hppa"
+sh4 sh4eb s390x aarch64 aarch64_be hppa"
 
 i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
 i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
@@ -92,6 +92,10 @@ aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x
 aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
 aarch64_family=arm
 
+aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
+aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+aarch64_be_family=arm
+
 hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f'
 hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
 hppa_family=hppa
Signature · 1 line
2.15.1
#8 lore raw

PATCH v2 4/5 configure: Add aarch64_be-linux-user target

In reply to Michael Weiser

Add target aarch64_be-linux-user. This allows a qemu-aarch64_be binary to be built that will run big-endian aarch64 binaries.

---
 configure                                 | 9 +++++----
 default-configs/aarch64_be-linux-user.mak | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
 create mode 100644 default-configs/aarch64_be-linux-user.mak
configure +5 -4
index 9c8aa5a98b..03d95340d8 100755
@@ -657,7 +657,7 @@ case "$cpu" in
     cpu="arm"
     supported_cpu="yes"
   ;;
-  aarch64)
+  aarch64|aarch64_be)
     cpu="aarch64"
     supported_cpu="yes"
   ;;
@@ -6345,7 +6345,7 @@ if test "$linux" = "yes" ; then
   s390x)
     linux_arch=s390
     ;;
-  aarch64)
+  aarch64|aarch64_be)
     linux_arch=arm64
     ;;
   mips64)
@@ -6369,7 +6369,7 @@ target_name=$(echo $target | cut -d '-' -f 1)
 target_bigendian="no"
 
 case "$target_name" in
-  armeb|hppa|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or1k|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
+  armeb|aarch64_be|hppa|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or1k|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
   target_bigendian=yes
   ;;
 esac
@@ -6424,7 +6424,8 @@ case "$target_name" in
     mttcg="yes"
     gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
   ;;
-  aarch64)
+  aarch64|aarch64_be)
+    TARGET_ARCH=aarch64
     TARGET_BASE_ARCH=arm
     bflt="yes"
     mttcg="yes"
default-configs/aarch64_be-linux-user.mak new file +1 -0
new file mode 100644
index 0000000000..a69d9d2e41
@@ -0,0 +1 @@
+# Default configuration for aarch64_be-linux-user
Signature · 1 line
2.15.1
#12 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh

In reply to Michael Weiser

Le 19/12/2017 à 21:16, Michael Weiser a écrit :

Quoted 22 lines

As we now have a linux-user aarch64_be target, we can add it to the list of supported targets in qemu-binfmt-conf.sh

---
 scripts/qemu-binfmt-conf.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/qemu-binfmt-conf.sh +1 -1
index 8afc3eb5bb..d69953525c 100755
@@ -4,7 +4,7 @@
 
 qemu_target_list="i386 i486 alpha arm sparc32plus ppc ppc64 ppc64le m68k \
 mips mipsel mipsn32 mipsn32el mips64 mips64el \
-sh4 sh4eb s390x aarch64 hppa"
+sh4 sh4eb s390x aarch64 aarch64_be hppa"
 
 i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
 i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'

scripts/qemu-binfmt-conf.sh aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x · line 97

Quoted 6 lines
scripts/qemu-binfmt-conf.sh +3 -0
@@ -92,6 +92,10 @@ aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x
 aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
 aarch64_family=arm
 
+aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
+aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+aarch64_be_family=arm

You need a different family, something like "armbe", to let qemu_set_binfmts() registers aarch64_be on aarch64 and vice-versa.

The principle is binaries of a given family can be executed natively on the host of the same family, so we don't want to register a binfmt handler. Is that the case between aarch64 and arch64_be?

Thanks,
Laurent

#9 lore raw

Re: [Qemu-devel] [PATCH v2 4/5] configure: Add aarch64_be-linux-user target

In reply to Michael Weiser

Le 19/12/2017 à 21:16, Michael Weiser a écrit :

Quoted 15 lines

Add target aarch64_be-linux-user. This allows a qemu-aarch64_be binary to be built that will run big-endian aarch64 binaries.

---
 configure                                 | 9 +++++----
 default-configs/aarch64_be-linux-user.mak | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
 create mode 100644 default-configs/aarch64_be-linux-user.mak
configure +0 -0
index 9c8aa5a98b..03d95340d8 100755

configure case "$cpu" in · line 662

Quoted 7 lines
configure +1 -1
@@ -657,7 +657,7 @@ case "$cpu" in
     cpu="arm"
     supported_cpu="yes"
   ;;
-  aarch64)
+  aarch64|aarch64_be)
     cpu="aarch64"
     supported_cpu="yes"

This switch is for host CPU. Do you want to add aarch64_be as a supported host architecture?

configure if test "$linux" = "yes" ; then · line 6349

Quoted 8 lines
configure +1 -1
   ;;
@@ -6345,7 +6345,7 @@ if test "$linux" = "yes" ; then
   s390x)
     linux_arch=s390
     ;;
-  aarch64)
+  aarch64|aarch64_be)
     linux_arch=arm64

This is also for the host.

Thanks,
Laurent

#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/5] linux-user: Add separate aarch64_be uname

In reply to Michael Weiser

Le 19/12/2017 à 21:16, Michael Weiser a écrit :

Quoted 13 lines

Make big-endian aarch64 systems identify as aarch64_be as expected by big-endian userland and toolchains.

---
 linux-user/aarch64/target_syscall.h | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/aarch64/target_syscall.h +0 -0
index 1b62953eeb..604ab99b14 100644

linux-user/aarch64/target_syscall.h struct target_pt_regs { · line 16

Quoted 9 lines
linux-user/aarch64/target_syscall.h +4 -0
@@ -8,7 +8,11 @@ struct target_pt_regs {
     uint64_t        pstate;
 };
 
+#if defined(TARGET_WORDS_BIGENDIAN)
+#define UNAME_MACHINE "aarch64_be"
+#else
 #define UNAME_MACHINE "aarch64"
+#endif
 #define UNAME_MINIMUM_RELEASE "3.8.0"

For aarch64_be, I think the minimum release should be 4.9.0 (see kernel commit cfa88c79462d "arm64: Set UTS_MACHINE in the Makefile")

Thanks,
Laurent

#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/5] linux-user: Add separate aarch64_be uname

Quoted 17 lines · Laurent Vivier
Quoted 16 lines · Michael Weiser

Make big-endian aarch64 systems identify as aarch64_be as expected by big-endian userland and toolchains.

---
 linux-user/aarch64/target_syscall.h | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/aarch64/target_syscall.h +0 -0
index 1b62953eeb..604ab99b14 100644
@@ -8,7 +8,11 @@ struct target_pt_regs {
     uint64_t        pstate;
 };
 
Quoted 9 lines

linux-user/aarch64/target_syscall.h struct target_pt_regs { · line 16

Quoted 6 lines
linux-user/aarch64/target_syscall.h +4 -0
+#if defined(TARGET_WORDS_BIGENDIAN)
+#define UNAME_MACHINE "aarch64_be"
+#else
 #define UNAME_MACHINE "aarch64"
+#endif
 #define UNAME_MINIMUM_RELEASE "3.8.0"

For aarch64_be, I think the minimum release should be 4.9.0 (see kernel commit cfa88c79462d "arm64: Set UTS_MACHINE in the Makefile")

Isn't the thing that defines what we set the minimum-release to glibc, not the kernel? That is, the reason we lie to the guest about the kernel version for some architectures is because the glibc for those archs insists on a minimum kernel version which the host may not have. Unless aarch64_be glibc insists on kernel 4.9.0 there's no need to tell the guest that.

thanks
-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH v2 2/5] linux-user: Add separate aarch64_be uname

Le 20/12/2017 à 16:36, Peter Maydell a écrit :

Quoted 28 lines · Laurent Vivier
Quoted 17 lines · Michael Weiser
Quoted 16 lines

Make big-endian aarch64 systems identify as aarch64_be as expected by big-endian userland and toolchains.

---
 linux-user/aarch64/target_syscall.h | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/aarch64/target_syscall.h +0 -0
index 1b62953eeb..604ab99b14 100644
@@ -8,7 +8,11 @@ struct target_pt_regs {
     uint64_t        pstate;
 };
 
Quoted 9 lines

linux-user/aarch64/target_syscall.h struct target_pt_regs { · line 16

Quoted 6 lines
linux-user/aarch64/target_syscall.h +4 -0
+#if defined(TARGET_WORDS_BIGENDIAN)
+#define UNAME_MACHINE "aarch64_be"
+#else
 #define UNAME_MACHINE "aarch64"
+#endif
 #define UNAME_MINIMUM_RELEASE "3.8.0"

For aarch64_be, I think the minimum release should be 4.9.0 (see kernel commit cfa88c79462d "arm64: Set UTS_MACHINE in the Makefile")

Quoted 6 lines

Isn't the thing that defines what we set the minimum-release to glibc, not the kernel? That is, the reason we lie to the guest about the kernel version for some architectures is because the glibc for those archs insists on a minimum kernel version which the host may not have. Unless aarch64_be glibc insists on kernel 4.9.0 there's no need to tell the guest that.

As you are the author of the original commit (4a24a75810 "linux-user:
Allow targets to specify a minimum uname release"), I guess you're right. So ignore my comment...

Thanks,
Laurent

#14 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh

In reply to Michael Weiser

Le 20/12/2017 à 16:37, Michael Weiser a écrit :

Quoted 21 lines

Hi Laurent,

Quoted 10 lines · Laurent Vivier

Review

Quoted 3 lines
(quoted diff) +3 -0
+aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
+aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+aarch64_be_family=arm

You need a different family, something like "armbe", to let qemu_set_binfmts() registers aarch64_be on aarch64 and vice-versa.

The principle is binaries of a given family can be executed natively on the host of the same family, so we don't want to register a binfmt handler. Is that the case between aarch64 and arch64_be?

Right, while the CPU certainly is capable of switching endianess on the fly I'm not sure if there is any multilib/multiarch userland setup and kernel interface that would support mixed little/big-endianess of arm or aarch64 binaries. Even if, it would likely need further detection in the script to make sure it's there.

Quoted 4 lines

Based on that I suspect that qemu-binfmt-conf.sh's current assignment of armeb and aarch64 into the arm CPU family is over-optimistic as well. So I'd suggest treating all of arm, armeb, aarch64 and aarch64_be as separate families.

So it's not like on intel/AMD where we can execute a 32bit binary on a 64bit kernel?

Quoted 3 lines

Incidentally: I noticed that armeb is missing from qemu_target_list. Is that intentional?

no. please fix it :)

Quoted 40 lines

How about the following changes, maybe split into two patches "add armeb" and "separate ARM CPU families"?

scripts/qemu-binfmt-conf.sh +4 -4
index d69953525c..69ebfe7a6e 100755
@@ -2,7 +2,7 @@
 # enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390/HPPA
 # program execution by the kernel
 
-qemu_target_list="i386 i486 alpha arm sparc32plus ppc ppc64 ppc64le m68k \
+qemu_target_list="i386 i486 alpha arm armeb sparc32plus ppc ppc64 ppc64le m68k \
 mips mipsel mipsn32 mipsn32el mips64 mips64el \
 sh4 sh4eb s390x aarch64 aarch64_be hppa"
 
@@ -24,7 +24,7 @@ arm_family=arm
 
 armeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28'
 armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-armeb_family=arm
+armeb_family=armeb
 
 sparc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'
 sparc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
@@ -90,11 +90,11 @@ s390x_family=s390x
 
 aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00'
 aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-aarch64_family=arm
+aarch64_family=aarch64
 
 aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
 aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-aarch64_be_family=arm
+aarch64_be_family=aarch64_be
 
 hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f'
 hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
Quoted 2 lines

Okay?

It looks good to me.

Thanks,
Laurent

#13 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh

In reply to Laurent Vivier

Hi Laurent,

Quoted 10 lines · Laurent Vivier

Review

Quoted 3 lines
(quoted diff) +3 -0
+aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
+aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+aarch64_be_family=arm

You need a different family, something like "armbe", to let qemu_set_binfmts() registers aarch64_be on aarch64 and vice-versa.

The principle is binaries of a given family can be executed natively on the host of the same family, so we don't want to register a binfmt handler. Is that the case between aarch64 and arch64_be?

Right, while the CPU certainly is capable of switching endianess on the fly I'm not sure if there is any multilib/multiarch userland setup and kernel interface that would support mixed little/big-endianess of arm or aarch64 binaries. Even if, it would likely need further detection in the script to make sure it's there.

Based on that I suspect that qemu-binfmt-conf.sh's current assignment of armeb and aarch64 into the arm CPU family is over-optimistic as well. So I'd suggest treating all of arm, armeb, aarch64 and aarch64_be as separate families.

Incidentally: I noticed that armeb is missing from qemu_target_list. Is that intentional?

How about the following changes, maybe split into two patches "add armeb" and "separate ARM CPU families"?

scripts/qemu-binfmt-conf.sh +4 -4
index d69953525c..69ebfe7a6e 100755
@@ -2,7 +2,7 @@
 # enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390/HPPA
 # program execution by the kernel
 
-qemu_target_list="i386 i486 alpha arm sparc32plus ppc ppc64 ppc64le m68k \
+qemu_target_list="i386 i486 alpha arm armeb sparc32plus ppc ppc64 ppc64le m68k \
 mips mipsel mipsn32 mipsn32el mips64 mips64el \
 sh4 sh4eb s390x aarch64 aarch64_be hppa"
 
@@ -24,7 +24,7 @@ arm_family=arm
 
 armeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28'
 armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-armeb_family=arm
+armeb_family=armeb
 
 sparc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'
 sparc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
@@ -90,11 +90,11 @@ s390x_family=s390x
 
 aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00'
 aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-aarch64_family=arm
+aarch64_family=aarch64
 
 aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
 aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-aarch64_be_family=arm
+aarch64_be_family=aarch64_be
 
 hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f'
 hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'

Okay?

Signature · 1 line
bye, Michael
#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/5] linux-user: Add separate aarch64_be uname

In reply to Peter Maydell

Hi Peter,

Quoted 11 lines · Peter Maydell
Quoted 4 lines
Quoted 1 line

#define UNAME_MINIMUM_RELEASE "3.8.0"

For aarch64_be, I think the minimum release should be 4.9.0 (see kernel commit cfa88c79462d "arm64: Set UTS_MACHINE in the Makefile")

Isn't the thing that defines what we set the minimum-release to glibc, not the kernel? That is, the reason we lie to the guest about the kernel version for some architectures is because the glibc for those archs insists on a minimum kernel version which the host may not have. Unless aarch64_be glibc insists on kernel 4.9.0 there's no need to tell the guest that.

I can confirm that cross-compiled glibc runs fine with the current value. Also, a native compile of glibc inside an qemu-aarch64_be binfmt chroot configured without problem and currently churns along compiling.

My Gentoo setup calls configure with --enable-kernel=3.2.0 and that says about this:

checking installed Linux kernel header files... 3.2.0 or later
configure: WARNING: minimum kernel version reset to 3.7.0 checking for kernel header at least 3.7.0... ok

So it seems your memory is right.

Signature · 2 lines
Bye,
Michael
#15 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh

In reply to Laurent Vivier

Hi Laurent,

Quoted 6 lines · Laurent Vivier
Quoted 4 lines

Based on that I suspect that qemu-binfmt-conf.sh's current assignment of armeb and aarch64 into the arm CPU family is over-optimistic as well. So I'd suggest treating all of arm, armeb, aarch64 and aarch64_be as separate families.

So it's not like on intel/AMD where we can execute a 32bit binary on a 64bit kernel?

An aarch64 CPU is capable of running arm (i.e. aarch32) code. And I think this is supported as a multilib setup on Linux. But not in mixed endianess as far as I know.

Looking at the code again, I'm confused now: Wouldn't the current logic treat an actual i386 machine as capable of running x86_64 binaries natively and omit registering the handler for x86_64?

Quoted 3 lines
Quoted 2 lines

Incidentally: I noticed that armeb is missing from qemu_target_list. Is that intentional?

no. please fix it :)

Will do.

Quoted 2 lines
Quoted 1 line

Okay?

It looks good to me.

Based on the above I now lean towards the following assignments:

arm_family=arm
[...]
-armeb_family=arm
+armeb_family=armeb
[...]
aarch64_family=arm
[...]
-aarch64_be_family=arm
+aarch64_be_family=armeb

This would be in line with what you recommended, how i386/x86_64 is treated and reflects the principal platform capabilities.

Signature · 2 lines
Bye,
Michael
#16 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh

Le 20/12/2017 à 17:15, Michael Weiser a écrit :

Quoted 11 lines

Hi Laurent,

Quoted 6 lines · Laurent Vivier
Quoted 4 lines

Based on that I suspect that qemu-binfmt-conf.sh's current assignment of armeb and aarch64 into the arm CPU family is over-optimistic as well. So I'd suggest treating all of arm, armeb, aarch64 and aarch64_be as separate families.

So it's not like on intel/AMD where we can execute a 32bit binary on a 64bit kernel?

Quoted 7 lines

An aarch64 CPU is capable of running arm (i.e. aarch32) code. And I think this is supported as a multilib setup on Linux. But not in mixed endianess as far as I know.

Looking at the code again, I'm confused now: Wouldn't the current logic treat an actual i386 machine as capable of running x86_64 binaries natively and omit registering the handler for x86_64?

It can be read like that, but actually 32bit machine cannot emulate 64bit architecture, so we don't register it.

So for the same family:

- on 64bit machine, we don't register the interpreter because the 32bit binary can be executed natively,

- on 32bit machine, we don't register the interpreter because the interpreter cannot work,

Thanks,
Laurent

#10 lore raw

Re: [Qemu-devel] [PATCH v2 4/5] configure: Add aarch64_be-linux-user target

In reply to Laurent Vivier

Hello Laurent,

Quoted 6 lines · Laurent Vivier
Quoted 6 lines
configure +0 -0
index 9c8aa5a98b..03d95340d8 100755
@@ -657,7 +657,7 @@ case "$cpu" in
     cpu="arm"
Quoted 8 lines

configure case "$cpu" in · line 662

Quoted 6 lines
configure +1 -1
     supported_cpu="yes"
   ;;
-  aarch64)
+  aarch64|aarch64_be)
     cpu="aarch64"
     supported_cpu="yes"

This switch is for host CPU. Do you want to add aarch64_be as a supported host architecture?

No, that's a project for another day, I guess and certainly doesn't belong into that patch. Dropped.

Quoted 9 lines

configure if test "$linux" = "yes" ; then · line 6349

Quoted 8 lines
configure +1 -1
   ;;
@@ -6345,7 +6345,7 @@ if test "$linux" = "yes" ; then
   s390x)
     linux_arch=s390
     ;;
-  aarch64)
+  aarch64|aarch64_be)
     linux_arch=arm64

This is also for the host.

Same here.

Signature · 2 lines
Thanks,
Michael
#17 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh

In reply to Laurent Vivier

Hi Laurent,

Quoted 7 lines · Laurent Vivier
Quoted 7 lines
Quoted 2 lines

So it's not like on intel/AMD where we can execute a 32bit binary on a 64bit kernel?

An aarch64 CPU is capable of running arm (i.e. aarch32) code. And I think this is supported as a multilib setup on Linux. But not in mixed endianess as far as I know.

Quoted 5 lines
Quoted 3 lines

Looking at the code again, I'm confused now: Wouldn't the current logic treat an actual i386 machine as capable of running x86_64 binaries natively and omit registering the handler for x86_64?

- on 32bit machine, we don't register the interpreter because the interpreter cannot work,

Okay, makes sense.

Meanwhile I verified that a little-endian arm kernel indeed refuses to run a statically linked big-endian arm binary and vice-versa with ENOEXEC ("Exec format error").

Looking at fs/binfmt_elf.c of the kernel, I understand that the kernel makes no attempt to adjust for binary images of differing endianness. Because the e_type ELF header field is byte-swapped in the big-endian arm ELF binary, the kernel will see an invalid executable type and return ENOEXEC.

Based on this I'm reasonably sure that a mixed little-/big-endian userland is not currently possible on Linux. So I've gone with the arm/armeb family split.

I'll push out a new version of the patch series with all the discussed changes in a minute.

Signature · 2 lines
Bye,
Michael
#18 lore raw
In reply to Michael Weiser
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v2 0/5] Add aarch64_be-linux-user target

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
1408be599f linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh 246c0913be configure: Add aarch64_be-linux-user target e845d35c97 linux-user: Fix endianess of aarch64 signal trampoline c9dc348343 linux-user: Add separate aarch64_be uname 138f48ac61 linux-user: Add support for big-endian aarch64

=== OUTPUT BEGIN ===
Checking PATCH 1/5: linux-user: Add support for big-endian aarch64... Checking PATCH 2/5: linux-user: Add separate aarch64_be uname...
Checking PATCH 3/5: linux-user: Fix endianess of aarch64 signal trampoline... Checking PATCH 4/5: configure: Add aarch64_be-linux-user target...
Checking PATCH 5/5: linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh...
WARNING: line over 80 characters
#30: FILE: scripts/qemu-binfmt-conf.sh:95:
+aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'

ERROR: line over 90 characters
#31: FILE: scripts/qemu-binfmt-conf.sh:96:
+aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'

total: 1 errors, 1 warnings, 18 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]