Skip to content

Commit 334b2ce

Browse files
torvaldsIngo Molnar
authored andcommitted
x86/mm: Add prot_sethuge() helper to abstract out _PAGE_PSE handling
We still have some historic cases of direct fiddling of page attributes with (dangerous & fragile) type casting and address shifting. Add the prot_sethuge() helper instead that gets the types right and doesn't have to transform addresses. ( Also add a debug check to make sure this doesn't get applied to _PAGE_BIT_PAT/_PAGE_BIT_PAT_LARGE pages. ) Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Dave Hansen <[email protected]>
1 parent a3d3163 commit 334b2ce

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

arch/x86/mm/init_64.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ DEFINE_ENTRY(pud, pud, init)
9090
DEFINE_ENTRY(pmd, pmd, init)
9191
DEFINE_ENTRY(pte, pte, init)
9292

93+
static inline pgprot_t prot_sethuge(pgprot_t prot)
94+
{
95+
WARN_ON_ONCE(pgprot_val(prot) & _PAGE_PAT);
96+
97+
return __pgprot(pgprot_val(prot) | _PAGE_PSE);
98+
}
9399

94100
/*
95101
* NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the
@@ -557,9 +563,8 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long paddr, unsigned long paddr_end,
557563
if (page_size_mask & (1<<PG_LEVEL_2M)) {
558564
pages++;
559565
spin_lock(&init_mm.page_table_lock);
560-
set_pte_init((pte_t *)pmd,
561-
pfn_pte((paddr & PMD_MASK) >> PAGE_SHIFT,
562-
__pgprot(pgprot_val(prot) | _PAGE_PSE)),
566+
set_pmd_init(pmd,
567+
pfn_pmd(paddr >> PAGE_SHIFT, prot_sethuge(prot)),
563568
init);
564569
spin_unlock(&init_mm.page_table_lock);
565570
paddr_last = paddr_next;
@@ -644,12 +649,8 @@ phys_pud_init(pud_t *pud_page, unsigned long paddr, unsigned long paddr_end,
644649
if (page_size_mask & (1<<PG_LEVEL_1G)) {
645650
pages++;
646651
spin_lock(&init_mm.page_table_lock);
647-
648-
prot = __pgprot(pgprot_val(prot) | _PAGE_PSE);
649-
650-
set_pte_init((pte_t *)pud,
651-
pfn_pte((paddr & PUD_MASK) >> PAGE_SHIFT,
652-
prot),
652+
set_pud_init(pud,
653+
pfn_pud(paddr >> PAGE_SHIFT, prot_sethuge(prot)),
653654
init);
654655
spin_unlock(&init_mm.page_table_lock);
655656
paddr_last = paddr_next;

0 commit comments

Comments
 (0)