All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches
@ 2018-07-23 12:56 Laurent Vivier
  2018-07-23 12:56 ` [Qemu-devel] [PULL 1/2] linux-user: fix ELF load alignment error Laurent Vivier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Laurent Vivier @ 2018-07-23 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier

The following changes since commit 5b3ecd3d941a0ae8a8cfbba5ab8139b2bf104822:

  Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180719' into staging (2018-07-20 11:08:33 +0100)

are available in the Git repository at:

  git://github.com/vivier/qemu.git tags/linux-user-for-3.0-pull-request

for you to fetch changes up to fa97e38eed3bbdbc322d94092ca49450e724fff1:

  linux-user/ppc: Implement swapcontext syscall (2018-07-22 21:33:45 +0200)

----------------------------------------------------------------
Some ppc/ppc64 fixes:
- we can run now most of the targets on a ppc64 host with 64kB pages
- add swapcontext syscall to run tests/test-coroutine in
  debian-powerpc-user-cross

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

Laurent Vivier (1):
  linux-user: fix ELF load alignment error

Richard Henderson (1):
  linux-user/ppc: Implement swapcontext syscall

 linux-user/elfload.c    | 10 +++++++-
 linux-user/ppc/signal.c | 56 +++++++++++++++++++++++++++++++++++++++++
 linux-user/qemu.h       |  3 +++
 linux-user/syscall.c    |  6 +++++
 4 files changed, 74 insertions(+), 1 deletion(-)

-- 
2.17.1

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

* [Qemu-devel] [PULL 1/2] linux-user: fix ELF load alignment error
  2018-07-23 12:56 [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches Laurent Vivier
@ 2018-07-23 12:56 ` Laurent Vivier
  2018-07-23 12:56 ` [Qemu-devel] [PULL 2/2] linux-user/ppc: Implement swapcontext syscall Laurent Vivier
  2018-07-23 14:15 ` [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2018-07-23 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier

When we try to use some targets on ppc64, it can happen the target
doesn't support the host page size to align ELF load sections and
fails with:

  ELF load command alignment not page-aligned

Since commit a70daba3771 ("linux-user: Tell guest about big host
page sizes") the host page size is used to align ELF sections, but
this doesn't work if the alignment required by the load section is
smaller than the host one.  For these cases, we continue to use the
TARGET_PAGE_SIZE instead of the host one.

I have tested this change on ppc64, and it fixes qemu linux-user for:
  s390x, m68k, i386, arm, aarch64, hppa
and I have tested it doesn't break the following targets:
  x86_64, mips64el, sh4
mips and mipsel abort, but I think for another reason.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
[lv: fixed "info->alignment = 0"]
Message-Id: <20180716195349.29959-1-laurent@vivier.eu>
---
 linux-user/elfload.c | 10 +++++++++-
 linux-user/qemu.h    |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 942a1b661f..df07055361 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1875,7 +1875,13 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     NEW_AUX_ENT(AT_PHDR, (abi_ulong)(info->load_addr + exec->e_phoff));
     NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr)));
     NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum));
-    NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(MAX(TARGET_PAGE_SIZE, getpagesize())));
+    if ((info->alignment & ~qemu_host_page_mask) != 0) {
+        /* Target doesn't support host page size alignment */
+        NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE));
+    } else {
+        NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(MAX(TARGET_PAGE_SIZE,
+                                               qemu_host_page_size)));
+    }
     NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_info ? interp_info->load_addr : 0));
     NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0);
     NEW_AUX_ENT(AT_ENTRY, info->entry);
@@ -2202,6 +2208,7 @@ static void load_elf_image(const char *image_name, int image_fd,
     /* Find the maximum size of the image and allocate an appropriate
        amount of memory to handle that.  */
     loaddr = -1, hiaddr = 0;
+    info->alignment = 0;
     for (i = 0; i < ehdr->e_phnum; ++i) {
         if (phdr[i].p_type == PT_LOAD) {
             abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset;
@@ -2213,6 +2220,7 @@ static void load_elf_image(const char *image_name, int image_fd,
                 hiaddr = a;
             }
             ++info->nsegs;
+            info->alignment |= phdr[i].p_align;
         }
     }
 
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index bb85c81aa4..7b16a1cdea 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -51,6 +51,7 @@ struct image_info {
         abi_ulong       file_string;
         uint32_t        elf_flags;
 	int		personality;
+        abi_ulong       alignment;
 
         /* The fields below are used in FDPIC mode.  */
         abi_ulong       loadmap_addr;
-- 
2.17.1

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

* [Qemu-devel] [PULL 2/2] linux-user/ppc: Implement swapcontext syscall
  2018-07-23 12:56 [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches Laurent Vivier
  2018-07-23 12:56 ` [Qemu-devel] [PULL 1/2] linux-user: fix ELF load alignment error Laurent Vivier
@ 2018-07-23 12:56 ` Laurent Vivier
  2018-07-23 14:15 ` [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2018-07-23 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier, Richard Henderson

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

This allows the tests generated by debian-powerpc-user-cross
to function properly, especially tests/test-coroutine.

Technically this syscall is available to both ppc32 and ppc64,
but only ppc32 glibc actually uses it.  Thus the ppc64 path is
untested.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20180718200648.22529-1-richard.henderson@linaro.org>
---
 linux-user/ppc/signal.c | 56 +++++++++++++++++++++++++++++++++++++++++
 linux-user/qemu.h       |  2 ++
 linux-user/syscall.c    |  6 +++++
 3 files changed, 64 insertions(+)

diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c
index ef4c518f11..2ae120a2bc 100644
--- a/linux-user/ppc/signal.c
+++ b/linux-user/ppc/signal.c
@@ -675,3 +675,59 @@ sigsegv:
     force_sig(TARGET_SIGSEGV);
     return -TARGET_QEMU_ESIGRETURN;
 }
+
+/* This syscall implements {get,set,swap}context for userland.  */
+abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx,
+                        abi_ulong unew_ctx, abi_long ctx_size)
+{
+    struct target_ucontext *uctx;
+    struct target_mcontext *mctx;
+
+    /* For ppc32, ctx_size is "reserved for future use".
+     * For ppc64, we do not yet support the VSX extension.
+     */
+    if (ctx_size < sizeof(struct target_ucontext)) {
+        return -TARGET_EINVAL;
+    }
+
+    if (uold_ctx) {
+        TaskState *ts = (TaskState *)thread_cpu->opaque;
+
+        if (!lock_user_struct(VERIFY_WRITE, uctx, uold_ctx, 1)) {
+            return -TARGET_EFAULT;
+        }
+
+#ifdef TARGET_PPC64
+        mctx = &uctx->tuc_sigcontext.mcontext;
+#else
+        /* ??? The kernel aligns the pointer down here into padding, but
+         * in setup_rt_frame we don't.  Be self-compatible for now.
+         */
+        mctx = &uctx->tuc_mcontext;
+        __put_user(h2g(mctx), &uctx->tuc_regs);
+#endif
+
+        save_user_regs(env, mctx);
+        host_to_target_sigset(&uctx->tuc_sigmask, &ts->signal_mask);
+
+        unlock_user_struct(uctx, uold_ctx, 1);
+    }
+
+    if (unew_ctx) {
+        int err;
+
+        if (!lock_user_struct(VERIFY_READ, uctx, unew_ctx, 1)) {
+            return -TARGET_EFAULT;
+        }
+        err = do_setcontext(uctx, env, 0);
+        unlock_user_struct(uctx, unew_ctx, 1);
+
+        if (err) {
+            /* We cannot return to a partially updated context.  */
+            force_sig(TARGET_SIGSEGV);
+        }
+        return -TARGET_QEMU_ESIGRETURN;
+    }
+
+    return 0;
+}
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 7b16a1cdea..b4959e41c6 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -396,6 +396,8 @@ long do_sigreturn(CPUArchState *env);
 long do_rt_sigreturn(CPUArchState *env);
 abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp);
 int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
+abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx,
+                        abi_ulong unew_ctx, abi_long ctx_size);
 /**
  * block_signals: block all signals while handling this guest syscall
  *
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3df3bdffb2..dfc851cc35 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -12790,6 +12790,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(kcmp(arg1, arg2, arg3, arg4, arg5));
         break;
 #endif
+#ifdef TARGET_NR_swapcontext
+    case TARGET_NR_swapcontext:
+        /* PowerPC specific.  */
+        ret = do_swapcontext(cpu_env, arg1, arg2, arg3);
+        break;
+#endif
 
     default:
     unimplemented:
-- 
2.17.1

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

* Re: [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches
  2018-07-23 12:56 [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches Laurent Vivier
  2018-07-23 12:56 ` [Qemu-devel] [PULL 1/2] linux-user: fix ELF load alignment error Laurent Vivier
  2018-07-23 12:56 ` [Qemu-devel] [PULL 2/2] linux-user/ppc: Implement swapcontext syscall Laurent Vivier
@ 2018-07-23 14:15 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2018-07-23 14:15 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: QEMU Developers, Riku Voipio

On 23 July 2018 at 13:56, Laurent Vivier <laurent@vivier.eu> wrote:
> The following changes since commit 5b3ecd3d941a0ae8a8cfbba5ab8139b2bf104822:
>
>   Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180719' into staging (2018-07-20 11:08:33 +0100)
>
> are available in the Git repository at:
>
>   git://github.com/vivier/qemu.git tags/linux-user-for-3.0-pull-request
>
> for you to fetch changes up to fa97e38eed3bbdbc322d94092ca49450e724fff1:
>
>   linux-user/ppc: Implement swapcontext syscall (2018-07-22 21:33:45 +0200)
>
> ----------------------------------------------------------------
> Some ppc/ppc64 fixes:
> - we can run now most of the targets on a ppc64 host with 64kB pages
> - add swapcontext syscall to run tests/test-coroutine in
>   debian-powerpc-user-cross
>
> ----------------------------------------------------------------

Applied, thanks.

-- PMM

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

end of thread, other threads:[~2018-07-23 14:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-23 12:56 [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches Laurent Vivier
2018-07-23 12:56 ` [Qemu-devel] [PULL 1/2] linux-user: fix ELF load alignment error Laurent Vivier
2018-07-23 12:56 ` [Qemu-devel] [PULL 2/2] linux-user/ppc: Implement swapcontext syscall Laurent Vivier
2018-07-23 14:15 ` [Qemu-devel] [PULL 0/2] Linux user for 3.0 patches Peter Maydell

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.