The patch titled Subject: mm/madvise: employ mmget_still_valid() for write lock has been added to the -mm tree. Its filename is mm-madvise-employ-mmget_still_valid-for-write-lock.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-madvise-employ-mmget_still_valid-for-write-lock.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-madvise-employ-mmget_still_valid-for-write-lock.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Oleksandr Natalenko <oleksandr@xxxxxxxxxx> Subject: mm/madvise: employ mmget_still_valid() for write lock Do the very same trick as we already do since 04f5866e41fb. KSM hints will require locking mmap_sem for write since they modify vm_flags, so for remote KSM hinting this additional check is needed. Link: http://lkml.kernel.org/r/20200302193630.68771-7-minchan@xxxxxxxxxx Signed-off-by: Oleksandr Natalenko <oleksandr@xxxxxxxxxx> Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx> Reviewed-by: Suren Baghdasaryan <surenb@xxxxxxxxxx> Cc: Alexander Duyck <alexander.h.duyck@xxxxxxxxxxxxxxx> Cc: Brian Geffon <bgeffon@xxxxxxxxxx> Cc: Christian Brauner <christian@xxxxxxxxxx> Cc: Daniel Colascione <dancol@xxxxxxxxxx> Cc: Jann Horn <jannh@xxxxxxxxxx> Cc: Jens Axboe <axboe@xxxxxxxxx> Cc: Joel Fernandes <joel@xxxxxxxxxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: John Dias <joaodias@xxxxxxxxxx> Cc: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Sandeep Patil <sspatil@xxxxxxxxxx> Cc: SeongJae Park <sj38.park@xxxxxxxxx> Cc: SeongJae Park <sjpark@xxxxxxxxx> Cc: Shakeel Butt <shakeelb@xxxxxxxxxx> Cc: Sonny Rao <sonnyrao@xxxxxxxxxx> Cc: Tim Murray <timmurray@xxxxxxxxxx> Cc: <linux-man@xxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/madvise.c | 3 +++ 1 file changed, 3 insertions(+) --- a/mm/madvise.c~mm-madvise-employ-mmget_still_valid-for-write-lock +++ a/mm/madvise.c @@ -1118,6 +1118,8 @@ int do_madvise(struct task_struct *targe if (write) { if (down_write_killable(&mm->mmap_sem)) return -EINTR; + if (current->mm != mm && !mmget_still_valid(mm)) + goto skip_mm; } else { down_read(&mm->mmap_sem); } @@ -1169,6 +1171,7 @@ int do_madvise(struct task_struct *targe } out: blk_finish_plug(&plug); +skip_mm: if (write) up_write(&mm->mmap_sem); else _ Patches currently in -mm which might be from oleksandr@xxxxxxxxxx are mm-madvise-employ-mmget_still_valid-for-write-lock.patch mm-madvise-allow-ksm-hints-for-remote-api.patch