From nobody Thu Nov 28 05:52:28 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4631121BB0F; Fri, 4 Oct 2024 14:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053022; cv=none; b=axS2W8sAfxeiD484FWmJDbwDdHZG0vc005kEkLDg8x0XuhwYJFq5cVHR4IJShecrVlAXUAUWusPBHTeVaW+lRrXDALsJcle1YyQ73+MF8nhrCIU8aJHgX4kkvB3OnmUlIj2CzkCDGmCFwuQm1v+zg9OtNrRrbUWmEhIgeflSVHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053022; c=relaxed/simple; bh=m3/FSGzHIG3x/uAMlAm0inEDdKo/0vzrDx5FTjqT2G8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HqE/QZPqqmzZCy8fYhTY3s4C1EPIitMDscMUWwXgeP7YUqgYqhWAOfKzhwBMOiAevAF4tT2B7bLcM+BNzxY2l+VROOe8v4iUzP99IG84dKbLk2LLBnZ4ebmXCNExJf3v0pIziZfzwF7ioct5Otbn8XU/Z4kei/zo+Zg7rl8TXRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 32875339; Fri, 4 Oct 2024 07:44:10 -0700 (PDT) Received: from e122027.cambridge.arm.com (unknown [10.1.25.25]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 10F7C3F58B; Fri, 4 Oct 2024 07:43:35 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Steven Price , Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" Subject: [PATCH v6 03/11] arm64: realm: Query IPA size from the RMM Date: Fri, 4 Oct 2024 15:42:58 +0100 Message-Id: <20241004144307.66199-4-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241004144307.66199-1-steven.price@arm.com> References: <20241004144307.66199-1-steven.price@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The top bit of the configured IPA size is used as an attribute to control whether the address is protected or shared. Query the configuration from the RMM to assertain which bit this is. Reviewed-by: Catalin Marinas Reviewed-by: Gavin Shan Co-developed-by: Suzuki K Poulose Signed-off-by: Suzuki K Poulose Signed-off-by: Steven Price --- Changes since v4: * Make PROT_NS_SHARED check is_realm_world() to reduce impact on non-CCA systems. Changes since v2: * Drop unneeded extra brackets from PROT_NS_SHARED. * Drop the explicit alignment from 'config' as struct realm_config now specifies the alignment. --- arch/arm64/include/asm/pgtable-prot.h | 4 ++++ arch/arm64/include/asm/rsi.h | 2 +- arch/arm64/kernel/rsi.c | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm= /pgtable-prot.h index 2a11d0c10760..820a3b06f08c 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -68,8 +68,12 @@ =20 #include #include +#include =20 extern bool arm64_use_ng_mappings; +extern unsigned long prot_ns_shared; + +#define PROT_NS_SHARED (is_realm_world() ? prot_ns_shared : 0) =20 #define PTE_MAYBE_NG (arm64_use_ng_mappings ? PTE_NG : 0) #define PMD_MAYBE_NG (arm64_use_ng_mappings ? PMD_SECT_NG : 0) diff --git a/arch/arm64/include/asm/rsi.h b/arch/arm64/include/asm/rsi.h index e4c01796c618..acba065eb00e 100644 --- a/arch/arm64/include/asm/rsi.h +++ b/arch/arm64/include/asm/rsi.h @@ -27,7 +27,7 @@ static inline int rsi_set_memory_range(phys_addr_t start,= phys_addr_t end, =20 while (start !=3D end) { ret =3D rsi_set_addr_range_state(start, end, state, flags, &top); - if (WARN_ON(ret || top < start || top > end)) + if (ret || top < start || top > end) return -EINVAL; start =3D top; } diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c index 9bf757b4b00c..a6495a64d9bb 100644 --- a/arch/arm64/kernel/rsi.c +++ b/arch/arm64/kernel/rsi.c @@ -8,6 +8,11 @@ #include #include =20 +struct realm_config config; + +unsigned long prot_ns_shared; +EXPORT_SYMBOL(prot_ns_shared); + DEFINE_STATIC_KEY_FALSE_RO(rsi_present); EXPORT_SYMBOL(rsi_present); =20 @@ -67,6 +72,9 @@ void __init arm64_rsi_init(void) return; if (!rsi_version_matches()) return; + if (WARN_ON(rsi_get_realm_config(&config))) + return; + prot_ns_shared =3D BIT(config.ipa_bits - 1); =20 arm64_rsi_setup_memory(); =20 --=20 2.34.1