TencentOS-kernel/kernel
Yang Shi 2f09e7ee6d mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct
mmap_sem is on the hot path of kernel, and it very contended, but it is
abused too.  It is used to protect arg_start|end and evn_start|end when
reading /proc/$PID/cmdline and /proc/$PID/environ, but it doesn't make
sense since those proc files just expect to read 4 values atomically and
not related to VM, they could be set to arbitrary values by C/R.

And, the mmap_sem contention may cause unexpected issue like below:

INFO: task ps:14018 blocked for more than 120 seconds.
       Tainted: G            E 4.9.79-009.ali3000.alios7.x86_64 #1
 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this
message.
 ps              D    0 14018      1 0x00000004
 Call Trace:
   schedule+0x36/0x80
   rwsem_down_read_failed+0xf0/0x150
   call_rwsem_down_read_failed+0x18/0x30
   down_read+0x20/0x40
   proc_pid_cmdline_read+0xd9/0x4e0
   __vfs_read+0x37/0x150
   vfs_read+0x96/0x130
   SyS_read+0x55/0xc0
   entry_SYSCALL_64_fastpath+0x1a/0xc5

Both Alexey Dobriyan and Michal Hocko suggested to use dedicated lock
for them to mitigate the abuse of mmap_sem.

So, introduce a new spinlock in mm_struct to protect the concurrent
access to arg_start|end, env_start|end and others, as well as replace
write map_sem to read to protect the race condition between prctl and
sys_brk which might break check_data_rlimit(), and makes prctl more
friendly to other VM operations.

This patch just eliminates the abuse of mmap_sem, but it can't resolve
the above hung task warning completely since the later
access_remote_vm() call needs acquire mmap_sem.  The mmap_sem
scalability issue will be solved in the future.

[yang.shi@linux.alibaba.com: add comment about mmap_sem and arg_lock]
  Link: http://lkml.kernel.org/r/1524077799-80690-1-git-send-email-yang.shi@linux.alibaba.com
Link: http://lkml.kernel.org/r/1523730291-109696-1-git-send-email-yang.shi@linux.alibaba.com
Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mateusz Guzik <mguzik@redhat.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-07-26 16:13:08 +08:00
..
bpf Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
cgroup sched: /proc/cpuinfo in docker base on cpu quota 2020-07-16 14:59:05 +08:00
configs Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
debug Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
events Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
gcov Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
irq irq: allow user manage irq affinity 2020-01-02 12:22:25 +08:00
livepatch Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
locking Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
power Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
printk Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
rcu Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
sched backport wake affine upstream optimization 2021-03-17 17:00:12 +08:00
time clocksource: add kernel.clocksource_unstable_cnt to track tsc unstable 2020-05-29 10:40:52 +08:00
tkernel build: fix series of warnings 2020-06-04 18:43:47 +08:00
trace Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
.gitignore Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
Kconfig.freezer Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
Kconfig.hz Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
Kconfig.locks Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
Kconfig.preempt Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
Makefile Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
acct.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
async.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
audit.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
audit.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
audit_fsnotify.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
audit_tree.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
audit_watch.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
auditfilter.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
auditsc.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
backtracetest.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
bounds.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
capability.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
compat.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
configs.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
context_tracking.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
cpu.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
cpu_pm.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
crash_core.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
crash_dump.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
cred.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
delayacct.c sched: add offline scheduler class 2020-03-02 22:03:09 +08:00
dma.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
elfcore.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
exec_domain.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
exit.c sched: add offline scheduler class 2020-03-02 22:03:09 +08:00
extable.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
fork.c mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct 2021-07-26 16:13:08 +08:00
freezer.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
futex.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
futex_compat.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
groups.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
hung_task.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
irq_work.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
jump_label.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kallsyms.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kcmp.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kcov.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kexec.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kexec_core.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kexec_file.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kexec_internal.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kmod.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kprobes.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
ksysfs.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kthread.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
latencytop.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
memremap.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
module-internal.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
module.c tkernel: add the kpatch kmod support 2020-01-02 12:15:37 +08:00
module_signing.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
notifier.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
nsproxy.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
padata.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
panic.c kernel/panic: set crash_kexec_post_notifiers default to true 2020-01-02 12:17:31 +08:00
params.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
pid.c vm:isolate max_map_count by pid namespace 2020-01-02 11:51:53 +08:00
pid_namespace.c vm: add max_map_count isolate switch 2020-05-29 10:38:28 +08:00
profile.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
ptrace.c tools: add ttools module to support ptrace protect 2020-01-02 15:12:03 +08:00
range.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
reboot.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
relay.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
resource.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
seccomp.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
signal.c signal: add print_fatal_signals_src_dst sysctl to switch dump fatal signals from sender side 2020-01-02 11:44:57 +08:00
smp.c smp: smp_call_function_many_async 2020-12-01 10:34:56 +08:00
smpboot.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
smpboot.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
softirq.c softirq: enhance network latency 2020-10-16 11:55:22 +08:00
stacktrace.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
stop_machine.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
sys.c mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct 2021-07-26 16:13:08 +08:00
sys_ni.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
sysctl.c net: rps using pvipi 2020-12-01 10:36:20 +08:00
sysctl_binary.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
task_work.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
taskstats.c expose taskstats to all netspace 2020-01-02 12:00:26 +08:00
test_kprobes.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
torture.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
tracepoint.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
tsacct.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
ucount.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
uid16.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
umh.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
up.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
user-return-notifier.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
user.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
user_namespace.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
utsname.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
utsname_sysctl.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
watchdog.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
watchdog_hld.c wathdog: add symbol info when panic by hard lockup 2020-01-02 11:50:31 +08:00
workqueue.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
workqueue_internal.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00