Skip to content

Commit f25748e

Browse files
djbwtorvalds
authored andcommitted
mm, dax: convert vmf_insert_pfn_pmd() to pfn_t
Similar to the conversion of vm_insert_mixed() use pfn_t in the vmf_insert_pfn_pmd() to tag the resulting pte with _PAGE_DEVICE when the pfn is backed by a devm_memremap_pages() mapping. Signed-off-by: Dan Williams <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Alexander Viro <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 01c8f1c commit f25748e

File tree

8 files changed

+30
-11
lines changed

8 files changed

+30
-11
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ static inline pmd_t pmd_mkdirty(pmd_t pmd)
286286
return pmd_set_flags(pmd, _PAGE_DIRTY | _PAGE_SOFT_DIRTY);
287287
}
288288

289+
static inline pmd_t pmd_mkdevmap(pmd_t pmd)
290+
{
291+
return pmd_set_flags(pmd, _PAGE_DEVMAP);
292+
}
293+
289294
static inline pmd_t pmd_mkhuge(pmd_t pmd)
290295
{
291296
return pmd_set_flags(pmd, _PAGE_PSE);

arch/x86/mm/pat.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/debugfs.h>
1313
#include <linux/kernel.h>
1414
#include <linux/module.h>
15+
#include <linux/pfn_t.h>
1516
#include <linux/slab.h>
1617
#include <linux/mm.h>
1718
#include <linux/fs.h>
@@ -949,15 +950,15 @@ int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,
949950
}
950951

951952
int track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot,
952-
unsigned long pfn)
953+
pfn_t pfn)
953954
{
954955
enum page_cache_mode pcm;
955956

956957
if (!pat_enabled())
957958
return 0;
958959

959960
/* Set prot based on lookup */
960-
pcm = lookup_memtype((resource_size_t)pfn << PAGE_SHIFT);
961+
pcm = lookup_memtype(pfn_t_to_phys(pfn));
961962
*prot = __pgprot((pgprot_val(vma->vm_page_prot) & (~_PAGE_CACHE_MASK)) |
962963
cachemode2protval(pcm));
963964

fs/dax.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ int __dax_pmd_fault(struct vm_area_struct *vma, unsigned long address,
693693
dax_unmap_atomic(bdev, &dax);
694694

695695
result |= vmf_insert_pfn_pmd(vma, address, pmd,
696-
pfn_t_to_pfn(dax.pfn), write);
696+
dax.pfn, write);
697697
}
698698

699699
out:

include/asm-generic/pgtable.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _ASM_GENERIC_PGTABLE_H
22
#define _ASM_GENERIC_PGTABLE_H
33

4+
#include <linux/pfn.h>
5+
46
#ifndef __ASSEMBLY__
57
#ifdef CONFIG_MMU
68

@@ -549,7 +551,7 @@ static inline int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,
549551
* by vm_insert_pfn().
550552
*/
551553
static inline int track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot,
552-
unsigned long pfn)
554+
pfn_t pfn)
553555
{
554556
return 0;
555557
}
@@ -584,7 +586,7 @@ extern int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,
584586
unsigned long pfn, unsigned long addr,
585587
unsigned long size);
586588
extern int track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot,
587-
unsigned long pfn);
589+
pfn_t pfn);
588590
extern int track_pfn_copy(struct vm_area_struct *vma);
589591
extern void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
590592
unsigned long size);

include/linux/huge_mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
3737
unsigned long addr, pgprot_t newprot,
3838
int prot_numa);
3939
int vmf_insert_pfn_pmd(struct vm_area_struct *, unsigned long addr, pmd_t *,
40-
unsigned long pfn, bool write);
40+
pfn_t pfn, bool write);
4141

4242
enum transparent_hugepage_flag {
4343
TRANSPARENT_HUGEPAGE_FLAG,

include/linux/pfn_t.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ static inline pte_t pfn_t_pte(pfn_t pfn, pgprot_t pgprot)
7777
}
7878
#endif
7979

80+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
81+
static inline pmd_t pfn_t_pmd(pfn_t pfn, pgprot_t pgprot)
82+
{
83+
return pfn_pmd(pfn_t_to_pfn(pfn), pgprot);
84+
}
85+
#endif
86+
8087
#ifdef __HAVE_ARCH_PTE_DEVMAP
8188
static inline bool pfn_t_devmap(pfn_t pfn)
8289
{
@@ -90,5 +97,6 @@ static inline bool pfn_t_devmap(pfn_t pfn)
9097
return false;
9198
}
9299
pte_t pte_mkdevmap(pte_t pte);
100+
pmd_t pmd_mkdevmap(pmd_t pmd);
93101
#endif
94102
#endif /* _LINUX_PFN_T_H_ */

mm/huge_memory.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/kthread.h>
2222
#include <linux/khugepaged.h>
2323
#include <linux/freezer.h>
24+
#include <linux/pfn_t.h>
2425
#include <linux/mman.h>
2526
#include <linux/pagemap.h>
2627
#include <linux/debugfs.h>
@@ -931,14 +932,16 @@ int do_huge_pmd_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
931932
}
932933

933934
static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
934-
pmd_t *pmd, unsigned long pfn, pgprot_t prot, bool write)
935+
pmd_t *pmd, pfn_t pfn, pgprot_t prot, bool write)
935936
{
936937
struct mm_struct *mm = vma->vm_mm;
937938
pmd_t entry;
938939
spinlock_t *ptl;
939940

940941
ptl = pmd_lock(mm, pmd);
941-
entry = pmd_mkhuge(pfn_pmd(pfn, prot));
942+
entry = pmd_mkhuge(pfn_t_pmd(pfn, prot));
943+
if (pfn_t_devmap(pfn))
944+
entry = pmd_mkdevmap(entry);
942945
if (write) {
943946
entry = pmd_mkyoung(pmd_mkdirty(entry));
944947
entry = maybe_pmd_mkwrite(entry, vma);
@@ -949,7 +952,7 @@ static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
949952
}
950953

951954
int vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
952-
pmd_t *pmd, unsigned long pfn, bool write)
955+
pmd_t *pmd, pfn_t pfn, bool write)
953956
{
954957
pgprot_t pgprot = vma->vm_page_prot;
955958
/*
@@ -961,7 +964,7 @@ int vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
961964
BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) ==
962965
(VM_PFNMAP|VM_MIXEDMAP));
963966
BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags));
964-
BUG_ON((vma->vm_flags & VM_MIXEDMAP) && pfn_valid(pfn));
967+
BUG_ON(!pfn_t_devmap(pfn));
965968

966969
if (addr < vma->vm_start || addr >= vma->vm_end)
967970
return VM_FAULT_SIGBUS;

mm/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
15671567

15681568
if (addr < vma->vm_start || addr >= vma->vm_end)
15691569
return -EFAULT;
1570-
if (track_pfn_insert(vma, &pgprot, pfn))
1570+
if (track_pfn_insert(vma, &pgprot, __pfn_to_pfn_t(pfn, PFN_DEV)))
15711571
return -EINVAL;
15721572

15731573
ret = insert_pfn(vma, addr, __pfn_to_pfn_t(pfn, PFN_DEV), pgprot);

0 commit comments

Comments
 (0)