From patchwork Fri Apr 2 21:42:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 414407 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1727721jai; Fri, 2 Apr 2021 14:45:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7KrdqZ3waNExEtyht3z74r3u4tvHStvsjRQNVRnG/xbDfZYcNqpM2PjmwzHp3ZqmrAgLp X-Received: by 2002:a25:4e84:: with SMTP id c126mr21963117ybb.291.1617399906466; Fri, 02 Apr 2021 14:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617399906; cv=none; d=google.com; s=arc-20160816; b=jGpPq+4t6h7y4dfCRZ7gpjYX+nf7J4A9eL2NSAPbbVegLmXGoePkcORqTMslWsnvLu pyQ3CiKj/Lf433LBNnfOa4ttwva3rkTla9dgTu/b7Yw0bZPytW2v/mXeaIUAkev7BIOu 3069YNRrmlXiOdq2wIPGvgFNHl5lzQ4yDhUUOJTDG0UPUdqNEHN4SwlqORXzyQ87cqHd LgBgVQLVsMdIg1F14y6wnzpWwQMByIvpyrN0IIybSYe60ANRcwG6jiLDf5w5hyVaSjX4 9ZrwCAXcd7cBCNuT0CyNBmjyA818Z3PUHbY/gPjWR9TUtfa/HDdbVclbz7WPUjfu6y18 0TBg== 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=cOmrmLleIvfS9SAvRM+rFaIFvSakRJgmx9iPS/gIMnk=; b=HDuGDjaaOG2It3RwtdWzgIpILJNVfXs6GsCHuFHBloULtQ/U3vnHRU5ahdKFWHy0ZH FbhS7xbvSZVVhMDxBUTOZaFoyeTG9+se8jEBzQs+VbroBRqb7C3CrvZ2mJJqICLeAPN1 j1mDAQNNkXYHlP+44kogI3yI37w2g3eMe+eXtfFts5od8DgXuYrBqaowPlz5dJ39zox1 lb03LZcwUty41YEc8SWwiilRp0B+QEaK8rn1bA9yKSkJ0UxMmYpW7C2KwfLvz0R1Vd5w 7M5/fkMlvx8gv7ufgSEg2H8CyIVNdQu8pkrSXVWl44AS76yDN8BfWDlDKw2fzY83svOt FTVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GXWN0eHl; 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=pass (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 c12si6120233ybn.193.2021.04.02.14.45.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 02 Apr 2021 14:45:06 -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=pass header.i=@linaro.org header.s=google header.b=GXWN0eHl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSRbF-0003pw-RF for patch@linaro.org; Fri, 02 Apr 2021 17:45:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSRYj-0000Kj-MH for qemu-devel@nongnu.org; Fri, 02 Apr 2021 17:42:29 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:35373) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lSRYh-0007hw-Q3 for qemu-devel@nongnu.org; Fri, 02 Apr 2021 17:42:29 -0400 Received: by mail-pj1-x1030.google.com with SMTP id il9-20020a17090b1649b0290114bcb0d6c2so5142246pjb.0 for ; Fri, 02 Apr 2021 14:42:27 -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=cOmrmLleIvfS9SAvRM+rFaIFvSakRJgmx9iPS/gIMnk=; b=GXWN0eHleJIOYPqqVw7XDwTogr0Wie/tRM2bVSFJvXYXKaK8EVi+Kj53UZVuB95CpT rnwEnCWWZGzt/R1XBOa1kGBn26Jnid1adpFlcbwp9dUDx9FfyZe9p1zNgIVq5g7ZzPaw A3AGJ9s+uFUwcdJQNRR5pdLhMTHX3+duC2KwelAbtPl4aao52GNVFWDrZn6AfZRxQUe0 43x0GK05Lt7f4EzxNQFhIjshN9ueEITLWCa67krdf3N/rWeXm1P3rf/daAZn+lkAPGes Mgz6ah4hPvTVT+hoKZwp2jl6KrpiLadfgqM3FqACuNayIy3xnePZonMjQ0spl/kAoNNa NNag== 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=cOmrmLleIvfS9SAvRM+rFaIFvSakRJgmx9iPS/gIMnk=; b=dm1fv3g8XEqieRf4TXzzIsW3Qcmk0ipuogOp103gWpT1K91Hw62QQ1nbwibi2FNYa5 /LMggETeD+ra9nwmvsaXAjw5Gak84gA9cj/2vRNWp+FjoYAcovQKJqJM4Ifnkr6GXLgB GbdwRlrwUAMjSRt1PzeK/4iO2FuEMeRqPrG8mBB5cfib3Z0rcPcRR7tedvz+f7lnkG+/ IZF+hHl/OxYBmei/DKNyPda+Bf3K5A3/xg30K7el4EklWKD0lTNb8UhUqta18xiqH09/ i8UKTE22JxyaY7BtuNLztWOg59AIHvOVbdkO1LV7BoXTQXLkpISMUrANgH96CoQruK+r +PVQ== X-Gm-Message-State: AOAM533XZ40SMTTAmkY6QDkGFW26z8fRijuwl/xCOJPrdR3Npqp9+kdV 6kvvkimDw+33dfgUbQ7wjC521B85RM5FoQ== X-Received: by 2002:a17:902:ce8d:b029:e4:bc38:c4 with SMTP id f13-20020a170902ce8db02900e4bc3800c4mr14144501plg.48.1617399746604; Fri, 02 Apr 2021 14:42:26 -0700 (PDT) Received: from localhost.localdomain (h216-228-167-147.bendor.dedicated.static.tds.net. [216.228.167.147]) by smtp.gmail.com with ESMTPSA id f16sm7923329pfj.220.2021.04.02.14.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Apr 2021 14:42:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 05/11] target/arm: Fix unaligned checks for mte_check1, mte_probe1 Date: Fri, 2 Apr 2021 14:42:11 -0700 Message-Id: <20210402214217.422585-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210402214217.422585-1-richard.henderson@linaro.org> References: <20210402214217.422585-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.google.com 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=ham autolearn_force=no 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: qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We were incorrectly assuming that only the first byte of an MTE access is checked against the tags. But per the ARM, unaligned accesses are pre-decomposed into single-byte accesses. So by the time we reach the actual MTE check in the ARM pseudocode, all accesses are aligned. We cannot tell a priori whether or not a given scalar access is aligned, therefore we must at least check. Use mte_probe_int, which is already set up for checking multiple granules. Buglink: https://bugs.launchpad.net/bugs/1921948 Signed-off-by: Richard Henderson --- target/arm/mte_helper.c | 109 +++++++++++++--------------------------- 1 file changed, 35 insertions(+), 74 deletions(-) -- 2.25.1 diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index 179846b463..6fcfaf5c9e 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -617,80 +617,6 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc, } } -/* - * Perform an MTE checked access for a single logical or atomic access. - */ -static bool mte_probe1_int(CPUARMState *env, uint32_t desc, uint64_t ptr, - uintptr_t ra, int bit55) -{ - int mem_tag, mmu_idx, ptr_tag, size; - MMUAccessType type; - uint8_t *mem; - - ptr_tag = allocation_tag_from_addr(ptr); - - if (tcma_check(desc, bit55, ptr_tag)) { - return true; - } - - mmu_idx = FIELD_EX32(desc, MTEDESC, MIDX); - type = FIELD_EX32(desc, MTEDESC, WRITE) ? MMU_DATA_STORE : MMU_DATA_LOAD; - size = FIELD_EX32(desc, MTEDESC, ESIZE); - - mem = allocation_tag_mem(env, mmu_idx, ptr, type, size, - MMU_DATA_LOAD, 1, ra); - if (!mem) { - return true; - } - - mem_tag = load_tag1(ptr, mem); - return ptr_tag == mem_tag; -} - -/* - * No-fault version of mte_check1, to be used by SVE for MemSingleNF. - * Returns false if the access is Checked and the check failed. This - * is only intended to probe the tag -- the validity of the page must - * be checked beforehand. - */ -bool mte_probe1(CPUARMState *env, uint32_t desc, uint64_t ptr) -{ - int bit55 = extract64(ptr, 55, 1); - - /* If TBI is disabled, the access is unchecked. */ - if (unlikely(!tbi_check(desc, bit55))) { - return true; - } - - return mte_probe1_int(env, desc, ptr, 0, bit55); -} - -uint64_t mte_check1(CPUARMState *env, uint32_t desc, - uint64_t ptr, uintptr_t ra) -{ - int bit55 = extract64(ptr, 55, 1); - - /* If TBI is disabled, the access is unchecked, and ptr is not dirty. */ - if (unlikely(!tbi_check(desc, bit55))) { - return ptr; - } - - if (unlikely(!mte_probe1_int(env, desc, ptr, ra, bit55))) { - mte_check_fail(env, desc, ptr, ra); - } - - return useronly_clean_ptr(ptr); -} - -uint64_t HELPER(mte_check1)(CPUARMState *env, uint32_t desc, uint64_t ptr) -{ - return mte_check1(env, desc, ptr, GETPC()); -} - -/* - * Perform an MTE checked access for multiple logical accesses. - */ - /** * checkN: * @tag: tag memory to test @@ -882,6 +808,41 @@ uint64_t HELPER(mte_checkN)(CPUARMState *env, uint32_t desc, uint64_t ptr) return mte_checkN(env, desc, ptr, GETPC()); } +uint64_t mte_check1(CPUARMState *env, uint32_t desc, + uint64_t ptr, uintptr_t ra) +{ + uint64_t fault; + uint32_t total = FIELD_EX32(desc, MTEDESC, ESIZE); + int ret = mte_probe_int(env, desc, ptr, ra, total, &fault); + + if (unlikely(ret == 0)) { + mte_check_fail(env, desc, fault, ra); + } else if (ret < 0) { + return ptr; + } + return useronly_clean_ptr(ptr); +} + +uint64_t HELPER(mte_check1)(CPUARMState *env, uint32_t desc, uint64_t ptr) +{ + return mte_check1(env, desc, ptr, GETPC()); +} + +/* + * No-fault version of mte_check1, to be used by SVE for MemSingleNF. + * Returns false if the access is Checked and the check failed. This + * is only intended to probe the tag -- the validity of the page must + * be checked beforehand. + */ +bool mte_probe1(CPUARMState *env, uint32_t desc, uint64_t ptr) +{ + uint64_t fault; + uint32_t total = FIELD_EX32(desc, MTEDESC, ESIZE); + int ret = mte_probe_int(env, desc, ptr, 0, total, &fault); + + return ret != 0; +} + /* * Perform an MTE checked access for DC_ZVA. */