Skip to content

Commit 7518202

Browse files
xzpeterakpm00
authored andcommitted
mm/x86: support large pfn mappings
Helpers to install and detect special pmd/pud entries. In short, bit 9 on x86 is not used for pmd/pud, so we can directly define them the same as the pte level. One note is that it's also used in _PAGE_BIT_CPA_TEST but that is only used in the debug test, and shouldn't conflict in this case. One note is that pxx_set|clear_flags() for pmd/pud will need to be moved upper so that they can be referenced by the new special bit helpers. There's no change in the code that was moved. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Peter Xu <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Alex Williamson <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Gavin Shan <[email protected]> Cc: Gerald Schaefer <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Niklas Schnelle <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Will Deacon <[email protected]> Cc: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b0a1c0d commit 7518202

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ config X86_64
2828
select ARCH_HAS_GIGANTIC_PAGE
2929
select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
3030
select ARCH_SUPPORTS_PER_VMA_LOCK
31+
select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE
3132
select HAVE_ARCH_SOFT_DIRTY
3233
select MODULES_USE_ELF_RELA
3334
select NEED_DMA_MAP_STATE

arch/x86/include/asm/pgtable.h

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,34 @@ extern pmdval_t early_pmd_flags;
120120
#define arch_end_context_switch(prev) do {} while(0)
121121
#endif /* CONFIG_PARAVIRT_XXL */
122122

123+
static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set)
124+
{
125+
pmdval_t v = native_pmd_val(pmd);
126+
127+
return native_make_pmd(v | set);
128+
}
129+
130+
static inline pmd_t pmd_clear_flags(pmd_t pmd, pmdval_t clear)
131+
{
132+
pmdval_t v = native_pmd_val(pmd);
133+
134+
return native_make_pmd(v & ~clear);
135+
}
136+
137+
static inline pud_t pud_set_flags(pud_t pud, pudval_t set)
138+
{
139+
pudval_t v = native_pud_val(pud);
140+
141+
return native_make_pud(v | set);
142+
}
143+
144+
static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear)
145+
{
146+
pudval_t v = native_pud_val(pud);
147+
148+
return native_make_pud(v & ~clear);
149+
}
150+
123151
/*
124152
* The following only work if pte_present() is true.
125153
* Undefined behaviour if not..
@@ -317,6 +345,30 @@ static inline int pud_devmap(pud_t pud)
317345
}
318346
#endif
319347

348+
#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
349+
static inline bool pmd_special(pmd_t pmd)
350+
{
351+
return pmd_flags(pmd) & _PAGE_SPECIAL;
352+
}
353+
354+
static inline pmd_t pmd_mkspecial(pmd_t pmd)
355+
{
356+
return pmd_set_flags(pmd, _PAGE_SPECIAL);
357+
}
358+
#endif /* CONFIG_ARCH_SUPPORTS_PMD_PFNMAP */
359+
360+
#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
361+
static inline bool pud_special(pud_t pud)
362+
{
363+
return pud_flags(pud) & _PAGE_SPECIAL;
364+
}
365+
366+
static inline pud_t pud_mkspecial(pud_t pud)
367+
{
368+
return pud_set_flags(pud, _PAGE_SPECIAL);
369+
}
370+
#endif /* CONFIG_ARCH_SUPPORTS_PUD_PFNMAP */
371+
320372
static inline int pgd_devmap(pgd_t pgd)
321373
{
322374
return 0;
@@ -487,20 +539,6 @@ static inline pte_t pte_mkdevmap(pte_t pte)
487539
return pte_set_flags(pte, _PAGE_SPECIAL|_PAGE_DEVMAP);
488540
}
489541

490-
static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set)
491-
{
492-
pmdval_t v = native_pmd_val(pmd);
493-
494-
return native_make_pmd(v | set);
495-
}
496-
497-
static inline pmd_t pmd_clear_flags(pmd_t pmd, pmdval_t clear)
498-
{
499-
pmdval_t v = native_pmd_val(pmd);
500-
501-
return native_make_pmd(v & ~clear);
502-
}
503-
504542
/* See comments above mksaveddirty_shift() */
505543
static inline pmd_t pmd_mksaveddirty(pmd_t pmd)
506544
{
@@ -595,20 +633,6 @@ static inline pmd_t pmd_mkwrite_novma(pmd_t pmd)
595633
pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
596634
#define pmd_mkwrite pmd_mkwrite
597635

598-
static inline pud_t pud_set_flags(pud_t pud, pudval_t set)
599-
{
600-
pudval_t v = native_pud_val(pud);
601-
602-
return native_make_pud(v | set);
603-
}
604-
605-
static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear)
606-
{
607-
pudval_t v = native_pud_val(pud);
608-
609-
return native_make_pud(v & ~clear);
610-
}
611-
612636
/* See comments above mksaveddirty_shift() */
613637
static inline pud_t pud_mksaveddirty(pud_t pud)
614638
{

0 commit comments

Comments
 (0)