Btrfs: raid56: fix race between merge_bio and rbio_orig_end_io
authorLiu Bo <bo.li.liu@oracle.com>
Wed, 10 Jan 2018 01:36:25 +0000 (18:36 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 26 Apr 2018 09:02:09 +0000 (11:02 +0200)
commit48b8839d91a49cde35ddab422a99ef908391aeee
tree7042622bc4edf64b9b9743b4a782d05784a799a0
parentebe064401f078ae68f2532833ad8f212b6ee2be2
Btrfs: raid56: fix race between merge_bio and rbio_orig_end_io

[ Upstream commit 7583d8d088ff2c323b1d4f15b191ca2c23d32558 ]

Before rbio_orig_end_io() goes to free rbio, rbio may get merged with
more bios from other rbios and rbio->bio_list becomes non-empty,
in that case, these newly merged bios don't end properly.

Once unlock_stripe() is done, rbio->bio_list will not be updated any
more and we can call bio_endio() on all queued bios.

It should only happen in error-out cases, the normal path of recover
and full stripe write have already set RBIO_RMW_LOCKED_BIT to disable
merge before doing IO, so rbio_orig_end_io() called by them doesn't
have the above issue.

Reported-by: Jérôme Carretero <cJ-ko@zougloub.eu>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/raid56.c