From patchwork Fri Nov 11 17:11:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040620 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 87D74C43217 for ; Fri, 11 Nov 2022 17:13:33 +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=cDn18vatDb2H1qrhqhWP7UbjaKJEhARle9P19URvnTw=; b=e5ej49r73pA1K4 69UGi6qH3yuhWiqmcfVQv4TxEGmAWH110oTSY8RzmccLGEqu3QZFUHiJC8ud3mgGY9n8GYLZbTwEb sv1p0btlrKOsyLO/2sfm2DB6F99jTIFOZ0Pc6WVHjNgsKz9hXpPgzReeCw1pr3m8MFne/3w7kqeBK 3ZkPSQ0oHHmzYQ/Ors/QvwqvEx8y04HD6KCgB8m6adnrK2Hr5xLv3GP94eKxNF9qJ+B58a8SdlXCq E1rx5mgzvFmEyM97oWRhk+jdIVW2kiuCmi7j1XCot6XwcwVwNUfTTHBUvd5lv33Z0ZuW5MQkaYago KlOd7/EbUG+riQd9w3CA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXZp-00H7Uf-P6; Fri, 11 Nov 2022 17:12:26 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXZm-00H7S1-0J for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:12:23 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 5DD2362066; Fri, 11 Nov 2022 17:12:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E69A3C43470; Fri, 11 Nov 2022 17:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186740; bh=J++SBGWUY6FVLhysDTR5H/9o1FHWzVTfhLMhqjMESfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FVHka5vxBw/Ui67mfLdp3Vl6o+ignFj807EZuvG3SBYeEFqUKwKe/imREtduaOi7B tT/c0yzsjJAtq0lbcZEuKp5SxzlwiRgzReeXB2yp7z2L7Fp1/+Nb5xrr29dQ+GfniH 5lfCPacql2bARaTE1v326YrZNvKJ1hxXtlEYmdcRySNAqXNTCoQlSK1KceQ6N+8DKX r0o6kGwLTm/XvvQfXnuY1ddXBABIIETp3ZkDyasi1HH/+1a4izEB5ijlFcHsiWb/H6 eOJ55YTV2m6rwMkL2sq7mK3+H9kw5b4w/nd2s3SP3tcTfnNW4NhqRvIMNHWzrlTfzl uWOMWvWRGsT9g== 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 Subject: [PATCH v7 01/33] arm64: mm: Avoid SWAPPER_BLOCK_xxx constants in FDT fixmap logic Date: Fri, 11 Nov 2022 18:11:29 +0100 Message-Id: <20221111171201.2088501-2-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221111171201.2088501-1-ardb@kernel.org> References: <20221111171201.2088501-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4747; i=ardb@kernel.org; h=from:subject; bh=J++SBGWUY6FVLhysDTR5H/9o1FHWzVTfhLMhqjMESfM=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjboIq+zZ9FL9wP02x8xraMZ1LSQZx9Eszwi1VJDk1 ot94QeuJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CKgAKCRDDTyI5ktmPJN7KDA CaeO1xRNCZqquTHymhy4cz+oWANlsYFEo4Ga3tJl2LZBifb8s17gP1lBSXicRqQ6k0wq3IQRb+5OAD 4Gc2H9fIvVi9C6+Ni7cVIHneZSqSJJKjBC+McIB2+T80ZCjXaAt2oBwa3rE/Cr5r1TkMzPX+QwqWod Q8ePZcKN74UYtNqMt22RRU9I44bii3Mu8U9csF+/uPwyJ9yEydqht9peKaMi/HrHnUgK4nVtiCGwyV EY1MBuNDzeEevFdSBUI+me+DZLsemPb5ZKDn8oGgV8Lxe4Qtx6H1B0OQcLVeEeYxo68NKa0EE/kVhi dgxzpn9iMAyRhOSMmbh4moFRrcFhhjQ4zblXYymj61pHcmI+UTlA4QQtDnLy/LGfJ7eUtHTvj0m2jo awe14nS0srGa6rvd5CXUlvzRFjdo9tWrlOL8ATGVDSLG9xZQjapcfZDom3JPv0srQcpFWR0F1EMi+k +Q2xDboPPOhmmxx3CA+ihUfjBTg2xYPWrEemOCwUHK2fc= 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-20221111_091222_164495_82B886AF X-CRM114-Status: GOOD ( 26.73 ) 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 The FDT is permitted to be up to 2 MiB in size, and is mapped in the fixmap region using the same granularity as we use for the initial ID map, and up until recently, as we use for the preliminary mapping of the kernel in swapper_pg_dir. However, even though the constants are the same, the motivation is different: on 4k pagesize configurations, the fixmap region only has 2 MiB's worth of level 3 PTE slots to begin with, and so mapping the FDT down to pages in the fixmap would be wasteful, and this is why we use block mappings in this case. This is also documented in the boot protocol, i.e., adjacent regions must not be used by the platform in a away that could result in the need for memory attributes that conflict with the cacheable attributes used for the FDT block mapping. For larger page sizes, using block mappings is unnecessary, and given the potential issues caused by rounding, undesirable, so we use page mappings in that case. So to convey that this granularity is unrelated to the swapper block size, and to allow us to rename or remove the associated constants in a subsequent patch, use our own constants to define the granularity. No functional change intended, although the FDT fixmap virtual address will no longer be 2 MiB aligned on non-4k pages configurations. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/fixmap.h | 5 ++-- arch/arm64/mm/mmu.c | 27 ++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h index 71ed5fdf718bd0fd..d09654af5b1277c6 100644 --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -40,11 +40,12 @@ enum fixed_addresses { * maximum supported size, and put it at the top of the fixmap region. * The additional space ensures that any FDT that does not exceed * MAX_FDT_SIZE can be mapped regardless of whether it crosses any - * 2 MB alignment boundaries. + * 2 MB alignment boundaries on 4k pages configurations. * * Keep this at the top so it remains 2 MB aligned. */ -#define FIX_FDT_SIZE (MAX_FDT_SIZE + SZ_2M) +#define FIX_FDT_BSIZE (MAX_FDT_SIZE >= PMD_SIZE ? PMD_SIZE : PAGE_SIZE) +#define FIX_FDT_SIZE (MAX_FDT_SIZE + FIX_FDT_BSIZE) FIX_FDT_END, FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1, diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 9a7c38965154081e..757c2fe54d2e99f0 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1373,22 +1373,23 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) * allocate additional translation table pages, so that it is safe * to call create_mapping_noalloc() this early. * - * On 64k pages, the FDT will be mapped using PTEs, so we need to - * be in the same PMD as the rest of the fixmap. - * On 4k pages, we'll use section mappings for the FDT so we only - * have to be in the same PUD. + * On 4k pages, the entire level 3 fixmap only covers 2 MiB, so we'll + * need to use section mappings for the FDT, and these must be covered + * by the same statically allocated PUD (bm_pud). Otherwise, the FDT + * will be mapped using PTEs, so the entire mappings needs to fit into + * a single PMD (bm_pmd). */ - BUILD_BUG_ON(dt_virt_base % SZ_2M); + BUILD_BUG_ON(dt_virt_base % FIX_FDT_BSIZE); - BUILD_BUG_ON(__fix_to_virt(FIX_FDT_END) >> SWAPPER_TABLE_SHIFT != - __fix_to_virt(FIX_BTMAP_BEGIN) >> SWAPPER_TABLE_SHIFT); + BUILD_BUG_ON((__fix_to_virt(FIX_FDT_END) ^ __fix_to_virt(FIX_BTMAP_BEGIN)) + & ~((FIX_FDT_BSIZE << (PAGE_SHIFT - 3)) - 1)); - offset = dt_phys % SWAPPER_BLOCK_SIZE; + offset = dt_phys % FIX_FDT_BSIZE; dt_virt = (void *)dt_virt_base + offset; /* map the first chunk so we can read the size from the header */ - create_mapping_noalloc(round_down(dt_phys, SWAPPER_BLOCK_SIZE), - dt_virt_base, SWAPPER_BLOCK_SIZE, prot); + create_mapping_noalloc(round_down(dt_phys, FIX_FDT_BSIZE), + dt_virt_base, FIX_FDT_BSIZE, prot); if (fdt_magic(dt_virt) != FDT_MAGIC) return NULL; @@ -1397,9 +1398,9 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) if (*size > MAX_FDT_SIZE) return NULL; - if (offset + *size > SWAPPER_BLOCK_SIZE) - create_mapping_noalloc(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base, - round_up(offset + *size, SWAPPER_BLOCK_SIZE), prot); + if (offset + *size > FIX_FDT_BSIZE) + create_mapping_noalloc(round_down(dt_phys, FIX_FDT_BSIZE), dt_virt_base, + round_up(offset + *size, FIX_FDT_BSIZE), prot); return dt_virt; }