From: Khazhy Kumykov <khazhy@google.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Ming Lei <ming.lei@redhat.com>, Hannes Reinecke <hare@suse.de>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
John Garry <john.garry@huawei.com>,
"Shin'ichiro Kawasaki" <shinichiro.kawasaki@wdc.com>
Subject: Re: [PATCH v4 3/3] blk-mq: Fix a race between iterating over requests and freeing requests
Date: Fri, 2 Apr 2021 20:37:30 -0700 [thread overview]
Message-ID: <CACGdZYKbV6QHaPJveUyf34iwgMRV2sDcSmrue23k=EfSWeLgjA@mail.gmail.com> (raw)
In-Reply-To: <229d08ec-7ae9-31f2-9f7c-ae340e372c56@acm.org>
[-- Attachment #1: Type: text/plain, Size: 2346 bytes --]
On Fri, Apr 2, 2021 at 8:26 PM Bart Van Assche <bvanassche@acm.org> wrote:
>
> On 4/2/21 4:59 PM, Khazhy Kumykov wrote:
> > On Sun, Mar 28, 2021 at 7:00 PM Bart Van Assche <bvanassche@acm.org> wrote:
> >> @@ -209,7 +209,12 @@ static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
> >>
> >> if (!reserved)
> >> bitnr += tags->nr_reserved_tags;
> >> - rq = tags->rqs[bitnr];
> >> + /*
> >> + * See also the percpu_ref_tryget() and blk_queue_exit() calls in
> >> + * blk_mq_queue_tag_busy_iter().
> >> + */
> >> + rq = rcu_dereference_check(tags->rqs[bitnr],
> >> + !percpu_ref_is_zero(&hctx->queue->q_usage_counter));
> >
> > do we need to worry about rq->q != hctx->queue here? i.e., could we
> > run into use-after-free on rq->q == hctx->queue check below, since
> > rq->q->q_usage_counter might not be raised? Once we verify rq->q ==
> > hctx->queue, i agree q_usage_counter is sufficient then
>
> That's a great question. I will change the second
> rcu_dereference_check() argument into 'true' and elaborate the comment
> above rcu_dereference_check().
>
> >> -static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
> >> +static bool __bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr,
> >> + void *data)
> >> {
> >> struct bt_tags_iter_data *iter_data = data;
> >> struct blk_mq_tags *tags = iter_data->tags;
> >> @@ -275,7 +286,7 @@ static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
> >> if (iter_data->flags & BT_TAG_ITER_STATIC_RQS)
> >> rq = tags->static_rqs[bitnr];
> >> else
> >> - rq = tags->rqs[bitnr];
> >> + rq = rcu_dereference_check(tags->rqs[bitnr], true);
> >
> > lockdep_is_held(&tags->iter_rwsem) ?
>
> I will change the second rcu_dereference_check() argument into the
> following:
>
> rcu_read_lock_held() || lockdep_is_held(&tags->iter_rwsem)
rcu_dereference_check() already has a || rcu_read_lock_held(), fwiw
>
> >> + /*
> >> + * Freeing tags happens with the request queue frozen so the
> >> + * srcu dereference below is protected by the request queue
> >
> > s/srcu/rcu
>
> Thanks, will fix.
>
> Bart.
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 3996 bytes --]
next prev parent reply other threads:[~2021-04-03 3:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-29 2:00 [PATCH v4 0/3] blk-mq: Fix a race between iterating over requests and freeing requests Bart Van Assche
2021-03-29 2:00 ` [PATCH v4 1/3] blk-mq: Move the elevator_exit() definition Bart Van Assche
2021-03-29 2:00 ` [PATCH v4 2/3] blk-mq: Introduce atomic variants of the tag iteration functions Bart Van Assche
2021-03-29 2:00 ` [PATCH v4 3/3] blk-mq: Fix a race between iterating over requests and freeing requests Bart Van Assche
2021-04-02 23:59 ` Khazhy Kumykov
2021-04-03 3:25 ` Bart Van Assche
2021-04-03 3:37 ` Khazhy Kumykov [this message]
2021-04-04 1:11 ` Bart Van Assche
2021-03-30 22:30 ` [PATCH v4 0/3] " Bart Van Assche
2021-04-01 0:48 ` Shinichiro Kawasaki
2021-04-01 1:55 ` Martin K. Petersen
2021-04-02 10:00 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACGdZYKbV6QHaPJveUyf34iwgMRV2sDcSmrue23k=EfSWeLgjA@mail.gmail.com' \
--to=khazhy@google.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=johannes.thumshirn@wdc.com \
--cc=john.garry@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=shinichiro.kawasaki@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).