Commit 00d873c
ext4: avoid deadlock in fs reclaim with page writeback
Ext4 has a filesystem wide lock protecting ext4_writepages() calls to
avoid races with switching of journalled data flag or inode format. This
lock can however cause a deadlock like:
CPU0 CPU1
ext4_writepages()
percpu_down_read(sbi->s_writepages_rwsem);
ext4_change_inode_journal_flag()
percpu_down_write(sbi->s_writepages_rwsem);
- blocks, all readers block from now on
ext4_do_writepages()
ext4_init_io_end()
kmem_cache_zalloc(io_end_cachep, GFP_KERNEL)
fs_reclaim frees dentry...
dentry_unlink_inode()
iput() - last ref =>
iput_final() - inode dirty =>
write_inode_now()...
ext4_writepages() tries to acquire sbi->s_writepages_rwsem
and blocks forever
Make sure we cannot recurse into filesystem reclaim from writeback code
to avoid the deadlock.
Reported-by: syzbot+6898da502aef574c5f8a@syzkaller.appspotmail.com
Link: https://lore.kernel.org/all/0000000000004c66b405fa108e27@google.com
Fixes: c8585c6 ("ext4: fix races between changing inode journal mode and ext4_writepages")
CC: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230504124723.20205-1-jack@suse.cz
Signed-off-by: Theodore Ts'o <tytso@mit.edu>1 parent b87c7cd commit 00d873c
3 files changed
Lines changed: 40 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1684 | 1684 | | |
1685 | 1685 | | |
1686 | 1686 | | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
1687 | 1711 | | |
1688 | 1712 | | |
1689 | 1713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2783 | 2783 | | |
2784 | 2784 | | |
2785 | 2785 | | |
| 2786 | + | |
2786 | 2787 | | |
2787 | 2788 | | |
2788 | 2789 | | |
2789 | 2790 | | |
2790 | | - | |
| 2791 | + | |
2791 | 2792 | | |
2792 | 2793 | | |
2793 | 2794 | | |
| |||
2796 | 2797 | | |
2797 | 2798 | | |
2798 | 2799 | | |
2799 | | - | |
| 2800 | + | |
2800 | 2801 | | |
2801 | 2802 | | |
2802 | 2803 | | |
| |||
2824 | 2825 | | |
2825 | 2826 | | |
2826 | 2827 | | |
| 2828 | + | |
2827 | 2829 | | |
2828 | 2830 | | |
2829 | 2831 | | |
2830 | 2832 | | |
2831 | | - | |
| 2833 | + | |
2832 | 2834 | | |
2833 | 2835 | | |
2834 | 2836 | | |
2835 | 2837 | | |
2836 | 2838 | | |
2837 | | - | |
| 2839 | + | |
2838 | 2840 | | |
2839 | 2841 | | |
2840 | 2842 | | |
| |||
5928 | 5930 | | |
5929 | 5931 | | |
5930 | 5932 | | |
5931 | | - | |
| 5933 | + | |
5932 | 5934 | | |
5933 | 5935 | | |
5934 | 5936 | | |
| |||
5966 | 5968 | | |
5967 | 5969 | | |
5968 | 5970 | | |
5969 | | - | |
| 5971 | + | |
5970 | 5972 | | |
5971 | 5973 | | |
5972 | 5974 | | |
| |||
5983 | 5985 | | |
5984 | 5986 | | |
5985 | 5987 | | |
5986 | | - | |
| 5988 | + | |
5987 | 5989 | | |
5988 | 5990 | | |
5989 | 5991 | | |
5990 | 5992 | | |
5991 | 5993 | | |
5992 | 5994 | | |
5993 | 5995 | | |
5994 | | - | |
| 5996 | + | |
5995 | 5997 | | |
5996 | 5998 | | |
5997 | 5999 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
411 | | - | |
412 | 411 | | |
413 | 412 | | |
414 | 413 | | |
| |||
418 | 417 | | |
419 | 418 | | |
420 | 419 | | |
| 420 | + | |
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| |||
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
437 | | - | |
| 437 | + | |
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
| |||
586 | 586 | | |
587 | 587 | | |
588 | 588 | | |
589 | | - | |
| 589 | + | |
590 | 590 | | |
591 | 591 | | |
592 | 592 | | |
| |||
605 | 605 | | |
606 | 606 | | |
607 | 607 | | |
| 608 | + | |
608 | 609 | | |
609 | 610 | | |
610 | 611 | | |
| |||
621 | 622 | | |
622 | 623 | | |
623 | 624 | | |
624 | | - | |
| 625 | + | |
625 | 626 | | |
626 | 627 | | |
627 | 628 | | |
| |||
665 | 666 | | |
666 | 667 | | |
667 | 668 | | |
668 | | - | |
| 669 | + | |
669 | 670 | | |
670 | 671 | | |
0 commit comments