Skip to content

Commit 1ed303c

Browse files
lorenzo-stoakesakpm00
authored andcommitted
mm/madvise: fix madvise_[un]lock() issue
We are asymmetric in our locking/unlocking in the case of memory failure madvise() behaviour options, correct this and abstract the memory failure check. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Lorenzo Stoakes <[email protected]> Reported-by: "Lai, Yi" <[email protected]> Closes: https://lore.kernel.org/Z6rgiVp7221r4JZ5@ly-workstation Reviewed-by: SeongJae Park <[email protected]> Tested-by: SeongJae Park <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Naresh Kamboju <[email protected]> Cc: Shakeel Butt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4437b17 commit 1ed303c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

mm/madvise.c

+23-6
Original file line numberDiff line numberDiff line change
@@ -1575,26 +1575,43 @@ int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
15751575
}
15761576
#endif /* CONFIG_ANON_VMA_NAME */
15771577

1578-
static int madvise_lock(struct mm_struct *mm, int behavior)
1579-
{
1580-
15811578
#ifdef CONFIG_MEMORY_FAILURE
1582-
if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE)
1583-
return 0;
1579+
static bool is_memory_failure(int behavior)
1580+
{
1581+
switch (behavior) {
1582+
case MADV_HWPOISON:
1583+
case MADV_SOFT_OFFLINE:
1584+
return true;
1585+
default:
1586+
return false;
1587+
}
1588+
}
1589+
#else
1590+
static bool is_memory_failure(int behavior)
1591+
{
1592+
return false;
1593+
}
15841594
#endif
15851595

1596+
static int madvise_lock(struct mm_struct *mm, int behavior)
1597+
{
1598+
if (is_memory_failure(behavior))
1599+
return 0;
1600+
15861601
if (madvise_need_mmap_write(behavior)) {
15871602
if (mmap_write_lock_killable(mm))
15881603
return -EINTR;
15891604
} else {
15901605
mmap_read_lock(mm);
15911606
}
15921607
return 0;
1593-
15941608
}
15951609

15961610
static void madvise_unlock(struct mm_struct *mm, int behavior)
15971611
{
1612+
if (is_memory_failure(behavior))
1613+
return;
1614+
15981615
if (madvise_need_mmap_write(behavior))
15991616
mmap_write_unlock(mm);
16001617
else

0 commit comments

Comments
 (0)