From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75EBBC433EA for ; Wed, 15 Jul 2020 17:09:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D0AC20663 for ; Wed, 15 Jul 2020 17:09:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D0AC20663 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 91EE68D000E; Wed, 15 Jul 2020 13:09:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A89E8D0002; Wed, 15 Jul 2020 13:09:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74AB88D000E; Wed, 15 Jul 2020 13:09:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id 548BD8D0002 for ; Wed, 15 Jul 2020 13:09:19 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 16B2D1EF1 for ; Wed, 15 Jul 2020 17:09:19 +0000 (UTC) X-FDA: 77040946038.14.rock67_2e0789726efb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id D2AF21822987A for ; Wed, 15 Jul 2020 17:09:18 +0000 (UTC) X-HE-Tag: rock67_2e0789726efb X-Filterd-Recvd-Size: 4530 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jul 2020 17:09:18 +0000 (UTC) Received: from localhost.localdomain (unknown [95.146.230.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6711206F4; Wed, 15 Jul 2020 17:09:15 +0000 (UTC) From: Catalin Marinas To: linux-arm-kernel@lists.infradead.org Cc: linux-mm@kvack.org, linux-arch@vger.kernel.org, Will Deacon , Dave P Martin , Vincenzo Frascino , Szabolcs Nagy , Kevin Brodsky , Andrey Konovalov , Peter Collingbourne , Andrew Morton Subject: [PATCH v7 12/29] arm64: mte: Handle the MAIR_EL1 changes for late CPU bring-up Date: Wed, 15 Jul 2020 18:08:27 +0100 Message-Id: <20200715170844.30064-13-catalin.marinas@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200715170844.30064-1-catalin.marinas@arm.com> References: <20200715170844.30064-1-catalin.marinas@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D2AF21822987A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: CnP must be enabled only after the MAIR_EL1 register has been set up by the cpu_enable_mte() function. 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. Move the ARM64_HAS_CNP capability to a higher number and add a corresponding BUILD_BUG_ON() to check for any inadvertent future change in the relative positions of MTE and CnP. The cpufeature.c code ensures that the cpu_enable() function is called in the ascending order of the capability number. In addition, move the TLB invalidation to cpu_enable_mte() since late CPUs brought up won't be covered by the flush_tlb_all() in system_enable_mte(). Signed-off-by: Catalin Marinas Cc: Will Deacon --- Notes: New in v7. arch/arm64/include/asm/cpucaps.h | 4 ++-- arch/arm64/kernel/cpufeature.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cp= ucaps.h index 6bc3e21e5929..bc39fdbf0706 100644 --- a/arch/arm64/include/asm/cpucaps.h +++ b/arch/arm64/include/asm/cpucaps.h @@ -22,7 +22,7 @@ #define ARM64_WORKAROUND_CAVIUM_27456 12 #define ARM64_HAS_32BIT_EL0 13 #define ARM64_HARDEN_EL2_VECTORS 14 -#define ARM64_HAS_CNP 15 +#define ARM64_MTE 15 #define ARM64_HAS_NO_FPSIMD 16 #define ARM64_WORKAROUND_REPEAT_TLBI 17 #define ARM64_WORKAROUND_QCOM_FALKOR_E1003 18 @@ -62,7 +62,7 @@ #define ARM64_HAS_GENERIC_AUTH 52 #define ARM64_HAS_32BIT_EL1 53 #define ARM64_BTI 54 -#define ARM64_MTE 55 +#define ARM64_HAS_CNP 55 =20 #define ARM64_NCAPS 56 =20 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeatur= e.c index c1df72bfede4..4d3abb51f7d4 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1670,6 +1670,14 @@ static void cpu_enable_mte(struct arm64_cpu_capabi= lities const *cap) write_sysreg_s(0, SYS_TFSR_EL1); write_sysreg_s(0, SYS_TFSRE0_EL1); =20 + /* + * 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. + */ + BUILD_BUG_ON(ARM64_HAS_CNP < ARM64_MTE); + /* * Update the MT_NORMAL_TAGGED index in MAIR_EL1. Tag checking is * disabled for the kernel, so there won't be any observable effect @@ -1679,8 +1687,9 @@ static void cpu_enable_mte(struct arm64_cpu_capabil= ities const *cap) mair &=3D ~MAIR_ATTRIDX(MAIR_ATTR_MASK, MT_NORMAL_TAGGED); mair |=3D MAIR_ATTRIDX(MAIR_ATTR_NORMAL_TAGGED, MT_NORMAL_TAGGED); write_sysreg_s(mair, SYS_MAIR_EL1); - isb(); + + local_flush_tlb_all(); } =20 static int __init system_enable_mte(void) @@ -1688,9 +1697,6 @@ static int __init system_enable_mte(void) if (!system_supports_mte()) return 0; =20 - /* Ensure the TLB does not have stale MAIR attributes */ - flush_tlb_all(); - /* * Clear the tags in the zero page. This needs to be done via the * linear map which has the Tagged attribute.