From patchwork Mon Jan 28 22:31:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156910 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3971009jaa; Mon, 28 Jan 2019 14:59:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN4RVK7ys4ESYFv09LYA589JDa1l/ziDQwdbNtTaYSJgndmPQzaKbrzG9SDtEZwK+0CsQEvc X-Received: by 2002:a1c:3d44:: with SMTP id k65mr18544295wma.76.1548716370484; Mon, 28 Jan 2019 14:59:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548716370; cv=none; d=google.com; s=arc-20160816; b=hC7m9Z37Gco8ZI/FADBihIolx4wn9G3jO7keE/49tx0TlEirKOkzHetUZcmDXupDET t7idPVwnLEcgPMlAE9nvEBkQaouO9WgcQLjC9Y0f9xt1n2i165PYIO+r+C8NvoiFao21 FrqQu5/YSZMoxXl52e/bItHtteNLs7KW7e/TFsGdHyVA5ha5fDoEg++Dun1yBnZIHxu2 HSFtioSB+Q//U2YSWcTD671aJaVMTjEFQuuYuZDzGZ9YyYWsLDypj6V4rovV+4BL5qaD TabM7YyvEXBeVIcx6UEcXv70mPR2Ll+Hkya2mk6txqN3ZMlIj9HK191dOSLyRJGLZt6s iJ5A== 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=FU6VM0/bn2KGW7WbYepledET8E6WIGztTULH/WAiw80=; b=jZCu5Kz0u25ZTj2gmYUnfvrqRWdMOZg1BSzW/h1MyssdJ9tpP24twQtUbAVV2KGpq6 AzMM1oCfEyVebkOdpNuqHqAofM5earcTgauTMC5QJt5jvHLMau1FQyaNo2lI62q2Jq9v IO/6tDeZ5V3wN/MboQTnaUthMHPpKJwAYyqkLZAN7/ZEBxHuDTpTS2J1AOVrNc92Eh// 1ThUU4gWf522sy70KTUNkTVIt799WdOIOGcEEPH2N12ZUaxnCnCPVXD1VItL7fYsqgMZ B7vWxznZRviqT2rrA0KcQT+zCXrRzjdIwOsMOEZCw0CGUzHWk6By2NvGoVe8q8VlSGaB lfXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kpVei5F9; 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 v10si12140652wre.30.2019.01.28.14.59.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 14:59:30 -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=kpVei5F9; 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]:39816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFsH-0001kL-G5 for patch@linaro.org; Mon, 28 Jan 2019 17:59:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcB-0006rk-W3 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRM-0006GX-SR for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:42 -0500 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:36376) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRM-0006FK-4s for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:40 -0500 Received: by mail-oi1-x243.google.com with SMTP id x23so14513399oix.3 for ; Mon, 28 Jan 2019 14:31:38 -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=FU6VM0/bn2KGW7WbYepledET8E6WIGztTULH/WAiw80=; b=kpVei5F9kQzPwTdj5e9fE6LMjw1LhU/qyOtcgW7/gpbtlQGB71ElE1LabPft9VaW78 NMKz7u8xzNL44A7DMIc3v/+5XaxSQHQEiMsfn/aFZuqrCYJ5VrnwDirF0bKeWap3EYZQ tYB5sfxzylbRpf0KNO7t1dnlw8ApUHhDoY6U8= 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=FU6VM0/bn2KGW7WbYepledET8E6WIGztTULH/WAiw80=; b=Mo0qw28cx4kRBnR3xY0bBHZ1cMpS0NscQnfOKqNkSS3geGbFRBM305ai4YchHRZD68 3rxvYt7358L2DO7NlyEv/4/ErnpH/fUcifvLdqu96yUXYdYF6EwP0T7Hh8UQD7nj4p+d Hcj2AtLRziU1WpStimFiT/WjUDMeTptaJy1dsv8e74IpBMq2iDbPYUIxbHCWPiX5Juw5 G+KCJf3xngn2ibYnYLBY1PyI6Rb6aHQeojuJEwOsAfhyrc/mHDv6lxVE97btsfHkLVP2 XRKOQwY1NRue1neU6eNK9OOQ6UbKFWKT814b4rWtn5aFU33RC5oQG9pUeioKWjZMID+p MsSg== X-Gm-Message-State: AJcUukdrzfaz+SFXXQNygUEDouu25jNqYUrrN+sBRDW2nzUQigfNRtyy MXd1OzIpsZypo+rw2JzkNm6yIHaJ2Mg= X-Received: by 2002:aca:1702:: with SMTP id j2mr7536584oii.267.1548714697762; Mon, 28 Jan 2019 14:31:37 -0800 (PST) Received: from cloudburst.twiddle.net ([12.227.73.85]) by smtp.gmail.com with ESMTPSA id v3sm7460438oib.57.2019.01.28.14.31.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:17 -0800 Message-Id: <20190128223118.5255-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190128223118.5255-1-richard.henderson@linaro.org> References: <20190128223118.5255-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::243 Subject: [Qemu-devel] [PATCH v2 11/12] 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 --- linux-user/aarch64/cpu_loop.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- 2.17.2 diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 65d815f030..51ea9961ba 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,12 +134,14 @@ 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; queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); break; case EXCP_SEMIHOST: + env->btype = 0; env->xregs[0] = do_arm_semihosting(env); break; case EXCP_YIELD: