From nobody Wed Oct 1 00:55:48 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 1548716103270622.9743375438684; Mon, 28 Jan 2019 14:55:03 -0800 (PST) Received: from localhost ([127.0.0.1]:39746 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFny-0007D3-89 for importer@patchew.org; Mon, 28 Jan 2019 17:55:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcG-0006rk-AX for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRB-0006AT-0f for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:30 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:44846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFR9-00069M-BE for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:28 -0500 Received: by mail-ot1-x341.google.com with SMTP id g16so12158073otg.11 for ; Mon, 28 Jan 2019 14:31:27 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:25 -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=oB13W6ViuF4Pl3PcFp1ZSaIRPV4uku7wsFdqo+bmYms=; b=SAqyu7nl3vK4PqEKjZSlnJuCOuhkV7s7VzPm7xYw9iO28zPz3+uCJdiarYOTHBzy6O Q40WuIhUphNRq8Cv+9dhGFy/yTbz6JpVJp140anXok8ssrTpaRPdqenk0aat3ftP0y/0 YMf6hPkWACkq9R2KjfpjPMAdO/QQRUzAaJz6c= 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=oB13W6ViuF4Pl3PcFp1ZSaIRPV4uku7wsFdqo+bmYms=; b=DzTnAK0lOoFcH0ukf9aGEhs8swqtJGK0j6ZzZPlDhQ70OmMiQzN87pFhnzs8bld8IQ xiOLBiHbJLIa3Xn5qyntja/+COT5g2HJKpklQetY6Wd1J4w8wyKR9Hqmjrj1DzuHJSDL 2CACp4qfdEvrK+0tZQNKuJi2nCFoyDxho3LxFQEkdsZZEh9MPY2H1YorMSE3pxMtSliW hgdA3aoa0bjLOHSSujeFve+pLDHbWcWQb2WbllRtim5zo+mLO5zvQsGSkkw9KJhKD7F1 lG4kNO/4+PCv3zGfQYvI9lebt5jP1FkzW9ZTL41CTAflwdpyG6O3Iw1y7hOV4WMOwQQq 5+Xw== X-Gm-Message-State: AJcUukeiZ2neZhzWnvNnejoUrBSiU77mCmtKI4NETRkD99R+0jtUXkGY cSWT/m44UNIwpms1CIFFrz/EtcTnJ+g= X-Google-Smtp-Source: ALg8bN7NPfpAqIomrTA9IHRNkevg7Qt33TQRPME3ORzlpkzj4cy/hF/0nqHFgXbtfy331HJ0QRDoAQ== X-Received: by 2002:a9d:2af:: with SMTP id 44mr18099350otl.181.1548714686174; Mon, 28 Jan 2019 14:31:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:07 -0800 Message-Id: <20190128223118.5255-2-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::341 Subject: [Qemu-devel] [PATCH v2 01/12] 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. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v2: Include MTE and RAS_FRAC fields of AA64PFR1. --- target/arm/cpu.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index ff81db420d..d7190f0712 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1672,6 +1672,11 @@ 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_AA64PFR1, MTE, 8, 4) +FIELD(ID_AA64PFR1, RAS_FRAC, 12, 4) + FIELD(ID_AA64MMFR0, PARANGE, 0, 4) FIELD(ID_AA64MMFR0, ASIDBITS, 4, 4) FIELD(ID_AA64MMFR0, BIGEND, 8, 4) @@ -3319,6 +3324,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 Wed Oct 1 00:55:48 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548716496074370.6881032111162; Mon, 28 Jan 2019 15:01:36 -0800 (PST) Received: from localhost ([127.0.0.1]:39878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFuE-0004DR-0v for importer@patchew.org; Mon, 28 Jan 2019 18:01:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcD-0006iZ-2v for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRD-0006Bb-1k for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:32 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:39656) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRB-0006A1-5S for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:30 -0500 Received: by mail-ot1-x344.google.com with SMTP id n8so16173280otl.6 for ; Mon, 28 Jan 2019 14:31:28 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:26 -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=L1V0Cb951FG+u8k/qfbiwXAE3MaliW8mMdVB2nz63mc=; b=GEqDlfPeCWheGeQKmnNw7Rl3t6XL7mh2Cx7O2fKmN2wMG4+95eplmxpJ2cXAxzaHOL zZNfQBV4OKPRNDRaivN/XP/Uj2fyZEhDocIQJvtsvVacDwri2c9lVm2G2UiaaaiN9oR0 yT/SsLg2Xo8JDXB705g2b+OQJA4uZilVMS0ec= 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=L1V0Cb951FG+u8k/qfbiwXAE3MaliW8mMdVB2nz63mc=; b=Qr7IZz0PChdHbzSKRSkJWYMBlPfVmCKszwlEqxDvkHIzLKaNZeEigA6K/fbX2iMKf/ ITka71eDbCErooVpyMRgcKpoDZpJFXt2EUZKmM+YyYzm6S27Azy97QjP9I6IX4KHsZCS kfdg4GOOf30KQlwi8wCCJC8g8cqb25crMgNsENZ/yGG8+kUmbLRalbmqHGh5eEYJRBD7 P1Zua8drwuS0OgNvncOQLREYxY48MOmr/IhNEKaPUJOdhy5ICNDIMjf3Va9hvZoTeOTP GNhHDGcVNgUTi+JPDH4Jxuo5xHyF5l8qG2j1WP5aaCW0iuXSSGzo9NPd2yeMrrrmyBxd 0+Dw== X-Gm-Message-State: AJcUukcYAjB/O48Pp8uBB7RN+Axn/QuXoccXcujTwDxFe7H5DUpSnDrs +xDM/uHkD0QBBPQodu4qWi+QZyGXeoM= X-Google-Smtp-Source: ALg8bN6BivlY5nDYgnJjTQpJ8U0EDUzYuxT3KQqT57HJl2rmrma2NTzuKYoAWroDY51fxkynXMFGhQ== X-Received: by 2002:a9d:721e:: with SMTP id u30mr18117064otj.203.1548714687523; Mon, 28 Jan 2019 14:31:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:08 -0800 Message-Id: <20190128223118.5255-3-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::344 Subject: [Qemu-devel] [PATCH v2 02/12] 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. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- 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 d7190f0712..76e2f8fd42 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 */ @@ -1197,6 +1199,7 @@ uint64_t get_pmceid(CPUARMState *env, unsigned which); #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) @@ -1205,7 +1208,7 @@ uint64_t get_pmceid(CPUARMState *env, unsigned which); #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 @@ -1237,7 +1240,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) @@ -1247,6 +1250,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 4d28a27c3b..611279e98e 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 Wed Oct 1 00:55:48 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 1548715918054784.8586722521687; Mon, 28 Jan 2019 14:51:58 -0800 (PST) Received: from localhost ([127.0.0.1]:39724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFky-0004ux-VN for importer@patchew.org; Mon, 28 Jan 2019 17:51:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcC-0006rk-Ue for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRE-0006Cn-Ua for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:34 -0500 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]:35290) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRE-0006Ai-Js for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:32 -0500 Received: by mail-oi1-x244.google.com with SMTP id v6so14530861oif.2 for ; Mon, 28 Jan 2019 14:31:29 -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.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:27 -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=yfx9FpdqdozZiBPg7dcsv6e5CFB+7qa5v/xOlmbgNhY=; b=kM4pn0wB9UQR3RwymhGca/pcSefCUtQUgGGnOOBospAPrRGzF2FuPPeq3FuWtRpjuE qgduZmP4+N0hoThqHclyS+E7FuZZWum3hY7bkXqpOq3dXUEK7vXW7PK/2qjl5oOB5Leb x90pq8fSLHWvnsKEjjqKvUTCNm178LayPE+n8= 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=yfx9FpdqdozZiBPg7dcsv6e5CFB+7qa5v/xOlmbgNhY=; b=AcP1piEgnaWCFpWjM2Pl/+0FT+P6iBceBUueutx6OU1zTRp89dF/5CYYvtc7nONvBC YQ42ZxE0oQ3HXLOd0NkH08Jpmg1GX5bIZIqjGk93jPafEmOxQD8Hm1XR1bajGGz+2UlE sl0SqyQjXE3ElJLsoEHd0PUjUUdTwio+UuU47RdaLbv77gfXfLyTHGui2l8zGhFqPSCT sasV0blvhVnl/56uviaNZFlL+elgt2YwwiGbeTGFGeD7NkFK1mODtdaXNCsLAL0uRatc jydH4EwFf+ZIXKoXjf4Zf5ZLlFDXezDJL+wN7Kifq6thaySAF1MqQjM1tr1gx2ZgJAlV iOyQ== X-Gm-Message-State: AJcUukctIn2VlyGE/5/KjTxqI6quo9XM9sBBQOOmi8o7YjoieDgjMu+y 0DcWuQsLv+VRl0Sh1qKU2jtGWTB06nw= X-Google-Smtp-Source: ALg8bN6ZlkTfgoWdL3TKZm9tusiJfU9wcZzJs9E5wx5rDX4EKEzEVkgEhkBijLCWNIFvd03DR6mnNg== X-Received: by 2002:aca:aad8:: with SMTP id t207mr7021779oie.90.1548714688679; Mon, 28 Jan 2019 14:31:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:09 -0800 Message-Id: <20190128223118.5255-4-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::244 Subject: [Qemu-devel] [PATCH v2 03/12] 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" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- 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 76e2f8fd42..e18f823419 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3043,6 +3043,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 92666e5208..6efe88a157 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -13607,6 +13607,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); @@ -13651,6 +13652,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 @@ -13658,17 +13665,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 611279e98e..9ce523e2ff 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -13801,6 +13801,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 Wed Oct 1 00:55:48 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 1548715597966337.0599612234113; Mon, 28 Jan 2019 14:46:37 -0800 (PST) Received: from localhost ([127.0.0.1]:39647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFfo-00010A-Sf for importer@patchew.org; Mon, 28 Jan 2019 17:46:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcA-0006wV-IB for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRS-0006Jz-NK for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:48 -0500 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]:37911) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRR-0006B8-0J for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:46 -0500 Received: by mail-oi1-x241.google.com with SMTP id a77so14513303oii.5 for ; Mon, 28 Jan 2019 14:31:30 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:29 -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=PuHA9slAwS6cMEvVcURGk2HxWJ9T4N5ch4vNRS6j+AM=; b=IiWuYMX1jpvgkxpK0LDH6uYffIgdEnbsgvw9Lfkk0W7xO9fnyr8g9p22PbEigM8Sqw yOo2D1YmFxwKbRgsf4j2VsvQmCtVB6LT50Ov0eGoW1T/4eeRMnN09iMEe2mDIoBPBwaX y8tHO7u7lh3OgGE6q/RjrKaDy7+EpcisfC0NU= 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=PuHA9slAwS6cMEvVcURGk2HxWJ9T4N5ch4vNRS6j+AM=; b=STy/mrElMEOGioQ7zOA4WbycSMquvOeQx6qQR7sWPAFFF9SvEQwmE9gH/A6LpMna5g 9T1dQtaC38iqbO7QTFWvWdyUiOKFgzpJY9U+IlVttcLws7PnnZezqKCZiK3au8L5N912 s1cMb5S8m0Jl/YO7qWIFTCLi6HljstVfz/DwE7qHPMJ7/+87wmrI4B5vu7k0nT9uTVSW 3uGOG3NPIjdnbAvN0KNYWDZONzURlE6bEAalU1EeXp+peftNK8FcLXKHWIqGewuL9vyl 0asxUerYreZWPo4AdU8wkBkQWYzjJH7ZtXr7sYZW8BpdvW3GQK43ZhPSmc9+ddunxSxl sBdQ== X-Gm-Message-State: AJcUukfhDPIeP4H7YnQPN6ibyfYibqqUCQyPtHJJBWexxaUxRWzh1Q3I MpC7eWIcTC+8AJsYkhopLKO0jpx8kkk= X-Google-Smtp-Source: ALg8bN5qqI3YNpWsfPvp+6zAJPp5z07gTGChpcQ3T/NEuJbv7KboXO+InqjGpl7x9EI1jyhFVNh9ew== X-Received: by 2002:a54:450f:: with SMTP id l15mr7612944oil.351.1548714689843; Mon, 28 Jan 2019 14:31:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:10 -0800 Message-Id: <20190128223118.5255-5-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::241 Subject: [Qemu-devel] [PATCH v2 04/12] exec: Add target-specific tlb bits to 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" These bits can be used to cache target-specific data in cputlb read from the page tables. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/exec/memattrs.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index d4a1642098..d4a3477d71 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -37,6 +37,16 @@ typedef struct MemTxAttrs { unsigned int user:1; /* Requester ID (for MSI for example) */ unsigned int requester_id:16; + /* + * The following are target-specific page-table bits. These are not + * related to actual memory transactions at all. However, this struct= ure + * is part of the tlb_fill interface, cached in the cputlb structure, + * and has unused bits. These fields will be read by target-specific + * helpers using env->iotlb[mmu_idx][tlb_index()].attrs.target_tlb_bit= N. + */ + unsigned int target_tlb_bit0 : 1; + unsigned int target_tlb_bit1 : 1; + unsigned int target_tlb_bit2 : 1; } MemTxAttrs; =20 /* Bus masters which don't specify any attributes will get this, --=20 2.17.2 From nobody Wed Oct 1 00:55:48 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 154871551518625.222577273040883; Mon, 28 Jan 2019 14:45:15 -0800 (PST) Received: from localhost ([127.0.0.1]:39607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFeU-0008Pb-6e for importer@patchew.org; Mon, 28 Jan 2019 17:45:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcB-0006iZ-5Y for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRQ-0006Ic-Ns for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:46 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:46884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRO-0006Bz-N1 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:42 -0500 Received: by mail-ot1-x343.google.com with SMTP id w25so16140538otm.13 for ; Mon, 28 Jan 2019 14:31:32 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:30 -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=D+PDofj1o/9B5dTtIL1BwBv8O4UrkEKB0kHElaN43pE=; b=NdmIDKY2WqNM3i55GEzJfoTuSM+FZCANmO2dZQMf2ZTjKzid9qHttBI016VTpl42C+ gw8ceq5CVBehzAvgeGA9z2ogiYZJ0qJlkncHhBLRHUN8gdcGQMaWQx+dQoxwqPjjKAGf 6K64Cc577uDCMTPZjo3jTWkqARqM0IXyUM2Xg= 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=D+PDofj1o/9B5dTtIL1BwBv8O4UrkEKB0kHElaN43pE=; b=rkOQ53dGxqyHj7JONXTsH9nzqEqEFWmICxsVSUaIrePqL5cS9juBi5PYVh6IlB5uN2 fIw0En7+RJBDm4OPJLz0yuY79Np5YAX/SAAuR/k6sHmR8wx0MkWXHaTmbiIXGxW8rkYp zaoTdp8GhWB+sRkG/NbcunM63TNMYNQQKNkCz92OqqR6WskSyRrps0WOdTJXNfLh7T/Y e+QNvBiHeKgVk+FrN0U5BaUm18AzwHFXyq8AQY4zO9MMl7xfM3TwBtQR1p2sCZ7LtwDa zhznc0bX+sx0lOaFA6bBY5c5jFjro49fB0ihQcqqRsnLNZzwoVPX7UrpnyrPH7uUe2VN XrIQ== X-Gm-Message-State: AJcUukfv9NJnn546ET8YHf11lfdQbKbNoS+0jVddljFXke6/Tloe6gQP y2fGvwX+4qa0Q1vAduVKwM+yi1vUCzY= X-Google-Smtp-Source: ALg8bN4FZDb/Mwgcnu4pe/5QjkB+kE9Z/6d0PqlsDS9PjMBzCDaugOTqX5rZCpu9wav5oSr4e3bfow== X-Received: by 2002:a9d:6c44:: with SMTP id g4mr16550494otq.368.1548714690939; Mon, 28 Jan 2019 14:31:30 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:11 -0800 Message-Id: <20190128223118.5255-6-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::343 Subject: [Qemu-devel] [PATCH v2 05/12] target/arm: Cache 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" Caching the bit means that we will not have to re-walk the page tables to look up the bit during translation. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/helper.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/arm/helper.c b/target/arm/helper.c index 6efe88a157..70277222da 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10457,6 +10457,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, ta= rget_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. @@ -10629,6 +10630,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; @@ -10674,6 +10676,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->target_tlb_bit0 =3D true; + } =20 if (cacheattrs !=3D NULL) { if (mmu_idx =3D=3D ARMMMUIdx_S2NS) { --=20 2.17.2 From nobody Wed Oct 1 00:55:48 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 1548715724197689.5523056963747; Mon, 28 Jan 2019 14:48:44 -0800 (PST) Received: from localhost ([127.0.0.1]:39667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFhr-0002Nc-3J for importer@patchew.org; Mon, 28 Jan 2019 17:48:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcB-0006wV-Dl 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 1goFRP-0006Hh-0I for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:44 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:44849) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRM-0006Cj-Sj for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:42 -0500 Received: by mail-ot1-x344.google.com with SMTP id g16so12158270otg.11 for ; Mon, 28 Jan 2019 14:31:33 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:31 -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=xY3AiwlvI8bD51I3D9hVlZ1QPX6oH0ZaOkYhIUDuI8E=; b=HuFTKCD43GNTykYYB/RbQ+tJnUTHP7j3BXGknLKia2e0pfPtwJDbQFxNHa7TU9pxZJ UVquzPqQsSgSBCjbpBGMtCI8vzy2yZ7L+EJB2ThgAT6A5nshMKsP9Tj38rCyfUuYjccS s2QyN2Ty8DYp8RBjV6MH7aYzz8JRj2lLDSgGw= 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=xY3AiwlvI8bD51I3D9hVlZ1QPX6oH0ZaOkYhIUDuI8E=; b=j2AeHdLMXJd7pgRw5YSzkCJOhIir8w0roWeyX0Mcr9iREpzCe12KfoTvFglnGZc6dL V3f9f2YouRI9hrlIGpMldzPErfu3GyVmliIpPgc/GL68beK7jwYcR3VUnvRRhSBu/Xgb mfTeHhsZ/lsP+Tz6fhcwInXMmbnnoIfuULGdmwBPEFnNBs7yNjuA9lbBx3QG8bwqwhO3 T+ecWPAXrLdSqqwj1DK7QRdW0VIvTUMPG8Bo99sQxJboOx+SZewv7Fba0ep+rhPvyg5P YYOc1YxWkMKb7x8Qupb4+RwiPq2EYWvKHdFxkXk4BzYoUhP0vAL1mbG1qNWS+8YrEw/H xxQg== X-Gm-Message-State: AJcUukeYMEPCs+eNQcr0ayLch5gnfgOAbCDTp/CzgF9xU2sKwka5xw8O UgAlVlrprpvwSpBP8d7K2xPZcc2c08g= X-Google-Smtp-Source: ALg8bN50Z9bnq7UaVieyfih724jd2vRSqhy0mDJfPtWWwjaYksZXq90+JrlITHsJo33+J4etlRaqMw== X-Received: by 2002:a05:6830:1453:: with SMTP id w19mr18001388otp.213.1548714692041; Mon, 28 Jan 2019 14:31:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:12 -0800 Message-Id: <20190128223118.5255-7-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::344 Subject: [Qemu-devel] [PATCH v2 06/12] 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. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v2: Change octal constants to binary. --- 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 9ce523e2ff..bb64a47c0f 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) { @@ -13717,6 +13727,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.target_tlb_bit0); +#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 0b011001: /* PACIASP */ + case 0b011011: /* 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 0b100000: /* BTI */ + /* Not compatible with any btype. */ + return false; + case 0b100010: /* BTI c */ + /* Not compatible with btype =3D=3D 3 */ + return btype !=3D 3; + case 0b100100: /* BTI j */ + /* Not compatible with btype =3D=3D 2 */ + return btype !=3D 2; + case 0b100110: /* 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) { @@ -13728,6 +13822,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); @@ -13764,6 +13895,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 Wed Oct 1 00:55:48 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 1548715724735267.43502862349465; Mon, 28 Jan 2019 14:48:44 -0800 (PST) Received: from localhost ([127.0.0.1]:39669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFhr-0002OF-JO for importer@patchew.org; Mon, 28 Jan 2019 17:48:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcC-0006iZ-4F 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 1goFRI-0006EL-HK for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:40 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:33122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRG-0006DJ-QN for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:36 -0500 Received: by mail-ot1-x341.google.com with SMTP id i20so16202603otl.0 for ; Mon, 28 Jan 2019 14:31:34 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:32 -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=g/wlaoP5e340Ci6J1OFniSrZU/3oGYMfCDfo8IwBy0Y=; b=BI4HhTc4xKOxmY35izj+YJxBCtSf+DdfUtMBhEupQKEfHFJUi2uBZ6jY99ZJSbvwRY 344EveFisW39/lCGiXN1WLAR/BfeXGbhGBj4VAeK9/6PlptBajtqTmqh90iIVVgEklP/ oIfxWC2J1FSX1iH3Qn7Y2ZK27RavZRo+0ELv4= 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=g/wlaoP5e340Ci6J1OFniSrZU/3oGYMfCDfo8IwBy0Y=; b=YECwWh5wehO2JrQjeJapll+S8h9Q6OCvT8W3gQSWBcmCrOaDqhC15Pn+zDDCpZgeVd 6oW+FhSOZ/Gc4gGJC2iN5ZLUq55JrPe3jLkknLMRO/uUrRlnp0iUgTGo9ucC6f/KVSuh G6ZbB1U7aaIlroN5xnvJVwj916tkyiGHz+Xa1tvrIa3SsLPrSwhjbvetatrmmyf7Ry4x s9hZfZwhlS8Tmyfag7VYTPuHHRUrkd6e0cm/CwRxZgCSO7gqQNcss8xLG/q/DXKXEpKW aozsfo41Q+m7a3uENK33hwbAX5JoQUyc5sxdEsWq/8ZENba5ESbSp/XC9MKKF37r/Q2P Q8Hw== X-Gm-Message-State: AJcUukdk1Tkfy01oYrjbwaMsAP9J1olhqH9PoLlrWPY1szSIR6qkn/YS keWAfyoAzqTuHFCbhG95AFuMBQ8no6w= X-Google-Smtp-Source: ALg8bN7daxsgKhgvaxrcs3o7vwiypsWzSnnVr22JfqsB4TKDqrW9+jjfB0dhGfFRIctBElrvPM93tA== X-Received: by 2002:a9d:6a1a:: with SMTP id g26mr18305385otn.172.1548714693253; Mon, 28 Jan 2019 14:31:33 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:13 -0800 Message-Id: <20190128223118.5255-8-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::341 Subject: [Qemu-devel] [PATCH v2 07/12] target/arm: Reset btype for direct 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" This is all of the non-exception cases of DISAS_NORETURN. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- v2: Do not reset byte for syscalls --- target/arm/translate-a64.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index bb64a47c0f..dbac09743c 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: --=20 2.17.2 From nobody Wed Oct 1 00:55:48 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1548715695589173.90273548292066; Mon, 28 Jan 2019 14:48:15 -0800 (PST) Received: from localhost ([127.0.0.1]:39661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFhE-0001wD-6B for importer@patchew.org; Mon, 28 Jan 2019 17:48:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcA-0006rk-8B for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRS-0006K6-Nk for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:48 -0500 Received: from mail-oi1-x242.google.com ([2607:f8b0:4864:20::242]:43115) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRR-0006Dv-So for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:46 -0500 Received: by mail-oi1-x242.google.com with SMTP id u18so14489180oie.10 for ; Mon, 28 Jan 2019 14:31:35 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:33 -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=aRqO13PLpb8W1n66DnnonWFep8pSE0GiVCC/pgwaWCQ=; b=PKihwxIrGPGSXs+bIXxW9YSKLQPSZQLQz4sXM6HpYPS1Yzafh8FK+8uVmRls3d0ocU pq0033qUW+BD+qJ5Uru7btawxqHNZ+VHi3sTv9XJacz3JUo97LB449ve9ULdG/ExiCO2 JSEqRWvb91RhaSbIjAz3tIntNLKjb+jHLZevI= 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=aRqO13PLpb8W1n66DnnonWFep8pSE0GiVCC/pgwaWCQ=; b=sTdAKyyov/+Sp72pvSdQLP7o0EmqXfMSH09mZUidM2/0g5iD49unUTgscyVFpRhozZ MYQGUSvoaaVwqRMsUWdfZEkP/DWX9H6BlNWIauOR0atI6mYuKfegazOjsVtTdlcwRkTl cPJLrmG78HDn6cT4nrwuyUhD0WpsGtz997Kwdv2BRgH+toGwcU7vxAuEaf8Dn5VxoTnr 2SEm8veGJ+g9W5oR6CN9S98D+h1SZGqq3C80xl19VXZsbxbIc/qEJoNRKBQ0fzrKuXPb FCnfeSKSAycARC0CC0oypQMZegTxf+BbVhCkhCVUFho6TyWG4ZC5JzFQsnrTi/CcA9BU EUqQ== X-Gm-Message-State: AJcUukfEhYu9KA2I1ej6XRzIgFcgqGJzFZN2Wr6uA7R4YrnGHveXzCSo 6BjljnfGcnscDWBnFuhEAjNUi7Ld+EE= X-Google-Smtp-Source: ALg8bN7uWchueT5l+unKGDbHuiYKl3YVVK4bGa24quadYJNwL9RoDIHKZPP1/y6xP/wsHw4jGyb+dw== X-Received: by 2002:aca:4fc5:: with SMTP id d188mr7086403oib.138.1548714694392; Mon, 28 Jan 2019 14:31:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:14 -0800 Message-Id: <20190128223118.5255-9-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::242 Subject: [Qemu-devel] [PATCH v2 08/12] 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" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- 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 dbac09743c..89cc54dbed 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) { @@ -1982,6 +1995,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; /* 0: BR, 1: BLR, 2: other */ TCGv_i64 dst; TCGv_i64 modifier; =20 @@ -1999,6 +2013,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 */ @@ -2042,7 +2057,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) { @@ -2058,6 +2072,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); @@ -2141,6 +2156,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 Wed Oct 1 00:55:48 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 1548715476622827.1031042264194; Mon, 28 Jan 2019 14:44:36 -0800 (PST) Received: from localhost ([127.0.0.1]:39597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFdr-0007uU-7Y for importer@patchew.org; Mon, 28 Jan 2019 17:44:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFbq-0006iZ-Dx for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRP-0006HX-09 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:44 -0500 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]:35289) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRN-0006EV-HY for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:42 -0500 Received: by mail-oi1-x241.google.com with SMTP id v6so14531168oif.2 for ; 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.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:34 -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=Srgal5L+T4f9BJA308PnBpjmkpNAduRiPZ7ATLTRwkQ=; b=RCl/BXogUyRAExfZa+W/Gw9RrHscv7PKc3rJQ7rXYxB4Yzzvoenr7ayW4Dj1Wg0f6n J3IJ8xDBWQMj7Nm8ilIe6ZbI98aYFcqLHQ28FSEWs4OsTWZ0FEHoT9kaAbna9pR7WR5K MS4conjzW3IJ2kvIutc9M74mIdZ0RQo7R3y0E= 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=Srgal5L+T4f9BJA308PnBpjmkpNAduRiPZ7ATLTRwkQ=; b=HAiRQSMKifUX+PSP4ZNi8QJ8MwxYwIVgcayKttc1QryHObG0jbaIuvTRX8RSY14ZgC sbkoa9eCBReXAi1Y4PxTvbkJVqP73cxX2UrZdwwTkPsToRYLFsJqXhPDCw4X77DE4GdL rPAwS1YyjOwkCiSTad+TWS5mYpd1Nijl0k7zHRCDuuhqH2euQFRRVn1BVLvtj8IrdWJa SCsbIKtvgx5WX0jW6HXhtoPvbVKZ9Q58VdFue7T7Ddyt7MbW6lciec7nrU6Gr4+/0n0K Yqw+QmVSrQ4tkTvJ6sAvtLjaevq46nyNk7QQ1WXQIwTmZGNfz/MuxACDcZzz1KR0o64K yzjg== X-Gm-Message-State: AJcUukdPmr3x3+71OcPGM15P6/gHNt4wkW3TV1KHGc0s8RYNZ1hTd+hT f3coeQDsUzn0b/kgBPbk3/VHBFb8NQE= X-Google-Smtp-Source: AHgI3IYhdNYgjD7+qjprO+Fm9DchV0A623lQCWHYQpELrRyVhfkj9b2+Vc5yxCmNnJ7uuftfjjL94A== X-Received: by 2002:a54:4f8f:: with SMTP id g15mr7662915oiy.166.1548714695462; Mon, 28 Jan 2019 14:31:35 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:15 -0800 Message-Id: <20190128223118.5255-10-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::241 Subject: [Qemu-devel] [PATCH v2 09/12] target/arm: Add x-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 --- v2: Renamed the property with x- prefix --- 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 e18f823419..8c9eb519ef 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -895,6 +895,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 e9bc461c36..a563f7e74d 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -311,6 +311,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); @@ -416,6 +428,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, "x-guarded-pages", + aarch64_cpu_get_guarded_pages, + aarch64_cpu_set_guarded_pages, NULL); + object_property_set_description(obj, "x-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 89cc54dbed..a1adb8cde0 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -13778,7 +13778,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 Wed Oct 1 00:55:48 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 154871587457191.80759923583776; Mon, 28 Jan 2019 14:51:14 -0800 (PST) Received: from localhost ([127.0.0.1]:39716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFkH-0004QY-HL for importer@patchew.org; Mon, 28 Jan 2019 17:51:13 -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-8s for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRP-0006Hc-0G for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:44 -0500 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]:33433) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRM-0006El-R4 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:42 -0500 Received: by mail-oi1-x232.google.com with SMTP id c206so14560594oib.0 for ; 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.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:35 -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=UKRLKQXKGzj/mpvH/wYH3nx2J6OhgQcb+mzh4u+p648=; b=MJqd9/nqGh1FTKSLgOvy5IWkD+S4mxf/3Mwwz0uhj5uQehZuAJ4hxNl7Un0GFG6DtY HpcGQ+xmhbBzxLn5yY6LLmhyeLPULiwuGBYHxWByAYwfjL1aFTPWnOkMqhUox7Vjs9FD YkSpRST2q9GsZbeOBSAOrtuIEVJAmH5Ji7aTk= 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=UKRLKQXKGzj/mpvH/wYH3nx2J6OhgQcb+mzh4u+p648=; b=HiaR2eTJgDC9Aos+EjxslUcBlnTCJc5TA8pKGdpN9USObLZMGoGMYHc1/eBOe/5sqD tv7mhmKjckL82RZakgRfiOmWMECfCrnXiZX2iH61ua8nOY8foArKsHoelG0YSxWPpGcU 7LWenoIG9fOAvN0t4w55pT8OKC1Kuf2eKGhG1bNi5y0fmjvFJ50vP7eKrVwJczr7dbpX 4HKYil15c0F/HZO36EsmiCIqz03OFnhcyWfrtOAMlg91CDzQWpytmwX4FP4lXAYWp36m Qow93cZKRhOpXDCyzuPNIwRaQTVbEIvVhi0pHsvINwpWg2h4U7vQbZOYCVlGaEez192H KK9w== X-Gm-Message-State: AJcUukdfysur4JSpmOfW1aQ8E5weo/MUKDOahjAajGDrriT2a32ftljd 8yltYmas2b4/fcxmrxeonsCjU4t8egE= X-Google-Smtp-Source: ALg8bN5w5FPDnu4f5WNwYe9Sfhd3q+h9nzDzLVrRKOjlpcLIki4/BZcgoEU6PjP35S5m3QsLgUIUmw== X-Received: by 2002:aca:c142:: with SMTP id r63mr7565867oif.98.1548714696544; Mon, 28 Jan 2019 14:31:36 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:16 -0800 Message-Id: <20190128223118.5255-11-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::232 Subject: [Qemu-devel] [PATCH v2 10/12] 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" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu64.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index a563f7e74d..9d2276fe53 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -368,6 +368,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 Wed Oct 1 00:55:48 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 From nobody Wed Oct 1 00:55:48 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 1548715514062473.9615032373259; Mon, 28 Jan 2019 14:45:14 -0800 (PST) Received: from localhost ([127.0.0.1]:39605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFeT-0008Np-2B for importer@patchew.org; Mon, 28 Jan 2019 17:45:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcA-0006iZ-1y for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRU-0006LD-IW for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:50 -0500 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:42910) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRS-0006Fn-Ty for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:47 -0500 Received: by mail-ot1-x342.google.com with SMTP id v23so16154552otk.9 for ; Mon, 28 Jan 2019 14:31:39 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); 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=y0k/H38xJNqLR/HphofIOtky77ujQ33o+YBmpOTNSTs=; b=D9WGvklmHUrmvl12m6DcI7j1Cwv/PNa/94u/02x2EPz4wNzIl2IJYqV2iZEf8oHDn4 hRuwltnEdQL6CT4+0ShoCpU0Q/O+YIkbZw4BW+OwOvMQdLTvkkiFzUZZhqUzKImFUlJa Fk4PxoFN/cEzZGAWStyMCgrbLSR0H1yTxDaok= 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=y0k/H38xJNqLR/HphofIOtky77ujQ33o+YBmpOTNSTs=; b=rqqHr8RgjqEke/y4gXvJKjsAcaDiWB9LXE90bOOu/Kfrd8Wv1scRA3nH3/FF9yam+k MA9fb1hT0zwy7wf2dWcoo0ERI4kNizfQUyqhrsHQMHwW0jY/hEfu4Ld9o4K4B5aAlqek 1rwLwgCEmN9oTgJH/ckRhDvJL0gSLfYoC9eEDGiDvv/T4tdMFnQU8kVJHefBmlEeaOXb uuP9F00SOq7IBe17WozxRuDVfp5pyz++ShjTRGjC936c6/LHW1qRQZL25dJpNL7lEw5e PEucxJn6uBap+EmA1HT2iRkaCQJU5SUDzYhuqOENiMLpTt/X41gjUbs4kjsQuj7kKDyG mMJg== X-Gm-Message-State: AJcUukfeqHwfXrbFUry38R2n7h6qLbbX2s2REYO+yyd/t0hgNyytu0Pc Sounf8Cparc46LUFNUQp+qR/ju3gEqk= X-Google-Smtp-Source: ALg8bN4Lpy3siIayM5jA3vACXL3sBoYNbC3CgS07OPkBh34FqAagZlquBm52rNeQBsja+4VM9Lk3Sw== X-Received: by 2002:a9d:a2e:: with SMTP id 43mr16449151otg.8.1548714698845; Mon, 28 Jan 2019 14:31:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:18 -0800 Message-Id: <20190128223118.5255-13-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::342 Subject: [Qemu-devel] [PATCH v2 12/12] 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..b529a8c9c9 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,x-guarded-pages=3Don + +TESTS:=3D$(AARCH64_TESTS) --=20 2.17.2