mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	mm, hugetlbfs: introduce ->split() to vm_operations_struct
Patch series "device-dax: fix unaligned munmap handling"
When device-dax is operating in huge-page mode we want it to behave like
hugetlbfs and fail attempts to split vmas into unaligned ranges.  It
would be messy to teach the munmap path about device-dax alignment
constraints in the same (hstate) way that hugetlbfs communicates this
constraint.  Instead, these patches introduce a new ->split() vm
operation.
This patch (of 2):
The device-dax interface has similar constraints as hugetlbfs in that it
requires the munmap path to unmap in huge page aligned units.  Rather
than add more custom vma handling code in __split_vma() introduce a new
vm operation to perform this vma specific check.
Link: http://lkml.kernel.org/r/151130418135.4029.6783191281930729710.stgit@dwillia2-desk3.amr.corp.intel.com
Fixes: dee4107924 ("/dev/dax, core: file operations and dax-mmap")
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
			
			
This commit is contained in:
		
							parent
							
								
									95a8798254
								
							
						
					
					
						commit
						31383c6865
					
				
					 3 changed files with 14 additions and 3 deletions
				
			
		| 
						 | 
					@ -377,6 +377,7 @@ enum page_entry_size {
 | 
				
			||||||
struct vm_operations_struct {
 | 
					struct vm_operations_struct {
 | 
				
			||||||
	void (*open)(struct vm_area_struct * area);
 | 
						void (*open)(struct vm_area_struct * area);
 | 
				
			||||||
	void (*close)(struct vm_area_struct * area);
 | 
						void (*close)(struct vm_area_struct * area);
 | 
				
			||||||
 | 
						int (*split)(struct vm_area_struct * area, unsigned long addr);
 | 
				
			||||||
	int (*mremap)(struct vm_area_struct * area);
 | 
						int (*mremap)(struct vm_area_struct * area);
 | 
				
			||||||
	int (*fault)(struct vm_fault *vmf);
 | 
						int (*fault)(struct vm_fault *vmf);
 | 
				
			||||||
	int (*huge_fault)(struct vm_fault *vmf, enum page_entry_size pe_size);
 | 
						int (*huge_fault)(struct vm_fault *vmf, enum page_entry_size pe_size);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3125,6 +3125,13 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int hugetlb_vm_op_split(struct vm_area_struct *vma, unsigned long addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (addr & ~(huge_page_mask(hstate_vma(vma))))
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * We cannot handle pagefaults against hugetlb pages at all.  They cause
 | 
					 * We cannot handle pagefaults against hugetlb pages at all.  They cause
 | 
				
			||||||
 * handle_mm_fault() to try to instantiate regular-sized pages in the
 | 
					 * handle_mm_fault() to try to instantiate regular-sized pages in the
 | 
				
			||||||
| 
						 | 
					@ -3141,6 +3148,7 @@ const struct vm_operations_struct hugetlb_vm_ops = {
 | 
				
			||||||
	.fault = hugetlb_vm_op_fault,
 | 
						.fault = hugetlb_vm_op_fault,
 | 
				
			||||||
	.open = hugetlb_vm_op_open,
 | 
						.open = hugetlb_vm_op_open,
 | 
				
			||||||
	.close = hugetlb_vm_op_close,
 | 
						.close = hugetlb_vm_op_close,
 | 
				
			||||||
 | 
						.split = hugetlb_vm_op_split,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
 | 
					static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2555,9 +2555,11 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
 | 
				
			||||||
	struct vm_area_struct *new;
 | 
						struct vm_area_struct *new;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (is_vm_hugetlb_page(vma) && (addr &
 | 
						if (vma->vm_ops && vma->vm_ops->split) {
 | 
				
			||||||
					~(huge_page_mask(hstate_vma(vma)))))
 | 
							err = vma->vm_ops->split(vma, addr);
 | 
				
			||||||
		return -EINVAL;
 | 
							if (err)
 | 
				
			||||||
 | 
								return err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
 | 
						new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
 | 
				
			||||||
	if (!new)
 | 
						if (!new)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue