From patchwork Fri Feb 16 21:56:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 128649 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1015893ljc; Fri, 16 Feb 2018 13:56:46 -0800 (PST) X-Google-Smtp-Source: AH8x224DuEPQWzpVHn3U9yJSQQ30ld2I8kJMFYiV7llHS/cINYYPW9b2zgdbgittE+Gp+5LDseFc X-Received: by 10.13.211.130 with SMTP id v124mr5875632ywd.476.1518818206090; Fri, 16 Feb 2018 13:56:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518818206; cv=none; d=google.com; s=arc-20160816; b=gU0AE2hszw+JNbi1lE8Mm++6nIc0uOvL3Pqf9pxsmJYoqyOsAT/BlOgfBxgCMb43MJ O5a0aI2PlQi9QH7WUp2NQ53FHYIvHY1MjfQnWHctg1rlVt3kHtOaDx6gosOwTRVjS7ki l2bc6fl3d/nXPsVQkHvVMAPxW3DwByRKglDGnVAjmCQ5VDQywwJy7RqMebgunAE+xa3w Iqt3Sf/p9Z8P2TVpkQN/wMTpuyB0hyBib7PwP7sZRi/Q9jxj63csVM4E/YMghWgx1DtO q3KhosHqi4cdB3qhTjXJpQIe35A0RMxk5uysS5xHbN1v0uexAfp2t4PekgjrB5CahwPH f7zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=bnjIeJ0zUZZdzLcpfwGGLtbGySP4npCBOMdTQxqIDAs=; b=RKDHt1yf7TzbKh7iCtOVUuca1yc4jYhHaYB+NJ/YQqtrTC7g84/AVn4Ualjh5cLBO1 PzWOUZTp5E/s0CeFGWniJfTkjvYtt/o73ySP542OZ9LwLAtsEnldQHI9Glof6bEJZ1+i Rf7D91uJWqxUggGaysJ91MMRUQ7IG38Ymu2ouLpq0ca1rCPpDFkVffWTr+XPQhJprwaH CiK+oLF2F7cyMegujgNHbqXI9Iy34pC+zdmgq+zY2DE/wjHyDGtuPN1zozAVKxg83ODd nw1zzhEFYL9ZZYT7DKmqVs7gGEz096eMTyvbgTf7IxgtKG5eeLkDHwEoJ1YXhd2DBwnS yFxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XRj4Yi8M; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x4si406657ybc.232.2018.02.16.13.56.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 16 Feb 2018 13:56:46 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XRj4Yi8M; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emnzp-0006nQ-BL for patch@linaro.org; Fri, 16 Feb 2018 16:56:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emnzQ-0006l4-0U for qemu-devel@nongnu.org; Fri, 16 Feb 2018 16:56:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emnzO-0007Pk-G1 for qemu-devel@nongnu.org; Fri, 16 Feb 2018 16:56:20 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:44084) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1emnzO-0007PN-7y for qemu-devel@nongnu.org; Fri, 16 Feb 2018 16:56:18 -0500 Received: by mail-pg0-x243.google.com with SMTP id l4so1283636pgp.11 for ; Fri, 16 Feb 2018 13:56:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bnjIeJ0zUZZdzLcpfwGGLtbGySP4npCBOMdTQxqIDAs=; b=XRj4Yi8MHlqcWguTap5qyygqNLHKGe/nfD55iTa5ta/Ky5DW3jYJ0djhmIt2njF+Lv tuO95nB+MyfO26/8N4Q0sMxJe9MdXaeJJ1ZC83Ih5nE6peB4Jgp5jLnPD6dHTCpwWZWm QeKmtl1mR1djYy2gh4Efnro0pqmVkAhJU9lAY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bnjIeJ0zUZZdzLcpfwGGLtbGySP4npCBOMdTQxqIDAs=; b=ZI3r3e6Y/7ceFWsLWietvIBfuBvNeNeFMVhJpsrGcopizc0B0i4Jcntm2YXA+6JpU4 e3QrE8bZIJdgspy7qRYi7Fonc61iKpt7Pn2OzlG/Gi/7mRE90z6OSdytybnG6iaw8sbF Ws8Mz99D3LcQZNvybqeY4dTS97oBE2Iu5Hn2fTTIBq4iPn0KrkWqNcTclbc+4ybNYP+J /h8tfz+gGR7jh4t7eXI4x5acoHHQBLG94F74ZKnF6WBfkQ2mKfnyj+VV/wST2IgkJWdU CP9cmNKyhyl8bTWe+wykhiPq6I25F3YNhp6SKGQBoMeyUfvUIOCyJ7iloZbyREwjiYd1 Bp1g== X-Gm-Message-State: APf1xPAZJCI7pO9hJbZ+Er5gORu0BAIPLBXLr/2vWWqkBk2/l9f0ix1k ZyFJSNwWLRxEJfTK7jmfOHstYJELtPM= X-Received: by 10.99.152.70 with SMTP id l6mr6026584pgo.87.1518818176741; Fri, 16 Feb 2018 13:56:16 -0800 (PST) Received: from cloudburst.twiddle.net ([50.0.192.64]) by smtp.gmail.com with ESMTPSA id b88sm39230538pfd.108.2018.02.16.13.56.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2018 13:56:15 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 13:56:06 -0800 Message-Id: <20180216215608.13227-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180216215608.13227-1-richard.henderson@linaro.org> References: <20180216215608.13227-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v3 3/5] aarch64-linux-user: Remove struct target_aux_context 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This changes the qemu signal frame layout to be more like the kernel's, in that the various records are dynamically allocated rather than fixed in place by a structure. For now, all of the allocation is out of uc.tuc_mcontext.__reserved, so the allocation is actually trivial. That will change with SVE support. Signed-off-by: Richard Henderson --- linux-user/signal.c | 89 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 28 deletions(-) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/linux-user/signal.c b/linux-user/signal.c index 25c9743aed..f9eef3d753 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -1443,20 +1443,12 @@ struct target_fpsimd_context { uint64_t vregs[32 * 2]; /* really uint128_t vregs[32] */ }; -/* - * Auxiliary context saved in the sigcontext.__reserved array. Not exported to - * user space as it will change with the addition of new context. User space - * should check the magic/size information. - */ -struct target_aux_context { - struct target_fpsimd_context fpsimd; - /* additional context to be added before "end" */ - struct target_aarch64_ctx end; -}; - struct target_rt_sigframe { struct target_siginfo info; struct target_ucontext uc; +}; + +struct target_rt_frame_record { uint64_t fp; uint64_t lr; uint32_t tramp[2]; @@ -1562,20 +1554,47 @@ static void target_restore_fpsimd_record(CPUARMState *env, static int target_restore_sigframe(CPUARMState *env, struct target_rt_sigframe *sf) { - struct target_aux_context *aux - = (struct target_aux_context *)sf->uc.tuc_mcontext.__reserved; - uint32_t magic, size; + struct target_aarch64_ctx *ctx; + struct target_fpsimd_context *fpsimd = NULL; target_restore_general_frame(env, sf); - __get_user(magic, &aux->fpsimd.head.magic); - __get_user(size, &aux->fpsimd.head.size); - if (magic == TARGET_FPSIMD_MAGIC - && size == sizeof(struct target_fpsimd_context)) { - target_restore_fpsimd_record(env, &aux->fpsimd); - } else { + ctx = (struct target_aarch64_ctx *)sf->uc.tuc_mcontext.__reserved; + while (ctx) { + uint32_t magic, size; + + __get_user(magic, &ctx->magic); + __get_user(size, &ctx->size); + switch (magic) { + case 0: + if (size != 0) { + return 1; + } + ctx = NULL; + continue; + + case TARGET_FPSIMD_MAGIC: + if (fpsimd || size != sizeof(struct target_fpsimd_context)) { + return 1; + } + fpsimd = (struct target_fpsimd_context *)ctx; + break; + + default: + /* Unknown record -- we certainly didn't generate it. + * Did we in fact get out of sync? + */ + return 1; + } + ctx = (void *)ctx + size; + } + + /* Require FPSIMD always. */ + if (!fpsimd) { return 1; } + target_restore_fpsimd_record(env, fpsimd); + return 0; } @@ -1601,20 +1620,33 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUARMState *env) { + int size = offsetof(struct target_rt_sigframe, uc.tuc_mcontext.__reserved); + int fpsimd_ofs, end1_ofs, fr_ofs; struct target_rt_sigframe *frame; - struct target_aux_context *aux; + struct target_rt_frame_record *fr; abi_ulong frame_addr, return_addr; + fpsimd_ofs = size; + size += sizeof(struct target_fpsimd_context); + end1_ofs = size; + size += sizeof(struct target_aarch64_ctx); + fr_ofs = size; + size += sizeof(struct target_rt_frame_record); + frame_addr = get_sigframe(ka, env); trace_user_setup_frame(env, frame_addr); if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { goto give_sigsegv; } - aux = (struct target_aux_context *)frame->uc.tuc_mcontext.__reserved; target_setup_general_frame(frame, env, set); - target_setup_fpsimd_record(&aux->fpsimd, env); - target_setup_end_record(&aux->end); + target_setup_fpsimd_record((void *)frame + fpsimd_ofs, env); + target_setup_end_record((void *)frame + end1_ofs); + + /* Set up the stack frame for unwinding. */ + fr = (void *)frame + fr_ofs; + __put_user(env->xregs[29], &fr->fp); + __put_user(env->xregs[30], &fr->lr); if (ka->sa_flags & TARGET_SA_RESTORER) { return_addr = ka->sa_restorer; @@ -1624,13 +1656,14 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, * Since these are instructions they need to be put as little-endian * regardless of target default or current CPU endianness. */ - __put_user_e(0xd2801168, &frame->tramp[0], le); - __put_user_e(0xd4000001, &frame->tramp[1], le); - return_addr = frame_addr + offsetof(struct target_rt_sigframe, tramp); + __put_user_e(0xd2801168, &fr->tramp[0], le); + __put_user_e(0xd4000001, &fr->tramp[1], le); + return_addr = frame_addr + fr_ofs + + offsetof(struct target_rt_frame_record, tramp); } env->xregs[0] = usig; env->xregs[31] = frame_addr; - env->xregs[29] = env->xregs[31] + offsetof(struct target_rt_sigframe, fp); + env->xregs[29] = frame_addr + fr_ofs; env->pc = ka->_sa_handler; env->xregs[30] = return_addr; if (info) {