From nobody Sat Apr 20 00:34:09 2024 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 1547123016496913.0935279477335; Thu, 10 Jan 2019 04:23:36 -0800 (PST) Received: from localhost ([127.0.0.1]:57457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZN1-0008RF-2g for importer@patchew.org; Thu, 10 Jan 2019 07:23:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHQ-0004Qt-Ne for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHQ-0007Tr-1Z for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:48 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:34143) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHP-0007Sd-Rl for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:47 -0500 Received: by mail-pg1-x542.google.com with SMTP id j10so4776284pga.1 for ; Thu, 10 Jan 2019 04:17:47 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.17.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:17:45 -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=xcgpdHXeoLZj898IpUPl+D9wheSQAsJzisRYxgxJu00=; b=Wg/qPzrMIx626c03pPUtxCovYpM2zLncUfcuG4uZpeXbc0onoITPBfYW+HZR5WnfCb 4We05s+aEQmin1QePft2iw5fAvtMKOX5QPRGfutYf6JUFKXlVsK+qylz3Kcu4MdLBvKd eBqsBTguzlkwHB4UPe0kkhxcj5dfgQG9MlIec= 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=xcgpdHXeoLZj898IpUPl+D9wheSQAsJzisRYxgxJu00=; b=mxX6LfI0X4I0YKOKkcXQA7DgcydaXxt7SKXEfQHBdcNAL/jdTCyDJ/GtPc3I9ntu6b MTzmJqh+t1KfWy4gSEWGQlIlPgmoojETm/yrYeo4BrLIv9DvUtkM8hV95kGQt7nB9gXE smxmc+gH/8KgKdyos7DmjUaiXPzX10Zpj/9EtZZu2H/JdCwZaJ6S61qwGeEbPdCWtKhl ZvBSUAXP7SGIq49n1dNA5o4BgtbyRTmpo5CMGgB/sRMv8Bx5ELQHz07XWnjy61pkGsGs bhu4TBzWe253J+7hjkBihyumPaV8ajCnFA6LgYbeudJ6NlWGPoWfZAh3fKHaq5rMuhvQ +dYA== X-Gm-Message-State: AJcUukdKpAEQsc84+gKQ88K96qUcvWVbiQVLHJynn1HVbe8x4hgp43Mh DxKBhTyjbA/jyG8ECRnNBoeHHSBZgQ4D5Q== X-Google-Smtp-Source: ALg8bN6kOWAjLMVyAkqZDDBcWviObH1bZtqoOIOlfFcIrecrUxg9h/IOUiaXGDEqYE9lp9pfIAPbKQ== X-Received: by 2002:a62:c711:: with SMTP id w17mr10111242pfg.50.1547122666342; Thu, 10 Jan 2019 04:17:46 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:26 +1100 Message-Id: <20190110121736.23448-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::542 Subject: [Qemu-devel] [PATCH 01/11] target/arm: Introduce isar_feature_aa64_bti 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" Also create field definitions for id_aa64pfr1 from ARMv8.5. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/cpu.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 8512ca3552..fadb74d9a6 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1630,6 +1630,9 @@ FIELD(ID_AA64PFR0, GIC, 24, 4) FIELD(ID_AA64PFR0, RAS, 28, 4) FIELD(ID_AA64PFR0, SVE, 32, 4) =20 +FIELD(ID_AA64PFR1, BT, 0, 4) +FIELD(ID_AA64PFR1, SBSS, 4, 4) + FIELD(ID_AA64MMFR0, PARANGE, 0, 4) FIELD(ID_AA64MMFR0, ASIDBITS, 4, 4) FIELD(ID_AA64MMFR0, BIGEND, 8, 4) @@ -3268,6 +3271,11 @@ static inline bool isar_feature_aa64_lor(const ARMIS= ARegisters *id) return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, LO) !=3D 0; } =20 +static inline bool isar_feature_aa64_bti(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, BT) !=3D 0; +} + /* * Forward to the above feature tests given an ARMCPU pointer. */ --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 1547122827231888.1447937269716; Thu, 10 Jan 2019 04:20:27 -0800 (PST) Received: from localhost ([127.0.0.1]:56680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZJu-0005xp-IH for importer@patchew.org; Thu, 10 Jan 2019 07:20:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHT-0004ST-Aa for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHS-0007WY-Ez for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:51 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:34144) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHS-0007Vt-8K for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:50 -0500 Received: by mail-pg1-x542.google.com with SMTP id j10so4776332pga.1 for ; Thu, 10 Jan 2019 04:17:50 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.17.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:17:48 -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=oasvDAmRt5epJt1fiYz/E8kNR8BOc+EcbCwre/X4ac8=; b=dI88+ojopaP7ka3+0IfkC2DvwOJZTwhAhr+sL34Up+DjtE9tarODcIE3vxFLrIwdgd VoPOyZdy+mDYUgTSnVFJo7e0RPB3MTHOEzOGoEmgmq5dOMZhXkBaoEaJq5KdEF6X6Xjs /o8uOLk+NbTEZxbUJH791zMyabE+RE/GCLjK8= 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=oasvDAmRt5epJt1fiYz/E8kNR8BOc+EcbCwre/X4ac8=; b=FzBTuMexK0lg/18dULyGa9hoiObNpudKx6vP1GpVHMRBXaoCIjQZx0QPUQjiIK8/Vl SU7/czK0HyEdiNBa5WfK2xQy1uAVe0VmpX336mr5tk0PKBab6xip2ys3lnt830q174OS ACuwZWHTIlW4TGvVRbc0qi/X75K/0sTNnzLxw76rcmshUutakCcacM52TP4i7ZjGLkZH kjRcfzyfEQ/jaViTSfUTWbK9+38J6nvF5Z4tXoMioHSfIlNK6Oii7HGdvzXjUBvEo6P8 U4nCvflia4wZwP4LRqN7unZgip9uOrRKRahlv0Id6V1bIFCm9CChz4Kl2gzZj77XYUhZ aFFQ== X-Gm-Message-State: AJcUukdFmqo0jr1RwjduuM/mM3G/tSBtXJ55J7aYDLDdsR8BrsN3JQtt 5ZXwtKTHQwphw8JTELXnuWR/LEw644ZjrA== X-Google-Smtp-Source: ALg8bN6wcSllXTASlG4MHU3QvCfm67EJxHRxYuQv6jsynb71w7B0/sx4EYyJUaTv35zoAeQR63WOQg== X-Received: by 2002:a62:4c5:: with SMTP id 188mr10175480pfe.130.1547122668952; Thu, 10 Jan 2019 04:17:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:27 +1100 Message-Id: <20190110121736.23448-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::542 Subject: [Qemu-devel] [PATCH 02/11] target/arm: Add PSTATE.BTYPE 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" Place this in its own field within ENV, as that will make it easier to reset from within TCG generated code. With the change to pstate_read/write, exception entry and return are automatically handled. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/cpu.h | 8 ++++++-- target/arm/translate-a64.c | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index fadb74d9a6..8179c07250 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -234,6 +234,7 @@ typedef struct CPUARMState { * semantics as for AArch32, as described in the comments on each f= ield) * nRW (also known as M[4]) is kept, inverted, in env->aarch64 * DAIF (exception masks) are kept in env->daif + * BTYPE is kept in env->btype * all other bits are stored in their correct places in env->pstate */ uint32_t pstate; @@ -263,6 +264,7 @@ typedef struct CPUARMState { uint32_t GE; /* cpsr[19:16] */ uint32_t thumb; /* cpsr[5]. 0 =3D arm mode, 1 =3D thumb mode. */ uint32_t condexec_bits; /* IT bits. cpsr[15:10,26:25]. */ + uint32_t btype; /* BTI branch type. spsr[11:10]. */ uint64_t daif; /* exception masks, in the bits they are in PSTATE */ =20 uint64_t elr_el[4]; /* AArch64 exception link regs */ @@ -1155,6 +1157,7 @@ void pmccntr_sync(CPUARMState *env); #define PSTATE_I (1U << 7) #define PSTATE_A (1U << 8) #define PSTATE_D (1U << 9) +#define PSTATE_BTYPE (3U << 10) #define PSTATE_IL (1U << 20) #define PSTATE_SS (1U << 21) #define PSTATE_V (1U << 28) @@ -1163,7 +1166,7 @@ void pmccntr_sync(CPUARMState *env); #define PSTATE_N (1U << 31) #define PSTATE_NZCV (PSTATE_N | PSTATE_Z | PSTATE_C | PSTATE_V) #define PSTATE_DAIF (PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F) -#define CACHED_PSTATE_BITS (PSTATE_NZCV | PSTATE_DAIF) +#define CACHED_PSTATE_BITS (PSTATE_NZCV | PSTATE_DAIF | PSTATE_BTYPE) /* Mode values for AArch64 */ #define PSTATE_MODE_EL3h 13 #define PSTATE_MODE_EL3t 12 @@ -1195,7 +1198,7 @@ static inline uint32_t pstate_read(CPUARMState *env) ZF =3D (env->ZF =3D=3D 0); return (env->NF & 0x80000000) | (ZF << 30) | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) - | env->pstate | env->daif; + | env->pstate | env->daif | (env->btype << 10); } =20 static inline void pstate_write(CPUARMState *env, uint32_t val) @@ -1205,6 +1208,7 @@ static inline void pstate_write(CPUARMState *env, uin= t32_t val) env->CF =3D (val >> 29) & 1; env->VF =3D (val << 3) & 0x80000000; env->daif =3D val & PSTATE_DAIF; + env->btype =3D (val >> 10) & 3; env->pstate =3D val & ~CACHED_PSTATE_BITS; } =20 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 2c5ad1774a..e43f0982f9 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -163,6 +163,9 @@ void aarch64_cpu_dump_state(CPUState *cs, FILE *f, el, psr & PSTATE_SP ? 'h' : 't'); =20 + if (cpu_isar_feature(aa64_bti, cpu)) { + cpu_fprintf(f, " BTYPE=3D%d", (psr & PSTATE_BTYPE) >> 10); + } if (!(flags & CPU_DUMP_FPU)) { cpu_fprintf(f, "\n"); return; --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 15471230253168.117080539365475; Thu, 10 Jan 2019 04:23:45 -0800 (PST) Received: from localhost ([127.0.0.1]:57492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZN6-00004w-S0 for importer@patchew.org; Thu, 10 Jan 2019 07:23:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHV-0004Uh-RW for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHU-0007Yj-UE for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:53 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:43506) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHU-0007Y8-Ne for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:52 -0500 Received: by mail-pl1-x643.google.com with SMTP id gn14so5109073plb.10 for ; Thu, 10 Jan 2019 04:17:52 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.17.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:17:50 -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=fkaNmZExNvexpax6vpTVFC0ERbhvs5NzXZdOCGU7hoY=; b=PZHnUCJ0kNHlPBr0dOaEwsCUJEWxpULjgxa2NpGOlAgXGVQSYO5CWe3QMcaP3PH17V M0yv+q631zamwC8dVyYLCf7lGuy0RAn0e7I2iwwHZfstVQ0O6Z+xS2eFBSr3owHWAtQG FmVM5TcMWTyqiJBSHqaehZUSt8QzZhduXAWmY= 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=fkaNmZExNvexpax6vpTVFC0ERbhvs5NzXZdOCGU7hoY=; b=GqDE2/EOl4v09Yxa13pRx41tlhanjiC3Cp/MJ13bz17/TrA7OwaqW1XksI7LSjcEsT 8WsISXSCGLVwXnn2uEzoDgtlz2JV9DBCwvwaGVha36Qa2UoO6dujy2wsCpBDHzoxBqZr o36k7+Tt8xgPvizPZGo74RmrkEe8MZvZmbGjeOZIGbnmNNP/4q2CPKlKtP098ULrXobW W2wnsY/ioOuaqbz9OkMg71OkePEoUsfXhpYoDaSugLRFu6zQ3zBIJyN1scL3w3IY7Da0 IV3DaIxKPCEcGiS8pGhoMicd0m1I9UvEFi1PSWZPzsuIU2SY7XZ8V2SrKmCt9eLUawQJ taUQ== X-Gm-Message-State: AJcUukd+CmVkiFrRFfVArIcmuG094xSVgntBMK+W4DhjdU6Wt7gAlIu1 6jQugS3i1MSrK5IprJDB6M8HcoVF+38RAA== X-Google-Smtp-Source: ALg8bN6kP7TFBWsTwgi50SN4nBZZj37TlDac2PTjhyYF+cPb/EQHT/V96x1HGmzdqgqjPT6OYaFdvw== X-Received: by 2002:a17:902:8c91:: with SMTP id t17mr9823027plo.119.1547122671242; Thu, 10 Jan 2019 04:17:51 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:28 +1100 Message-Id: <20190110121736.23448-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::643 Subject: [Qemu-devel] [PATCH 03/11] target/arm: Add BT and BTYPE to tb->flags 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" Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/cpu.h | 2 ++ target/arm/translate.h | 4 ++++ target/arm/helper.c | 22 +++++++++++++++------- target/arm/translate-a64.c | 2 ++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 8179c07250..506c490a16 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2990,6 +2990,8 @@ FIELD(TBFLAG_A64, TBII, 0, 2) FIELD(TBFLAG_A64, SVEEXC_EL, 2, 2) FIELD(TBFLAG_A64, ZCR_LEN, 4, 4) FIELD(TBFLAG_A64, PAUTH_ACTIVE, 8, 1) +FIELD(TBFLAG_A64, BT, 9, 1) +FIELD(TBFLAG_A64, BTYPE, 10, 2) =20 static inline bool bswap_code(bool sctlr_b) { diff --git a/target/arm/translate.h b/target/arm/translate.h index bb37d35741..3d5e8bacac 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -69,6 +69,10 @@ typedef struct DisasContext { bool ss_same_el; /* True if v8.3-PAuth is active. */ bool pauth_active; + /* True with v8.5-BTI and SCTLR_ELx.BT* set. */ + bool bt; + /* A copy of PSTATE.BTYPE, which will be 0 without v8.5-BTI. */ + uint8_t btype; /* Bottom two bits of XScale c15_cpar coprocessor access control reg */ int c15_cpar; /* TCG op of the current insn_start. */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 0e1bf521ab..138d9d5565 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -13076,6 +13076,7 @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_= ulong *pc, =20 if (is_a64(env)) { ARMCPU *cpu =3D arm_env_get_cpu(env); + uint64_t sctlr; =20 *pc =3D env->pc; flags =3D FIELD_DP32(flags, TBFLAG_ANY, AARCH64_STATE, 1); @@ -13120,6 +13121,12 @@ void cpu_get_tb_cpu_state(CPUARMState *env, target= _ulong *pc, flags =3D FIELD_DP32(flags, TBFLAG_A64, ZCR_LEN, zcr_len); } =20 + if (current_el =3D=3D 0) { + /* FIXME: ARMv8.1-VHE S2 translation regime. */ + sctlr =3D env->cp15.sctlr_el[1]; + } else { + sctlr =3D env->cp15.sctlr_el[current_el]; + } if (cpu_isar_feature(aa64_pauth, cpu)) { /* * In order to save space in flags, we record only whether @@ -13127,17 +13134,18 @@ void cpu_get_tb_cpu_state(CPUARMState *env, targe= t_ulong *pc, * a nop, or "active" when some action must be performed. * The decision of which action to take is left to a helper. */ - uint64_t sctlr; - if (current_el =3D=3D 0) { - /* FIXME: ARMv8.1-VHE S2 translation regime. */ - sctlr =3D env->cp15.sctlr_el[1]; - } else { - sctlr =3D env->cp15.sctlr_el[current_el]; - } if (sctlr & (SCTLR_EnIA | SCTLR_EnIB | SCTLR_EnDA | SCTLR_EnDB= )) { flags =3D FIELD_DP32(flags, TBFLAG_A64, PAUTH_ACTIVE, 1); } } + + if (cpu_isar_feature(aa64_bti, cpu)) { + /* Note that SCTLR_EL[23].BT =3D=3D SCTLR_BT1. */ + if (sctlr & (current_el =3D=3D 0 ? SCTLR_BT0 : SCTLR_BT1)) { + flags =3D FIELD_DP32(flags, TBFLAG_A64, BT, 1); + } + flags =3D FIELD_DP32(flags, TBFLAG_A64, BTYPE, env->btype); + } } else { *pc =3D env->regs[15]; flags =3D FIELD_DP32(flags, TBFLAG_A32, THUMB, env->thumb); diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index e43f0982f9..ca2ae40701 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -13800,6 +13800,8 @@ static void aarch64_tr_init_disas_context(DisasCont= extBase *dcbase, dc->sve_excp_el =3D FIELD_EX32(tb_flags, TBFLAG_A64, SVEEXC_EL); dc->sve_len =3D (FIELD_EX32(tb_flags, TBFLAG_A64, ZCR_LEN) + 1) * 16; dc->pauth_active =3D FIELD_EX32(tb_flags, TBFLAG_A64, PAUTH_ACTIVE); + dc->bt =3D FIELD_EX32(tb_flags, TBFLAG_A64, BT); + dc->btype =3D FIELD_EX32(tb_flags, TBFLAG_A64, BTYPE); dc->vec_len =3D 0; dc->vec_stride =3D 0; dc->cp_regs =3D arm_cpu->cp_regs; --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 1547122835301337.0229827426733; Thu, 10 Jan 2019 04:20:35 -0800 (PST) Received: from localhost ([127.0.0.1]:56716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZK3-00068F-Ok for importer@patchew.org; Thu, 10 Jan 2019 07:20:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHY-0004Wi-6w for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHX-0007bR-Fs for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:56 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:35850) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHX-0007al-AE for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:55 -0500 Received: by mail-pl1-x644.google.com with SMTP id g9so5121865plo.3 for ; Thu, 10 Jan 2019 04:17:55 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.17.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:17:53 -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=6iqUO+dfMicx3Wse2EXLLlldaaZeN5/b/MYFSpmB9uM=; b=L6geguyR7WVRKBxTNLweSo2mwjkVkZHowbWb8mCJ1b9Lp88Bw27YaOkKDdi5Yex/aQ MJZpLtRjLIuFJHWDsjo1T0Wt1z7D62B3CWL/vJhFoklx8oKVjuufXtQtSkSlZrvdSzIF eyyv1sWwnOrBD8NTC7IvwpN3AWJVqC4piKBO4= 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=6iqUO+dfMicx3Wse2EXLLlldaaZeN5/b/MYFSpmB9uM=; b=RhwmNJSABsjqvlNeHAxhzLVEeSuyJiIg8nJLsR1/mAATqdX3clEY1ChNXP/waFrGae 1etbC1p1KPpCWDtHh5kdCPZ6xCEH7sFFV/Kt9HVnVlw+hL0EpSyJSWnvniZ0Elz+KeB9 g6TBGgVmFIhAFATERZNyTVqI7ERNaCwwRiMXKx0xyH3/SKQoNFkY3RrTJD/C2D9D98YD YoRnjmGHGTzIBgY0ywu6tZLp4/WfwxPkB+warFx+OqQpwWQWp4SgSctL3ya2q5TXKw2j nvw3wW1BZRX2Rc+gHOh2O6fjGTg7CdJqKi3uvVdulefA8XDuPPqnSK6frXP43e/sQbK+ /viA== X-Gm-Message-State: AJcUukd7BQMqZkUz5XBtzRCHurLS9eU4q/uZKJym6pXnfM5pqqsNcqsQ 8oB0kg29KA4XlWpzGwKsg+4+5J5lyVQzsw== X-Google-Smtp-Source: ALg8bN7+HsXWtpLf07LWi9zynZ5Z1k5VWQR9nQL8LIkOaOWfpPZnxuLGHdlbwOTFthHZLE3HSIzTOw== X-Received: by 2002:a17:902:6946:: with SMTP id k6mr10328849plt.101.1547122673790; Thu, 10 Jan 2019 04:17:53 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:29 +1100 Message-Id: <20190110121736.23448-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::644 Subject: [Qemu-devel] [PATCH 04/11] target/arm: Record the GP bit for a page in MemTxAttrs 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" This isn't really a transaction attribute, but that's the most convenient place to hold a random bit of information within the softmmu tlb. Signed-off-by: Richard Henderson --- include/exec/memattrs.h | 2 ++ target/arm/helper.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index d4a1642098..39d61188e1 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -35,6 +35,8 @@ typedef struct MemTxAttrs { unsigned int secure:1; /* Memory access is usermode (unprivileged) */ unsigned int user:1; + /* Page is marked as "guarded" */ + unsigned int guarded:1; /* Requester ID (for MSI for example) */ unsigned int requester_id:16; } MemTxAttrs; diff --git a/target/arm/helper.c b/target/arm/helper.c index 138d9d5565..4e9ea2ed39 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -9927,6 +9927,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, targ= et_ulong address, bool ttbr1_valid; uint64_t descaddrmask; bool aarch64 =3D arm_el_is_aa64(env, el); + bool guarded =3D false; =20 /* TODO: * This code does not handle the different format TCR for VTCR_EL2. @@ -10098,6 +10099,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, ta= rget_ulong address, } /* Merge in attributes from table descriptors */ attrs |=3D nstable << 3; /* NS */ + guarded |=3D extract64(descriptor, 50, 1); /* GP */ if (param.hpd) { /* HPD disables all the table attributes except NSTable. */ break; @@ -10143,6 +10145,10 @@ static bool get_phys_addr_lpae(CPUARMState *env, t= arget_ulong address, */ txattrs->secure =3D false; } + /* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB.= */ + if (aarch64 && guarded && cpu_isar_feature(aa64_bti, cpu)) { + txattrs->guarded =3D true; + } =20 if (cacheattrs !=3D NULL) { if (mmu_idx =3D=3D ARMMMUIdx_S2NS) { --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547123206902145.07675763677366; Thu, 10 Jan 2019 04:26:46 -0800 (PST) Received: from localhost ([127.0.0.1]:58270 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZPv-0002uv-Ax for importer@patchew.org; Thu, 10 Jan 2019 07:26:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHb-0004XM-8j for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHZ-0007dV-W8 for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:59 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:32977) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHZ-0007cu-N9 for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:17:57 -0500 Received: by mail-pl1-x642.google.com with SMTP id z23so5134824plo.0 for ; Thu, 10 Jan 2019 04:17:57 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.17.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:17:55 -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=/YB2L3OtfumYbatzc4HBobxII2tPYayqfJux+fHDtIY=; b=HWYtGytLLkOnRHqXxJKbzoHch3/Rh+LQJ2jxK3s/SJtjS1lHkho+Bb64IiVZZ0FmCg IyClrDXJ2lkyuE/Zi6FgLpo+uyHmGlKc35F6oOrXWSb3zSZtXadc/kuW6Pb+Rt6iaITc TiWPPkD5XUuakzAuH6o/lSQhQaYcf9/CCH9wM= 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=/YB2L3OtfumYbatzc4HBobxII2tPYayqfJux+fHDtIY=; b=gtJ5pNBGIydrxTXWXYhWWisoH3KX13BZYZVsOrHASpnu197xjI7J998XDEhX6GwGsc Zr3kK4GXb3YRXqu0u2I4jqdn/yLEZInuumHuagHtZG6zuOMQYY7Stb7JO8ALf89VOXve 9WBgN7oI3hwndXnuKtU57Fjs6+OxyHd1KnSpBFI2W23Z1mPsBES495BH4YpzblI7yuJQ ylyjyX85Hp+TTGTtGrlme4bSuT//5QlBwvRZr3p6DkcSod+jGetUBz2ywU/J+5qfU7wr 0sDEAzcPzgENRFz6l8hOwKd3haUX5OXdBpFfUU5OnOEty+YMiWf2/HZW2pzsXMAxEJLL LxNw== X-Gm-Message-State: AJcUukd0C6UdjQwvcbW1bA+dF4P78DBWl6diIc7pFmmsY42zsjmtmFIV 5ExeBC7ZQCZOqQhTAgBPbqyGzbluGwGO3w== X-Google-Smtp-Source: ALg8bN5KHX/xwnqKNfgpRm27Heb1+0zRgDI4dflgBcWG7c3k8IV96slSGU6J16he6h1R2WNJAUmSEw== X-Received: by 2002:a17:902:5ac7:: with SMTP id g7mr10274374plm.212.1547122676196; Thu, 10 Jan 2019 04:17:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:30 +1100 Message-Id: <20190110121736.23448-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::642 Subject: [Qemu-devel] [PATCH 05/11] target/arm: Default handling of BTYPE during translation 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 branch target exception for guarded pages has high priority, and only 8 instructions are valid for that case. Perform this check before doing any other decode. Clear BTYPE after all insns that neither set BTYPE nor exit via exception (DISAS_NORETURN). Not yet handled are insns that exit via DISAS_NORETURN for some other reason, like direct branches. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/internals.h | 6 ++ target/arm/translate.h | 9 ++- target/arm/translate-a64.c | 139 +++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index a6fd4582b2..d01a3f9f44 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -268,6 +268,7 @@ enum arm_exception_class { EC_FPIDTRAP =3D 0x08, EC_PACTRAP =3D 0x09, EC_CP14RRTTRAP =3D 0x0c, + EC_BTITRAP =3D 0x0d, EC_ILLEGALSTATE =3D 0x0e, EC_AA32_SVC =3D 0x11, EC_AA32_HVC =3D 0x12, @@ -439,6 +440,11 @@ static inline uint32_t syn_pactrap(void) return EC_PACTRAP << ARM_EL_EC_SHIFT; } =20 +static inline uint32_t syn_btitrap(int btype) +{ + return (EC_BTITRAP << ARM_EL_EC_SHIFT) | btype; +} + static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int = fsc) { return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) diff --git a/target/arm/translate.h b/target/arm/translate.h index 3d5e8bacac..f73939d7b4 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -71,8 +71,13 @@ typedef struct DisasContext { bool pauth_active; /* True with v8.5-BTI and SCTLR_ELx.BT* set. */ bool bt; - /* A copy of PSTATE.BTYPE, which will be 0 without v8.5-BTI. */ - uint8_t btype; + /* + * >=3D 0, a copy of PSTATE.BTYPE, which will be 0 without v8.5-BTI. + * < 0, set by the current instruction. + */ + int8_t btype; + /* True if this page is guarded. */ + bool guarded_page; /* Bottom two bits of XScale c15_cpar coprocessor access control reg */ int c15_cpar; /* TCG op of the current insn_start. */ diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index ca2ae40701..68eb27089a 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -128,6 +128,16 @@ static inline int get_a64_user_mem_index(DisasContext = *s) return arm_to_core_mmu_idx(useridx); } =20 +static void reset_btype(DisasContext *s) +{ + if (s->btype !=3D 0) { + TCGv_i32 zero =3D tcg_const_i32(0); + tcg_gen_st_i32(zero, cpu_env, offsetof(CPUARMState, btype)); + tcg_temp_free_i32(zero); + s->btype =3D 0; + } +} + void aarch64_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, int flags) { @@ -13716,6 +13726,90 @@ static void disas_data_proc_simd_fp(DisasContext *= s, uint32_t insn) } } =20 +/** + * is_guarded_page: + * @env: The cpu environment + * @s: The DisasContext + * + * Return true if the page is guarded. + */ +static bool is_guarded_page(CPUARMState *env, DisasContext *s) +{ +#ifdef CONFIG_USER_ONLY + return false; /* FIXME */ +#else + uint64_t addr =3D s->base.pc_first; + int mmu_idx =3D arm_to_core_mmu_idx(s->mmu_idx); + unsigned int index =3D tlb_index(env, mmu_idx, addr); + CPUTLBEntry *entry =3D tlb_entry(env, mmu_idx, addr); + + /* + * We test this immediately after reading an insn, which means + * that any normal page must be in the TLB. The only exception + * would be for executing from flash or device memory, which + * does not retain the TLB entry. + * + * FIXME: Assume false for those, for now. We could use + * arm_cpu_get_phys_page_attrs_debug to re-read the page + * table entry even for that case. + */ + return (tlb_hit(entry->addr_code, addr) && + env->iotlb[mmu_idx][index].attrs.guarded); +#endif +} + +/** + * btype_destination_ok: + * @insn: The instruction at the branch destination + * @bt: SCTLR_ELx.BT + * @btype: PSTATE.BTYPE, and is non-zero + * + * On a guarded page, there are a limited number of insns + * that may be present at the branch target: + * - branch target identifiers, + * - paciasp, pacibsp, + * - BRK insn + * - HLT insn + * Anything else causes a Branch Target Exception. + * + * Return true if the branch is compatible, false to raise BTITRAP. + */ +static bool btype_destination_ok(uint32_t insn, bool bt, int btype) +{ + if ((insn & 0xfffff01fu) =3D=3D 0xd503201fu) { + /* HINT space */ + switch (extract32(insn, 5, 7)) { + case 031: /* PACIASP */ + case 033: /* PACIBSP */ + /* + * If SCTLR_ELx.BT, then PACI*SP are not compatible + * with btype =3D=3D 3. Otherwise all btype are ok. + */ + return !bt || btype !=3D 3; + case 040: /* BTI */ + /* Not compatible with any btype. */ + return false; + case 042: /* BTI c */ + /* Not compatible with btype =3D=3D 3 */ + return btype !=3D 3; + case 044: /* BTI j */ + /* Not compatible with btype =3D=3D 2 */ + return btype !=3D 2; + case 046: /* BTI jc */ + /* Compatible with any btype. */ + return true; + } + } else { + switch (insn & 0xffe0001fu) { + case 0xd4200000u: /* BRK */ + case 0xd4400000u: /* HLT */ + /* Give priority to the breakpoint exception. */ + return true; + } + } + return false; +} + /* C3.1 A64 instruction index by encoding */ static void disas_a64_insn(CPUARMState *env, DisasContext *s) { @@ -13727,6 +13821,43 @@ static void disas_a64_insn(CPUARMState *env, Disas= Context *s) =20 s->fp_access_checked =3D false; =20 + if (dc_isar_feature(aa64_bti, s)) { + if (s->base.num_insns =3D=3D 1) { + /* + * At the first insn of the TB, compute s->guarded_page. + * We delayed computing this until successfully reading + * the first insn of the TB, above. This (mostly) ensures + * that the softmmu tlb entry has been populated, and the + * page table GP bit is available. + * + * Note that we need to compute this even if btype =3D=3D 0, + * because this value is used for BR instructions later + * where ENV is not available. + */ + s->guarded_page =3D is_guarded_page(env, s); + + /* First insn can have btype set to non-zero. */ + tcg_debug_assert(s->btype >=3D 0); + + /* + * Note that the Branch Target Exception has fairly high + * priority -- below debugging exceptions but above most + * everything else. This allows us to handle this now + * instead of waiting until the insn is otherwise decoded. + */ + if (s->btype !=3D 0 + && s->guarded_page + && !btype_destination_ok(insn, s->bt, s->btype)) { + gen_exception_insn(s, 4, EXCP_UDEF, syn_btitrap(s->btype), + default_exception_el(s)); + return; + } + } else { + /* Not the first insn: btype must be 0. */ + tcg_debug_assert(s->btype =3D=3D 0); + } + } + switch (extract32(insn, 25, 4)) { case 0x0: case 0x1: case 0x3: /* UNALLOCATED */ unallocated_encoding(s); @@ -13763,6 +13894,14 @@ static void disas_a64_insn(CPUARMState *env, Disas= Context *s) =20 /* if we allocated any temporaries, free them here */ free_tmp_a64(s); + + /* + * After execution of most insns, btype is reset to 0. + * Note that we set btype =3D=3D -1 when the insn sets btype. + */ + if (s->btype > 0 && s->base.is_jmp !=3D DISAS_NORETURN) { + reset_btype(s); + } } =20 static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 1547123340606235.01648184058558; Thu, 10 Jan 2019 04:29:00 -0800 (PST) Received: from localhost ([127.0.0.1]:58970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZSF-0004lO-7N for importer@patchew.org; Thu, 10 Jan 2019 07:28:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHd-0004ZZ-Da for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHc-0007fD-Gb for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:01 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:42989) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHc-0007eT-9v for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:00 -0500 Received: by mail-pf1-x442.google.com with SMTP id 64so5217731pfr.9 for ; Thu, 10 Jan 2019 04:18:00 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.17.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:17:58 -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=XRiJh3WKJG2YABKLlUHfm4ue/ZPukKnI+eeZ63W9pjg=; b=V0fTXv6l1QFL7jynuBWm85rs3eUq0bwkEwNdnAdtBwpE5gr78cbLwhBx4HYv5tfUr1 dcVJ57u+4CHHVpog/LJMT0p7o+dQbzjddus2JeIr8JTPNFuVUSOGF+kIvEANVRy34lL5 tBiAQ1JBjwC8FE2SjpboyRNQ2wefKCam3Ogzg= 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=XRiJh3WKJG2YABKLlUHfm4ue/ZPukKnI+eeZ63W9pjg=; b=Ed3G/CViuwKImBgc25zeL3P9V+Yd2G2RNJDs/bSKRb5IOY3KwfPTuEcheP7eHza8eT lHmXiL7pmJSSRkdVCnOQRHppIrtz4Nz+oOLgKofyoEQHXxVlY5ja29jAuYk5Ie9LoHNX +ifTHN5eQFL2Xk7IxqnvTXuhmsoTdjQWxb34ZfYvDIEMoxrMUzjQkHtSH6Yn8GjAm+Dy f44oav+abgry0BD6X3utedw+JfsuZM9iW/PJ11k18E6T2xWP9iB8c1uN1D50oY0IHyOm E+OrVRborgxNJzvRi/aHwB0L3N17DlGhqwW7lPmAcobNfwcgzPzjJS1mda79kLC9fZQh KzUg== X-Gm-Message-State: AJcUukcAEz8/EdPMF/sLM62seTb+nSYwLqdEihxZdMxyrhdasq0jRfpn T0pwwBMaboWwj0lZJCpXXndId2jR0ofG9Q== X-Google-Smtp-Source: ALg8bN6/W8W7nx+HreDlrE9zDTvy1Hh86GqZOSIvJEHSIsik3CScpykHsJtnIM2HVSXYMpOY32qM0w== X-Received: by 2002:a63:1e56:: with SMTP id p22mr9168171pgm.126.1547122678809; Thu, 10 Jan 2019 04:17:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:31 +1100 Message-Id: <20190110121736.23448-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::442 Subject: [Qemu-devel] [PATCH 06/11] target/arm: Reset btype for direct branches and syscalls 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" This is all of the non-exception cases of DISAS_NORETURN. For the rest of the synchronous exceptions, the state of SPSR_ELx.BTYPE is CONSTRAINED UNPREDICTABLE. However, it makes more sense to me to have syscalls reset BTYPE. Signed-off-by: Richard Henderson --- target/arm/translate-a64.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 68eb27089a..f319fa000e 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -1362,6 +1362,7 @@ static void disas_uncond_b_imm(DisasContext *s, uint3= 2_t insn) } =20 /* B Branch / BL Branch with link */ + reset_btype(s); gen_goto_tb(s, 0, addr); } =20 @@ -1386,6 +1387,7 @@ static void disas_comp_b_imm(DisasContext *s, uint32_= t insn) tcg_cmp =3D read_cpu_reg(s, rt, sf); label_match =3D gen_new_label(); =20 + reset_btype(s); tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ, tcg_cmp, 0, label_match); =20 @@ -1415,6 +1417,8 @@ static void disas_test_b_imm(DisasContext *s, uint32_= t insn) tcg_cmp =3D tcg_temp_new_i64(); tcg_gen_andi_i64(tcg_cmp, cpu_reg(s, rt), (1ULL << bit_pos)); label_match =3D gen_new_label(); + + reset_btype(s); tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ, tcg_cmp, 0, label_match); tcg_temp_free_i64(tcg_cmp); @@ -1441,6 +1445,7 @@ static void disas_cond_b_imm(DisasContext *s, uint32_= t insn) addr =3D s->pc + sextract32(insn, 5, 19) * 4 - 4; cond =3D extract32(insn, 0, 4); =20 + reset_btype(s); if (cond < 0x0e) { /* genuinely conditional branches */ TCGLabel *label_match =3D gen_new_label(); @@ -1605,6 +1610,7 @@ static void handle_sync(DisasContext *s, uint32_t ins= n, * a self-modified code correctly and also to take * any pending interrupts immediately. */ + reset_btype(s); gen_goto_tb(s, 0, s->pc); return; default: @@ -1885,6 +1891,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) switch (op2_ll) { case 1: /* SVC= */ gen_ss_advance(s); + reset_btype(s); gen_exception_insn(s, 0, EXCP_SWI, syn_aa64_svc(imm16), default_exception_el(s)); break; @@ -1899,6 +1906,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) gen_a64_set_pc_im(s->pc - 4); gen_helper_pre_hvc(cpu_env); gen_ss_advance(s); + reset_btype(s); gen_exception_insn(s, 0, EXCP_HVC, syn_aa64_hvc(imm16), 2); break; case 3: /* SMC= */ @@ -1911,6 +1919,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) gen_helper_pre_smc(cpu_env, tmp); tcg_temp_free_i32(tmp); gen_ss_advance(s); + reset_btype(s); gen_exception_insn(s, 0, EXCP_SMC, syn_aa64_smc(imm16), 3); break; default: --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 1547123034689216.78426730524552; Thu, 10 Jan 2019 04:23:54 -0800 (PST) Received: from localhost ([127.0.0.1]:57522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZNJ-0000AD-5z for importer@patchew.org; Thu, 10 Jan 2019 07:23:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHf-0004bc-Mj for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHe-0007he-PN for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:03 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:45642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHe-0007gy-Ir for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:02 -0500 Received: by mail-pf1-x42d.google.com with SMTP id g62so5212170pfd.12 for ; Thu, 10 Jan 2019 04:18:02 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.17.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:18:00 -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=PRWaIbFhaCG50KtAhIfgw4/3zpMsZFNNO0ITZ9DcBeA=; b=NzarwsFOGde2+MjQqUPVg6cvBcCLs77h03WkxcnrLtGvYjPr5NedwlCyHwbH0bP6i6 MQhxNcH2TCOEQJzoJOAs4ONEK6rvceU3jr68kNE62UTtGnJOZla/mOuLAi3yCApg+ozr TlTdt3RyQrRhWOG9dmxKCm9kkbDmygsbfZMSg= 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=PRWaIbFhaCG50KtAhIfgw4/3zpMsZFNNO0ITZ9DcBeA=; b=supVwv2XXS65utpM4i6ys7LeRbKv6rXxRgtcPVLqlUs5T9mUpTVtZRlgINi6PJ5qAK PCVHw0a54ikKP5pfCTsFd5e0sCtUjXaYZHgtTmZ/GXNbvSHCZgXhk5CStvrSq/ypYgN4 huSkLrHo/NHiNmdHbFX2LMQ2zLS7tc0d8+acPTe4rWMHZUMK44Ea5wx5PpMY4cTjzd93 wJecE2G0JlRfkSSXuRggIjoZacwJ4EfsI16QRYIzwUmtq84JBkPS9h4tuv5vhzq8uWft OAwnqmpmVIfsXiouk2YFEaRkl5a7H2bSDrId5qyZwxitGuBdcnN0+91Pn7mWUbNwUUMz 33OQ== X-Gm-Message-State: AJcUukd74Cbyb/dpH2leTmPEOUCLvbT4PymbrrDPiOjCzWqCe4sDtRde aYV7sKaUHgAghDDIr0IE4UgWvCDsZLVBQg== X-Google-Smtp-Source: ALg8bN6LtAByo5WsynrHCswj2sOxMCS/RSzVvplvjJ0gZn0kTulNgf1FWICytX2+kgqsczBKVYJxTw== X-Received: by 2002:a62:710a:: with SMTP id m10mr9977016pfc.69.1547122681193; Thu, 10 Jan 2019 04:18:01 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:32 +1100 Message-Id: <20190110121736.23448-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::42d Subject: [Qemu-devel] [PATCH 07/11] target/arm: Set btype for indirect branches 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" Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/translate-a64.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index f319fa000e..5f0ecb297f 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -138,6 +138,19 @@ static void reset_btype(DisasContext *s) } } =20 +static void set_btype(DisasContext *s, int val) +{ + TCGv_i32 tcg_val; + + /* BTYPE is a 2-bit field, and 0 should be done with reset_btype. */ + tcg_debug_assert(val >=3D 1 && val <=3D 3); + + tcg_val =3D tcg_const_i32(val); + tcg_gen_st_i32(tcg_val, cpu_env, offsetof(CPUARMState, btype)); + tcg_temp_free_i32(tcg_val); + s->btype =3D -1; +} + void aarch64_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, int flags) { @@ -1985,6 +1998,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) { unsigned int opc, op2, op3, rn, op4; + unsigned btype_mod =3D 2; TCGv_i64 dst; TCGv_i64 modifier; =20 @@ -2002,6 +2016,7 @@ static void disas_uncond_b_reg(DisasContext *s, uint3= 2_t insn) case 0: /* BR */ case 1: /* BLR */ case 2: /* RET */ + btype_mod =3D opc; switch (op3) { case 0: /* BR, BLR, RET */ @@ -2045,7 +2060,6 @@ static void disas_uncond_b_reg(DisasContext *s, uint3= 2_t insn) default: goto do_unallocated; } - gen_a64_set_pc(s, dst); /* BLR also needs to load return address */ if (opc =3D=3D 1) { @@ -2061,6 +2075,7 @@ static void disas_uncond_b_reg(DisasContext *s, uint3= 2_t insn) if (op3 !=3D 2 || op3 !=3D 3) { goto do_unallocated; } + btype_mod =3D opc & 1; if (s->pauth_active) { dst =3D new_tmp_a64(s); modifier =3D cpu_reg_sp(s, op4); @@ -2144,6 +2159,26 @@ static void disas_uncond_b_reg(DisasContext *s, uint= 32_t insn) return; } =20 + switch (btype_mod) { + case 0: /* BR */ + if (dc_isar_feature(aa64_bti, s)) { + /* BR to {x16,x17} or !guard -> 1, else 3. */ + set_btype(s, rn =3D=3D 16 || rn =3D=3D 17 || !s->guarded_page = ? 1 : 3); + } + break; + + case 1: /* BLR */ + if (dc_isar_feature(aa64_bti, s)) { + /* BLR sets BTYPE to 2, regardless of source guarded page. */ + set_btype(s, 2); + } + break; + + default: /* RET or none of the above. */ + /* BTYPE will be set to 0 by normal end-of-insn processing. */ + break; + } + s->base.is_jmp =3D DISAS_JUMP; } =20 --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 154712320878064.0062011434037; Thu, 10 Jan 2019 04:26:48 -0800 (PST) Received: from localhost ([127.0.0.1]:58315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZQ5-000326-3Y for importer@patchew.org; Thu, 10 Jan 2019 07:26:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHi-0004dl-H1 for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHh-0007j5-O9 for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:06 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:35700) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHh-0007iZ-8u for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:05 -0500 Received: by mail-pf1-x442.google.com with SMTP id z9so5240333pfi.2 for ; Thu, 10 Jan 2019 04:18:04 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.18.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:18:03 -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=YHh3MpNr2I+etho4t8QqJysbEK1iGomhou5bx9QcAMY=; b=ZSICzhI50zretaTvfhil9n/gCcEstgZJug1exwZnGDFg04JjUmNuqZp9lg3JDnRmbN 8L2hIbE5CLzJaeyRR2Z37GaIvCX2RYqOhVPwok0EIkIrHg93LJswG7SQ+7jaTVjjxheD VQZDq4xjHuolLnroSNE2b8oXpUNOAxgX2Upo8= 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=YHh3MpNr2I+etho4t8QqJysbEK1iGomhou5bx9QcAMY=; b=O855MS922p+PY6tcUswH3vSe5LvdZRMs6PAwbJw1iJ2b3G+/11Lz4a3v/VA+B4RNP5 +B2oJZ32CpnK4+7WCTbGMCMlBtoeKFyYMWx8ovoFcCtYkazYQUep86yyH+cOq7oIc41k hEu9RNPoHmB+1wBBiBc3znp2HGVhUvHIfCM7YFsibWLeQiSrWB9JqSEud4A+pn8sOUMF A7S60452Jj2gQMQrz+BHh7jE6dl1s+E64tJEAwkKwtgpwWM3F3mNv/tAkYXg+LMg2yP2 41zTcfljHumBxzo5ETGOlNU4njsCej/TAVfP5ET3iZnmBTiMhkZZp/RjuSWr1tDwO3m6 mrTA== X-Gm-Message-State: AJcUukdJZE3579djZ7mdOZSbXzl/s5eTxqCKkVTe+cgJAE1o6NQ585R9 ywVie7T4M9vtYmXra2Rl+sMiiklVvnVPRQ== X-Google-Smtp-Source: ALg8bN6WeF0sUGPriMFgu8EZg1ORxWm4UF3YsigaxMAC4r9/x9fm4EgO/rzLBAdCyfVrnwbpUyMHGQ== X-Received: by 2002:a62:60c5:: with SMTP id u188mr10047799pfb.4.1547122683661; Thu, 10 Jan 2019 04:18:03 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:33 +1100 Message-Id: <20190110121736.23448-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::442 Subject: [Qemu-devel] [PATCH 08/11] target/arm: Add guarded_pages cpu property for user-only 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" While waiting for a proper userland ABI, allow static test cases to be written assuming that GP is set for all pages. Signed-off-by: Richard Henderson --- target/arm/cpu.h | 4 ++++ target/arm/cpu64.c | 18 ++++++++++++++++++ target/arm/translate-a64.c | 8 +++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 506c490a16..929f16dd6b 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -882,6 +882,10 @@ struct ARMCPU { */ bool cfgend; =20 +#ifdef CONFIG_USER_ONLY + bool guarded_pages; +#endif + QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks; QLIST_HEAD(, ARMELChangeHook) el_change_hooks; =20 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index d0de0d5dcf..713d2d5579 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -315,6 +315,18 @@ static void cpu_max_set_packey(Object *obj, Visitor *v= , const char *name, } error_propagate(errp, err); } + +static bool aarch64_cpu_get_guarded_pages(Object *obj, Error **errp) +{ + ARMCPU *cpu =3D ARM_CPU(obj); + return cpu->guarded_pages; +} + +static void aarch64_cpu_set_guarded_pages(Object *obj, bool val, Error **e= rrp) +{ + ARMCPU *cpu =3D ARM_CPU(obj); + cpu->guarded_pages =3D val; +} #endif =20 /* -cpu max: if KVM is enabled, like -cpu host (best possible with this ho= st); @@ -420,6 +432,12 @@ static void aarch64_max_initfn(Object *obj) cpu->env.cp15.sctlr_el[1] |=3D SCTLR_EnIA | SCTLR_EnIB; cpu->env.cp15.sctlr_el[1] |=3D SCTLR_EnDA | SCTLR_EnDB; } + + object_property_add_bool(obj, "guarded_pages", + aarch64_cpu_get_guarded_pages, + aarch64_cpu_set_guarded_pages, NULL); + object_property_set_description(obj, "guarded_pages", + "Set on/off GuardPage bit for all pages", NULL); #endif =20 cpu->sve_max_vq =3D ARM_MAX_VQ; diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 5f0ecb297f..f225517077 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -13780,7 +13780,13 @@ static void disas_data_proc_simd_fp(DisasContext *= s, uint32_t insn) static bool is_guarded_page(CPUARMState *env, DisasContext *s) { #ifdef CONFIG_USER_ONLY - return false; /* FIXME */ + /* + * FIXME: What is the userland ABI for this? + * For the moment this is controlled by an attribute: + * -cpu max,guarded_pages=3Don. + */ + ARMCPU *cpu =3D arm_env_get_cpu(env); + return cpu->guarded_pages; #else uint64_t addr =3D s->base.pc_first; int mmu_idx =3D arm_to_core_mmu_idx(s->mmu_idx); --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 1547123037612750.1464245608744; Thu, 10 Jan 2019 04:23:57 -0800 (PST) Received: from localhost ([127.0.0.1]:57541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZNM-0000DZ-5U for importer@patchew.org; Thu, 10 Jan 2019 07:23:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZHn-0004g4-S7 for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHk-0007kA-De for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:10 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:41738) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHk-0007jq-5c for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:08 -0500 Received: by mail-pl1-x644.google.com with SMTP id u6so5107838plm.8 for ; Thu, 10 Jan 2019 04:18:07 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.18.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:18:05 -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=2xcblPi8ob/nT206QUAh9O3OrdajZ4sfTdq1UgATXq4=; b=FVMyaHBld9lnmZQtITq/P+DHmOC3RTIcG0ICAk+OQpj8pgsejxSHE8U4bD0tm3JFyl VfaPQMeZna/5zPc6zHQrD2FZDt+v1SAKg7u6auO+OWKUSPoo/iOQmh+zJ17KDJOaDIAa aHkdcGlVcYsXEekHYpXgaffEO6xXh3RhoRtMo= 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=2xcblPi8ob/nT206QUAh9O3OrdajZ4sfTdq1UgATXq4=; b=SadIpuIpYE7e9CI1/8Qf4RvGxh7DAvDFJMlrWdu4LuN6j1hYAo05dLVbqrn+r9mVLT zYamcebBsnKXVk8HoTC9GtGCWAiC25FZ9B87dQNebNkmwQMq7WSo4LxHjwCRGZhC2wOO 0lt6S6mh3+esx51UMIbQO9yGFkUYQpWRuRukwLavAF6gy0OOxbznsRxOdkvFHs/45HqU hDLcj9oZ66Ku0J97VY0Vf4i+Nrwy1TzCR0OuyzsGAxgkkOJPsOMokoFfC/z9Nl70dT14 w3hutCkgl7NpF00A2V54yNHvOeqZJOWRuyJhCwLl1/QqDfMx9VRY/Ix/7TyfOhLN+Glq k3Iw== X-Gm-Message-State: AJcUukdWpkHEZgUqkIqzBS6g4hf79CFwAVeG58XAqyQd6H7Pt327TR9I 8vOsFJoZR0fnPwE4JeWVe05cy+arZL0Q/g== X-Google-Smtp-Source: ALg8bN7C+tMb6yKbD8vhlhAF1lpxMmtegeQbQ0q2cbQ8s5fRU/fszoL0VPnmm7VCvbSpX7d6wEdD8A== X-Received: by 2002:a17:902:8a95:: with SMTP id p21mr10368637plo.183.1547122686288; Thu, 10 Jan 2019 04:18:06 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:34 +1100 Message-Id: <20190110121736.23448-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::644 Subject: [Qemu-devel] [PATCH 09/11] target/arm: Enable BTI for -cpu max 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" Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/cpu64.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 713d2d5579..64fbe75eca 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -372,6 +372,10 @@ static void aarch64_max_initfn(Object *obj) t =3D FIELD_DP64(t, ID_AA64PFR0, ADVSIMD, 1); cpu->isar.id_aa64pfr0 =3D t; =20 + t =3D cpu->isar.id_aa64pfr1; + t =3D FIELD_DP64(t, ID_AA64PFR1, BT, 1); + cpu->isar.id_aa64pfr1 =3D t; + t =3D cpu->isar.id_aa64mmfr1; t =3D FIELD_DP64(t, ID_AA64MMFR1, HPDS, 1); /* HPD */ t =3D FIELD_DP64(t, ID_AA64MMFR1, LO, 1); --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 1547123211090809.6460949611815; Thu, 10 Jan 2019 04:26:51 -0800 (PST) Received: from localhost ([127.0.0.1]:58335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZQ9-00035E-P2 for importer@patchew.org; Thu, 10 Jan 2019 07:26:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZI2-0004nh-3S for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZHu-0007nY-I2 for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:22 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:38951) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZHo-0007kU-6W for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:13 -0500 Received: by mail-pl1-x641.google.com with SMTP id 101so5114634pld.6 for ; Thu, 10 Jan 2019 04:18:09 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.18.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:18:08 -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=p2TU+6xewpFPfZjXVs3cgyi3ohvpda2DuzV/stCY8oE=; b=AJuLh51mCjv+PuR7LJlWLy0+bBdGQxM2YHVFZgU8IqRAy9ye5EVa2UVVT7/OQnnMlZ JIajoHJVxnWpRvchgc2UYuoVn4+TQecYAZ7ltNTJogNVDA/rpZTnzm9tt8gAh9Sm3c8l w3pYWSdzUSO25Vr66BKyqwPHBEUA5YJJRW59s= 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=p2TU+6xewpFPfZjXVs3cgyi3ohvpda2DuzV/stCY8oE=; b=LeFGlfl9i0qjXJ73bVbDP9GSDxmwFE0eK7yhT+he+kG314GNjq7FJw5Yc/IFYXoF0T 89vIGF/yoTgO0C4gv4Dm1KJ8bBLUEiwazqbGY3+pbfxchrfnjaHUNHWwghKFBX4bJLY+ AYUPeoTtxrqa00WkSq0xY/P7cvSHesrcWh4L/2Ml85Rtj5C6B9kyQN/8sQxPjUnkXuZA YamXgchPgN0Ay/mkIcwqMuEDDMCDzXRBHEx0VepAZHxj3D9uckxAa6KmXeWiAb0kjw1V myqPxDuK8F/8kJ4P3QwWzbxWfC7R8D3UCr85EWNzQAAlBTyCrch19n3DCM6T+azlKBgy BCkA== X-Gm-Message-State: AJcUukftJz2TDyrAPDDlRgkKNV99fUAXSWot9zq+aXoHWkcbBj9KFdpy gQmGPCrluHwkxCUYk7VDL0XhKh8axAr3eg== X-Google-Smtp-Source: ALg8bN7+V7BJZ0gQIli00YoRfM6cX3fWJGBkyilbUuVYD4aWNjjV+IvOj8RX98Jr4vuK9SMYz6UDhw== X-Received: by 2002:a17:902:ba89:: with SMTP id k9mr10262428pls.189.1547122688704; Thu, 10 Jan 2019 04:18:08 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:35 +1100 Message-Id: <20190110121736.23448-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::641 Subject: [Qemu-devel] [PATCH 10/11] linux-user/aarch64: Reset btype for signal handlers 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" It does not make sense for a SIGILL handler to enter with the btype set as for the indirect branch that caused the SIGILL. Nor does it make sense to return from a handler with BTYPE set. This could be argued to be the handler's job, setting BTYPE within ucontext->uc_mcontext.pstate, but handling this here while the ABI is undiscussed. Signed-off-by: Richard Henderson --- linux-user/aarch64/signal.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index f84a9cf28a..1fb229e696 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -218,6 +218,8 @@ static void target_restore_general_frame(CPUARMState *e= nv, __get_user(env->pc, &sf->uc.tuc_mcontext.pc); __get_user(pstate, &sf->uc.tuc_mcontext.pstate); pstate_write(env, pstate); + /* Reset btype that might have been there going into the frame. */ + env->btype =3D 0; } =20 static void target_restore_fpsimd_record(CPUARMState *env, @@ -510,6 +512,8 @@ static void target_setup_frame(int usig, struct target_= sigaction *ka, env->xregs[29] =3D frame_addr + fr_ofs; env->pc =3D ka->_sa_handler; env->xregs[30] =3D return_addr; + /* Reset btype going into the signal handler. */ + env->btype =3D 0; if (info) { tswap_siginfo(&frame->info, info); env->xregs[1] =3D frame_addr + offsetof(struct target_rt_sigframe,= info); --=20 2.17.2 From nobody Sat Apr 20 00:34:09 2024 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 1547123347207266.7094531388441; Thu, 10 Jan 2019 04:29:07 -0800 (PST) Received: from localhost ([127.0.0.1]:59008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZSL-0004qq-OD for importer@patchew.org; Thu, 10 Jan 2019 07:29:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZIC-0004ww-Ch for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZIA-0007vL-CE for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:36 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:39998) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZIA-0007lM-5m for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:34 -0500 Received: by mail-pf1-x441.google.com with SMTP id i12so5226894pfo.7 for ; Thu, 10 Jan 2019 04:18:12 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.18.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:18:10 -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=DkHGGDD7DZ0xeYnvEOJO+AcazmZv0MJI3ad+LhKQaBM=; b=ZWbOKnnoVob0MUDon/MRZWEq8OtvqHwAOpVhlbbnFPFssNXnwD9e8xlqZSMkmTpZRX sPR+Ng7H7YxNmdDeB63qrJNP3FTGvoESiXppuiBEpfeQapQj8JGsZ+94wbITps2PDTPR lQfCqO5QP166uuiW2Adytxrn3l0oQFHPGPymo= 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=DkHGGDD7DZ0xeYnvEOJO+AcazmZv0MJI3ad+LhKQaBM=; b=D3/w2VlA6+zMiPtYYqWoxRkCwCJPocHT9/KG/6kY7jFjZs4PadhBDe6BcYQBndHUkF EXNq1LKZKgA/hXnV0Ahts4S5Ryw+yBF4DqcUPdiulOphaypN/OfYPsJhnhDGN6hEYbik qW1QAlsJ4OGbNQjNfQpQbba61VnuogUSiNdKJ3N8FqbCJHL/9LWq2lmNOYl7+FAlW5xT 9KcX0EXmqOtwTUOzREOKbz29WLxWbKq6cCo3n10PZ/ecosYFVhH0XMQfJZUeamN0R9VR l1GmKA9QtPbqxoh4npxSCJQ0Xl8Hcux1w49cn4IbDklyIj6lKXaV9nzQsu/7jmV0BQVU VHEg== X-Gm-Message-State: AJcUukf/isM6U1L8Bfme12srhbnGrJXyjFsk1UD8p+M15zjHRKfcwJpR +wacHqLV8VZv7u8JfIELxUALP1kWnQVAmw== X-Google-Smtp-Source: ALg8bN7HFxqaPjC4vmiOd9cc5LiZXPttVKWjfir+YEkdMnxZ5QuXMgIe2c2cMUa5++cqPHctZYAXBw== X-Received: by 2002:a62:8e19:: with SMTP id k25mr9978801pfe.185.1547122691272; Thu, 10 Jan 2019 04:18:11 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:36 +1100 Message-Id: <20190110121736.23448-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::441 Subject: [Qemu-devel] [PATCH 11/11] tests/tcg/aarch64: Add bti smoke test 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" Signed-off-by: Richard Henderson --- tests/tcg/aarch64/bti-1.c | 61 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/bti-crt.inc.c | 51 ++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 7 +++- 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/bti-1.c create mode 100644 tests/tcg/aarch64/bti-crt.inc.c diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c new file mode 100644 index 0000000000..fa8a521a47 --- /dev/null +++ b/tests/tcg/aarch64/bti-1.c @@ -0,0 +1,61 @@ +/* + * Branch target identification, basic notskip cases. + */ + +#include "bti-crt.inc.c" + +static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) +{ + uc->uc_mcontext.pc +=3D 8; +} + +#define NOP "nop" +#define BTI_N "hint #32" +#define BTI_C "hint #34" +#define BTI_J "hint #36" +#define BTI_JC "hint #38" + +#define BTYPE_1(DEST) \ + asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x16") + +#define BTYPE_2(DEST) \ + asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x16", "x30") + +#define BTYPE_3(DEST) \ + asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x15") + +#define TEST(WHICH, DEST, EXPECT) \ + do { WHICH(DEST); fail +=3D skipped ^ EXPECT; } while (0) + + +int main() +{ + int fail =3D 0; + int skipped; + + /* Signal-like with SA_SIGINFO. */ + signal_info(SIGILL, skip2_sigill); + + TEST(BTYPE_1, NOP, 1); + TEST(BTYPE_1, BTI_N, 1); + TEST(BTYPE_1, BTI_C, 0); + TEST(BTYPE_1, BTI_J, 0); + TEST(BTYPE_1, BTI_JC, 0); + + TEST(BTYPE_2, NOP, 1); + TEST(BTYPE_2, BTI_N, 1); + TEST(BTYPE_2, BTI_C, 0); + TEST(BTYPE_2, BTI_J, 1); + TEST(BTYPE_2, BTI_JC, 0); + + TEST(BTYPE_3, NOP, 1); + TEST(BTYPE_3, BTI_N, 1); + TEST(BTYPE_3, BTI_C, 1); + TEST(BTYPE_3, BTI_J, 0); + TEST(BTYPE_3, BTI_JC, 0); + + return fail; +} diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.in= c.c new file mode 100644 index 0000000000..ef7831ad76 --- /dev/null +++ b/tests/tcg/aarch64/bti-crt.inc.c @@ -0,0 +1,51 @@ +/* + * Minimal user-environment for testing BTI. + * + * Normal libc is not built with BTI support enabled, and so could + * generate a BTI TRAP before ever reaching main. + */ + +#include +#include +#include +#include + +int main(void); + +void _start(void) +{ + exit(main()); +} + +void exit(int ret) +{ + register int x0 __asm__("x0") =3D ret; + register int x8 __asm__("x8") =3D __NR_exit; + + asm volatile("svc #0" : : "r"(x0), "r"(x8)); + __builtin_unreachable(); +} + +/* + * Irritatingly, the user API struct sigaction does not match the + * kernel API struct sigaction. So for simplicity, isolate the + * kernel ABI here, and make this act like signal. + */ +void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *)) +{ + struct kernel_sigaction { + void (*handler)(int, siginfo_t *, ucontext_t *); + unsigned long flags; + unsigned long restorer; + unsigned long mask; + } sa =3D { fn, SA_SIGINFO, 0, 0 }; + + register int x0 __asm__("x0") =3D sig; + register void *x1 __asm__("x1") =3D &sa; + register void *x2 __asm__("x2") =3D 0; + register int x3 __asm__("x3") =3D sizeof(unsigned long); + register int x8 __asm__("x8") =3D __NR_rt_sigaction; + + asm volatile("svc #0" + : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory= "); +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 08c45b8470..3d56e7c6ea 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -8,10 +8,15 @@ VPATH +=3D $(AARCH64_SRC) # we don't build any of the ARM tests AARCH64_TESTS=3D$(filter-out $(ARM_TESTS), $(TESTS)) AARCH64_TESTS+=3Dfcvt -TESTS:=3D$(AARCH64_TESTS) =20 fcvt: LDFLAGS+=3D-lm =20 run-fcvt: fcvt $(call run-test,$<,$(QEMU) $<, "$< on $(TARGET_NAME)") $(call diff-out,$<,$(AARCH64_SRC)/fcvt.ref) + +AARCH64_TESTS +=3D bti-1 +bti-1: LDFLAGS +=3D -nostartfiles -nodefaultlibs -nostdlib +run-bti-1: QEMU +=3D -cpu max,guarded_pages=3Don + +TESTS:=3D$(AARCH64_TESTS) --=20 2.17.2