Commit 4f9669f
mm/filemap.c: fix a data race in filemap_fault()
struct file_ra_state ra.mmap_miss could be accessed concurrently during
page faults as noticed by KCSAN,
BUG: KCSAN: data-race in filemap_fault / filemap_map_pages
write to 0xffff9b1700a2c1b4 of 4 bytes by task 3292 on cpu 30:
filemap_fault+0x920/0xfc0
do_sync_mmap_readahead at mm/filemap.c:2384
(inlined by) filemap_fault at mm/filemap.c:2486
__xfs_filemap_fault+0x112/0x3e0 [xfs]
xfs_filemap_fault+0x74/0x90 [xfs]
__do_fault+0x9e/0x220
do_fault+0x4a0/0x920
__handle_mm_fault+0xc69/0xd00
handle_mm_fault+0xfc/0x2f0
do_page_fault+0x263/0x6f9
page_fault+0x34/0x40
read to 0xffff9b1700a2c1b4 of 4 bytes by task 3313 on cpu 32:
filemap_map_pages+0xc2e/0xd80
filemap_map_pages at mm/filemap.c:2625
do_fault+0x3da/0x920
__handle_mm_fault+0xc69/0xd00
handle_mm_fault+0xfc/0x2f0
do_page_fault+0x263/0x6f9
page_fault+0x34/0x40
Reported by Kernel Concurrency Sanitizer on:
CPU: 32 PID: 3313 Comm: systemd-udevd Tainted: G W L 5.5.0-next-20200210+ #1
Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019
ra.mmap_miss is used to contribute the readahead decisions, a data race
could be undesirable. Both the read and write is only under non-exclusive
mmap_sem, two concurrent writers could even underflow the counter. Fix
the underflow by writing to a local variable before committing a final
store to ra.mmap_miss given a small inaccuracy of the counter should be
acceptable.
Link: http://lkml.kernel.org/r/20200211030134.1847-1-cai@lca.pw
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Qian Cai <cai@lca.pw>
Tested-by: Qian Cai <cai@lca.pw>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Marco Elver <elver@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>1 parent db63258 commit 4f9669f
1 file changed
+13
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2409 | 2409 | | |
2410 | 2410 | | |
2411 | 2411 | | |
| 2412 | + | |
2412 | 2413 | | |
2413 | 2414 | | |
2414 | 2415 | | |
| |||
2424 | 2425 | | |
2425 | 2426 | | |
2426 | 2427 | | |
2427 | | - | |
2428 | | - | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
2429 | 2431 | | |
2430 | 2432 | | |
2431 | 2433 | | |
2432 | 2434 | | |
2433 | 2435 | | |
2434 | | - | |
| 2436 | + | |
2435 | 2437 | | |
2436 | 2438 | | |
2437 | 2439 | | |
| |||
2457 | 2459 | | |
2458 | 2460 | | |
2459 | 2461 | | |
| 2462 | + | |
2460 | 2463 | | |
2461 | 2464 | | |
2462 | 2465 | | |
2463 | 2466 | | |
2464 | 2467 | | |
2465 | | - | |
2466 | | - | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
2467 | 2471 | | |
2468 | 2472 | | |
2469 | 2473 | | |
| |||
2629 | 2633 | | |
2630 | 2634 | | |
2631 | 2635 | | |
| 2636 | + | |
2632 | 2637 | | |
2633 | 2638 | | |
2634 | 2639 | | |
| |||
2665 | 2670 | | |
2666 | 2671 | | |
2667 | 2672 | | |
2668 | | - | |
2669 | | - | |
| 2673 | + | |
| 2674 | + | |
2670 | 2675 | | |
2671 | 2676 | | |
2672 | 2677 | | |
| |||
2686 | 2691 | | |
2687 | 2692 | | |
2688 | 2693 | | |
| 2694 | + | |
2689 | 2695 | | |
2690 | 2696 | | |
2691 | 2697 | | |
| |||
0 commit comments