Skip to content

Commit e1fb4a0

Browse files
davejiangtorvalds
authored andcommitted
dax: remove VM_MIXEDMAP for fsdax and device dax
This patch is reworked from an earlier patch that Dan has posted: https://patchwork.kernel.org/patch/10131727/ VM_MIXEDMAP is used by dax to direct mm paths like vm_normal_page() that the memory page it is dealing with is not typical memory from the linear map. The get_user_pages_fast() path, since it does not resolve the vma, is already using {pte,pmd}_devmap() as a stand-in for VM_MIXEDMAP, so we use that as a VM_MIXEDMAP replacement in some locations. In the cases where there is no pte to consult we fallback to using vma_is_dax() to detect the VM_MIXEDMAP special case. Now that we have explicit driver pfn_t-flag opt-in/opt-out for get_user_pages() support for DAX we can stop setting VM_MIXEDMAP. This also means we no longer need to worry about safely manipulating vm_flags in a future where we support dynamically changing the dax mode of a file. DAX should also now be supported with madvise_behavior(), vma_merge(), and copy_page_range(). This patch has been tested against ndctl unit test. It has also been tested against xfstests commit: 625515d using fake pmem created by memmap and no additional issues have been observed. Link: http://lkml.kernel.org/r/152847720311.55924.16999195879201817653.stgit@djiang5-desk3.ch.intel.com Signed-off-by: Dave Jiang <[email protected]> Acked-by: Dan Williams <[email protected]> Cc: Jan Kara <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e36488c commit e1fb4a0

File tree

11 files changed

+27
-14
lines changed

11 files changed

+27
-14
lines changed

drivers/dax/device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int dax_mmap(struct file *filp, struct vm_area_struct *vma)
474474
return rc;
475475

476476
vma->vm_ops = &dax_vm_ops;
477-
vma->vm_flags |= VM_MIXEDMAP | VM_HUGEPAGE;
477+
vma->vm_flags |= VM_HUGEPAGE;
478478
return 0;
479479
}
480480

fs/ext2/file.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma)
126126

127127
file_accessed(file);
128128
vma->vm_ops = &ext2_dax_vm_ops;
129-
vma->vm_flags |= VM_MIXEDMAP;
130129
return 0;
131130
}
132131
#else

fs/ext4/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
374374
file_accessed(file);
375375
if (IS_DAX(file_inode(file))) {
376376
vma->vm_ops = &ext4_dax_vm_ops;
377-
vma->vm_flags |= VM_MIXEDMAP | VM_HUGEPAGE;
377+
vma->vm_flags |= VM_HUGEPAGE;
378378
} else {
379379
vma->vm_ops = &ext4_file_vm_ops;
380380
}

fs/xfs/xfs_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ xfs_file_mmap(
11691169
file_accessed(filp);
11701170
vma->vm_ops = &xfs_file_vm_ops;
11711171
if (IS_DAX(file_inode(filp)))
1172-
vma->vm_flags |= VM_MIXEDMAP | VM_HUGEPAGE;
1172+
vma->vm_flags |= VM_HUGEPAGE;
11731173
return 0;
11741174
}
11751175

mm/hmm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ int hmm_vma_get_pfns(struct hmm_range *range)
676676
return -EINVAL;
677677

678678
/* FIXME support hugetlb fs */
679-
if (is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_SPECIAL)) {
679+
if (is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_SPECIAL) ||
680+
vma_is_dax(vma)) {
680681
hmm_pfns_special(range);
681682
return -EINVAL;
682683
}
@@ -849,7 +850,8 @@ int hmm_vma_fault(struct hmm_range *range, bool block)
849850
return -EINVAL;
850851

851852
/* FIXME support hugetlb fs */
852-
if (is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_SPECIAL)) {
853+
if (is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_SPECIAL) ||
854+
vma_is_dax(vma)) {
853855
hmm_pfns_special(range);
854856
return -EINVAL;
855857
}

mm/huge_memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,11 @@ int vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
762762
* but we need to be consistent with PTEs and architectures that
763763
* can't support a 'special' bit.
764764
*/
765-
BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)));
765+
BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) &&
766+
!pfn_t_devmap(pfn));
766767
BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) ==
767768
(VM_PFNMAP|VM_MIXEDMAP));
768769
BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags));
769-
BUG_ON(!pfn_t_devmap(pfn));
770770

771771
if (addr < vma->vm_start || addr >= vma->vm_end)
772772
return VM_FAULT_SIGBUS;

mm/ksm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,9 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
24302430
VM_HUGETLB | VM_MIXEDMAP))
24312431
return 0; /* just ignore the advice */
24322432

2433+
if (vma_is_dax(vma))
2434+
return 0;
2435+
24332436
#ifdef VM_SAO
24342437
if (*vm_flags & VM_SAO)
24352438
return 0;

mm/memory.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,10 @@ struct page *_vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
859859
return NULL;
860860
}
861861
}
862+
863+
if (pte_devmap(pte))
864+
return NULL;
865+
862866
print_bad_pte(vma, addr, pte, NULL);
863867
return NULL;
864868
}
@@ -923,6 +927,8 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
923927
}
924928
}
925929

930+
if (pmd_devmap(pmd))
931+
return NULL;
926932
if (is_zero_pfn(pfn))
927933
return NULL;
928934
if (unlikely(pfn > highest_memmap_pfn))

mm/migrate.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,8 @@ int migrate_vma(const struct migrate_vma_ops *ops,
29512951
/* Sanity check the arguments */
29522952
start &= PAGE_MASK;
29532953
end &= PAGE_MASK;
2954-
if (!vma || is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_SPECIAL))
2954+
if (!vma || is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_SPECIAL) ||
2955+
vma_is_dax(vma))
29552956
return -EINVAL;
29562957
if (start < vma->vm_start || start >= vma->vm_end)
29572958
return -EINVAL;

mm/mlock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ static int mlock_fixup(struct vm_area_struct *vma, struct vm_area_struct **prev,
527527
vm_flags_t old_flags = vma->vm_flags;
528528

529529
if (newflags == vma->vm_flags || (vma->vm_flags & VM_SPECIAL) ||
530-
is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm))
530+
is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm) ||
531+
vma_is_dax(vma))
531532
/* don't set VM_LOCKED or VM_LOCKONFAULT and don't count */
532533
goto out;
533534

mm/mmap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,11 +1796,12 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
17961796

17971797
vm_stat_account(mm, vm_flags, len >> PAGE_SHIFT);
17981798
if (vm_flags & VM_LOCKED) {
1799-
if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
1800-
vma == get_gate_vma(current->mm)))
1801-
mm->locked_vm += (len >> PAGE_SHIFT);
1802-
else
1799+
if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) ||
1800+
is_vm_hugetlb_page(vma) ||
1801+
vma == get_gate_vma(current->mm))
18031802
vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
1803+
else
1804+
mm->locked_vm += (len >> PAGE_SHIFT);
18041805
}
18051806

18061807
if (file)

0 commit comments

Comments
 (0)