From patchwork Fri Apr 2 21:42:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 414403 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1727006jai; Fri, 2 Apr 2021 14:43:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT7NN4tpn3nrp4L2e574naIDkb0Uxs9SkOPFkaFQiEX1k/fSko+2i4qOqC2WbZBwpZJk+n X-Received: by 2002:a05:6638:1a6:: with SMTP id b6mr14371768jaq.116.1617399803300; Fri, 02 Apr 2021 14:43:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617399803; cv=none; d=google.com; s=arc-20160816; b=DkaM/Gr6qSDN0O9wf+uZEEe8mjGsqW6BMTQJth02LLzzMvycjBCXDMDtXEz64ajjUR Vi4bHo8f/DBFS4CoVpJbCoIvglSO4SSRsGC4c1qoyfznCVKVyR0Rv/fcIRqRhpn0vR9J kxqyc9Cld4KwV1lvPKzwjscCsGf+APJDG4IXFjlvpJK5O4paX/quWBQvAdx8vG1jHEV1 bxvYv2tnPzprX2ave2l+GdTgzSranQseZjVOpfKuYc4QM2QpuKTPYeIx1n6IGpwr5d6z EsayJ4UIvFez65o0WXfmGu/9dBhHDnwWxfHdE8t9W9bd9cnyHUDbK6Tlhz1ZpguYbPai MZoQ== 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=OVt5iR1dmccHY0b49ovqyPgeianDpRHBCkX5yRWRcH8=; b=d4CM2b+vuu5q4IT5vtl5IzlUV3DcQoVY8AWainncu4kiyoUN0sx5XIYI1dJPAxzT4T bOtxnfZTjlLaZpNYtOEnmZCRc055DP10mfflrW4rFV3XLhGgDnZwz72bZDWBdJJ9hB5U b7N1VFftCQdarvmZnal+bNEmZ428DHTt5ydxp/NDrbk9+8NBo1/m7kE2WfHuyhYbGdMo hO/G2evZdRKm1HSb7YMC9nvDGM7VRWJIcBBIfvCphHl2beEzUCchTqx/qkr0yaTI2VB5 C5UnI9KifqB/y7XhScc4Eas1U3I3sLnBhsJ19oKgD/231k1Nmu6sKXji6/Ii4xXm29Ma T1ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vwN9kpi0; 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 y14si9014275ilu.81.2021.04.02.14.43.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 02 Apr 2021 14:43:23 -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=vwN9kpi0; 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]:34200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSRZa-0000PO-MP for patch@linaro.org; Fri, 02 Apr 2021 17:43:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSRYi-0000I1-Rl for qemu-devel@nongnu.org; Fri, 02 Apr 2021 17:42:28 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:33381) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lSRYg-0007h7-M4 for qemu-devel@nongnu.org; Fri, 02 Apr 2021 17:42:28 -0400 Received: by mail-pl1-x62e.google.com with SMTP id f17so3051394plr.0 for ; Fri, 02 Apr 2021 14:42:26 -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=OVt5iR1dmccHY0b49ovqyPgeianDpRHBCkX5yRWRcH8=; b=vwN9kpi0tXz2ObvJkmlLlmFzhTVZA7Gf7gL+20qLlfZUh1SSBH8hB/iQWbCAivgbH1 0m9tF9D0fcO3UqXeZXj08+GH9LJqEFEfcTAhY+ldMMCHqkfWOnNlMdPIo3hK8rx19jyJ dGTfwul7XufzyOwkHspRFMjxbK11Q3pSZI8nIapDdpwuvhgn2AhXZXSlOPFAHoHs7kpQ nmLX33E/D6ndpoHTV7VjXCU3C58DBJf6G6gVe89VX14Hs6OHyJwfEfyD3zElmGDR/NYv FDANZG3pU4CIwUmO7REKa1gLK+TFkiLGDeR+KT8DEo3fMhMZRTIbYgIQZvsXyHCYu+gh JgVw== 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=OVt5iR1dmccHY0b49ovqyPgeianDpRHBCkX5yRWRcH8=; b=dmQfOjtm+PKHHwrXKkbg0VoEAPpLQ4jaFAwiSOf4x9AM/DVyMDMV7K/wD6H1f2Ot4u eWANCyQWnpMVgqQjjLDvCzpcz9p41amF0+MGeFfYVt8LDnUsmfd4MlqTt2xdr/Ge096G QU89P9tcFBtkhfiWYzgTbo94PXLUikxE6f9JmQNcETUzeCsL0ESVnyXq1t5n+eHRaLPU nvKjcSxfHG3uiSQ87mpw5w5yAbraSS3+CQZgNCuTLrb8k3W4m6Gc4Th35gdtqe1XwehM D5FCIN4nBL546vMGzDkpTGnMvPxsHIiYJd2po6/fKIKo9ERcdI2wQN/RH/jPG09r56Ah bK2g== X-Gm-Message-State: AOAM533eae/xtuzP810lab2dRDRw1RPjXfF0sVOp/x0v3xwy+ed1FOoJ 7wKl+vhcj+OYg36dnd+opefaVeO6K/41ig== X-Received: by 2002:a17:90a:990a:: with SMTP id b10mr15548299pjp.178.1617399745303; Fri, 02 Apr 2021 14:42:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Apr 2021 14:42:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 04/11] target/arm: Split out mte_probe_int Date: Fri, 2 Apr 2021 14:42:10 -0700 Message-Id: <20210402214217.422585-5-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::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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=unavailable 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" Split out a helper function from mte_checkN to perform all of the checking and address manpulation. So far, just use this in mte_checkN itself. Signed-off-by: Richard Henderson --- target/arm/mte_helper.c | 52 +++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-) -- 2.25.1 diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index 473d84cee2..179846b463 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -753,33 +753,45 @@ static int checkN(uint8_t *mem, int odd, int cmp, int count) return n; } -uint64_t mte_checkN(CPUARMState *env, uint32_t desc, - uint64_t ptr, uintptr_t ra) +/* + * mte_probe_int: + * @env: CPU environment + * @desc: MTEDESC descriptor + * @ptr: virtual address of the base of the access + * @fault: return virtual address of the first check failure + * + * Internal routine for both mte_probe and mte_check. + * Return zero on failure, filling in *fault. + * Return negative on trivial success for tbi disabled. + * Return positive on success with tbi enabled. + */ +static int mte_probe_int(CPUARMState *env, uint32_t desc, uint64_t ptr, + uintptr_t ra, uint32_t total, uint64_t *fault) { int mmu_idx, ptr_tag, bit55; uint64_t ptr_last, prev_page, next_page; uint64_t tag_first, tag_end; uint64_t tag_byte_first, tag_byte_end; - uint32_t total, tag_count, tag_size, n, c; + uint32_t tag_count, tag_size, n, c; uint8_t *mem1, *mem2; MMUAccessType type; bit55 = extract64(ptr, 55, 1); + *fault = ptr; /* If TBI is disabled, the access is unchecked, and ptr is not dirty. */ if (unlikely(!tbi_check(desc, bit55))) { - return ptr; + return -1; } ptr_tag = allocation_tag_from_addr(ptr); if (tcma_check(desc, bit55, ptr_tag)) { - goto done; + return 1; } mmu_idx = FIELD_EX32(desc, MTEDESC, MIDX); type = FIELD_EX32(desc, MTEDESC, WRITE) ? MMU_DATA_STORE : MMU_DATA_LOAD; - total = FIELD_EX32(desc, MTEDESC, TSIZE); /* Find the addr of the end of the access, and of the last element. */ ptr_last = ptr + total - 1; @@ -803,7 +815,7 @@ uint64_t mte_checkN(CPUARMState *env, uint32_t desc, mem1 = allocation_tag_mem(env, mmu_idx, ptr, type, total, MMU_DATA_LOAD, tag_size, ra); if (!mem1) { - goto done; + return 1; } /* Perform all of the comparisons. */ n = checkN(mem1, ptr & TAG_GRANULE, ptr_tag, tag_count); @@ -829,23 +841,39 @@ uint64_t mte_checkN(CPUARMState *env, uint32_t desc, } if (n == c) { if (!mem2) { - goto done; + return 1; } n += checkN(mem2, 0, ptr_tag, tag_count - c); } } + if (likely(n == tag_count)) { + return 1; + } + /* * If we failed, we know which granule. For the first granule, the * failure address is @ptr, the first byte accessed. Otherwise the * failure address is the first byte of the nth granule. */ - if (unlikely(n < tag_count)) { - uint64_t fault = (n == 0 ? ptr : tag_first + n * TAG_GRANULE); - mte_check_fail(env, desc, fault, ra); + if (n > 0) { + *fault = tag_first + n * TAG_GRANULE; } + return 0; +} - done: +uint64_t mte_checkN(CPUARMState *env, uint32_t desc, + uint64_t ptr, uintptr_t ra) +{ + uint64_t fault; + uint32_t total = FIELD_EX32(desc, MTEDESC, TSIZE); + 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); }