From nobody Wed Oct 1 02:10:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548716324807351.749336177356; Mon, 28 Jan 2019 14:58:44 -0800 (PST) Received: from localhost ([127.0.0.1]:39816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFrX-0001kL-NY for importer@patchew.org; Mon, 28 Jan 2019 17:58:43 -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) 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) 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-Google-Smtp-Source: ALg8bN6NknSIZxW4JpxFb1jnw0T0LN+OYe0LMgZxAXJyPO667GV2kuiDsumRWs4an1zpFRyaFa8HoA== X-Received: by 2002:aca:1702:: with SMTP id j2mr7536584oii.267.1548714697762; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(+) 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); =20 + /* + * The state of BTYPE on syscall and interrupt entry is CONSTRAINED + * UNPREDICTABLE. The real kernel will need to tidy this up as we= ll. + * Do this before syscalls and signals, so that the value is corre= ct + * both within signal handlers, and on return from syscall (especi= ally + * clone & fork) and from signal handlers. + * + * The SIGILL signal handler, for BTITrap, can see the failing BTY= PE + * within the ESR value in the signal frame. + */ switch (trapnr) { case EXCP_SWI: + env->btype =3D 0; ret =3D 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 =3D 0; info.si_signo =3D TARGET_SIGILL; info.si_errno =3D 0; info.si_code =3D TARGET_ILL_ILLOPN; @@ -112,6 +124,7 @@ void cpu_loop(CPUARMState *env) break; case EXCP_PREFETCH_ABORT: case EXCP_DATA_ABORT: + env->btype =3D 0; info.si_signo =3D TARGET_SIGSEGV; info.si_errno =3D 0; /* XXX: check env->error_code */ @@ -121,12 +134,14 @@ void cpu_loop(CPUARMState *env) break; case EXCP_DEBUG: case EXCP_BKPT: + env->btype =3D 0; info.si_signo =3D TARGET_SIGTRAP; info.si_errno =3D 0; info.si_code =3D TARGET_TRAP_BRKPT; queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); break; case EXCP_SEMIHOST: + env->btype =3D 0; env->xregs[0] =3D do_arm_semihosting(env); break; case EXCP_YIELD: --=20 2.17.2