public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Bart Van Assche <Bart.VanAssche@wdc.com>,
	"axboe@kernel.dk" <axboe@kernel.dk>
Cc: "hch@lst.de" <hch@lst.de>,
	"ulf.hansson@linaro.org" <ulf.hansson@linaro.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"philipp.reisner@linbit.com" <philipp.reisner@linbit.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	"keescook@chromium.org" <keescook@chromium.org>
Subject: Re: [PATCH v2 2/2] block: Fix a race between the throttling code and request queue initialization
Date: Sat, 3 Feb 2018 10:51:31 +0800	[thread overview]
Message-ID: <63bb4057-d502-69cd-0385-10ae33bd6649@linux.alibaba.com> (raw)
In-Reply-To: <1517588518.2675.14.camel@wdc.com>

Hi Bart,

On 18/2/3 00:21, Bart Van Assche wrote:
> On Fri, 2018-02-02 at 09:02 +0800, Joseph Qi wrote:
>> We triggered this race when using single queue. I'm not sure if it
>> exists in multi-queue.
> 
> Regarding the races between modifying the queue_lock pointer and the code that
> uses that pointer, I think the following construct in blk_cleanup_queue() is
> sufficient to avoid races between the queue_lock pointer assignment and the code
> that executes concurrently with blk_cleanup_queue():
> 
> 	spin_lock_irq(lock);
> 	if (q->queue_lock != &q->__queue_lock)
> 		q->queue_lock = &q->__queue_lock;
> 	spin_unlock_irq(lock);
> 
IMO, the race also exists.

blk_cleanup_queue                   blkcg_print_blkgs
  spin_lock_irq(lock) (1)           spin_lock_irq(blkg->q->queue_lock) (2,5)
    q->queue_lock = &q->__queue_lock (3)
  spin_unlock_irq(lock) (4)
                                    spin_unlock_irq(blkg->q->queue_lock) (6)

(1) take driver lock;
(2) busy loop for driver lock;
(3) override driver lock with internal lock;
(4) unlock driver lock; 
(5) can take driver lock now;
(6) but unlock internal lock.

If we get blkg->q->queue_lock to local first like blk_cleanup_queue,
it indeed can fix the different lock use in lock/unlock. But since
blk_cleanup_queue has overridden queue lock to internal lock now, I'm
afraid we couldn't still use driver lock in blkcg_print_blkgs.

Thanks,
Joseph

> In other words, I think that this patch series should be sufficient to address
> all races between .queue_lock assignments and the code that uses that pointer.
> 
> Thanks,
> 
> Bart.
> 

  reply	other threads:[~2018-02-03  2:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-31 23:52 [PATCH v2 0/2] block: Fix a race between the throttling code and request queue initialization Bart Van Assche
2018-01-31 23:52 ` [PATCH v2 1/2] block: Add a third argument to blk_alloc_queue_node() Bart Van Assche
2018-01-31 23:53 ` [PATCH v2 2/2] block: Fix a race between the throttling code and request queue initialization Bart Van Assche
2018-02-01  1:53   ` Joseph Qi
2018-02-01 16:16     ` Bart Van Assche
2018-02-02  1:02       ` Joseph Qi
2018-02-02 14:52         ` Jens Axboe
2018-02-02 16:21         ` Bart Van Assche
2018-02-03  2:51           ` Joseph Qi [this message]
2018-02-05 17:58             ` Bart Van Assche
2018-02-07 11:54               ` Jan Kara

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=63bb4057-d502-69cd-0385-10ae33bd6649@linux.alibaba.com \
    --to=joseph.qi@linux.alibaba.com \
    --cc=Bart.VanAssche@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=keescook@chromium.org \
    --cc=linux-block@vger.kernel.org \
    --cc=philipp.reisner@linbit.com \
    --cc=stable@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /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