Skip to content

Commit 1601df9

Browse files
Anshuman Khandualctmarinas
authored andcommitted
arm64/mm: Clear PXX_TYPE_MASK and set PXD_TYPE_SECT in [pmd|pud]_mkhuge()
Clear PXX_TYPE_MASK in [pmd|pud]_mkhuge() while creating section mappings instead of just the PXX_TABLE_BIT and also set PXD_TYPE_SECT. Also ensure PTE_VALID does not get modified in these helpers, because present-invalid entries should preserve their state across. Cc: Will Deacon <will@kernel.org> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> Link: https://lore.kernel.org/r/20250221044227.1145393-5-anshuman.khandual@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent dba9548 commit 1601df9

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

arch/arm64/include/asm/pgtable.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,18 @@ static inline int pmd_trans_huge(pmd_t pmd)
585585

586586
#define pmd_write(pmd) pte_write(pmd_pte(pmd))
587587

588-
#define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT))
588+
static inline pmd_t pmd_mkhuge(pmd_t pmd)
589+
{
590+
/*
591+
* It's possible that the pmd is present-invalid on entry
592+
* and in that case it needs to remain present-invalid on
593+
* exit. So ensure the VALID bit does not get modified.
594+
*/
595+
pmdval_t mask = PMD_TYPE_MASK & ~PTE_VALID;
596+
pmdval_t val = PMD_TYPE_SECT & ~PTE_VALID;
597+
598+
return __pmd((pmd_val(pmd) & ~mask) | val);
599+
}
589600

590601
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
591602
#define pmd_devmap(pmd) pte_devmap(pmd_pte(pmd))
@@ -613,7 +624,18 @@ static inline pmd_t pmd_mkspecial(pmd_t pmd)
613624
#define pud_mkyoung(pud) pte_pud(pte_mkyoung(pud_pte(pud)))
614625
#define pud_write(pud) pte_write(pud_pte(pud))
615626

616-
#define pud_mkhuge(pud) (__pud(pud_val(pud) & ~PUD_TABLE_BIT))
627+
static inline pud_t pud_mkhuge(pud_t pud)
628+
{
629+
/*
630+
* It's possible that the pud is present-invalid on entry
631+
* and in that case it needs to remain present-invalid on
632+
* exit. So ensure the VALID bit does not get modified.
633+
*/
634+
pudval_t mask = PUD_TYPE_MASK & ~PTE_VALID;
635+
pudval_t val = PUD_TYPE_SECT & ~PTE_VALID;
636+
637+
return __pud((pud_val(pud) & ~mask) | val);
638+
}
617639

618640
#define __pud_to_phys(pud) __pte_to_phys(pud_pte(pud))
619641
#define __phys_to_pud_val(phys) __phys_to_pte_val(phys)

0 commit comments

Comments
 (0)