public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] x86/mm: consolidate bad_area handling to the end
@ 2019-09-19  2:08 Wei Yang
  2019-09-19  2:08 ` [PATCH 2/2] x86/mm: replace a goto by merging two if clause Wei Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Wei Yang @ 2019-09-19  2:08 UTC (permalink / raw)
  To: dave.hansen, luto, peterz; +Cc: x86, linux-kernel, Wei Yang

There are totally 7 bad_area[_nosemaphore] error branch in
do_user_addr_fault().

Consolidate all these handling to the end to make the code a little
neat.

BTW, after doing so, function bad_area is not used any more. Remove it.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
 arch/x86/mm/fault.c | 44 ++++++++++++++++----------------------------
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 9ceacd1156db..9d18b73b5f77 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -933,12 +933,6 @@ __bad_area(struct pt_regs *regs, unsigned long error_code,
 	__bad_area_nosemaphore(regs, error_code, address, pkey, si_code);
 }
 
-static noinline void
-bad_area(struct pt_regs *regs, unsigned long error_code, unsigned long address)
-{
-	__bad_area(regs, error_code, address, 0, SEGV_MAPERR);
-}
-
 static inline bool bad_area_access_from_pkeys(unsigned long error_code,
 		struct vm_area_struct *vma)
 {
@@ -1313,19 +1307,14 @@ void do_user_addr_fault(struct pt_regs *regs,
 	if (unlikely(cpu_feature_enabled(X86_FEATURE_SMAP) &&
 		     !(hw_error_code & X86_PF_USER) &&
 		     !(regs->flags & X86_EFLAGS_AC)))
-	{
-		bad_area_nosemaphore(regs, hw_error_code, address);
-		return;
-	}
+		goto bad_area_nosem;
 
 	/*
 	 * If we're in an interrupt, have no user context or are running
 	 * in a region with pagefaults disabled then we must not take the fault
 	 */
-	if (unlikely(faulthandler_disabled() || !mm)) {
-		bad_area_nosemaphore(regs, hw_error_code, address);
-		return;
-	}
+	if (unlikely(faulthandler_disabled() || !mm))
+		goto bad_area_nosem;
 
 	/*
 	 * It's safe to allow irq's after cr2 has been saved and the
@@ -1385,8 +1374,7 @@ void do_user_addr_fault(struct pt_regs *regs,
 			 * Fault from code in kernel from
 			 * which we do not expect faults.
 			 */
-			bad_area_nosemaphore(regs, hw_error_code, address);
-			return;
+			goto bad_area_nosem;
 		}
 retry:
 		down_read(&mm->mmap_sem);
@@ -1400,20 +1388,14 @@ void do_user_addr_fault(struct pt_regs *regs,
 	}
 
 	vma = find_vma(mm, address);
-	if (unlikely(!vma)) {
-		bad_area(regs, hw_error_code, address);
-		return;
-	}
+	if (unlikely(!vma))
+		goto bad_area;
 	if (likely(vma->vm_start <= address))
 		goto good_area;
-	if (unlikely(!(vma->vm_flags & VM_GROWSDOWN))) {
-		bad_area(regs, hw_error_code, address);
-		return;
-	}
-	if (unlikely(expand_stack(vma, address))) {
-		bad_area(regs, hw_error_code, address);
-		return;
-	}
+	if (unlikely(!(vma->vm_flags & VM_GROWSDOWN)))
+		goto bad_area;
+	if (unlikely(expand_stack(vma, address)))
+		goto bad_area;
 
 	/*
 	 * Ok, we have a good vm_area for this memory access, so
@@ -1483,6 +1465,12 @@ void do_user_addr_fault(struct pt_regs *regs,
 	}
 
 	check_v8086_mode(regs, address, tsk);
+	return;
+
+bad_area:
+	up_read(&mm->mmap_sem);
+bad_area_nosem:
+	bad_area_nosemaphore(regs, hw_error_code, address);
 }
 NOKPROBE_SYMBOL(do_user_addr_fault);
 
-- 
2.17.1


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

end of thread, other threads:[~2019-10-01 11:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-19  2:08 [PATCH 1/2] x86/mm: consolidate bad_area handling to the end Wei Yang
2019-09-19  2:08 ` [PATCH 2/2] x86/mm: replace a goto by merging two if clause Wei Yang
2019-09-23  9:22   ` Peter Zijlstra
2019-09-24  0:29     ` Wei Yang
2019-10-01 11:47     ` Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox