All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bart.vanassche@wdc.com>,
	Hannes Reinecke <hare@suse.de>,
	Johannes Thumshirn <jthumshirn@suse.de>,
	Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 04/11] block: Protect queue flag changes with the queue lock
Date: Wed, 28 Feb 2018 11:28:16 -0800	[thread overview]
Message-ID: <20180228192823.5191-5-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20180228192823.5191-1-bart.vanassche@wdc.com>

Since the queue flags may be changed concurrently from multiple
contexts after a queue becomes visible in sysfs, make these changes
safe by protecting these with the queue lock.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Ming Lei <ming.lei@redhat.com>
---
 block/blk-mq.c   | 3 +--
 block/blk-stat.c | 6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 67026494119b..899f357962e8 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3022,8 +3022,7 @@ EXPORT_SYMBOL_GPL(blk_mq_update_nr_hw_queues);
 /* Enable polling stats and return whether they were already enabled. */
 static bool blk_poll_stats_enable(struct request_queue *q)
 {
-	if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags) ||
-	    test_and_set_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags))
+	if (blk_queue_flag_test_and_set(QUEUE_FLAG_POLL_STATS, q))
 		return true;
 	blk_stat_add_callback(q, q->poll_cb);
 	return false;
diff --git a/block/blk-stat.c b/block/blk-stat.c
index b664aa6df725..bd365a95fcf8 100644
--- a/block/blk-stat.c
+++ b/block/blk-stat.c
@@ -152,7 +152,7 @@ void blk_stat_add_callback(struct request_queue *q,
 
 	spin_lock(&q->stats->lock);
 	list_add_tail_rcu(&cb->list, &q->stats->callbacks);
-	queue_flag_set(QUEUE_FLAG_STATS, q);
+	blk_queue_flag_set(QUEUE_FLAG_STATS, q);
 	spin_unlock(&q->stats->lock);
 }
 EXPORT_SYMBOL_GPL(blk_stat_add_callback);
@@ -163,7 +163,7 @@ void blk_stat_remove_callback(struct request_queue *q,
 	spin_lock(&q->stats->lock);
 	list_del_rcu(&cb->list);
 	if (list_empty(&q->stats->callbacks) && !q->stats->enable_accounting)
-		queue_flag_clear(QUEUE_FLAG_STATS, q);
+		blk_queue_flag_clear(QUEUE_FLAG_STATS, q);
 	spin_unlock(&q->stats->lock);
 
 	del_timer_sync(&cb->timer);
@@ -191,7 +191,7 @@ void blk_stat_enable_accounting(struct request_queue *q)
 {
 	spin_lock(&q->stats->lock);
 	q->stats->enable_accounting = true;
-	queue_flag_set(QUEUE_FLAG_STATS, q);
+	blk_queue_flag_set(QUEUE_FLAG_STATS, q);
 	spin_unlock(&q->stats->lock);
 }
 
-- 
2.16.2

  parent reply	other threads:[~2018-02-28 19:28 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 19:28 [PATCH 00/11] Make all concurrent queue flag manipulations safe Bart Van Assche
2018-02-28 19:28 ` [PATCH 01/11] block: Reorder the queue flag manipulaton function definitions Bart Van Assche
2018-03-01  8:42   ` Johannes Thumshirn
2018-03-02 23:09   ` Martin K. Petersen
2018-03-08  1:02     ` Bart Van Assche
2018-02-28 19:28 ` [PATCH 02/11] block: Use the queue_flag_*() functions instead of open-coding these Bart Van Assche
2018-03-01  8:43   ` Johannes Thumshirn
2018-03-02 23:09   ` Martin K. Petersen
2018-02-28 19:28 ` [PATCH 03/11] block: Introduce blk_queue_flag_{set,clear,test_and_{set,clear}}() Bart Van Assche
2018-03-01  8:46   ` Johannes Thumshirn
2018-03-02 23:11   ` Martin K. Petersen
2018-02-28 19:28 ` Bart Van Assche [this message]
2018-03-01  8:51   ` [PATCH 04/11] block: Protect queue flag changes with the queue lock Johannes Thumshirn
2018-03-01 15:19     ` Bart Van Assche
2018-03-01 15:22       ` Johannes Thumshirn
2018-03-02 23:12   ` Martin K. Petersen
2018-02-28 19:28 ` [PATCH 05/11] mtip32xx: Use the blk_queue_flag_*() functions Bart Van Assche
2018-03-01  8:52   ` Johannes Thumshirn
2018-03-02 23:12   ` Martin K. Petersen
2018-02-28 19:28 ` [PATCH 06/11] bcache: Use the blk_queue_flag_{set,clear}() functions Bart Van Assche
2018-02-28 20:18   ` Michael Lyle
2018-03-01  8:52   ` Johannes Thumshirn
2018-03-02 23:12   ` Martin K. Petersen
2018-02-28 19:28 ` [PATCH 07/11] iscsi: Use blk_queue_flag_set() Bart Van Assche
2018-03-01  8:53   ` Johannes Thumshirn
2018-03-02 23:14   ` Martin K. Petersen
2018-02-28 19:28 ` [PATCH 08/11] target/tcm_loop: " Bart Van Assche
2018-03-01  8:53   ` Johannes Thumshirn
2018-03-02 23:17   ` Martin K. Petersen
2018-02-28 19:28 ` [PATCH 09/11] block: Use blk_queue_flag_*() in drivers instead of queue_flag_*() Bart Van Assche
2018-03-02 23:17   ` Martin K. Petersen
2018-02-28 19:28 ` [PATCH 10/11] block: Complain if queue_flag_(set|clear)_unlocked() is abused Bart Van Assche
2018-03-01  8:57   ` Johannes Thumshirn
2018-03-02 23:18   ` Martin K. Petersen
2018-02-28 19:28 ` [PATCH 11/11] block: Move the queue_flag_*() functions from a public into a private header file Bart Van Assche
2018-03-01  8:57   ` Johannes Thumshirn
2018-03-02 23:20   ` Martin K. Petersen

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=20180228192823.5191-5-bart.vanassche@wdc.com \
    --to=bart.vanassche@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jthumshirn@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.