Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp248549rwa; Sat, 20 Aug 2022 03:03:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR5bZnxsmfKq/zA/9wi+Lt9Mp9rsYlN0gdtntFV3gfrNX5uZWxDrPax314hkxPa05KSSgpG2 X-Received: by 2002:a05:6402:524c:b0:43e:aba4:a42d with SMTP id t12-20020a056402524c00b0043eaba4a42dmr9111155edd.328.1660989788455; Sat, 20 Aug 2022 03:03:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660989788; cv=none; d=google.com; s=arc-20160816; b=FMjMMTPSeZXNQS2nKmrJvJ5guGuWAw+vqcmdXKFm6a7pow47cHiQHqxo+MUAVqLBaa mUKW0BToMYVGTrPeCiv8Ckd6aIzJqVU4uFWtKs+ePPw/L1Hcg1zs6ii3X92SFZ8kjQwf Z5K6w3ASr+sHP8S4krnuFXWQV4oolcyj8bVaTvoC0F8tgJGSigy4M45czDfiNoHTUpDp yX5wLEfHZOh+gu6+Ijzk53d3qchwVjCVdbbrTy2dJIgtmgZxBgOLb0lm5Nd1/XoiuZ3x Gm/44Q2TAujCWVgJuP0EBcskDOlGuj7vakiUDKVG2E/rRIlhslD3O8eDO/w15U1d6PCy wlsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=u7fbzdyS7lNmFlfFkpL9ui3k5/AhRZuOO8ZbzrPXUW4=; b=wMvYiN2t1vcSASUUfuZxZ0tdq2TTOVMOL4A0/DYY1HhU/+xuCfmGRAlxyIt2WkL7FU pZL1K1NQ7z1DM116+qW1g6tG4l5ecrv6hVz7n9xFTf/gIpGTOdFQ3MXUOR1kLcd3lOMp mTdB2/Sem97MWiPtp9VvxJtW0V99NvKGrKI3vQTb0xcj8n4uTd0Qjbx2kCfZ09Je+bnr /b7jukVA3RJabIkDWxoKSzlg/ZDIvydGK4/5qdw1Gtq5zeoMjuetynogesgLo6G4iPsa yyzBOpNxWkV965p07OGsa21+Yy9GTk9l8v+Qo/vwiRuPyP2mrlzbFz4dBqt+BMSYZbNs 2mNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq24-20020a1709073f1800b0073d23ad8850si3215568ejc.515.2022.08.20.03.02.40; Sat, 20 Aug 2022 03:03:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343689AbiHTJlC (ORCPT + 99 others); Sat, 20 Aug 2022 05:41:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbiHTJlB (ORCPT ); Sat, 20 Aug 2022 05:41:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C61C31C133 for ; Sat, 20 Aug 2022 02:41:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6DE3FB8013A for ; Sat, 20 Aug 2022 09:40:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6B3AC433C1; Sat, 20 Aug 2022 09:40:55 +0000 (UTC) Date: Sat, 20 Aug 2022 10:40:51 +0100 From: Catalin Marinas To: Peter Collingbourne Cc: Evgenii Stepanov , Marc Zyngier , Will Deacon , Vincenzo Frascino , Andrey Konovalov , Mark Brown , Linux ARM , LKML Subject: Re: [PATCH] arm64: mte: move register initialization to C Message-ID: References: <20220819013526.2682765-1-pcc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220819013526.2682765-1-pcc@google.com> X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 18, 2022 at 06:35:26PM -0700, Peter Collingbourne wrote: > If FEAT_MTE2 is disabled via the arm64.nomte command line argument on a > CPU that claims to support FEAT_MTE2, the kernel will use Tagged Normal > in the MAIR. If we interpret arm64.nomte to mean that the CPU does not > in fact implement FEAT_MTE2, setting the system register like this may > lead to UNSPECIFIED behavior. I'm not convinced by this wording. There is no UNDEFINED behaviour since proc.S checks the raw ID regs. Just passing arm64.nomte currently still allows fully defined behaviour (well, unless you try to map tag storage into the linear map but changing MAIR doesn't solve that anyway). [...] > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index 907401e4fffb..3554ff869f4b 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -2030,8 +2030,47 @@ static void bti_enable(const struct arm64_cpu_capabilities *__unused) > #ifdef CONFIG_ARM64_MTE > static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap) > { > + u64 rgsr; > + > sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ATA | SCTLR_EL1_ATA0); > + > + /* > + * CnP must be enabled only after the MAIR_EL1 register has been set > + * up. Inconsistent MAIR_EL1 between CPUs sharing the same TLB may > + * lead to the wrong memory type being used for a brief window during > + * CPU power-up. > + * > + * CnP is not a boot feature so MTE gets enabled before CnP, but let's > + * make sure that is the case. > + */ > + BUG_ON(read_sysreg(ttbr0_el1) & TTBR_CNP_BIT); > + BUG_ON(read_sysreg(ttbr1_el1) & TTBR_CNP_BIT); Ah, good point. SCOPE_BOOT_CPU features are initialised before the others even for late secondary CPUs, so that should work without having to reorder the features table. > + > + /* Normal Tagged memory type at the corresponding MAIR index */ > + sysreg_clear_set( > + mair_el1, MAIR_ATTRIDX(MAIR_ATTR_MASK, MT_NORMAL_TAGGED), > + MAIR_ATTRIDX(MAIR_ATTR_NORMAL_TAGGED, MT_NORMAL_TAGGED)); Nitpick: keep 'mair_el1' on the same line with sysreg_clear_set, I think it looks slightly better if MAIR_ATTRIDX are both aligned. [...] > - /* set the TCR_EL1 bits */ > - mov_q x10, TCR_MTE_FLAGS > - orr tcr, tcr, x10 I'd keep the TCR setting under #ifdef MTE or rather the TCR_MTE_FLAGS and make them 0 if !MTE. It gives us a chance to still test a kernel configuration where TBI1 == 0. BTW, we end up setting the TCMA1 bit even when MTE is not supported. It shouldn't be a problem usually with RES0 bits which we know what they do. -- Catalin