Commit d8ed45c5 authored by Michel Lespinasse's avatar Michel Lespinasse Committed by Linus Torvalds
Browse files

mmap locking API: use coccinelle to convert mmap_sem rwsem call sites



This change converts the existing mmap_sem rwsem calls to use the new mmap
locking API instead.

The change is generated using coccinelle with the following rule:

// spatch --sp-file mmap_lock_api.cocci --in-place --include-headers --dir .

@@
expression mm;
@@
(
-init_rwsem
+mmap_init_lock
|
-down_write
+mmap_write_lock
|
-down_write_killable
+mmap_write_lock_killable
|
-down_write_trylock
+mmap_write_trylock
|
-up_write
+mmap_write_unlock
|
-downgrade_write
+mmap_write_downgrade
|
-down_read
+mmap_read_lock
|
-down_read_killable
+mmap_read_lock_killable
|
-down_read_trylock
+mmap_read_trylock
|
-up_read
+mmap_read_unlock
)
-(&mm->mmap_sem)
+(mm)

Signed-off-by: default avatarMichel Lespinasse <walken@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
Reviewed-by: default avatarLaurent Dufour <ldufour@linux.ibm.com>
Reviewed-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Davidlohr Bueso <dbueso@suse.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Liam Howlett <Liam.Howlett@oracle.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ying Han <yinghan@google.com>
Link: http://lkml.kernel.org/r/20200520052908.204642-5-walken@google.com


Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0adf65f5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -957,12 +957,12 @@ give_sigsegv:
		si_code = SEGV_ACCERR;
	else {
		struct mm_struct *mm = current->mm;
		down_read(&mm->mmap_sem);
		mmap_read_lock(mm);
		if (find_vma(mm, (unsigned long)va))
			si_code = SEGV_ACCERR;
		else
			si_code = SEGV_MAPERR;
		up_read(&mm->mmap_sem);
		mmap_read_unlock(mm);
	}
	send_sig_fault(SIGSEGV, si_code, va, 0, current);
	return;
+5 −5
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
	if (user_mode(regs))
		flags |= FAULT_FLAG_USER;
retry:
	down_read(&mm->mmap_sem);
	mmap_read_lock(mm);
	vma = find_vma(mm, address);
	if (!vma)
		goto bad_area;
@@ -180,14 +180,14 @@ retry:
		}
	}

	up_read(&mm->mmap_sem);
	mmap_read_unlock(mm);

	return;

	/* Something tried to access memory that isn't in our memory map.
	   Fix it, but check if it's kernel or user first.  */
 bad_area:
	up_read(&mm->mmap_sem);
	mmap_read_unlock(mm);

	if (user_mode(regs))
		goto do_sigsegv;
@@ -211,14 +211,14 @@ retry:
	/* We ran out of memory, or some other thing happened to us that
	   made us unable to handle the page fault gracefully.  */
 out_of_memory:
	up_read(&mm->mmap_sem);
	mmap_read_unlock(mm);
	if (!user_mode(regs))
		goto no_context;
	pagefault_out_of_memory();
	return;

 do_sigbus:
	up_read(&mm->mmap_sem);
	mmap_read_unlock(mm);
	/* Send a sigbus, regardless of whether we were in kernel
	   or user mode.  */
	force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *) address, 0);
+2 −2
Original line number Diff line number Diff line
@@ -90,10 +90,10 @@ fault:
	if (unlikely(ret != -EFAULT))
		 goto fail;

	down_read(&current->mm->mmap_sem);
	mmap_read_lock(current->mm);
	ret = fixup_user_fault(current, current->mm, (unsigned long) uaddr,
			       FAULT_FLAG_WRITE, NULL);
	up_read(&current->mm->mmap_sem);
	mmap_read_unlock(current->mm);

	if (likely(!ret))
		 goto again;
+2 −2
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ static void show_faulting_vma(unsigned long address)
	/* can't use print_vma_addr() yet as it doesn't check for
	 * non-inclusive vma
	 */
	down_read(&active_mm->mmap_sem);
	mmap_read_lock(active_mm);
	vma = find_vma(active_mm, address);

	/* check against the find_vma( ) behaviour which returns the next VMA
@@ -111,7 +111,7 @@ static void show_faulting_vma(unsigned long address)
	} else
		pr_info("    @No matching VMA found\n");

	up_read(&active_mm->mmap_sem);
	mmap_read_unlock(active_mm);
}

static void show_ecr_verbose(struct pt_regs *regs)
+2 −2
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
		flags |= FAULT_FLAG_WRITE;

retry:
	down_read(&mm->mmap_sem);
	mmap_read_lock(mm);

	vma = find_vma(mm, address);
	if (!vma)
@@ -150,7 +150,7 @@ retry:
	}

bad_area:
	up_read(&mm->mmap_sem);
	mmap_read_unlock(mm);

	/*
	 * Major/minor page fault accounting
Loading