Skip to content

Commit d073569

Browse files
Christoph Hellwigsuryasaimadhu
authored andcommitted
x86/mm: Cleanup pgprot_4k_2_large() and pgprot_large_2_4k()
Make use of lower level helpers that operate on the raw protection values to make the code a little easier to understand, and to also avoid extra conversions in a few callers. [ Qian: Fix a wrongly placed bracket in the original submission. Reported and fixed by Qian Cai <[email protected]>. Details in second Link: below. ] Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 7fa3e10 commit d073569

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

arch/x86/include/asm/pgtable_types.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -488,24 +488,24 @@ static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm)
488488
{
489489
return __pgprot(cachemode2protval(pcm));
490490
}
491-
static inline pgprot_t pgprot_4k_2_large(pgprot_t pgprot)
491+
static inline unsigned long protval_4k_2_large(unsigned long val)
492492
{
493-
pgprotval_t val = pgprot_val(pgprot);
494-
pgprot_t new;
495-
496-
pgprot_val(new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
493+
return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
497494
((val & _PAGE_PAT) << (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
498-
return new;
495+
}
496+
static inline pgprot_t pgprot_4k_2_large(pgprot_t pgprot)
497+
{
498+
return __pgprot(protval_4k_2_large(pgprot_val(pgprot)));
499+
}
500+
static inline unsigned long protval_large_2_4k(unsigned long val)
501+
{
502+
return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
503+
((val & _PAGE_PAT_LARGE) >>
504+
(_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
499505
}
500506
static inline pgprot_t pgprot_large_2_4k(pgprot_t pgprot)
501507
{
502-
pgprotval_t val = pgprot_val(pgprot);
503-
pgprot_t new;
504-
505-
pgprot_val(new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
506-
((val & _PAGE_PAT_LARGE) >>
507-
(_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
508-
return new;
508+
return __pgprot(protval_large_2_4k(pgprot_val(pgprot)));
509509
}
510510

511511

arch/x86/mm/init_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
367367
pgprot_t prot;
368368

369369
pgprot_val(prot) = pgprot_val(PAGE_KERNEL_LARGE) |
370-
pgprot_val(pgprot_4k_2_large(cachemode2pgprot(cache)));
370+
protval_4k_2_large(cachemode2protval(cache));
371371
BUG_ON((phys & ~PMD_MASK) || (size & ~PMD_MASK));
372372
for (; size; phys += PMD_SIZE, size -= PMD_SIZE) {
373373
pgd = pgd_offset_k((unsigned long)__va(phys));

arch/x86/mm/pgtable.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,9 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
706706
if (pud_present(*pud) && !pud_huge(*pud))
707707
return 0;
708708

709-
prot = pgprot_4k_2_large(prot);
710-
711709
set_pte((pte_t *)pud, pfn_pte(
712710
(u64)addr >> PAGE_SHIFT,
713-
__pgprot(pgprot_val(prot) | _PAGE_PSE)));
711+
__pgprot(protval_4k_2_large(pgprot_val(prot)) | _PAGE_PSE)));
714712

715713
return 1;
716714
}
@@ -738,11 +736,9 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
738736
if (pmd_present(*pmd) && !pmd_huge(*pmd))
739737
return 0;
740738

741-
prot = pgprot_4k_2_large(prot);
742-
743739
set_pte((pte_t *)pmd, pfn_pte(
744740
(u64)addr >> PAGE_SHIFT,
745-
__pgprot(pgprot_val(prot) | _PAGE_PSE)));
741+
__pgprot(protval_4k_2_large(pgprot_val(prot)) | _PAGE_PSE)));
746742

747743
return 1;
748744
}

0 commit comments

Comments
 (0)