From nobody Tue Feb 10 08:03:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1617399824; cv=none; d=zohomail.com; s=zohoarc; b=boSrnOgJxqzCgPCnSNwXpkPUI3Fu+5MWOC2IPfaZIZzi8ZpGa5JavQ2A4VQblehljcNMWeiXOZlvlCSj7HbPk4O2VnmHNk1FPArOo/Ppe/dRS6R9Ub3wprJiaLyce51j8Duz+QlPkZ3FZ6S6LmcAgTyD1Xvs41PI+XaV0XovJJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617399824; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OVt5iR1dmccHY0b49ovqyPgeianDpRHBCkX5yRWRcH8=; b=DRa4jn5sEtlundlID/NPGEZAevET4nYtzM2vCAIkkanal+E2ARiSl3tCAkLsnz+vI7l/B6jdsgsWTwiExkRksgvceq/BwqWRaJFaNfuRYgU2OEBV74c7unhbLakKANE5TFzHObsyUE3HFjERoupZZMHd1FnwqeDBwX/OM7f++xo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617399824221687.6365030866701; Fri, 2 Apr 2021 14:43:44 -0700 (PDT) Received: from localhost ([::1]:38306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSRZv-00024s-4P for importer@patchew.org; Fri, 02 Apr 2021 17:43:43 -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) 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) 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-Google-Smtp-Source: ABdhPJy4xUoBjc2z25BJXGO/A7nlYKFymk7Tk4Ob+F8sXlJ3sTjU3DyXrhMCsA0GNffB+1l50AiKoA== X-Received: by 2002:a17:90a:990a:: with SMTP id b10mr15548299pjp.178.1617399745303; Fri, 02 Apr 2021 14:42:25 -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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" 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(-) 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; } =20 -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; =20 bit55 =3D extract64(ptr, 55, 1); + *fault =3D ptr; =20 /* If TBI is disabled, the access is unchecked, and ptr is not dirty. = */ if (unlikely(!tbi_check(desc, bit55))) { - return ptr; + return -1; } =20 ptr_tag =3D allocation_tag_from_addr(ptr); =20 if (tcma_check(desc, bit55, ptr_tag)) { - goto done; + return 1; } =20 mmu_idx =3D FIELD_EX32(desc, MTEDESC, MIDX); type =3D FIELD_EX32(desc, MTEDESC, WRITE) ? MMU_DATA_STORE : MMU_DATA_= LOAD; - total =3D FIELD_EX32(desc, MTEDESC, TSIZE); =20 /* Find the addr of the end of the access, and of the last element. */ ptr_last =3D ptr + total - 1; @@ -803,7 +815,7 @@ uint64_t mte_checkN(CPUARMState *env, uint32_t desc, mem1 =3D 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 =3D checkN(mem1, ptr & TAG_GRANULE, ptr_tag, tag_count); @@ -829,23 +841,39 @@ uint64_t mte_checkN(CPUARMState *env, uint32_t desc, } if (n =3D=3D c) { if (!mem2) { - goto done; + return 1; } n +=3D checkN(mem2, 0, ptr_tag, tag_count - c); } } =20 + if (likely(n =3D=3D 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 =3D (n =3D=3D 0 ? ptr : tag_first + n * TAG_GRANULE= ); - mte_check_fail(env, desc, fault, ra); + if (n > 0) { + *fault =3D tag_first + n * TAG_GRANULE; } + return 0; +} =20 - done: +uint64_t mte_checkN(CPUARMState *env, uint32_t desc, + uint64_t ptr, uintptr_t ra) +{ + uint64_t fault; + uint32_t total =3D FIELD_EX32(desc, MTEDESC, TSIZE); + int ret =3D mte_probe_int(env, desc, ptr, ra, total, &fault); + + if (unlikely(ret =3D=3D 0)) { + mte_check_fail(env, desc, fault, ra); + } else if (ret < 0) { + return ptr; + } return useronly_clean_ptr(ptr); } =20 --=20 2.25.1