From: Sasha Levin Date: Mon, 29 Jun 2020 14:35:22 +0000 (-0400) Subject: Fixes for 4.9 X-Git-Tag: v5.7.7~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6761c0ce69493c6ceec5ede9d4b0068fc5613124;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 4.9 Signed-off-by: Sasha Levin --- diff --git a/queue-4.9/series b/queue-4.9/series index 7faea508686..453fe85dab2 100644 --- a/queue-4.9/series +++ b/queue-4.9/series @@ -187,3 +187,4 @@ sunrpc-properly-set-the-subbuf-parameter-of-xdr_buf_subsegment.patch pnfs-flexfiles-fix-list-corruption-if-the-mirror-count-changes.patch nfsv4-fix-close-not-waiting-for-direct-io-compeletion.patch alsa-usb-audio-fix-invalid-null-check-in-snd_emuusb_set_samplerate.patch +xfs-add-agf-freeblocks-verify-in-xfs_agf_verify.patch diff --git a/queue-4.9/xfs-add-agf-freeblocks-verify-in-xfs_agf_verify.patch b/queue-4.9/xfs-add-agf-freeblocks-verify-in-xfs_agf_verify.patch new file mode 100644 index 00000000000..4404fc4b9e7 --- /dev/null +++ b/queue-4.9/xfs-add-agf-freeblocks-verify-in-xfs_agf_verify.patch @@ -0,0 +1,112 @@ +From 2821c8e2295d6c6ee9635693d0b5119032c30645 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 21 Feb 2020 07:38:20 -0800 +Subject: xfs: add agf freeblocks verify in xfs_agf_verify + +From: Zheng Bin + +[ Upstream commit d0c7feaf87678371c2c09b3709400be416b2dc62 ] + +We recently used fuzz(hydra) to test XFS and automatically generate +tmp.img(XFS v5 format, but some metadata is wrong) + +xfs_repair information(just one AG): +agf_freeblks 0, counted 3224 in ag 0 +agf_longest 536874136, counted 3224 in ag 0 +sb_fdblocks 613, counted 3228 + +Test as follows: +mount tmp.img tmpdir +cp file1M tmpdir +sync + +In 4.19-stable, sync will stuck, the reason is: +xfs_mountfs + xfs_check_summary_counts + if ((!xfs_sb_version_haslazysbcount(&mp->m_sb) || + XFS_LAST_UNMOUNT_WAS_CLEAN(mp)) && + !xfs_fs_has_sickness(mp, XFS_SICK_FS_COUNTERS)) + return 0; -->just return, incore sb_fdblocks still be 613 + xfs_initialize_perag_data + +cp file1M tmpdir -->ok(write file to pagecache) +sync -->stuck(write pagecache to disk) +xfs_map_blocks + xfs_iomap_write_allocate + while (count_fsb != 0) { + nimaps = 0; + while (nimaps == 0) { --> endless loop + nimaps = 1; + xfs_bmapi_write(..., &nimaps) --> nimaps becomes 0 again +xfs_bmapi_write + xfs_bmap_alloc + xfs_bmap_btalloc + xfs_alloc_vextent + xfs_alloc_fix_freelist + xfs_alloc_space_available -->fail(agf_freeblks is 0) + +In linux-next, sync not stuck, cause commit c2b3164320b5 ("xfs: +use the latest extent at writeback delalloc conversion time") remove +the above while, dmesg is as follows: +[ 55.250114] XFS (loop0): page discard on page ffffea0008bc7380, inode 0x1b0c, offset 0. + +Users do not know why this page is discard, the better soultion is: +1. Like xfs_repair, make sure sb_fdblocks is equal to counted +(xfs_initialize_perag_data did this, who is not called at this mount) +2. Add agf verify, if fail, will tell users to repair + +This patch use the second soultion. + +Signed-off-by: Zheng Bin +Signed-off-by: Ren Xudong +Reviewed-by: Darrick J. Wong +Signed-off-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/libxfs/xfs_alloc.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c +index e567551402a65..b904d46343556 100644 +--- a/fs/xfs/libxfs/xfs_alloc.c ++++ b/fs/xfs/libxfs/xfs_alloc.c +@@ -2507,6 +2507,13 @@ xfs_agf_verify( + be32_to_cpu(agf->agf_flcount) <= XFS_AGFL_SIZE(mp))) + return false; + ++ if (be32_to_cpu(agf->agf_length) > mp->m_sb.sb_dblocks) ++ return false; ++ ++ if (be32_to_cpu(agf->agf_freeblks) < be32_to_cpu(agf->agf_longest) || ++ be32_to_cpu(agf->agf_freeblks) > be32_to_cpu(agf->agf_length)) ++ return false; ++ + if (be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) < 1 || + be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) < 1 || + be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) > XFS_BTREE_MAXLEVELS || +@@ -2518,6 +2525,10 @@ xfs_agf_verify( + be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) > XFS_BTREE_MAXLEVELS)) + return false; + ++ if (xfs_sb_version_hasrmapbt(&mp->m_sb) && ++ be32_to_cpu(agf->agf_rmap_blocks) > be32_to_cpu(agf->agf_length)) ++ return false; ++ + /* + * during growfs operations, the perag is not fully initialised, + * so we can't use it for any useful checking. growfs ensures we can't +@@ -2531,6 +2542,11 @@ xfs_agf_verify( + be32_to_cpu(agf->agf_btreeblks) > be32_to_cpu(agf->agf_length)) + return false; + ++ if (xfs_sb_version_hasreflink(&mp->m_sb) && ++ be32_to_cpu(agf->agf_refcount_blocks) > ++ be32_to_cpu(agf->agf_length)) ++ return false; ++ + if (xfs_sb_version_hasreflink(&mp->m_sb) && + (be32_to_cpu(agf->agf_refcount_level) < 1 || + be32_to_cpu(agf->agf_refcount_level) > XFS_BTREE_MAXLEVELS)) +-- +2.25.1 +