[BUG] There are several bug reports of btrfs/125 failure recently, either causing balance failure (-EIO), or even kernel crash. The balance failure looks like this: Mount normal and balance +ERROR: error during balancing '/mnt/scratch': Input/output error +There may be more info in syslog - try dmesg | tail +md5sum: /mnt/scratch/tf2: Input/output error The test case btrfs/125 is not reliable in the past, and has been discussed several times: https://lore.kernel.org/linux-btrfs/CAL3q7H4oa70DUhOFE7kot62KjxcbvvZKxu62VfLpAcmgsinBFw@xxxxxxxxxxxxxx/ https://lore.kernel.org/linux-btrfs/53f7bace2ac75d88ace42dd811d48b7912647301.1654672140.git.wqu@xxxxxxxx/#t [CAUSE] There are several different factors involved. 1. RMW mix the old and new metadata, causing unrepairable corruption E.g. with the following layout: data 1 |<- Stale metadata ->| (from the out-of-date device) data 2 | Unused | parity |PPPPPPPPPPPPPPPPPPPP| In above case, although metadata on data 1 is out-of-date, we can still rebuild the correct data from parity and data 2. But if we have new metadata writes into the data 2 stripe, an RMW will screw up the whole situation: data 1 |<- Stale metadata ->| (from the out-of-date device) data 2 |<- New metadata ->| parity |XXXXXXXXXXXXXXXXXXXX| The RMW will use the stale metadata and new metadata to calculate new parity. The resulted new parity will no longer be able to recover the old data 1. This is a known bug, thus our documentation is already recommending to avoid RAID56 for metadata usage. > Metadata > Do not use raid5 nor raid6 for metadata. Use raid1 or raid1c3 > respectively. And this is very hard to fix, unlike data we can fetch the data csum and verify during RMW, we can not do that during RMW. At the timing of RMW, we're holding the rbio lock for the full stripe. If the extent tree search requires a read-recover, it will generate another rbio, which may cover the same full stripe we're working on, leading to a deadlock. Furthermore the current RAID56 repair code is all based on veritical sectors, but metadata can cross several horizontal sectors. This will require multiple combinations to repair a metadata. 2. Crash caused by double freeing a bio By chance if the above RMW corrupted csum tree, then during btrfs_submit_chunk() we will hit an error path that leads to double freeing of a bio, resulting crash or a KASAN report. Thankfully the patch fixing the use-after-free is already sent to the mailing list: https://lore.kernel.org/linux-btrfs/f4f916352ddf3f80048567ec7d8cc64cb388dc09.1724493430.git.wqu@xxxxxxxx/ [WORKAROUND] Since it's very hard to fix the RAID56 metadata problem without a deadlock or a huge code rework, for now just use RAID1 for the metadata of this particular test case. There may be a chance to fix the situation by properly marking the missing-then-reappear device as out-of-date, so no direct read from that device. But that will also be a huge new feature, not something can be done immediately. Reviewed-by: Filipe Manana <fdmanana@xxxxxxxx> Signed-off-by: Qu Wenruo <wqu@xxxxxxxx> --- Changelog: v2: - Add links to the past discussion of the btrfs/125 failure - Add a link to the kernel fix of the use-after-free bug --- tests/btrfs/125 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/btrfs/125 b/tests/btrfs/125 index 31379d81..c8c0dd42 100755 --- a/tests/btrfs/125 +++ b/tests/btrfs/125 @@ -70,7 +70,7 @@ count=$(($max_fs_sz / 1000000)) echo >> $seqres.full echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full echo "-----Initialize -----" >> $seqres.full -_scratch_pool_mkfs "-mraid5 -draid5" >> $seqres.full 2>&1 +_scratch_pool_mkfs "-mraid1 -draid5" >> $seqres.full 2>&1 _scratch_mount >> $seqres.full 2>&1 dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \ >>$seqres.full 2>&1 -- 2.46.0