From patchwork Thu Aug 31 10:44:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 718952 Delivered-To: patch@linaro.org Received: by 2002:adf:e5c2:0:b0:31d:da82:a3b4 with SMTP id a2csp394505wrn; Thu, 31 Aug 2023 03:45:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeehliB8USTZ06fxtZn3KasiHB0wvkD36N3sklYHc1ssXumZd2ataFVxp6p8mHpgC68eei X-Received: by 2002:a0c:de11:0:b0:63d:d83:8808 with SMTP id t17-20020a0cde11000000b0063d0d838808mr2073693qvk.63.1693478752449; Thu, 31 Aug 2023 03:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693478752; cv=none; d=google.com; s=arc-20160816; b=G++eAR1yjSDdhhNi9CNqV3DJ5MHiBuPJisAtbUnLCf8JGHWFZrwRxtQG17XnBgx6lv IaLTqp03iRbYI7+U1tWydqcD0eH3uJSnBgHpO9sKB6eGJRQlidCohaKL/O33jL1H9Z1m 4EWzcBJvL4SVYg/qA2ovjh4zuRV3CSAbJ9HhoVbnMGW7CMnrXjp9NX3/pPwYUUG7jDGh CMINDRnUCx12iDB+dHxtDZ66UoUKCDtIkmfc0xGEPyrWhaIGVyPtC0ghueJFJ+VJ+ckQ SSnwxKvwI/42O7fAKhtKg86XgotwJ5C0aVXF2RZdFm/5mr2Bg7sQzpwpE5hiyDyzO61k 3xgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=0tfdVnStaNkhnripPGAZual0o+sSnkMAkUnDX0QV/9I=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=fSDvIv3u/Lq3F8GqLTY1NMAbFTLieqeuSS3lxNpFczHw2x6oYp6rgfQDYFHMAlnAnM RSa9jPnYrj62AXmt5656UlJEEZYpBllRO/JDKi7zUtb1mC3eFe42RtSoQZqkzNsYjYdX 2PTIQHVcOkKgYWbVYmqNjs+v4PDG4KXCHsghhkQeqUN6/ERy5k313isYnSUSteiu9VCP Y2vgCQWAur3Ob9oyO7hKMSMBd0s0U+6b9pBu7rntQIMJ3WVj9XeDX6J6sjfKMQscMDQQ Dm/d4RSwaIpK89+LCDkb0KbnxQSMQ4zbr5U7VeewsJBCoaTmV+HQV0kVsrO0pIEQc9zy ZCdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PIVcoiQx; 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 y6-20020a05620a25c600b0076811f91fc2si805621qko.124.2023.08.31.03.45.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Aug 2023 03:45:52 -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=PIVcoiQx; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbfB2-0003NM-P3; Thu, 31 Aug 2023 06:45:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbfB0-0003I3-8r for qemu-devel@nongnu.org; Thu, 31 Aug 2023 06:45:27 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbfAx-00042O-Gf for qemu-devel@nongnu.org; Thu, 31 Aug 2023 06:45:25 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-307d58b3efbso467404f8f.0 for ; Thu, 31 Aug 2023 03:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693478722; x=1694083522; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=0tfdVnStaNkhnripPGAZual0o+sSnkMAkUnDX0QV/9I=; b=PIVcoiQxTGhllsoBJP9FcXQa+Kklav2aZqa8f/BAI3REWgi9iL8jfYR2cZXpaTL3FJ ypaVlememSRkq/hW+ZY+/vBg2ma715g9qL4PmAEfmkeAdfUUS+RPt/eT8mzb2DI7mbPu nX3MUk492DxqPAK9MVeVP1ThHqEgl1q+1hkqv/eQicM+BEmpcyVUiAYNFGcxLd1Wds7B joTh5U+YUKZAcllTM4T4jdCaJoPZCdu71k1gbk2JqtvgmAuvEIkI+PNBBFWzNc9v7Ujy zKmMuQU/il9bC0f7mYcMf30saU3qknb5ho/7/+QXCyQyLK2h5woZs4sUTSsXNCTLBDbv 8p3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693478722; x=1694083522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0tfdVnStaNkhnripPGAZual0o+sSnkMAkUnDX0QV/9I=; b=IQ1M9Vgq2O8rPsStlYUYgqiPYf3Kbmds/4gz0S2JsYXf3r6MR5CrdBT29rQmuMdUUp 8HCCNbzEwJK3x9M8bQuJNUpZrJ8tnVzzgYfIbtfHAnKdSn0u/UVnQROtkdvUyZTxeV4g 0JoUaZTcH9B9RZeOBS1v6ENjgharUFKPQ2TDX+A8S6Ey9lnU4Sl5QBpV/p5uMB24u0Ob 441TMHstjVXQ1MAh/omY2peT45j+49+EyJgetn6qZAyJK/Q1t/1h3l8O0zBHtW74dsTo U1rw03x74oU5Q7xO3CdhPfAevtcJ83BplHBex4jBE2r5A+w+RE4BLlv/4wyr8tWYME71 OFsw== X-Gm-Message-State: AOJu0Yxa/jasu8bmUTsTEogNm1s6u5bXL8KXq2aZI33yYbMUm6Dl1AD0 5i4Pfmpy2DKsvHxFQrr8Jqy720FwX3okc5VkMVY= X-Received: by 2002:a5d:568f:0:b0:31a:d3fd:221b with SMTP id f15-20020a5d568f000000b0031ad3fd221bmr3478186wrv.20.1693478721761; Thu, 31 Aug 2023 03:45:21 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l5-20020adfe585000000b0031c71693449sm1785524wrm.1.2023.08.31.03.45.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 03:45:21 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 03/24] target/arm: Support more GM blocksizes Date: Thu, 31 Aug 2023 11:44:58 +0100 Message-Id: <20230831104519.3520658-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831104519.3520658-1-peter.maydell@linaro.org> References: <20230831104519.3520658-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Support all of the easy GM block sizes. Use direct memory operations, since the pointers are aligned. While BS=2 (16 bytes, 1 tag) is a legal setting, that requires an atomic store of one nibble. This is not difficult, but there is also no point in supporting it until required. Note that cortex-a710 sets GM blocksize to match its cacheline size of 64 bytes. I expect many implementations will also match the cacheline, which makes 16 bytes very unlikely. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Message-id: 20230811214031.171020-4-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/cpu.c | 18 +++++++++--- target/arm/tcg/mte_helper.c | 56 +++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index d906d2b1caa..fe73fd8af75 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2056,16 +2056,26 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) ID_PFR1, VIRTUALIZATION, 0); } + if (cpu_isar_feature(aa64_mte, cpu)) { + /* + * The architectural range of GM blocksize is 2-6, however qemu + * doesn't support blocksize of 2 (see HELPER(ldgm)). + */ + if (tcg_enabled()) { + assert(cpu->gm_blocksize >= 3 && cpu->gm_blocksize <= 6); + } + #ifndef CONFIG_USER_ONLY - if (cpu->tag_memory == NULL && cpu_isar_feature(aa64_mte, cpu)) { /* * Disable the MTE feature bits if we do not have tag-memory * provided by the machine. */ - cpu->isar.id_aa64pfr1 = - FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 0); - } + if (cpu->tag_memory == NULL) { + cpu->isar.id_aa64pfr1 = + FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 0); + } #endif + } if (tcg_enabled()) { /* diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c index 3640c6e57f5..b23d11563ab 100644 --- a/target/arm/tcg/mte_helper.c +++ b/target/arm/tcg/mte_helper.c @@ -428,6 +428,8 @@ uint64_t HELPER(ldgm)(CPUARMState *env, uint64_t ptr) int gm_bs = env_archcpu(env)->gm_blocksize; int gm_bs_bytes = 4 << gm_bs; void *tag_mem; + uint64_t ret; + int shift; ptr = QEMU_ALIGN_DOWN(ptr, gm_bs_bytes); @@ -443,16 +445,41 @@ uint64_t HELPER(ldgm)(CPUARMState *env, uint64_t ptr) /* * The ordering of elements within the word corresponds to - * a little-endian operation. + * a little-endian operation. Computation of shift comes from + * + * index = address + * data = tag + * + * Because of the alignment of ptr above, BS=6 has shift=0. + * All memory operations are aligned. Defer support for BS=2, + * requiring insertion or extraction of a nibble, until we + * support a cpu that requires it. */ switch (gm_bs) { + case 3: + /* 32 bytes -> 2 tags -> 8 result bits */ + ret = *(uint8_t *)tag_mem; + break; + case 4: + /* 64 bytes -> 4 tags -> 16 result bits */ + ret = cpu_to_le16(*(uint16_t *)tag_mem); + break; + case 5: + /* 128 bytes -> 8 tags -> 32 result bits */ + ret = cpu_to_le32(*(uint32_t *)tag_mem); + break; case 6: /* 256 bytes -> 16 tags -> 64 result bits */ - return ldq_le_p(tag_mem); + return cpu_to_le64(*(uint64_t *)tag_mem); default: - /* cpu configured with unsupported gm blocksize. */ + /* + * CPU configured with unsupported/invalid gm blocksize. + * This is detected early in arm_cpu_realizefn. + */ g_assert_not_reached(); } + shift = extract64(ptr, LOG2_TAG_GRANULE, 4) * 4; + return ret << shift; } void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val) @@ -462,6 +489,7 @@ void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val) int gm_bs = env_archcpu(env)->gm_blocksize; int gm_bs_bytes = 4 << gm_bs; void *tag_mem; + int shift; ptr = QEMU_ALIGN_DOWN(ptr, gm_bs_bytes); @@ -478,13 +506,25 @@ void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val) return; } - /* - * The ordering of elements within the word corresponds to - * a little-endian operation. - */ + /* See LDGM for comments on BS and on shift. */ + shift = extract64(ptr, LOG2_TAG_GRANULE, 4) * 4; + val >>= shift; switch (gm_bs) { + case 3: + /* 32 bytes -> 2 tags -> 8 result bits */ + *(uint8_t *)tag_mem = val; + break; + case 4: + /* 64 bytes -> 4 tags -> 16 result bits */ + *(uint16_t *)tag_mem = cpu_to_le16(val); + break; + case 5: + /* 128 bytes -> 8 tags -> 32 result bits */ + *(uint32_t *)tag_mem = cpu_to_le32(val); + break; case 6: - stq_le_p(tag_mem, val); + /* 256 bytes -> 16 tags -> 64 result bits */ + *(uint64_t *)tag_mem = cpu_to_le64(val); break; default: /* cpu configured with unsupported gm blocksize. */