From nobody Fri Apr 3 04:39:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58BDD36AB7F; Tue, 17 Feb 2026 13:35:39 +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=1771335341; cv=none; b=j2g258o0unjEPSPcASDerVtKTQTnspNK4IZQDFrx/FsQOQgUPAHooYyIuaJuENhUkdz+AFMs3UE9Nfjsg8pG2RDjV082kGuxdsooL5aXbAeUOBX/Dz8kWmtw9owdI7q6t9ndzVwv4NSSTNUmqBkLBFZLrdGgVEd8Bsy+qW4J1ZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771335341; c=relaxed/simple; bh=p2HUttTMJumb+w1Vr92JOVSoBkMyNgtjNJUbYjrTcCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ra2PU+6hV3aSdImIP6fhfsO9xO1358LdOFphS4sHXGIIwaxLeZ6gkvGL38iqtm4i6EheZCd2B1qXkVC5Jj17HCe/nTCSfJdIqFoeYQmfBCFfh22QQns7BBU9usdanlvMyqPH9qJL32HQc0HcENUIxIVBBuH5aOqyRZyRuC24zeY= 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 86AB21650; Tue, 17 Feb 2026 05:35:32 -0800 (PST) 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 231DD3F632; Tue, 17 Feb 2026 05:35:37 -0800 (PST) From: Ryan Roberts To: stable@vger.kernel.org Cc: Ryan Roberts , catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jack Aboutboul , Sharath George John , Noah Meyerhans , Jim Perrin , Itaru Kitayama , Eric Chanudet , Mark Rutland , Ard Biesheuvel Subject: [PATCH 6.1 1/3] arm64: mm: Don't remap pgtables per-cont(pte|pmd) block Date: Tue, 17 Feb 2026 13:35:22 +0000 Message-ID: <20260217133527.2881603-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260217133527.2881603-1-ryan.roberts@arm.com> References: <20260217133527.2881603-1-ryan.roberts@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" [ Upstream commit 5c63db59c5f89925add57642be4f789d0d671ccd ] A large part of the kernel boot time is creating the kernel linear map page tables. When rodata=3Dfull, all memory is mapped by pte. And when there is lots of physical ram, there are lots of pte tables to populate. The primary cost associated with this is mapping and unmapping the pte table memory in the fixmap; at unmap time, the TLB entry must be invalidated and this is expensive. Previously, each pmd and pte table was fixmapped/fixunmapped for each cont(pte|pmd) block of mappings (16 entries with 4K granule). This means we ended up issuing 32 TLBIs per (pmd|pte) table during the population phase. Let's fix that, and fixmap/fixunmap each page once per population, for a saving of 31 TLBIs per (pmd|pte) table. This gives a significant boot speedup. Execution time of map_mem(), which creates the kernel linear map page tables, was measured on different machines with different RAM configs: | Apple M2 VM | Ampere Altra| Ampere Altra| Ampere Altra | VM, 16G | VM, 64G | VM, 256G | Metal, 512G Reviewed-by: Ard Biesheuvel Reviewed-by: Mark Rutland Tested-by: Eric Chanudet Tested-by: Itaru Kitayama ---------------|-------------|-------------|-------------|------------- | ms (%) | ms (%) | ms (%) | ms (%) ---------------|-------------|-------------|-------------|------------- before | 168 (0%) | 2198 (0%) | 8644 (0%) | 17447 (0%) after | 78 (-53%) | 435 (-80%) | 1723 (-80%) | 3779 (-78%) Signed-off-by: Ryan Roberts Tested-by: Itaru Kitayama Tested-by: Eric Chanudet Reviewed-by: Mark Rutland Reviewed-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20240412131908.433043-2-ryan.roberts@arm.com Signed-off-by: Will Deacon [ Ryan: Trivial backport ] Signed-off-by: Ryan Roberts --- arch/arm64/mm/mmu.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index e9288b28cb1e3..b193ea2c0a629 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -169,12 +169,9 @@ static bool pgattr_change_is_safe(u64 old, u64 new) return ((old ^ new) & ~mask) =3D=3D 0; } -static void init_pte(pmd_t *pmdp, unsigned long addr, unsigned long end, +static void init_pte(pte_t *ptep, unsigned long addr, unsigned long end, phys_addr_t phys, pgprot_t prot) { - pte_t *ptep; - - ptep =3D pte_set_fixmap_offset(pmdp, addr); do { pte_t old_pte =3D READ_ONCE(*ptep); @@ -189,8 +186,6 @@ static void init_pte(pmd_t *pmdp, unsigned long addr, u= nsigned long end, phys +=3D PAGE_SIZE; } while (ptep++, addr +=3D PAGE_SIZE, addr !=3D end); - - pte_clear_fixmap(); } static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, @@ -201,6 +196,7 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned l= ong addr, { unsigned long next; pmd_t pmd =3D READ_ONCE(*pmdp); + pte_t *ptep; BUG_ON(pmd_sect(pmd)); if (pmd_none(pmd)) { @@ -216,6 +212,7 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned l= ong addr, } BUG_ON(pmd_bad(pmd)); + ptep =3D pte_set_fixmap_offset(pmdp, addr); do { pgprot_t __prot =3D prot; @@ -226,20 +223,21 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned= long addr, (flags & NO_CONT_MAPPINGS) =3D=3D 0) __prot =3D __pgprot(pgprot_val(prot) | PTE_CONT); - init_pte(pmdp, addr, next, phys, __prot); + init_pte(ptep, addr, next, phys, __prot); + ptep +=3D pte_index(next) - pte_index(addr); phys +=3D next - addr; } while (addr =3D next, addr !=3D end); + + pte_clear_fixmap(); } -static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end, +static void init_pmd(pmd_t *pmdp, unsigned long addr, unsigned long end, phys_addr_t phys, pgprot_t prot, phys_addr_t (*pgtable_alloc)(int), int flags) { unsigned long next; - pmd_t *pmdp; - pmdp =3D pmd_set_fixmap_offset(pudp, addr); do { pmd_t old_pmd =3D READ_ONCE(*pmdp); @@ -265,8 +263,6 @@ static void init_pmd(pud_t *pudp, unsigned long addr, u= nsigned long end, } phys +=3D next - addr; } while (pmdp++, addr =3D next, addr !=3D end); - - pmd_clear_fixmap(); } static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, @@ -276,6 +272,7 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned l= ong addr, { unsigned long next; pud_t pud =3D READ_ONCE(*pudp); + pmd_t *pmdp; /* * Check for initial section mappings in the pgd/pud. @@ -294,6 +291,7 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned l= ong addr, } BUG_ON(pud_bad(pud)); + pmdp =3D pmd_set_fixmap_offset(pudp, addr); do { pgprot_t __prot =3D prot; @@ -304,10 +302,13 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned= long addr, (flags & NO_CONT_MAPPINGS) =3D=3D 0) __prot =3D __pgprot(pgprot_val(prot) | PTE_CONT); - init_pmd(pudp, addr, next, phys, __prot, pgtable_alloc, flags); + init_pmd(pmdp, addr, next, phys, __prot, pgtable_alloc, flags); + pmdp +=3D pmd_index(next) - pmd_index(addr); phys +=3D next - addr; } while (addr =3D next, addr !=3D end); + + pmd_clear_fixmap(); } static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long = end, -- 2.43.0 From nobody Fri Apr 3 04:39:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E5C932548C; Tue, 17 Feb 2026 13:35: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=1771335343; cv=none; b=G9zlolWc8vazo3BnjPZf/KbGIxoJCXP8fCa8jNqw2YrqBnirdSluIMlF0vj8gvV4V8hZmTp+5yntYLI7QEeoBFGX0pirSURjiPygi6ja57o7oZ6MprABkMQ7S4Lr511gDb+lz01fpXcs5UhsmIjEqg3l1Vtvac/waACvhJkO8Eo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771335343; c=relaxed/simple; bh=y/V3R9g2AsOvXhnFszhbQ+7M//mYi5qmnHVETJIoqso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aEKuLAVbs5rgGtqP2+3pDyb6ZEuPjWtb3fvlW6jcEhWlbqvswDPuZpbOjcPxMAq41JDVoaRpomey/wbitXgHlIxPteheec4aLTfSzqajX/mFbBv9p66Py3LF0SggqgKyDsXb/UX1SOJEwQ6HYuZIP9ECSP9GlWz0PBsibdLPI9c= 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 7658A1655; Tue, 17 Feb 2026 05:35:34 -0800 (PST) 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 15EC73F632; Tue, 17 Feb 2026 05:35:38 -0800 (PST) From: Ryan Roberts To: stable@vger.kernel.org Cc: Ryan Roberts , catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jack Aboutboul , Sharath George John , Noah Meyerhans , Jim Perrin , Itaru Kitayama , Eric Chanudet , Mark Rutland , Ard Biesheuvel Subject: [PATCH 6.1 2/3] arm64: mm: Batch dsb and isb when populating pgtables Date: Tue, 17 Feb 2026 13:35:23 +0000 Message-ID: <20260217133527.2881603-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260217133527.2881603-1-ryan.roberts@arm.com> References: <20260217133527.2881603-1-ryan.roberts@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" [ Upstream commit 1fcb7cea8a5f7747e02230f816c2c80b060d9517 ] After removing uneccessary TLBIs, the next bottleneck when creating the page tables for the linear map is DSB and ISB, which were previously issued per-pte in __set_pte(). Since we are writing multiple ptes in a given pte table, we can elide these barriers and insert them once we have finished writing to the table. Execution time of map_mem(), which creates the kernel linear map page tables, was measured on different machines with different RAM configs: | Apple M2 VM | Ampere Altra| Ampere Altra| Ampere Altra | VM, 16G | VM, 64G | VM, 256G | Metal, 512G Reviewed-by: Ard Biesheuvel Reviewed-by: Mark Rutland Tested-by: Eric Chanudet Tested-by: Itaru Kitayama ---------------|-------------|-------------|-------------|------------- | ms (%) | ms (%) | ms (%) | ms (%) ---------------|-------------|-------------|-------------|------------- before | 78 (0%) | 435 (0%) | 1723 (0%) | 3779 (0%) after | 11 (-86%) | 161 (-63%) | 656 (-62%) | 1654 (-56%) Signed-off-by: Ryan Roberts Tested-by: Itaru Kitayama Tested-by: Eric Chanudet Reviewed-by: Mark Rutland Reviewed-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20240412131908.433043-3-ryan.roberts@arm.com Signed-off-by: Will Deacon [ Ryan: Trivial backport ] Signed-off-by: Ryan Roberts --- arch/arm64/include/asm/pgtable.h | 7 ++++++- arch/arm64/mm/mmu.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index 62326f249aa71..3ea0c9768c4c9 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -261,9 +261,14 @@ static inline pte_t pte_mkdevmap(pte_t pte) return set_pte_bit(pte, __pgprot(PTE_DEVMAP | PTE_SPECIAL)); } -static inline void set_pte(pte_t *ptep, pte_t pte) +static inline void set_pte_nosync(pte_t *ptep, pte_t pte) { WRITE_ONCE(*ptep, pte); +} + +static inline void set_pte(pte_t *ptep, pte_t pte) +{ + set_pte_nosync(ptep, pte); /* * Only if the new pte is valid and kernel, otherwise TLB maintenance diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index b193ea2c0a629..ca06b5e131e0f 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -175,7 +175,11 @@ static void init_pte(pte_t *ptep, unsigned long addr, = unsigned long end, do { pte_t old_pte =3D READ_ONCE(*ptep); - set_pte(ptep, pfn_pte(__phys_to_pfn(phys), prot)); + /* + * Required barriers to make this visible to the table walker + * are deferred to the end of alloc_init_cont_pte(). + */ + set_pte_nosync(ptep, pfn_pte(__phys_to_pfn(phys), prot)); /* * After the PTE entry has been populated once, we @@ -229,6 +233,11 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned = long addr, phys +=3D next - addr; } while (addr =3D next, addr !=3D end); + /* + * Note: barriers and maintenance necessary to clear the fixmap slot + * ensure that all previous pgtable writes are visible to the table + * walker. + */ pte_clear_fixmap(); } -- 2.43.0 From nobody Fri Apr 3 04:39:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FCC236B066; Tue, 17 Feb 2026 13:35:43 +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=1771335344; cv=none; b=gBANE8pHOoVm/a27t0iqAgn4kLDmpTxiIdsWRQsDN2mOfJKMN64IQ8R35c6+y/W0cTDukVmDU/gvg/buVJ6Tr0niDhkgkEpDj4JkWU5EZYsoRSBa1W3X8btacgwB2TANIw0fBBYTm7cJZ6Ro9fGNZfI7hK1WQQ7AjSFCb6buq0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771335344; c=relaxed/simple; bh=1YIhWqZuX/5+uFQxGW6DplC0TV4TWqwnIxIJFKZGVRg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=icvdeXgJDWkhbQytX+rQSstCae7GlPF/DL2XgSFVQGjYEuogaSDsi3DlpOp9Em7OCRgGfLQfxjZKUfT1QFWzezIMa7Jmg1fmPi764vyZ8qgPBpatuTuL+yVMinTOE7gRQQoKZt9JQqFxSpzFi8Wly8VFgbJYJseaFA34kTvwUHI= 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 6BCCB1477; Tue, 17 Feb 2026 05:35:36 -0800 (PST) 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 087B73FD09; Tue, 17 Feb 2026 05:35:40 -0800 (PST) From: Ryan Roberts To: stable@vger.kernel.org Cc: Ryan Roberts , catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jack Aboutboul , Sharath George John , Noah Meyerhans , Jim Perrin , Mark Rutland , Itaru Kitayama , Eric Chanudet , Ard Biesheuvel Subject: [PATCH 6.1 3/3] arm64: mm: Don't remap pgtables for allocate vs populate Date: Tue, 17 Feb 2026 13:35:24 +0000 Message-ID: <20260217133527.2881603-4-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260217133527.2881603-1-ryan.roberts@arm.com> References: <20260217133527.2881603-1-ryan.roberts@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" [ Upstream commit 0e9df1c905d8293d333ace86c13d147382f5caf9 ] During linear map pgtable creation, each pgtable is fixmapped / fixunmapped twice; once during allocation to zero the memory, and a again during population to write the entries. This means each table has 2 TLB invalidations issued against it. Let's fix this so that each table is only fixmapped/fixunmapped once, halving the number of TLBIs, and improving performance. Achieve this by separating allocation and initialization (zeroing) of the page. The allocated page is now fixmapped directly by the walker and initialized, before being populated and finally fixunmapped. This approach keeps the change small, but has the side effect that late allocations (using __get_free_page()) must also go through the generic memory clearing routine. So let's tell __get_free_page() not to zero the memory to avoid duplication. Additionally this approach means that fixmap/fixunmap is still used for late pgtable modifications. That's not technically needed since the memory is all mapped in the linear map by that point. That's left as a possible future optimization if found to be needed. Execution time of map_mem(), which creates the kernel linear map page tables, was measured on different machines with different RAM configs: | Apple M2 VM | Ampere Altra| Ampere Altra| Ampere Altra | VM, 16G | VM, 64G | VM, 256G | Metal, 512G ---------------|-------------|-------------|-------------|------------- | ms (%) | ms (%) | ms (%) | ms (%) ---------------|-------------|-------------|-------------|------------- before | 11 (0%) | 161 (0%) | 656 (0%) | 1654 (0%) after | 10 (-11%) | 104 (-35%) | 438 (-33%) | 1223 (-26%) Signed-off-by: Ryan Roberts Suggested-by: Mark Rutland Tested-by: Itaru Kitayama Tested-by: Eric Chanudet Reviewed-by: Mark Rutland Reviewed-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20240412131908.433043-4-ryan.roberts@arm.com Signed-off-by: Will Deacon [ Ryan: Trivial backport ] Signed-off-by: Ryan Roberts --- arch/arm64/mm/mmu.c | 58 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index ca06b5e131e0f..ca0bf180082d3 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -110,28 +110,12 @@ EXPORT_SYMBOL(phys_mem_access_prot); static phys_addr_t __init early_pgtable_alloc(int shift) { phys_addr_t phys; - void *ptr; phys =3D memblock_phys_alloc_range(PAGE_SIZE, PAGE_SIZE, 0, MEMBLOCK_ALLOC_NOLEAKTRACE); if (!phys) panic("Failed to allocate page table page\n"); - /* - * The FIX_{PGD,PUD,PMD} slots may be in active use, but the FIX_PTE - * slot will be free, so we can (ab)use the FIX_PTE slot to initialise - * any level of table. - */ - ptr =3D pte_set_fixmap(phys); - - memset(ptr, 0, PAGE_SIZE); - - /* - * Implicit barriers also ensure the zeroed page is visible to the page - * table walker - */ - pte_clear_fixmap(); - return phys; } @@ -169,6 +153,14 @@ static bool pgattr_change_is_safe(u64 old, u64 new) return ((old ^ new) & ~mask) =3D=3D 0; } +static void init_clear_pgtable(void *table) +{ + clear_page(table); + + /* Ensure the zeroing is observed by page table walks. */ + dsb(ishst); +} + static void init_pte(pte_t *ptep, unsigned long addr, unsigned long end, phys_addr_t phys, pgprot_t prot) { @@ -211,12 +203,15 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned= long addr, pmdval |=3D PMD_TABLE_PXN; BUG_ON(!pgtable_alloc); pte_phys =3D pgtable_alloc(PAGE_SHIFT); + ptep =3D pte_set_fixmap(pte_phys); + init_clear_pgtable(ptep); + ptep +=3D pte_index(addr); __pmd_populate(pmdp, pte_phys, pmdval); - pmd =3D READ_ONCE(*pmdp); + } else { + BUG_ON(pmd_bad(pmd)); + ptep =3D pte_set_fixmap_offset(pmdp, addr); } - BUG_ON(pmd_bad(pmd)); - ptep =3D pte_set_fixmap_offset(pmdp, addr); do { pgprot_t __prot =3D prot; @@ -295,12 +290,15 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned= long addr, pudval |=3D PUD_TABLE_PXN; BUG_ON(!pgtable_alloc); pmd_phys =3D pgtable_alloc(PMD_SHIFT); + pmdp =3D pmd_set_fixmap(pmd_phys); + init_clear_pgtable(pmdp); + pmdp +=3D pmd_index(addr); __pud_populate(pudp, pmd_phys, pudval); - pud =3D READ_ONCE(*pudp); + } else { + BUG_ON(pud_bad(pud)); + pmdp =3D pmd_set_fixmap_offset(pudp, addr); } - BUG_ON(pud_bad(pud)); - pmdp =3D pmd_set_fixmap_offset(pudp, addr); do { pgprot_t __prot =3D prot; @@ -338,12 +336,15 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long= addr, unsigned long end, p4dval |=3D P4D_TABLE_PXN; BUG_ON(!pgtable_alloc); pud_phys =3D pgtable_alloc(PUD_SHIFT); + pudp =3D pud_set_fixmap(pud_phys); + init_clear_pgtable(pudp); + pudp +=3D pud_index(addr); __p4d_populate(p4dp, pud_phys, p4dval); - p4d =3D READ_ONCE(*p4dp); + } else { + BUG_ON(p4d_bad(p4d)); + pudp =3D pud_set_fixmap_offset(p4dp, addr); } - BUG_ON(p4d_bad(p4d)); - pudp =3D pud_set_fixmap_offset(p4dp, addr); do { pud_t old_pud =3D READ_ONCE(*pudp); @@ -425,11 +426,10 @@ void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_= t phys, unsigned long virt, static phys_addr_t __pgd_pgtable_alloc(int shift) { - void *ptr =3D (void *)__get_free_page(GFP_PGTABLE_KERNEL); - BUG_ON(!ptr); + /* Page is zeroed by init_clear_pgtable() so don't duplicate effort. */ + void *ptr =3D (void *)__get_free_page(GFP_PGTABLE_KERNEL & ~__GFP_ZERO); - /* Ensure the zeroed page is visible to the page table walker */ - dsb(ishst); + BUG_ON(!ptr); return __pa(ptr); } -- 2.43.0