1
0
Fork 0
alistair23-linux/arch/mips
Peter Xu 4064b98270 mm: allow VM_FAULT_RETRY for multiple times
The idea comes from a discussion between Linus and Andrea [1].

Before this patch we only allow a page fault to retry once.  We achieved
this by clearing the FAULT_FLAG_ALLOW_RETRY flag when doing
handle_mm_fault() the second time.  This was majorly used to avoid
unexpected starvation of the system by looping over forever to handle the
page fault on a single page.  However that should hardly happen, and after
all for each code path to return a VM_FAULT_RETRY we'll first wait for a
condition (during which time we should possibly yield the cpu) to happen
before VM_FAULT_RETRY is really returned.

This patch removes the restriction by keeping the FAULT_FLAG_ALLOW_RETRY
flag when we receive VM_FAULT_RETRY.  It means that the page fault handler
now can retry the page fault for multiple times if necessary without the
need to generate another page fault event.  Meanwhile we still keep the
FAULT_FLAG_TRIED flag so page fault handler can still identify whether a
page fault is the first attempt or not.

Then we'll have these combinations of fault flags (only considering
ALLOW_RETRY flag and TRIED flag):

  - ALLOW_RETRY and !TRIED:  this means the page fault allows to
                             retry, and this is the first try

  - ALLOW_RETRY and TRIED:   this means the page fault allows to
                             retry, and this is not the first try

  - !ALLOW_RETRY and !TRIED: this means the page fault does not allow
                             to retry at all

  - !ALLOW_RETRY and TRIED:  this is forbidden and should never be used

In existing code we have multiple places that has taken special care of
the first condition above by checking against (fault_flags &
FAULT_FLAG_ALLOW_RETRY).  This patch introduces a simple helper to detect
the first retry of a page fault by checking against both (fault_flags &
FAULT_FLAG_ALLOW_RETRY) and !(fault_flag & FAULT_FLAG_TRIED) because now
even the 2nd try will have the ALLOW_RETRY set, then use that helper in
all existing special paths.  One example is in __lock_page_or_retry(), now
we'll drop the mmap_sem only in the first attempt of page fault and we'll
keep it in follow up retries, so old locking behavior will be retained.

This will be a nice enhancement for current code [2] at the same time a
supporting material for the future userfaultfd-writeprotect work, since in
that work there will always be an explicit userfault writeprotect retry
for protected pages, and if that cannot resolve the page fault (e.g., when
userfaultfd-writeprotect is used in conjunction with swapped pages) then
we'll possibly need a 3rd retry of the page fault.  It might also benefit
other potential users who will have similar requirement like userfault
write-protection.

GUP code is not touched yet and will be covered in follow up patch.

Please read the thread below for more information.

[1] https://lore.kernel.org/lkml/20171102193644.GB22686@redhat.com/
[2] https://lore.kernel.org/lkml/20181230154648.GB9832@redhat.com/

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Tested-by: Brian Geffon <bgeffon@google.com>
Cc: Bobby Powers <bobbypowers@gmail.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Denis Plotnikov <dplotnikov@virtuozzo.com>
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: "Kirill A . Shutemov" <kirill@shutemov.name>
Cc: Martin Cracauer <cracauer@cons.org>
Cc: Marty McFadden <mcfadden8@llnl.gov>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Maya Gokhale <gokhale2@llnl.gov>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Pavel Emelyanov <xemul@openvz.org>
Link: http://lkml.kernel.org/r/20200220160246.9790-1-peterx@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-02 09:35:30 -07:00
..
alchemy MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
ar7 MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
ath25 MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
ath79 MIPS: ath79: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-02-19 10:34:22 -08:00
bcm47xx MIPS: BCM47XX: Add support for Netgear R6200 V1 2019-07-25 22:10:05 -07:00
bcm63xx MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
bmips MIPS: BMIPS: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-02-19 10:36:02 -08:00
boot MIPS: Loongson64: Add generic dts 2020-03-25 16:07:12 +01:00
cavium-octeon MIPS updates for v5.7: 2020-03-31 08:51:45 -07:00
cobalt MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
configs MIPS: CI20: defconfig: multiple improvements 2020-03-23 13:43:56 +01:00
crypto crypto: {arm,arm64,mips}/poly1305 - remove redundant non-reduction from emit 2020-01-16 15:18:12 +08:00
dec MIPS: pass non-NULL dev_id on shared request_irq() 2020-03-16 16:04:49 +01:00
emma MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
fw MIPS: do not compile generic functions for CONFIG_CAVIUM_OCTEON_SOC 2020-03-25 16:07:13 +01:00
generic MIPS: generic: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-02-19 10:36:07 -08:00
include asm-generic: make more kernel-space headers mandatory 2020-04-02 09:35:25 -07:00
jazz MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
jz4740 MIPS: jz4740: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-02-19 10:36:12 -08:00
kernel MIPS updates for v5.7: 2020-03-31 08:51:45 -07:00
kvm KVM: MIPS: Fold comparecount_func() into comparecount_wakeup() 2020-02-05 15:29:55 +01:00
lantiq remove ioremap_nocache and devm_ioremap_nocache 2020-01-06 09:45:59 +01:00
lasat MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
lib MIPS: do not compile generic functions for CONFIG_CAVIUM_OCTEON_SOC 2020-03-25 16:07:13 +01:00
loongson2ef MIPS: pass non-NULL dev_id on shared request_irq() 2020-03-16 16:04:49 +01:00
loongson32 MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
loongson64 MIPS: Loongson64: Load built-in dtbs 2020-03-25 16:07:12 +01:00
math-emu MIPS: Add MAC2008 Support 2020-01-22 15:56:08 -08:00
mm mm: allow VM_FAULT_RETRY for multiple times 2020-04-02 09:35:30 -07:00
mti-malta MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
net MIPS: BPF: Use sizeof_field() instead of FIELD_SIZEOF() 2020-01-10 11:33:35 -08:00
netlogic MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
oprofile MIPS: Loongson: Rename LOONGSON1 to LOONGSON32 2019-11-11 10:43:13 -08:00
paravirt mips: unify prom_putchar() declarations 2018-07-17 09:40:17 -07:00
pci The main MIPS changes for 5.6: 2020-01-31 11:28:31 -08:00
pic32 MIPS: pic32mzda: Drop pointless static qualifier 2020-02-28 12:44:39 +01:00
pistachio MIPS: Pistachio: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-02-19 10:36:21 -08:00
pmcs-msp71xx MIPS: pass non-NULL dev_id on shared request_irq() 2020-03-16 16:04:49 +01:00
pnx833x A batch of MIPS fixes: 2019-06-08 13:09:31 -07:00
power mips: check for dsp presence only once before save/restore 2019-10-07 10:58:53 -07:00
ralink MIPS: ralink: mt7621: Fix soc_device introduction 2020-03-28 17:26:36 +01:00
rb532 remove ioremap_nocache and devm_ioremap_nocache 2020-01-06 09:45:59 +01:00
sgi-ip22 MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
sgi-ip27 mfd: ioc3: Add driver for SGI IOC3 chip 2020-01-09 15:30:59 -08:00
sgi-ip30 MIPS: SGI-IP30: Check for valid pointer before using it 2020-01-22 10:15:45 -08:00
sgi-ip32 MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
sibyte treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
sni MIPS: pass non-NULL dev_id on shared request_irq() 2020-03-16 16:04:49 +01:00
tools kbuild: rename hostprogs-y/always to hostprogs/always-y 2020-02-04 01:53:07 +09:00
txx9 A batch of MIPS fixes: 2019-06-08 13:09:31 -07:00
vdso MIPS: vdso: Wrap -mexplicit-relocs in cc-option 2020-02-19 10:30:10 -08:00
vr41xx MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
Kbuild treewide: Add SPDX license identifier - Kbuild 2019-05-30 11:32:33 -07:00
Kbuild.platforms MIPS: add support for SGI Octane (IP30) 2019-11-01 14:58:56 -07:00
Kconfig MIPS updates for v5.7: 2020-03-31 08:51:45 -07:00
Kconfig.debug MIPS: cmdline: Remove redundant Kconfig defaults 2019-10-09 15:53:16 -07:00
Makefile Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2019-11-25 19:49:58 -08:00
Makefile.postlink MIPS: fix indentation of the 'RELOCS' message 2020-01-20 15:37:30 -08:00