Re: [PATCH] blk-throttle: fix race between submitter and throttler thread

From: Dmitry Monakhov
Date: Thu May 20 2021 - 13:02:51 EST




> Hello, Dmitry.
>
> This generally looks good to me. A couple nits below.
>
>> @@ -277,6 +277,8 @@ static struct bio *__bio_chain_endio(struct bio *bio)
>> {
>> struct bio *parent = bio->bi_private;
>>
>> + BUG_ON(!bio_flagged(parent, BIO_CHAIN));
>
> Let's do WARN_ON_ONCE().
If we hit this point when this mean that ->bio_end_io will be called for parent bio.
Which likely result in use-after-free for that bio and silent data corruption for bio's pages
So IMHO BUG_ON is more appropriate here. What do you think?
>
>> @@ -2270,6 +2285,8 @@ bool blk_throtl_bio(struct bio *bio)
>>
>> td->nr_queued[rw]++;
>> throtl_add_bio_tg(bio, qn, tg);
>
> Can you add some comment here explaining how now that the bio is added for
> throttling, there are two accessors of it and the bio must not be modified
> without holding the lock?
Sound reasonable, will be back with updated comments.
>
> Thank you.
>
> --
> tejun