linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] x86/fault: move might_sleep() out of mmap read lock
@ 2021-11-19  6:58 Muchun Song
  2021-11-19 15:04 ` Dave Hansen
  0 siblings, 1 reply; 5+ messages in thread
From: Muchun Song @ 2021-11-19  6:58 UTC (permalink / raw)
  To: dave.hansen, luto, peterz, tglx, mingo, bp, hpa
  Cc: x86, linux-kernel, duanxiongchun, zhengqi.arch, Muchun Song

The mmap lock is supposed to be a contended lock sometimes, scheduling
to other task with holding mmap read lock does not seems to be a wise
choice. So move it to the front of mmap_read_trylock(). Although
mmap_read_lock() implies a might_sleep(), I think redundant check is
not a problem since this task is about to sleep and it is not a hot
path.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 arch/x86/mm/fault.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 4bfed53e210e..22fd1dfafa3d 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -1323,6 +1323,8 @@ void do_user_addr_fault(struct pt_regs *regs,
 	}
 #endif
 
+	might_sleep();
+
 	/*
 	 * Kernel-mode access to the user address space should only occur
 	 * on well-defined single instructions listed in the exception
@@ -1346,13 +1348,6 @@ void do_user_addr_fault(struct pt_regs *regs,
 		}
 retry:
 		mmap_read_lock(mm);
-	} else {
-		/*
-		 * The above down_read_trylock() might have succeeded in
-		 * which case we'll have missed the might_sleep() from
-		 * down_read():
-		 */
-		might_sleep();
 	}
 
 	vma = find_vma(mm, address);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-26  5:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19  6:58 [RFC PATCH] x86/fault: move might_sleep() out of mmap read lock Muchun Song
2021-11-19 15:04 ` Dave Hansen
2021-11-22  6:59   ` Muchun Song
2021-11-25 10:45     ` Thomas Gleixner
2021-11-26  5:54       ` [External] " Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).