mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
* refs/heads/tmp-2bb70f4: ANDROID: virtio: virtio_input: Set the amount of multitouch slots in virtio input ANDROID: dummy_cpufreq: Implement get() rtlwifi: Fix potential overflow on P2P code ANDROID: cpufreq: create dummy cpufreq driver ANDROID: Allow DRM_IOCTL_MODE_*_DUMB for render clients. ANDROID: sdcardfs: evict dentries on fscrypt key removal ANDROID: fscrypt: add key removal notifier chain ANDROID: Move from clang r353983c to r365631c ANDROID: move up spin_unlock_bh() ahead of remove_proc_entry() BACKPORT: arm64: tags: Preserve tags for addresses translated via TTBR1 UPSTREAM: arm64: memory: Implement __tag_set() as common function UPSTREAM: arm64/mm: fix variable 'tag' set but not used UPSTREAM: arm64: avoid clang warning about self-assignment ANDROID: refactor build.config files to remove duplication UPSTREAM: mm: vmalloc: show number of vmalloc pages in /proc/meminfo BACKPORT: PM/sleep: Expose suspend stats in sysfs UPSTREAM: power: supply: Init device wakeup after device_add() UPSTREAM: PM / wakeup: Unexport wakeup_source_sysfs_{add,remove}() UPSTREAM: PM / wakeup: Register wakeup class kobj after device is added BACKPORT: PM / wakeup: Fix sysfs registration error path BACKPORT: PM / wakeup: Show wakeup sources stats in sysfs UPSTREAM: PM / wakeup: Print warn if device gets enabled as wakeup source during sleep UPSTREAM: PM / wakeup: Use wakeup_source_register() in wakelock.c UPSTREAM: PM / wakeup: Only update last time for active wakeup sources UPSTREAM: PM / core: Add support to skip power management in device/driver model cuttlefish-4.14: Enable CONFIG_DM_SNAPSHOT ANDROID: cuttlefish_defconfig: Enable BPF_JIT and BPF_JIT_ALWAYS_ON UPSTREAM: netfilter: xt_IDLETIMER: fix sysfs callback function type UPSTREAM: mm: untag user pointers in mmap/munmap/mremap/brk UPSTREAM: vfio/type1: untag user pointers in vaddr_get_pfn UPSTREAM: media/v4l2-core: untag user pointers in videobuf_dma_contig_user_get UPSTREAM: drm/radeon: untag user pointers in radeon_gem_userptr_ioctl BACKPORT: drm/amdgpu: untag user pointers UPSTREAM: userfaultfd: untag user pointers UPSTREAM: fs/namespace: untag user pointers in copy_mount_options UPSTREAM: mm: untag user pointers in get_vaddr_frames UPSTREAM: mm: untag user pointers in mm/gup.c BACKPORT: mm: untag user pointers passed to memory syscalls BACKPORT: lib: untag user pointers in strn*_user UPSTREAM: arm64: Fix reference to docs for ARM64_TAGGED_ADDR_ABI UPSTREAM: selftests, arm64: add kernel headers path for tags_test BACKPORT: arm64: Relax Documentation/arm64/tagged-pointers.rst UPSTREAM: arm64: Define Documentation/arm64/tagged-address-abi.rst UPSTREAM: arm64: Change the tagged_addr sysctl control semantics to only prevent the opt-in UPSTREAM: arm64: Tighten the PR_{SET, GET}_TAGGED_ADDR_CTRL prctl() unused arguments UPSTREAM: selftests, arm64: fix uninitialized symbol in tags_test.c UPSTREAM: arm64: mm: Really fix sparse warning in untagged_addr() UPSTREAM: selftests, arm64: add a selftest for passing tagged pointers to kernel BACKPORT: arm64: Introduce prctl() options to control the tagged user addresses ABI UPSTREAM: thread_info: Add update_thread_flag() helpers UPSTREAM: arm64: untag user pointers in access_ok and __uaccess_mask_ptr UPSTREAM: uaccess: add noop untagged_addr definition BACKPORT: block: annotate refault stalls from IO submission ext4: add verity flag check for dax ANDROID: usb: gadget: Fix dependency for f_accessory ANDROID: sched: fair: balance for single core cluster UPSTREAM: mm/kasan: fix false positive invalid-free reports with CONFIG_KASAN_SW_TAGS=y f2fs: add a condition to detect overflow in f2fs_ioc_gc_range() f2fs: fix to add missing F2FS_IO_ALIGNED() condition f2fs: fix to fallback to buffered IO in IO aligned mode f2fs: fix to handle error path correctly in f2fs_map_blocks f2fs: fix extent corrupotion during directIO in LFS mode f2fs: check all the data segments against all node ones f2fs: Add a small clarification to CONFIG_FS_F2FS_FS_SECURITY f2fs: fix inode rwsem regression f2fs: fix to avoid accessing uninitialized field of inode page in is_alive() f2fs: avoid infinite GC loop due to stale atomic files f2fs: Fix indefinite loop in f2fs_gc() f2fs: convert inline_data in prior to i_size_write f2fs: fix error path of f2fs_convert_inline_page() f2fs: add missing documents of reserve_root/resuid/resgid f2fs: fix flushing node pages when checkpoint is disabled f2fs: enhance f2fs_is_checkpoint_ready()'s readability f2fs: clean up __bio_alloc()'s parameter f2fs: fix wrong error injection path in inc_valid_block_count() f2fs: fix to writeout dirty inode during node flush f2fs: optimize case-insensitive lookups f2fs: introduce f2fs_match_name() for cleanup f2fs: Fix indefinite loop in f2fs_gc() f2fs: allocate memory in batch in build_sit_info() f2fs: fix to avoid data corruption by forbidding SSR overwrite f2fs: Fix build error while CONFIG_NLS=m Revert "f2fs: avoid out-of-range memory access" f2fs: cleanup the code in build_sit_entries. f2fs: fix wrong available node count calculation f2fs: remove duplicate code in f2fs_file_write_iter f2fs: fix to migrate blocks correctly during defragment f2fs: use wrapped f2fs_cp_error() f2fs: fix to use more generic EOPNOTSUPP f2fs: use wrapped IS_SWAPFILE() f2fs: Support case-insensitive file name lookups f2fs: include charset encoding information in the superblock fs: Reserve flag for casefolding f2fs: fix to avoid call kvfree under spinlock fs: f2fs: Remove unnecessary checks of SM_I(sbi) in update_general_status() f2fs: disallow direct IO in atomic write f2fs: fix to handle quota_{on,off} correctly f2fs: fix to detect cp error in f2fs_setxattr() f2fs: fix to spread f2fs_is_checkpoint_ready() f2fs: support fiemap() for directory inode f2fs: fix to avoid discard command leak f2fs: fix to avoid tagging SBI_QUOTA_NEED_REPAIR incorrectly f2fs: fix to drop meta/node pages during umount f2fs: disallow switching io_bits option during remount f2fs: fix panic of IO alignment feature f2fs: introduce {page,io}_is_mergeable() for readability f2fs: fix livelock in swapfile writes f2fs: add fs-verity support ext4: update on-disk format documentation for fs-verity ext4: add fs-verity read support ext4: add basic fs-verity support fs-verity: support builtin file signatures fs-verity: add SHA-512 support fs-verity: implement FS_IOC_MEASURE_VERITY ioctl fs-verity: implement FS_IOC_ENABLE_VERITY ioctl fs-verity: add data verification hooks for ->readpages() fs-verity: add the hook for file ->setattr() fs-verity: add the hook for file ->open() fs-verity: add inode and superblock fields fs-verity: add Kconfig and the helper functions for hashing fs: uapi: define verity bit for FS_IOC_GETFLAGS fs-verity: add UAPI header fs-verity: add MAINTAINERS file entry fs-verity: add a documentation file ext4: fix kernel oops caused by spurious casefold flag ext4: fix coverity warning on error path of filename setup ext4: optimize case-insensitive lookups ext4: fix dcache lookup of !casefolded directories unicode: update to Unicode 12.1.0 final unicode: add missing check for an error return from utf8lookup() ext4: export /sys/fs/ext4/feature/casefold if Unicode support is present unicode: refactor the rule for regenerating utf8data.h ext4: Support case-insensitive file name lookups ext4: include charset encoding information in the superblock unicode: update unicode database unicode version 12.1.0 unicode: introduce test module for normalized utf8 implementation unicode: implement higher level API for string handling unicode: reduce the size of utf8data[] unicode: introduce code for UTF-8 normalization unicode: introduce UTF-8 character database ext4 crypto: fix to check feature status before get policy fscrypt: document the new ioctls and policy version ubifs: wire up new fscrypt ioctls f2fs: wire up new fscrypt ioctls ext4: wire up new fscrypt ioctls fscrypt: require that key be added when setting a v2 encryption policy fscrypt: add FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS ioctl fscrypt: allow unprivileged users to add/remove keys for v2 policies fscrypt: v2 encryption policy support fscrypt: add an HKDF-SHA512 implementation fscrypt: add FS_IOC_GET_ENCRYPTION_KEY_STATUS ioctl fscrypt: add FS_IOC_REMOVE_ENCRYPTION_KEY ioctl fscrypt: add FS_IOC_ADD_ENCRYPTION_KEY ioctl fscrypt: rename keyinfo.c to keysetup.c fscrypt: move v1 policy key setup to keysetup_v1.c fscrypt: refactor key setup code in preparation for v2 policies fscrypt: rename fscrypt_master_key to fscrypt_direct_key fscrypt: add ->ci_inode to fscrypt_info fscrypt: use FSCRYPT_* definitions, not FS_* fscrypt: use FSCRYPT_ prefix for uapi constants fs, fscrypt: move uapi definitions to new header <linux/fscrypt.h> fscrypt: use ENOPKG when crypto API support missing fscrypt: improve warnings for missing crypto API support fscrypt: improve warning messages for unsupported encryption contexts fscrypt: make fscrypt_msg() take inode instead of super_block fscrypt: clean up base64 encoding/decoding fscrypt: remove loadable module related code ANDROID: arm64: bpf: implement arch_bpf_jit_check_func ANDROID: bpf: validate bpf_func when BPF_JIT is enabled with CFI UPSTREAM: kcm: use BPF_PROG_RUN UPSTREAM: psi: get poll_work to run when calling poll syscall next time UPSTREAM: sched/psi: Do not require setsched permission from the trigger creator UPSTREAM: sched/psi: Reduce psimon FIFO priority BACKPORT: arm64: Add support for relocating the kernel with RELR relocations ANDROID: Log which device failed to suspend in dpm_suspend_start() ANDROID: Revert "ANDROID: sched: Disallow WALT with CFS bandwidth control" ANDROID: sched: WALT: Add support for CFS_BANDWIDTH ANDROID: sched: WALT: Refactor cumulative runnable average fixup ANDROID: sched: Disallow WALT with CFS bandwidth control fscrypt: document testing with xfstests fscrypt: remove selection of CONFIG_CRYPTO_SHA256 fscrypt: remove unnecessary includes of ratelimit.h fscrypt: don't set policy for a dead directory fscrypt: decrypt only the needed blocks in __fscrypt_decrypt_bio() fscrypt: support decrypting multiple filesystem blocks per page fscrypt: introduce fscrypt_decrypt_block_inplace() fscrypt: handle blocksize < PAGE_SIZE in fscrypt_zeroout_range() fscrypt: support encrypting multiple filesystem blocks per page fscrypt: introduce fscrypt_encrypt_block_inplace() fscrypt: clean up some BUG_ON()s in block encryption/decryption fscrypt: rename fscrypt_do_page_crypto() to fscrypt_crypt_block() fscrypt: remove the "write" part of struct fscrypt_ctx fscrypt: simplify bounce page handling ANDROID: fiq_debugger: remove UPSTREAM: lib/test_meminit.c: use GFP_ATOMIC in RCU critical section UPSTREAM: mm: slub: Fix slab walking for init_on_free UPSTREAM: lib/test_meminit.c: minor test fixes UPSTREAM: lib/test_meminit.c: fix -Wmaybe-uninitialized false positive UPSTREAM: lib: introduce test_meminit module UPSTREAM: mm: init: report memory auto-initialization features at boot time BACKPORT: mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options UPSTREAM: arm64: move jump_label_init() before parse_early_param() ANDROID: Add a tracepoint for mapping inode to full path BACKPORT: arch: add pidfd and io_uring syscalls everywhere UPSTREAM: dma-buf: add show_fdinfo handler UPSTREAM: dma-buf: add DMA_BUF_SET_NAME ioctls BACKPORT: dma-buf: give each buffer a full-fledged inode ANDROID: fix kernelci build-break UPSTREAM: drm/virtio: Fix cache entry creation race. UPSTREAM: drm/virtio: Wake up all waiters when capset response comes in. UPSTREAM: drm/virtio: Ensure cached capset entries are valid before copying. UPSTREAM: drm/virtio: use u64_to_user_ptr macro UPSTREAM: drm/virtio: remove irrelevant DRM_UNLOCKED flag UPSTREAM: drm/virtio: Remove redundant return type UPSTREAM: drm/virtio: allocate fences with GFP_KERNEL UPSTREAM: drm/virtio: add trace events for commands UPSTREAM: drm/virtio: trace drm_fence_emit BACKPORT: drm/virtio: set seqno for dma-fence BACKPORT: drm/virtio: move drm_connector_update_edid_property() call UPSTREAM: drm/virtio: add missing drm_atomic_helper_shutdown() call. BACKPORT: drm/virtio: rework resource creation workflow. UPSTREAM: drm/virtio: params struct for virtio_gpu_cmd_create_resource_3d() BACKPORT: drm/virtio: params struct for virtio_gpu_cmd_create_resource() BACKPORT: drm/virtio: use struct to pass params to virtio_gpu_object_create() UPSTREAM: drm/virtio: add virtio-gpu-features debugfs file. UPSTREAM: drm/virtio: remove set but not used variable 'vgdev' BACKPORT: drm/virtio: implement prime export UPSTREAM: drm/virtio: remove prime pin/unpin callbacks. UPSTREAM: drm/virtio: implement prime mmap UPSTREAM: drm/virtio: drop virtio_gpu_fence_cleanup() UPSTREAM: drm/virtio: fix pageflip flush UPSTREAM: drm/virtio: log error responses UPSTREAM: drm/virtio: Add missing virtqueue reset UPSTREAM: drm/virtio: Remove incorrect kfree() UPSTREAM: drm/virtio: virtio_gpu_cmd_resource_create_3d: drop unused fence arg UPSTREAM: drm/virtio: fence: pass plain pointer BACKPORT: drm/virtio: add edid support UPSTREAM: virtio-gpu: add VIRTIO_GPU_F_EDID feature BACKPORT: drm/virtio: fix memory leak of vfpriv on error return path UPSTREAM: drm/virtio: bump driver version after explicit synchronization addition UPSTREAM: drm/virtio: add in/out fence support for explicit synchronization UPSTREAM: drm/virtio: add uapi for in and out explicit fences UPSTREAM: drm/virtio: add virtio_gpu_alloc_fence() UPSTREAM: drm/virtio: Handle error from virtio_gpu_resource_id_get UPSTREAM: gpu/drm/virtio/virtgpu_vq.c: Use kmem_cache_zalloc UPSTREAM: drm/virtio: fix resource id handling UPSTREAM: drm/virtio: drop resource_id argument. UPSTREAM: drm/virtio: use virtio_gpu_object->hw_res_handle in virtio_gpu_resource_create_ioctl() UPSTREAM: drm/virtio: use virtio_gpu_object->hw_res_handle in virtio_gpu_mode_dumb_create() UPSTREAM: drm/virtio: use virtio_gpu_object->hw_res_handle in virtio_gpufb_create() BACKPORT: drm/virtio: track created object state UPSTREAM: drm/virtio: document drm_dev_set_unique workaround UPSTREAM: virtio: Support prime objects vmap/vunmap UPSTREAM: virtio: Rework virtio_gpu_object_kmap() UPSTREAM: virtio: Add virtio_gpu_object_kunmap() UPSTREAM: drm/virtio: pass virtio_gpu_object to virtio_gpu_cmd_transfer_to_host_{2d, 3d} UPSTREAM: drm/virtio: add dma sync for dma mapped virtio gpu framebuffer pages UPSTREAM: drm/virtio: Remove set but not used variable 'bo' UPSTREAM: drm/virtio: add iommu support. UPSTREAM: drm/virtio: add virtio_gpu_object_detach() function UPSTREAM: drm/virtio: track virtual output state UPSTREAM: drm/virtio: fix bounds check in virtio_gpu_cmd_get_capset() UPSTREAM: gpu: drm: virtio: code cleanup UPSTREAM: drm/virtio: Place GEM BOs in drm_framebuffer UPSTREAM: drm/virtio: fix mode_valid's return type UPSTREAM: drm/virtio: Add spaces around operators UPSTREAM: drm/virtio: Remove multiple blank lines UPSTREAM: drm/virtio: Replace 'unsigned' for 'unsigned int' UPSTREAM: drm/virtio: Remove return from void function UPSTREAM: drm/virtio: Add */ in block comments to separate line UPSTREAM: drm/virtio: Add blank line after variable declarations UPSTREAM: drm/virtio: Add tabs at the start of a line UPSTREAM: drm/virtio: Don't return invalid caps on timeout UPSTREAM: virtgpu: remove redundant task_comm copying UPSTREAM: drm/virtio: add create_handle support. UPSTREAM: drm: virtio: replace reference/unreference with get/put UPSTREAM: drm/virtio: Replace instances of reference/unreference with get/put UPSTREAM: drm: byteorder: add DRM_FORMAT_HOST_* UPSTREAM: drm: add drm_connector_attach_edid_property() BACKPORT: drm/prime: Add drm_gem_prime_mmap() f2fs: fix build error on android tracepoints ANDROID: cuttlefish_defconfig: Enable CAN/VCAN UPSTREAM: pidfd: fix a poll race when setting exit_state BACKPORT: arch: wire-up pidfd_open() BACKPORT: pid: add pidfd_open() UPSTREAM: pidfd: add polling support UPSTREAM: signal: improve comments UPSTREAM: fork: do not release lock that wasn't taken BACKPORT: signal: support CLONE_PIDFD with pidfd_send_signal BACKPORT: clone: add CLONE_PIDFD UPSTREAM: Make anon_inodes unconditional UPSTREAM: signal: use fdget() since we don't allow O_PATH UPSTREAM: signal: don't silently convert SI_USER signals to non-current pidfd BACKPORT: signal: add pidfd_send_signal() syscall UPSTREAM: net-ipv6-ndisc: add support for RFC7710 RA Captive Portal Identifier ANDROID: fix up 9p filesystem due to CFI non-upstream patches f2fs: use EINVAL for superblock with invalid magic f2fs: fix to read source block before invalidating it f2fs: remove redundant check from f2fs_setflags_common() f2fs: use generic checking function for FS_IOC_FSSETXATTR f2fs: use generic checking and prep function for FS_IOC_SETFLAGS ubifs, fscrypt: cache decrypted symlink target in ->i_link vfs: use READ_ONCE() to access ->i_link fs, fscrypt: clear DCACHE_ENCRYPTED_NAME when unaliasing directory ANDROID: (arm64) cuttlefish_defconfig: enable CONFIG_CPU_FREQ_TIMES ANDROID: xfrm: remove in_compat_syscall() checks ANDROID: enable CONFIG_RTC_DRV_TEST on cuttlefish UPSTREAM: binder: Set end of SG buffer area properly. ANDROID: x86_64_cuttlefish_defconfig: enable CONFIG_CPU_FREQ_TIMES ANDROID: f2fs: add android fsync tracepoint ANDROID: f2fs: fix wrong android tracepoint fscrypt: cache decrypted symlink target in ->i_link fscrypt: fix race where ->lookup() marks plaintext dentry as ciphertext fscrypt: only set dentry_operations on ciphertext dentries fscrypt: fix race allowing rename() and link() of ciphertext dentries fscrypt: clean up and improve dentry revalidation fscrypt: use READ_ONCE() to access ->i_crypt_info fscrypt: remove WARN_ON_ONCE() when decryption fails fscrypt: drop inode argument from fscrypt_get_ctx() f2fs: improve print log in f2fs_sanity_check_ckpt() f2fs: avoid out-of-range memory access f2fs: fix to avoid long latency during umount f2fs: allow all the users to pin a file f2fs: support swap file w/ DIO f2fs: allocate blocks for pinned file f2fs: fix is_idle() check for discard type f2fs: add a rw_sem to cover quota flag changes f2fs: set SBI_NEED_FSCK for xattr corruption case f2fs: use generic EFSBADCRC/EFSCORRUPTED f2fs: Use DIV_ROUND_UP() instead of open-coding f2fs: print kernel message if filesystem is inconsistent f2fs: introduce f2fs_<level> macros to wrap f2fs_printk() f2fs: avoid get_valid_blocks() for cleanup f2fs: ioctl for removing a range from F2FS f2fs: only set project inherit bit for directory f2fs: separate f2fs i_flags from fs_flags and ext4 i_flags UPSTREAM: kasan: initialize tag to 0xff in __kasan_kmalloc UPSTREAM: x86/boot: Provide KASAN compatible aliases for string routines UPSTREAM: mm/kasan: Remove the ULONG_MAX stack trace hackery UPSTREAM: x86/uaccess, kasan: Fix KASAN vs SMAP UPSTREAM: x86/uaccess: Introduce user_access_{save,restore}() UPSTREAM: kasan: fix variable 'tag' set but not used warning UPSTREAM: Revert "x86_64: Increase stack size for KASAN_EXTRA" UPSTREAM: kasan: fix coccinelle warnings in kasan_p*_table UPSTREAM: kasan: fix kasan_check_read/write definitions BACKPORT: kasan: remove use after scope bugs detection. BACKPORT: kasan: turn off asan-stack for clang-8 and earlier UPSTREAM: slub: fix a crash with SLUB_DEBUG + KASAN_SW_TAGS UPSTREAM: kasan, slab: remove redundant kasan_slab_alloc hooks UPSTREAM: kasan, slab: make freelist stored without tags UPSTREAM: kasan, slab: fix conflicts with CONFIG_HARDENED_USERCOPY UPSTREAM: kasan: prevent tracing of tags.c UPSTREAM: kasan: fix random seed generation for tag-based mode UPSTREAM: slub: fix SLAB_CONSISTENCY_CHECKS + KASAN_SW_TAGS UPSTREAM: kasan, slub: fix more conflicts with CONFIG_SLAB_FREELIST_HARDENED UPSTREAM: kasan, slub: fix conflicts with CONFIG_SLAB_FREELIST_HARDENED UPSTREAM: kasan, slub: move kasan_poison_slab hook before page_address UPSTREAM: kasan, kmemleak: pass tagged pointers to kmemleak UPSTREAM: kasan: fix assigning tags twice UPSTREAM: kasan: mark file common so ftrace doesn't trace it UPSTREAM: kasan, arm64: remove redundant ARCH_SLAB_MINALIGN define UPSTREAM: kasan: fix krealloc handling for tag-based mode UPSTREAM: kasan: make tag based mode work with CONFIG_HARDENED_USERCOPY UPSTREAM: kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning BACKPORT: mm/memblock.c: skip kmemleak for kasan_init() UPSTREAM: kasan: add SPDX-License-Identifier mark to source files BACKPORT: kasan: update documentation UPSTREAM: kasan, arm64: select HAVE_ARCH_KASAN_SW_TAGS UPSTREAM: kasan: add __must_check annotations to kasan hooks BACKPORT: kasan, mm, arm64: tag non slab memory allocated via pagealloc UPSTREAM: kasan, arm64: add brk handler for inline instrumentation UPSTREAM: kasan: add hooks implementation for tag-based mode UPSTREAM: mm: move obj_to_index to include/linux/slab_def.h UPSTREAM: kasan: add bug reporting routines for tag-based mode UPSTREAM: kasan: split out generic_report.c from report.c UPSTREAM: kasan, mm: perform untagged pointers comparison in krealloc BACKPORT: kasan, arm64: enable top byte ignore for the kernel BACKPORT: kasan, arm64: fix up fault handling logic UPSTREAM: kasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU UPSTREAM: kasan, arm64: untag address in _virt_addr_is_linear UPSTREAM: kasan: add tag related helper functions BACKPORT: arm64: move untagged_addr macro from uaccess.h to memory.h BACKPORT: kasan: initialize shadow to 0xff for tag-based mode BACKPORT: kasan: rename kasan_zero_page to kasan_early_shadow_page BACKPORT: kasan, arm64: adjust shadow size for tag-based mode BACKPORT: kasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS UPSTREAM: kasan: rename source files to reflect the new naming scheme BACKPORT: kasan: move common generic and tag-based code to common.c UPSTREAM: kasan, slub: handle pointer tags in early_kmem_cache_node_alloc UPSTREAM: kasan, mm: change hooks signatures UPSTREAM: arm64: add EXPORT_SYMBOL_NOKASAN() BACKPORT: compiler: remove __no_sanitize_address_or_inline again UPSTREAM: mm/kasan/quarantine.c: make quarantine_lock a raw_spinlock_t UPSTREAM: lib/test_kasan.c: add tests for several string/memory API functions UPSTREAM: arm64: lib: use C string functions with KASAN enabled UPSTREAM: compiler: introduce __no_sanitize_address_or_inline UPSTREAM: arm64: Fix typo in a comment in arch/arm64/mm/kasan_init.c BACKPORT: kernel/memremap, kasan: make ZONE_DEVICE with work with KASAN BACKPORT: mm/mempool.c: remove unused argument in kasan_unpoison_element() and remove_element() UPSTREAM: kasan: only select SLUB_DEBUG with SYSFS=y UPSTREAM: kasan: depend on CONFIG_SLUB_DEBUG UPSTREAM: KASAN: prohibit KASAN+STRUCTLEAK combination UPSTREAM: arm64: kasan: avoid pfn_to_nid() before page array is initialized UPSTREAM: kasan: fix invalid-free test crashing the kernel UPSTREAM: kasan, slub: fix handling of kasan_slab_free hook UPSTREAM: slab, slub: skip unnecessary kasan_cache_shutdown() BACKPORT: kasan: make kasan_cache_create() work with 32-bit slab cache sizes UPSTREAM: locking/atomics: Instrument cmpxchg_double*() UPSTREAM: locking/atomics: Instrument xchg() UPSTREAM: locking/atomics: Simplify cmpxchg() instrumentation UPSTREAM: locking/atomics/x86: Reduce arch_cmpxchg64*() instrumentation UPSTREAM: locking/atomic, asm-generic, x86: Add comments for atomic instrumentation UPSTREAM: locking/atomic, asm-generic: Add KASAN instrumentation to atomic operations UPSTREAM: locking/atomic/x86: Switch atomic.h to use atomic-instrumented.h UPSTREAM: locking/atomic, asm-generic: Add asm-generic/atomic-instrumented.h BACKPORT: kasan, arm64: clean up KASAN_SHADOW_SCALE_SHIFT usage UPSTREAM: kasan: clean up KASAN_SHADOW_SCALE_SHIFT usage UPSTREAM: kasan: fix prototype author email address UPSTREAM: kasan: detect invalid frees UPSTREAM: kasan: unify code between kasan_slab_free() and kasan_poison_kfree() UPSTREAM: kasan: detect invalid frees for large mempool objects UPSTREAM: kasan: don't use __builtin_return_address(1) UPSTREAM: kasan: detect invalid frees for large objects UPSTREAM: kasan: add functions for unpoisoning stack variables UPSTREAM: kasan: add tests for alloca poisoning UPSTREAM: kasan: support alloca() poisoning UPSTREAM: kasan/Makefile: support LLVM style asan parameters BACKPORT: kasan: add compiler support for clang BACKPORT: fs: dcache: Revert "manually unpoison dname after allocation to shut up kasan's reports" UPSTREAM: fs/dcache: Use read_word_at_a_time() in dentry_string_cmp() UPSTREAM: lib/strscpy: Shut up KASAN false-positives in strscpy() UPSTREAM: compiler.h: Add read_word_at_a_time() function. UPSTREAM: compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() UPSTREAM: arm64/mm/kasan: don't use vmemmap_populate() to initialize shadow UPSTREAM: Documentation/features/KASAN: mark KASAN as supported only on 64-bit on x86 f2fs: Add option to limit required GC for checkpoint=disable f2fs: Fix accounting for unusable blocks f2fs: Fix root reserved on remount f2fs: Lower threshold for disable_cp_again f2fs: fix sparse warning f2fs: fix f2fs_show_options to show nodiscard mount option f2fs: add error prints for debugging mount failure f2fs: fix to do sanity check on segment bitmap of LFS curseg f2fs: add missing sysfs entries in documentation f2fs: fix to avoid deadloop if data_flush is on f2fs: always assume that the device is idle under gc_urgent f2fs: add bio cache for IPU f2fs: allow ssr block allocation during checkpoint=disable period f2fs: fix to check layout on last valid checkpoint park Conflicts: arch/arm64/configs/cuttlefish_defconfig arch/arm64/include/asm/memory.h arch/arm64/include/asm/thread_info.h arch/x86/configs/x86_64_cuttlefish_defconfig build.config.common drivers/dma-buf/dma-buf.c fs/crypto/Makefile fs/crypto/bio.c fs/crypto/fscrypt_private.h fs/crypto/keyinfo.c fs/ext4/page-io.c fs/f2fs/data.c fs/f2fs/f2fs.h fs/f2fs/inode.c fs/f2fs/segment.c fs/userfaultfd.c include/linux/dma-buf.h include/linux/fscrypt.h include/linux/kasan.h include/linux/platform_data/ds2482.h include/uapi/linux/fs.h kernel/sched/deadline.c kernel/sched/fair.c kernel/sched/rt.c kernel/sched/sched.h kernel/sched/stop_task.c kernel/sched/walt.c kernel/sched/walt.h lib/test_kasan.c mm/kasan/common.c mm/kasan/kasan.h mm/kasan/report.c mm/slub.c mm/vmalloc.c scripts/Makefile.kasan Changed below files to fix build errors: drivers/char/diag/diagchar_core.c drivers/power/supply/qcom/battery.c drivers/power/supply/qcom/smb1390-charger-psy.c drivers/power/supply/qcom/smb1390-charger.c drivers/power/supply/qcom/step-chg-jeita.c fs/crypto/fscrypt_ice.c fs/crypto/fscrypt_private.h fs/f2fs/inode.c include/uapi/linux/fscrypt.h net/qrtr/qrtr.c gen_headers_arm.bp gen_headers_arm64.bp Extra added fixes in fs/f2fs/data.c for FBE: * Fix FBE regression with 9937c21ce1 ("f2fs: add bio cache for IPU"). The above commit is not setting the DUN for bio, due to which the bio's could get corrupted when FBE is enabled. * The f2fs_merge_page_bio() incorrectly uses the bio after it is submitted for IO when fscrypt_mergeable_bio() returns false. Fix it by making the submitted bio NULL so that a new bio gets allocated for the next/new page. Ignored the below scheduler patches as they are already present: ANDROID: sched: WALT: Add support for CFS_BANDWIDTH ANDROID: sched: WALT: Refactor cumulative runnable average fixup picked below patches from 4.14.159 and 4.14.172 versions to fix issues 0e39aa9d5 "UPSTREAM: arm64: Validate tagged addresses in access_ok() called from kernel threads" 352902650 "fscrypt: support passing a keyring key to FS_IOC_ADD_ENCRYPTION_KEY" Change-Id: I205b796ee125fa6e9d27fa30f881e4e8fe8bea29 Signed-off-by: Srinivasarao P <spathi@codeaurora.org> Signed-off-by: Blagovest Kolenichev <bkolenichev@codeaurora.org>
874 lines
23 KiB
C
874 lines
23 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* linux/mm/mlock.c
|
|
*
|
|
* (C) Copyright 1995 Linus Torvalds
|
|
* (C) Copyright 2002 Christoph Hellwig
|
|
*/
|
|
|
|
#include <linux/capability.h>
|
|
#include <linux/mman.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/sched/user.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/swapops.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/pagevec.h>
|
|
#include <linux/mempolicy.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/export.h>
|
|
#include <linux/rmap.h>
|
|
#include <linux/mmzone.h>
|
|
#include <linux/hugetlb.h>
|
|
#include <linux/memcontrol.h>
|
|
#include <linux/mm_inline.h>
|
|
|
|
#include "internal.h"
|
|
|
|
bool can_do_mlock(void)
|
|
{
|
|
if (rlimit(RLIMIT_MEMLOCK) != 0)
|
|
return true;
|
|
if (capable(CAP_IPC_LOCK))
|
|
return true;
|
|
return false;
|
|
}
|
|
EXPORT_SYMBOL(can_do_mlock);
|
|
|
|
/*
|
|
* Mlocked pages are marked with PageMlocked() flag for efficient testing
|
|
* in vmscan and, possibly, the fault path; and to support semi-accurate
|
|
* statistics.
|
|
*
|
|
* An mlocked page [PageMlocked(page)] is unevictable. As such, it will
|
|
* be placed on the LRU "unevictable" list, rather than the [in]active lists.
|
|
* The unevictable list is an LRU sibling list to the [in]active lists.
|
|
* PageUnevictable is set to indicate the unevictable state.
|
|
*
|
|
* When lazy mlocking via vmscan, it is important to ensure that the
|
|
* vma's VM_LOCKED status is not concurrently being modified, otherwise we
|
|
* may have mlocked a page that is being munlocked. So lazy mlock must take
|
|
* the mmap_sem for read, and verify that the vma really is locked
|
|
* (see mm/rmap.c).
|
|
*/
|
|
|
|
/*
|
|
* LRU accounting for clear_page_mlock()
|
|
*/
|
|
void clear_page_mlock(struct page *page)
|
|
{
|
|
if (!TestClearPageMlocked(page))
|
|
return;
|
|
|
|
mod_zone_page_state(page_zone(page), NR_MLOCK,
|
|
-hpage_nr_pages(page));
|
|
count_vm_event(UNEVICTABLE_PGCLEARED);
|
|
if (!isolate_lru_page(page)) {
|
|
putback_lru_page(page);
|
|
} else {
|
|
/*
|
|
* We lost the race. the page already moved to evictable list.
|
|
*/
|
|
if (PageUnevictable(page))
|
|
count_vm_event(UNEVICTABLE_PGSTRANDED);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Mark page as mlocked if not already.
|
|
* If page on LRU, isolate and putback to move to unevictable list.
|
|
*/
|
|
void mlock_vma_page(struct page *page)
|
|
{
|
|
/* Serialize with page migration */
|
|
BUG_ON(!PageLocked(page));
|
|
|
|
VM_BUG_ON_PAGE(PageTail(page), page);
|
|
VM_BUG_ON_PAGE(PageCompound(page) && PageDoubleMap(page), page);
|
|
|
|
if (!TestSetPageMlocked(page)) {
|
|
mod_zone_page_state(page_zone(page), NR_MLOCK,
|
|
hpage_nr_pages(page));
|
|
count_vm_event(UNEVICTABLE_PGMLOCKED);
|
|
if (!isolate_lru_page(page))
|
|
putback_lru_page(page);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Isolate a page from LRU with optional get_page() pin.
|
|
* Assumes lru_lock already held and page already pinned.
|
|
*/
|
|
static bool __munlock_isolate_lru_page(struct page *page, bool getpage)
|
|
{
|
|
if (PageLRU(page)) {
|
|
struct lruvec *lruvec;
|
|
|
|
lruvec = mem_cgroup_page_lruvec(page, page_pgdat(page));
|
|
if (getpage)
|
|
get_page(page);
|
|
ClearPageLRU(page);
|
|
del_page_from_lru_list(page, lruvec, page_lru(page));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* Finish munlock after successful page isolation
|
|
*
|
|
* Page must be locked. This is a wrapper for try_to_munlock()
|
|
* and putback_lru_page() with munlock accounting.
|
|
*/
|
|
static void __munlock_isolated_page(struct page *page)
|
|
{
|
|
/*
|
|
* Optimization: if the page was mapped just once, that's our mapping
|
|
* and we don't need to check all the other vmas.
|
|
*/
|
|
if (page_mapcount(page) > 1)
|
|
try_to_munlock(page);
|
|
|
|
/* Did try_to_unlock() succeed or punt? */
|
|
if (!PageMlocked(page))
|
|
count_vm_event(UNEVICTABLE_PGMUNLOCKED);
|
|
|
|
putback_lru_page(page);
|
|
}
|
|
|
|
/*
|
|
* Accounting for page isolation fail during munlock
|
|
*
|
|
* Performs accounting when page isolation fails in munlock. There is nothing
|
|
* else to do because it means some other task has already removed the page
|
|
* from the LRU. putback_lru_page() will take care of removing the page from
|
|
* the unevictable list, if necessary. vmscan [page_referenced()] will move
|
|
* the page back to the unevictable list if some other vma has it mlocked.
|
|
*/
|
|
static void __munlock_isolation_failed(struct page *page)
|
|
{
|
|
if (PageUnevictable(page))
|
|
__count_vm_event(UNEVICTABLE_PGSTRANDED);
|
|
else
|
|
__count_vm_event(UNEVICTABLE_PGMUNLOCKED);
|
|
}
|
|
|
|
/**
|
|
* munlock_vma_page - munlock a vma page
|
|
* @page - page to be unlocked, either a normal page or THP page head
|
|
*
|
|
* returns the size of the page as a page mask (0 for normal page,
|
|
* HPAGE_PMD_NR - 1 for THP head page)
|
|
*
|
|
* called from munlock()/munmap() path with page supposedly on the LRU.
|
|
* When we munlock a page, because the vma where we found the page is being
|
|
* munlock()ed or munmap()ed, we want to check whether other vmas hold the
|
|
* page locked so that we can leave it on the unevictable lru list and not
|
|
* bother vmscan with it. However, to walk the page's rmap list in
|
|
* try_to_munlock() we must isolate the page from the LRU. If some other
|
|
* task has removed the page from the LRU, we won't be able to do that.
|
|
* So we clear the PageMlocked as we might not get another chance. If we
|
|
* can't isolate the page, we leave it for putback_lru_page() and vmscan
|
|
* [page_referenced()/try_to_unmap()] to deal with.
|
|
*/
|
|
unsigned int munlock_vma_page(struct page *page)
|
|
{
|
|
int nr_pages;
|
|
struct zone *zone = page_zone(page);
|
|
|
|
/* For try_to_munlock() and to serialize with page migration */
|
|
BUG_ON(!PageLocked(page));
|
|
|
|
VM_BUG_ON_PAGE(PageTail(page), page);
|
|
|
|
/*
|
|
* Serialize with any parallel __split_huge_page_refcount() which
|
|
* might otherwise copy PageMlocked to part of the tail pages before
|
|
* we clear it in the head page. It also stabilizes hpage_nr_pages().
|
|
*/
|
|
spin_lock_irq(zone_lru_lock(zone));
|
|
|
|
if (!TestClearPageMlocked(page)) {
|
|
/* Potentially, PTE-mapped THP: do not skip the rest PTEs */
|
|
nr_pages = 1;
|
|
goto unlock_out;
|
|
}
|
|
|
|
nr_pages = hpage_nr_pages(page);
|
|
__mod_zone_page_state(zone, NR_MLOCK, -nr_pages);
|
|
|
|
if (__munlock_isolate_lru_page(page, true)) {
|
|
spin_unlock_irq(zone_lru_lock(zone));
|
|
__munlock_isolated_page(page);
|
|
goto out;
|
|
}
|
|
__munlock_isolation_failed(page);
|
|
|
|
unlock_out:
|
|
spin_unlock_irq(zone_lru_lock(zone));
|
|
|
|
out:
|
|
return nr_pages - 1;
|
|
}
|
|
|
|
/*
|
|
* convert get_user_pages() return value to posix mlock() error
|
|
*/
|
|
static int __mlock_posix_error_return(long retval)
|
|
{
|
|
if (retval == -EFAULT)
|
|
retval = -ENOMEM;
|
|
else if (retval == -ENOMEM)
|
|
retval = -EAGAIN;
|
|
return retval;
|
|
}
|
|
|
|
/*
|
|
* Prepare page for fast batched LRU putback via putback_lru_evictable_pagevec()
|
|
*
|
|
* The fast path is available only for evictable pages with single mapping.
|
|
* Then we can bypass the per-cpu pvec and get better performance.
|
|
* when mapcount > 1 we need try_to_munlock() which can fail.
|
|
* when !page_evictable(), we need the full redo logic of putback_lru_page to
|
|
* avoid leaving evictable page in unevictable list.
|
|
*
|
|
* In case of success, @page is added to @pvec and @pgrescued is incremented
|
|
* in case that the page was previously unevictable. @page is also unlocked.
|
|
*/
|
|
static bool __putback_lru_fast_prepare(struct page *page, struct pagevec *pvec,
|
|
int *pgrescued)
|
|
{
|
|
VM_BUG_ON_PAGE(PageLRU(page), page);
|
|
VM_BUG_ON_PAGE(!PageLocked(page), page);
|
|
|
|
if (page_mapcount(page) <= 1 && page_evictable(page)) {
|
|
pagevec_add(pvec, page);
|
|
if (TestClearPageUnevictable(page))
|
|
(*pgrescued)++;
|
|
unlock_page(page);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* Putback multiple evictable pages to the LRU
|
|
*
|
|
* Batched putback of evictable pages that bypasses the per-cpu pvec. Some of
|
|
* the pages might have meanwhile become unevictable but that is OK.
|
|
*/
|
|
static void __putback_lru_fast(struct pagevec *pvec, int pgrescued)
|
|
{
|
|
count_vm_events(UNEVICTABLE_PGMUNLOCKED, pagevec_count(pvec));
|
|
/*
|
|
*__pagevec_lru_add() calls release_pages() so we don't call
|
|
* put_page() explicitly
|
|
*/
|
|
__pagevec_lru_add(pvec);
|
|
count_vm_events(UNEVICTABLE_PGRESCUED, pgrescued);
|
|
}
|
|
|
|
/*
|
|
* Munlock a batch of pages from the same zone
|
|
*
|
|
* The work is split to two main phases. First phase clears the Mlocked flag
|
|
* and attempts to isolate the pages, all under a single zone lru lock.
|
|
* The second phase finishes the munlock only for pages where isolation
|
|
* succeeded.
|
|
*
|
|
* Note that the pagevec may be modified during the process.
|
|
*/
|
|
static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone)
|
|
{
|
|
int i;
|
|
int nr = pagevec_count(pvec);
|
|
int delta_munlocked = -nr;
|
|
struct pagevec pvec_putback;
|
|
int pgrescued = 0;
|
|
|
|
pagevec_init(&pvec_putback, 0);
|
|
|
|
/* Phase 1: page isolation */
|
|
spin_lock_irq(zone_lru_lock(zone));
|
|
for (i = 0; i < nr; i++) {
|
|
struct page *page = pvec->pages[i];
|
|
|
|
if (TestClearPageMlocked(page)) {
|
|
/*
|
|
* We already have pin from follow_page_mask()
|
|
* so we can spare the get_page() here.
|
|
*/
|
|
if (__munlock_isolate_lru_page(page, false))
|
|
continue;
|
|
else
|
|
__munlock_isolation_failed(page);
|
|
} else {
|
|
delta_munlocked++;
|
|
}
|
|
|
|
/*
|
|
* We won't be munlocking this page in the next phase
|
|
* but we still need to release the follow_page_mask()
|
|
* pin. We cannot do it under lru_lock however. If it's
|
|
* the last pin, __page_cache_release() would deadlock.
|
|
*/
|
|
pagevec_add(&pvec_putback, pvec->pages[i]);
|
|
pvec->pages[i] = NULL;
|
|
}
|
|
__mod_zone_page_state(zone, NR_MLOCK, delta_munlocked);
|
|
spin_unlock_irq(zone_lru_lock(zone));
|
|
|
|
/* Now we can release pins of pages that we are not munlocking */
|
|
pagevec_release(&pvec_putback);
|
|
|
|
/* Phase 2: page munlock */
|
|
for (i = 0; i < nr; i++) {
|
|
struct page *page = pvec->pages[i];
|
|
|
|
if (page) {
|
|
lock_page(page);
|
|
if (!__putback_lru_fast_prepare(page, &pvec_putback,
|
|
&pgrescued)) {
|
|
/*
|
|
* Slow path. We don't want to lose the last
|
|
* pin before unlock_page()
|
|
*/
|
|
get_page(page); /* for putback_lru_page() */
|
|
__munlock_isolated_page(page);
|
|
unlock_page(page);
|
|
put_page(page); /* from follow_page_mask() */
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Phase 3: page putback for pages that qualified for the fast path
|
|
* This will also call put_page() to return pin from follow_page_mask()
|
|
*/
|
|
if (pagevec_count(&pvec_putback))
|
|
__putback_lru_fast(&pvec_putback, pgrescued);
|
|
}
|
|
|
|
/*
|
|
* Fill up pagevec for __munlock_pagevec using pte walk
|
|
*
|
|
* The function expects that the struct page corresponding to @start address is
|
|
* a non-TPH page already pinned and in the @pvec, and that it belongs to @zone.
|
|
*
|
|
* The rest of @pvec is filled by subsequent pages within the same pmd and same
|
|
* zone, as long as the pte's are present and vm_normal_page() succeeds. These
|
|
* pages also get pinned.
|
|
*
|
|
* Returns the address of the next page that should be scanned. This equals
|
|
* @start + PAGE_SIZE when no page could be added by the pte walk.
|
|
*/
|
|
static unsigned long __munlock_pagevec_fill(struct pagevec *pvec,
|
|
struct vm_area_struct *vma, struct zone *zone,
|
|
unsigned long start, unsigned long end)
|
|
{
|
|
pte_t *pte;
|
|
spinlock_t *ptl;
|
|
|
|
/*
|
|
* Initialize pte walk starting at the already pinned page where we
|
|
* are sure that there is a pte, as it was pinned under the same
|
|
* mmap_sem write op.
|
|
*/
|
|
pte = get_locked_pte(vma->vm_mm, start, &ptl);
|
|
/* Make sure we do not cross the page table boundary */
|
|
end = pgd_addr_end(start, end);
|
|
end = p4d_addr_end(start, end);
|
|
end = pud_addr_end(start, end);
|
|
end = pmd_addr_end(start, end);
|
|
|
|
/* The page next to the pinned page is the first we will try to get */
|
|
start += PAGE_SIZE;
|
|
while (start < end) {
|
|
struct page *page = NULL;
|
|
pte++;
|
|
if (pte_present(*pte))
|
|
page = vm_normal_page(vma, start, *pte);
|
|
/*
|
|
* Break if page could not be obtained or the page's node+zone does not
|
|
* match
|
|
*/
|
|
if (!page || page_zone(page) != zone)
|
|
break;
|
|
|
|
/*
|
|
* Do not use pagevec for PTE-mapped THP,
|
|
* munlock_vma_pages_range() will handle them.
|
|
*/
|
|
if (PageTransCompound(page))
|
|
break;
|
|
|
|
get_page(page);
|
|
/*
|
|
* Increase the address that will be returned *before* the
|
|
* eventual break due to pvec becoming full by adding the page
|
|
*/
|
|
start += PAGE_SIZE;
|
|
if (pagevec_add(pvec, page) == 0)
|
|
break;
|
|
}
|
|
pte_unmap_unlock(pte, ptl);
|
|
return start;
|
|
}
|
|
|
|
/*
|
|
* munlock_vma_pages_range() - munlock all pages in the vma range.'
|
|
* @vma - vma containing range to be munlock()ed.
|
|
* @start - start address in @vma of the range
|
|
* @end - end of range in @vma.
|
|
*
|
|
* For mremap(), munmap() and exit().
|
|
*
|
|
* Called with @vma VM_LOCKED.
|
|
*
|
|
* Returns with VM_LOCKED cleared. Callers must be prepared to
|
|
* deal with this.
|
|
*
|
|
* We don't save and restore VM_LOCKED here because pages are
|
|
* still on lru. In unmap path, pages might be scanned by reclaim
|
|
* and re-mlocked by try_to_{munlock|unmap} before we unmap and
|
|
* free them. This will result in freeing mlocked pages.
|
|
*/
|
|
void munlock_vma_pages_range(struct vm_area_struct *vma,
|
|
unsigned long start, unsigned long end)
|
|
{
|
|
vm_write_begin(vma);
|
|
WRITE_ONCE(vma->vm_flags, vma->vm_flags & VM_LOCKED_CLEAR_MASK);
|
|
vm_write_end(vma);
|
|
|
|
while (start < end) {
|
|
struct page *page;
|
|
unsigned int page_mask = 0;
|
|
unsigned long page_increm;
|
|
struct pagevec pvec;
|
|
struct zone *zone;
|
|
|
|
pagevec_init(&pvec, 0);
|
|
/*
|
|
* Although FOLL_DUMP is intended for get_dump_page(),
|
|
* it just so happens that its special treatment of the
|
|
* ZERO_PAGE (returning an error instead of doing get_page)
|
|
* suits munlock very well (and if somehow an abnormal page
|
|
* has sneaked into the range, we won't oops here: great).
|
|
*/
|
|
page = follow_page(vma, start, FOLL_GET | FOLL_DUMP);
|
|
|
|
if (page && !IS_ERR(page)) {
|
|
if (PageTransTail(page)) {
|
|
VM_BUG_ON_PAGE(PageMlocked(page), page);
|
|
put_page(page); /* follow_page_mask() */
|
|
} else if (PageTransHuge(page)) {
|
|
lock_page(page);
|
|
/*
|
|
* Any THP page found by follow_page_mask() may
|
|
* have gotten split before reaching
|
|
* munlock_vma_page(), so we need to compute
|
|
* the page_mask here instead.
|
|
*/
|
|
page_mask = munlock_vma_page(page);
|
|
unlock_page(page);
|
|
put_page(page); /* follow_page_mask() */
|
|
} else {
|
|
/*
|
|
* Non-huge pages are handled in batches via
|
|
* pagevec. The pin from follow_page_mask()
|
|
* prevents them from collapsing by THP.
|
|
*/
|
|
pagevec_add(&pvec, page);
|
|
zone = page_zone(page);
|
|
|
|
/*
|
|
* Try to fill the rest of pagevec using fast
|
|
* pte walk. This will also update start to
|
|
* the next page to process. Then munlock the
|
|
* pagevec.
|
|
*/
|
|
start = __munlock_pagevec_fill(&pvec, vma,
|
|
zone, start, end);
|
|
__munlock_pagevec(&pvec, zone);
|
|
goto next;
|
|
}
|
|
}
|
|
page_increm = 1 + page_mask;
|
|
start += page_increm * PAGE_SIZE;
|
|
next:
|
|
cond_resched();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* mlock_fixup - handle mlock[all]/munlock[all] requests.
|
|
*
|
|
* Filters out "special" vmas -- VM_LOCKED never gets set for these, and
|
|
* munlock is a no-op. However, for some special vmas, we go ahead and
|
|
* populate the ptes.
|
|
*
|
|
* For vmas that pass the filters, merge/split as appropriate.
|
|
*/
|
|
static int mlock_fixup(struct vm_area_struct *vma, struct vm_area_struct **prev,
|
|
unsigned long start, unsigned long end, vm_flags_t newflags)
|
|
{
|
|
struct mm_struct *mm = vma->vm_mm;
|
|
pgoff_t pgoff;
|
|
int nr_pages;
|
|
int ret = 0;
|
|
int lock = !!(newflags & VM_LOCKED);
|
|
vm_flags_t old_flags = vma->vm_flags;
|
|
|
|
if (newflags == vma->vm_flags || (vma->vm_flags & VM_SPECIAL) ||
|
|
is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm))
|
|
/* don't set VM_LOCKED or VM_LOCKONFAULT and don't count */
|
|
goto out;
|
|
|
|
pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
|
|
*prev = vma_merge(mm, *prev, start, end, newflags, vma->anon_vma,
|
|
vma->vm_file, pgoff, vma_policy(vma),
|
|
vma->vm_userfaultfd_ctx, vma_get_anon_name(vma));
|
|
if (*prev) {
|
|
vma = *prev;
|
|
goto success;
|
|
}
|
|
|
|
if (start != vma->vm_start) {
|
|
ret = split_vma(mm, vma, start, 1);
|
|
if (ret)
|
|
goto out;
|
|
}
|
|
|
|
if (end != vma->vm_end) {
|
|
ret = split_vma(mm, vma, end, 0);
|
|
if (ret)
|
|
goto out;
|
|
}
|
|
|
|
success:
|
|
/*
|
|
* Keep track of amount of locked VM.
|
|
*/
|
|
nr_pages = (end - start) >> PAGE_SHIFT;
|
|
if (!lock)
|
|
nr_pages = -nr_pages;
|
|
else if (old_flags & VM_LOCKED)
|
|
nr_pages = 0;
|
|
mm->locked_vm += nr_pages;
|
|
|
|
/*
|
|
* vm_flags is protected by the mmap_sem held in write mode.
|
|
* It's okay if try_to_unmap_one unmaps a page just after we
|
|
* set VM_LOCKED, populate_vma_page_range will bring it back.
|
|
*/
|
|
if (lock) {
|
|
vm_write_begin(vma);
|
|
WRITE_ONCE(vma->vm_flags, newflags);
|
|
vm_write_end(vma);
|
|
} else
|
|
munlock_vma_pages_range(vma, start, end);
|
|
|
|
out:
|
|
*prev = vma;
|
|
return ret;
|
|
}
|
|
|
|
static int apply_vma_lock_flags(unsigned long start, size_t len,
|
|
vm_flags_t flags)
|
|
{
|
|
unsigned long nstart, end, tmp;
|
|
struct vm_area_struct * vma, * prev;
|
|
int error;
|
|
|
|
VM_BUG_ON(offset_in_page(start));
|
|
VM_BUG_ON(len != PAGE_ALIGN(len));
|
|
end = start + len;
|
|
if (end < start)
|
|
return -EINVAL;
|
|
if (end == start)
|
|
return 0;
|
|
vma = find_vma(current->mm, start);
|
|
if (!vma || vma->vm_start > start)
|
|
return -ENOMEM;
|
|
|
|
prev = vma->vm_prev;
|
|
if (start > vma->vm_start)
|
|
prev = vma;
|
|
|
|
for (nstart = start ; ; ) {
|
|
vm_flags_t newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
|
|
|
|
newflags |= flags;
|
|
|
|
/* Here we know that vma->vm_start <= nstart < vma->vm_end. */
|
|
tmp = vma->vm_end;
|
|
if (tmp > end)
|
|
tmp = end;
|
|
error = mlock_fixup(vma, &prev, nstart, tmp, newflags);
|
|
if (error)
|
|
break;
|
|
nstart = tmp;
|
|
if (nstart < prev->vm_end)
|
|
nstart = prev->vm_end;
|
|
if (nstart >= end)
|
|
break;
|
|
|
|
vma = prev->vm_next;
|
|
if (!vma || vma->vm_start != nstart) {
|
|
error = -ENOMEM;
|
|
break;
|
|
}
|
|
}
|
|
return error;
|
|
}
|
|
|
|
/*
|
|
* Go through vma areas and sum size of mlocked
|
|
* vma pages, as return value.
|
|
* Note deferred memory locking case(mlock2(,,MLOCK_ONFAULT)
|
|
* is also counted.
|
|
* Return value: previously mlocked page counts
|
|
*/
|
|
static unsigned long count_mm_mlocked_page_nr(struct mm_struct *mm,
|
|
unsigned long start, size_t len)
|
|
{
|
|
struct vm_area_struct *vma;
|
|
unsigned long count = 0;
|
|
|
|
if (mm == NULL)
|
|
mm = current->mm;
|
|
|
|
vma = find_vma(mm, start);
|
|
if (vma == NULL)
|
|
vma = mm->mmap;
|
|
|
|
for (; vma ; vma = vma->vm_next) {
|
|
if (start >= vma->vm_end)
|
|
continue;
|
|
if (start + len <= vma->vm_start)
|
|
break;
|
|
if (vma->vm_flags & VM_LOCKED) {
|
|
if (start > vma->vm_start)
|
|
count -= (start - vma->vm_start);
|
|
if (start + len < vma->vm_end) {
|
|
count += start + len - vma->vm_start;
|
|
break;
|
|
}
|
|
count += vma->vm_end - vma->vm_start;
|
|
}
|
|
}
|
|
|
|
return count >> PAGE_SHIFT;
|
|
}
|
|
|
|
static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
|
|
{
|
|
unsigned long locked;
|
|
unsigned long lock_limit;
|
|
int error = -ENOMEM;
|
|
|
|
start = untagged_addr(start);
|
|
|
|
if (!can_do_mlock())
|
|
return -EPERM;
|
|
|
|
lru_add_drain_all(); /* flush pagevec */
|
|
|
|
len = PAGE_ALIGN(len + (offset_in_page(start)));
|
|
start &= PAGE_MASK;
|
|
|
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
|
lock_limit >>= PAGE_SHIFT;
|
|
locked = len >> PAGE_SHIFT;
|
|
|
|
if (down_write_killable(¤t->mm->mmap_sem))
|
|
return -EINTR;
|
|
|
|
locked += current->mm->locked_vm;
|
|
if ((locked > lock_limit) && (!capable(CAP_IPC_LOCK))) {
|
|
/*
|
|
* It is possible that the regions requested intersect with
|
|
* previously mlocked areas, that part area in "mm->locked_vm"
|
|
* should not be counted to new mlock increment count. So check
|
|
* and adjust locked count if necessary.
|
|
*/
|
|
locked -= count_mm_mlocked_page_nr(current->mm,
|
|
start, len);
|
|
}
|
|
|
|
/* check against resource limits */
|
|
if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
|
|
error = apply_vma_lock_flags(start, len, flags);
|
|
|
|
up_write(¤t->mm->mmap_sem);
|
|
if (error)
|
|
return error;
|
|
|
|
error = __mm_populate(start, len, 0);
|
|
if (error)
|
|
return __mlock_posix_error_return(error);
|
|
return 0;
|
|
}
|
|
|
|
SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
|
|
{
|
|
return do_mlock(start, len, VM_LOCKED);
|
|
}
|
|
|
|
SYSCALL_DEFINE3(mlock2, unsigned long, start, size_t, len, int, flags)
|
|
{
|
|
vm_flags_t vm_flags = VM_LOCKED;
|
|
|
|
if (flags & ~MLOCK_ONFAULT)
|
|
return -EINVAL;
|
|
|
|
if (flags & MLOCK_ONFAULT)
|
|
vm_flags |= VM_LOCKONFAULT;
|
|
|
|
return do_mlock(start, len, vm_flags);
|
|
}
|
|
|
|
SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
|
|
{
|
|
int ret;
|
|
|
|
start = untagged_addr(start);
|
|
|
|
len = PAGE_ALIGN(len + (offset_in_page(start)));
|
|
start &= PAGE_MASK;
|
|
|
|
if (down_write_killable(¤t->mm->mmap_sem))
|
|
return -EINTR;
|
|
ret = apply_vma_lock_flags(start, len, 0);
|
|
up_write(¤t->mm->mmap_sem);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Take the MCL_* flags passed into mlockall (or 0 if called from munlockall)
|
|
* and translate into the appropriate modifications to mm->def_flags and/or the
|
|
* flags for all current VMAs.
|
|
*
|
|
* There are a couple of subtleties with this. If mlockall() is called multiple
|
|
* times with different flags, the values do not necessarily stack. If mlockall
|
|
* is called once including the MCL_FUTURE flag and then a second time without
|
|
* it, VM_LOCKED and VM_LOCKONFAULT will be cleared from mm->def_flags.
|
|
*/
|
|
static int apply_mlockall_flags(int flags)
|
|
{
|
|
struct vm_area_struct * vma, * prev = NULL;
|
|
vm_flags_t to_add = 0;
|
|
|
|
current->mm->def_flags &= VM_LOCKED_CLEAR_MASK;
|
|
if (flags & MCL_FUTURE) {
|
|
current->mm->def_flags |= VM_LOCKED;
|
|
|
|
if (flags & MCL_ONFAULT)
|
|
current->mm->def_flags |= VM_LOCKONFAULT;
|
|
|
|
if (!(flags & MCL_CURRENT))
|
|
goto out;
|
|
}
|
|
|
|
if (flags & MCL_CURRENT) {
|
|
to_add |= VM_LOCKED;
|
|
if (flags & MCL_ONFAULT)
|
|
to_add |= VM_LOCKONFAULT;
|
|
}
|
|
|
|
for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
|
|
vm_flags_t newflags;
|
|
|
|
newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
|
|
newflags |= to_add;
|
|
|
|
/* Ignore errors */
|
|
mlock_fixup(vma, &prev, vma->vm_start, vma->vm_end, newflags);
|
|
cond_resched_rcu_qs();
|
|
}
|
|
out:
|
|
return 0;
|
|
}
|
|
|
|
SYSCALL_DEFINE1(mlockall, int, flags)
|
|
{
|
|
unsigned long lock_limit;
|
|
int ret;
|
|
|
|
if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)))
|
|
return -EINVAL;
|
|
|
|
if (!can_do_mlock())
|
|
return -EPERM;
|
|
|
|
if (flags & MCL_CURRENT)
|
|
lru_add_drain_all(); /* flush pagevec */
|
|
|
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
|
lock_limit >>= PAGE_SHIFT;
|
|
|
|
if (down_write_killable(¤t->mm->mmap_sem))
|
|
return -EINTR;
|
|
|
|
ret = -ENOMEM;
|
|
if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
|
|
capable(CAP_IPC_LOCK))
|
|
ret = apply_mlockall_flags(flags);
|
|
up_write(¤t->mm->mmap_sem);
|
|
if (!ret && (flags & MCL_CURRENT))
|
|
mm_populate(0, TASK_SIZE);
|
|
|
|
return ret;
|
|
}
|
|
|
|
SYSCALL_DEFINE0(munlockall)
|
|
{
|
|
int ret;
|
|
|
|
if (down_write_killable(¤t->mm->mmap_sem))
|
|
return -EINTR;
|
|
ret = apply_mlockall_flags(0);
|
|
up_write(¤t->mm->mmap_sem);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Objects with different lifetime than processes (SHM_LOCK and SHM_HUGETLB
|
|
* shm segments) get accounted against the user_struct instead.
|
|
*/
|
|
static DEFINE_SPINLOCK(shmlock_user_lock);
|
|
|
|
int user_shm_lock(size_t size, struct user_struct *user)
|
|
{
|
|
unsigned long lock_limit, locked;
|
|
int allowed = 0;
|
|
|
|
locked = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
|
if (lock_limit == RLIM_INFINITY)
|
|
allowed = 1;
|
|
lock_limit >>= PAGE_SHIFT;
|
|
spin_lock(&shmlock_user_lock);
|
|
if (!allowed &&
|
|
locked + user->locked_shm > lock_limit && !capable(CAP_IPC_LOCK))
|
|
goto out;
|
|
get_uid(user);
|
|
user->locked_shm += locked;
|
|
allowed = 1;
|
|
out:
|
|
spin_unlock(&shmlock_user_lock);
|
|
return allowed;
|
|
}
|
|
|
|
void user_shm_unlock(size_t size, struct user_struct *user)
|
|
{
|
|
spin_lock(&shmlock_user_lock);
|
|
user->locked_shm -= (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
spin_unlock(&shmlock_user_lock);
|
|
free_uid(user);
|
|
}
|