mm: fix data race in PagePoisoned()
Subsystems (2)
PATCH 1/1 mm: fix data race in PagePoisoned()
PagePoisoned() accesses page->flags which can be updated concurrently:
| BUG: KCSAN: data-race in next_uptodate_page / unlock_page | | write (marked) to 0xffffea00050f37c0 of 8 bytes by task 1872 on cpu 1: | instrument_atomic_write include/linux/instrumented.h:87 [inline] | clear_bit_unlock_is_negative_byte include/asm-generic/bitops/instrumented-lock.h:74 [inline] | unlock_page+0x102/0x1b0 mm/filemap.c:1465 | filemap_map_pages+0x6c6/0x890 mm/filemap.c:3057 | ... | read to 0xffffea00050f37c0 of 8 bytes by task 1873 on cpu 0: | PagePoisoned include/linux/page-flags.h:204 [inline] | PageReadahead include/linux/page-flags.h:382 [inline] | next_uptodate_page+0x456/0x830 mm/filemap.c:2975 | ... | CPU: 0 PID: 1873 Comm: systemd-udevd Not tainted 5.11.0-rc4-00001-gf9ce0be71d1f #1
To avoid the compiler tearing or otherwise optimizing the access, use READ_ONCE() to access flags.
Reported-by kernel test robot <[email protected]>
Signed-off-by Marco Elver <[email protected]>
Cc Will Deacon <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
--- include/linux/page-flags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/page-flags.h +1 -1
@@ -206,7 +206,7 @@ static __always_inline int PageCompound(struct page *page)#define PAGE_POISON_PATTERN -1lstatic inline int PagePoisoned (const struct page *page) { -return page->flags ==PAGE_POISON_PATTERN ; +return READ_ONCE (page->flags) ==PAGE_POISON_PATTERN ; }#ifdef CONFIG_DEBUG_VM
Signature · 1 line
2.33.0.309.g3052b89438-goog
Quoted 34 lines · Marco Elver
PagePoisoned()accessespage->flagswhich can be updated concurrently:| BUG: KCSAN: data-race in next_uptodate_page / unlock_page | | write (marked) to 0xffffea00050f37c0 of 8 bytes by task 1872 on cpu 1: | instrument_atomic_write include/linux/instrumented.h:87 [inline] | clear_bit_unlock_is_negative_byte include/asm-generic/bitops/instrumented-lock.h:74 [inline] | unlock_page+0x102/0x1b0 mm/filemap.c:1465 | filemap_map_pages+0x6c6/0x890 mm/filemap.c:3057 | ... | read to 0xffffea00050f37c0 of 8 bytes by task 1873 on cpu 0: | PagePoisoned include/linux/page-flags.h:204 [inline] | PageReadahead include/linux/page-flags.h:382 [inline] | next_uptodate_page+0x456/0x830 mm/filemap.c:2975 | ... | CPU: 0 PID: 1873 Comm: systemd-udevd Not tainted 5.11.0-rc4-00001-gf9ce0be71d1f #1To avoid the compiler tearing or otherwise optimizing the access, use
READ_ONCE()to access flags.Reported-by kernel test robot <[email protected]>Signed-off-by Marco Elver <[email protected]>Cc Will Deacon <[email protected]>Cc Kirill A. Shutemov <[email protected]>--- include/linux/page-flags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/page-flags.h +0
-0
include/linux/page-flags.h static __always_inline int PageCompound(struct page *page) · line 210
Quoted 6 lines
include/linux/page-flags.h +1
-1@@ -206,7 +206,7 @@ static __always_inline int PageCompound(struct page *page)#define PAGE_POISON_PATTERN -1lstatic inline int PagePoisoned (const struct page *page) { -return page->flags ==PAGE_POISON_PATTERN ; +return READ_ONCE (page->flags) ==PAGE_POISON_PATTERN ; }
Acked-by Will Deacon <[email protected]>
Thanks for writing up the patch!
Will
Quoted 17 lines · Marco Elver
PagePoisoned()accessespage->flagswhich can be updated concurrently:| BUG: KCSAN: data-race in next_uptodate_page / unlock_page | | write (marked) to 0xffffea00050f37c0 of 8 bytes by task 1872 on cpu 1: | instrument_atomic_write include/linux/instrumented.h:87 [inline] | clear_bit_unlock_is_negative_byte include/asm-generic/bitops/instrumented-lock.h:74 [inline] | unlock_page+0x102/0x1b0 mm/filemap.c:1465 | filemap_map_pages+0x6c6/0x890 mm/filemap.c:3057 | ... | read to 0xffffea00050f37c0 of 8 bytes by task 1873 on cpu 0: | PagePoisoned include/linux/page-flags.h:204 [inline] | PageReadahead include/linux/page-flags.h:382 [inline] | next_uptodate_page+0x456/0x830 mm/filemap.c:2975 | ... | CPU: 0 PID: 1873 Comm: systemd-udevd Not tainted 5.11.0-rc4-00001-gf9ce0be71d1f #1
Quoted 7 lines
To avoid the compiler tearing or otherwise optimizing the access, use
READ_ONCE()to access flags.Reported-by kernel test robot <[email protected]>Signed-off-by Marco Elver <[email protected]>Cc Will Deacon <[email protected]>
Signature · 1 line
Kirill A. Shutemov