From patchwork Fri Oct 11 13:47:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 175952 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp961979ocf; Fri, 11 Oct 2019 06:52:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJdm9xGFYpYFgtIDZZNxV9C89AQBrAWB/i1dYQmGrQ7Ld26KKk7JCfWokAoBEL1TN7CK1n X-Received: by 2002:a17:906:6d08:: with SMTP id m8mr13879234ejr.150.1570801953221; Fri, 11 Oct 2019 06:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570801953; cv=none; d=google.com; s=arc-20160816; b=IharQFizu3HsyuopiqDFTJvEvL7IS0JB2OqgMJDusKlyyKfh9bvL/U+2hy9qIi+AbO BHBTaSaS+QxDjNxQ9JEBlUesecBjBaeJR3vx/eWoKVtRWqBeoCV5xhBDazUrshMzwcXu qLqVvgz21cw88XbdqYmGl8g2Wz1BhL8JN5vXk61HiwyKbA75jdcYj2fP2VyaIjHXg2Jg v8SJm2YZWFdnuJX82iTwTnhdylB3nKZyyogrGHzhF5qbGVVtR6B88MCXZyKFQZs6mro4 oE82rP+1v1/Z/3VU+Gd/dkgMF2/4IQrGDNR7Rn4QeXK45xAypkW5JD8yieBvKXLD0KIe tGYg== 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:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=DBn82VDoTIkQHKrcIDGuEVCWKjWKbpPGI9lxXV47UXY=; b=RGQoZlk4/l0N2Fc2rD7rDSOxxZrYlkuXPksz5VBuWTz2ktExKla/w3fPLEQam5N0WK O8c0sEi4xCATNmPhtweqlcz+XOKiuPvOFqtQt1fbchMeFEJi0e5OSmnUdQV6ew09c9f+ mvjYb60SIo00Thjf2T3+NgFc4WLi/tBuBueMLzuhJZcCLlS8L7BszL+voek/rpWKDjY3 aC2RuFbO5vqTiuQ5XElNoTV8DMWPgZ3eL3ZJR7TQRwPhHtbsmwwKIBCybgKObRFWRs5l mVmxE5qTfJ2mVPziGZhX+/XnKm+o1R/Pj69J3XKR3Ku1LlMq619fISsCg2Nchfw5efMf OXMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ufd5x4g0; 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 v39si6125353edc.234.2019.10.11.06.52.33 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Oct 2019 06:52:33 -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=ufd5x4g0; 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]:50576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIvLL-00077h-NN for patch@linaro.org; Fri, 11 Oct 2019 09:52:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38804) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIvIT-0004Zn-3h for qemu-devel@nongnu.org; Fri, 11 Oct 2019 09:49:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIvIR-0003aX-RC for qemu-devel@nongnu.org; Fri, 11 Oct 2019 09:49:32 -0400 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]:40339) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iIvIR-0003aI-NY for qemu-devel@nongnu.org; Fri, 11 Oct 2019 09:49:31 -0400 Received: by mail-yb1-xb42.google.com with SMTP id s7so3115739ybq.7 for ; Fri, 11 Oct 2019 06:49:31 -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; bh=DBn82VDoTIkQHKrcIDGuEVCWKjWKbpPGI9lxXV47UXY=; b=ufd5x4g0OMzc1f3gjfMgUaDLvB0xHGQQCNgDp3kUD2jk2SX0CGKxt/5v3IoIZqX9Ys 0TELz48Ia74rWxI3baTtHWmnvDuZ+tFGPi5hNVYSWm266T01VZmxQLGawL20d5HBIYmZ Jqxaxag80kZBCQnSl5fAgcApqr3cegWNUEnJUCTJ104M1bJQoF2b0YUVeMTbcgABEfD0 Ufy7F4NWzpIVcDjLYRNYZrYo37Gxq4J7LnGbKUp8Ke1tmJZKarB0xwvUo+0CL2mdtEnI xYkKWk7n4TwsHIDVQffror+eaujZuxeULCMQPRYMHUgpsrFMADafRdkdAnv8417PmOPa 7vzw== 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=DBn82VDoTIkQHKrcIDGuEVCWKjWKbpPGI9lxXV47UXY=; b=sZKHYRGcq4ytAvOJ6V02dwikbuDb7I8MCLmnD8s9Zq9FSqxfxRLDSuglRza0UA2S4b ZaIM1DFLVSIw28KVBuQB+kfBZ/aBa/1NxdRINDBQ8ytaCa8xpZEoAnkiSAndJm1/CsmU jMYOmu64ftnS0oGgIr3BXU9ucSXVzAqwqEUvvLTj+6QwWj8F1T+qsV+/a2YFSQRoAXaO ikte+gGPU2n2ZIYkvsmcM8zp0jm65lW4I4sUvZtCf3q5Cdy3Q+Y0A37ARWSlIxmaYUzN cWwZX0UTEDEghptqqiZejar7/90oPZPGB4To9cHwqSItnT8I6lrLnJ+hqmB9+M48W/Tx YY6w== X-Gm-Message-State: APjAAAVyCvUYWNp/a2kfneB2Y0hyNdy2A3C9CiTAsS/Gmkly8Q/HN6kX mHbu4aXHYFYbrWJM1IdscSCNLM+zujI= X-Received: by 2002:a25:cbce:: with SMTP id b197mr10024381ybg.355.1570801770705; Fri, 11 Oct 2019 06:49:30 -0700 (PDT) Received: from cloudburst.gateway.pace.com (67.216.151.25.pool.hargray.net. [67.216.151.25]) by smtp.gmail.com with ESMTPSA id f68sm2534000ywb.96.2019.10.11.06.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 06:49:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 06/22] target/arm: Implement the IRG instruction Date: Fri, 11 Oct 2019 09:47:28 -0400 Message-Id: <20191011134744.2477-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191011134744.2477-1-richard.henderson@linaro.org> References: <20191011134744.2477-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::b42 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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. --- target/arm/helper-a64.h | 1 + target/arm/mte_helper.c | 57 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-a64.c | 7 +++++ 3 files changed, 65 insertions(+) -- 2.17.1 diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h index a82e21f15a..6ff7f5b756 100644 --- a/target/arm/helper-a64.h +++ b/target/arm/helper-a64.h @@ -106,3 +106,4 @@ DEF_HELPER_FLAGS_2(xpacd, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_2(mte_check1, TCG_CALL_NO_WG, i64, env, i64) DEF_HELPER_FLAGS_2(mte_check2, TCG_CALL_NO_WG, i64, env, i64) DEF_HELPER_FLAGS_3(mte_check3, TCG_CALL_NO_WG, i64, env, i64, i32) +DEF_HELPER_FLAGS_3(irg, TCG_CALL_NO_RWG, i64, env, i64, i64) diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index bbb90cbe86..9848849a91 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -37,6 +37,31 @@ static int allocation_tag_from_addr(uint64_t ptr) return extract64(ptr, 56, 4); } +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; +} + +static uint64_t address_with_allocation_tag(uint64_t ptr, int rtag) +{ + rtag -= extract64(ptr, 55, 1); + return deposit64(ptr, 56, 4, rtag); +} + /* * Perform a checked access for MTE. * On arrival, TBI is known to enabled, as is allocation_tag_access_enabled. @@ -165,3 +190,35 @@ uint64_t HELPER(mte_check3)(CPUARMState *env, uint64_t dirty_ptr, uint32_t tbi) return dirty_ptr; } } + +uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm) +{ + int el = arm_current_el(env); + uint64_t sctlr = arm_sctlr(env, el); + int rtag = 0; + + if (allocation_tag_access_enabled(env, el, sctlr)) { + /* + * 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 18d45fba87..83d253d67f 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -5156,6 +5156,13 @@ 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; + } + gen_helper_irg(cpu_reg_sp(s, rd), cpu_env, + cpu_reg_sp(s, rn), cpu_reg(s, rm)); + break; case 8: /* LSLV */ handle_shift_reg(s, A64_SHIFT_TYPE_LSL, sf, rm, rn, rd); break;