dax: Clear dirty bits after flushing caches
Subsystems (36)
Jan Kara
maintainerv4 cover dax: Clear dirty bits after flushing caches
Hello,
this is the fourth revision of my patches to clear dirty bits from radix tree of DAX inodes when caches for corresponding pfns have been flushed. This patch set is significantly larger than the previous version because I'm changing how ->fault, ->page_mkwrite, and ->pfn_mkwrite handlers may choose to handle the fault so that we don't have to leak details about DAX locking into the generic code. 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 be really like feedback from mm folks whether such changes to fault handling code are fine or what they'd do differently.
The patches are based on 4.9-rc1 + Ross' DAX PMD page fault series [1] + 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] http://www.spinics.net/lists/linux-mm/msg115247.html
[2] Posted an hour ago - look for "ext4: Convert ext4 DAX IO to iomap framework"
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 1/20 mm: Change type of vmf->virtual_address
Every single user of vmf->virtual_address typed that entry to unsigned long before doing anything with it. So just change the type of that entry to unsigned long immediately.
--- arch/powerpc/platforms/cell/spufs/file.c | 4 ++-- arch/x86/entry/vdso/vma.c | 4 ++-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/mspec.c | 2 +- drivers/dax/dax.c | 2 +- drivers/gpu/drm/armada/armada_gem.c | 2 +- drivers/gpu/drm/drm_vm.c | 9 ++++----- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 7 +++---- drivers/gpu/drm/exynos/exynos_drm_gem.c | 5 ++--- drivers/gpu/drm/gma500/framebuffer.c | 2 +- drivers/gpu/drm/gma500/gem.c | 5 ++--- drivers/gpu/drm/i915/i915_gem.c | 5 ++--- drivers/gpu/drm/msm/msm_gem.c | 7 +++---- drivers/gpu/drm/omapdrm/omap_gem.c | 17 +++++++---------- 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 | 2 +- drivers/misc/sgi-gru/grumain.c | 2 +- drivers/staging/android/ion/ion.c | 2 +- drivers/staging/lustre/lustre/llite/vvp_io.c | 8 +++++--- drivers/xen/privcmd.c | 2 +- fs/dax.c | 4 ++-- include/linux/mm.h | 2 +- mm/memory.c | 7 +++---- 27 files changed, 55 insertions(+), 65 deletions(-)
arch/powerpc/platforms/cell/spufs/file.c +2 -2
@@ -236,7 +236,7 @@ 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 address = vmf->virtual_address;unsigned long pfn, offset; offset = vmf->pgoff <<PAGE_SHIFT ;
@@ -355,7 +355,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, +vm_insert_pfn (vma, vmf->virtual_address, (area + offset) >>PAGE_SHIFT );spu_context_trace (spufs_ps_fault__insert, ctx, ctx->spu); }
arch/x86/entry/vdso/vma.c +2 -2
@@ -157,7 +157,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->virtual_address,__pa_symbol (&__vvar_page) >>PAGE_SHIFT ); }else if (sym_offset == image->sym_pvclock_page) { struct pvclock_vsyscall_time_info *pvti =
@@ -165,7 +165,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->virtual_address,__pa (pvti) >>PAGE_SHIFT ); } }
drivers/char/agp/alpha-agp.c +1 -1
@@ -19,7 +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 + dma_addr = vmf->virtual_address - vma->vm_start + agp->aperture.bus_base; pa = agp->ops->translate (agp, dma_addr);
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->virtual_address, pfn);return VM_FAULT_NOPAGE ; }
drivers/dax/dax.c +1 -1
@@ -381,7 +381,7 @@ 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; +unsigned long vaddr = vmf->virtual_address;struct device *dev = dax_dev->dev;struct dax_region *dax_region;int rc =VM_FAULT_SIGBUS ;
drivers/gpu/drm/armada/armada_gem.c +1 -1
@@ -17,7 +17,7 @@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 addr = vmf->virtual_address;unsigned long pfn = obj->phys_addr >>PAGE_SHIFT ;int ret;
drivers/gpu/drm/drm_vm.c +4 -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->virtual_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->virtual_address - vma->vm_start; i = (unsigned long )map->handle + offset; page =vmalloc_to_page ((void *)i);if (!page)
@@ -301,7 +300,7 @@ 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->virtual_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 +336,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->virtual_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->virtual_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->virtual_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->virtual_address, page); out:switch (ret) {
drivers/gpu/drm/exynos/exynos_drm_gem.c +2 -3
@@ -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->virtual_address - vma->vm_start) >>PAGE_SHIFT ;if (page_offset >= (exynos_gem->size >>PAGE_SHIFT )) {DRM_ERROR ("invalid page offset\n" );
@@ -465,7 +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, + ret =vm_insert_mixed (vma, vmf->virtual_address,__pfn_to_pfn_t (pfn,PFN_DEV )); out:
drivers/gpu/drm/gma500/framebuffer.c +1 -1
@@ -126,7 +126,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->virtual_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->virtual_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->virtual_address, pfn); fail:mutex_unlock (&dev_priv->mmap_mutex);
drivers/gpu/drm/i915/i915_gem.c +2 -3
@@ -2020,8 +2020,7 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)intel_runtime_pm_get (dev_priv);/* We don't use vmf->pgoff since that has the fake offset */ - page_offset = ((unsigned long )vmf->virtual_address - vma->vm_start) >> -PAGE_SHIFT ; + page_offset = (vmf->virtual_address - vma->vm_start) >>PAGE_SHIFT ; ret =i915_mutex_lock_interruptible (dev);if (ret)
@@ -2112,7 +2111,7 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) obj->fault_mappable = true; }else ret =vm_insert_pfn (vma, - (unsigned long )vmf->virtual_address, + vmf->virtual_address, pfn + page_offset); } unpin:
drivers/gpu/drm/msm/msm_gem.c +3 -4
@@ -225,15 +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->virtual_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->virtual_address, pfn, pfn <<PAGE_SHIFT ); - ret =vm_insert_mixed (vma, (unsigned long )vmf->virtual_address, + ret =vm_insert_mixed (vma, vmf->virtual_address,__pfn_to_pfn_t (pfn,PFN_DEV )); out_unlock:
drivers/gpu/drm/omapdrm/omap_gem.c +7 -10
@@ -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->virtual_address - vma->vm_start) >>PAGE_SHIFT ;if (omap_obj->pages) {omap_gem_cpu_sync (obj, pgoff);
@@ -407,10 +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->virtual_address, pfn, pfn <<PAGE_SHIFT ); -return vm_insert_mixed (vma, (unsigned long )vmf->virtual_address, +return vm_insert_mixed (vma, vmf->virtual_address,__pfn_to_pfn_t (pfn,PFN_DEV )); }
@@ -425,7 +424,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 +444,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->virtual_address - vma->vm_start) >>PAGE_SHIFT ;/* * Actual address we start mapping at is rounded down to previous slot
@@ -501,12 +499,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->virtual_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->virtual_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->virtual_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->virtual_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->virtual_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->virtual_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->virtual_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
@@ -436,13 +436,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->virtual_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->virtual_address); vmf->page = page;return 0 ;
drivers/misc/cxl/context.c +1 -1
@@ -117,7 +117,7 @@ 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; +unsigned long address = vmf->virtual_address;u64 area, offset; offset = vmf->pgoff <<PAGE_SHIFT ;
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->virtual_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
@@ -1022,7 +1022,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->virtual_address, pfn);mutex_unlock (&buffer->lock);if (ret)return VM_FAULT_ERROR ;
drivers/staging/lustre/lustre/llite/vvp_io.c +5 -3
@@ -1002,7 +1002,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->virtual_address);if (unlikely (!(cfio->ft_flags &VM_FAULT_LOCKED ))) {lock_page (vmf->page); cfio->ft_flags |=VM_FAULT_LOCKED ;
@@ -1013,12 +1013,14 @@ 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->virtual_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->virtual_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->virtual_address);return VM_FAULT_SIGBUS ; }
fs/dax.c +2 -2
@@ -794,7 +794,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->virtual_address; struct blk_dax_ctl dax = { .sector = sector, .size = size,
@@ -832,7 +832,7 @@ int dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf,struct inode *inode = mapping->host;void *entry;struct buffer_head bh; -unsigned long vaddr = (unsigned long )vmf->virtual_address; +unsigned long vaddr = vmf->virtual_address;unsigned blkbits = inode->i_blkbits;sector_t block;pgoff_t size;
include/linux/mm.h +1 -1
@@ -295,7 +295,7 @@ struct vm_fault {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 virtual_address;/* Faulting virtual address */ struct page *cow_page;/* Handler may choose to COW */ struct page *page;/* ->fault handlers should return a
mm/memory.c +3 -4
@@ -2040,7 +2040,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.virtual_address = address &PAGE_MASK ; vmf.pgoff = page->index; vmf.flags =FAULT_FLAG_WRITE |FAULT_FLAG_MKWRITE ; vmf.gfp_mask =__get_fault_gfp_mask (vma);
@@ -2275,8 +2275,7 @@ static int wp_pfn_shared(struct fault_env *fe, pte_t orig_pte)struct vm_fault vmf = { .page =NULL , .pgoff =linear_page_index (vma, fe->address), - .virtual_address = - (void __user *)(fe->address &PAGE_MASK ), + .virtual_address = fe->address &PAGE_MASK , .flags =FAULT_FLAG_WRITE |FAULT_FLAG_MKWRITE , };int ret;
@@ -2850,7 +2849,7 @@ static int __do_fault(struct fault_env *fe, pgoff_t pgoff,struct vm_fault vmf;int ret; - vmf.virtual_address = (void __user *)(fe->address &PAGE_MASK ); + vmf.virtual_address = fe->address &PAGE_MASK ; vmf.pgoff = pgoff; vmf.flags = fe->flags; vmf.page =NULL ;
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: Change type of vmf->virtual_address
Quoted 5 lines · Jan Kara
Every single user of
vmf->virtual_addresstyped that entry to unsigned long before doing anything with it. So just change the type of that entry to unsigned long immediately.Signed-off-by Jan Kara <[email protected]>
Signature · 7 lines
Kirill A. Shutemov -- 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 v4 1/21 mm: Join struct fault_env and vm_fault
In reply to Jan KaraCurrently 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
@@ -557,7 +557,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
@@ -2101,7 +2095,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
@@ -2211,12 +2211,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;
@@ -2272,11 +2272,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;
@@ -2286,7 +2286,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/21] mm: Join struct fault_env and vm_fault
Quoted 8 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.
What about just reference fault_env from vm_fault? We don't always need vm_fault where we nee fault_env. It may save space on stack for some codepaths.
Signature · 7 lines
Kirill A. Shutemov -- 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
maintainerRe: [PATCH 01/21] mm: Join struct fault_env and vm_fault
Quoted 10 lines · Kirill A. Shutemov
Quoted 8 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.
Quoted 3 lines
What about just reference
fault_envfromvm_fault? We don't always needvm_faultwhere we neefault_env. It may save space on stack for some codepaths.
I was considering that as well but there is some duplication between those two which I'd prefer to avoid and you would need both structures for the fault handler which you eventually end up calling anyway (and that is very likely the most stack-demanding path) so maximum stack consumption would likely be even slightly higher.
Honza
Signature · 8 lines
Jan Kara <[email protected]> SUSE Labs, CR -- 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 2/20 mm: Join struct fault_env and vm_fault
In reply to Jan KaraCurrently 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
@@ -549,7 +549,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 @@ out:* 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,
@@ -138,7 +138,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;
@@ -203,7 +203,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 */ -unsigned long virtual_address;/* Faulting virtual address */ +unsigned long address;/* Faulting virtual address */ +unsigned long 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
@@ -2103,7 +2097,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
@@ -2193,12 +2193,12 @@ page_not_uptodate: }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;
@@ -2254,11 +2254,11 @@ repeat: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;
@@ -2268,7 +2268,7 @@ skip: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,210 lines not on this page · raw message
mm/nommu.c +1 -1
@@ -1809,7 +1809,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>
Jan Kara
maintainerPATCH v4 2/21 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 | 4 ++-- arch/x86/entry/vdso/vma.c | 4 ++-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/mspec.c | 2 +- drivers/dax/dax.c | 2 +- drivers/gpu/drm/armada/armada_gem.c | 2 +- drivers/gpu/drm/drm_vm.c | 11 ++++++----- 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 | 2 +- drivers/gpu/drm/msm/msm_gem.c | 7 +++---- 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 | 2 +- drivers/misc/sgi-gru/grumain.c | 2 +- drivers/staging/android/ion/ion.c | 2 +- drivers/staging/lustre/lustre/llite/vvp_io.c | 9 ++++++--- drivers/xen/privcmd.c | 2 +- fs/dax.c | 4 ++-- include/linux/mm.h | 2 -- mm/memory.c | 7 +++---- 27 files changed, 59 insertions(+), 65 deletions(-)
arch/powerpc/platforms/cell/spufs/file.c +2 -2
@@ -236,7 +236,7 @@ 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 address = vmf->address &PAGE_MASK ;unsigned long pfn, offset; offset = vmf->pgoff <<PAGE_SHIFT ;
@@ -355,7 +355,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, +vm_insert_pfn (vma, vmf->address &PAGE_MASK , (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 &PAGE_MASK ,__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 &PAGE_MASK ,__pa (pvti) >>PAGE_SHIFT ); } }
drivers/char/agp/alpha-agp.c +1 -1
@@ -19,7 +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 + dma_addr = (vmf->address &PAGE_MASK ) - vma->vm_start + agp->aperture.bus_base; pa = agp->ops->translate (agp, dma_addr);
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 &PAGE_MASK , pfn);return VM_FAULT_NOPAGE ; }
drivers/dax/dax.c +1 -1
@@ -328,7 +328,7 @@ 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; +unsigned long vaddr = vmf->address &PAGE_MASK ;struct device *dev = &dax_dev->dev;struct dax_region *dax_region;int rc =VM_FAULT_SIGBUS ;
drivers/gpu/drm/armada/armada_gem.c +1 -1
@@ -17,7 +17,7 @@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 addr = vmf->address &PAGE_MASK ;unsigned long pfn = obj->phys_addr >>PAGE_SHIFT ;int ret;
drivers/gpu/drm/drm_vm.c +6 -5
@@ -124,8 +124,8 @@ 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 &PAGE_MASK ) - + vma->vm_start;resource_size_t baddr = map->offset + offset;struct drm_agp_mem *agpmem;struct page *page;
@@ -195,7 +195,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 &PAGE_MASK ) - vma->vm_start; i = (unsigned long )map->handle + offset; page =vmalloc_to_page ((void *)i);if (!page)
@@ -301,7 +301,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 &PAGE_MASK ) - 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 +338,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 &PAGE_MASK ) - 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 &PAGE_MASK ) - 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_MASK ),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_MASK , page); out:switch (ret) {
drivers/gpu/drm/exynos/exynos_drm_gem.c +3 -3
@@ -455,8 +455,8 @@ 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 &PAGE_MASK ) - vma->vm_start) >> +PAGE_SHIFT ;if (page_offset >= (exynos_gem->size >>PAGE_SHIFT )) {DRM_ERROR ("invalid page offset\n" );
@@ -465,7 +465,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, + ret =vm_insert_mixed (vma, vmf->address &PAGE_MASK ,__pfn_to_pfn_t (pfn,PFN_DEV )); out:
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 &PAGE_MASK ) - (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 &PAGE_MASK )- 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 &PAGE_MASK , pfn); fail:mutex_unlock (&dev_priv->mmap_mutex);
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -1763,7 +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_offset = ((vmf->address &PAGE_MASK )- area->vm_start) >>PAGE_SHIFT ;trace_i915_gem_object_fault (obj, page_offset, true, write);
drivers/gpu/drm/msm/msm_gem.c +3 -4
@@ -225,15 +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 &PAGE_MASK )- 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 &PAGE_MASK ), pfn, pfn <<PAGE_SHIFT ); - ret =vm_insert_mixed (vma, (unsigned long )vmf->virtual_address, + ret =vm_insert_mixed (vma, vmf->address &PAGE_MASK ,__pfn_to_pfn_t (pfn,PFN_DEV )); out_unlock:
drivers/gpu/drm/omapdrm/omap_gem.c +9 -11
@@ -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 &PAGE_MASK )- vma->vm_start) >>PAGE_SHIFT ;if (omap_obj->pages) {omap_gem_cpu_sync (obj, pgoff);
@@ -407,10 +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 &PAGE_MASK ), pfn, pfn <<PAGE_SHIFT ); -return vm_insert_mixed (vma, (unsigned long )vmf->virtual_address, +return vm_insert_mixed (vma, vmf->address &PAGE_MASK ,__pfn_to_pfn_t (pfn,PFN_DEV )); }
@@ -425,7 +424,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 +444,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 &PAGE_MASK ) - vma->vm_start) >>PAGE_SHIFT ;/* * Actual address we start mapping at is rounded down to previous slot
@@ -457,7 +455,8 @@ 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 &PAGE_MASK ) - + ((pgoff - base_pgoff) <<PAGE_SHIFT ); entry = &priv->usergart[fmt].entry[priv->usergart[fmt].last];
@@ -501,12 +500,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 &PAGE_MASK ), 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 &PAGE_MASK )- 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_MASK , 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 &PAGE_MASK ;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 &PAGE_MASK )- 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_MASK , 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 &PAGE_MASK ;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 &PAGE_MASK , 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 &PAGE_MASK ); vmf->page = page;return 0 ;
drivers/misc/cxl/context.c +1 -1
@@ -117,7 +117,7 @@ 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; +unsigned long address = vmf->address &PAGE_MASK ;u64 area, offset; offset = vmf->pgoff <<PAGE_SHIFT ;
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 &PAGE_MASK ;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 &PAGE_MASK , pfn);mutex_unlock (&buffer->lock);if (ret)return VM_FAULT_ERROR ;
drivers/staging/lustre/lustre/llite/vvp_io.c +6 -3
@@ -984,7 +984,8 @@ 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 & PAGE_MASK));if (unlikely (!(cfio->ft_flags &VM_FAULT_LOCKED ))) {lock_page (vmf->page); cfio->ft_flags |=VM_FAULT_LOCKED ;
@@ -995,12 +996,14 @@ 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 &PAGE_MASK ));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 &PAGE_MASK ));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 &PAGE_MASK ));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 & PAGE_MASK; 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 &PAGE_MASK ;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 +3 -4
@@ -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; 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 ;
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/21] mm: Use vmf->address instead of of vmf->virtual_address
include/linux/mm.h struct vm_fault { · line 302
Quoted 13 lines · Jan Kara
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' */
We have a pmd field currently?
In [PATCH 01/20] mm: Change type of vmf->virtual_address we see
[1] __user * gone,
[2] no field of address added
and doubt stray merge occurred.
btw, s:01/20:01/21: in subject line?
Hillf
include/linux/mm.h struct vm_fault { · line 301
Quoted 13 lines
include/linux/mm.h +1
-1@@ -295,7 +295,7 @@ struct vm_fault {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 virtual_address;/* Faulting virtual address */ struct page *cow_page;/* Handler may choose to COW */ struct page *page;/* ->fault handlers should return a
--
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
maintainerRe: [PATCH 02/21] mm: Use vmf->address instead of of vmf->virtual_address
Quoted 16 lines · Hillf Danton
include/linux/mm.h struct vm_fault { · line 302
Quoted 13 lines · Jan Kara
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' */ We have a pmd field currently?
Quoted 6 lines
In [PATCH 01/20] mm: Change type of
vmf->virtual_addresswe see
[1]__user* gone,
[2] no field of address added
and doubt stray merge occurred.btw, s:01/20:01/21: in subject line?
Sorry, I had old version of the series in the directory so things got messed up. I'll resend the series. Thanks for having a look.
Honza
Signature · 8 lines
Jan Kara <[email protected]> SUSE Labs, CR -- 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 v4 3/21 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, .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 v4 4/21 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, .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 v4 5/21 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 | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-)
mm/memory.c +23 -30
@@ -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,24 +3181,23 @@ 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 page *new_page;struct mem_cgroup *memcg;int ret;
@@ -3221,20 +3214,21 @@ static int do_cow_fault(struct vm_fault *vmf)return VM_FAULT_OOM ; } - ret =__do_fault (vmf, new_page, &fault_page, &fault_entry); + vmf->cow_page = new_page; + 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); +copy_user_highpage (new_page, vmf->page, vmf->address, vma);__SetPageUptodate (new_page); ret |=alloc_set_pte (vmf, memcg, new_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); }
@@ -3250,12 +3244,11 @@ 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 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 +3257,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 +3284,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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v4 6/21 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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v4 7/21 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 v4 8/21 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 | 8 +++++--- 2 files changed, 8 insertions(+), 4 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 +5 -3
@@ -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))) {
@@ -3209,9 +3208,12 @@ static int do_cow_fault(struct vm_fault *vmf) } vmf->cow_page = new_page; + vmf->memcg = memcg; 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 (new_page, vmf->page, vmf->address, 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 v4 9/21 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 v4 10/21 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 | 58 +++++++++++++++++++++++++++-------------------------- include/linux/dax.h | 7 ------- include/linux/mm.h | 9 +-------- mm/memory.c | 14 ++++--------- 4 files changed, 35 insertions(+), 53 deletions(-)
fs/dax.c +30 -28
@@ -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.
@@ -953,7 +954,7 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf,struct iomap iomap = {0 };unsigned flags =0 ;int error, major =0 ; -int locked_status =0 ; +int vmf_ret =0 ;void *entry;/*
@@ -1006,13 +1007,14 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf,if (error) goto finish_iomap; -if (!radix_tree_exceptional_entry (entry)) { + +__SetPageUptodate (vmf->cow_page); +if (!radix_tree_exceptional_entry (entry)) vmf->page = entry; - locked_status =VM_FAULT_LOCKED ; - }else { - vmf->entry = entry; - locked_status =VM_FAULT_DAX_LOCKED ; - } + vmf_ret =finish_fault (vmf); +if (!vmf_ret) + vmf_ret =VM_FAULT_DONE_COW ; + vmf->page =NULL ; goto finish_iomap; }
@@ -1029,7 +1031,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 +1043,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 +1053,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 +1061,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 -10
@@ -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))) {
@@ -3245,17 +3245,11 @@ 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 (new_page, vmf->page, vmf->address, vma); +copy_user_highpage (new_page, vmf->page, vmf->address, vma);__SetPageUptodate (new_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>
Jan Kara
maintainerPATCH v4 11/21 mm: Remove unnecessary vma->vm_ops check
In reply to Jan KaraWe don't check whether vma->vm_ops is NULL in do_shared_fault() so there's hardly any point in checking it in wp_page_shared() or wp_pfn_shared() which get called only for shared file mappings as well.
--- mm/memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory.c +2 -2
@@ -2275,7 +2275,7 @@ static int wp_pfn_shared(struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma; -if (vma->vm_ops && vma->vm_ops->pfn_mkwrite) { +if (vma->vm_ops->pfn_mkwrite) {int ret;pte_unmap_unlock (vmf->pte, vmf->ptl);
@@ -2305,7 +2305,7 @@ static int wp_page_shared(struct vm_fault *vmf, struct page *old_page)get_page (old_page); -if (vma->vm_ops && vma->vm_ops->page_mkwrite) { +if (vma->vm_ops->page_mkwrite) {int tmp;pte_unmap_unlock (vmf->pte, vmf->ptl);
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 6/20 mm: Use pass 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
@@ -2273,16 +2273,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, - .virtual_address = vmf->address &PAGE_MASK , - .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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v4 12/21 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->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 ;
@@ -3262,8 +3280,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);
@@ -3292,27 +3308,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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v4 13/21 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 | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
mm/memory.c +7 -12
@@ -2038,20 +2038,14 @@ 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; - vmf.address = address; - 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);if (unlikely (ret & (VM_FAULT_ERROR |VM_FAULT_NOPAGE )))return ret;if (unlikely (!(ret &VM_FAULT_LOCKED ))) {
@@ -2327,7 +2321,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);
@@ -3292,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>
Jan Kara
maintainerPATCH 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
@@ -1224,6 +1224,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
@@ -3763,8 +3763,8 @@ out: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 v4 14/21 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
@@ -2103,11 +2103,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
@@ -2151,10 +2152,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 ;
@@ -2306,26 +2308,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->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; }/*
@@ -2337,15 +2338,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 ); }/*
@@ -2370,10 +2371,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.
@@ -2386,30 +2386,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
@@ -2418,24 +2418,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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH 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 | 66 +++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 24 deletions(-)
fs/dax.c +42 -24
@@ -672,43 +672,63 @@ 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; -int type =RADIX_DAX_TYPE (entry); -struct radix_tree_node *node;struct blk_dax_ctl dax; -void **slot; +void *entry2, **slot;int ret =0 ; +int type; -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_unlock; +/* +* 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 (RADIX_DAX_SECTOR (entry2) !=RADIX_DAX_SECTOR (entry)) + goto put_unlock; + type =RADIX_DAX_TYPE (entry2);if (WARN_ON_ONCE (type !=RADIX_DAX_PTE && type !=RADIX_DAX_PMD )) { ret = -EIO ; - goto unlock; + goto put_unlock; } +/* Another fsync thread may have already written back this entry */ +if (!radix_tree_tag_get (page_tree, index,PAGECACHE_TAG_TOWRITE )) + goto put_unlock; +/* 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); + dax.sector =RADIX_DAX_SECTOR (entry); dax.size = (type ==RADIX_DAX_PMD ?PMD_SIZE :PAGE_SIZE ); -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 ;
@@ -716,15 +736,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: +unmap:dax_unmap_atomic (bdev, &dax); +put_locked_mapping_entry (mapping, index, entry);return ret; - unlock: +put_unlock: +put_unlocked_mapping_entry (mapping, index, entry2);spin_unlock_irq (&mapping->tree_lock);return ret; }
Signature · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v4 15/21 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
@@ -2103,8 +2103,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;
@@ -2124,16 +2123,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 ; }/*
@@ -2308,7 +2297,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)
@@ -2346,7 +2336,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 ; }/*
@@ -2421,7 +2417,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 · 1 line
2.6.6
Jan Kara
maintainerPATCH v4 16/21 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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v4 17/21 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
@@ -2296,10 +2296,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 ; }/*
@@ -2342,8 +2342,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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v4 18/21 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 · 1 line
2.6.6
Jan Kara
maintainerPATCH 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 consisten 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
@@ -1163,17 +1163,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
@@ -2310,7 +2310,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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH 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"
@@ -668,6 +669,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) {
@@ -735,7 +789,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>
Jan Kara
maintainerPATCH v4 19/21 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
@@ -619,32 +619,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
@@ -654,15 +672,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 ;
@@ -670,15 +689,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 v4 20/21 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
@@ -784,17 +784,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
@@ -2316,7 +2316,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 · 6 lines
2.6.6 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Jan Kara
maintainerPATCH v4 21/21 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"
@@ -615,6 +616,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) {
@@ -688,7 +742,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>
Jan Kara
maintainerHi,
forgot to add Kirill to CC since this modifies the fault path he changed recently. I don't want to resend the whole series just because of this so at least I'm pinging him like this...
Honza
Quoted 70 lines · Jan Kara
Hello,
this is the fourth revision of my patches to clear dirty bits from radix tree of DAX inodes when caches for corresponding pfns have been flushed. This patch set is significantly larger than the previous version because I'm changing how ->fault, ->page_mkwrite, and ->pfn_mkwrite handlers may choose to handle the fault so that we don't have to leak details about DAX locking into the generic code. 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 be really like feedback from mm folks whether such changes to fault handling code are fine or what they'd do differently.
The patches are based on 4.9-rc1 + Ross' DAX PMD page fault series [1] + 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.gitdaxThe 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] http://www.spinics.net/lists/linux-mm/msg115247.html
[2] Posted an hour ago - look for "ext4: Convert ext4 DAX IO to iomap framework"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 invm_faultstructure as requested by ChristophChanges since v2:
* rebased on top of 4.8-rc8 - this involved dealing with newfault_envstructure
* changed calling convention for fault helpersChanges 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 frommm/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
Signature · 8 lines
Jan Kara <[email protected]> SUSE Labs, CR -- 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>
Quoted 5 lines · Jan Kara
Hi,
forgot to add Kirill to CC since this modifies the fault path he changed recently. I don't want to resend the whole series just because of this so at least I'm pinging him like this...
I see strange mix x/20 and x/21 patches. Which should I look at?
Signature · 7 lines
Kirill A. Shutemov -- 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
maintainerQuoted 8 lines · Kirill A. Shutemov
Quoted 5 lines · Jan Kara
Hi,
forgot to add Kirill to CC since this modifies the fault path he changed recently. I don't want to resend the whole series just because of this so at least I'm pinging him like this...
I see strange mix x/20 and x/21 patches. Which should I look at?
Ah, sorry, I've messed up the send out (I already had the old series formatted in that directory). I'll send it again with you in CC.
Honza
Signature · 8 lines
Jan Kara <[email protected]> SUSE Labs, CR -- 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>
Quoted 12 lines · Jan Kara
Hello,
this is the fourth revision of my patches to clear dirty bits from radix tree of DAX inodes when caches for corresponding pfns have been flushed. This patch set is significantly larger than the previous version because I'm changing how ->fault, ->page_mkwrite, and ->pfn_mkwrite handlers may choose to handle the fault so that we don't have to leak details about DAX locking into the generic code. 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 be really like feedback from mm folks whether such changes to fault handling code are fine or what they'd do differently.
Quoted 6 lines
The patches are based on 4.9-rc1 + Ross' DAX PMD page fault series [1] + 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.gitdax
In my testing I hit what I believe to be a new lockdep splat. This was produced with ext4+dax+generic/246, though I've tried several times to reproduce it and haven't been able. This testing was done with your tree plus one patch to fix the DAX PMD recursive fallback issue that you reported. This new patch is folded into v9 of my PMD series that I sent out earlier today.
I've posted the tree I was testing with here:
https://git.kernel.org/cgit/linux/kernel/git/zwisler/linux.git/log/?h=jan_dax
Here is the lockdep splat, passed through kasan_symbolize:
run fstests generic/246 at 2016-11-01 21:51:34
======================================================
[ INFO: possible circular locking dependency detected ] 4.9.0-rc1-00165-g13826b5 #2 Not tainted
-------------------------------------------------------
t_mmap_writev/13704 is trying to acquire lock:
([ 3522.320075] &ei->i_mmap_sem
){++++.+}[ 3522.320924] , at:
[<ffffffff8133ef06>] ext4_dax_fault+0x36/0xd0 fs/ext4/file.c:267
but task is already holding lock:
([ 3522.324135] jbd2_handle
){++++.+}[ 3522.324875] , at:
[<ffffffff813a48b0>] start_this_handle+0x110/0x440 fs/jbd2/transaction.c:361
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1[ 3522.330384] (
jbd2_handle[ 3522.330889] ){++++.+}
:
[<ffffffff8110efa2>] lock_acquire+0xf2/0x1e0 kernel/locking/lockdep.c:3746
[<ffffffff813a4914>] start_this_handle+0x174/0x440 fs/jbd2/transaction.c:389
[<ffffffff813a4ecb>] jbd2__journal_start+0xdb/0x290 fs/jbd2/transaction.c:457
[<ffffffff8137c989>] __ext4_journal_start_sb+0x89/0x1d0 fs/ext4/ext4_jbd2.c:76
[< inline >] __ext4_journal_start fs/ext4/ext4_jbd2.h:318
[<ffffffff8137370f>] ext4_alloc_file_blocks.isra.34+0xef/0x310 fs/ext4/extents.c:4701
[< inline >] ext4_zero_range fs/ext4/extents.c:4850
[<ffffffff8137bfa4>] ext4_fallocate+0x974/0xae0 fs/ext4/extents.c:4952
[<ffffffff81292a8a>] vfs_fallocate+0x15a/0x230 fs/open.c:320
[< inline >] SYSC_fallocate fs/open.c:343
[<ffffffff812938e4>] SyS_fallocate+0x44/0x70 fs/open.c:337
[<ffffffff81b3d501>] entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:209-> #0[ 3522.342547] (
&ei->i_mmap_sem[ 3522.343023] ){++++.+}
:
[< inline >] check_prev_add kernel/locking/lockdep.c:1829
[< inline >] check_prevs_add kernel/locking/lockdep.c:1939
[< inline >] validate_chain kernel/locking/lockdep.c:2266
[<ffffffff8110e89f>] __lock_acquire+0x127f/0x14d0 kernel/locking/lockdep.c:3335
[<ffffffff8110efa2>] lock_acquire+0xf2/0x1e0 kernel/locking/lockdep.c:3746
[<ffffffff81b39b7e>] down_read+0x3e/0xa0 kernel/locking/rwsem.c:22
[<ffffffff8133ef06>] ext4_dax_fault+0x36/0xd0 fs/ext4/file.c:267
[<ffffffff8122f9d1>] __do_fault+0x21/0x130 mm/memory.c:2872
[< inline >] do_read_fault mm/memory.c:3231
[< inline >] do_fault mm/memory.c:3333
[< inline >] handle_pte_fault mm/memory.c:3534
[< inline >] __handle_mm_fault mm/memory.c:3624
[<ffffffff812348ae>] handle_mm_fault+0x114e/0x1550 mm/memory.c:3661
[<ffffffff8106bc27>] __do_page_fault+0x247/0x4f0 arch/x86/mm/fault.c:1397
[<ffffffff8106bfad>] trace_do_page_fault+0x5d/0x290 arch/x86/mm/fault.c:1490
[<ffffffff81065dba>] do_async_page_fault+0x1a/0xa0 arch/x86/kernel/kvm.c:265
[<ffffffff81b3ea08>] async_page_fault+0x28/0x30 arch/x86/entry/entry_64.S:1015
[< inline >] arch_copy_from_iter_pmem ./arch/x86/include/asm/pmem.h:95
[< inline >] copy_from_iter_pmem ./include/linux/pmem.h:118
[<ffffffff812f4a27>] dax_iomap_actor+0x147/0x270 fs/dax.c:1027
[<ffffffff8130c513>] iomap_apply+0xb3/0x130 fs/iomap.c:78
[<ffffffff812f46d6>] dax_iomap_rw+0x76/0xa0 fs/dax.c:1067
[< inline >] ext4_dax_write_iter fs/ext4/file.c:196
[<ffffffff8133fb13>] ext4_file_write_iter+0x243/0x340 fs/ext4/file.c:217
[<ffffffff812957d1>] do_iter_readv_writev+0xb1/0x130 fs/read_write.c:695
[<ffffffff81296384>] do_readv_writev+0x1a4/0x250 fs/read_write.c:872
[<ffffffff8129668f>] vfs_writev+0x3f/0x50 fs/read_write.c:911
[<ffffffff81296704>] do_writev+0x64/0x100 fs/read_write.c:944
[< inline >] SYSC_writev fs/read_write.c:1017
[<ffffffff81297900>] SyS_writev+0x10/0x20 fs/read_write.c:1014
[<ffffffff81b3d501>] entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:209other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock([ 3522.369967] jbd2_handle
);
lock([ 3522.371437] &ei->i_mmap_sem
);
lock([ 3522.372912] jbd2_handle);
lock([ 3522.373903] &ei->i_mmap_sem
);
*** DEADLOCK ***
4 locks held by t_mmap_writev/13704:
#0: [ 3522.376722] (
sb_writers[ 3522.377174] #15
){++++.+}[ 3522.377632] , at:
[< inline >] file_start_write ./include/linux/fs.h:2592
[<ffffffff812963ec>] do_readv_writev+0x20c/0x250 fs/read_write.c:868
#1: [ 3522.379225] (
&sb->s_type->i_mutex_key[ 3522.379876] #20
){++++++}[ 3522.380327] , at:
[< inline >] inode_lock ./include/linux/fs.h:740
[< inline >] ext4_dax_write_iter fs/ext4/file.c:181
[<ffffffff8133faa6>] ext4_file_write_iter+0x1d6/0x340 fs/ext4/file.c:217
#2: [ 3522.382013] (jbd2_handle[ 3522.382486] ){++++.+}
, at: [ 3522.382980] [<ffffffff813a48b0>] start_this_handle+0x110/0x440
#3: [ 3522.384263] (
&mm->mmap_sem[ 3522.384757] ){++++++}
, at: [ 3522.385251] [<ffffffff8106bb44>] __do_page_fault+0x164/0x4f0
stack backtrace: CPU: 0 PID: 13704 Comm: t_mmap_writev Not tainted 4.9.0-rc1-00165-g13826b5 #2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.1-0-gb3ef39f-prebuilt.qemu-project.org 04/01/2014 ffffc9000a223720 ffffffff815f5773 ffffffff82f78170 ffffffff82f78170 ffffc9000a223760 ffffffff8110bc03 ffffc9000a2237b0 ffff880310e5da58 ffff880310e5d100 0000000000000004 ffff880310e5d9e8 0000000000000003 Call Trace: [< inline >] __dump_stack lib/dump_stack.c:15 [<ffffffff815f5773>] dump_stack+0x85/0xc2 lib/dump_stack.c:51 [<ffffffff8110bc03>] print_circular_bug+0x1e3/0x250 kernel/locking/lockdep.c:1202 [< inline >] check_prev_add kernel/locking/lockdep.c:1829 [< inline >] check_prevs_add kernel/locking/lockdep.c:1939 [< inline >] validate_chain kernel/locking/lockdep.c:2266 [<ffffffff8110e89f>] __lock_acquire+0x127f/0x14d0 kernel/locking/lockdep.c:3335 [<ffffffff8110efa2>] lock_acquire+0xf2/0x1e0 kernel/locking/lockdep.c:3746 [<ffffffff81b39b7e>] down_read+0x3e/0xa0 kernel/locking/rwsem.c:22 [<ffffffff8133ef06>] ext4_dax_fault+0x36/0xd0 fs/ext4/file.c:267 [<ffffffff8122f9d1>] __do_fault+0x21/0x130 mm/memory.c:2872 [< inline >] do_read_fault mm/memory.c:3231 [< inline >] do_fault mm/memory.c:3333 [< inline >] handle_pte_fault mm/memory.c:3534 [< inline >] __handle_mm_fault mm/memory.c:3624 [<ffffffff812348ae>] handle_mm_fault+0x114e/0x1550 mm/memory.c:3661 [<ffffffff8106bc27>] __do_page_fault+0x247/0x4f0 arch/x86/mm/fault.c:1397 [<ffffffff8106bfad>] trace_do_page_fault+0x5d/0x290 arch/x86/mm/fault.c:1490 [<ffffffff81065dba>] do_async_page_fault+0x1a/0xa0 arch/x86/kernel/kvm.c:265 [<ffffffff81b3ea08>] async_page_fault+0x28/0x30 arch/x86/entry/entry_64.S:1015 [< inline >] arch_copy_from_iter_pmem ./arch/x86/include/asm/pmem.h:95 [< inline >] copy_from_iter_pmem ./include/linux/pmem.h:118 [<ffffffff812f4a27>] dax_iomap_actor+0x147/0x270 fs/dax.c:1027 [<ffffffff8130c513>] iomap_apply+0xb3/0x130 fs/iomap.c:78 [<ffffffff812f46d6>] dax_iomap_rw+0x76/0xa0 fs/dax.c:1067 [< inline >] ext4_dax_write_iter fs/ext4/file.c:196 [<ffffffff8133fb13>] ext4_file_write_iter+0x243/0x340 fs/ext4/file.c:217 [<ffffffff812957d1>] do_iter_readv_writev+0xb1/0x130 fs/read_write.c:695 [<ffffffff81296384>] do_readv_writev+0x1a4/0x250 fs/read_write.c:872 [<ffffffff8129668f>] vfs_writev+0x3f/0x50 fs/read_write.c:911 [<ffffffff81296704>] do_writev+0x64/0x100 fs/read_write.c:944 [< inline >] SYSC_writev fs/read_write.c:1017 [<ffffffff81297900>] SyS_writev+0x10/0x20 fs/read_write.c:1014 [<ffffffff81b3d501>] entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:209
--
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
maintainerQuoted 34 lines · Ross Zwisler
Quoted 12 lines · Jan Kara
Hello,
this is the fourth revision of my patches to clear dirty bits from radix tree of DAX inodes when caches for corresponding pfns have been flushed. This patch set is significantly larger than the previous version because I'm changing how ->fault, ->page_mkwrite, and ->pfn_mkwrite handlers may choose to handle the fault so that we don't have to leak details about DAX locking into the generic code. 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 be really like feedback from mm folks whether such changes to fault handling code are fine or what they'd do differently.
Quoted 6 lines
The patches are based on 4.9-rc1 + Ross' DAX PMD page fault series [1] + 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.gitdaxIn my testing I hit what I believe to be a new lockdep splat. This was produced with ext4+dax+generic/246, though I've tried several times to reproduce it and haven't been able. This testing was done with your tree plus one patch to fix the DAX PMD recursive fallback issue that you reported. This new patch is folded into v9 of my PMD series that I sent out earlier today.
I've posted the tree I was testing with here:
https://git.kernel.org/cgit/linux/kernel/git/zwisler/linux.git/log/?h=jan_dax
Here is the lockdep splat, passed through
kasan_symbolize:run fstests generic/246 at 2016-11-01 21:51:34
Quoted 8 lines
======================================================
[ INFO: possible circular locking dependency detected ] 4.9.0-rc1-00165-g13826b5 #2 Not tainted
-------------------------------------------------------
t_mmap_writev/13704 is trying to acquire lock:
([ 3522.320075]&ei->i_mmap_sem
){++++.+}[ 3522.320924] , at:
[<ffffffff8133ef06>]ext4_dax_fault+0x36/0xd0fs/ext4/file.c:267
Interesting, I didn't see this in my testing.
Quoted 16 lines
-> #0[ 3522.342547] (
&ei->i_mmap_sem[ 3522.343023] ){++++.+}
:[< inline >] check_prev_add kernel/locking/lockdep.c:1829 [< inline >] check_prevs_add kernel/locking/lockdep.c:1939 [< inline >] validate_chain kernel/locking/lockdep.c:2266 [<ffffffff8110e89f>] __lock_acquire+0x127f/0x14d0 kernel/locking/lockdep.c:3335 [<ffffffff8110efa2>] lock_acquire+0xf2/0x1e0 kernel/locking/lockdep.c:3746 [<ffffffff81b39b7e>] down_read+0x3e/0xa0 kernel/locking/rwsem.c:22 [<ffffffff8133ef06>] ext4_dax_fault+0x36/0xd0 fs/ext4/file.c:267 [<ffffffff8122f9d1>] __do_fault+0x21/0x130 mm/memory.c:2872 [< inline >] do_read_fault mm/memory.c:3231 [< inline >] do_fault mm/memory.c:3333 [< inline >] handle_pte_fault mm/memory.c:3534 [< inline >] __handle_mm_fault mm/memory.c:3624 [<ffffffff812348ae>] handle_mm_fault+0x114e/0x1550 mm/memory.c:3661
Quoted 8 lines
[<ffffffff8106bc27>] __do_page_fault+0x247/0x4f0 arch/x86/mm/fault.c:1397
[<ffffffff8106bfad>] trace_do_page_fault+0x5d/0x290 arch/x86/mm/fault.c:1490
[<ffffffff81065dba>] do_async_page_fault+0x1a/0xa0 arch/x86/kernel/kvm.c:265
[<ffffffff81b3ea08>] async_page_fault+0x28/0x30 arch/x86/entry/entry_64.S:1015
[< inline >] arch_copy_from_iter_pmem ./arch/x86/include/asm/pmem.h:95
[< inline >] copy_from_iter_pmem ./include/linux/pmem.h:118
[<ffffffff812f4a27>] dax_iomap_actor+0x147/0x270 fs/dax.c:1027
[<ffffffff8130c513>] iomap_apply+0xb3/0x130 fs/iomap.c:78So the problem is that we were doing write to a DAX file from a buffer which is mmapped DAX file and we took a fault when copying data from the buffer. That looks like a real problem. I'll have to think what to do with it... Thanks for report!
Quoted 11 lines
[<ffffffff812f46d6>] dax_iomap_rw+0x76/0xa0 fs/dax.c:1067
[< inline >] ext4_dax_write_iter fs/ext4/file.c:196
[<ffffffff8133fb13>] ext4_file_write_iter+0x243/0x340 fs/ext4/file.c:217
[<ffffffff812957d1>] do_iter_readv_writev+0xb1/0x130 fs/read_write.c:695
[<ffffffff81296384>] do_readv_writev+0x1a4/0x250 fs/read_write.c:872
[<ffffffff8129668f>] vfs_writev+0x3f/0x50 fs/read_write.c:911
[<ffffffff81296704>] do_writev+0x64/0x100 fs/read_write.c:944
[< inline >] SYSC_writev fs/read_write.c:1017
[<ffffffff81297900>] SyS_writev+0x10/0x20 fs/read_write.c:1014
[<ffffffff81b3d501>] entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:209 Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR
--
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
maintainerQuoted 71 lines · Jan Kara
Quoted 34 lines · Ross Zwisler
Quoted 12 lines · Jan Kara
Hello,
this is the fourth revision of my patches to clear dirty bits from radix tree of DAX inodes when caches for corresponding pfns have been flushed. This patch set is significantly larger than the previous version because I'm changing how ->fault, ->page_mkwrite, and ->pfn_mkwrite handlers may choose to handle the fault so that we don't have to leak details about DAX locking into the generic code. 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 be really like feedback from mm folks whether such changes to fault handling code are fine or what they'd do differently.
Quoted 6 lines
The patches are based on 4.9-rc1 + Ross' DAX PMD page fault series [1] + 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.gitdaxIn my testing I hit what I believe to be a new lockdep splat. This was produced with ext4+dax+generic/246, though I've tried several times to reproduce it and haven't been able. This testing was done with your tree plus one patch to fix the DAX PMD recursive fallback issue that you reported. This new patch is folded into v9 of my PMD series that I sent out earlier today.
I've posted the tree I was testing with here:
https://git.kernel.org/cgit/linux/kernel/git/zwisler/linux.git/log/?h=jan_dax
Here is the lockdep splat, passed through
kasan_symbolize:run fstests generic/246 at 2016-11-01 21:51:34
Quoted 8 lines
======================================================
[ INFO: possible circular locking dependency detected ] 4.9.0-rc1-00165-g13826b5 #2 Not tainted
-------------------------------------------------------
t_mmap_writev/13704 is trying to acquire lock:
([ 3522.320075]&ei->i_mmap_sem
){++++.+}[ 3522.320924] , at:
[<ffffffff8133ef06>]ext4_dax_fault+0x36/0xd0fs/ext4/file.c:267Interesting, I didn't see this in my testing.
Quoted 16 lines
-> #0[ 3522.342547] (
&ei->i_mmap_sem[ 3522.343023] ){++++.+}
:[< inline >] check_prev_add kernel/locking/lockdep.c:1829 [< inline >] check_prevs_add kernel/locking/lockdep.c:1939 [< inline >] validate_chain kernel/locking/lockdep.c:2266 [<ffffffff8110e89f>] __lock_acquire+0x127f/0x14d0 kernel/locking/lockdep.c:3335 [<ffffffff8110efa2>] lock_acquire+0xf2/0x1e0 kernel/locking/lockdep.c:3746 [<ffffffff81b39b7e>] down_read+0x3e/0xa0 kernel/locking/rwsem.c:22 [<ffffffff8133ef06>] ext4_dax_fault+0x36/0xd0 fs/ext4/file.c:267 [<ffffffff8122f9d1>] __do_fault+0x21/0x130 mm/memory.c:2872 [< inline >] do_read_fault mm/memory.c:3231 [< inline >] do_fault mm/memory.c:3333 [< inline >] handle_pte_fault mm/memory.c:3534 [< inline >] __handle_mm_fault mm/memory.c:3624 [<ffffffff812348ae>] handle_mm_fault+0x114e/0x1550 mm/memory.c:3661Quoted 8 lines
[<ffffffff8106bc27>] __do_page_fault+0x247/0x4f0 arch/x86/mm/fault.c:1397 [<ffffffff8106bfad>] trace_do_page_fault+0x5d/0x290 arch/x86/mm/fault.c:1490 [<ffffffff81065dba>] do_async_page_fault+0x1a/0xa0 arch/x86/kernel/kvm.c:265 [<ffffffff81b3ea08>] async_page_fault+0x28/0x30 arch/x86/entry/entry_64.S:1015 [< inline >] arch_copy_from_iter_pmem ./arch/x86/include/asm/pmem.h:95 [< inline >] copy_from_iter_pmem ./include/linux/pmem.h:118 [<ffffffff812f4a27>] dax_iomap_actor+0x147/0x270 fs/dax.c:1027 [<ffffffff8130c513>] iomap_apply+0xb3/0x130 fs/iomap.c:78
Quoted 4 lines
So the problem is that we were doing write to a DAX file from a buffer which is mmapped DAX file and we took a fault when copying data from the buffer. That looks like a real problem. I'll have to think what to do with it... Thanks for report!
So the problem is in ext4 iomap conversion (i.e., not in this patch series). The culprit is that we keep transaction handle running between ->iomap_begin() and ->iomap_end() calls. I was thinking about possible solutions and I've found only two:
1) Add inode to orphan list when we are extending the file in ext4_iomap_begin() and stop the current handle. Then grab a new handle in ext4_iomap_end() and remove inode from the orphan list and update inode size. This is what we were basically using in the original direct IO path.
2) Add a version of dax_iomap_rw() (or a flag for it) to prefault pages before calling ->iomap_begin(), then use atomic copy for the data. In ->iomap_end() we'd have to truncate the file if we didn't copy data for the whole extent. This is more like standard write path works.
Doing 1) is easier, doing 2) may perform better unless there is high memory pressure which would evict buffers from memory before we actually allocate the extent and copy data to it.
I guess for now I'll go with 1) just to have the conversion to iomap code done and look into doing 2) later while measuring what performance benefits do we get from it.
Honza
Quoted 10 lines
Quoted 10 lines
[<ffffffff812f46d6>] dax_iomap_rw+0x76/0xa0 fs/dax.c:1067 [< inline >] ext4_dax_write_iter fs/ext4/file.c:196 [<ffffffff8133fb13>] ext4_file_write_iter+0x243/0x340 fs/ext4/file.c:217 [<ffffffff812957d1>] do_iter_readv_writev+0xb1/0x130 fs/read_write.c:695 [<ffffffff81296384>] do_readv_writev+0x1a4/0x250 fs/read_write.c:872 [<ffffffff8129668f>] vfs_writev+0x3f/0x50 fs/read_write.c:911 [<ffffffff81296704>] do_writev+0x64/0x100 fs/read_write.c:944 [< inline >] SYSC_writev fs/read_write.c:1017 [<ffffffff81297900>] SyS_writev+0x10/0x20 fs/read_write.c:1014 [<ffffffff81b3d501>] entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:209
Signature · 8 lines
Jan Kara <[email protected]> SUSE Labs, CR -- 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>