holepunch: fix mmap_sem i_mutex deadlock
commit4879e0dfe9c9199e55566a6025a729854bb2a00e
authorHugh Dickins <hugh@veritas.com>
Thu, 3 May 2007 22:54:25 +0000 (4 00:54 +0200)
committerAdrian Bunk <bunk@stusta.de>
Thu, 3 May 2007 22:54:25 +0000 (4 00:54 +0200)
treedae9fb7549555e94c71d41701f67875b04557035
parent7943951f236f91699a634097a70abc35927efeb9
holepunch: fix mmap_sem i_mutex deadlock

sys_madvise has down_write of mmap_sem, then madvise_remove calls
vmtruncate_range which takes i_mutex and i_alloc_sem: no, we can
easily devise deadlocks from that ordering.

madvise_remove drop mmap_sem while calling vmtruncate_range: luckily,
since madvise_remove doesn't split or merge vmas, it's easy to handle
this case with a NULL prev, without restructuring sys_madvise.  (Though
sad to retake mmap_sem when it's unlikely to be needed, and certainly
down_read is sufficient for MADV_REMOVE, unlike the other madvices.)

Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
mm/madvise.c