1
0
Fork 0
alistair23-linux/arch/arm
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
..
boot Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2020-03-31 17:29:33 -07:00
common ARM: sa1111: Fix irq_retrigger callback return value 2020-03-16 15:48:54 +00:00
configs ARM: socfpga_defconfig: add back DEBUGFS 2020-03-04 08:51:55 -08:00
crypto crypto: arm/chacha - fix build failured when kernel mode NEON is disabled 2020-01-22 16:21:11 +08:00
include asm-generic: make more kernel-space headers mandatory 2020-04-02 09:35:25 -07:00
kernel CPU (hotplug) updates: 2020-03-30 18:06:39 -07:00
kvm KVM: Drop kvm_arch_vcpu_setup() 2020-01-27 19:59:28 +01:00
lib ARM: 8958/1: rename missed uaccess .fixup section 2020-02-21 17:03:21 +00:00
mach-actions
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed ARM: SoC fixes 2019-09-30 10:04:28 -07:00
mach-at91 ARM: at91: pm: use of_device_id array to find the proper shdwc node 2020-01-10 23:40:31 +01:00
mach-axxia
mach-bcm ARM: SoC platform updates 2020-02-08 13:55:25 -08:00
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci ARM: SoC: late updates 2020-02-08 14:17:27 -08:00
mach-digicolor
mach-dove
mach-ebsa110
mach-efm32
mach-ep93xx Merge branch 'spi-5.4' into spi-next 2019-09-15 10:32:06 +01:00
mach-exynos ARM: SoC platform updates 2020-02-08 13:55:25 -08:00
mach-footbridge ARM: 8911/1: move pcibios_report_status to <asm/pci.h> 2019-10-27 21:14:40 +00:00
mach-gemini
mach-highbank
mach-hisi ARM: hisi: drop useless depend on ARCH_MULTI_V7 2019-10-26 15:31:22 +08:00
mach-imx ARM: imx: build v7_cpu_resume() unconditionally 2020-02-13 21:21:44 +08:00
mach-integrator
mach-iop32x
mach-ixp4xx ARM/net: ixp4xx: Pass ethernet physical base as resource 2020-01-12 12:59:53 -08:00
mach-keystone
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson ARM: meson: Drop unneeded select of COMMON_CLK 2020-02-29 08:16:20 -08:00
mach-milbeaut
mach-mmp ARM: mmp: do not divide the clock rate 2020-01-06 09:18:50 -08:00
mach-moxart
mach-mv78xx0
mach-mvebu
mach-mxs
mach-nomadik
mach-npcm ARM: npcm: Bring back GPIOLIB support 2020-02-09 03:44:51 -08:00
mach-nspire
mach-omap1 ARM: OMAP1: drop duplicated dependency on ARCH_OMAP1 2019-11-11 12:30:39 -08:00
mach-omap2 ARM: OMAP2+: Fix compile if CONFIG_HAVE_ARM_SMCCC is not set 2020-02-26 10:49:25 -08:00
mach-orion5x
mach-oxnas
mach-picoxcell
mach-prima2
mach-pxa USB/Thunderbolt/PHY driver updates for 5.6-rc1 2020-01-29 10:09:44 -08:00
mach-qcom
mach-rda
mach-realview
mach-rockchip
mach-rpc
mach-s3c24xx ARM: s3c24xx: Switch to atomic pwm API in rx1950 2020-01-21 20:56:47 +01:00
mach-s3c64xx ARM: SoC platform updates 2020-02-08 13:55:25 -08:00
mach-s5pv210
mach-sa1100
mach-shmobile remove ioremap_nocache and devm_ioremap_nocache 2020-01-06 09:45:59 +01:00
mach-socfpga arm: socfpga: execute cold reboot by default 2019-11-22 12:12:10 -06:00
mach-spear
mach-sti
mach-stm32
mach-sunxi ARM: sunxi: Fix CPU powerdown on A83T 2019-10-29 09:09:56 +01:00
mach-tango
mach-tegra ARM: tegra: Use clk_m CPU on Tegra124 LP1 resume 2020-01-08 12:58:46 +01:00
mach-u300 pinctrl: Allow modules to use pinctrl_[un]register_mappings 2019-12-30 14:27:17 +01:00
mach-uniphier
mach-ux500 mfd: db8500-prcmu: Support U8420-sysclk firmware 2019-11-11 08:45:04 +00:00
mach-versatile
mach-vexpress ARM: vexpress: Set-up shared OPP table instead of individual for each CPU 2019-12-09 11:52:50 +00:00
mach-vt8500
mach-zx
mach-zynq ARM: zynq: use physical cpuid in zynq_slcr_cpu_stop/start 2020-01-08 15:21:09 +01:00
mm mm: allow VM_FAULT_RETRY for multiple times 2020-04-02 09:35:30 -07:00
net ARM: net: bpf: Improve prologue code sequence 2019-12-11 14:34:26 +01:00
nwfpe
oprofile
plat-omap dmaengine: ti: omap-dma: Configure global priority register directly 2019-12-30 09:45:25 -08:00
plat-orion
plat-pxa spi: pxa2xx: No need to keep pointer to platform device 2019-10-18 18:24:50 +01:00
plat-samsung ARM: samsung: Rename Samsung and Exynos to lowercase 2020-01-07 20:44:22 +01:00
plat-versatile
probes
tools threads-v5.6 2020-01-29 19:38:34 -08:00
vdso kbuild: rename hostprogs-y/always to hostprogs/always-y 2020-02-04 01:53:07 +09:00
vfp
xen dma-mapping updates for 5.5-rc1 2019-11-28 11:16:43 -08:00
Kconfig ARM/arm64: vdso: Use common vdso clock mode storage 2020-02-17 20:12:16 +01:00
Kconfig-nommu
Kconfig.debug ARM: debug-ll: select DEBUG_AT91_RM9200_DBGU for sam9x60 2019-12-10 00:45:30 +01:00
Makefile ARM: 8961/2: Fix Kbuild issue caused by per-task stack protector GCC plugin 2020-02-21 17:03:22 +00:00