Skip to content

Commit b7a2750

Browse files
committed
LoongArch: Add ARCH_HAS_PTE_DEVMAP support
In order for things like get_user_pages() to work on ZONE_DEVICE memory, we need a software PTE bit to identify device-backed PFNs. Hook this up along with the relevant helpers to join in with ARCH_HAS_PTE_DEVMAP. Signed-off-by: Huacai Chen <[email protected]>
1 parent a0f7085 commit b7a2750

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

arch/loongarch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config LOONGARCH
2222
select ARCH_HAS_KERNEL_FPU_SUPPORT if CPU_HAS_FPU
2323
select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS
2424
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
25+
select ARCH_HAS_PTE_DEVMAP
2526
select ARCH_HAS_PTE_SPECIAL
2627
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
2728
select ARCH_INLINE_READ_LOCK if !PREEMPTION

arch/loongarch/include/asm/pgtable-bits.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define _PAGE_PFN_SHIFT 12
2323
#define _PAGE_SWP_EXCLUSIVE_SHIFT 23
2424
#define _PAGE_PFN_END_SHIFT 48
25+
#define _PAGE_DEVMAP_SHIFT 59
2526
#define _PAGE_PRESENT_INVALID_SHIFT 60
2627
#define _PAGE_NO_READ_SHIFT 61
2728
#define _PAGE_NO_EXEC_SHIFT 62
@@ -35,6 +36,7 @@
3536
#define _PAGE_MODIFIED (_ULCAST_(1) << _PAGE_MODIFIED_SHIFT)
3637
#define _PAGE_PROTNONE (_ULCAST_(1) << _PAGE_PROTNONE_SHIFT)
3738
#define _PAGE_SPECIAL (_ULCAST_(1) << _PAGE_SPECIAL_SHIFT)
39+
#define _PAGE_DEVMAP (_ULCAST_(1) << _PAGE_DEVMAP_SHIFT)
3840

3941
/* We borrow bit 23 to store the exclusive marker in swap PTEs. */
4042
#define _PAGE_SWP_EXCLUSIVE (_ULCAST_(1) << _PAGE_SWP_EXCLUSIVE_SHIFT)
@@ -74,8 +76,8 @@
7476
#define __READABLE (_PAGE_VALID)
7577
#define __WRITEABLE (_PAGE_DIRTY | _PAGE_WRITE)
7678

77-
#define _PAGE_CHG_MASK (_PAGE_MODIFIED | _PAGE_SPECIAL | _PFN_MASK | _CACHE_MASK | _PAGE_PLV)
78-
#define _HPAGE_CHG_MASK (_PAGE_MODIFIED | _PAGE_SPECIAL | _PFN_MASK | _CACHE_MASK | _PAGE_PLV | _PAGE_HUGE)
79+
#define _PAGE_CHG_MASK (_PAGE_MODIFIED | _PAGE_SPECIAL | _PAGE_DEVMAP | _PFN_MASK | _CACHE_MASK | _PAGE_PLV)
80+
#define _HPAGE_CHG_MASK (_PAGE_MODIFIED | _PAGE_SPECIAL | _PAGE_DEVMAP | _PFN_MASK | _CACHE_MASK | _PAGE_PLV | _PAGE_HUGE)
7981

8082
#define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_NO_READ | \
8183
_PAGE_USER | _CACHE_CC)

arch/loongarch/include/asm/pgtable.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ static inline int pte_special(pte_t pte) { return pte_val(pte) & _PAGE_SPECIAL;
424424
static inline pte_t pte_mkspecial(pte_t pte) { pte_val(pte) |= _PAGE_SPECIAL; return pte; }
425425
#endif /* CONFIG_ARCH_HAS_PTE_SPECIAL */
426426

427+
static inline int pte_devmap(pte_t pte) { return !!(pte_val(pte) & _PAGE_DEVMAP); }
428+
static inline pte_t pte_mkdevmap(pte_t pte) { pte_val(pte) |= _PAGE_DEVMAP; return pte; }
429+
427430
#define pte_accessible pte_accessible
428431
static inline unsigned long pte_accessible(struct mm_struct *mm, pte_t a)
429432
{
@@ -558,6 +561,17 @@ static inline pmd_t pmd_mkyoung(pmd_t pmd)
558561
return pmd;
559562
}
560563

564+
static inline int pmd_devmap(pmd_t pmd)
565+
{
566+
return !!(pmd_val(pmd) & _PAGE_DEVMAP);
567+
}
568+
569+
static inline pmd_t pmd_mkdevmap(pmd_t pmd)
570+
{
571+
pmd_val(pmd) |= _PAGE_DEVMAP;
572+
return pmd;
573+
}
574+
561575
static inline struct page *pmd_page(pmd_t pmd)
562576
{
563577
if (pmd_trans_huge(pmd))
@@ -613,6 +627,11 @@ static inline long pmd_protnone(pmd_t pmd)
613627
#define pmd_leaf(pmd) ((pmd_val(pmd) & _PAGE_HUGE) != 0)
614628
#define pud_leaf(pud) ((pud_val(pud) & _PAGE_HUGE) != 0)
615629

630+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
631+
#define pud_devmap(pud) (0)
632+
#define pgd_devmap(pgd) (0)
633+
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
634+
616635
/*
617636
* We provide our own get_unmapped area to cope with the virtual aliasing
618637
* constraints placed on us by the cache architecture.

0 commit comments

Comments
 (0)