Skip to content

Commit 7b7aca6

Browse files
peiliiakpm00
authored andcommitted
mm: ignore data-race in __swap_writepage
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 3222d8c ("block: remove ->rw_page"), where this if branch is introduced. Link: https://lkml.kernel.org/r/[email protected] Fixes: 3222d8c ("block: remove ->rw_page") Signed-off-by: Pei Li <[email protected]> Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=da25887cc13da6bf3b8c Cc: Dan Williams <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent dffe24e commit 7b7aca6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mm/page_io.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,12 @@ void __swap_writepage(struct folio *folio, struct writeback_control *wbc)
382382
*/
383383
if (data_race(sis->flags & SWP_FS_OPS))
384384
swap_writepage_fs(folio, wbc);
385-
else if (sis->flags & SWP_SYNCHRONOUS_IO)
385+
/*
386+
* ->flags can be updated non-atomicially (scan_swap_map_slots),
387+
* but that will never affect SWP_SYNCHRONOUS_IO, so the data_race
388+
* is safe.
389+
*/
390+
else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO))
386391
swap_writepage_bdev_sync(folio, wbc, sis);
387392
else
388393
swap_writepage_bdev_async(folio, wbc, sis);

0 commit comments

Comments
 (0)