From patchwork Tue Jun 23 19:36:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 191504 Delivered-To: patch@linaro.org Received: by 2002:a92:1f07:0:0:0:0:0 with SMTP id i7csp2277081ile; Tue, 23 Jun 2020 12:44:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzipPsZA/iLEewboBJaA2MzkGwk6g6gGW5HiX3kWIoGYQCxkAoPBtQLAiM+SSJryW76I3c5 X-Received: by 2002:a5b:f4d:: with SMTP id y13mr38330410ybr.286.1592941487686; Tue, 23 Jun 2020 12:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592941487; cv=none; d=google.com; s=arc-20160816; b=RODBN/Bc+TbwktCpAHdI5PfYhKf/anL/H5/wYNn24brgMdECeKkAPJhZwpPzJqbjOq Bxz11sIWubRKY1EHy/cxnqri5ZnHeFdkuMNf00OtGUjTcFFJ8I3/gHpiMGTbA6NTThno X2VfoIQOqsd+foTDmqE3FZQx7CunmZ4K5PMby05vE2aP9jKkLfVcQEkUW5YkCZH8bDMm km2fz5CWN+kf9x70sWPsAOzi7DV29Ew/LuGLUgRmDGEDGF5dSK2xphsgWtw9IRLhbjnC XB59cxV92Z2cKQwlllxUzM6SnuqIH2BR9uB9ocPK6oMEn3P2W+E6W0h/UFdsp4i3qGXI S+PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=/f1Kq86xOn0I6KfO6hqhA/hMinh4ZLMOHCrw3GZ9sHA=; b=gRMzASnwnkf4B6E5cn/TRjLbntAS1Kk0A5g4BW4SrmZFRJ9G/+Og6y8IB4n+KM4BRD 50jjCe3zR1AYTKcjj0b1CJB3RWsb9cxnU3D0W3hLwoOJkyioHF9H6ODvpcffu6gAwSt8 fMMWnYI39ulDoST/GX1axDfVSDpU/JfqE3Fhb1idG1DS4idFkhKzegvjzPvuJAkeRu8W TdDmg38N7Ril6WbuF8mXaCBdu+Id+p5VhLIgTtm0u2tDAh8WytZJ1uYgn00+yCDPpHDX UABiM3Ih8VL+5+PHHVclb2srW1K5k8nForggozEVOAjy5a+oyw01kPXuE8JPFIQlAF4B 3QNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZjbbO7MM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y9si17129287ybo.2.2020.06.23.12.44.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jun 2020 12:44:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZjbbO7MM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnoqd-0008RG-48 for patch@linaro.org; Tue, 23 Jun 2020 15:44:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnojM-0003VL-IG for qemu-devel@nongnu.org; Tue, 23 Jun 2020 15:37:16 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:36541) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnojK-0005aE-Kx for qemu-devel@nongnu.org; Tue, 23 Jun 2020 15:37:16 -0400 Received: by mail-pg1-x543.google.com with SMTP id p3so24961pgh.3 for ; Tue, 23 Jun 2020 12:37:14 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=/f1Kq86xOn0I6KfO6hqhA/hMinh4ZLMOHCrw3GZ9sHA=; b=ZjbbO7MMJ66uzVE8HkvWz5IPBXwb2AMXTkbXknBmLGGTxSoHcgmqwvHxgV/FplrdY3 cB2O8akMIpzCy2Q7vthrud1CbKq0Zd7e1GM2P4G0Ks9rhpZPlsq0dao6Gfm9CziTl7UH LeJOmPANtRS/2TiKK4tHEDZiXGDrix35XfaMswngV0pi4Oyqhhj9y0OOll1qUVcJ7Y7W yzhWclj0QiRcKjLwOflNyFSRugewt3l+w+mRHjuWbOHY+8qYV4FK3RZmheY0X6rP+Ae+ FUJUqryxcUIDGC6szRTz8dp6LZ1s+YbrcxI8lyBQAUYUUCYxtliaoNZRIf3YwiBIf7mU o1vQ== 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:mime-version:content-transfer-encoding; bh=/f1Kq86xOn0I6KfO6hqhA/hMinh4ZLMOHCrw3GZ9sHA=; b=BOS2czjzsM3iqP0uWgoMJNnxcCNj5kHwhQAFYQ0ziNet9uO8nzU8Vou2375AhCHC1e Pwz/5RMPmQlHDh0oYWlbzfUwDrMI/ZoMV7LvcEif6ruyRuYmV3HhwZg8dVvchYZ67KBP A+Tg8EBiloy9mj1FsQBCokSZJqQOb6Dt5siDWu77sD2eogUkelyE3QvP9SKTdpnQHBnK d2szI+uAgyYCGyiclLcZeBh+oT5K5kRwalMf6Oy4JdrPxUEGPuclo4koAY2L8jORG+rb OErovwcBIwWgrXm0uC1Bjsi18a/pvkzYaEfPkRQn6mhWW9S3iamKTP04w5TelZSpozW2 odtg== X-Gm-Message-State: AOAM530bBKmRezkFaZHQQFb35byqJYjlQGSepgp2QrBG/lx3CW4Nirru TSuGkbG/TZBxxUFwEXge0uQAnxou2Y4= X-Received: by 2002:a63:195a:: with SMTP id 26mr16746019pgz.402.1592941032894; Tue, 23 Jun 2020 12:37:12 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id p12sm17927642pfq.69.2020.06.23.12.37.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2020 12:37:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v8 09/45] target/arm: Implement the IRG instruction Date: Tue, 23 Jun 2020 12:36:22 -0700 Message-Id: <20200623193658.623279-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200623193658.623279-1-richard.henderson@linaro.org> References: <20200623193658.623279-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, david.spickett@linaro.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v2: Update to 00eac5. Merge choose_random_nonexcluded_tag into helper_irg since that pseudo function no longer exists separately. v6: Remove obsolete logical/physical tag distinction; implement inline for !ATA. --- target/arm/helper-a64.h | 2 ++ target/arm/internals.h | 5 +++ target/arm/mte_helper.c | 72 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-a64.c | 18 ++++++++++ target/arm/Makefile.objs | 1 + 5 files changed, 98 insertions(+) create mode 100644 target/arm/mte_helper.c -- 2.25.1 diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h index 3df7c185aa..587ccbe42f 100644 --- a/target/arm/helper-a64.h +++ b/target/arm/helper-a64.h @@ -103,3 +103,5 @@ DEF_HELPER_FLAGS_3(autda, TCG_CALL_NO_WG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(autdb, TCG_CALL_NO_WG, i64, env, i64, i64) DEF_HELPER_FLAGS_2(xpaci, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_2(xpacd, TCG_CALL_NO_RWG_SE, i64, env, i64) + +DEF_HELPER_FLAGS_3(irg, TCG_CALL_NO_RWG, i64, env, i64, i64) diff --git a/target/arm/internals.h b/target/arm/internals.h index 53e249687b..ae611a6ff5 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1261,4 +1261,9 @@ void arm_log_exception(int idx); */ #define GMID_EL1_BS 6 +static inline uint64_t address_with_allocation_tag(uint64_t ptr, int rtag) +{ + return deposit64(ptr, 56, 4, rtag); +} + #endif diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c new file mode 100644 index 0000000000..539a04de84 --- /dev/null +++ b/target/arm/mte_helper.c @@ -0,0 +1,72 @@ +/* + * ARM v8.5-MemTag Operations + * + * Copyright (c) 2020 Linaro, Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "internals.h" +#include "exec/exec-all.h" +#include "exec/cpu_ldst.h" +#include "exec/helper-proto.h" + + +static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude) +{ + if (exclude == 0xffff) { + return 0; + } + if (offset == 0) { + while (exclude & (1 << tag)) { + tag = (tag + 1) & 15; + } + } else { + do { + do { + tag = (tag + 1) & 15; + } while (exclude & (1 << tag)); + } while (--offset > 0); + } + return tag; +} + +uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm) +{ + int rtag; + + /* + * Our IMPDEF choice for GCR_EL1.RRND==1 is to behave as if + * GCR_EL1.RRND==0, always producing deterministic results. + */ + uint16_t exclude = extract32(rm | env->cp15.gcr_el1, 0, 16); + int start = extract32(env->cp15.rgsr_el1, 0, 4); + int seed = extract32(env->cp15.rgsr_el1, 8, 16); + int offset, i; + + /* RandomTag */ + for (i = offset = 0; i < 4; ++i) { + /* NextRandomTagBit */ + int top = (extract32(seed, 5, 1) ^ extract32(seed, 3, 1) ^ + extract32(seed, 2, 1) ^ extract32(seed, 0, 1)); + seed = (top << 15) | (seed >> 1); + offset |= top << i; + } + rtag = choose_nonexcluded_tag(start, offset, exclude); + env->cp15.rgsr_el1 = rtag | (seed << 8); + + return address_with_allocation_tag(rn, rtag); +} diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 717cb96a40..14d51c0dd1 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -226,6 +226,12 @@ static TCGv_i64 clean_data_tbi(DisasContext *s, TCGv_i64 addr) return clean; } +/* Insert a zero tag into src, with the result at dst. */ +static void gen_address_with_allocation_tag0(TCGv_i64 dst, TCGv_i64 src) +{ + tcg_gen_andi_i64(dst, src, ~MAKE_64BIT_MASK(56, 4)); +} + typedef struct DisasCompare64 { TCGCond cond; TCGv_i64 value; @@ -5284,6 +5290,18 @@ static void disas_data_proc_2src(DisasContext *s, uint32_t insn) case 3: /* SDIV */ handle_div(s, true, sf, rm, rn, rd); break; + case 4: /* IRG */ + if (sf == 0 || !dc_isar_feature(aa64_mte_insn_reg, s)) { + goto do_unallocated; + } + if (s->ata) { + gen_helper_irg(cpu_reg_sp(s, rd), cpu_env, + cpu_reg_sp(s, rn), cpu_reg(s, rm)); + } else { + gen_address_with_allocation_tag0(cpu_reg_sp(s, rd), + cpu_reg_sp(s, rn)); + } + break; case 8: /* LSLV */ handle_shift_reg(s, A64_SHIFT_TYPE_LSL, sf, rm, rn, rd); break; diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs index 83febd232c..fa39fd7c83 100644 --- a/target/arm/Makefile.objs +++ b/target/arm/Makefile.objs @@ -86,3 +86,4 @@ obj-$(CONFIG_SOFTMMU) += psci.o obj-$(TARGET_AARCH64) += translate-a64.o helper-a64.o obj-$(TARGET_AARCH64) += translate-sve.o sve_helper.o obj-$(TARGET_AARCH64) += pauth_helper.o +obj-$(TARGET_AARCH64) += mte_helper.o