]> Git Repo - linux.git/commit
thp: fix MADV_DONTNEED vs. MADV_FREE race
authorKirill A. Shutemov <[email protected]>
Thu, 13 Apr 2017 21:56:26 +0000 (14:56 -0700)
committerLinus Torvalds <[email protected]>
Fri, 14 Apr 2017 01:24:21 +0000 (18:24 -0700)
commit58ceeb6bec86d9140f9d91d71a710e963523d063
treec9b4a990429893f3cdb70771701e2565de4b532f
parentc0c379e2931b05facef538e53bf3b21f283d9a0b
thp: fix MADV_DONTNEED vs. MADV_FREE race

Both MADV_DONTNEED and MADV_FREE handled with down_read(mmap_sem).

It's critical to not clear pmd intermittently while handling MADV_FREE
to avoid race with MADV_DONTNEED:

CPU0: CPU1:
madvise_free_huge_pmd()
 pmdp_huge_get_and_clear_full()
madvise_dontneed()
 zap_pmd_range()
  pmd_trans_huge(*pmd) == 0 (without ptl)
  // skip the pmd
 set_pmd_at();
 // pmd is re-established

It results in MADV_DONTNEED skipping the pmd, leaving it not cleared.
It violates MADV_DONTNEED interface and can result is userspace
misbehaviour.

Basically it's the same race as with numa balancing in
change_huge_pmd(), but a bit simpler to mitigate: we don't need to
preserve dirty/young flags here due to MADV_FREE functionality.

[[email protected]: Urgh... Power is special again]
Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Kirill A. Shutemov <[email protected]>
Acked-by: Minchan Kim <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Hillf Danton <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/huge_memory.c
This page took 0.058289 seconds and 4 git commands to generate.