From patchwork Mon Oct 14 10:58:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13834922 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 13C71D16256 for ; Mon, 14 Oct 2024 12:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Pem7/e2IY8K92Dd4GqzgmCKk29IF+hVKC5zPWZhX1eg=; b=WVwVaTTL+2STvSQ2EydJaA1a+V 244hZDwBcghe0JPQ/YsijkfHOPxkrsHsk/fwpFbQCnhfTmNJcPOiyPVUEsDG8TKIwQd44JLHQjteO o1oABRwa49uRfEBKfq+hwTvKyAGY6oD3ASN2LPACIva5Tqtyo4VRD60rdh3J4KkMbO0tPuxsLS+zb H1ytGDi5ORoYklBttYup6KEfdr4NcpUk6guVtQ0DZU4Dz4WOvKq9ecYkE1rxnVS1jlcRZpi4nMG6S RuiIv1BeoY0FkUmeGO5hVIWoc5SuoiJ4Hd8dtKruvNB65HaSpJ/DKsd89EIuFBrR8NQBYdIyjZ8pd urvkP3TQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0KBm-000000054zm-3IVK; Mon, 14 Oct 2024 12:28:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0Ipg-00000004oZ1-3DHe for linux-arm-kernel@lists.infradead.org; Mon, 14 Oct 2024 11:01:50 +0000 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 0E2C6176A; Mon, 14 Oct 2024 04:02:18 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0FACB3F51B; Mon, 14 Oct 2024 04:01:45 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Greg Marsden , Ivan Ivanov , Kalesh Singh , Marc Zyngier , Mark Rutland , Matthias Brugger , Miroslav Benes , Will Deacon Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1 46/57] arm64: Generalize fixmap for boot-time page size Date: Mon, 14 Oct 2024 11:58:53 +0100 Message-ID: <20241014105912.3207374-46-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241014105912.3207374-1-ryan.roberts@arm.com> References: <20241014105514.3206191-1-ryan.roberts@arm.com> <20241014105912.3207374-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241014_040148_919059_C131A498 X-CRM114-Status: GOOD ( 14.54 ) 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 Some fixmap fixed address slots previously depended on PAGE_SIZE (i.e. to determine how many slots were required to cover a given size). Since we require the fixed address slots to be compile-time constant, let's work out the worst case number of required slots when page size is PAGE_SIZE_MIN instead. Additionally, let's determine the worst-case number of PTE tables we require and statically allocate enough memory. For compile-time page size builds, the end result is the same as it was previously. Signed-off-by: Ryan Roberts --- ***NOTE*** Any confused maintainers may want to read the cover note here for context: https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/ arch/arm64/include/asm/fixmap.h | 12 ++++++++---- arch/arm64/mm/fixmap.c | 34 ++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h index 9a496d54dfe6e..c73fd3c1334ff 100644 --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -43,7 +43,7 @@ enum fixed_addresses { * whether it crosses any page boundary. */ FIX_FDT_END, - FIX_FDT = FIX_FDT_END + DIV_ROUND_UP(MAX_FDT_SIZE, PAGE_SIZE) + 1, + FIX_FDT = FIX_FDT_END + DIV_ROUND_UP(MAX_FDT_SIZE, PAGE_SIZE_MIN) + 1, FIX_EARLYCON_MEM_BASE, FIX_TEXT_POKE0, @@ -79,7 +79,7 @@ enum fixed_addresses { * Temporary boot-time mappings, used by early_ioremap(), * before ioremap() is functional. */ -#define NR_FIX_BTMAPS (SZ_256K / PAGE_SIZE) +#define NR_FIX_BTMAPS (SZ_256K / PAGE_SIZE_MIN) #define FIX_BTMAPS_SLOTS 7 #define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS) @@ -101,8 +101,12 @@ enum fixed_addresses { #define FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT) #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE) -#define FIXADDR_TOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT) -#define FIXADDR_TOT_START (FIXADDR_TOP - FIXADDR_TOT_SIZE) +#define __FIXADDR_TOT_SIZE(page_shift) \ + (__end_of_fixed_addresses << (page_shift)) +#define __FIXADDR_TOT_START(page_shift) \ + (FIXADDR_TOP - __FIXADDR_TOT_SIZE(page_shift)) +#define FIXADDR_TOT_SIZE __FIXADDR_TOT_SIZE(PAGE_SHIFT) +#define FIXADDR_TOT_START __FIXADDR_TOT_START(PAGE_SHIFT) #define FIXMAP_PAGE_IO __pgprot(PROT_DEVICE_nGnRE) diff --git a/arch/arm64/mm/fixmap.c b/arch/arm64/mm/fixmap.c index 15ce3253ad359..a0dcf2375ccb4 100644 --- a/arch/arm64/mm/fixmap.c +++ b/arch/arm64/mm/fixmap.c @@ -17,27 +17,39 @@ #include /* ensure that the fixmap region does not grow down into the PCI I/O region */ -static_assert(FIXADDR_TOT_START > PCI_IO_END); +static_assert(__FIXADDR_TOT_START(PAGE_SHIFT_MAX) > PCI_IO_END); -#define NR_BM_PTE_TABLES \ - SPAN_NR_ENTRIES(FIXADDR_TOT_START, FIXADDR_TOP, PMD_SHIFT) -#define NR_BM_PMD_TABLES \ - SPAN_NR_ENTRIES(FIXADDR_TOT_START, FIXADDR_TOP, PUD_SHIFT) +#define FIXMAP_LEVEL(page_shift, lvl, vstart, vend) \ + SPAN_NR_ENTRIES(vstart, vend, PGTABLE_LEVEL_SHIFT(page_shift, lvl)) -static_assert(NR_BM_PMD_TABLES == 1); +#define FIXMAP_PAGES(page_shift, level) \ + FIXMAP_LEVEL(page_shift, level, \ + __FIXADDR_TOT_START(page_shift), FIXADDR_TOP) + +#define FIXMAP_SIZE(page_shift, level) \ + (FIXMAP_PAGES(page_shift, level) * (UL(1) << (page_shift))) + +#define FIXMAP_PTE_SIZE_MAX \ + MAX_IF_HAVE_PGSZ(FIXMAP_SIZE(ARM64_PAGE_SHIFT_4K, 2), \ + FIXMAP_SIZE(ARM64_PAGE_SHIFT_16K, 2), \ + FIXMAP_SIZE(ARM64_PAGE_SHIFT_64K, 2)) + +static_assert(FIXMAP_PAGES(ARM64_PAGE_SHIFT_4K, 1) == 1); +static_assert(FIXMAP_PAGES(ARM64_PAGE_SHIFT_16K, 1) == 1); +static_assert(FIXMAP_PAGES(ARM64_PAGE_SHIFT_64K, 1) == 1); #define __BM_TABLE_IDX(addr, shift) \ (((addr) >> (shift)) - (FIXADDR_TOT_START >> (shift))) #define BM_PTE_TABLE_IDX(addr) __BM_TABLE_IDX(addr, PMD_SHIFT) -static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __page_aligned_bss; -static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused; -static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused; +static pte_t bm_pte[FIXMAP_PTE_SIZE_MAX / sizeof(pte_t)] __page_aligned_bss; +static pmd_t bm_pmd[MAX_PTRS_PER_PMD] __page_aligned_bss __maybe_unused; +static pud_t bm_pud[MAX_PTRS_PER_PUD] __page_aligned_bss __maybe_unused; static inline pte_t *fixmap_pte(unsigned long addr) { - return &bm_pte[BM_PTE_TABLE_IDX(addr)][pte_index(addr)]; + return &bm_pte[BM_PTE_TABLE_IDX(addr) * PTRS_PER_PTE + pte_index(addr)]; } static void __init early_fixmap_init_pte(pmd_t *pmdp, unsigned long addr) @@ -46,7 +58,7 @@ static void __init early_fixmap_init_pte(pmd_t *pmdp, unsigned long addr) pte_t *ptep; if (pmd_none(pmd)) { - ptep = bm_pte[BM_PTE_TABLE_IDX(addr)]; + ptep = &bm_pte[BM_PTE_TABLE_IDX(addr) * PTRS_PER_PTE]; __pmd_populate(pmdp, __pa_symbol(ptep), PMD_TYPE_TABLE); } }