dax: Clear dirty bits after flushing caches
Subsystems (36)
Jan Kara
maintainerv5 cover dax: Clear dirty bits after flushing caches
Hello,
This is the fifth revision of my patches to clear dirty bits from radix tree of DAX inodes when caches for corresponding pfns have been flushed. In principle, these patches enable handlers to easily update PTEs and do other work necessary to finish the fault without duplicating the functionality present in the generic code. I'd like to thank Kirill and Ross for reviews of the series! Kirill has reviewed most of patches from mm side and is fine with them - I'd just like his ack on the final version of patches 1, 2, 12 which I hope I've updated as he wished. Then I think the series can go in.
The patches are based on Ross' DAX PMD page fault series [1] currently sitting in XFS tree waiting for the merge window + ext4 conversion of DAX IO patch to the iomap infrastructure [2]. For testing, I've pushed out a tree including all these patches and further DAX fixes to:
git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git dax
The patches pass testing with xfstests on ext4 and xfs on my end. I'd be grateful for review so that we can push these patches for the next merge window.
[1] git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs.git dax-4.10-iomap-pmd
[2] Posted an hour ago - look for "ext4: Convert ext4 DAX IO to iomap framework"
Changes since v4:
* added acks and reviewed by's
* dropped cleanup patch to remove vma->vm_ops check
* make sure we restore original vmf->flags after using vm_fault structure for page_mkwrite handler
* mask vmf->address by PAGE_MASK in generic mm code rather than in ->fault handlers
* fixed up error handling dax_load_hole()
Changes since v3:
* rebased on top of 4.9-rc1 + DAX PMD fault series + ext4 iomap conversion
* reordered some of the patches
* killed ->virtual_address field in vm_fault structure as requested by Christoph
Changes since v2:
* rebased on top of 4.8-rc8 - this involved dealing with new fault_env structure
* changed calling convention for fault helpers
Changes since v1:
* make sure all PTE updates happen under radix tree entry lock to protect against races between faults & write-protecting code
* remove information about DAX locking from mm/memory.c
* smaller updates based on Ross' feedback
----
Background information regarding the motivation:
Currently we never clear dirty bits in the radix tree of a DAX inode. Thus fsync(2) flushes all the dirty pfns again and again. This patches implement clearing of the dirty tag in the radix tree so that we issue flush only when needed.
The difficulty with clearing the dirty tag is that we have to protect against a concurrent page fault setting the dirty tag and writing new data into the page. So we need a lock serializing page fault and clearing of the dirty tag and write-protecting PTEs (so that we get another pagefault when pfn is written to again and we have to set the dirty tag again).
The effect of the patch set is easily visible:
Writing 1 GB of data via mmap, then fsync twice.
Before this patch set both fsyncs take ~205 ms on my test machine, after the patch set the first fsync takes ~283 ms (the additional cost of walking PTEs, clearing dirty bits etc. is very noticeable), the second fsync takes below 1 us.
As a bonus, these patches make filesystem freezing for DAX filesystems reliable because mappings are now properly writeprotected while freezing the fs.
Honza
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 1/20 mm: Join struct fault_env and vm_fault
Currently we have two different structures for passing fault information around - struct vm_fault and struct fault_env. DAX will need more information in struct vm_fault to handle its faults so the content of that structure would become event closer to fault_env. Furthermore it would need to generate struct fault_env to be able to call some of the generic functions. So at this point I don't think there's much use in keeping these two structures separate. Just embed into struct vm_fault all that is needed to use it for both purposes.
--- Documentation/filesystems/Locking | 2 +- fs/userfaultfd.c | 22 +- include/linux/huge_mm.h | 10 +- include/linux/mm.h | 28 +- include/linux/userfaultfd_k.h | 4 +- mm/filemap.c | 14 +- mm/huge_memory.c | 173 ++++++------ mm/internal.h | 2 +- mm/khugepaged.c | 20 +- mm/memory.c | 549 +++++++++++++++++++------------------- mm/nommu.c | 2 +- 11 files changed, 414 insertions(+), 412 deletions(-)
Documentation/filesystems/Locking +1 -1
@@ -556,7 +556,7 @@ till "end_pgoff". ->map_pages() is called with page table locked and must not block. If it's not possible to reach a page without blocking, filesystem should skip it. Filesystem should use do_set_pte() to setup page table entry. Pointer to entry associated with the page is passed in -"pte" field in fault_env structure. Pointers to entries for other offsets +"pte" field in vm_fault structure. Pointers to entries for other offsets should be calculated relative to "pte". ->page_mkwrite() is called when a previously read-only pte is
fs/userfaultfd.c +12 -10
@@ -257,9 +257,9 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx,* fatal_signal_pending()s, and the mmap_sem must be released before * returning it. */ -int handle_userfault (struct fault_env *fe,unsigned long reason) +int handle_userfault (struct vm_fault *vmf,unsigned long reason) { -struct mm_struct *mm = fe->vma->vm_mm; +struct mm_struct *mm = vmf->vma->vm_mm;struct userfaultfd_ctx *ctx;struct userfaultfd_wait_queue uwq;int ret;
@@ -268,7 +268,7 @@ int handle_userfault(struct fault_env *fe, unsigned long reason)BUG_ON (!rwsem_is_locked (&mm->mmap_sem)); ret =VM_FAULT_SIGBUS ; - ctx = fe->vma->vm_userfaultfd_ctx.ctx; + ctx = vmf->vma->vm_userfaultfd_ctx.ctx;if (!ctx) goto out;
@@ -301,17 +301,18 @@ int handle_userfault(struct fault_env *fe, unsigned long reason)* without first stopping userland access to the memory. For * VM_UFFD_MISSING userfaults this is enough for now. */ -if (unlikely (!(fe->flags &FAULT_FLAG_ALLOW_RETRY ))) { +if (unlikely (!(vmf->flags &FAULT_FLAG_ALLOW_RETRY ))) {/* * Validate the invariant that nowait must allow retry * to be sure not to return SIGBUS erroneously on * nowait invocations. */ -BUG_ON (fe->flags &FAULT_FLAG_RETRY_NOWAIT ); +BUG_ON (vmf->flags &FAULT_FLAG_RETRY_NOWAIT );#ifdef CONFIG_DEBUG_VM if (printk_ratelimit ()) {printk (KERN_WARNING -"FAULT_FLAG_ALLOW_RETRY missing %x\n" , fe->flags); +"FAULT_FLAG_ALLOW_RETRY missing %x\n" , + vmf->flags);dump_stack (); }#endif
@@ -323,7 +324,7 @@ int handle_userfault(struct fault_env *fe, unsigned long reason)* and wait. */ ret =VM_FAULT_RETRY ; -if (fe->flags &FAULT_FLAG_RETRY_NOWAIT ) +if (vmf->flags &FAULT_FLAG_RETRY_NOWAIT ) goto out;/* take the reference before dropping the mmap_sem */
@@ -331,11 +332,11 @@ int handle_userfault(struct fault_env *fe, unsigned long reason)init_waitqueue_func_entry (&uwq.wq, userfaultfd_wake_function); uwq.wq.private = current; - uwq.msg =userfault_msg (fe->address, fe->flags, reason); + uwq.msg =userfault_msg (vmf->address, vmf->flags, reason); uwq.ctx = ctx; return_to_userland = - (fe->flags & (FAULT_FLAG_USER |FAULT_FLAG_KILLABLE )) == + (vmf->flags & (FAULT_FLAG_USER |FAULT_FLAG_KILLABLE )) == (FAULT_FLAG_USER |FAULT_FLAG_KILLABLE );spin_lock (&ctx->fault_pending_wqh.lock);
@@ -353,7 +354,8 @@ int handle_userfault(struct fault_env *fe, unsigned long reason) TASK_KILLABLE);spin_unlock (&ctx->fault_pending_wqh.lock); - must_wait =userfaultfd_must_wait (ctx, fe->address, fe->flags, reason); + must_wait =userfaultfd_must_wait (ctx, vmf->address, vmf->flags, + reason);up_read (&mm->mmap_sem); if (likely(must_wait && !ACCESS_ONCE(ctx->released) &&
include/linux/huge_mm.h +5 -5
@@ -1,12 +1,12 @@#ifndef _LINUX_HUGE_MM_H#define _LINUX_HUGE_MM_H -extern int do_huge_pmd_anonymous_page (struct fault_env *fe); +extern int do_huge_pmd_anonymous_page (struct vm_fault *vmf);extern int copy_huge_pmd (struct mm_struct *dst_mm,struct mm_struct *src_mm,pmd_t *dst_pmd,pmd_t *src_pmd,unsigned long addr,struct vm_area_struct *vma); -extern void huge_pmd_set_accessed (struct fault_env *fe,pmd_t orig_pmd); -extern int do_huge_pmd_wp_page (struct fault_env *fe,pmd_t orig_pmd); +extern void huge_pmd_set_accessed (struct vm_fault *vmf,pmd_t orig_pmd); +extern int do_huge_pmd_wp_page (struct vm_fault *vmf,pmd_t orig_pmd); extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd,
@@ -142,7 +142,7 @@ static inline int hpage_nr_pages(struct page *page)return 1 ; } -extern int do_huge_pmd_numa_page (struct fault_env *fe,pmd_t orig_pmd); +extern int do_huge_pmd_numa_page (struct vm_fault *vmf,pmd_t orig_pmd);extern struct page *huge_zero_page;
@@ -210,7 +210,7 @@ static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,return NULL ; } -static inline int do_huge_pmd_numa_page (struct fault_env *fe,pmd_t orig_pmd) +static inline int do_huge_pmd_numa_page (struct vm_fault *vmf,pmd_t orig_pmd) {return 0 ; }
include/linux/mm.h +11 -17
@@ -292,10 +292,16 @@ extern pgprot_t protection_map[16];* pgoff should be used in favour of virtual_address, if possible. */ struct vm_fault { +struct vm_area_struct *vma;/* Target VMA */ unsigned int flags;/* FAULT_FLAG_xxx flags */ gfp_t gfp_mask;/* gfp mask to be used for allocations */ pgoff_t pgoff;/* Logical page offset based on vma */ -void __user *virtual_address;/* Faulting virtual address */ +unsigned long address;/* Faulting virtual address */ +void __user *virtual_address;/* Faulting virtual address masked by +* PAGE_MASK */ +pmd_t *pmd;/* Pointer to pmd entry matching +* the 'address' +*/ struct page *cow_page;/* Handler may choose to COW */ struct page *page;/* ->fault handlers should return a
@@ -309,19 +315,7 @@ struct vm_fault {* VM_FAULT_DAX_LOCKED and fill in * entry here. */ -}; - -/* -* Page fault context: passes though page fault handler instead of endless list -* of function arguments. -*/ -struct fault_env { -struct vm_area_struct *vma;/* Target VMA */ -unsigned long address;/* Faulting virtual address */ -unsigned int flags;/* FAULT_FLAG_xxx flags */ -pmd_t *pmd;/* Pointer to pmd entry matching -* the 'address' -*/ +/* These three entries are valid only while holding ptl lock */ pte_t *pte;/* Pointer to pte entry matching * the 'address'. NULL if the page * table hasn't been allocated.
@@ -351,7 +345,7 @@ struct vm_operations_struct {int (*fault)(struct vm_area_struct *vma,struct vm_fault *vmf);int (*pmd_fault)(struct vm_area_struct *,unsigned long address,pmd_t *,unsigned int flags); -void (*map_pages)(struct fault_env *fe, +void (*map_pages)(struct vm_fault *vmf,pgoff_t start_pgoff,pgoff_t end_pgoff);/* notification that a previously read-only page is about to become
@@ -625,7 +619,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) return pte; } -int alloc_set_pte (struct fault_env *fe,struct mem_cgroup *memcg, +int alloc_set_pte (struct vm_fault *vmf,struct mem_cgroup *memcg,struct page *page);#endif
@@ -2097,7 +2091,7 @@ extern void truncate_inode_pages_final(struct address_space *);/* generic vm_area_ops exported for stackable file systems */ extern int filemap_fault (struct vm_area_struct *,struct vm_fault *); -extern void filemap_map_pages (struct fault_env *fe, +extern void filemap_map_pages (struct vm_fault *vmf,pgoff_t start_pgoff,pgoff_t end_pgoff);extern int filemap_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf);
include/linux/userfaultfd_k.h +2 -2
@@ -27,7 +27,7 @@#define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)#define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS) -extern int handle_userfault (struct fault_env *fe,unsigned long reason); +extern int handle_userfault (struct vm_fault *vmf,unsigned long reason);extern ssize_t mcopy_atomic (struct mm_struct *dst_mm,unsigned long dst_start,unsigned long src_start,unsigned long len);
@@ -55,7 +55,7 @@ static inline bool userfaultfd_armed(struct vm_area_struct *vma)#else /* CONFIG_USERFAULTFD */ /* mm helpers */ -static inline int handle_userfault (struct fault_env *fe,unsigned long reason) +static inline int handle_userfault (struct vm_fault *vmf,unsigned long reason) {return VM_FAULT_SIGBUS ; }
mm/filemap.c +7 -7
@@ -2212,12 +2212,12 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) }EXPORT_SYMBOL (filemap_fault); -void filemap_map_pages (struct fault_env *fe, +void filemap_map_pages (struct vm_fault *vmf,pgoff_t start_pgoff,pgoff_t end_pgoff) {struct radix_tree_iter iter;void **slot; -struct file *file = fe->vma->vm_file; +struct file *file = vmf->vma->vm_file;struct address_space *mapping = file->f_mapping;pgoff_t last_pgoff = start_pgoff;loff_t size;
@@ -2273,11 +2273,11 @@ void filemap_map_pages(struct fault_env *fe,if (file->f_ra.mmap_miss >0 ) file->f_ra.mmap_miss--; - fe->address += (iter.index - last_pgoff) <<PAGE_SHIFT ; -if (fe->pte) - fe->pte += iter.index - last_pgoff; + vmf->address += (iter.index - last_pgoff) <<PAGE_SHIFT ; +if (vmf->pte) + vmf->pte += iter.index - last_pgoff; last_pgoff = iter.index; -if (alloc_set_pte (fe,NULL , page)) +if (alloc_set_pte (vmf,NULL , page)) goto unlock;unlock_page (page); goto next;
@@ -2287,7 +2287,7 @@ void filemap_map_pages(struct fault_env *fe,put_page (page); next:/* Huge page is mapped? No need to proceed. */ -if (pmd_trans_huge (*fe->pmd)) +if (pmd_trans_huge (*vmf->pmd))break ;if (iter.index == end_pgoff)break ;
mm/huge_memory.c +87 -86
424 lines not on this page · raw message
mm/internal.h +1 -1
@@ -36,7 +36,7 @@/* Do not use these with a slab allocator */ #define GFP_SLAB_BUG_MASK (__GFP_DMA32|__GFP_HIGHMEM|~__GFP_BITS_MASK) -int do_swap_page (struct fault_env *fe,pte_t orig_pte); +int do_swap_page (struct vm_fault *vmf,pte_t orig_pte);void free_pgtables (struct mmu_gather *tlb,struct vm_area_struct *start_vma,unsigned long floor,unsigned long ceiling);
mm/khugepaged.c +10 -10
@@ -875,7 +875,7 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm, {pte_t pteval;int swapped_in =0 , ret =0 ; -struct fault_env fe = { +struct vm_fault vmf = { .vma = vma, .address = address, .flags =FAULT_FLAG_ALLOW_RETRY ,
@@ -887,19 +887,19 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm,trace_mm_collapse_huge_page_swapin (mm, swapped_in, referenced,0 );return false; } - fe.pte =pte_offset_map (pmd, address); -for (; fe.address < address +HPAGE_PMD_NR *PAGE_SIZE ; - fe.pte++, fe.address +=PAGE_SIZE ) { - pteval = *fe.pte; + vmf.pte =pte_offset_map (pmd, address); +for (; vmf.address < address +HPAGE_PMD_NR *PAGE_SIZE ; + vmf.pte++, vmf.address +=PAGE_SIZE ) { + pteval = *vmf.pte;if (!is_swap_pte (pteval))continue ; swapped_in++; - ret =do_swap_page (&fe, pteval); + ret =do_swap_page (&vmf, pteval);/* do_swap_page returns VM_FAULT_RETRY with released mmap_sem */ if (ret &VM_FAULT_RETRY ) {down_read (&mm->mmap_sem); -if (hugepage_vma_revalidate (mm, address, &fe.vma)) { +if (hugepage_vma_revalidate (mm, address, &vmf.vma)) {/* vma is no longer available, don't continue to swapin */ trace_mm_collapse_huge_page_swapin (mm, swapped_in, referenced,0 );return false;
@@ -913,10 +913,10 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm,return false; }/* pte is unmapped now, we need to map it */ - fe.pte =pte_offset_map (pmd, fe.address); + vmf.pte =pte_offset_map (pmd, vmf.address); } - fe.pte--; -pte_unmap (fe.pte); + vmf.pte--; +pte_unmap (vmf.pte);trace_mm_collapse_huge_page_swapin (mm, swapped_in, referenced,1 );return true; }
mm/memory.c +277 -272
1,211 lines not on this page · raw message
mm/nommu.c +1 -1
@@ -1801,7 +1801,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) }EXPORT_SYMBOL (filemap_fault); -void filemap_map_pages (struct fault_env *fe, +void filemap_map_pages (struct vm_fault *vmf,pgoff_t start_pgoff,pgoff_t end_pgoff) {BUG ();
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 01/20] mm: Join struct fault_env and vm_fault
Quoted 10 lines · Jan Kara
Currently we have two different structures for passing fault information around - struct
vm_faultand structfault_env. DAX will need more information in structvm_faultto handle its faults so the content of that structure would become event closer tofault_env. Furthermore it would need to generate structfault_envto be able to call some of the generic functions. So at this point I don't think there's much use in keeping these two structures separate. Just embed into structvm_faultall that is needed to use it for both purposes.Signed-off-by Jan Kara <[email protected]>
Signature · 5 lines
Kirill A. Shutemov _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v5 2/20 mm: Use vmf->address instead of of vmf->virtual_address
In reply to Jan KaraEvery single user of vmf->virtual_address typed that entry to unsigned long before doing anything with it so the type of virtual_address does not really provide us any additional safety. Just use masked vmf->address which already has the appropriate type.
--- arch/powerpc/platforms/cell/spufs/file.c | 8 +++----- arch/x86/entry/vdso/vma.c | 4 ++-- drivers/char/agp/alpha-agp.c | 3 +-- drivers/char/mspec.c | 2 +- drivers/dax/dax.c | 3 +-- drivers/gpu/drm/armada/armada_gem.c | 5 ++--- drivers/gpu/drm/drm_vm.c | 10 +++++----- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 7 +++---- drivers/gpu/drm/exynos/exynos_drm_gem.c | 6 ++---- drivers/gpu/drm/gma500/framebuffer.c | 2 +- drivers/gpu/drm/gma500/gem.c | 5 ++--- drivers/gpu/drm/i915/i915_gem.c | 3 +-- drivers/gpu/drm/msm/msm_gem.c | 8 +++----- drivers/gpu/drm/omapdrm/omap_gem.c | 20 ++++++++------------ drivers/gpu/drm/tegra/gem.c | 4 ++-- drivers/gpu/drm/ttm/ttm_bo_vm.c | 2 +- drivers/gpu/drm/udl/udl_gem.c | 5 ++--- drivers/gpu/drm/vgem/vgem_drv.c | 2 +- drivers/media/v4l2-core/videobuf-dma-sg.c | 5 ++--- drivers/misc/cxl/context.c | 5 ++--- drivers/misc/sgi-gru/grumain.c | 2 +- drivers/staging/android/ion/ion.c | 2 +- drivers/staging/lustre/lustre/llite/vvp_io.c | 6 +++--- drivers/xen/privcmd.c | 2 +- fs/dax.c | 4 ++-- include/linux/mm.h | 2 -- mm/memory.c | 9 ++++----- 27 files changed, 57 insertions(+), 79 deletions(-)
arch/powerpc/platforms/cell/spufs/file.c +3 -5
@@ -236,7 +236,6 @@ static int spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) { struct spu_context *ctx = vma->vm_file->private_data; -unsigned long address = (unsigned long )vmf->virtual_address;unsigned long pfn, offset; offset = vmf->pgoff <<PAGE_SHIFT ;
@@ -244,7 +243,7 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)return VM_FAULT_SIGBUS ;pr_debug ("spufs_mem_mmap_fault address=0x%lx, offset=0x%lx\n" , - address, offset); + vmf->address, offset);if (spu_acquire (ctx))return VM_FAULT_NOPAGE ;
@@ -256,7 +255,7 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) vma->vm_page_prot =pgprot_noncached_wc (vma->vm_page_prot); pfn = (ctx->spu->local_store_phys + offset) >>PAGE_SHIFT ; } -vm_insert_pfn (vma, address, pfn); +vm_insert_pfn (vma, vmf->address, pfn);spu_release (ctx);
@@ -355,8 +354,7 @@ static int spufs_ps_fault(struct vm_area_struct *vma,down_read (¤t->mm->mmap_sem); }else { area = ctx->spu->problem_phys + ps_offs; -vm_insert_pfn (vma, (unsigned long )vmf->virtual_address, - (area + offset) >>PAGE_SHIFT ); +vm_insert_pfn (vma, vmf->address, (area + offset) >>PAGE_SHIFT );spu_context_trace (spufs_ps_fault__insert, ctx, ctx->spu); }
arch/x86/entry/vdso/vma.c +2 -2
@@ -109,7 +109,7 @@ static int vvar_fault(const struct vm_special_mapping *sm,return VM_FAULT_SIGBUS ;if (sym_offset == image->sym_vvar_page) { - ret =vm_insert_pfn (vma, (unsigned long )vmf->virtual_address, + ret =vm_insert_pfn (vma, vmf->address,__pa_symbol (&__vvar_page) >>PAGE_SHIFT ); }else if (sym_offset == image->sym_pvclock_page) { struct pvclock_vsyscall_time_info *pvti =
@@ -117,7 +117,7 @@ static int vvar_fault(const struct vm_special_mapping *sm,if (pvti &&vclock_was_used (VCLOCK_PVCLOCK )) { ret =vm_insert_pfn ( vma, - (unsigned long )vmf->virtual_address, + vmf->address,__pa (pvti) >>PAGE_SHIFT ); } }
drivers/char/agp/alpha-agp.c +1 -2
@@ -19,8 +19,7 @@ static int alpha_core_agp_vm_fault(struct vm_area_struct *vma,unsigned long pa;struct page *page; - dma_addr = (unsigned long )vmf->virtual_address - vma->vm_start - + agp->aperture.bus_base; + dma_addr = vmf->address - vma->vm_start + agp->aperture.bus_base; pa = agp->ops->translate (agp, dma_addr);if (pa == (unsigned long )-EINVAL )
drivers/char/mspec.c +1 -1
@@ -227,7 +227,7 @@ mspec_fault(struct vm_area_struct *vma, struct vm_fault *vmf)* be because another thread has installed the pte first, so it * is no problem. */ -vm_insert_pfn (vma, (unsigned long )vmf->virtual_address, pfn); +vm_insert_pfn (vma, vmf->address, pfn);return VM_FAULT_NOPAGE ; }
drivers/dax/dax.c +1 -2
@@ -328,7 +328,6 @@ static phys_addr_t pgoff_to_phys(struct dax_dev *dax_dev, pgoff_t pgoff,static int __dax_dev_fault (struct dax_dev *dax_dev,struct vm_area_struct *vma,struct vm_fault *vmf) { -unsigned long vaddr = (unsigned long ) vmf->virtual_address;struct device *dev = &dax_dev->dev;struct dax_region *dax_region;int rc =VM_FAULT_SIGBUS ;
@@ -353,7 +352,7 @@ static int __dax_dev_fault(struct dax_dev *dax_dev, struct vm_area_struct *vma, pfn =phys_to_pfn_t (phys, dax_region->pfn_flags); - rc =vm_insert_mixed (vma, vaddr, pfn); + rc =vm_insert_mixed (vma, vmf->address, pfn);if (rc == -ENOMEM )return VM_FAULT_OOM ;
drivers/gpu/drm/armada/armada_gem.c +2 -3
@@ -17,12 +17,11 @@static int armada_gem_vm_fault (struct vm_area_struct *vma,struct vm_fault *vmf) {struct armada_gem_object *obj =drm_to_armada_gem (vma->vm_private_data); -unsigned long addr = (unsigned long )vmf->virtual_address;unsigned long pfn = obj->phys_addr >>PAGE_SHIFT ;int ret; - pfn += (addr - vma->vm_start) >>PAGE_SHIFT ; - ret =vm_insert_pfn (vma, addr, pfn); + pfn += (vmf->address - vma->vm_start) >>PAGE_SHIFT ; + ret =vm_insert_pfn (vma, vmf->address, pfn);switch (ret) {case 0 :
drivers/gpu/drm/drm_vm.c +5 -5
@@ -124,8 +124,7 @@ static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)* Using vm_pgoff as a selector forces us to use this unusual * addressing scheme. */ -resource_size_t offset = (unsigned long )vmf->virtual_address - - vma->vm_start; +resource_size_t offset = vmf->address - vma->vm_start;resource_size_t baddr = map->offset + offset;struct drm_agp_mem *agpmem;struct page *page;
@@ -195,7 +194,7 @@ static int drm_do_vm_shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)if (!map)return VM_FAULT_SIGBUS ;/* Nothing allocated */ - offset = (unsigned long )vmf->virtual_address - vma->vm_start; + offset = vmf->address - vma->vm_start; i = (unsigned long )map->handle + offset; page =vmalloc_to_page ((void *)i);if (!page)
@@ -301,7 +300,8 @@ static int drm_do_vm_dma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)if (!dma->pagelist)return VM_FAULT_SIGBUS ;/* Nothing allocated */ - offset = (unsigned long )vmf->virtual_address - vma->vm_start;/* vm_[pg]off[set] should be 0 */ + offset = vmf->address - vma->vm_start; +/* vm_[pg]off[set] should be 0 */ page_nr = offset >>PAGE_SHIFT ;/* page_nr could just be vmf->pgoff */ page =virt_to_page ((void *)dma->pagelist[page_nr]);
@@ -337,7 +337,7 @@ static int drm_do_vm_sg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)if (!entry->pagelist)return VM_FAULT_SIGBUS ;/* Nothing allocated */ - offset = (unsigned long )vmf->virtual_address - vma->vm_start; + offset = vmf->address - vma->vm_start; map_offset = map->offset - (unsigned long )dev->sg->virtual; page_offset = (offset >>PAGE_SHIFT ) + (map_offset >>PAGE_SHIFT ); page = entry->pagelist[page_offset];
drivers/gpu/drm/etnaviv/etnaviv_gem.c +3 -4
@@ -202,15 +202,14 @@ int etnaviv_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) }/* We don't use vmf->pgoff since that has the fake offset: */ - pgoff = ((unsigned long )vmf->virtual_address - - vma->vm_start) >>PAGE_SHIFT ; + pgoff = (vmf->address - vma->vm_start) >>PAGE_SHIFT ; page = pages[pgoff]; -VERB ("Inserting %p pfn %lx, pa %lx" , vmf->virtual_address, +VERB ("Inserting %p pfn %lx, pa %lx" , (void *)vmf->address,page_to_pfn (page),page_to_pfn (page) <<PAGE_SHIFT ); - ret =vm_insert_page (vma, (unsigned long )vmf->virtual_address, page); + ret =vm_insert_page (vma, vmf->address, page); out:switch (ret) {
drivers/gpu/drm/exynos/exynos_drm_gem.c +2 -4
@@ -455,8 +455,7 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)pgoff_t page_offset;int ret; - page_offset = ((unsigned long )vmf->virtual_address - - vma->vm_start) >>PAGE_SHIFT ; + page_offset = (vmf->address - vma->vm_start) >>PAGE_SHIFT ;if (page_offset >= (exynos_gem->size >>PAGE_SHIFT )) {DRM_ERROR ("invalid page offset\n" );
@@ -465,8 +464,7 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) } pfn =page_to_pfn (exynos_gem->pages[page_offset]); - ret =vm_insert_mixed (vma, (unsigned long )vmf->virtual_address, -__pfn_to_pfn_t (pfn,PFN_DEV )); + ret =vm_insert_mixed (vma, vmf->address,__pfn_to_pfn_t (pfn,PFN_DEV )); out:switch (ret) {
drivers/gpu/drm/gma500/framebuffer.c +1 -1
@@ -125,7 +125,7 @@ static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) psbfb->gtt->offset; page_num = (vma->vm_end - vma->vm_start) >>PAGE_SHIFT ; - address = (unsigned long )vmf->virtual_address - (vmf->pgoff <<PAGE_SHIFT ); + address = vmf->address - (vmf->pgoff <<PAGE_SHIFT ); vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);
drivers/gpu/drm/gma500/gem.c +2 -3
@@ -197,15 +197,14 @@ int psb_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)/* Page relative to the VMA start - we must calculate this ourselves because vmf->pgoff is the fake GEM offset */ - page_offset = ((unsigned long ) vmf->virtual_address - vma->vm_start) - >>PAGE_SHIFT ; + page_offset = (vmf->address - vma->vm_start) >>PAGE_SHIFT ;/* CPU view of the page, don't go via the GART for CPU writes */ if (r->stolen) pfn = (dev_priv->stolen_base + r->offset) >>PAGE_SHIFT ;else pfn =page_to_pfn (r->pages[page_offset]); - ret =vm_insert_pfn (vma, (unsigned long )vmf->virtual_address, pfn); + ret =vm_insert_pfn (vma, vmf->address, pfn); fail:mutex_unlock (&dev_priv->mmap_mutex);
drivers/gpu/drm/i915/i915_gem.c +1 -2
@@ -1763,8 +1763,7 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf)int ret;/* We don't use vmf->pgoff since that has the fake offset */ - page_offset = ((unsigned long )vmf->virtual_address - area->vm_start) >> -PAGE_SHIFT ; + page_offset = (vmf->address - area->vm_start) >>PAGE_SHIFT ;trace_i915_gem_object_fault (obj, page_offset, true, write);
drivers/gpu/drm/msm/msm_gem.c +3 -5
@@ -225,16 +225,14 @@ int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) }/* We don't use vmf->pgoff since that has the fake offset: */ - pgoff = ((unsigned long )vmf->virtual_address - - vma->vm_start) >>PAGE_SHIFT ; + pgoff = (vmf->address - vma->vm_start) >>PAGE_SHIFT ; pfn =page_to_pfn (pages[pgoff]); -VERB ("Inserting %p pfn %lx, pa %lx" , vmf->virtual_address, +VERB ("Inserting %p pfn %lx, pa %lx" , (void *)vmf->address, pfn, pfn <<PAGE_SHIFT ); - ret =vm_insert_mixed (vma, (unsigned long )vmf->virtual_address, -__pfn_to_pfn_t (pfn,PFN_DEV )); + ret =vm_insert_mixed (vma, vmf->address,__pfn_to_pfn_t (pfn,PFN_DEV )); out_unlock:mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/omapdrm/omap_gem.c +8 -12
@@ -396,8 +396,7 @@ static int fault_1d(struct drm_gem_object *obj,pgoff_t pgoff;/* We don't use vmf->pgoff since that has the fake offset: */ - pgoff = ((unsigned long )vmf->virtual_address - - vma->vm_start) >>PAGE_SHIFT ; + pgoff = (vmf->address - vma->vm_start) >>PAGE_SHIFT ;if (omap_obj->pages) {omap_gem_cpu_sync (obj, pgoff);
@@ -407,11 +406,10 @@ static int fault_1d(struct drm_gem_object *obj, pfn = (omap_obj->paddr >>PAGE_SHIFT ) + pgoff; } -VERB ("Inserting %p pfn %lx, pa %lx" , vmf->virtual_address, +VERB ("Inserting %p pfn %lx, pa %lx" , (void *)vmf->address, pfn, pfn <<PAGE_SHIFT ); -return vm_insert_mixed (vma, (unsigned long )vmf->virtual_address, -__pfn_to_pfn_t (pfn,PFN_DEV )); +return vm_insert_mixed (vma, vmf->address,__pfn_to_pfn_t (pfn,PFN_DEV )); }/* Special handling for the case of faulting in 2d tiled buffers */
@@ -425,7 +423,7 @@ static int fault_2d(struct drm_gem_object *obj,struct page *pages[64 ];/* XXX is this too much to have on stack? */ unsigned long pfn;pgoff_t pgoff, base_pgoff; -void __user *vaddr; +unsigned long vaddr;int i, ret, slots;/*
@@ -445,8 +443,7 @@ static int fault_2d(struct drm_gem_object *obj,const int m =1 + ((omap_obj->width << fmt) /PAGE_SIZE );/* We don't use vmf->pgoff since that has the fake offset: */ - pgoff = ((unsigned long )vmf->virtual_address - - vma->vm_start) >>PAGE_SHIFT ; + pgoff = (vmf->address - vma->vm_start) >>PAGE_SHIFT ;/* * Actual address we start mapping at is rounded down to previous slot
@@ -457,7 +454,7 @@ static int fault_2d(struct drm_gem_object *obj,/* figure out buffer width in slots */ slots = omap_obj->width >> priv->usergart[fmt].slot_shift; - vaddr = vmf->virtual_address - ((pgoff - base_pgoff) <<PAGE_SHIFT ); + vaddr = vmf->address - ((pgoff - base_pgoff) <<PAGE_SHIFT ); entry = &priv->usergart[fmt].entry[priv->usergart[fmt].last];
@@ -501,12 +498,11 @@ static int fault_2d(struct drm_gem_object *obj, pfn = entry->paddr >>PAGE_SHIFT ; -VERB ("Inserting %p pfn %lx, pa %lx" , vmf->virtual_address, +VERB ("Inserting %p pfn %lx, pa %lx" , (void *)vmf->address, pfn, pfn <<PAGE_SHIFT );for (i = n; i >0 ; i--) { -vm_insert_mixed (vma, (unsigned long )vaddr, -__pfn_to_pfn_t (pfn,PFN_DEV )); +vm_insert_mixed (vma, vaddr,__pfn_to_pfn_t (pfn,PFN_DEV )); pfn += priv->usergart[fmt].stride_pfn; vaddr +=PAGE_SIZE * m; }
drivers/gpu/drm/tegra/gem.c +2 -2
@@ -427,10 +427,10 @@ static int tegra_bo_fault(struct vm_area_struct *vma, struct vm_fault *vmf)if (!bo->pages)return VM_FAULT_SIGBUS ; - offset = ((unsigned long )vmf->virtual_address - vma->vm_start) >>PAGE_SHIFT ; + offset = (vmf->address - vma->vm_start) >>PAGE_SHIFT ; page = bo->pages[offset]; - err =vm_insert_page (vma, (unsigned long )vmf->virtual_address, page); + err =vm_insert_page (vma, vmf->address, page);switch (err) {case -EAGAIN :case 0 :
drivers/gpu/drm/ttm/ttm_bo_vm.c +1 -1
@@ -101,7 +101,7 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)struct page *page;int ret;int i; -unsigned long address = (unsigned long )vmf->virtual_address; +unsigned long address = vmf->address;int retval =VM_FAULT_NOPAGE ;struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];
drivers/gpu/drm/udl/udl_gem.c +2 -3
@@ -107,14 +107,13 @@ int udl_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)unsigned int page_offset;int ret =0 ; - page_offset = ((unsigned long )vmf->virtual_address - vma->vm_start) >> -PAGE_SHIFT ; + page_offset = (vmf->address - vma->vm_start) >>PAGE_SHIFT ;if (!obj->pages)return VM_FAULT_SIGBUS ; page = obj->pages[page_offset]; - ret =vm_insert_page (vma, (unsigned long )vmf->virtual_address, page); + ret =vm_insert_page (vma, vmf->address, page);switch (ret) {case -EAGAIN :case 0 :
drivers/gpu/drm/vgem/vgem_drv.c +1 -1
@@ -54,7 +54,7 @@ static int vgem_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) {struct drm_vgem_gem_object *obj = vma->vm_private_data;/* We don't use vmf->pgoff since that has the fake offset */ -unsigned long vaddr = (unsigned long )vmf->virtual_address; +unsigned long vaddr = vmf->address;struct page *page; page = shmem_read_mapping_page(file_inode(obj->base.filp)->i_mapping,
drivers/media/v4l2-core/videobuf-dma-sg.c +2 -3
@@ -439,13 +439,12 @@ static int videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)struct page *page;dprintk (3 ,"fault: fault @ %08lx [vma %08lx-%08lx]\n" , - (unsigned long )vmf->virtual_address, - vma->vm_start, vma->vm_end); + vmf->address, vma->vm_start, vma->vm_end); page =alloc_page (GFP_USER | __GFP_DMA32);if (!page)return VM_FAULT_OOM ; -clear_user_highpage (page, (unsigned long )vmf->virtual_address); +clear_user_highpage (page, vmf->address); vmf->page = page;return 0 ;
drivers/misc/cxl/context.c +2 -3
@@ -117,13 +117,12 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,static int cxl_mmap_fault (struct vm_area_struct *vma,struct vm_fault *vmf) {struct cxl_context *ctx = vma->vm_file->private_data; -unsigned long address = (unsigned long )vmf->virtual_address;u64 area, offset; offset = vmf->pgoff <<PAGE_SHIFT ;pr_devel ("%s: pe: %i address: 0x%lx offset: 0x%llx\n" , - __func__, ctx->pe, address, offset); + __func__, ctx->pe, vmf->address, offset);if (ctx->afu->current_mode ==CXL_MODE_DEDICATED ) { area = ctx->afu->psn_phys;
@@ -155,7 +154,7 @@ static int cxl_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)return VM_FAULT_SIGBUS ; } -vm_insert_pfn (vma, address, (area + offset) >>PAGE_SHIFT ); +vm_insert_pfn (vma, vmf->address, (area + offset) >>PAGE_SHIFT );mutex_unlock (&ctx->status_mutex);
drivers/misc/sgi-gru/grumain.c +1 -1
@@ -932,7 +932,7 @@ int gru_fault(struct vm_area_struct *vma, struct vm_fault *vmf)unsigned long paddr, vaddr;unsigned long expires; - vaddr = (unsigned long )vmf->virtual_address; + vaddr = vmf->address;gru_dbg (grudev,"vma %p, vaddr 0x%lx (0x%lx)\n" , vma, vaddr,GSEG_BASE (vaddr));STAT (nopfn);
drivers/staging/android/ion/ion.c +1 -1
@@ -882,7 +882,7 @@ static int ion_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)BUG_ON (!buffer->pages || !buffer->pages[vmf->pgoff]); pfn =page_to_pfn (ion_buffer_page (buffer->pages[vmf->pgoff])); - ret =vm_insert_pfn (vma, (unsigned long )vmf->virtual_address, pfn); + ret =vm_insert_pfn (vma, vmf->address, pfn);mutex_unlock (&buffer->lock);if (ret)return VM_FAULT_ERROR ;
drivers/staging/lustre/lustre/llite/vvp_io.c +3 -3
@@ -984,7 +984,7 @@ static int vvp_io_kernel_fault(struct vvp_fault_io *cfio)"page %p map %p index %lu flags %lx count %u priv %0lx: got addr %p type NOPAGE\n" , vmf->page, vmf->page->mapping, vmf->page->index, (long )vmf->page->flags,page_count (vmf->page), - page_private(vmf->page), vmf->virtual_address); + page_private(vmf->page), (void *)vmf->address);if (unlikely (!(cfio->ft_flags &VM_FAULT_LOCKED ))) {lock_page (vmf->page); cfio->ft_flags |=VM_FAULT_LOCKED ;
@@ -995,12 +995,12 @@ static int vvp_io_kernel_fault(struct vvp_fault_io *cfio) }if (cfio->ft_flags & (VM_FAULT_SIGBUS |VM_FAULT_SIGSEGV )) { -CDEBUG (D_PAGE ,"got addr %p - SIGBUS\n" , vmf->virtual_address); +CDEBUG (D_PAGE ,"got addr %p - SIGBUS\n" , (void *)vmf->address);return -EFAULT ; }if (cfio->ft_flags &VM_FAULT_OOM ) { -CDEBUG (D_PAGE ,"got addr %p - OOM\n" , vmf->virtual_address); +CDEBUG (D_PAGE ,"got addr %p - OOM\n" , (void *)vmf->address);return -ENOMEM ; }
drivers/xen/privcmd.c +1 -1
@@ -602,7 +602,7 @@ static int privcmd_fault(struct vm_area_struct *vma, struct vm_fault *vmf) {printk (KERN_DEBUG "privcmd_fault: vma=%p %lx-%lx, pgoff=%lx, uv=%p\n" , vma, vma->vm_start, vma->vm_end, - vmf->pgoff, vmf->virtual_address); + vmf->pgoff, (void *)vmf->address);return VM_FAULT_SIGBUS ; }
fs/dax.c +2 -2
@@ -737,7 +737,7 @@ static int dax_insert_mapping(struct address_space *mapping, struct block_device *bdev, sector_t sector, size_t size, void **entryp, struct vm_area_struct *vma, struct vm_fault *vmf) { - unsigned long vaddr = (unsigned long)vmf->virtual_address; + unsigned long vaddr = vmf->address; struct blk_dax_ctl dax = { .sector = sector, .size = size,
@@ -947,7 +947,7 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf, {struct address_space *mapping = vma->vm_file->f_mapping;struct inode *inode = mapping->host; -unsigned long vaddr = (unsigned long )vmf->virtual_address; +unsigned long vaddr = vmf->address;loff_t pos = (loff_t )vmf->pgoff <<PAGE_SHIFT ;sector_t sector;struct iomap iomap = {0 };
include/linux/mm.h +0 -2
@@ -297,8 +297,6 @@ struct vm_fault {gfp_t gfp_mask;/* gfp mask to be used for allocations */ pgoff_t pgoff;/* Logical page offset based on vma */ unsigned long address;/* Faulting virtual address */ -void __user *virtual_address;/* Faulting virtual address masked by -* PAGE_MASK */ pmd_t *pmd;/* Pointer to pmd entry matching * the 'address' */
mm/memory.c +4 -5
@@ -2044,7 +2044,7 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,struct vm_fault vmf;int ret; - vmf.virtual_address = (void __user *)(address &PAGE_MASK ); + vmf.address = address &PAGE_MASK ; vmf.pgoff = page->index; vmf.flags =FAULT_FLAG_WRITE |FAULT_FLAG_MKWRITE ; vmf.gfp_mask =__get_fault_gfp_mask (vma);
@@ -2280,8 +2280,7 @@ static int wp_pfn_shared(struct vm_fault *vmf, pte_t orig_pte)struct vm_fault vmf2 = { .page =NULL , .pgoff =linear_page_index (vma, vmf->address), - .virtual_address = - (void __user *)(vmf->address &PAGE_MASK ), + .address = vmf->address, .flags =FAULT_FLAG_WRITE |FAULT_FLAG_MKWRITE , };int ret;
@@ -2856,7 +2855,7 @@ static int __do_fault(struct vm_fault *vmf, pgoff_t pgoff,struct vm_fault vmf2;int ret; - vmf2.virtual_address = (void __user *)(vmf->address &PAGE_MASK ); + vmf2.address = vmf->address; vmf2.pgoff = pgoff; vmf2.flags = vmf->flags; vmf2.page =NULL ;
@@ -3577,7 +3576,7 @@ static int __handle_mm_fault(struct vm_area_struct *vma, unsigned long address, {struct vm_fault vmf = { .vma = vma, - .address = address, + .address = address &PAGE_MASK , .flags = flags, };struct mm_struct *mm = vma->vm_mm;
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 02/20] mm: Use vmf->address instead of of vmf->virtual_address
Quoted 6 lines · Jan Kara
Every single user of
vmf->virtual_addresstyped that entry to unsigned long before doing anything with it so the type ofvirtual_addressdoes not really provide us any additional safety. Just use maskedvmf->addresswhich already has the appropriate type.Signed-off-by Jan Kara <[email protected]>
Signature · 5 lines
Kirill A. Shutemov _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v5 3/20 mm: Use pgoff in struct vm_fault instead of passing it separately
In reply to Jan Karastruct vm_fault has already pgoff entry. Use it instead of passing pgoff as a separate argument and then assigning it later.
--- mm/khugepaged.c | 1 + mm/memory.c | 35 ++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-)
mm/khugepaged.c +1 -0
@@ -880,6 +880,7 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm, .address = address, .flags = FAULT_FLAG_ALLOW_RETRY, .pmd = pmd, + .pgoff = linear_page_index(vma, address), };/* we only decide to swapin, if there is enough young ptes */
mm/memory.c +18 -17
@@ -2279,7 +2279,7 @@ static int wp_pfn_shared(struct vm_fault *vmf, pte_t orig_pte)if (vma->vm_ops && vma->vm_ops->pfn_mkwrite) {struct vm_fault vmf2 = { .page =NULL , - .pgoff =linear_page_index (vma, vmf->address), + .pgoff = vmf->pgoff, .address = vmf->address, .flags =FAULT_FLAG_WRITE |FAULT_FLAG_MKWRITE , };
@@ -2848,15 +2848,15 @@ static int do_anonymous_page(struct vm_fault *vmf)* released depending on flags and vma->vm_ops->fault() return value. * See filemap_fault() and __lock_page_retry(). */ -static int __do_fault (struct vm_fault *vmf,pgoff_t pgoff, -struct page *cow_page,struct page **page,void **entry) +static int __do_fault (struct vm_fault *vmf,struct page *cow_page, +struct page **page,void **entry) {struct vm_area_struct *vma = vmf->vma;struct vm_fault vmf2;int ret; vmf2.address = vmf->address; - vmf2.pgoff = pgoff; + vmf2.pgoff = vmf->pgoff; vmf2.flags = vmf->flags; vmf2.page =NULL ; vmf2.gfp_mask =__get_fault_gfp_mask (vma);
@@ -3115,9 +3115,10 @@ late_initcall(fault_around_debugfs);* fault_around_pages() value (and therefore to page order). This way it's * easier to guarantee that we don't cross page table boundaries. */ -static int do_fault_around (struct vm_fault *vmf,pgoff_t start_pgoff) +static int do_fault_around (struct vm_fault *vmf) {unsigned long address = vmf->address, nr_pages, mask; +pgoff_t start_pgoff = vmf->pgoff;pgoff_t end_pgoff;int off, ret =0 ;
@@ -3175,7 +3176,7 @@ static int do_fault_around(struct vm_fault *vmf, pgoff_t start_pgoff)return ret; } -static int do_read_fault (struct vm_fault *vmf,pgoff_t pgoff) +static int do_read_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct page *fault_page;
@@ -3187,12 +3188,12 @@ static int do_read_fault(struct vm_fault *vmf, pgoff_t pgoff)* something). */ if (vma->vm_ops->map_pages && fault_around_bytes >>PAGE_SHIFT >1 ) { - ret =do_fault_around (vmf, pgoff); + ret =do_fault_around (vmf);if (ret)return ret; } - ret =__do_fault (vmf, pgoff,NULL , &fault_page,NULL ); + ret =__do_fault (vmf,NULL , &fault_page,NULL );if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY )))return ret;
@@ -3205,7 +3206,7 @@ static int do_read_fault(struct vm_fault *vmf, pgoff_t pgoff)return ret; } -static int do_cow_fault (struct vm_fault *vmf,pgoff_t pgoff) +static int do_cow_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct page *fault_page, *new_page;
@@ -3226,7 +3227,7 @@ static int do_cow_fault(struct vm_fault *vmf, pgoff_t pgoff)return VM_FAULT_OOM ; } - ret =__do_fault (vmf, pgoff, new_page, &fault_page, &fault_entry); + ret =__do_fault (vmf, new_page, &fault_page, &fault_entry);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY ))) goto uncharge_out;
@@ -3241,7 +3242,7 @@ static int do_cow_fault(struct vm_fault *vmf, pgoff_t pgoff)unlock_page (fault_page);put_page (fault_page); }else { -dax_unlock_mapping_entry (vma->vm_file->f_mapping, pgoff); +dax_unlock_mapping_entry (vma->vm_file->f_mapping, vmf->pgoff); }if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY ))) goto uncharge_out;
@@ -3252,7 +3253,7 @@ static int do_cow_fault(struct vm_fault *vmf, pgoff_t pgoff)return ret; } -static int do_shared_fault (struct vm_fault *vmf,pgoff_t pgoff) +static int do_shared_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct page *fault_page;
@@ -3260,7 +3261,7 @@ static int do_shared_fault(struct vm_fault *vmf, pgoff_t pgoff)int dirtied =0 ;int ret, tmp; - ret =__do_fault (vmf, pgoff,NULL , &fault_page,NULL ); + ret =__do_fault (vmf,NULL , &fault_page,NULL );if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY )))return ret;
@@ -3321,16 +3322,15 @@ static int do_shared_fault(struct vm_fault *vmf, pgoff_t pgoff)static int do_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma; -pgoff_t pgoff =linear_page_index (vma, vmf->address);/* The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */ if (!vma->vm_ops->fault)return VM_FAULT_SIGBUS ;if (!(vmf->flags &FAULT_FLAG_WRITE )) -return do_read_fault (vmf, pgoff); +return do_read_fault (vmf);if (!(vma->vm_flags &VM_SHARED )) -return do_cow_fault (vmf, pgoff); -return do_shared_fault (vmf, pgoff); +return do_cow_fault (vmf); +return do_shared_fault (vmf); } static int numa_migrate_prep(struct page *page, struct vm_area_struct *vma,
@@ -3578,6 +3578,7 @@ static int __handle_mm_fault(struct vm_area_struct *vma, unsigned long address, .vma = vma, .address = address & PAGE_MASK, .flags = flags, + .pgoff = linear_page_index(vma, address), };struct mm_struct *mm = vma->vm_mm;pgd_t *pgd;
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 4/20 mm: Use passed vm_fault structure in __do_fault()
In reply to Jan KaraInstead of creating another vm_fault structure, use the one passed to __do_fault() for passing arguments into fault handler.
--- mm/memory.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
mm/memory.c +10 -15
@@ -2852,37 +2852,31 @@ static int __do_fault(struct vm_fault *vmf, struct page *cow_page, struct page **page, void **entry) { struct vm_area_struct *vma = vmf->vma; -struct vm_fault vmf2;int ret; - vmf2.address = vmf->address; - vmf2.pgoff = vmf->pgoff; - vmf2.flags = vmf->flags; - vmf2.page =NULL ; - vmf2.gfp_mask =__get_fault_gfp_mask (vma); - vmf2.cow_page = cow_page; + vmf->cow_page = cow_page; - ret = vma->vm_ops->fault (vma, &vmf2); + ret = vma->vm_ops->fault (vma, vmf);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY )))return ret;if (ret &VM_FAULT_DAX_LOCKED ) { - *entry = vmf2.entry; + *entry = vmf->entry;return ret; } -if (unlikely (PageHWPoison (vmf2.page))) { +if (unlikely (PageHWPoison (vmf->page))) {if (ret &VM_FAULT_LOCKED ) -unlock_page (vmf2.page); -put_page (vmf2.page); +unlock_page (vmf->page); +put_page (vmf->page);return VM_FAULT_HWPOISON ; }if (unlikely (!(ret &VM_FAULT_LOCKED ))) -lock_page (vmf2.page); +lock_page (vmf->page);else -VM_BUG_ON_PAGE (!PageLocked (vmf2.page), vmf2.page); +VM_BUG_ON_PAGE (!PageLocked (vmf->page), vmf->page); - *page = vmf2.page; + *page = vmf->page;return ret; }
@@ -3579,6 +3573,7 @@ static int __handle_mm_fault(struct vm_area_struct *vma, unsigned long address, .address = address & PAGE_MASK, .flags = flags, .pgoff = linear_page_index(vma, address), + .gfp_mask = __get_fault_gfp_mask(vma), };struct mm_struct *mm = vma->vm_mm;pgd_t *pgd;
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 5/20 mm: Trim __do_fault() arguments
In reply to Jan KaraUse vm_fault structure to pass cow_page, page, and entry in and out of the function. That reduces number of __do_fault() arguments from 4 to 1.
--- mm/memory.c | 67 ++++++++++++++++++++++++++----------------------------------- 1 file changed, 29 insertions(+), 38 deletions(-)
mm/memory.c +29 -38
@@ -2848,26 +2848,22 @@ static int do_anonymous_page(struct vm_fault *vmf)* released depending on flags and vma->vm_ops->fault() return value. * See filemap_fault() and __lock_page_retry(). */ -static int __do_fault (struct vm_fault *vmf,struct page *cow_page, -struct page **page,void **entry) +static int __do_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;int ret; - vmf->cow_page = cow_page; - ret = vma->vm_ops->fault (vma, vmf);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY )))return ret; -if (ret &VM_FAULT_DAX_LOCKED ) { - *entry = vmf->entry; +if (ret &VM_FAULT_DAX_LOCKED )return ret; - }if (unlikely (PageHWPoison (vmf->page))) {if (ret &VM_FAULT_LOCKED )unlock_page (vmf->page);put_page (vmf->page); + vmf->page =NULL ;return VM_FAULT_HWPOISON ; }
@@ -2876,7 +2872,6 @@ static int __do_fault(struct vm_fault *vmf, struct page *cow_page,else VM_BUG_ON_PAGE (!PageLocked (vmf->page), vmf->page); - *page = vmf->page;return ret; }
@@ -3173,7 +3168,6 @@ static int do_fault_around(struct vm_fault *vmf)static int do_read_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma; -struct page *fault_page;int ret =0 ;/*
@@ -3187,54 +3181,52 @@ static int do_read_fault(struct vm_fault *vmf)return ret; } - ret =__do_fault (vmf,NULL , &fault_page,NULL ); + ret =__do_fault (vmf);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY )))return ret; - ret |=alloc_set_pte (vmf,NULL , fault_page); + ret |=alloc_set_pte (vmf,NULL , vmf->page);if (vmf->pte)pte_unmap_unlock (vmf->pte, vmf->ptl); -unlock_page (fault_page); +unlock_page (vmf->page);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY ))) -put_page (fault_page); +put_page (vmf->page);return ret; }static int do_cow_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma; -struct page *fault_page, *new_page; -void *fault_entry;struct mem_cgroup *memcg;int ret;if (unlikely (anon_vma_prepare (vma)))return VM_FAULT_OOM ; - new_page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); -if (!new_page) + vmf->cow_page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); +if (!vmf->cow_page)return VM_FAULT_OOM ; -if (mem_cgroup_try_charge (new_page, vma->vm_mm,GFP_KERNEL , +if (mem_cgroup_try_charge (vmf->cow_page, vma->vm_mm,GFP_KERNEL , &memcg, false)) { -put_page (new_page); +put_page (vmf->cow_page);return VM_FAULT_OOM ; } - ret =__do_fault (vmf, new_page, &fault_page, &fault_entry); + ret =__do_fault (vmf);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY ))) goto uncharge_out;if (!(ret &VM_FAULT_DAX_LOCKED )) -copy_user_highpage (new_page, fault_page, vmf->address, vma); -__SetPageUptodate (new_page); +copy_user_highpage (vmf->cow_page, vmf->page, vmf->address, vma); +__SetPageUptodate (vmf->cow_page); - ret |=alloc_set_pte (vmf, memcg, new_page); + ret |=alloc_set_pte (vmf, memcg, vmf->cow_page);if (vmf->pte)pte_unmap_unlock (vmf->pte, vmf->ptl);if (!(ret &VM_FAULT_DAX_LOCKED )) { -unlock_page (fault_page); -put_page (fault_page); +unlock_page (vmf->page); +put_page (vmf->page); }else {dax_unlock_mapping_entry (vma->vm_file->f_mapping, vmf->pgoff); }
@@ -3242,20 +3234,19 @@ static int do_cow_fault(struct vm_fault *vmf) goto uncharge_out;return ret; uncharge_out: -mem_cgroup_cancel_charge (new_page, memcg, false); -put_page (new_page); +mem_cgroup_cancel_charge (vmf->cow_page, memcg, false); +put_page (vmf->cow_page);return ret; }static int do_shared_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma; -struct page *fault_page;struct address_space *mapping;int dirtied =0 ;int ret, tmp; - ret =__do_fault (vmf,NULL , &fault_page,NULL ); + ret =__do_fault (vmf);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY )))return ret;
@@ -3264,26 +3255,26 @@ static int do_shared_fault(struct vm_fault *vmf)* about to become writable */ if (vma->vm_ops->page_mkwrite) { -unlock_page (fault_page); - tmp =do_page_mkwrite (vma, fault_page, vmf->address); +unlock_page (vmf->page); + tmp =do_page_mkwrite (vma, vmf->page, vmf->address);if (unlikely (!tmp || (tmp & (VM_FAULT_ERROR |VM_FAULT_NOPAGE )))) { -put_page (fault_page); +put_page (vmf->page);return tmp; } } - ret |=alloc_set_pte (vmf,NULL , fault_page); + ret |=alloc_set_pte (vmf,NULL , vmf->page);if (vmf->pte)pte_unmap_unlock (vmf->pte, vmf->ptl);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY ))) { -unlock_page (fault_page); -put_page (fault_page); +unlock_page (vmf->page); +put_page (vmf->page);return ret; } -if (set_page_dirty (fault_page)) +if (set_page_dirty (vmf->page)) dirtied =1 ;/* * Take a local copy of the address_space - page.mapping may be zeroed
@@ -3291,8 +3282,8 @@ static int do_shared_fault(struct vm_fault *vmf)* pinned by vma->vm_file's reference. We rely on unlock_page()'s * release semantics to prevent the compiler from undoing this copying. */ - mapping =page_rmapping (fault_page); -unlock_page (fault_page); + mapping =page_rmapping (vmf->page); +unlock_page (vmf->page);if ((dirtied || vma->vm_ops->page_mkwrite) && mapping) {/* * Some device drivers do not set page.mapping but still
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 6/20 mm: Use passed vm_fault structure for in wp_pfn_shared()
In reply to Jan KaraInstead of creating another vm_fault structure, use the one passed to wp_pfn_shared() for passing arguments into pfn_mkwrite handler.
--- mm/memory.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
mm/memory.c +2 -7
@@ -2277,16 +2277,11 @@ static int wp_pfn_shared(struct vm_fault *vmf, pte_t orig_pte)struct vm_area_struct *vma = vmf->vma;if (vma->vm_ops && vma->vm_ops->pfn_mkwrite) { -struct vm_fault vmf2 = { - .page =NULL , - .pgoff = vmf->pgoff, - .address = vmf->address, - .flags =FAULT_FLAG_WRITE |FAULT_FLAG_MKWRITE , - };int ret;pte_unmap_unlock (vmf->pte, vmf->ptl); - ret = vma->vm_ops->pfn_mkwrite (vma, &vmf2); + vmf->flags |=FAULT_FLAG_MKWRITE ; + ret = vma->vm_ops->pfn_mkwrite (vma, vmf);if (ret &VM_FAULT_ERROR )return ret; vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd,
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 7/20 mm: Add orig_pte field into vm_fault
In reply to Jan KaraAdd orig_pte field to vm_fault structure to allow ->page_mkwrite handlers to fully handle the fault. This also allows us to save some passing of extra arguments around.
--- include/linux/mm.h | 4 +-- mm/internal.h | 2 +- mm/khugepaged.c | 7 ++--- mm/memory.c | 82 +++++++++++++++++++++++++++--------------------------- 4 files changed, 47 insertions(+), 48 deletions(-)
include/linux/mm.h +2 -2
@@ -298,8 +298,8 @@ struct vm_fault {pgoff_t pgoff;/* Logical page offset based on vma */ unsigned long address;/* Faulting virtual address */ pmd_t *pmd;/* Pointer to pmd entry matching -* the 'address' -*/ +* the 'address' */ +pte_t orig_pte;/* Value of PTE at the time of fault */ struct page *cow_page;/* Handler may choose to COW */ struct page *page;/* ->fault handlers should return a
mm/internal.h +1 -1
@@ -36,7 +36,7 @@/* Do not use these with a slab allocator */ #define GFP_SLAB_BUG_MASK (__GFP_DMA32|__GFP_HIGHMEM|~__GFP_BITS_MASK) -int do_swap_page (struct vm_fault *vmf,pte_t orig_pte); +int do_swap_page (struct vm_fault *vmf);void free_pgtables (struct mmu_gather *tlb,struct vm_area_struct *start_vma,unsigned long floor,unsigned long ceiling);
mm/khugepaged.c +3 -4
@@ -873,7 +873,6 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm, unsigned long address, pmd_t *pmd, int referenced) { - pte_t pteval; int swapped_in = 0, ret = 0; struct vm_fault vmf = { .vma = vma,
@@ -891,11 +890,11 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm, vmf.pte =pte_offset_map (pmd, address);for (; vmf.address < address +HPAGE_PMD_NR *PAGE_SIZE ; vmf.pte++, vmf.address +=PAGE_SIZE ) { - pteval = *vmf.pte; -if (!is_swap_pte (pteval)) + vmf.orig_pte = *vmf.pte; +if (!is_swap_pte (vmf.orig_pte))continue ; swapped_in++; - ret =do_swap_page (&vmf, pteval); + ret =do_swap_page (&vmf);/* do_swap_page returns VM_FAULT_RETRY with released mmap_sem */ if (ret &VM_FAULT_RETRY ) {
mm/memory.c +41 -41
273 lines not on this page · raw message
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 8/20 mm: Allow full handling of COW faults in ->fault handlers
In reply to Jan KaraTo allow full handling of COW faults add memcg field to struct vm_fault and a return value of ->fault() handler meaning that COW fault is fully handled and memcg charge must not be canceled. This will allow us to remove knowledge about special DAX locking from the generic fault code.
--- include/linux/mm.h | 4 +++- mm/memory.c | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-)
include/linux/mm.h +3 -1
@@ -301,7 +301,8 @@ struct vm_fault {* the 'address' */ pte_t orig_pte;/* Value of PTE at the time of fault */ -struct page *cow_page;/* Handler may choose to COW */ +struct page *cow_page;/* Page handler may use for COW fault */ +struct mem_cgroup *memcg;/* Cgroup cow_page belongs to */ struct page *page;/* ->fault handlers should return a * page here, unless VM_FAULT_NOPAGE * is set (which is also implied by
@@ -1103,6 +1104,7 @@ static inline void clear_page_pfmemalloc(struct page *page)#define VM_FAULT_RETRY 0x0400/* ->fault blocked, must retry */ #define VM_FAULT_FALLBACK 0x0800/* huge page fault failed, fall back to small */ #define VM_FAULT_DAX_LOCKED 0x1000/* ->fault has locked DAX entry */ +#define VM_FAULT_DONE_COW 0x2000/* ->fault has fully handled COW */ #define VM_FAULT_HWPOISON_LARGE_MASK 0xf000/* encodes hpage index for large hwpoison */
mm/memory.c +7 -7
@@ -2848,9 +2848,8 @@ static int __do_fault(struct vm_fault *vmf)int ret; ret = vma->vm_ops->fault (vma, vmf); -if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY ))) -return ret; -if (ret &VM_FAULT_DAX_LOCKED ) +if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY | +VM_FAULT_DAX_LOCKED |VM_FAULT_DONE_COW )))return ret;if (unlikely (PageHWPoison (vmf->page))) {
@@ -3191,7 +3190,6 @@ static int do_read_fault(struct vm_fault *vmf)static int do_cow_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma; -struct mem_cgroup *memcg;int ret;if (unlikely (anon_vma_prepare (vma)))
@@ -3202,7 +3200,7 @@ static int do_cow_fault(struct vm_fault *vmf)return VM_FAULT_OOM ;if (mem_cgroup_try_charge (vmf->cow_page, vma->vm_mm,GFP_KERNEL , - &memcg, false)) { + &vmf->memcg, false)) {put_page (vmf->cow_page);return VM_FAULT_OOM ; }
@@ -3210,12 +3208,14 @@ static int do_cow_fault(struct vm_fault *vmf) ret =__do_fault (vmf);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY ))) goto uncharge_out; +if (ret &VM_FAULT_DONE_COW ) +return ret;if (!(ret &VM_FAULT_DAX_LOCKED ))copy_user_highpage (vmf->cow_page, vmf->page, vmf->address, vma);__SetPageUptodate (vmf->cow_page); - ret |=alloc_set_pte (vmf, memcg, vmf->cow_page); + ret |=alloc_set_pte (vmf, vmf->memcg, vmf->cow_page);if (vmf->pte)pte_unmap_unlock (vmf->pte, vmf->ptl);if (!(ret &VM_FAULT_DAX_LOCKED )) {
@@ -3228,7 +3228,7 @@ static int do_cow_fault(struct vm_fault *vmf) goto uncharge_out;return ret; uncharge_out: -mem_cgroup_cancel_charge (vmf->cow_page, memcg, false); +mem_cgroup_cancel_charge (vmf->cow_page, vmf->memcg, false);put_page (vmf->cow_page);return ret; }
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 9/20 mm: Factor out functionality to finish page faults
In reply to Jan KaraIntroduce function finish_fault() as a helper function for finishing page faults. It is rather thin wrapper around alloc_set_pte() but since we'd want to call this from DAX code or filesystems, it is still useful to avoid some boilerplate code.
--- include/linux/mm.h | 1 + mm/memory.c | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 9 deletions(-)
include/linux/mm.h +1 -0
@@ -620,6 +620,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)int alloc_set_pte (struct vm_fault *vmf,struct mem_cgroup *memcg,struct page *page); +int finish_fault (struct vm_fault *vmf);#endif /*
mm/memory.c +35 -9
68 lines not on this page · raw message
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 10/20 mm: Move handling of COW faults into DAX code
In reply to Jan KaraMove final handling of COW faults from generic code into DAX fault handler. That way generic code doesn't have to be aware of peculiarities of DAX locking so remove that knowledge and make locking functions private to fs/dax.c.
--- fs/dax.c | 61 +++++++++++++++++++++++++---------------------------- include/linux/dax.h | 7 ------ include/linux/mm.h | 9 +------- mm/memory.c | 13 ++++-------- 4 files changed, 34 insertions(+), 56 deletions(-)
fs/dax.c +29 -32
@@ -240,6 +240,23 @@ static void *get_unlocked_mapping_entry(struct address_space *mapping, } } +static void dax_unlock_mapping_entry (struct address_space *mapping, +pgoff_t index) +{ +void *entry, **slot; + +spin_lock_irq (&mapping->tree_lock); + entry =__radix_tree_lookup (&mapping->page_tree, index,NULL , &slot); +if (WARN_ON_ONCE (!entry || !radix_tree_exceptional_entry (entry) || + !slot_locked (mapping, slot))) { +spin_unlock_irq (&mapping->tree_lock); +return ; + } +unlock_slot (mapping, slot); +spin_unlock_irq (&mapping->tree_lock); +dax_wake_mapping_entry_waiter (mapping, index, entry, false); +} +static void put_locked_mapping_entry (struct address_space *mapping,pgoff_t index,void *entry) {
@@ -434,22 +451,6 @@ void dax_wake_mapping_entry_waiter(struct address_space *mapping,__wake_up (wq,TASK_NORMAL , wake_all ?0 :1 , &key); } -void dax_unlock_mapping_entry (struct address_space *mapping,pgoff_t index) -{ -void *entry, **slot; - -spin_lock_irq (&mapping->tree_lock); - entry =__radix_tree_lookup (&mapping->page_tree, index,NULL , &slot); -if (WARN_ON_ONCE (!entry || !radix_tree_exceptional_entry (entry) || - !slot_locked (mapping, slot))) { -spin_unlock_irq (&mapping->tree_lock); -return ; - } -unlock_slot (mapping, slot); -spin_unlock_irq (&mapping->tree_lock); -dax_wake_mapping_entry_waiter (mapping, index, entry, false); -} -/* * Delete exceptional DAX entry at @index from @mapping. Wait for radix tree * entry to get unlocked before deleting it.
@@ -501,10 +502,8 @@ static int dax_load_hole(struct address_space *mapping, void *entry,/* This will replace locked radix tree entry with a hole page */ page =find_or_create_page (mapping, vmf->pgoff, vmf->gfp_mask | __GFP_ZERO); -if (!page) { -put_locked_mapping_entry (mapping, vmf->pgoff, entry); +if (!page)return VM_FAULT_OOM ; - } vmf->page = page;return VM_FAULT_LOCKED ; }
@@ -953,7 +952,7 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf,struct iomap iomap = {0 };unsigned flags =IOMAP_FAULT ;int error, major =0 ; -int locked_status =0 ; +int vmf_ret =0 ;void *entry;/*
@@ -1006,13 +1005,11 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf,if (error) goto finish_iomap; -if (!radix_tree_exceptional_entry (entry)) { - vmf->page = entry; - locked_status =VM_FAULT_LOCKED ; - }else { - vmf->entry = entry; - locked_status =VM_FAULT_DAX_LOCKED ; - } + +__SetPageUptodate (vmf->cow_page); + vmf_ret =finish_fault (vmf); +if (!vmf_ret) + vmf_ret =VM_FAULT_DONE_COW ; goto finish_iomap; }
@@ -1029,7 +1026,7 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf,case IOMAP_UNWRITTEN :case IOMAP_HOLE :if (!(vmf->flags &FAULT_FLAG_WRITE )) { - locked_status =dax_load_hole (mapping, entry, vmf); + vmf_ret =dax_load_hole (mapping, entry, vmf);break ; }/*FALLTHRU*/
@@ -1041,7 +1038,7 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf, finish_iomap:if (ops->iomap_end) { -if (error) { +if (error || (vmf_ret &VM_FAULT_ERROR )) {/* keep previous error */ ops->iomap_end (inode, pos,PAGE_SIZE ,0 , flags, &iomap);
@@ -1051,7 +1048,7 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf, } } unlock_entry: -if (!locked_status || error) +if (vmf_ret !=VM_FAULT_LOCKED || error)put_locked_mapping_entry (mapping, vmf->pgoff, entry); out:if (error == -ENOMEM )
@@ -1059,9 +1056,9 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf,/* -EBUSY is fine, somebody else faulted on the same PTE */ if (error <0 && error != -EBUSY )return VM_FAULT_SIGBUS | major; -if (locked_status) { +if (vmf_ret) {WARN_ON_ONCE (error);/* -EBUSY from ops->iomap_end? */ -return locked_status; +return vmf_ret; }return VM_FAULT_NOPAGE | major; }
include/linux/dax.h +0 -7
@@ -46,7 +46,6 @@ void dax_wake_mapping_entry_waiter(struct address_space *mapping,#ifdef CONFIG_FS_DAX struct page *read_dax_sector (struct block_device *bdev,sector_t n); -void dax_unlock_mapping_entry (struct address_space *mapping,pgoff_t index);int __dax_zero_page_range (struct block_device *bdev,sector_t sector,unsigned int offset,unsigned int length);#else
@@ -55,12 +54,6 @@ static inline struct page *read_dax_sector(struct block_device *bdev, {return ERR_PTR (-ENXIO ); } -/* Shouldn't ever be called when dax is disabled. */ -static inline void dax_unlock_mapping_entry (struct address_space *mapping, -pgoff_t index) -{ -BUG (); -}static inline int __dax_zero_page_range (struct block_device *bdev,sector_t sector,unsigned int offset,unsigned int length) {
include/linux/mm.h +1 -8
@@ -308,12 +308,6 @@ struct vm_fault {* is set (which is also implied by * VM_FAULT_ERROR). */ -void *entry;/* ->fault handler can alternatively -* return locked DAX entry. In that -* case handler should return -* VM_FAULT_DAX_LOCKED and fill in -* entry here. -*/ /* These three entries are valid only while holding ptl lock */ pte_t *pte;/* Pointer to pte entry matching * the 'address'. NULL if the page
@@ -1104,8 +1098,7 @@ static inline void clear_page_pfmemalloc(struct page *page)#define VM_FAULT_LOCKED 0x0200/* ->fault locked the returned page */ #define VM_FAULT_RETRY 0x0400/* ->fault blocked, must retry */ #define VM_FAULT_FALLBACK 0x0800/* huge page fault failed, fall back to small */ -#define VM_FAULT_DAX_LOCKED 0x1000/* ->fault has locked DAX entry */ -#define VM_FAULT_DONE_COW 0x2000/* ->fault has fully handled COW */ +#define VM_FAULT_DONE_COW 0x1000/* ->fault has fully handled COW */ #define VM_FAULT_HWPOISON_LARGE_MASK 0xf000/* encodes hpage index for large hwpoison */
mm/memory.c +4 -9
@@ -2849,7 +2849,7 @@ static int __do_fault(struct vm_fault *vmf) ret = vma->vm_ops->fault (vma, vmf);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY | -VM_FAULT_DAX_LOCKED |VM_FAULT_DONE_COW ))) +VM_FAULT_DONE_COW )))return ret;if (unlikely (PageHWPoison (vmf->page))) {
@@ -3241,17 +3241,12 @@ static int do_cow_fault(struct vm_fault *vmf)if (ret &VM_FAULT_DONE_COW )return ret; -if (!(ret &VM_FAULT_DAX_LOCKED )) -copy_user_highpage (vmf->cow_page, vmf->page, vmf->address, vma); +copy_user_highpage (vmf->cow_page, vmf->page, vmf->address, vma);__SetPageUptodate (vmf->cow_page); ret |=finish_fault (vmf); -if (!(ret &VM_FAULT_DAX_LOCKED )) { -unlock_page (vmf->page); -put_page (vmf->page); - }else { -dax_unlock_mapping_entry (vma->vm_file->f_mapping, vmf->pgoff); - } +unlock_page (vmf->page); +put_page (vmf->page);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE |VM_FAULT_RETRY ))) goto uncharge_out;return ret;
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 10/20] mm: Move handling of COW faults into DAX code
Quoted 7 lines · Jan Kara
Move final handling of COW faults from generic code into DAX fault handler. That way generic code doesn't have to be aware of peculiarities of DAX locking so remove that knowledge and make locking functions private to
fs/dax.c.Signed-off-by Jan Kara <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 11/20 mm: Factor out common parts of write fault handling
In reply to Jan KaraCurrently we duplicate handling of shared write faults in wp_page_reuse() and do_shared_fault(). Factor them out into a common function.
--- mm/memory.c | 78 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 41 deletions(-)
mm/memory.c +37 -41
@@ -2067,6 +2067,41 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page, }/* +* Handle dirtying of a page in shared file mapping on a write fault. +* +* The function expects the page to be locked and unlocks it. +*/ +static void fault_dirty_shared_page (struct vm_area_struct *vma, +struct page *page) +{ +struct address_space *mapping; +bool dirtied; +bool page_mkwrite = vma->vm_ops && vma->vm_ops->page_mkwrite; + + dirtied =set_page_dirty (page); +VM_BUG_ON_PAGE (PageAnon (page), page); +/* +* Take a local copy of the address_space - page.mapping may be zeroed +* by truncate after unlock_page(). The address_space itself remains +* pinned by vma->vm_file's reference. We rely on unlock_page()'s +* release semantics to prevent the compiler from undoing this copying. +*/ + mapping =page_rmapping (page); +unlock_page (page); + +if ((dirtied || page_mkwrite) && mapping) { +/* +* Some device drivers do not set page.mapping +* but still dirty their pages +*/ +balance_dirty_pages_ratelimited (mapping); + } + +if (!page_mkwrite) +file_update_time (vma->vm_file); +} + +/* * Handle write page faults for pages that can be reused in the current vma * * This can happen either due to the mapping being with the VM_SHARED flag,
@@ -2096,28 +2131,11 @@ static inline int wp_page_reuse(struct vm_fault *vmf, struct page *page,pte_unmap_unlock (vmf->pte, vmf->ptl);if (dirty_shared) { -struct address_space *mapping; -int dirtied; -if (!page_mkwrite)lock_page (page); - dirtied =set_page_dirty (page); -VM_BUG_ON_PAGE (PageAnon (page), page); - mapping = page->mapping; -unlock_page (page); +fault_dirty_shared_page (vma, page);put_page (page); - -if ((dirtied || page_mkwrite) && mapping) { -/* -* Some device drivers do not set page.mapping -* but still dirty their pages -*/ -balance_dirty_pages_ratelimited (mapping); - } - -if (!page_mkwrite) -file_update_time (vma->vm_file); }return VM_FAULT_WRITE ;
@@ -3259,8 +3277,6 @@ static int do_cow_fault(struct vm_fault *vmf)static int do_shared_fault (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma; -struct address_space *mapping; -int dirtied =0 ;int ret, tmp; ret =__do_fault (vmf);
@@ -3289,27 +3305,7 @@ static int do_shared_fault(struct vm_fault *vmf)return ret; } -if (set_page_dirty (vmf->page)) - dirtied =1 ; -/* -* Take a local copy of the address_space - page.mapping may be zeroed -* by truncate after unlock_page(). The address_space itself remains -* pinned by vma->vm_file's reference. We rely on unlock_page()'s -* release semantics to prevent the compiler from undoing this copying. -*/ - mapping =page_rmapping (vmf->page); -unlock_page (vmf->page); -if ((dirtied || vma->vm_ops->page_mkwrite) && mapping) { -/* -* Some device drivers do not set page.mapping but still -* dirty their pages -*/ -balance_dirty_pages_ratelimited (mapping); - } - -if (!vma->vm_ops->page_mkwrite) -file_update_time (vma->vm_file); - +fault_dirty_shared_page (vma, vmf->page);return ret; }
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 12/20 mm: Pass vm_fault structure into do_page_mkwrite()
In reply to Jan KaraWe will need more information in the ->page_mkwrite() helper for DAX to be able to fully finish faults there. Pass vm_fault structure to do_page_mkwrite() and use it there so that information propagates properly from upper layers.
--- mm/memory.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
mm/memory.c +10 -12
@@ -2038,20 +2038,17 @@ static gfp_t __get_fault_gfp_mask(struct vm_area_struct *vma)* * We do this without the lock held, so that it can sleep if it needs to. */ -static int do_page_mkwrite (struct vm_area_struct *vma,struct page *page, -unsigned long address) +static int do_page_mkwrite (struct vm_fault *vmf) { -struct vm_fault vmf;int ret; +struct page *page = vmf->page; +unsigned int old_flags = vmf->flags; - vmf.address = address &PAGE_MASK ; - vmf.pgoff = page->index; - vmf.flags =FAULT_FLAG_WRITE |FAULT_FLAG_MKWRITE ; - vmf.gfp_mask =__get_fault_gfp_mask (vma); - vmf.page = page; - vmf.cow_page =NULL ; + vmf->flags =FAULT_FLAG_WRITE |FAULT_FLAG_MKWRITE ; - ret = vma->vm_ops->page_mkwrite (vma, &vmf); + ret = vmf->vma->vm_ops->page_mkwrite (vmf->vma, vmf); +/* Restore original flags so that caller is not surprised */ + vmf->flags = old_flags;if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE )))return ret;if (unlikely (!(ret &VM_FAULT_LOCKED ))) {
@@ -2327,7 +2324,8 @@ static int wp_page_shared(struct vm_fault *vmf, struct page *old_page)int tmp;pte_unmap_unlock (vmf->pte, vmf->ptl); - tmp =do_page_mkwrite (vma, old_page, vmf->address); + vmf->page = old_page; + tmp =do_page_mkwrite (vmf);if (unlikely (!tmp || (tmp & (VM_FAULT_ERROR |VM_FAULT_NOPAGE )))) {put_page (old_page);
@@ -3289,7 +3287,7 @@ static int do_shared_fault(struct vm_fault *vmf)*/ if (vma->vm_ops->page_mkwrite) {unlock_page (vmf->page); - tmp =do_page_mkwrite (vma, vmf->page, vmf->address); + tmp =do_page_mkwrite (vmf);if (unlikely (!tmp || (tmp & (VM_FAULT_ERROR |VM_FAULT_NOPAGE )))) {put_page (vmf->page);
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/20] mm: Pass vm_fault structure into do_page_mkwrite()
Quoted 7 lines · Jan Kara
We will need more information in the ->page_mkwrite() helper for DAX to be able to fully finish faults there. Pass
vm_faultstructure todo_page_mkwrite()and use it there so that information propagates properly from upper layers.Reviewed-by Ross Zwisler <[email protected]>Signed-off-by Jan Kara <[email protected]>
Signature · 5 lines
Kirill A. Shutemov _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v5 13/20 mm: Use vmf->page during WP faults
In reply to Jan KaraSo far we set vmf->page during WP faults only when we needed to pass it to the ->page_mkwrite handler. Set it in all the cases now and use that instead of passing page pointer explicitly around.
--- mm/memory.c | 58 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-)
mm/memory.c +29 -29
@@ -2106,11 +2106,12 @@ static void fault_dirty_shared_page(struct vm_area_struct *vma,* case, all we need to do here is to mark the page as writable and update * any related book-keeping. */ -static inline int wp_page_reuse (struct vm_fault *vmf,struct page *page, +static inline int wp_page_reuse (struct vm_fault *vmf,int page_mkwrite,int dirty_shared) __releases(vmf->ptl) {struct vm_area_struct *vma = vmf->vma; +struct page *page = vmf->page;pte_t entry;/* * Clear the pages cpupid information as the existing
@@ -2154,10 +2155,11 @@ static inline int wp_page_reuse(struct vm_fault *vmf, struct page *page,* held to the old page, as well as updating the rmap. * - In any case, unlock the PTL and drop the reference we took to the old page. */ -static int wp_page_copy (struct vm_fault *vmf,struct page *old_page) +static int wp_page_copy (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct mm_struct *mm = vma->vm_mm; +struct page *old_page = vmf->page;struct page *new_page =NULL ;pte_t entry;int page_copied =0 ;
@@ -2309,26 +2311,25 @@ static int wp_pfn_shared(struct vm_fault *vmf)return 0 ; } } -return wp_page_reuse (vmf,NULL ,0 ,0 ); +return wp_page_reuse (vmf,0 ,0 ); } -static int wp_page_shared (struct vm_fault *vmf,struct page *old_page) +static int wp_page_shared (struct vm_fault *vmf) __releases(vmf->ptl) {struct vm_area_struct *vma = vmf->vma;int page_mkwrite =0 ; -get_page (old_page); +get_page (vmf->page);if (vma->vm_ops && vma->vm_ops->page_mkwrite) {int tmp;pte_unmap_unlock (vmf->pte, vmf->ptl); - vmf->page = old_page; tmp =do_page_mkwrite (vmf);if (unlikely (!tmp || (tmp & (VM_FAULT_ERROR |VM_FAULT_NOPAGE )))) { -put_page (old_page); +put_page (vmf->page);return tmp; }/*
@@ -2340,15 +2341,15 @@ static int wp_page_shared(struct vm_fault *vmf, struct page *old_page) vmf->pte =pte_offset_map_lock (vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl);if (!pte_same (*vmf->pte, vmf->orig_pte)) { -unlock_page (old_page); +unlock_page (vmf->page);pte_unmap_unlock (vmf->pte, vmf->ptl); -put_page (old_page); +put_page (vmf->page);return 0 ; } page_mkwrite =1 ; } -return wp_page_reuse (vmf, old_page, page_mkwrite,1 ); +return wp_page_reuse (vmf, page_mkwrite,1 ); }/*
@@ -2373,10 +2374,9 @@ static int do_wp_page(struct vm_fault *vmf) __releases(vmf->ptl) {struct vm_area_struct *vma = vmf->vma; -struct page *old_page; - old_page =vm_normal_page (vma, vmf->address, vmf->orig_pte); -if (!old_page) { + vmf->page =vm_normal_page (vma, vmf->address, vmf->orig_pte); +if (!vmf->page) {/* * VM_MIXEDMAP !pfn_valid() case, or VM_SOFTDIRTY clear on a * VM_PFNMAP VMA.
@@ -2389,30 +2389,30 @@ static int do_wp_page(struct vm_fault *vmf)return wp_pfn_shared (vmf);pte_unmap_unlock (vmf->pte, vmf->ptl); -return wp_page_copy (vmf, old_page); +return wp_page_copy (vmf); }/* * Take out anonymous pages first, anonymous shared vmas are * not dirty accountable. */ -if (PageAnon (old_page) && !PageKsm (old_page)) { +if (PageAnon (vmf->page) && !PageKsm (vmf->page)) {int total_mapcount; -if (!trylock_page (old_page)) { -get_page (old_page); +if (!trylock_page (vmf->page)) { +get_page (vmf->page);pte_unmap_unlock (vmf->pte, vmf->ptl); -lock_page (old_page); +lock_page (vmf->page); vmf->pte =pte_offset_map_lock (vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl);if (!pte_same (*vmf->pte, vmf->orig_pte)) { -unlock_page (old_page); +unlock_page (vmf->page);pte_unmap_unlock (vmf->pte, vmf->ptl); -put_page (old_page); +put_page (vmf->page);return 0 ; } -put_page (old_page); +put_page (vmf->page); } -if (reuse_swap_page (old_page, &total_mapcount)) { +if (reuse_swap_page (vmf->page, &total_mapcount)) {if (total_mapcount ==1 ) {/* * The page is all ours. Move it to
@@ -2421,24 +2421,24 @@ static int do_wp_page(struct vm_fault *vmf)* Protected against the rmap code by * the page lock. */ -page_move_anon_rmap (old_page, vma); +page_move_anon_rmap (vmf->page, vma); } -unlock_page (old_page); -return wp_page_reuse (vmf, old_page,0 ,0 ); +unlock_page (vmf->page); +return wp_page_reuse (vmf,0 ,0 ); } -unlock_page (old_page); +unlock_page (vmf->page); }else if (unlikely ((vma->vm_flags & (VM_WRITE |VM_SHARED )) == (VM_WRITE |VM_SHARED ))) { -return wp_page_shared (vmf, old_page); +return wp_page_shared (vmf); }/* * Ok, we need to copy. Oh, well.. */ -get_page (old_page); +get_page (vmf->page);pte_unmap_unlock (vmf->pte, vmf->ptl); -return wp_page_copy (vmf, old_page); +return wp_page_copy (vmf); } static void unmap_mapping_range_vma(struct vm_area_struct *vma,
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 14/20 mm: Move part of wp_page_reuse() into the single call site
In reply to Jan Karawp_page_reuse() handles write shared faults which is needed only in wp_page_shared(). Move the handling only into that location to make wp_page_reuse() simpler and avoid a strange situation when we sometimes pass in locked page, sometimes unlocked etc.
--- mm/memory.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
mm/memory.c +12 -15
@@ -2106,8 +2106,7 @@ static void fault_dirty_shared_page(struct vm_area_struct *vma,* case, all we need to do here is to mark the page as writable and update * any related book-keeping. */ -static inline int wp_page_reuse (struct vm_fault *vmf, -int page_mkwrite,int dirty_shared) +static inline void wp_page_reuse (struct vm_fault *vmf) __releases(vmf->ptl) {struct vm_area_struct *vma = vmf->vma;
@@ -2127,16 +2126,6 @@ static inline int wp_page_reuse(struct vm_fault *vmf,if (ptep_set_access_flags (vma, vmf->address, vmf->pte, entry,1 ))update_mmu_cache (vma, vmf->address, vmf->pte);pte_unmap_unlock (vmf->pte, vmf->ptl); - -if (dirty_shared) { -if (!page_mkwrite) -lock_page (page); - -fault_dirty_shared_page (vma, page); -put_page (page); - } - -return VM_FAULT_WRITE ; }/*
@@ -2311,7 +2300,8 @@ static int wp_pfn_shared(struct vm_fault *vmf)return 0 ; } } -return wp_page_reuse (vmf,0 ,0 ); +wp_page_reuse (vmf); +return VM_FAULT_WRITE ; }static int wp_page_shared (struct vm_fault *vmf)
@@ -2349,7 +2339,13 @@ static int wp_page_shared(struct vm_fault *vmf) page_mkwrite =1 ; } -return wp_page_reuse (vmf, page_mkwrite,1 ); +wp_page_reuse (vmf); +if (!page_mkwrite) +lock_page (vmf->page); +fault_dirty_shared_page (vma, vmf->page); +put_page (vmf->page); + +return VM_FAULT_WRITE ; }/*
@@ -2424,7 +2420,8 @@ static int do_wp_page(struct vm_fault *vmf)page_move_anon_rmap (vmf->page, vma); }unlock_page (vmf->page); -return wp_page_reuse (vmf,0 ,0 ); +wp_page_reuse (vmf); +return VM_FAULT_WRITE ; }unlock_page (vmf->page); } else if (unlikely((vma->vm_flags & (VM_WRITE|VM_SHARED)) ==
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 15/20 mm: Provide helper for finishing mkwrite faults
In reply to Jan KaraProvide a helper function for finishing write faults due to PTE being read-only. The helper will be used by DAX to avoid the need of complicating generic MM code with DAX locking specifics.
--- include/linux/mm.h | 1 + mm/memory.c | 67 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 27 deletions(-)
include/linux/mm.h +1 -0
@@ -615,6 +615,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)int alloc_set_pte (struct vm_fault *vmf,struct mem_cgroup *memcg,struct page *page);int finish_fault (struct vm_fault *vmf); +int finish_mkwrite_fault (struct vm_fault *vmf);#endif /*
mm/memory.c +40 -27
95 lines not on this page · raw message
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 16/20 mm: Change return values of finish_mkwrite_fault()
In reply to Jan KaraCurrently finish_mkwrite_fault() returns 0 when PTE got changed before we acquired PTE lock and VM_FAULT_WRITE when we succeeded in modifying the PTE. This is somewhat confusing since 0 generally means success, it is also inconsistent with finish_fault() which returns 0 on success. Change finish_mkwrite_fault() to return 0 on success and VM_FAULT_NOPAGE when PTE changed. Practically, there should be no behavioral difference since we bail out from the fault the same way regardless whether we return 0, VM_FAULT_NOPAGE, or VM_FAULT_WRITE. Also note that VM_FAULT_WRITE has no effect for shared mappings since the only two places that check it - KSM and GUP - care about private mappings only. Generally the meaning of VM_FAULT_WRITE for shared mappings is not well defined and we should probably clean that up.
--- mm/memory.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
mm/memory.c +3 -4
@@ -2299,10 +2299,10 @@ int finish_mkwrite_fault(struct vm_fault *vmf)*/ if (!pte_same (*vmf->pte, vmf->orig_pte)) {pte_unmap_unlock (vmf->pte, vmf->ptl); -return 0 ; +return VM_FAULT_NOPAGE ; }wp_page_reuse (vmf); -return VM_FAULT_WRITE ; +return 0 ; }/*
@@ -2345,8 +2345,7 @@ static int wp_page_shared(struct vm_fault *vmf)return tmp; } tmp =finish_mkwrite_fault (vmf); -if (unlikely (!tmp || (tmp & - (VM_FAULT_ERROR |VM_FAULT_NOPAGE )))) { +if (unlikely (tmp & (VM_FAULT_ERROR |VM_FAULT_NOPAGE ))) {unlock_page (vmf->page);put_page (vmf->page);return tmp;
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 17/20 mm: Export follow_pte()
In reply to Jan KaraDAX will need to implement its own version of page_check_address(). To avoid duplicating page table walking code, export follow_pte() which does what we need.
--- include/linux/mm.h | 2 ++ mm/memory.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/mm.h +2 -0
@@ -1210,6 +1210,8 @@ int copy_page_range(struct mm_struct *dst, struct mm_struct *src, struct vm_area_struct *vma);void unmap_mapping_range (struct address_space *mapping,loff_t const holebegin,loff_t const holelen,int even_cows); +int follow_pte (struct mm_struct *mm,unsigned long address,pte_t **ptepp, +spinlock_t **ptlp);int follow_pfn (struct vm_area_struct *vma,unsigned long address,unsigned long *pfn); int follow_phys(struct vm_area_struct *vma, unsigned long address,
mm/memory.c +2 -2
@@ -3782,8 +3782,8 @@ static int __follow_pte(struct mm_struct *mm, unsigned long address,return -EINVAL ; } -static inline int follow_pte (struct mm_struct *mm,unsigned long address, -pte_t **ptepp,spinlock_t **ptlp) +int follow_pte (struct mm_struct *mm,unsigned long address,pte_t **ptepp, +spinlock_t **ptlp) {int res;
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 18/20 dax: Make cache flushing protected by entry lock
In reply to Jan KaraCurrently, flushing of caches for DAX mappings was ignoring entry lock. So far this was ok (modulo a bug that a difference in entry lock could cause cache flushing to be mistakenly skipped) but in the following patches we will write-protect PTEs on cache flushing and clear dirty tags. For that we will need more exclusion. So do cache flushing under an entry lock. This allows us to remove one lock-unlock pair of mapping->tree_lock as a bonus.
--- fs/dax.c | 61 +++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 22 deletions(-)
fs/dax.c +39 -22
@@ -617,32 +617,50 @@ static int dax_writeback_one(struct block_device *bdev, struct address_space *mapping, pgoff_t index, void *entry) { struct radix_tree_root *page_tree = &mapping->page_tree; -struct radix_tree_node *node;struct blk_dax_ctl dax; -void **slot; +void *entry2, **slot;int ret =0 ; -spin_lock_irq (&mapping->tree_lock);/* -* Regular page slots are stabilized by the page lock even -* without the tree itself locked. These unlocked entries -* need verification under the tree lock. +* A page got tagged dirty in DAX mapping? Something is seriously +* wrong. */ -if (!__radix_tree_lookup (page_tree, index, &node, &slot)) - goto unlock; -if (*slot != entry) - goto unlock; - -/* another fsync thread may have already written back this entry */ -if (!radix_tree_tag_get (page_tree, index,PAGECACHE_TAG_TOWRITE )) - goto unlock; +if (WARN_ON (!radix_tree_exceptional_entry (entry))) +return -EIO ; +spin_lock_irq (&mapping->tree_lock); + entry2 =get_unlocked_mapping_entry (mapping, index, &slot); +/* Entry got punched out / reallocated? */ +if (!entry2 || !radix_tree_exceptional_entry (entry2)) + goto put_unlocked; +/* +* Entry got reallocated elsewhere? No need to writeback. We have to +* compare sectors as we must not bail out due to difference in lockbit +* or entry type. +*/ +if (dax_radix_sector (entry2) !=dax_radix_sector (entry)) + goto put_unlocked;if (WARN_ON_ONCE (dax_is_empty_entry (entry) ||dax_is_zero_entry (entry))) { ret = -EIO ; - goto unlock; + goto put_unlocked; } +/* Another fsync thread may have already written back this entry */ +if (!radix_tree_tag_get (page_tree, index,PAGECACHE_TAG_TOWRITE )) + goto put_unlocked; +/* Lock the entry to serialize with page faults */ + entry =lock_slot (mapping, slot); +/* +* We can clear the tag now but we have to be careful so that concurrent +* dax_writeback_one() calls for the same index cannot finish before we +* actually flush the caches. This is achieved as the calls will look +* at the entry only under tree_lock and once they do that they will +* see the entry locked and wait for it to unlock. +*/ +radix_tree_tag_clear (page_tree, index,PAGECACHE_TAG_TOWRITE ); +spin_unlock_irq (&mapping->tree_lock); +/* * Even if dax_writeback_mapping_range() was given a wbc->range_start * in the middle of a PMD, the 'index' we are given will be aligned to
@@ -652,15 +670,16 @@ static int dax_writeback_one(struct block_device *bdev,*/ dax.sector =dax_radix_sector (entry); dax.size =PAGE_SIZE <<dax_radix_order (entry); -spin_unlock_irq (&mapping->tree_lock);/* * We cannot hold tree_lock while calling dax_map_atomic() because it * eventually calls cond_resched(). */ ret =dax_map_atomic (bdev, &dax); -if (ret <0 ) +if (ret <0 ) { +put_locked_mapping_entry (mapping, index, entry);return ret; + }if (WARN_ON_ONCE (ret < dax.size)) { ret = -EIO ;
@@ -668,15 +687,13 @@ static int dax_writeback_one(struct block_device *bdev, }wb_cache_pmem (dax.addr, dax.size); - -spin_lock_irq (&mapping->tree_lock); -radix_tree_tag_clear (page_tree, index,PAGECACHE_TAG_TOWRITE ); -spin_unlock_irq (&mapping->tree_lock); unmap:dax_unmap_atomic (bdev, &dax); +put_locked_mapping_entry (mapping, index, entry);return ret; - unlock: + put_unlocked: +put_unlocked_mapping_entry (mapping, index, entry2);spin_unlock_irq (&mapping->tree_lock);return ret; }
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 19/20 dax: Protect PTE modification on WP fault by radix tree entry lock
In reply to Jan KaraCurrently PTE gets updated in wp_pfn_shared() after dax_pfn_mkwrite() has released corresponding radix tree entry lock. When we want to writeprotect PTE on cache flush, we need PTE modification to happen under radix tree entry lock to ensure consistent updates of PTE and radix tree (standard faults use page lock to ensure this consistency). So move update of PTE bit into dax_pfn_mkwrite().
--- fs/dax.c | 22 ++++++++++++++++------ mm/memory.c | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-)
fs/dax.c +16 -6
@@ -782,17 +782,27 @@ int dax_pfn_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) {struct file *file = vma->vm_file;struct address_space *mapping = file->f_mapping; -void *entry; +void *entry, **slot;pgoff_t index = vmf->pgoff;spin_lock_irq (&mapping->tree_lock); - entry =get_unlocked_mapping_entry (mapping, index,NULL ); -if (!entry || !radix_tree_exceptional_entry (entry)) - goto out; + entry =get_unlocked_mapping_entry (mapping, index, &slot); +if (!entry || !radix_tree_exceptional_entry (entry)) { +if (entry) +put_unlocked_mapping_entry (mapping, index, entry); +spin_unlock_irq (&mapping->tree_lock); +return VM_FAULT_NOPAGE ; + }radix_tree_tag_set (&mapping->page_tree, index,PAGECACHE_TAG_DIRTY ); -put_unlocked_mapping_entry (mapping, index, entry); -out: + entry =lock_slot (mapping, slot);spin_unlock_irq (&mapping->tree_lock); +/* +* If we race with somebody updating the PTE and finish_mkwrite_fault() +* fails, we don't care. We need to return VM_FAULT_NOPAGE and retry +* the fault in either case. +*/ +finish_mkwrite_fault (vmf); +put_locked_mapping_entry (mapping, index, entry);return VM_FAULT_NOPAGE ; }EXPORT_SYMBOL_GPL (dax_pfn_mkwrite);
mm/memory.c +1 -1
@@ -2319,7 +2319,7 @@ static int wp_pfn_shared(struct vm_fault *vmf)pte_unmap_unlock (vmf->pte, vmf->ptl); vmf->flags |=FAULT_FLAG_MKWRITE ; ret = vma->vm_ops->pfn_mkwrite (vma, vmf); -if (ret &VM_FAULT_ERROR ) +if (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE ))return ret;return finish_mkwrite_fault (vmf); }
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v5 20/20 dax: Clear dirty entry tags on cache flush
In reply to Jan KaraCurrently we never clear dirty tags in DAX mappings and thus address ranges to flush accumulate. Now that we have locking of radix tree entries, we have all the locking necessary to reliably clear the radix tree dirty tag when flushing caches for corresponding address range. Similarly to page_mkclean() we also have to write-protect pages to get a page fault when the page is next written to so that we can mark the entry dirty again.
--- fs/dax.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
fs/dax.c +64 -0
@@ -31,6 +31,7 @@#include <linux/vmstat.h> #include <linux/pfn_t.h> #include <linux/sizes.h> +#include <linux/mmu_notifier.h> #include <linux/iomap.h> #include "internal.h"
@@ -613,6 +614,59 @@ static void *dax_insert_mapping_entry(struct address_space *mapping,return new_entry; } +static inline unsigned long +pgoff_address (pgoff_t pgoff,struct vm_area_struct *vma) +{ +unsigned long address; + + address = vma->vm_start + ((pgoff - vma->vm_pgoff) <<PAGE_SHIFT ); +VM_BUG_ON_VMA (address < vma->vm_start || address >= vma->vm_end, vma); +return address; +} + +/* Walk all mappings of a given index of a file and writeprotect them */ +static void dax_mapping_entry_mkclean (struct address_space *mapping, +pgoff_t index,unsigned long pfn) +{ +struct vm_area_struct *vma; +pte_t *ptep; +pte_t pte; +spinlock_t *ptl; +bool changed; + +i_mmap_lock_read (mapping); + vma_interval_tree_foreach(vma, &mapping->i_mmap, index, index) { +unsigned long address; + +cond_resched (); + +if (!(vma->vm_flags &VM_SHARED )) +continue ; + + address =pgoff_address (index, vma); + changed = false; +if (follow_pte (vma->vm_mm, address, &ptep, &ptl)) +continue ; +if (pfn !=pte_pfn (*ptep)) + goto unlock; +if (!pte_dirty (*ptep) && !pte_write (*ptep)) + goto unlock; + +flush_cache_page (vma, address, pfn); + pte =ptep_clear_flush (vma, address, ptep); + pte =pte_wrprotect (pte); + pte =pte_mkclean (pte); +set_pte_at (vma->vm_mm, address, ptep, pte); + changed = true; +unlock: +pte_unmap_unlock (ptep, ptl); + +if (changed) +mmu_notifier_invalidate_page (vma->vm_mm, address); + } +i_mmap_unlock_read (mapping); +} +static int dax_writeback_one (struct block_device *bdev,struct address_space *mapping,pgoff_t index,void *entry) {
@@ -686,7 +740,17 @@ static int dax_writeback_one(struct block_device *bdev, goto unmap; } +dax_mapping_entry_mkclean (mapping, index,pfn_t_to_pfn (dax.pfn));wb_cache_pmem (dax.addr, dax.size); +/* +* After we have flushed the cache, we can clear the dirty tag. There +* cannot be new dirty data in the pfn after the flush has completed as +* the pfn mappings are writeprotected and fault waits for mapping +* entry lock. +*/ +spin_lock_irq (&mapping->tree_lock); +radix_tree_tag_clear (page_tree, index,PAGECACHE_TAG_DIRTY ); +spin_unlock_irq (&mapping->tree_lock); unmap:dax_unmap_atomic (bdev, &dax);put_locked_mapping_entry (mapping, index, entry);
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>