Re: [PATCH v4 3/3] block: prevent race condition on bi_status in __bio_chain_endio

From: Christoph Hellwig
Date: Mon Dec 01 2025 - 06:28:15 EST


On Mon, Dec 01, 2025 at 11:22:32AM +0100, Andreas Gruenbacher wrote:
> > - if (bio->bi_status && !parent->bi_status)
> > - parent->bi_status = bio->bi_status;
> > + if (bio->bi_status)
> > + cmpxchg(&parent->bi_status, 0, bio->bi_status);
>
> Hmm. I don't think cmpxchg() actually is of any value here: for all
> the chained bios, bi_status is initialized to 0, and it is only set
> again (to a non-0 value) when a failure occurs. When there are
> multiple failures, we only need to make sure that one of those
> failures is eventually reported, but for that, a simple assignment is
> enough here.

A simple assignment doesn't guarantee atomicy. It also overrides
earlier with later status codes, which might not be desirable.