Commit e630bfa
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.
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Qian Cai <cai@lca.pw>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Tested-by: Qian Cai <cai@lca.pw>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Marco Elver <elver@google.com>
Link: http://lkml.kernel.org/r/20200211030134.1847-1-cai@lca.pw
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>1 parent b96a3db commit e630bfa
1 file changed
Lines changed: 13 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2468 | 2468 | | |
2469 | 2469 | | |
2470 | 2470 | | |
| 2471 | + | |
2471 | 2472 | | |
2472 | 2473 | | |
2473 | 2474 | | |
| |||
2483 | 2484 | | |
2484 | 2485 | | |
2485 | 2486 | | |
2486 | | - | |
2487 | | - | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
2488 | 2490 | | |
2489 | 2491 | | |
2490 | 2492 | | |
2491 | 2493 | | |
2492 | 2494 | | |
2493 | | - | |
| 2495 | + | |
2494 | 2496 | | |
2495 | 2497 | | |
2496 | 2498 | | |
| |||
2516 | 2518 | | |
2517 | 2519 | | |
2518 | 2520 | | |
| 2521 | + | |
2519 | 2522 | | |
2520 | 2523 | | |
2521 | 2524 | | |
2522 | 2525 | | |
2523 | 2526 | | |
2524 | | - | |
2525 | | - | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
2526 | 2530 | | |
2527 | 2531 | | |
2528 | 2532 | | |
| |||
2688 | 2692 | | |
2689 | 2693 | | |
2690 | 2694 | | |
| 2695 | + | |
2691 | 2696 | | |
2692 | 2697 | | |
2693 | 2698 | | |
| |||
2724 | 2729 | | |
2725 | 2730 | | |
2726 | 2731 | | |
2727 | | - | |
2728 | | - | |
| 2732 | + | |
| 2733 | + | |
2729 | 2734 | | |
2730 | 2735 | | |
2731 | 2736 | | |
| |||
2745 | 2750 | | |
2746 | 2751 | | |
2747 | 2752 | | |
| 2753 | + | |
2748 | 2754 | | |
2749 | 2755 | | |
2750 | 2756 | | |
| |||
0 commit comments