Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mips: vdso: prefer do_mmap() to mmap_region()

Patch series "mm: update mips to use do_mmap(), make mmap_region()
internal".

Currently the only user of mmap_region() outside of the memory management
code is the MIPS VDSO implementation.

This uses mmap_region() to map a 'delay slot emulation page' at the top of
the stack which is read-only and executable.

This mapping requires that an already-acquired mmap write lock is utilised
and that uffd and populate logic is ignored. This rules out vm_mmap(),
however do_mmap() fits the bill.

Adapt this code to use do_mmap() and then once done, make mmap_region()
internal and userland testable, and avoid any other uses of mmap_region(),
which is absolutely and strictly an internal mm function which bypasses a
great number of checks and logic.


This patch (of 2):

mmap_region() is an internal memory management implementation detail that
is not intended to be used outside of the memory management subsystem.

Map the delay slot emulation page using do_mmap() which makes use of the
already-held mmap write lock and bypasses unneeded populate and
userfaultfd logic.

This should have the precise same behaviour as the existing logic.

Link: https://lkml.kernel.org/r/cover.1735819274.git.lorenzo.stoakes@oracle.com
Link: https://lkml.kernel.org/r/ef076e381570f709e5c2c142dc030ec5b3309a0e.1735819274.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: Jann Horn <jannh@google.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
c4f1b56f 4f79384a

+6 -4
+6 -4
arch/mips/kernel/vdso.c
··· 11 11 #include <linux/ioport.h> 12 12 #include <linux/kernel.h> 13 13 #include <linux/mm.h> 14 + #include <linux/mman.h> 14 15 #include <linux/random.h> 15 16 #include <linux/sched.h> 16 17 #include <linux/slab.h> ··· 98 97 return -EINTR; 99 98 100 99 if (IS_ENABLED(CONFIG_MIPS_FP_SUPPORT)) { 100 + unsigned long unused; 101 + 101 102 /* Map delay slot emulation page */ 102 - base = mmap_region(NULL, STACK_TOP, PAGE_SIZE, 103 - VM_READ | VM_EXEC | 104 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC, 105 - 0, NULL); 103 + base = do_mmap(NULL, STACK_TOP, PAGE_SIZE, PROT_READ | PROT_EXEC, 104 + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, 0, 0, &unused, 105 + NULL); 106 106 if (IS_ERR_VALUE(base)) { 107 107 ret = base; 108 108 goto out;