dec_pending() is given an error status (possibly 0) to be recorded against a bio. It can be called several times on the one 'struct dm_io', and it is careful to only assign a non-zero error to io->status. However when it then assigned io->status to bio->bi_status, it is not careful and could overwrite a genuine error status with 0. This can happen when chained bios are in use. If a bio is chained beneath the bio that this dm_io is handling, the child bio might complete and set bio->bi_status before the dm_io completes. This has been possible since chained bios were introduced in 3.14, and has become a lot easier to trigger with commit 18a25da84354 ("dm: ensure bio submission follows a depth-first tree walk") as that commit caused dm to start using chained bios itself. A particular failure mode is that if a bio spans an 'error' target and a working target, the 'error' fragment will complete instantly and set the ->bi_status, and the other fragment will normally complete a little later, and will clear ->bi_status. The fix is simply to only assign io_error to bio->bi_status when io_error is not zero.
Unified · Split
| @@ -903,7 +903,8 @@ static void dec_pending(struct dm_io *io, blk_status_t error) · 902 unmodified lines | |||
| 903 | queue_io(md, bio); | 903 | queue_io(md, bio); |
| 904 | } else { | 904 | } else { |
| 905 | /* done with normal IO or empty flush */ | 905 | /* done with normal IO or empty flush */ |
| 906 | bio->bi_status = io_error; | 906 | if (io_error) |
| 907 | bio->bi_status = io_error; | ||
| 907 | bio_endio(bio); | 908 | bio_endio(bio); |
| 908 | } | 909 | } |
| 909 | } | 910 | } |