Commit 58ef47ef authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Andrew Morton
Browse files

mm: hold the RCU read lock over calls to ->map_pages

Prevent filesystems from doing things which sleep in their map_pages
method.  This is in preparation for a pagefault path protected only by
RCU.

Link: https://lkml.kernel.org/r/20230327174515.1811532-4-willy@infradead.org


Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Cc: Darrick J. Wong <djwong@kernel.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 0050d7f5
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -645,7 +645,7 @@ ops mmap_lock PageLocked(page)
open:		yes
open:		yes
close:		yes
close:		yes
fault:		yes		can return with page locked
fault:		yes		can return with page locked
map_pages:	yes
map_pages:	read
page_mkwrite:	yes		can return with page locked
page_mkwrite:	yes		can return with page locked
pfn_mkwrite:	yes
pfn_mkwrite:	yes
access:		yes
access:		yes
@@ -661,7 +661,7 @@ locked. The VM will unlock the page.


->map_pages() is called when VM asks to map easy accessible pages.
->map_pages() is called when VM asks to map easy accessible pages.
Filesystem should find and map pages associated with offsets from "start_pgoff"
Filesystem should find and map pages associated with offsets from "start_pgoff"
till "end_pgoff". ->map_pages() is called with page table locked and must
till "end_pgoff". ->map_pages() is called with the RCU lock held and must
not block.  If it's not possible to reach a page without blocking,
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
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
page table entry. Pointer to entry associated with the page is passed in
+8 −3
Original line number Original line Diff line number Diff line
@@ -4450,6 +4450,7 @@ static vm_fault_t do_fault_around(struct vm_fault *vmf)
	/* The page offset of vmf->address within the VMA. */
	/* The page offset of vmf->address within the VMA. */
	pgoff_t vma_off = vmf->pgoff - vmf->vma->vm_pgoff;
	pgoff_t vma_off = vmf->pgoff - vmf->vma->vm_pgoff;
	pgoff_t from_pte, to_pte;
	pgoff_t from_pte, to_pte;
	vm_fault_t ret;


	/* The PTE offset of the start address, clamped to the VMA. */
	/* The PTE offset of the start address, clamped to the VMA. */
	from_pte = max(ALIGN_DOWN(pte_off, nr_pages),
	from_pte = max(ALIGN_DOWN(pte_off, nr_pages),
@@ -4465,9 +4466,13 @@ static vm_fault_t do_fault_around(struct vm_fault *vmf)
			return VM_FAULT_OOM;
			return VM_FAULT_OOM;
	}
	}


	return vmf->vma->vm_ops->map_pages(vmf,
	rcu_read_lock();
	ret = vmf->vma->vm_ops->map_pages(vmf,
			vmf->pgoff + from_pte - pte_off,
			vmf->pgoff + from_pte - pte_off,
			vmf->pgoff + to_pte - pte_off);
			vmf->pgoff + to_pte - pte_off);
	rcu_read_unlock();

	return ret;
}
}


/* Return true if we should do read fault-around, false otherwise */
/* Return true if we should do read fault-around, false otherwise */