Commit 2db9b571 authored by Pei Li's avatar Pei Li Committed by Kaixiong Yu
Browse files

mm: ignore data-race in __swap_writepage

mainline inclusion
from mainline-v6.11-rc1
commit 7b7aca6d7c0f9b2d9400bfc57cb2b23cfbd5134d
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBET92

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7b7aca6d7c0f9b2d9400bfc57cb2b23cfbd5134d

--------------------------------

Syzbot reported a possible data race:

BUG: KCSAN: data-race in __swap_writepage / scan_swap_map_slots

read-write to 0xffff888102fca610 of 8 bytes by task 7106 on cpu 1.
read to 0xffff888102fca610 of 8 bytes by task 7080 on cpu 0.

While we are in __swap_writepage to read sis->flags, scan_swap_map_slots
is trying to update it with SWP_SCANNING.

value changed: 0x0000000000008083 -> 0x0000000000004083.

While this can be updated non-atomicially, this won't affect
SWP_SYNCHRONOUS_IO, so we consider this data-race safe.

This is possibly introduced by commit 3222d8c2 ("block: remove
->rw_page"), where this if branch is introduced.

Link: https://lkml.kernel.org/r/20240711-bug13-v1-1-cea2b8ae8d76@gmail.com


Fixes: 3222d8c2 ("block: remove ->rw_page")
Signed-off-by: default avatarPei Li <peili.dev@gmail.com>
Reported-by: default avatar <syzbot+da25887cc13da6bf3b8c@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=da25887cc13da6bf3b8c


Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Conflicts:
	mm/page_io.c
[Because HULK-6.6 don't merge mainline patch
b99b4e0d9d7f29b428bacd7a61188b2abf340c1e ("mm: pass
a folio to __swap_writepage()")]
Signed-off-by: default avatarKaixiong Yu <yukaixiong@huawei.com>
parent 604e996d
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -381,7 +381,12 @@ void __swap_writepage(struct page *page, struct writeback_control *wbc)
	 */
	if (data_race(sis->flags & SWP_FS_OPS))
		swap_writepage_fs(page, wbc);
	else if (sis->flags & SWP_SYNCHRONOUS_IO)
	/*
	 * ->flags can be updated non-atomicially (scan_swap_map_slots),
	 * but that will never affect SWP_SYNCHRONOUS_IO, so the data_race
	 * is safe.
	 */
	else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO))
		swap_writepage_bdev_sync(page, wbc, sis);
	else
		swap_writepage_bdev_async(page, wbc, sis);