1
0
Fork 0
alistair23-linux/arch/s390/include/asm
Vasily Gorbik 4f5260ee0c mm/gup: fix gup_fast with dynamic page table folding
commit d3f7b1bb20 upstream.

Currently to make sure that every page table entry is read just once
gup_fast walks perform READ_ONCE and pass pXd value down to the next
gup_pXd_range function by value e.g.:

  static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end,
                           unsigned int flags, struct page **pages, int *nr)
  ...
          pudp = pud_offset(&p4d, addr);

This function passes a reference on that local value copy to pXd_offset,
and might get the very same pointer in return.  This happens when the
level is folded (on most arches), and that pointer should not be
iterated.

On s390 due to the fact that each task might have different 5,4 or
3-level address translation and hence different levels folded the logic
is more complex and non-iteratable pointer to a local copy leads to
severe problems.

Here is an example of what happens with gup_fast on s390, for a task
with 3-level paging, crossing a 2 GB pud boundary:

  // addr = 0x1007ffff000, end = 0x10080001000
  static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end,
                           unsigned int flags, struct page **pages, int *nr)
  {
        unsigned long next;
        pud_t *pudp;

        // pud_offset returns &p4d itself (a pointer to a value on stack)
        pudp = pud_offset(&p4d, addr);
        do {
                // on second iteratation reading "random" stack value
                pud_t pud = READ_ONCE(*pudp);

                // next = 0x10080000000, due to PUD_SIZE/MASK != PGDIR_SIZE/MASK on s390
                next = pud_addr_end(addr, end);
                ...
        } while (pudp++, addr = next, addr != end); // pudp++ iterating over stack

        return 1;
  }

This happens since s390 moved to common gup code with commit
d1874a0c28 ("s390/mm: make the pxd_offset functions more robust") and
commit 1a42010cdc ("s390/mm: convert to the generic
get_user_pages_fast code").

s390 tried to mimic static level folding by changing pXd_offset
primitives to always calculate top level page table offset in pgd_offset
and just return the value passed when pXd_offset has to act as folded.

What is crucial for gup_fast and what has been overlooked is that
PxD_SIZE/MASK and thus pXd_addr_end should also change correspondingly.
And the latter is not possible with dynamic folding.

To fix the issue in addition to pXd values pass original pXdp pointers
down to gup_pXd_range functions.  And introduce pXd_offset_lockless
helpers, which take an additional pXd entry value parameter.  This has
already been discussed in

  https://lkml.kernel.org/r/20190418100218.0a4afd51@mschwideX1

Fixes: 1a42010cdc ("s390/mm: convert to the generic get_user_pages_fast code")
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: <stable@vger.kernel.org>	[5.2+]
Link: https://lkml.kernel.org/r/patch.git-943f1e5dcff2.your-ad-here.call-01599856292-ext-8676@work.hours
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-01 13:18:24 +02:00
..
fpu License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Kbuild Remove Mysterious Macro Intended to Obscure Weird Behaviours (mmiowb()) 2019-05-06 16:57:52 -07:00
airq.h s390/airq: use DMA memory for adapter interrupts 2019-06-15 12:25:05 +02:00
alternative-asm.h s390: add assembler macros for CPU alternatives 2018-03-28 08:38:27 +02:00
alternative.h s390: add a few more SPDX identifiers 2017-12-05 07:51:09 +01:00
ap.h s390/zcrypt: Fix wrong dispatching for control domain CPRBs 2019-05-28 14:49:38 +02:00
appldata.h s390/appldata: pass parameter list pointer to appldata_asm 2018-10-09 11:20:50 +02:00
archrandom.h s390/archrandom: Rework arch random implementation. 2018-05-30 11:18:04 +02:00
asm-prototypes.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
atomic.h locking/atomic, s390: Use s64 for atomic64 2019-06-03 12:32:56 +02:00
atomic_ops.h s390/atomic,bitops: mark function(s) __always_inline 2019-10-04 16:37:33 +02:00
barrier.h s390: add optimized array_index_mask_nospec 2018-02-05 07:51:41 +01:00
bitops.h s390/atomic,bitops: mark function(s) __always_inline 2019-10-04 16:37:33 +02:00
boot_data.h s390/ipl: read IPL report at early boot 2019-04-26 12:34:05 +02:00
bug.h s390/bug: add entry size to the __bug_table section 2019-05-02 13:54:11 +02:00
bugs.h s390: add a few more SPDX identifiers 2017-12-05 07:51:09 +01:00
cache.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ccwdev.h s390/cio: add basic protected virtualization support 2019-06-15 12:25:00 +02:00
ccwgroup.h s390/ccwgroup: add get_ccwgroupdev_by_busid() 2018-10-08 09:09:59 +02:00
checksum.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
chpid.h s390/cio: rename struct channel_path_desc 2018-03-26 16:13:11 +02:00
cio.h s390/cio: move struct node_descriptor to cio.h 2019-06-19 17:54:27 +02:00
clp.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cmb.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cmpxchg.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
compat.h asm-generic: Move common compat types to asm-generic/compat.h 2018-08-29 15:42:20 +02:00
cpacf.h s390: mark __cpacf_query() as __always_inline 2019-10-04 16:37:33 +02:00
cpcmd.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cpu.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cpu_mcf.h s390/cpum_cf_diag: Add support for s390 counter facility diagnostic trace 2019-02-22 09:19:56 +01:00
cpu_mf-insn.h s390/cpu_mf: add store cpu counter multiple instruction support 2019-02-22 09:19:52 +01:00
cpu_mf.h s390/cpu_mf: mark function(s) __always_inline 2019-10-04 16:37:33 +02:00
cpufeature.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cputime.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
crw.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
css_chars.h s390/cio: sanitize css_general_characteristics definition 2018-06-12 15:14:05 +02:00
ctl_reg.h arch: replace _BITUL() in kernel-space headers with BIT() 2019-07-16 19:23:22 -07:00
current.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
debug.h docs: s390: unify and update s390dbf kdocs at debug.c 2019-07-05 13:42:22 +02:00
delay.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
diag.h s390/kernel: introduce .dma sections 2019-04-29 10:47:10 +02:00
dis.h s390/tools: generate header files in arch/s390/include/generated/ 2018-01-23 07:36:53 +01:00
dma.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
dwarf.h s390/vdso: revise CFI annotations of vDSO functions 2017-12-13 10:51:36 +01:00
eadm.h s390/eadm: fix CONFIG_BLOCK include dependency 2018-02-02 10:47:14 +01:00
ebcdic.h s390: fix clang -Wpointer-sign warnigns in boot code 2019-05-03 17:17:58 +02:00
elf.h s390: report new CPU capabilities 2019-04-25 15:34:10 +02:00
exec.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
extable.h s390/kernel: introduce .dma sections 2019-04-29 10:47:10 +02:00
extmem.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
facility.h s390: fix stfle zero padding 2019-06-19 17:54:27 +02:00
fcx.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ftrace.h s390/ftrace: use HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 2019-05-02 13:54:11 +02:00
futex.h s390: remove all code using the access register mode 2017-11-14 11:01:47 +01:00
gmap.h s390/mm: use refcount_t for refcount 2019-08-21 12:41:43 +02:00
hardirq.h softirq/s390: Move default mutators of overwritten softirq mask to s390 2018-05-14 11:25:28 +02:00
hugetlb.h s390/mm: fix -Wunused-but-set-variable warnings 2019-10-04 16:37:33 +02:00
hw_irq.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
idals.h s390/idal: use struct_size() in kmalloc() 2019-06-04 15:03:18 +02:00
idle.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
io.h s390/pci: provide support for MIO instructions 2019-04-29 10:47:01 +02:00
ipl.h s390/kernel: introduce .dma sections 2019-04-29 10:47:10 +02:00
irq.h s390/pci: gather statistics for floating vs directed irqs 2019-04-29 10:47:01 +02:00
irqflags.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
isc.h KVM: s390: add gib_alert_irq_handler() 2019-02-05 14:29:23 +01:00
itcw.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
jump_label.h s390/jump_label: mark function(s) __always_inline 2019-10-04 16:37:33 +02:00
kasan.h s390/kasan: add option for 4-level paging support 2018-10-09 11:21:29 +02:00
kdebug.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
kexec.h s390/kernel: build a relocatable kernel 2019-04-29 10:47:10 +02:00
kprobes.h s390/kprobes: Remove jprobe implementation 2018-06-21 12:33:10 +02:00
kvm_host.h KVM: s390: reduce number of IO pins to 1 2020-07-16 08:16:32 +02:00
kvm_para.h KVM: Introduce paravirtualization hints and KVM_HINTS_DEDICATED 2018-03-06 18:40:44 +01:00
linkage.h s390/kernel: introduce .dma sections 2019-04-29 10:47:10 +02:00
livepatch.h livepatch: Remove klp_check_compiler_support() 2019-05-10 17:53:29 -04:00
lowcore.h s390: prevent leaking kernel address in BEAR 2020-04-13 10:48:06 +02:00
mem_detect.h s390/mem_detect: provide single get_mem_detect_end 2019-08-26 12:51:18 +02:00
mem_encrypt.h s390/mm: Remove sev_active() function 2019-08-09 22:52:11 +10:00
mmu.h s390/vdso: avoid 64-bit vdso mapping for compat tasks 2018-09-20 13:20:29 +02:00
mmu_context.h s390/vdso: correct vdso mapping for compat tasks 2019-01-11 17:12:02 +01:00
mmzone.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
module.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nmi.h arch: replace _BITUL() in kernel-space headers with BIT() 2019-07-16 19:23:22 -07:00
nospec-branch.h s390: correct nospec auto detection init order 2018-04-11 17:46:00 +02:00
nospec-insn.h s390/nospec: rename assembler generated expoline thunks 2019-05-02 13:54:11 +02:00
numa.h s390/numa: set node distance to LOCAL_DISTANCE 2020-09-03 11:26:50 +02:00
os_info.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
page-states.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
page.h s390/mm: Explicitly compare PAGE_DEFAULT_KEY against zero in storage_key_init_range 2020-02-28 17:22:28 +01:00
pci.h s390/pci: Recover handle in clp_set_pci_fn() 2020-02-24 08:37:03 +01:00
pci_clp.h s390/pci: fix struct definition for set PCI function 2019-05-28 14:49:29 +02:00
pci_debug.h Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux 2017-11-13 11:47:01 -08:00
pci_dma.h s390: move s390_pci_dma_ops to asm/pci_dma.h 2018-01-10 16:41:19 +01:00
pci_insn.h s390: fix setting of mio addressing control 2019-07-11 20:40:02 +02:00
pci_io.h s390/pci: Fix s390_mmio_read/write with MIO 2020-05-27 17:46:47 +02:00
percpu.h s390: don't trace preemption in percpu macros 2020-09-09 19:12:22 +02:00
perf_event.h s390/cpum_sf: Support ioctl PERF_EVENT_IOC_PERIOD 2019-09-19 12:56:07 +02:00
pgalloc.h s390/mm: add mm_pxd_folded() checks to pxd_free() 2019-12-31 16:44:30 +01:00
pgtable.h mm/gup: fix gup_fast with dynamic page table folding 2020-10-01 13:18:24 +02:00
pkey.h s390/pkey: pkey cleanup: narrow in-kernel API, fix some variable types 2019-08-21 12:58:53 +02:00
pnet.h s390/net: move pnet constants 2019-02-07 18:06:18 -08:00
preempt.h preempt: Move PREEMPT_NEED_RESCHED definition into arch code 2018-12-07 12:35:46 +00:00
processor.h s390: prevent leaking kernel address in BEAR 2020-04-13 10:48:06 +02:00
ptrace.h arch: replace _BITUL() in kernel-space headers with BIT() 2019-07-16 19:23:22 -07:00
purgatory.h s390/purgatory: Remove duplicate variable definitions 2018-07-06 08:47:51 +02:00
qdio.h s390/qdio: fill SL with absolute addresses 2020-03-12 13:00:15 +01:00
runtime_instr.h s390/runtime instrumentation: provide uapi header file 2018-02-02 10:47:15 +01:00
schid.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sclp.h s390/ipl: Fix detection of has_secure attribute 2019-07-11 20:40:02 +02:00
scsw.h s390: fix comment for scsw_cmd_is_valid_sctl 2018-02-22 15:31:24 +01:00
seccomp.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sections.h locking/lockdep: check for freed initmem in static_obj() 2019-04-29 10:47:10 +02:00
serial.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
set_memory.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
setup.h s390: prevent leaking kernel address in BEAR 2020-04-13 10:48:06 +02:00
shmparam.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
signal.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sigp.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
smp.h s390: enforce CONFIG_HOTPLUG_CPU 2019-06-07 10:09:42 +02:00
sparsemem.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
spinlock.h s390: enforce CONFIG_SMP 2019-06-07 10:09:37 +02:00
spinlock_types.h Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux 2017-11-13 11:47:01 -08:00
stacktrace.h s390: avoid misusing CALL_ON_STACK for task stack setup 2020-10-01 13:17:22 +02:00
stp.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
string.h s390/kasan: provide uninstrumented __strlen 2019-08-21 12:58:52 +02:00
switch_to.h s390: always save and restore all registers on context switch 2017-12-05 07:51:08 +01:00
syscall.h s390: fix syscall_get_error for compat processes 2020-06-24 17:50:50 +02:00
syscall_wrapper.h s390: syscall_wrapper: avoid clang warning 2019-04-11 13:36:51 +02:00
sysinfo.h s390/sysinfo: add and display licensed internal code identifier 2018-02-02 10:47:15 +01:00
termios.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
thread_info.h arch: replace _BITUL() in kernel-space headers with BIT() 2019-07-16 19:23:22 -07:00
timex.h s390/time: Fix clk type in get_tod_clock 2020-02-19 19:53:07 +01:00
tlb.h s390/tlb: Convert to generic mmu_gather 2019-04-03 10:32:57 +02:00
tlbflush.h s390: enforce CONFIG_SMP 2019-06-07 10:09:37 +02:00
topology.h s390/numa: set node distance to LOCAL_DISTANCE 2020-09-03 11:26:50 +02:00
uaccess.h s390: Change s390_kernel_write() return type to match memcpy() 2020-07-16 08:16:48 +02:00
unistd.h s390: wire up clone3 system call 2019-07-23 10:45:53 +02:00
unwind.h s390/unwind: fix mixing regs and sp 2019-10-31 17:26:48 +01:00
uprobes.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
user.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
uv.h s390/uv: introduce guest side ultravisor code 2019-04-10 17:47:21 +02:00
vdso.h s390/vdso: fix vDSO clock_getres() 2020-06-30 15:37:05 -04:00
vga.h s390: add a few more SPDX identifiers 2017-12-05 07:51:09 +01:00
vmlinux.lds.h s390: introduce .boot.preserved.data section 2019-04-10 17:47:09 +02:00
vtime.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
vtimer.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
vx-insn.h s390: add alignment hints to vector load and store 2019-02-07 11:57:10 +01:00
xor.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00