All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] nios2: Enable cross compile and fix signals
@ 2021-10-01 15:33 Richard Henderson
  2021-10-01 15:33 ` [PATCH 1/9] tests/docker: Add debian-nios2-cross image Richard Henderson
                   ` (11 more replies)
  0 siblings, 12 replies; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

Patches 2, 3, and 5 have appeared before.

The patch for the kuser page has been updated to use the commpage
infrastructure, which needed expanding just a bit to handle the
page being at the beginning of the address space.

Getting the toolchain built allowed the code to actually be tested,
which showed up a few more problems in the testsuite.

I have already pushed the debian-nios2-cross image to gitlab, much
like we did for hexagon and its locally built toolchain.


r~


Richard Henderson (9):
  tests/docker: Add debian-nios2-cross image
  linux-user/nios2: Properly emulate EXCP_TRAP
  linux-user/nios2: Fixes for signal frame setup
  linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE
  linux-user/nios2: Map a real kuser page
  linux-user/nios2: Fix EA vs PC confusion
  linux-user/nios2: Fix sigmask in setup_rt_frame
  linux-user/nios2: Use set_sigmask in do_rt_sigreturn
  tests/tcg: Enable container_cross_cc for nios2

 target/nios2/cpu.h                            |  2 +-
 linux-user/elfload.c                          | 66 +++++++++++--
 linux-user/nios2/cpu_loop.c                   | 93 +++++++++---------
 linux-user/nios2/signal.c                     | 56 +++++------
 linux-user/signal.c                           |  2 -
 target/nios2/translate.c                      | 26 +++--
 tests/docker/Makefile.include                 | 19 ++++
 .../dockerfiles/debian-nios2-cross.docker     | 34 +++++++
 .../build-toolchain.sh                        | 97 +++++++++++++++++++
 tests/tcg/configure.sh                        |  6 ++
 10 files changed, 302 insertions(+), 99 deletions(-)
 create mode 100644 tests/docker/dockerfiles/debian-nios2-cross.docker
 create mode 100755 tests/docker/dockerfiles/debian-nios2-cross.docker.d/build-toolchain.sh

-- 
2.25.1



^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 1/9] tests/docker: Add debian-nios2-cross image
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-12 17:03   ` Alex Bennée
  2021-10-01 15:33 ` [PATCH 1/2] tests/docker: Remove fedora-i386-cross from DOCKER_PARTIAL_IMAGES Richard Henderson
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

Build the entire cross tool chain from source.
For this reason, default to caching.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/docker/Makefile.include                 | 19 ++++
 .../dockerfiles/debian-nios2-cross.docker     | 34 +++++++
 .../build-toolchain.sh                        | 97 +++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 tests/docker/dockerfiles/debian-nios2-cross.docker
 create mode 100755 tests/docker/dockerfiles/debian-nios2-cross.docker.d/build-toolchain.sh

diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index ff5d732889..2ccd93caa4 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -168,10 +168,28 @@ docker-image-debian-hexagon-cross: $(DOCKER_FILES_DIR)/debian-hexagon-cross.dock
 				qemu/debian-hexagon-cross --add-current-user,		\
 			"PREPARE", "debian-hexagon-cross"))
 
+docker-image-debian-nios2-cross: $(DOCKER_FILES_DIR)/debian-nios2-cross.docker
+	$(if $(NOCACHE), 								\
+		$(call quiet-command,							\
+			$(DOCKER_SCRIPT) build -t qemu/debian-nios2-cross -f $< 	\
+			$(if $V,,--quiet) --no-cache 					\
+			--registry $(DOCKER_REGISTRY) --extra-files			\
+			$(DOCKER_FILES_DIR)/debian-nios2-cross.docker.d/build-toolchain.sh, \
+			"BUILD", "debian-nios2-cross"),				        \
+		$(call quiet-command,							\
+			$(DOCKER_SCRIPT) fetch $(if $V,,--quiet)			\
+				qemu/debian-nios2-cross $(DOCKER_REGISTRY),		\
+			"FETCH", "debian-nios2-cross")				        \
+		$(call quiet-command,							\
+			$(DOCKER_SCRIPT) update $(if $V,,--quiet) 			\
+				qemu/debian-nios2-cross --add-current-user,		\
+			"PREPARE", "debian-nios2-cross"))
+
 # Specialist build images, sometimes very limited tools
 docker-image-debian-tricore-cross: docker-image-debian10
 docker-image-debian-all-test-cross: docker-image-debian10
 docker-image-debian-arm64-test-cross: docker-image-debian11
+docker-image-debian-nios2-cross: docker-image-debian10
 docker-image-debian-powerpc-test-cross: docker-image-debian11
 
 # These images may be good enough for building tests but not for test builds
@@ -180,6 +198,7 @@ DOCKER_PARTIAL_IMAGES += debian-arm64-test-cross
 DOCKER_PARTIAL_IMAGES += debian-powerpc-test-cross
 DOCKER_PARTIAL_IMAGES += debian-hppa-cross
 DOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross
+DOCKER_PARTIAL_IMAGES += debian-nios2-cross
 DOCKER_PARTIAL_IMAGES += debian-riscv64-cross
 DOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
 DOCKER_PARTIAL_IMAGES += debian-tricore-cross
diff --git a/tests/docker/dockerfiles/debian-nios2-cross.docker b/tests/docker/dockerfiles/debian-nios2-cross.docker
new file mode 100644
index 0000000000..208737fc5e
--- /dev/null
+++ b/tests/docker/dockerfiles/debian-nios2-cross.docker
@@ -0,0 +1,34 @@
+#
+# Docker NIOS2 cross-compiler target
+#
+# This docker target is used for building tests. As it also needs to be
+# able to build QEMU itself in CI we include it's build-deps. It is also
+# a "stand-alone" image so as not to be triggered by re-builds on other
+# base images given it takes a long time to build.
+#
+FROM qemu/debian10
+
+# Install build utilities for building gcc and glibc.
+# ??? The build-dep isn't working, missing a number of
+# minimal build dependiencies, e.g. libmpc.
+
+RUN apt update && \
+    DEBIAN_FRONTEND=noninteractive apt install -yy eatmydata && \
+    DEBIAN_FRONTEND=noninteractive eatmydata \
+    apt install -y --no-install-recommends \
+        bison \
+        flex \
+        gawk \
+        libmpc-dev \
+        libmpfr-dev \
+        rsync \
+        texinfo \
+        wget \
+        $(apt-get -s build-dep --arch-only gcc | egrep ^Inst | fgrep '[all]' | cut -d\  -f2) \
+        $(apt-get -s build-dep --arch-only glibc | egrep ^Inst | fgrep '[all]' | cut -d\  -f2)
+
+ADD build-toolchain.sh /root/build-toolchain.sh
+
+RUN cd /root && ./build-toolchain.sh
+
+ENV PATH $PATH:/usr/local/bin/
diff --git a/tests/docker/dockerfiles/debian-nios2-cross.docker.d/build-toolchain.sh b/tests/docker/dockerfiles/debian-nios2-cross.docker.d/build-toolchain.sh
new file mode 100755
index 0000000000..d8cb428dab
--- /dev/null
+++ b/tests/docker/dockerfiles/debian-nios2-cross.docker.d/build-toolchain.sh
@@ -0,0 +1,97 @@
+#!/bin/bash
+
+set -e
+
+TARGET=nios2-linux-gnu
+LINUX_ARCH=nios2
+
+J=$(expr $(nproc) / 2)
+TOOLCHAIN_INSTALL=/usr/local
+TOOLCHAIN_BIN=${TOOLCHAIN_INSTALL}/bin
+CROSS_SYSROOT=${TOOLCHAIN_INSTALL}/$TARGET/sys-root
+
+export PATH=${TOOLCHAIN_BIN}:$PATH
+
+mkdir cross
+cd cross
+
+#
+# Grab all of the source for the toolchain bootstrap.
+#
+
+wget https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.xz
+wget https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
+wget https://ftp.gnu.org/gnu/glibc/glibc-2.34.tar.xz
+wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.70.tar.xz
+
+tar axf binutils-2.37.tar.xz
+tar axf gcc-11.2.0.tar.xz
+tar axf glibc-2.34.tar.xz
+tar axf linux-5.10.70.tar.xz
+
+mv binutils-2.37 src-binu
+mv gcc-11.2.0 src-gcc
+mv glibc-2.34 src-glibc
+mv linux-5.10.70 src-linux
+
+mkdir -p bld-hdr bld-binu bld-gcc bld-glibc
+mkdir -p ${CROSS_SYSROOT}/usr/include
+
+#
+# Install kernel and glibc headers
+#
+
+cd src-linux
+make headers_install ARCH=${LINUX_ARCH} INSTALL_HDR_PATH=${CROSS_SYSROOT}/usr
+cd ..
+
+cd bld-hdr
+../src-glibc/configure --prefix=/usr --host=${TARGET}
+make install-headers DESTDIR=${CROSS_SYSROOT}
+touch ${CROSS_SYSROOT}/usr/include/gnu/stubs.h
+cd ..
+
+#
+# Build binutils
+#
+
+cd bld-binu
+../src-binu/configure --disable-werror \
+  --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET}
+make -j${J}
+make install
+cd ..
+
+#
+# Build gcc, without shared libraries, because we do not yet
+# have a shared libc against which to link.
+#
+
+cd bld-gcc
+../src-gcc/configure --disable-werror --disable-shared \
+  --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET} \
+  --enable-languages=c --disable-libssp --disable-libsanitizer \
+  --disable-libatomic --disable-libgomp --disable-libquadmath
+make -j${J}
+make install
+cd ..
+
+#
+# Build glibc
+# There are a few random things that use c++ but we didn't build that
+# cross-compiler.  We can get away without them.  Disable CXX so that
+# glibc doesn't try to use the host c++ compiler.
+#
+
+cd bld-glibc
+CXX=false ../src-glibc/configure --prefix=/usr --host=${TARGET}
+make -j${j}
+make install DESTDIR=${CROSS_SYSROOT}
+cd ..
+
+#
+# Clean up
+#
+
+cd ..
+rm -rf cross build-toolchain.sh
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 1/2] tests/docker: Remove fedora-i386-cross from DOCKER_PARTIAL_IMAGES
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
  2021-10-01 15:33 ` [PATCH 1/9] tests/docker: Add debian-nios2-cross image Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-14  9:35   ` Alex Bennée
  2021-10-01 15:33 ` [PATCH 2/9] linux-user/nios2: Properly emulate EXCP_TRAP Richard Henderson
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, Thomas Huth, crwulff, alex.bennee, laurent

The image was upgraded to a full image in ee381b7fe146.
This makes it possible to use docker-test@image syntax
with this container.

Cc: Thomas Huth <thuth@redhat.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/docker/Makefile.include | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index ff5d732889..0806c6f726 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -184,7 +184,7 @@ DOCKER_PARTIAL_IMAGES += debian-riscv64-cross
 DOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
 DOCKER_PARTIAL_IMAGES += debian-tricore-cross
 DOCKER_PARTIAL_IMAGES += debian-xtensa-cross
-DOCKER_PARTIAL_IMAGES += fedora-i386-cross fedora-cris-cross
+DOCKER_PARTIAL_IMAGES += fedora-cris-cross
 
 # Rules for building linux-user powered images
 #
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 2/9] linux-user/nios2: Properly emulate EXCP_TRAP
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
  2021-10-01 15:33 ` [PATCH 1/9] tests/docker: Add debian-nios2-cross image Richard Henderson
  2021-10-01 15:33 ` [PATCH 1/2] tests/docker: Remove fedora-i386-cross from DOCKER_PARTIAL_IMAGES Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-14  9:36   ` Alex Bennée
  2021-10-01 15:33 ` [PATCH 2/2] tests/docker: Fix fedora-i386-cross Richard Henderson
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

The real kernel has to load the instruction and extract
the imm5 field; for qemu, modify the translator to do this.

The use of R_AT for this in cpu_loop was a bug.  Handle
the other trap numbers as per the kernel's trap_table.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/nios2/cpu.h          |  2 +-
 linux-user/nios2/cpu_loop.c | 40 ++++++++++++++++++++-----------------
 target/nios2/translate.c    | 17 +++++++++++++++-
 3 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
index a80587338a..f8c9d11f2f 100644
--- a/target/nios2/cpu.h
+++ b/target/nios2/cpu.h
@@ -160,9 +160,9 @@ struct CPUNios2State {
 
 #if !defined(CONFIG_USER_ONLY)
     Nios2MMU mmu;
-
     uint32_t irq_pending;
 #endif
+    int error_code;
 };
 
 /**
diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
index 34290fb3b5..5c3d01d22d 100644
--- a/linux-user/nios2/cpu_loop.c
+++ b/linux-user/nios2/cpu_loop.c
@@ -26,7 +26,6 @@
 void cpu_loop(CPUNios2State *env)
 {
     CPUState *cs = env_cpu(env);
-    Nios2CPU *cpu = NIOS2_CPU(cs);
     target_siginfo_t info;
     int trapnr, ret;
 
@@ -39,9 +38,10 @@ void cpu_loop(CPUNios2State *env)
         case EXCP_INTERRUPT:
             /* just indicate that signals should be handled asap */
             break;
+
         case EXCP_TRAP:
-            if (env->regs[R_AT] == 0) {
-                abi_long ret;
+            switch (env->error_code) {
+            case 0:
                 qemu_log_mask(CPU_LOG_INT, "\nSyscall\n");
 
                 ret = do_syscall(env, env->regs[2],
@@ -55,26 +55,30 @@ void cpu_loop(CPUNios2State *env)
 
                 env->regs[2] = abs(ret);
                 /* Return value is 0..4096 */
-                env->regs[7] = (ret > 0xfffffffffffff000ULL);
-                env->regs[CR_ESTATUS] = env->regs[CR_STATUS];
-                env->regs[CR_STATUS] &= ~0x3;
-                env->regs[R_EA] = env->regs[R_PC] + 4;
+                env->regs[7] = ret > 0xfffff000u;
                 env->regs[R_PC] += 4;
                 break;
-            } else {
-                qemu_log_mask(CPU_LOG_INT, "\nTrap\n");
 
-                env->regs[CR_ESTATUS] = env->regs[CR_STATUS];
-                env->regs[CR_STATUS] &= ~0x3;
-                env->regs[R_EA] = env->regs[R_PC] + 4;
-                env->regs[R_PC] = cpu->exception_addr;
-
-                info.si_signo = TARGET_SIGTRAP;
-                info.si_errno = 0;
-                info.si_code = TARGET_TRAP_BRKPT;
-                queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            case 1:
+                qemu_log_mask(CPU_LOG_INT, "\nTrap 1\n");
+                force_sig_fault(TARGET_SIGUSR1, 0, env->regs[R_PC]);
+                break;
+            case 2:
+                qemu_log_mask(CPU_LOG_INT, "\nTrap 2\n");
+                force_sig_fault(TARGET_SIGUSR2, 0, env->regs[R_PC]);
+                break;
+            case 31:
+                qemu_log_mask(CPU_LOG_INT, "\nTrap 31\n");
+                force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->regs[R_PC]);
+                break;
+            default:
+                qemu_log_mask(CPU_LOG_INT, "\nTrap %d\n", env->error_code);
+                force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLTRP,
+                                env->regs[R_PC]);
                 break;
             }
+            break;
+
         case EXCP_DEBUG:
             info.si_signo = TARGET_SIGTRAP;
             info.si_errno = 0;
diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index 08d7ac5398..a759877519 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -636,6 +636,21 @@ static void divu(DisasContext *dc, uint32_t code, uint32_t flags)
     tcg_temp_free(t0);
 }
 
+static void trap(DisasContext *dc, uint32_t code, uint32_t flags)
+{
+#ifdef CONFIG_USER_ONLY
+    /*
+     * The imm5 field is not stored anywhere on real hw; the kernel
+     * has to load the insn and extract the field.  But we can make
+     * things easier for cpu_loop if we pop this into env->error_code.
+     */
+    R_TYPE(instr, code);
+    tcg_gen_st_i32(tcg_constant_i32(instr.imm5), cpu_env,
+                   offsetof(CPUNios2State, error_code));
+#endif
+    t_gen_helper_raise_exception(dc, EXCP_TRAP);
+}
+
 static const Nios2Instruction r_type_instructions[] = {
     INSTRUCTION_ILLEGAL(),
     INSTRUCTION(eret),                                /* eret */
@@ -682,7 +697,7 @@ static const Nios2Instruction r_type_instructions[] = {
     INSTRUCTION_ILLEGAL(),
     INSTRUCTION_ILLEGAL(),
     INSTRUCTION_ILLEGAL(),
-    INSTRUCTION_FLG(gen_excp, EXCP_TRAP),             /* trap */
+    INSTRUCTION(trap),                                /* trap */
     INSTRUCTION(wrctl),                               /* wrctl */
     INSTRUCTION_ILLEGAL(),
     INSTRUCTION_FLG(gen_cmpxx, TCG_COND_LTU),         /* cmpltu */
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 2/2] tests/docker: Fix fedora-i386-cross
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (2 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 2/9] linux-user/nios2: Properly emulate EXCP_TRAP Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-14  9:38   ` Alex Bennée
  2021-10-01 15:33 ` [PATCH 3/9] linux-user/nios2: Fixes for signal frame setup Richard Henderson
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: marex, Daniel P . Berrangé,
	crwulff, laurent, Richard W . M . Jones, Paolo Bonzini,
	alex.bennee

By using PKG_CONFIG_PATH instead of PKG_CONFIG_LIBDIR,
we were still including the 64-bit packages.  Install
pcre-devel.i686 to fill a missing glib2 dependency.

By using --extra-cflags instead of --cpu, we incorrectly
use the wrong probing during meson.

Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Daniel P. Berrangé <berrange@redhat.com>
Cc: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/docker/dockerfiles/fedora-i386-cross.docker | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/docker/dockerfiles/fedora-i386-cross.docker b/tests/docker/dockerfiles/fedora-i386-cross.docker
index dbb8195eb1..820740d5be 100644
--- a/tests/docker/dockerfiles/fedora-i386-cross.docker
+++ b/tests/docker/dockerfiles/fedora-i386-cross.docker
@@ -17,12 +17,13 @@ ENV PACKAGES \
     glibc-static.i686 \
     gnutls-devel.i686 \
     nettle-devel.i686 \
+    pcre-devel.i686 \
     perl-Test-Harness \
     pixman-devel.i686 \
     zlib-devel.i686
 
-ENV QEMU_CONFIGURE_OPTS --extra-cflags=-m32 --disable-vhost-user
-ENV PKG_CONFIG_PATH /usr/lib/pkgconfig
+ENV QEMU_CONFIGURE_OPTS --cpu=i386 --disable-vhost-user
+ENV PKG_CONFIG_LIBDIR /usr/lib/pkgconfig
 
 RUN dnf install -y $PACKAGES
 RUN rpm -q $PACKAGES | sort > /packages.txt
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 3/9] linux-user/nios2: Fixes for signal frame setup
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (3 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 2/2] tests/docker: Fix fedora-i386-cross Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-14  9:43   ` Alex Bennée
  2021-10-01 15:33 ` [PATCH 4/9] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE Richard Henderson
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, Peter Maydell, crwulff, alex.bennee, laurent

Do not confuse host and guest addresses.  Lock and unlock
the target_rt_sigframe structure in setup_rt_sigframe.

Since rt_setup_ucontext always returns 0, drop the return
value entirely.  This eliminates the only write to the err
variable in setup_rt_sigframe.

Always copy the siginfo structure.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20210924165926.752809-19-richard.henderson@linaro.org>
---
 linux-user/nios2/signal.c | 49 ++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 29 deletions(-)

diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index a77e8a40f4..adbffe32e3 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -42,7 +42,7 @@ struct target_rt_sigframe {
     struct target_ucontext uc;
 };
 
-static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
+static void rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
 {
     unsigned long *gregs = uc->tuc_mcontext.gregs;
 
@@ -75,8 +75,6 @@ static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
     __put_user(env->regs[R_GP], &gregs[25]);
     __put_user(env->regs[R_EA], &gregs[27]);
     __put_user(env->regs[R_SP], &gregs[28]);
-
-    return 0;
 }
 
 static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc,
@@ -135,8 +133,8 @@ static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc,
     return 0;
 }
 
-static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env,
-                          size_t frame_size)
+static abi_ptr get_sigframe(struct target_sigaction *ka, CPUNios2State *env,
+                            size_t frame_size)
 {
     unsigned long usp;
 
@@ -144,7 +142,7 @@ static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env,
     usp = target_sigsp(get_sp_from_cpustate(env), ka);
 
     /* Verify, is it 32 or 64 bit aligned */
-    return (void *)((usp - frame_size) & -8UL);
+    return (usp - frame_size) & -8;
 }
 
 void setup_rt_frame(int sig, struct target_sigaction *ka,
@@ -153,26 +151,25 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     CPUNios2State *env)
 {
     struct target_rt_sigframe *frame;
-    int i, err = 0;
+    abi_ptr frame_addr;
+    int i;
 
-    frame = get_sigframe(ka, env, sizeof(*frame));
-
-    if (ka->sa_flags & SA_SIGINFO) {
-        tswap_siginfo(&frame->info, info);
+    frame_addr = get_sigframe(ka, env, sizeof(*frame));
+    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
+        force_sigsegv(sig);
+        return;
     }
 
+    tswap_siginfo(&frame->info, info);
+
     /* Create the ucontext.  */
     __put_user(0, &frame->uc.tuc_flags);
     __put_user(0, &frame->uc.tuc_link);
     target_save_altstack(&frame->uc.tuc_stack, env);
-    err |= rt_setup_ucontext(&frame->uc, env);
+    rt_setup_ucontext(&frame->uc, env);
     for (i = 0; i < TARGET_NSIG_WORDS; i++) {
         __put_user((abi_ulong)set->sig[i],
-            (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]);
-    }
-
-    if (err) {
-        goto give_sigsegv;
+                   (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]);
     }
 
     /* Set up to return from userspace; jump to fixed address sigreturn
@@ -180,19 +177,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     env->regs[R_RA] = (unsigned long) (0x1044);
 
     /* Set up registers for signal handler */
-    env->regs[R_SP] = (unsigned long) frame;
-    env->regs[4] = (unsigned long) sig;
-    env->regs[5] = (unsigned long) &frame->info;
-    env->regs[6] = (unsigned long) &frame->uc;
-    env->regs[R_EA] = (unsigned long) ka->_sa_handler;
-    return;
+    env->regs[R_SP] = frame_addr;
+    env->regs[4] = sig;
+    env->regs[5] = frame_addr + offsetof(struct target_rt_sigframe, info);
+    env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, uc);
+    env->regs[R_EA] = ka->_sa_handler;
 
-give_sigsegv:
-    if (sig == TARGET_SIGSEGV) {
-        ka->_sa_handler = TARGET_SIG_DFL;
-    }
-    force_sigsegv(sig);
-    return;
+    unlock_user_struct(frame, frame_addr, 1);
 }
 
 long do_sigreturn(CPUNios2State *env)
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 4/9] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (4 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 3/9] linux-user/nios2: Fixes for signal frame setup Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-12  6:11   ` Laurent Vivier
  2021-10-01 15:33 ` [PATCH 5/9] linux-user/nios2: Map a real kuser page Richard Henderson
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

Arm will no longer be the only target requiring a commpage,
but it will continue to be the only target placing the page
at the high end of the address space.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5f9e2141ad..dc4ababedd 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -388,11 +388,11 @@ enum {
 
 /* The commpage only exists for 32 bit kernels */
 
-#define ARM_COMMPAGE (intptr_t)0xffff0f00u
+#define HI_COMMPAGE (intptr_t)0xffff0f00u
 
 static bool init_guest_commpage(void)
 {
-    void *want = g2h_untagged(ARM_COMMPAGE & -qemu_host_page_size);
+    void *want = g2h_untagged(HI_COMMPAGE & -qemu_host_page_size);
     void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE,
                       MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
 
@@ -2160,8 +2160,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     return sp;
 }
 
-#ifndef ARM_COMMPAGE
-#define ARM_COMMPAGE 0
+#ifndef HI_COMMPAGE
+#define HI_COMMPAGE 0
 #define init_guest_commpage() true
 #endif
 
@@ -2361,7 +2361,7 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
     }
 
     loaddr &= -align;
-    if (ARM_COMMPAGE) {
+    if (HI_COMMPAGE) {
         /*
          * Extend the allocation to include the commpage.
          * For a 64-bit host, this is just 4GiB; for a 32-bit host we
@@ -2372,14 +2372,14 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
         if (sizeof(uintptr_t) == 8 || loaddr >= 0x80000000u) {
             hiaddr = (uintptr_t) 4 << 30;
         } else {
-            offset = -(ARM_COMMPAGE & -align);
+            offset = -(HI_COMMPAGE & -align);
         }
     }
 
     addr = pgb_find_hole(loaddr, hiaddr - loaddr, align, offset);
     if (addr == -1) {
         /*
-         * If ARM_COMMPAGE, there *might* be a non-consecutive allocation
+         * If HI_COMMPAGE, there *might* be a non-consecutive allocation
          * that can satisfy both.  But as the normal arm32 link base address
          * is ~32k, and we extend down to include the commpage, making the
          * overhead only ~96k, this is unlikely.
@@ -2400,7 +2400,7 @@ static void pgb_dynamic(const char *image_name, long align)
      * All we need is a commpage that satisfies align.
      * If we do not need a commpage, leave guest_base == 0.
      */
-    if (ARM_COMMPAGE) {
+    if (HI_COMMPAGE) {
         uintptr_t addr, commpage;
 
         /* 64-bit hosts should have used reserved_va. */
@@ -2410,7 +2410,7 @@ static void pgb_dynamic(const char *image_name, long align)
          * By putting the commpage at the first hole, that puts guest_base
          * just above that, and maximises the positive guest addresses.
          */
-        commpage = ARM_COMMPAGE & -align;
+        commpage = HI_COMMPAGE & -align;
         addr = pgb_find_hole(commpage, -commpage, align, 0);
         assert(addr != -1);
         guest_base = addr;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 5/9] linux-user/nios2: Map a real kuser page
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (5 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 4/9] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-01 15:33 ` [PATCH 6/9] linux-user/nios2: Fix EA vs PC confusion Richard Henderson
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

The first word of page1 is data, so the whole thing
can't be implemented with emulation of addresses.
Use init_guest_commpage for the allocation.

Hijack trap number 16 to implement cmpxchg.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c        | 50 ++++++++++++++++++++++++++++++++++++-
 linux-user/nios2/cpu_loop.c | 50 ++++++++++++++++++++-----------------
 target/nios2/translate.c    |  9 -------
 3 files changed, 76 insertions(+), 33 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index dc4ababedd..206f7d511e 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1099,6 +1099,47 @@ static void init_thread(struct target_pt_regs *regs, struct image_info *infop)
     regs->estatus = 0x3;
 }
 
+#define LO_COMMPAGE  TARGET_PAGE_SIZE
+
+static bool init_guest_commpage(void)
+{
+    static const uint8_t kuser_page[4 + 2 * 64] = {
+        /* __kuser_helper_version */
+        [0x00] = 0x02, 0x00, 0x00, 0x00,
+
+        /* __kuser_cmpxchg */
+        [0x04] = 0x3a, 0x6c, 0x3b, 0x00,  /* trap 31 */
+                 0x3a, 0x28, 0x00, 0xf8,  /* ret */
+
+        /* __kuser_sigtramp */
+        [0x44] = 0xc4, 0x22, 0x80, 0x00,  /* movi r2, __NR_rt_sigreturn */
+                 0x3a, 0x68, 0x3b, 0x00,  /* trap 0 */
+    };
+
+    void *want = g2h_untagged(LO_COMMPAGE & -qemu_host_page_size);
+    void *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");
+        exit(EXIT_FAILURE);
+    }
+    if (addr != want) {
+        return false;
+    }
+
+    memcpy(addr, kuser_page, sizeof(kuser_page));
+
+    if (mprotect(addr, qemu_host_page_size, PROT_READ)) {
+        perror("Protecting guest commpage");
+        exit(EXIT_FAILURE);
+    }
+
+    page_set_flags(LO_COMMPAGE, LO_COMMPAGE + TARGET_PAGE_SIZE,
+                   PAGE_READ | PAGE_EXEC | PAGE_VALID);
+    return true;
+}
+
 #define ELF_EXEC_PAGESIZE        4096
 
 #define USE_ELF_CORE_DUMP
@@ -2160,8 +2201,13 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     return sp;
 }
 
-#ifndef HI_COMMPAGE
+#if defined(HI_COMMPAGE)
+#define LO_COMMPAGE 0
+#elif defined(LO_COMMPAGE)
 #define HI_COMMPAGE 0
+#else
+#define HI_COMMPAGE 0
+#define LO_COMMPAGE 0
 #define init_guest_commpage() true
 #endif
 
@@ -2374,6 +2420,8 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
         } else {
             offset = -(HI_COMMPAGE & -align);
         }
+    } else if (LO_COMMPAGE) {
+        loaddr = MIN(loaddr, LO_COMMPAGE & -align);
     }
 
     addr = pgb_find_hole(loaddr, hiaddr - loaddr, align, offset);
diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
index 5c3d01d22d..de0fc63e21 100644
--- a/linux-user/nios2/cpu_loop.c
+++ b/linux-user/nios2/cpu_loop.c
@@ -76,6 +76,32 @@ void cpu_loop(CPUNios2State *env)
                 force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLTRP,
                                 env->regs[R_PC]);
                 break;
+
+            case 16: /* QEMU specific, for __kuser_cmpxchg */
+                {
+                    abi_ptr g = env->regs[4];
+                    uint32_t *h, n, o;
+
+                    if (g & 0x3) {
+                        force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, g);
+                        break;
+                    }
+                    ret = page_get_flags(g);
+                    if (!(ret & PAGE_VALID)) {
+                        force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, g);
+                        break;
+                    }
+                    if (!(ret & PAGE_READ) || !(ret & PAGE_WRITE)) {
+                        force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_ACCERR, g);
+                        break;
+                    }
+                    h = g2h(cs, g);
+                    o = env->regs[5];
+                    n = env->regs[6];
+                    env->regs[2] = qatomic_cmpxchg(h, o, n) - o;
+                    env->regs[R_PC] += 4;
+                }
+                break;
             }
             break;
 
@@ -86,29 +112,7 @@ void cpu_loop(CPUNios2State *env)
             queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
             break;
         case 0xaa:
-            switch (env->regs[R_PC]) {
-            /*case 0x1000:*/  /* TODO:__kuser_helper_version */
-            case 0x1004:      /* __kuser_cmpxchg */
-                start_exclusive();
-                if (env->regs[4] & 0x3) {
-                    goto kuser_fail;
-                }
-                ret = get_user_u32(env->regs[2], env->regs[4]);
-                if (ret) {
-                    end_exclusive();
-                    goto kuser_fail;
-                }
-                env->regs[2] -= env->regs[5];
-                if (env->regs[2] == 0) {
-                    put_user_u32(env->regs[6], env->regs[4]);
-                }
-                end_exclusive();
-                env->regs[R_PC] = env->regs[R_RA];
-                break;
-            /*case 0x1040:*/  /* TODO:__kuser_sigtramp */
-            default:
-                ;
-kuser_fail:
+            {
                 info.si_signo = TARGET_SIGSEGV;
                 info.si_errno = 0;
                 /* TODO: check env->error_code */
diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index a759877519..f9abc2fdd2 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -795,15 +795,6 @@ static void nios2_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
     dc->base.pc_next = pc + 4;
 
     /* Decode an instruction */
-
-#if defined(CONFIG_USER_ONLY)
-    /* FIXME: Is this needed ? */
-    if (pc >= 0x1000 && pc < 0x2000) {
-        t_gen_helper_raise_exception(dc, 0xaa);
-        return;
-    }
-#endif
-
     code = cpu_ldl_code(env, pc);
     op = get_opcode(code);
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 6/9] linux-user/nios2: Fix EA vs PC confusion
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (6 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 5/9] linux-user/nios2: Map a real kuser page Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-01 15:33 ` [PATCH 7/9] linux-user/nios2: Fix sigmask in setup_rt_frame Richard Henderson
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

The real kernel will talk about the user PC as EA,
because that's where the hardware will have copied it,
and where it expects to put it to then use ERET.
But qemu does not emulate all of the exception stuff
while emulating user-only.  Manipulate PC directly.

This fixes signal entry and return, and eliminates
some slight confusion from target_cpu_copy_regs.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/nios2/cpu_loop.c | 5 +----
 linux-user/nios2/signal.c   | 6 +++---
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
index de0fc63e21..1e93ef34e6 100644
--- a/linux-user/nios2/cpu_loop.c
+++ b/linux-user/nios2/cpu_loop.c
@@ -155,9 +155,6 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
     env->regs[R_SP] = regs->sp;
     env->regs[R_GP] = regs->gp;
     env->regs[CR_ESTATUS] = regs->estatus;
-    env->regs[R_EA] = regs->ea;
-    /* TODO: unsigned long  orig_r7; */
-
-    /* Emulate eret when starting thread. */
     env->regs[R_PC] = regs->ea;
+    /* TODO: unsigned long  orig_r7; */
 }
diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index adbffe32e3..20b65aa06e 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -73,7 +73,7 @@ static void rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
     __put_user(env->regs[R_RA], &gregs[23]);
     __put_user(env->regs[R_FP], &gregs[24]);
     __put_user(env->regs[R_GP], &gregs[25]);
-    __put_user(env->regs[R_EA], &gregs[27]);
+    __put_user(env->regs[R_PC], &gregs[27]);
     __put_user(env->regs[R_SP], &gregs[28]);
 }
 
@@ -122,7 +122,7 @@ static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc,
     __get_user(env->regs[R_GP], &gregs[25]);
     /* Not really necessary no user settable bits */
     __get_user(temp, &gregs[26]);
-    __get_user(env->regs[R_EA], &gregs[27]);
+    __get_user(env->regs[R_PC], &gregs[27]);
 
     __get_user(env->regs[R_RA], &gregs[23]);
     __get_user(env->regs[R_SP], &gregs[28]);
@@ -181,7 +181,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     env->regs[4] = sig;
     env->regs[5] = frame_addr + offsetof(struct target_rt_sigframe, info);
     env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, uc);
-    env->regs[R_EA] = ka->_sa_handler;
+    env->regs[R_PC] = ka->_sa_handler;
 
     unlock_user_struct(frame, frame_addr, 1);
 }
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 7/9] linux-user/nios2: Fix sigmask in setup_rt_frame
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (7 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 6/9] linux-user/nios2: Fix EA vs PC confusion Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-12  6:16   ` Laurent Vivier
  2021-10-01 15:33 ` [PATCH 8/9] linux-user/nios2: Use set_sigmask in do_rt_sigreturn Richard Henderson
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

Do not cast the signal mask elements; trust __put_user.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/nios2/signal.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index 20b65aa06e..80e3d42fc9 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -168,8 +168,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     target_save_altstack(&frame->uc.tuc_stack, env);
     rt_setup_ucontext(&frame->uc, env);
     for (i = 0; i < TARGET_NSIG_WORDS; i++) {
-        __put_user((abi_ulong)set->sig[i],
-                   (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]);
+        __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
     }
 
     /* Set up to return from userspace; jump to fixed address sigreturn
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 8/9] linux-user/nios2: Use set_sigmask in do_rt_sigreturn
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (8 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 7/9] linux-user/nios2: Fix sigmask in setup_rt_frame Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-12  6:29   ` Laurent Vivier
  2021-10-01 15:33 ` [PATCH 9/9] tests/tcg: Enable container_cross_cc for nios2 Richard Henderson
  2021-10-11 19:06 ` [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
  11 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

Using do_sigprocmask directly was incorrect, as it will
leave the signal blocked by the outer layers of linux-user.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/nios2/signal.c | 2 +-
 linux-user/signal.c       | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index 80e3d42fc9..517cd39270 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -205,7 +205,7 @@ long do_rt_sigreturn(CPUNios2State *env)
     }
 
     target_to_host_sigset(&set, &frame->uc.tuc_sigmask);
-    do_sigprocmask(SIG_SETMASK, &set, NULL);
+    set_sigmask(&set);
 
     if (rt_restore_ucontext(env, &frame->uc, &rval)) {
         goto badframe;
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 2038216455..5ec63cd092 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -252,7 +252,6 @@ int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
     return 0;
 }
 
-#if !defined(TARGET_NIOS2)
 /* Just set the guest's signal mask to the specified value; the
  * caller is assumed to have called block_signals() already.
  */
@@ -262,7 +261,6 @@ void set_sigmask(const sigset_t *set)
 
     ts->signal_mask = *set;
 }
-#endif
 
 /* sigaltstack management */
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 9/9] tests/tcg: Enable container_cross_cc for nios2
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (9 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 8/9] linux-user/nios2: Use set_sigmask in do_rt_sigreturn Richard Henderson
@ 2021-10-01 15:33 ` Richard Henderson
  2021-10-11 19:06 ` [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
  11 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2021-10-01 15:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/tcg/configure.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh
index 1f985ccfc0..62ca1e2cae 100755
--- a/tests/tcg/configure.sh
+++ b/tests/tcg/configure.sh
@@ -59,6 +59,7 @@ fi
 : $(cross_cc_mips64="mips64-linux-gnuabi64-gcc")
 : $(cross_cc_mipsel="mipsel-linux-gnu-gcc")
 : $(cross_cc_mips="mips-linux-gnu-gcc")
+: $(cross_cc_nios2="nios2-linux-gnu-gcc")
 : ${cross_cc_ppc="powerpc-linux-gnu-gcc"}
 : ${cross_cc_cflags_ppc="-m32"}
 : ${cross_cc_ppc64="powerpc64-linux-gnu-gcc"}
@@ -153,6 +154,11 @@ for target in $target_list; do
       container_image=debian-mips-cross
       container_cross_cc=mips-linux-gnu-gcc
       ;;
+    nios2-*)
+      container_hosts=x86_64
+      container_image=debian-nios2-cross
+      container_cross_cc=nios2-linux-gnu-gcc
+      ;;
     ppc-*|ppc64abi32-*)
       container_hosts=x86_64
       container_image=debian-powerpc-test-cross
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 0/9] nios2: Enable cross compile and fix signals
  2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
                   ` (10 preceding siblings ...)
  2021-10-01 15:33 ` [PATCH 9/9] tests/tcg: Enable container_cross_cc for nios2 Richard Henderson
@ 2021-10-11 19:06 ` Richard Henderson
  11 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2021-10-11 19:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: marex, crwulff, alex.bennee, laurent

Ping.

On 10/1/21 8:33 AM, Richard Henderson wrote:
> Patches 2, 3, and 5 have appeared before.
> 
> The patch for the kuser page has been updated to use the commpage
> infrastructure, which needed expanding just a bit to handle the
> page being at the beginning of the address space.
> 
> Getting the toolchain built allowed the code to actually be tested,
> which showed up a few more problems in the testsuite.
> 
> I have already pushed the debian-nios2-cross image to gitlab, much
> like we did for hexagon and its locally built toolchain.
> 
> 
> r~
> 
> 
> Richard Henderson (9):
>    tests/docker: Add debian-nios2-cross image
>    linux-user/nios2: Properly emulate EXCP_TRAP
>    linux-user/nios2: Fixes for signal frame setup
>    linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE
>    linux-user/nios2: Map a real kuser page
>    linux-user/nios2: Fix EA vs PC confusion
>    linux-user/nios2: Fix sigmask in setup_rt_frame
>    linux-user/nios2: Use set_sigmask in do_rt_sigreturn
>    tests/tcg: Enable container_cross_cc for nios2
> 
>   target/nios2/cpu.h                            |  2 +-
>   linux-user/elfload.c                          | 66 +++++++++++--
>   linux-user/nios2/cpu_loop.c                   | 93 +++++++++---------
>   linux-user/nios2/signal.c                     | 56 +++++------
>   linux-user/signal.c                           |  2 -
>   target/nios2/translate.c                      | 26 +++--
>   tests/docker/Makefile.include                 | 19 ++++
>   .../dockerfiles/debian-nios2-cross.docker     | 34 +++++++
>   .../build-toolchain.sh                        | 97 +++++++++++++++++++
>   tests/tcg/configure.sh                        |  6 ++
>   10 files changed, 302 insertions(+), 99 deletions(-)
>   create mode 100644 tests/docker/dockerfiles/debian-nios2-cross.docker
>   create mode 100755 tests/docker/dockerfiles/debian-nios2-cross.docker.d/build-toolchain.sh
> 



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 4/9] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE
  2021-10-01 15:33 ` [PATCH 4/9] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE Richard Henderson
@ 2021-10-12  6:11   ` Laurent Vivier
  0 siblings, 0 replies; 26+ messages in thread
From: Laurent Vivier @ 2021-10-12  6:11 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: marex, crwulff, alex.bennee

Le 01/10/2021 à 17:33, Richard Henderson a écrit :
> Arm will no longer be the only target requiring a commpage,
> but it will continue to be the only target placing the page
> at the high end of the address space.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 5f9e2141ad..dc4ababedd 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -388,11 +388,11 @@ enum {
>  
>  /* The commpage only exists for 32 bit kernels */
>  
> -#define ARM_COMMPAGE (intptr_t)0xffff0f00u
> +#define HI_COMMPAGE (intptr_t)0xffff0f00u
>  
>  static bool init_guest_commpage(void)
>  {
> -    void *want = g2h_untagged(ARM_COMMPAGE & -qemu_host_page_size);
> +    void *want = g2h_untagged(HI_COMMPAGE & -qemu_host_page_size);
>      void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE,
>                        MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
>  
> @@ -2160,8 +2160,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
>      return sp;
>  }
>  
> -#ifndef ARM_COMMPAGE
> -#define ARM_COMMPAGE 0
> +#ifndef HI_COMMPAGE
> +#define HI_COMMPAGE 0
>  #define init_guest_commpage() true
>  #endif
>  
> @@ -2361,7 +2361,7 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
>      }
>  
>      loaddr &= -align;
> -    if (ARM_COMMPAGE) {
> +    if (HI_COMMPAGE) {
>          /*
>           * Extend the allocation to include the commpage.
>           * For a 64-bit host, this is just 4GiB; for a 32-bit host we
> @@ -2372,14 +2372,14 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
>          if (sizeof(uintptr_t) == 8 || loaddr >= 0x80000000u) {
>              hiaddr = (uintptr_t) 4 << 30;
>          } else {
> -            offset = -(ARM_COMMPAGE & -align);
> +            offset = -(HI_COMMPAGE & -align);
>          }
>      }
>  
>      addr = pgb_find_hole(loaddr, hiaddr - loaddr, align, offset);
>      if (addr == -1) {
>          /*
> -         * If ARM_COMMPAGE, there *might* be a non-consecutive allocation
> +         * If HI_COMMPAGE, there *might* be a non-consecutive allocation
>           * that can satisfy both.  But as the normal arm32 link base address
>           * is ~32k, and we extend down to include the commpage, making the
>           * overhead only ~96k, this is unlikely.
> @@ -2400,7 +2400,7 @@ static void pgb_dynamic(const char *image_name, long align)
>       * All we need is a commpage that satisfies align.
>       * If we do not need a commpage, leave guest_base == 0.
>       */
> -    if (ARM_COMMPAGE) {
> +    if (HI_COMMPAGE) {
>          uintptr_t addr, commpage;
>  
>          /* 64-bit hosts should have used reserved_va. */
> @@ -2410,7 +2410,7 @@ static void pgb_dynamic(const char *image_name, long align)
>           * By putting the commpage at the first hole, that puts guest_base
>           * just above that, and maximises the positive guest addresses.
>           */
> -        commpage = ARM_COMMPAGE & -align;
> +        commpage = HI_COMMPAGE & -align;
>          addr = pgb_find_hole(commpage, -commpage, align, 0);
>          assert(addr != -1);
>          guest_base = addr;
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 7/9] linux-user/nios2: Fix sigmask in setup_rt_frame
  2021-10-01 15:33 ` [PATCH 7/9] linux-user/nios2: Fix sigmask in setup_rt_frame Richard Henderson
@ 2021-10-12  6:16   ` Laurent Vivier
  0 siblings, 0 replies; 26+ messages in thread
From: Laurent Vivier @ 2021-10-12  6:16 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: marex, crwulff, alex.bennee

Le 01/10/2021 à 17:33, Richard Henderson a écrit :
> Do not cast the signal mask elements; trust __put_user.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/nios2/signal.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
> index 20b65aa06e..80e3d42fc9 100644
> --- a/linux-user/nios2/signal.c
> +++ b/linux-user/nios2/signal.c
> @@ -168,8 +168,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
>      target_save_altstack(&frame->uc.tuc_stack, env);
>      rt_setup_ucontext(&frame->uc, env);
>      for (i = 0; i < TARGET_NSIG_WORDS; i++) {
> -        __put_user((abi_ulong)set->sig[i],
> -                   (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]);
> +        __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
>      }
>  
>      /* Set up to return from userspace; jump to fixed address sigreturn
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 8/9] linux-user/nios2: Use set_sigmask in do_rt_sigreturn
  2021-10-01 15:33 ` [PATCH 8/9] linux-user/nios2: Use set_sigmask in do_rt_sigreturn Richard Henderson
@ 2021-10-12  6:29   ` Laurent Vivier
  0 siblings, 0 replies; 26+ messages in thread
From: Laurent Vivier @ 2021-10-12  6:29 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: marex, crwulff, alex.bennee

Le 01/10/2021 à 17:33, Richard Henderson a écrit :
> Using do_sigprocmask directly was incorrect, as it will
> leave the signal blocked by the outer layers of linux-user.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/nios2/signal.c | 2 +-
>  linux-user/signal.c       | 2 --
>  2 files changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
> index 80e3d42fc9..517cd39270 100644
> --- a/linux-user/nios2/signal.c
> +++ b/linux-user/nios2/signal.c
> @@ -205,7 +205,7 @@ long do_rt_sigreturn(CPUNios2State *env)
>      }
>  
>      target_to_host_sigset(&set, &frame->uc.tuc_sigmask);
> -    do_sigprocmask(SIG_SETMASK, &set, NULL);
> +    set_sigmask(&set);
>  
>      if (rt_restore_ucontext(env, &frame->uc, &rval)) {
>          goto badframe;
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 2038216455..5ec63cd092 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -252,7 +252,6 @@ int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
>      return 0;
>  }
>  
> -#if !defined(TARGET_NIOS2)
>  /* Just set the guest's signal mask to the specified value; the
>   * caller is assumed to have called block_signals() already.
>   */
> @@ -262,7 +261,6 @@ void set_sigmask(const sigset_t *set)
>  
>      ts->signal_mask = *set;
>  }
> -#endif
>  
>  /* sigaltstack management */
>  
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/9] tests/docker: Add debian-nios2-cross image
  2021-10-01 15:33 ` [PATCH 1/9] tests/docker: Add debian-nios2-cross image Richard Henderson
@ 2021-10-12 17:03   ` Alex Bennée
  2021-10-12 18:24     ` Richard Henderson
  2021-10-14 17:17     ` Richard Henderson
  0 siblings, 2 replies; 26+ messages in thread
From: Alex Bennée @ 2021-10-12 17:03 UTC (permalink / raw)
  To: Richard Henderson; +Cc: marex, crwulff, qemu-devel, laurent


Richard Henderson <richard.henderson@linaro.org> writes:

> Build the entire cross tool chain from source.
> For this reason, default to caching.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  tests/docker/Makefile.include                 | 19 ++++
>  .../dockerfiles/debian-nios2-cross.docker     | 34 +++++++
>  .../build-toolchain.sh                        | 97 +++++++++++++++++++
>  3 files changed, 150 insertions(+)
>  create mode 100644 tests/docker/dockerfiles/debian-nios2-cross.docker
>  create mode 100755 tests/docker/dockerfiles/debian-nios2-cross.docker.d/build-toolchain.sh
>
> diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
> index ff5d732889..2ccd93caa4 100644
> --- a/tests/docker/Makefile.include
> +++ b/tests/docker/Makefile.include
> @@ -168,10 +168,28 @@ docker-image-debian-hexagon-cross: $(DOCKER_FILES_DIR)/debian-hexagon-cross.dock
>  				qemu/debian-hexagon-cross --add-current-user,		\
>  			"PREPARE", "debian-hexagon-cross"))

We need^H^H^H^H (might need, see bellow) a separate patch with:

docker-image-debian10: NOUSER=1

to ensure the images we base our "handbuilt" compilers on don't include
a potentially clashing uid (which should only be added for local
builds).


> +docker-image-debian-nios2-cross: $(DOCKER_FILES_DIR)/debian-nios2-cross.docker
> +	$(if $(NOCACHE), 								\
> +		$(call quiet-command,							\
> +			$(DOCKER_SCRIPT) build -t qemu/debian-nios2-cross -f $< 	\
> +			$(if $V,,--quiet) --no-cache 					\
> +			--registry $(DOCKER_REGISTRY) --extra-files			\
> +			$(DOCKER_FILES_DIR)/debian-nios2-cross.docker.d/build-toolchain.sh, \
> +			"BUILD", "debian-nios2-cross"),				        \
> +		$(call quiet-command,							\
> +			$(DOCKER_SCRIPT) fetch $(if $V,,--quiet)			\
> +				qemu/debian-nios2-cross $(DOCKER_REGISTRY),		\
> +			"FETCH", "debian-nios2-cross")				        \
> +		$(call quiet-command,							\
> +			$(DOCKER_SCRIPT) update $(if $V,,--quiet) 			\
> +				qemu/debian-nios2-cross --add-current-user,		\
> +			"PREPARE", "debian-nios2-cross"))
> +

Could we update the comment above to something like:

  #
  # The build rule for these cross compilers are special in so far for
  # most of the time we don't want to build them. While dockers caching
  # does avoid this most of the time sometimes we want to force the
  # issue. Also we want to ensure the image they are based on hasn't
  # been polluted with our UID because it will fail when users build
  # their local version from what has been pushed upstream.
  #

>  # Specialist build images, sometimes very limited tools
>  docker-image-debian-tricore-cross: docker-image-debian10
>  docker-image-debian-all-test-cross: docker-image-debian10
>  docker-image-debian-arm64-test-cross: docker-image-debian11
> +docker-image-debian-nios2-cross: docker-image-debian10
>  docker-image-debian-powerpc-test-cross: docker-image-debian11
>  
>  # These images may be good enough for building tests but not for test builds
> @@ -180,6 +198,7 @@ DOCKER_PARTIAL_IMAGES += debian-arm64-test-cross
>  DOCKER_PARTIAL_IMAGES += debian-powerpc-test-cross
>  DOCKER_PARTIAL_IMAGES += debian-hppa-cross
>  DOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross
> +DOCKER_PARTIAL_IMAGES += debian-nios2-cross
>  DOCKER_PARTIAL_IMAGES += debian-riscv64-cross
>  DOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
>  DOCKER_PARTIAL_IMAGES += debian-tricore-cross
> diff --git a/tests/docker/dockerfiles/debian-nios2-cross.docker b/tests/docker/dockerfiles/debian-nios2-cross.docker
> new file mode 100644
> index 0000000000..208737fc5e
> --- /dev/null
> +++ b/tests/docker/dockerfiles/debian-nios2-cross.docker
> @@ -0,0 +1,34 @@
> +#
> +# Docker NIOS2 cross-compiler target
> +#
> +# This docker target is used for building tests. As it also needs to be
> +# able to build QEMU itself in CI we include it's build-deps. It is also
> +# a "stand-alone" image so as not to be triggered by re-builds on other
> +# base images given it takes a long time to build.
> +#
> +FROM qemu/debian10
> +
> +# Install build utilities for building gcc and glibc.
> +# ??? The build-dep isn't working, missing a number of
> +# minimal build dependiencies, e.g. libmpc.
> +
> +RUN apt update && \
> +    DEBIAN_FRONTEND=noninteractive apt install -yy eatmydata && \
> +    DEBIAN_FRONTEND=noninteractive eatmydata \
> +    apt install -y --no-install-recommends \
> +        bison \
> +        flex \
> +        gawk \
> +        libmpc-dev \
> +        libmpfr-dev \
> +        rsync \
> +        texinfo \
> +        wget \
> +        $(apt-get -s build-dep --arch-only gcc | egrep ^Inst | fgrep '[all]' | cut -d\  -f2) \
> +        $(apt-get -s build-dep --arch-only glibc | egrep ^Inst | fgrep '[all]' | cut -d\  -f2)
> +
> +ADD build-toolchain.sh /root/build-toolchain.sh
> +
> +RUN cd /root && ./build-toolchain.sh

We need to split this like in hexagon and have a second stage which does
a:

  COPY --from=0 /usr/local /usr/local

This will limit the size of the final image (and also avoid duplicting
the UID in the hexagon build).

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/9] tests/docker: Add debian-nios2-cross image
  2021-10-12 17:03   ` Alex Bennée
@ 2021-10-12 18:24     ` Richard Henderson
  2021-10-12 18:33       ` Alex Bennée
  2021-10-14  9:34       ` Alex Bennée
  2021-10-14 17:17     ` Richard Henderson
  1 sibling, 2 replies; 26+ messages in thread
From: Richard Henderson @ 2021-10-12 18:24 UTC (permalink / raw)
  To: Alex Bennée; +Cc: marex, crwulff, qemu-devel, laurent

On 10/12/21 10:03 AM, Alex Bennée wrote:
> We need to split this like in hexagon and have a second stage which does
> a:
> 
>    COPY --from=0 /usr/local /usr/local
> 
> This will limit the size of the final image (and also avoid duplicting
> the UID in the hexagon build).

Yeah, well, I had to take that out because it errors out.
I have no idea what that does or means.


r~


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/9] tests/docker: Add debian-nios2-cross image
  2021-10-12 18:24     ` Richard Henderson
@ 2021-10-12 18:33       ` Alex Bennée
  2021-10-14  9:34       ` Alex Bennée
  1 sibling, 0 replies; 26+ messages in thread
From: Alex Bennée @ 2021-10-12 18:33 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Marek Vasut, Chris Wulff, QEMU Developers, Laurent Vivier

[-- Attachment #1: Type: text/plain, Size: 590 bytes --]

It copies from the first stage. Is the compiler installed to a different
path?

On Tue, 12 Oct 2021, 19:24 Richard Henderson, <richard.henderson@linaro.org>
wrote:

> On 10/12/21 10:03 AM, Alex Bennée wrote:
> > We need to split this like in hexagon and have a second stage which does
> > a:
> >
> >    COPY --from=0 /usr/local /usr/local
> >
> > This will limit the size of the final image (and also avoid duplicting
> > the UID in the hexagon build).
>
> Yeah, well, I had to take that out because it errors out.
> I have no idea what that does or means.
>
>
> r~
>

[-- Attachment #2: Type: text/html, Size: 907 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/9] tests/docker: Add debian-nios2-cross image
  2021-10-12 18:24     ` Richard Henderson
  2021-10-12 18:33       ` Alex Bennée
@ 2021-10-14  9:34       ` Alex Bennée
  1 sibling, 0 replies; 26+ messages in thread
From: Alex Bennée @ 2021-10-14  9:34 UTC (permalink / raw)
  To: Richard Henderson; +Cc: marex, crwulff, qemu-devel, laurent


Richard Henderson <richard.henderson@linaro.org> writes:

> On 10/12/21 10:03 AM, Alex Bennée wrote:
>> We need to split this like in hexagon and have a second stage which does
>> a:
>>    COPY --from=0 /usr/local /usr/local
>> This will limit the size of the final image (and also avoid
>> duplicting
>> the UID in the hexagon build).
>
> Yeah, well, I had to take that out because it errors out.
> I have no idea what that does or means.

Having this worked for me:

modified   tests/docker/dockerfiles/debian-nios2-cross.docker
@@ -31,4 +31,14 @@ ADD build-toolchain.sh /root/build-toolchain.sh
 
 RUN cd /root && ./build-toolchain.sh
 
+FROM debian:buster-slim
+# Duplicate deb line as deb-src
+RUN cat /etc/apt/sources.list | sed "s/^deb\ /deb-src /" >> /etc/apt/sources.list
+# Install QEMU build deps for use in CI
+RUN apt update && \
+    DEBIAN_FRONTEND=noninteractive apt install -yy eatmydata && \
+    DEBIAN_FRONTEND=noninteractive eatmydata apt install -yy git ninja-build && \
+    DEBIAN_FRONTEND=noninteractive eatmydata \
+    apt build-dep -yy --arch-only qemu
+COPY --from=0 /usr/local /usr/local
 ENV PATH $PATH:/usr/local/bin/

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/2] tests/docker: Remove fedora-i386-cross from DOCKER_PARTIAL_IMAGES
  2021-10-01 15:33 ` [PATCH 1/2] tests/docker: Remove fedora-i386-cross from DOCKER_PARTIAL_IMAGES Richard Henderson
@ 2021-10-14  9:35   ` Alex Bennée
  0 siblings, 0 replies; 26+ messages in thread
From: Alex Bennée @ 2021-10-14  9:35 UTC (permalink / raw)
  To: Richard Henderson; +Cc: marex, Thomas Huth, crwulff, qemu-devel, laurent


Richard Henderson <richard.henderson@linaro.org> writes:

> The image was upgraded to a full image in ee381b7fe146.
> This makes it possible to use docker-test@image syntax
> with this container.
>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 2/9] linux-user/nios2: Properly emulate EXCP_TRAP
  2021-10-01 15:33 ` [PATCH 2/9] linux-user/nios2: Properly emulate EXCP_TRAP Richard Henderson
@ 2021-10-14  9:36   ` Alex Bennée
  0 siblings, 0 replies; 26+ messages in thread
From: Alex Bennée @ 2021-10-14  9:36 UTC (permalink / raw)
  To: Richard Henderson; +Cc: marex, crwulff, qemu-devel, laurent


Richard Henderson <richard.henderson@linaro.org> writes:

> The real kernel has to load the instruction and extract
> the imm5 field; for qemu, modify the translator to do this.
>
> The use of R_AT for this in cpu_loop was a bug.  Handle
> the other trap numbers as per the kernel's trap_table.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

I'm taking the values of the registers on trust but the change of moving
the error_code seems OK to me:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 2/2] tests/docker: Fix fedora-i386-cross
  2021-10-01 15:33 ` [PATCH 2/2] tests/docker: Fix fedora-i386-cross Richard Henderson
@ 2021-10-14  9:38   ` Alex Bennée
  0 siblings, 0 replies; 26+ messages in thread
From: Alex Bennée @ 2021-10-14  9:38 UTC (permalink / raw)
  To: Richard Henderson
  Cc: marex, Daniel P . Berrangé,
	Richard W . M . Jones, crwulff, qemu-devel, laurent,
	Paolo Bonzini


Richard Henderson <richard.henderson@linaro.org> writes:

> By using PKG_CONFIG_PATH instead of PKG_CONFIG_LIBDIR,
> we were still including the 64-bit packages.  Install
> pcre-devel.i686 to fill a missing glib2 dependency.
>
> By using --extra-cflags instead of --cpu, we incorrectly
> use the wrong probing during meson.
>
> Cc: Alex Bennée <alex.bennee@linaro.org>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Daniel P. Berrangé <berrange@redhat.com>
> Cc: Richard W.M. Jones <rjones@redhat.com>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 3/9] linux-user/nios2: Fixes for signal frame setup
  2021-10-01 15:33 ` [PATCH 3/9] linux-user/nios2: Fixes for signal frame setup Richard Henderson
@ 2021-10-14  9:43   ` Alex Bennée
  0 siblings, 0 replies; 26+ messages in thread
From: Alex Bennée @ 2021-10-14  9:43 UTC (permalink / raw)
  To: Richard Henderson; +Cc: marex, Peter Maydell, crwulff, qemu-devel, laurent


Richard Henderson <richard.henderson@linaro.org> writes:

> Do not confuse host and guest addresses.  Lock and unlock
> the target_rt_sigframe structure in setup_rt_sigframe.
>
> Since rt_setup_ucontext always returns 0, drop the return
> value entirely.  This eliminates the only write to the err
> variable in setup_rt_sigframe.
>
> Always copy the siginfo structure.
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> Message-Id: <20210924165926.752809-19-richard.henderson@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/9] tests/docker: Add debian-nios2-cross image
  2021-10-12 17:03   ` Alex Bennée
  2021-10-12 18:24     ` Richard Henderson
@ 2021-10-14 17:17     ` Richard Henderson
  2021-10-14 17:25       ` Alex Bennée
  1 sibling, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2021-10-14 17:17 UTC (permalink / raw)
  To: Alex Bennée; +Cc: marex, crwulff, qemu-devel, laurent

On 10/12/21 10:03 AM, Alex Bennée wrote:
> We need^H^H^H^H (might need, see bellow) a separate patch with:
> 
> docker-image-debian10: NOUSER=1
> 
> to ensure the images we base our "handbuilt" compilers on don't include
> a potentially clashing uid (which should only be added for local
> builds).

I think we ought to push this further back into docker.py.

I think that we should always have a separate image without the user installed.  When 
asking for a build with user installed, copy the nouser image (perhaps cached) and simply 
add the user.

> We need to split this like in hexagon and have a second stage which does
> a:
> 
>    COPY --from=0 /usr/local /usr/local
> 
> This will limit the size of the final image (and also avoid duplicting
> the UID in the hexagon build).

What are we eliminating from the image with the second FROM, since we then go back and add 
in all the build-dep for qemu.

There are one or two extra packages required for building gcc itself (e.g. libmpc) but 
they're not large.  Where does the major savings come from?


r~


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/9] tests/docker: Add debian-nios2-cross image
  2021-10-14 17:17     ` Richard Henderson
@ 2021-10-14 17:25       ` Alex Bennée
  0 siblings, 0 replies; 26+ messages in thread
From: Alex Bennée @ 2021-10-14 17:25 UTC (permalink / raw)
  To: Richard Henderson; +Cc: marex, crwulff, qemu-devel, laurent


Richard Henderson <richard.henderson@linaro.org> writes:

> On 10/12/21 10:03 AM, Alex Bennée wrote:
>> We need^H^H^H^H (might need, see bellow) a separate patch with:
>> docker-image-debian10: NOUSER=1
>> to ensure the images we base our "handbuilt" compilers on don't
>> include
>> a potentially clashing uid (which should only be added for local
>> builds).
>
> I think we ought to push this further back into docker.py.
>
> I think that we should always have a separate image without the user
> installed.  When asking for a build with user installed, copy the
> nouser image (perhaps cached) and simply add the user.
>
>> We need to split this like in hexagon and have a second stage which does
>> a:
>>    COPY --from=0 /usr/local /usr/local
>> This will limit the size of the final image (and also avoid
>> duplicting
>> the UID in the hexagon build).
>
> What are we eliminating from the image with the second FROM, since we
> then go back and add in all the build-dep for qemu.
>
> There are one or two extra packages required for building gcc itself
> (e.g. libmpc) but they're not large.  Where does the major savings
> come from?

Hmm that is curious:

 $ docker history registry.gitlab.com/qemu-project/qemu/qemu/debian-nios2-cross:latest
 ...
  <missing>      2 weeks ago   RUN /bin/sh -c id rth 2>/dev/null || useradd…   330kB     buildkit.dockerfile.v0
  <missing>      2 weeks ago   LABEL com.qemu./home/rth/qemu/git-alt/tests/…   0B        buildkit.dockerfile.v0
  <missing>      2 weeks ago   LABEL com.qemu.dockerfile-checksum=fc3e779ae…   0B        buildkit.dockerfile.v0
  <missing>      2 weeks ago   ENV PATH=/usr/local/sbin:/usr/local/bin:/usr…   0B        buildkit.dockerfile.v0
  <missing>      2 weeks ago   RUN /bin/sh -c cd /root && ./build-toolchain…   973MB     buildkit.dockerfile.v0
  <missing>      2 weeks ago   ADD build-toolchain.sh /root/build-toolchain…   2.14kB    buildkit.dockerfile.v0
  <missing>      2 weeks ago   RUN /bin/sh -c apt update &&     DEBIAN_FRON…   17.3MB    buildkit.dockerfile.v0
  <missing>      2 weeks ago   /bin/sh -c #(nop)  LABEL com.qemu.dockerfile…   0B   
  <missing>      2 weeks ago   /bin/sh -c apt update &&     DEBIAN_FRONTEND…   715MB
  <missing>      2 weeks ago   /bin/sh -c cat /etc/apt/sources.list | sed "…   854B              
  <missing>      2 weeks ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B                               
  <missing>      2 weeks ago   /bin/sh -c #(nop) ADD file:99db7cfe7952a1c7a…   69.2MB                           

yet with the split build:

  $ docker image history qemu/debian-nios2-cross:latest                                                        
  IMAGE          CREATED        CREATED BY                                      SIZE      COMMENT               
  24fbdeba931c   4 hours ago    LABEL com.qemu./home/alex.bennee/lsrc/qemu.g…   0B        buildkit.dockerfile.v0
  <missing>      4 hours ago    LABEL com.qemu.dockerfile-checksum=e7d3631e6…   0B        buildkit.dockerfile.v0
  <missing>      4 hours ago    ENV PATH=/usr/local/sbin:/usr/local/bin:/usr…   0B        buildkit.dockerfile.v0
  <missing>      4 hours ago    COPY /usr/local /usr/local # buildkit           1.77GB    buildkit.dockerfile.v0
  <missing>      4 hours ago    RUN /bin/sh -c apt update &&     DEBIAN_FRON…   781MB     buildkit.dockerfile.v0
  <missing>      4 hours ago    RUN /bin/sh -c cat /etc/apt/sources.list | s…   854B      buildkit.dockerfile.v0
  <missing>      7 months ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B                             
  <missing>      7 months ago   /bin/sh -c #(nop) ADD file:3c32f1cd03198e141…   69.2MB          

which makes it look like the artefacts are bigger than the whole build.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2021-10-15 13:27 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 15:33 [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson
2021-10-01 15:33 ` [PATCH 1/9] tests/docker: Add debian-nios2-cross image Richard Henderson
2021-10-12 17:03   ` Alex Bennée
2021-10-12 18:24     ` Richard Henderson
2021-10-12 18:33       ` Alex Bennée
2021-10-14  9:34       ` Alex Bennée
2021-10-14 17:17     ` Richard Henderson
2021-10-14 17:25       ` Alex Bennée
2021-10-01 15:33 ` [PATCH 1/2] tests/docker: Remove fedora-i386-cross from DOCKER_PARTIAL_IMAGES Richard Henderson
2021-10-14  9:35   ` Alex Bennée
2021-10-01 15:33 ` [PATCH 2/9] linux-user/nios2: Properly emulate EXCP_TRAP Richard Henderson
2021-10-14  9:36   ` Alex Bennée
2021-10-01 15:33 ` [PATCH 2/2] tests/docker: Fix fedora-i386-cross Richard Henderson
2021-10-14  9:38   ` Alex Bennée
2021-10-01 15:33 ` [PATCH 3/9] linux-user/nios2: Fixes for signal frame setup Richard Henderson
2021-10-14  9:43   ` Alex Bennée
2021-10-01 15:33 ` [PATCH 4/9] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE Richard Henderson
2021-10-12  6:11   ` Laurent Vivier
2021-10-01 15:33 ` [PATCH 5/9] linux-user/nios2: Map a real kuser page Richard Henderson
2021-10-01 15:33 ` [PATCH 6/9] linux-user/nios2: Fix EA vs PC confusion Richard Henderson
2021-10-01 15:33 ` [PATCH 7/9] linux-user/nios2: Fix sigmask in setup_rt_frame Richard Henderson
2021-10-12  6:16   ` Laurent Vivier
2021-10-01 15:33 ` [PATCH 8/9] linux-user/nios2: Use set_sigmask in do_rt_sigreturn Richard Henderson
2021-10-12  6:29   ` Laurent Vivier
2021-10-01 15:33 ` [PATCH 9/9] tests/tcg: Enable container_cross_cc for nios2 Richard Henderson
2021-10-11 19:06 ` [PATCH 0/9] nios2: Enable cross compile and fix signals Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.