From patchwork Thu Nov 17 13:24:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13046886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C621C433FE for ; Thu, 17 Nov 2022 13:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wNu6+klsiVpioW4EX73Zjmop2/RJR193Xg60dyygl2Y=; b=4/s6a7bfcy754/ ImeEuzLJHniorqDrDa7qoWj6/W2KE3/qP3rQArK70lN0bU9vP5VDIuh+VRtE0WTzA0wwgJ4AjaRXN qgjrgIrXFaKAiaLlcz5diNwQ5XjZlxHgYlL6gpD47Ecs6VjsO/cL/GOx/dU6olbMGZp6qJw8ftHfa HjvELOZq3oJf+tCHOeQ4790+Fvw0ECbgsdFfXvm6k203vavIQhRd8lYsJEKDBuo14lsSjDT6JXVLw trtigAMvVSh/7n7j5PBQFag8YuMKRdWP6DRycHbGBDPaawihec3d8viqO10ZOTirVvAOXr+R3AtpI amrwiWPeytQZteEBvO9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oveu9-00EFam-Sk; Thu, 17 Nov 2022 13:26:10 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovesi-00EEON-29 for linux-arm-kernel@lists.infradead.org; Thu, 17 Nov 2022 13:24:41 +0000 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 9E3EBB8204A; Thu, 17 Nov 2022 13:24:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EA21C43146; Thu, 17 Nov 2022 13:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668691477; bh=f3jU8SOL8V1K9vf5WNLO3RnL2atHxpm/RSRZiHJjccU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a80QJ2kFC+t9GWJodiJIAZomNTHcc0GLBfpxdNXKEdNQVck1WvX+G2TLdZ8m0Pwcc 8n3/0aafypIqouWABpFAQ3AE1o8SLkrtUfbaevUalE1bL65hRZK9l8SlCwV3WxZ3f0 RQBlTAl/n3qHzqSJ43mp8TGQHe4v1IpFD35FoDK27XuLl+kZalxpF03VeAlB1M6hS7 mvz7QsWlz+AzIcu0k26Tx3ei6ca9nLeS0KFgki5Rxht+WXBQjpHi4EhkvbpvPhzhpD BpTlbhIszgDLnf71hZ/6bv5ezvrVpt1oFonDpz2UGPSSFaXwXjU6XD/6xgHs5+cBDf gUkHWWfxPIGJg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown , Anshuman Khandual , Richard Henderson Subject: [RFC PATCH 3/7] arm64: mm: Wire up TCR.DS bit to PTE shareability fields Date: Thu, 17 Nov 2022 14:24:19 +0100 Message-Id: <20221117132423.1252942-4-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117132423.1252942-1-ardb@kernel.org> References: <20221117132423.1252942-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3012; i=ardb@kernel.org; h=from:subject; bh=f3jU8SOL8V1K9vf5WNLO3RnL2atHxpm/RSRZiHJjccU=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjdjYA/KvhDAnmqSRgQZ7ryOYanDvvk/q4jXMrJt0o Gy3KO9SJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3Y2AAAKCRDDTyI5ktmPJHQoC/ 4rcDbkRMFrVRDV4eOuM6fK+1WMto41s/kSPIau/YLFsI69nr2s6Eif3QtzwKHEkKVn1ht7Yn3OiUEc bsOYb8K4Ap316zkjM9hWbDh+1TQiF7brZMpRlv03sm0PFgUm4Fho0eV7KbozXDKiH0tm69Daf0pAi/ xIlOTcHLV26ELOG0/9VmJIl4NmDlfacqrm3p0Sq2NZwhCHsY3jMopUcxxMW+LUvgAC1UoEYXAWbFhJ KGsgEMpTHRcyTH6WW20SpEgTEN9182OfgOt4B506PLh0LmA/EdQ6LVwouO5UHWFIf+cP3x2Ded4qWm 3BLvpF/vvqcSasfdOyf9hzjelID8O1UnbvDU3ZdgydCfWcacizb37g83TgUUNFNOjomMD2nT9LfCIv UbtXtQL437VKREqJWzkj8nxC/2KTSli7szZuygheHmM4BkoyNEmFMx05TlkJQB+Id0n+iu5eYsyzSD bXw/kLFnIyKJMz78pa9qGSyEs2GOQca8TbbsI/7KmMO78= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221117_052440_438273_9794208A X-CRM114-Status: GOOD ( 16.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When LPA2 is enabled, bits 8 and 9 of page and block descriptors become part of the output address instead of carrying shareability attributes for the region in question. So avoid setting these bits if TCR.DS == 1, which means LPA2 is enabled. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/include/asm/pgtable-prot.h | 18 ++++++++++++++++-- arch/arm64/mm/mmap.c | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index f658aafc47dfa29a..c4ad7fbb12c5c07a 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -276,6 +276,7 @@ #define TCR_E0PD1 (UL(1) << 56) #define TCR_TCMA0 (UL(1) << 57) #define TCR_TCMA1 (UL(1) << 58) +#define TCR_DS (UL(1) << 59) /* * TTBR. diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index 9b165117a454595a..15888fa87072f609 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -40,6 +40,20 @@ extern bool arm64_use_ng_mappings; #define PTE_MAYBE_NG (arm64_use_ng_mappings ? PTE_NG : 0) #define PMD_MAYBE_NG (arm64_use_ng_mappings ? PMD_SECT_NG : 0) +#if !defined(CONFIG_ARM64_PA_BITS_52) || defined(CONFIG_ARM64_64K_PAGES) +#define lpa2_is_enabled() false +#define PTE_MAYBE_SHARED PTE_SHARED +#define PMD_MAYBE_SHARED PMD_SECT_S +#else +static inline bool lpa2_is_enabled(void) +{ + return read_sysreg(tcr_el1) & TCR_DS; +} + +#define PTE_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PTE_SHARED) +#define PMD_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PMD_SECT_S) +#endif + /* * If we have userspace only BTI we don't want to mark kernel pages * guarded even if the system does support BTI. @@ -50,8 +64,8 @@ extern bool arm64_use_ng_mappings; #define PTE_MAYBE_GP 0 #endif -#define PROT_DEFAULT (_PROT_DEFAULT | PTE_MAYBE_NG) -#define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_MAYBE_NG) +#define PROT_DEFAULT (PTE_TYPE_PAGE | PTE_MAYBE_NG | PTE_MAYBE_SHARED | PTE_AF) +#define PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_MAYBE_NG | PMD_MAYBE_SHARED | PMD_SECT_AF) #define PROT_DEVICE_nGnRnE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE)) #define PROT_DEVICE_nGnRE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE)) diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 8f5b7ce857ed4a8f..adcf547f74eb8e60 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -73,6 +73,10 @@ static int __init adjust_protection_map(void) protection_map[VM_EXEC | VM_SHARED] = PAGE_EXECONLY; } + if (lpa2_is_enabled()) + for (int i = 0; i < ARRAY_SIZE(protection_map); i++) + pgprot_val(protection_map[i]) &= ~PTE_SHARED; + return 0; } arch_initcall(adjust_protection_map);