linux/arch/arc
Vineet Gupta 4d447455e7 ARC: mm: do_page_fault fixes #1: relinquish mmap_sem if signal arrives while handle_mm_fault
do_page_fault() forgot to relinquish mmap_sem if a signal came while
handling handle_mm_fault() - due to say a ctl+c or oom etc.
This would later cause a deadlock by acquiring it twice.

This came to light when running libc testsuite tst-tls3-malloc test but
is likely also the cause for prior seen LTP failures. Using lockdep
clearly showed what the issue was.

| # while true; do ./tst-tls3-malloc ; done
| Didn't expect signal from child: got `Segmentation fault'
| ^C
| ============================================
| WARNING: possible recursive locking detected
| 4.17.0+ #25 Not tainted
| --------------------------------------------
| tst-tls3-malloc/510 is trying to acquire lock:
| 606c7728 (&mm->mmap_sem){++++}, at: __might_fault+0x28/0x5c
|
|but task is already holding lock:
|606c7728 (&mm->mmap_sem){++++}, at: do_page_fault+0x9c/0x2a0
|
| other info that might help us debug this:
|  Possible unsafe locking scenario:
|
|       CPU0
|       ----
|  lock(&mm->mmap_sem);
|  lock(&mm->mmap_sem);
|
| *** DEADLOCK ***
|

------------------------------------------------------------
What the change does is not obvious (note to myself)

prior code was

| do_page_fault
|
|   down_read()		<-- lock taken
|   handle_mm_fault	<-- signal pending as this runs
|   if fatal_signal_pending
|       if VM_FAULT_ERROR
|           up_read
|       if user_mode
|          return	<-- lock still held, this was the BUG

New code

| do_page_fault
|
|   down_read()		<-- lock taken
|   handle_mm_fault	<-- signal pending as this runs
|   if fatal_signal_pending
|       if VM_FAULT_RETRY
|          return       <-- not same case as above, but still OK since
|                           core mm already relinq lock for FAULT_RETRY
|    ...
|
|   < Now falls through for bug case above >
|
|   up_read()		<-- lock relinquished

Cc: stable@vger.kernel.org
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2019-01-17 16:24:39 -08:00
..
boot ARC: [plat-hsdk] Enable DW APB GPIO support 2018-11-12 10:38:27 -08:00
configs ARC: change defconfig defaults to ARCv2 2018-11-30 10:54:01 -08:00
include ARC: perf: map generic branches to correct hardware condition 2019-01-17 14:38:00 -08:00
kernel ARC: show_regs: lockdep: re-enable preemption 2019-01-17 14:38:00 -08:00
lib ARC: dw2 unwind: enable cfi pseudo ops in string lib 2016-09-30 14:48:22 -07:00
mm ARC: mm: do_page_fault fixes #1: relinquish mmap_sem if signal arrives while handle_mm_fault 2019-01-17 16:24:39 -08:00
oprofile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
plat-axs10x PCI: consolidate PCI config entry in drivers/pci 2018-11-23 11:45:34 +09:00
plat-eznps arc: [plat-eznps] fix printk warning in arc/plat-eznps/mtm.c 2018-07-30 11:48:49 -07:00
plat-hsdk PCI: consolidate PCI config entry in drivers/pci 2018-11-23 11:45:34 +09:00
plat-sim ARC: [plat-sim] Include this platform unconditionally 2017-08-04 13:49:47 +05:30
plat-tb10x arc: select GPIOLIB directly 2016-04-26 14:07:59 +02:00
Kbuild
Kconfig Kconfig file consolidation for v4.21 2018-12-29 13:40:29 -08:00
Kconfig.debug Kconfig: consolidate the "Kernel hacking" menu 2018-08-02 08:06:48 +09:00
Makefile ARC: change defconfig defaults to ARCv2 2018-11-30 10:54:01 -08:00