Skip to content

Commit 03dc00a

Browse files
abrestic-rivosAlexandre Ghiti
authored andcommitted
riscv: Support huge pfnmaps
Use RSW0 as the special bit for pmds and puds, just like for ptes. Also define the {pte,pmd,pud}_pgprot helpers which were previously missing and are needed for the follow_pfnmap APIs. Signed-off-by: Andrew Bresticker <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Ghiti <[email protected]>
1 parent 8df0cdc commit 03dc00a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ config RISCV
6262
select ARCH_SUPPORTS_ATOMIC_RMW
6363
select ARCH_SUPPORTS_CFI_CLANG
6464
select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
65+
select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE
6566
select ARCH_SUPPORTS_HUGETLBFS if MMU
6667
# LLD >= 14: https://github.com/llvm/llvm-project/issues/50505
6768
select ARCH_SUPPORTS_LTO_CLANG if LLD_VERSION >= 140000

arch/riscv/include/asm/pgtable.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
341341

342342
#define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot)
343343

344+
#define pte_pgprot pte_pgprot
345+
static inline pgprot_t pte_pgprot(pte_t pte)
346+
{
347+
unsigned long pfn = pte_pfn(pte);
348+
349+
return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
350+
}
351+
344352
static inline int pte_present(pte_t pte)
345353
{
346354
return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
@@ -674,6 +682,11 @@ static inline pmd_t pte_pmd(pte_t pte)
674682
return __pmd(pte_val(pte));
675683
}
676684

685+
static inline pud_t pte_pud(pte_t pte)
686+
{
687+
return __pud(pte_val(pte));
688+
}
689+
677690
static inline pmd_t pmd_mkhuge(pmd_t pmd)
678691
{
679692
return pmd;
@@ -699,6 +712,18 @@ static inline unsigned long pud_pfn(pud_t pud)
699712
return ((__pud_to_phys(pud) & PUD_MASK) >> PAGE_SHIFT);
700713
}
701714

715+
#define pmd_pgprot pmd_pgprot
716+
static inline pgprot_t pmd_pgprot(pmd_t pmd)
717+
{
718+
return pte_pgprot(pmd_pte(pmd));
719+
}
720+
721+
#define pud_pgprot pud_pgprot
722+
static inline pgprot_t pud_pgprot(pud_t pud)
723+
{
724+
return pte_pgprot(pud_pte(pud));
725+
}
726+
702727
static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
703728
{
704729
return pte_pmd(pte_modify(pmd_pte(pmd), newprot));
@@ -768,6 +793,30 @@ static inline pmd_t pmd_mkdevmap(pmd_t pmd)
768793
return pte_pmd(pte_mkdevmap(pmd_pte(pmd)));
769794
}
770795

796+
#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
797+
static inline bool pmd_special(pmd_t pmd)
798+
{
799+
return pte_special(pmd_pte(pmd));
800+
}
801+
802+
static inline pmd_t pmd_mkspecial(pmd_t pmd)
803+
{
804+
return pte_pmd(pte_mkspecial(pmd_pte(pmd)));
805+
}
806+
#endif
807+
808+
#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
809+
static inline bool pud_special(pud_t pud)
810+
{
811+
return pte_special(pud_pte(pud));
812+
}
813+
814+
static inline pud_t pud_mkspecial(pud_t pud)
815+
{
816+
return pte_pud(pte_mkspecial(pud_pte(pud)));
817+
}
818+
#endif
819+
771820
static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
772821
pmd_t *pmdp, pmd_t pmd)
773822
{

0 commit comments

Comments
 (0)