From patchwork Mon Jul 23 12:56:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 947763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Z1jm2lkBz9s29 for ; Mon, 23 Jul 2018 22:57:30 +1000 (AEST) Received: from localhost ([::1]:34492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhaP1-0004zc-JG for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2018 08:57:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhaOR-0004zU-5g for qemu-devel@nongnu.org; Mon, 23 Jul 2018 08:56:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhaOO-0007d0-4d for qemu-devel@nongnu.org; Mon, 23 Jul 2018 08:56:51 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:41216) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhaON-0007ck-R8 for qemu-devel@nongnu.org; Mon, 23 Jul 2018 08:56:48 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.167]) with ESMTPSA (Nemesis) id 0M4PCy-1fvfrs3pk4-00yi29; Mon, 23 Jul 2018 14:56:37 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 14:56:23 +0200 Message-Id: <20180723125624.18863-2-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723125624.18863-1-laurent@vivier.eu> References: <20180723125624.18863-1-laurent@vivier.eu> X-Provags-ID: V03:K1:h8eGkXeiUzNFWoeBZ5I+4h92uZY/hDBTAJzh7abA+dkfQ9Rr6pD tPwf4E23JvGKo4pos0fs/FocIGdHne6V+NbIooB31feyyOSpMQaX+NNVJreFtFjOH8OvgHz o2EtqSd+ROWZi4mkcQUl1rPMcr1oHGX6VsiaDPJZTwMR0Uw4eSPKhU8RejOP829cijAzrLv 4UD81bxp+Oqjjc8YOdJRA== X-UI-Out-Filterresults: notjunk:1; V01:K0:fbiseTpx7Ws=:c8jmQHe+kE4a0kffaESt+7 LcoFwO5uJ+B53djE8qOJdgsG7sxHW7d+ut48gE9AOsSDf6VdJJl85VvcyTtFrnY6pa9Nrsjoh TwKuZ/tRp063KpA8GVsSl6b61RSWCCYPEzW0vAQUK/9EVWweUIO2tl7HhMydrn75bIXnsZwxE y8r8etHTrvmPQsqupGIo8OW/N8CByxddrgnuCmUn5IAKGRwvf+QqS8khPezd9xAUPgyhIcnHD NcfP7NyaHuO9KTtxK0LUP5NdhnpcADde1wzHvi79gcAfnGpas4PoEUUM2HJhRGSyVmP9EsEPM UNsaVbgv64JWfRU2YNwxZncM+lqWoja2iDChVGm88hWfz64oLd11jnC7xPkfy0lkUsuUw8rg9 Q04mNL+yYFDe1BeaFd6F1I8Q1WPvI5OwS8k/OkoxWfifFjFpnJfbCNKawKpDJOW0MtsNn6G7A 8jmGtSH7XPgckw8JAkLCBGGyh5LeTLIas6Y3+AJsCMSOYPLv1DixDoZzUtMU1JO0OSJ3FxLyD KLSzsaaKol7Bdfze+2s2yw6Yv5cpJhJ2rUKs8f5qlZJoXY24Dmnz5WoK2QliaHQujdbxleh/o nG250APSLYufRQ93SvHXUkO2Feij6+fORJz6l83mX6FgCPM7LmYbBvGYEosFXJtthH6U5fg00 7rZ08/8UhgYmue+CzFkGeA6OmBzwXZMgboX8T590Tw4aAAgGUbeIcN+5z2+zGPTmfQn4= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.131 Subject: [Qemu-devel] [PULL 1/2] linux-user: fix ELF load alignment error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Richard Henderson [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; From patchwork Mon Jul 23 12:56:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 947778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Z1mG2Dx0z9s29 for ; Mon, 23 Jul 2018 22:59:42 +1000 (AEST) Received: from localhost ([::1]:34502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhaR9-0006Qa-Vx for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2018 08:59:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhaOX-000529-Rw for qemu-devel@nongnu.org; Mon, 23 Jul 2018 08:57:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhaOU-0007fR-RL for qemu-devel@nongnu.org; Mon, 23 Jul 2018 08:56:57 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:40859) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhaOU-0007ey-EV for qemu-devel@nongnu.org; Mon, 23 Jul 2018 08:56:54 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MWcQg-1fX6231quY-00XeUN; Mon, 23 Jul 2018 14:56:37 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 14:56:24 +0200 Message-Id: <20180723125624.18863-3-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723125624.18863-1-laurent@vivier.eu> References: <20180723125624.18863-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:ratF6hiCl01Jo2gmZbpwoleYJI7dyrvbjGIuDzZC8r7WV9MMm6u sH9Fjbyaq99xhATLqx67/PbEVYULhHokBuFqdF7tTA3gTkFlT2vnkff7hYgG9z7Xxxqai7v EHMxE4HBPOf4auObLIDc8l2KIDqmPz7k8jAguhiuCvihpK9kr2DSX7SWrE6EviKoVogRXm1 a1W1ZEMIjsVt6m7ozBjuQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:rQHoxcpY/34=:KiyxR0PRAadwPb0HvAl0rD pXOsmqMU0kOgNlmuc1xR+EFbURMPT9RhtgvAbuZqPCjxtoZNsKYjUUwDBLEANNd1n5LSb4pg1 zSQQ15XVqAD3KverXhv/GTageFmQHiCHpHu2wR2WK0XvNcKPA/bwD0iomdYWoJWxgF5GJy5Pd oapC8Gq1tMgbk8pZ3ghJIqfo1T35dov+TGSVW9jHvEgMomyALamLPvvjlXGdRhXGZRFq5SPMp vlaVD9efs3WaDxoTIYAoCAts1wd3WxOnba9uQOFLQ0UJ+Oxha62N/2nAz9cR7PoQZgIgLiI3P sTW9m7Fbk9XttJjB+19NMHaEVw1T3eLuJHbw+zGWZauE8MK6/ssRtY8Ssz7jrxeSPy0ughj7i wqfgrzLRWS8nVrzHcS9mYxOSmC+UG1dkdy0iQjyhiXKo5op56zrPrAVf72jF55KiPUqZxoEDG KrCnjTDZSPxm0eiwVam+t61xkdePSqMsICLICL2haSeLjYrx4Gr1JAdQAvxfjj52VbQ5bYXW7 wXU6o/JeqN2Qle/rmReHjwZQUGUs7/Zf2uCqNp9xHiaxL4RNEOXIqz++tXf+f7Kbk5xZZGCng DRi4itS0iscUTZXH2zjFBvOL8d8twALN8OHGATQZ2zCFSqxx974kxgE6yjzyTSmo1WwreAwg/ NiZqIBpFEKQYKezm2kVmfW5LRlQ+jtlCupP06HAE5zZyxd4F9gQLcE3sE96cGcJCfzq0U+Z3X D5gT1GdVCoSy+jJg X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.134 Subject: [Qemu-devel] [PULL 2/2] linux-user/ppc: Implement swapcontext syscall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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 Tested-by: Alex Bennée Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Laurent Vivier 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: