Skip to content

Commit f884ae0

Browse files
committed
mm/x86: support large pfn mappings
JIRA: https://issues.redhat.com/browse/RHEL-73613 commit 7518202 Author: Peter Xu <peterx@redhat.com> Date: Mon Aug 26 16:43:51 2024 -0400 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/20240826204353.2228736-18-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Alex Williamson <alex.williamson@redhat.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: David Hildenbrand <david@redhat.com> Cc: Gavin Shan <gshan@redhat.com> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Niklas Schnelle <schnelle@linux.ibm.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Will Deacon <will@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Donald Dutile <ddutile@redhat.com>
1 parent 50863d4 commit f884ae0

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 ARCH_SUPPORTS_RT
3233
select HAVE_ARCH_SOFT_DIRTY
3334
select MODULES_USE_ELF_RELA

arch/x86/include/asm/pgtable.h

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

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

341+
#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
342+
static inline bool pmd_special(pmd_t pmd)
343+
{
344+
return pmd_flags(pmd) & _PAGE_SPECIAL;
345+
}
346+
347+
static inline pmd_t pmd_mkspecial(pmd_t pmd)
348+
{
349+
return pmd_set_flags(pmd, _PAGE_SPECIAL);
350+
}
351+
#endif /* CONFIG_ARCH_SUPPORTS_PMD_PFNMAP */
352+
353+
#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
354+
static inline bool pud_special(pud_t pud)
355+
{
356+
return pud_flags(pud) & _PAGE_SPECIAL;
357+
}
358+
359+
static inline pud_t pud_mkspecial(pud_t pud)
360+
{
361+
return pud_set_flags(pud, _PAGE_SPECIAL);
362+
}
363+
#endif /* CONFIG_ARCH_SUPPORTS_PUD_PFNMAP */
364+
313365
static inline int pgd_devmap(pgd_t pgd)
314366
{
315367
return 0;
@@ -480,20 +532,6 @@ static inline pte_t pte_mkdevmap(pte_t pte)
480532
return pte_set_flags(pte, _PAGE_SPECIAL|_PAGE_DEVMAP);
481533
}
482534

483-
static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set)
484-
{
485-
pmdval_t v = native_pmd_val(pmd);
486-
487-
return native_make_pmd(v | set);
488-
}
489-
490-
static inline pmd_t pmd_clear_flags(pmd_t pmd, pmdval_t clear)
491-
{
492-
pmdval_t v = native_pmd_val(pmd);
493-
494-
return native_make_pmd(v & ~clear);
495-
}
496-
497535
/* See comments above mksaveddirty_shift() */
498536
static inline pmd_t pmd_mksaveddirty(pmd_t pmd)
499537
{
@@ -588,20 +626,6 @@ static inline pmd_t pmd_mkwrite_novma(pmd_t pmd)
588626
pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
589627
#define pmd_mkwrite pmd_mkwrite
590628

591-
static inline pud_t pud_set_flags(pud_t pud, pudval_t set)
592-
{
593-
pudval_t v = native_pud_val(pud);
594-
595-
return native_make_pud(v | set);
596-
}
597-
598-
static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear)
599-
{
600-
pudval_t v = native_pud_val(pud);
601-
602-
return native_make_pud(v & ~clear);
603-
}
604-
605629
/* See comments above mksaveddirty_shift() */
606630
static inline pud_t pud_mksaveddirty(pud_t pud)
607631
{

0 commit comments

Comments
 (0)