From patchwork Mon Feb 4 13:12:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 157416 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3922432jaa; Mon, 4 Feb 2019 05:34:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN54gBKbxPGs5ll+C5ZhjzJ+62Bm+Tf/tlmJon2lZbyc+91xXDXwk4jLHLvJMe2w/rT0sfV1 X-Received: by 2002:a81:9ad8:: with SMTP id r207mr47355494ywg.72.1549287245782; Mon, 04 Feb 2019 05:34:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549287245; cv=none; d=google.com; s=arc-20160816; b=yyeARcIpxgxdXcol0sADgPzEZtQDIrS1/mr7rCAe8mPmrW0D1/XnUDMjVp3O+Ma48T Q3/6rZI6lObpKjjhi8jX8Ui7MkldaGlIZ93R9oYSxY62edy/qao3sYVhQBvv2hxDF+MX 7aamAEk/85WBtchhz6ELmUYCKBdLb95/VfI3q96rNe719VUANpw0f5dQUhP81X1VJz0u QV92975KhxDPSN702GdOq9Vb7CoSII0/m4pK43hBx6FQ9gxkVvhPoZJMkr+HTLzvbNTz w8hRacpntHMBBWyC/9ihRYQS9CuU0Yh0tQf0m2inmJO5n3zZQn0llty90sPXihI/xlcC Py7Q== 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; bh=1yNoac1ShBnXw/zdOxjpmLH8NTh7CPRm4nWUT3FtlnU=; b=LpNjxmJEIlTo/azTfcxFqfbMQq+H9iW2PN/gsxFaKMzR7TBopEaT24cju3Rx2ytEml +pc/csfifG9xkueEUlv9uqPxmkdMdYmg6/XW14Y8oVZRyGQNuVTOEHcOuXvfAOatURlA 81IybxhKeBF2Oe/i7oil4jJ3llEnf1wYSWvkeADeIbhbZY9her4DLj8wIzzxELe5ewqG VX5Gc/HBUeSc757QXtbcpuGeguUJP/SMFyxR21qLqDGa8E+4Tj+cAqVMeXOgMocC5JrF 17HijoJMmM4pk5q5itmwBqdn41g5r9afpVLrkZf1eu0ttPtTPaQvyrqi2YoMvD3WIDjT v2CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=X4aMjpUz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id x18si66981ybj.26.2019.02.04.05.34.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 04 Feb 2019 05:34:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=X4aMjpUz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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 ([127.0.0.1]:42875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeNx-0001RZ-8r for patch@linaro.org; Mon, 04 Feb 2019 08:34:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeC2-000110-In for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:21:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqe3P-0002bU-CY for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:52 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:54503) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gqe3P-00027S-2P for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:51 -0500 Received: by mail-wm1-x342.google.com with SMTP id a62so13134249wmh.4 for ; Mon, 04 Feb 2019 05:12:40 -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=1yNoac1ShBnXw/zdOxjpmLH8NTh7CPRm4nWUT3FtlnU=; b=X4aMjpUz18dlq8P0P5vGpst/OI30cR1MBmnGhQs4TTR12ckntJvSqs1MDg4YYgeKjO 09s11Z9OSV056cbuXfx1IfGriN+1SAK+APHf1aX2QzyhHigbRnft/N1F+5J157uUdPK9 YA+pitMqWkvdKEBCMcJEaj1yB6abLiBYc5ISE= 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=1yNoac1ShBnXw/zdOxjpmLH8NTh7CPRm4nWUT3FtlnU=; b=UQ62owgGwpMy87f7FyAE0WQE9BQ9Ern1WhhnXVHSUfQ1QHRxFGK5WWldxGNV9WcETf DE3VewqSOhALWwi/drYZMJNHPDLshX9WMXpBsuWJiQtKVptFuf6qSIVnnezvRVSGRdKY z84cacAQ/mYQqJWy7dhAA7g570USsdBXDOsYCx+g/D9zt0Q5FzORWpON8f0lCtgjh86S pm+o0yScFwiRVsLYfp1E8F9d0NXxzRaf6UEVr+kc1I+XRkwYkq4RoeAIkWJa0MmaguQQ O+JLTdoW2LyH3bGti23Zyyjyb2oiODlZh67x3rtiutGcamcOxzaA+oSB9HFv018srevj eRzQ== X-Gm-Message-State: AHQUAuYS1x71Xk7bvdU990h43U0TiAx3PHM05ZsKFFFpVzYTAtIEEePk gHKSPcHUgn7Tdf4+hi6HSJcJAEBWtjH/yw== X-Received: by 2002:a1c:2c6:: with SMTP id 189mr13045736wmc.21.1549285959070; Mon, 04 Feb 2019 05:12:39 -0800 (PST) Received: from cloudburst.twiddle.net (host81-133-38-158.in-addr.btopenworld.com. [81.133.38.158]) by smtp.gmail.com with ESMTPSA id z9sm22283025wrs.63.2019.02.04.05.12.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 05:12:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 13:12:27 +0000 Message-Id: <20190204131228.25949-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190204131228.25949-1-richard.henderson@linaro.org> References: <20190204131228.25949-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v3 3/4] linux-user/aarch64: Reset btype for syscalls and signals 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" The value of btype for syscalls is CONSTRAINED UNPREDICTABLE, so we need to make sure that the value is 0 before clone, fork, or syscall return. The value of btype for signals is defined, but it does not make sense for a SIGILL handler to enter with the btype set as for the indirect branch that caused the SIGILL. Clearing the value early means that btype is zero within the pstate saved into the signal frame, and so is also zero on (normal) signal return, but also allows the signal handler to adjust the value as seen after the sigcontext restore. This last is a guess at a future kernel's user-space ABI. Signed-off-by: Richard Henderson --- v3: Do not clear btype for semihost. --- linux-user/aarch64/cpu_loop.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.17.2 diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index d75fd9d3e2..3f046dbbd7 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -83,8 +83,19 @@ void cpu_loop(CPUARMState *env) cpu_exec_end(cs); process_queued_cpu_work(cs); + /* + * The state of BTYPE on syscall and interrupt entry is CONSTRAINED + * UNPREDICTABLE. The real kernel will need to tidy this up as well. + * Do this before syscalls and signals, so that the value is correct + * both within signal handlers, and on return from syscall (especially + * clone & fork) and from signal handlers. + * + * The SIGILL signal handler, for BTITrap, can see the failing BTYPE + * within the ESR value in the signal frame. + */ switch (trapnr) { case EXCP_SWI: + env->btype = 0; ret = do_syscall(env, env->xregs[8], env->xregs[0], @@ -104,6 +115,7 @@ void cpu_loop(CPUARMState *env) /* just indicate that signals should be handled asap */ break; case EXCP_UDEF: + env->btype = 0; info.si_signo = TARGET_SIGILL; info.si_errno = 0; info.si_code = TARGET_ILL_ILLOPN; @@ -112,6 +124,7 @@ void cpu_loop(CPUARMState *env) break; case EXCP_PREFETCH_ABORT: case EXCP_DATA_ABORT: + env->btype = 0; info.si_signo = TARGET_SIGSEGV; info.si_errno = 0; /* XXX: check env->error_code */ @@ -121,6 +134,7 @@ void cpu_loop(CPUARMState *env) break; case EXCP_DEBUG: case EXCP_BKPT: + env->btype = 0; info.si_signo = TARGET_SIGTRAP; info.si_errno = 0; info.si_code = TARGET_TRAP_BRKPT;