Make all concurrent queue flag manipulations safe
Subsystems (24)
v2 cover Make all concurrent queue flag manipulations safe
Hello Jens,
As you probably know there is considerable confusion in the block layer core and in block drivers about how to protect queue flag changes against concurrent modifications. Some code protects these changes with the queue lock, other code uses atomic operations and some code does not protect queue flag changes against concurrent changes at all. Hence this patch series that protects all queue flag changes consistently with the queue lock and that removes functions that are not safe in a concurrent context from the public block layer header files.
Please consider these patches for kernel v4.17.
Note: it may be a good idea to postpone patch 11 until after the kernel v4.17 merge window to avoid merge conflicts.
Thanks,
Bart.
Changes compared to v1:
- Restored one test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags) call to avoid introducing a slowdown in the polling hot path.
Bart Van Assche (11):
block: Reorder the queue flag manipulation function definitions
block: Use the queue_flag_*() functions instead of open-coding these
block: Introduce blk_queue_flag_{set,clear,test_and_{set,clear}}()
block: Protect queue flag changes with the queue lock
mtip32xx: Use the blk_queue_flag_*() functions
bcache: Use the blk_queue_flag_{set,clear}() functions
iscsi: Use blk_queue_flag_set()
target/tcm_loop: Use blk_queue_flag_set()
block: Use blk_queue_flag_*() in drivers instead of queue_flag_*()
block: Complain if queue_flag_(set|clear)_unlocked() is abused
block: Move the queue_flag_*() functions from a public into a private
header file
block/blk-core.c | 93 +++++++++++++++++++++++------ block/blk-mq.c | 16 ++--- block/blk-settings.c | 6 +- block/blk-stat.c | 6 +- block/blk-sysfs.c | 22 +++---- block/blk-timeout.c | 6 +- block/blk.h | 69 +++++++++++++++++++++ block/bsg-lib.c | 4 +- drivers/block/drbd/drbd_nl.c | 4 +- drivers/block/loop.c | 10 ++-- drivers/block/mtip32xx/mtip32xx.c | 8 +-- drivers/block/nbd.c | 8 +-- drivers/block/null_blk.c | 6 +- drivers/block/rbd.c | 4 +- drivers/block/rsxx/dev.c | 6 +- drivers/block/skd_main.c | 4 +- drivers/block/xen-blkfront.c | 10 ++-- drivers/block/zram/zram_drv.c | 6 +- drivers/ide/ide-disk.c | 4 +- drivers/ide/ide-probe.c | 2 +- drivers/lightnvm/pblk-init.c | 2 +- drivers/md/bcache/super.c | 6 +- drivers/md/dm-table.c | 16 ++--- drivers/md/md-linear.c | 4 +- drivers/md/md.c | 4 +- drivers/md/raid0.c | 4 +- drivers/md/raid1.c | 6 +- drivers/md/raid10.c | 6 +- drivers/md/raid5.c | 4 +- drivers/mmc/core/queue.c | 8 +-- drivers/mtd/mtd_blkdevs.c | 6 +- drivers/nvdimm/blk.c | 2 +- drivers/nvdimm/btt.c | 2 +- drivers/nvdimm/pmem.c | 4 +- drivers/nvme/host/core.c | 4 +- drivers/nvme/host/multipath.c | 2 +- drivers/s390/block/dasd.c | 4 +- drivers/s390/block/dcssblk.c | 2 +- drivers/s390/block/scm_blk.c | 4 +- drivers/s390/block/xpram.c | 4 +- drivers/scsi/iscsi_tcp.c | 2 +- drivers/scsi/megaraid/megaraid_sas_base.c | 2 +- drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 +- drivers/scsi/scsi_debug.c | 2 +- drivers/scsi/scsi_lib.c | 2 +- drivers/scsi/scsi_transport_sas.c | 4 +- drivers/scsi/sd.c | 8 +-- drivers/target/loopback/tcm_loop.c | 2 +- include/linux/blkdev.h | 76 +++-------------------- 50 files changed, 270 insertions(+), 220 deletions(-)
Signature · 1 line
2.16.2
PATCH v2 1/11 block: Reorder the queue flag manipulation function definitions
Move the definition of queue_flag_clear_unlocked() up and move the definition of queue_in_flight() down such that all queue flag manipulation function definitions become contiguous.
This patch does not change any functionality.
--- include/linux/blkdev.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
include/linux/blkdev.h +11 -11
@@ -724,6 +724,12 @@ static inline void queue_flag_set_unlocked(unsigned int flag,__set_bit (flag, &q->queue_flags); } +static inline void queue_flag_clear_unlocked (unsigned int flag, +struct request_queue *q) +{ +__clear_bit (flag, &q->queue_flags); +} +static inline int queue_flag_test_and_clear (unsigned int flag,struct request_queue *q) {
@@ -756,17 +762,6 @@ static inline void queue_flag_set(unsigned int flag, struct request_queue *q)__set_bit (flag, &q->queue_flags); } -static inline void queue_flag_clear_unlocked (unsigned int flag, -struct request_queue *q) -{ -__clear_bit (flag, &q->queue_flags); -} - -static inline int queue_in_flight (struct request_queue *q) -{ -return q->in_flight[0 ] + q->in_flight[1 ]; -} -static inline void queue_flag_clear (unsigned int flag,struct request_queue *q) {queue_lockdep_assert_held (q);
@@ -802,6 +797,11 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)extern int blk_set_preempt_only (struct request_queue *q);extern void blk_clear_preempt_only (struct request_queue *q); +static inline int queue_in_flight (struct request_queue *q) +{ +return q->in_flight[0 ] + q->in_flight[1 ]; +} +static inline bool blk_account_rq (struct request *rq) {return (rq->rq_flags &RQF_STARTED ) && !blk_rq_is_passthrough (rq);
Signature · 1 line
2.16.2
PATCH v2 2/11 block: Use the queue_flag_*() functions instead of open-coding these
In reply to Bart Van AsscheExcept for changing the atomic queue flag manipulations that are protected by the queue lock into non-atomic manipulations, this patch does not change any functionality.
--- block/blk-core.c | 2 +- block/blk-mq.c | 2 +- block/blk-settings.c | 4 ++-- block/blk-stat.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-)
block/blk-core.c +1 -1
@@ -995,7 +995,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id,* registered by blk_register_queue(). */ q->bypass_depth =1 ; -__set_bit (QUEUE_FLAG_BYPASS , &q->queue_flags); +queue_flag_set_unlocked (QUEUE_FLAG_BYPASS , q);init_waitqueue_head (&q->mq_freeze_wq);
block/blk-mq.c +1 -1
@@ -2698,7 +2698,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, q->queue_flags |=QUEUE_FLAG_MQ_DEFAULT ;if (!(set->flags &BLK_MQ_F_SG_MERGE )) - q->queue_flags |=1 <<QUEUE_FLAG_NO_SG_MERGE ; +queue_flag_set_unlocked (QUEUE_FLAG_NO_SG_MERGE , q); q->sg_reserved_size =INT_MAX ;
block/blk-settings.c +2 -2
@@ -861,9 +861,9 @@ void blk_queue_flush_queueable(struct request_queue *q, bool queueable) {spin_lock_irq (q->queue_lock);if (queueable) -clear_bit (QUEUE_FLAG_FLUSH_NQ , &q->queue_flags); +queue_flag_clear (QUEUE_FLAG_FLUSH_NQ , q);else -set_bit (QUEUE_FLAG_FLUSH_NQ , &q->queue_flags); +queue_flag_set (QUEUE_FLAG_FLUSH_NQ , q);spin_unlock_irq (q->queue_lock); }EXPORT_SYMBOL_GPL (blk_queue_flush_queueable);
block/blk-stat.c +3 -3
@@ -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); -set_bit (QUEUE_FLAG_STATS , &q->queue_flags); +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) -clear_bit (QUEUE_FLAG_STATS , &q->queue_flags); +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; -set_bit (QUEUE_FLAG_STATS , &q->queue_flags); +queue_flag_set (QUEUE_FLAG_STATS , q);spin_unlock (&q->stats->lock); }
Signature · 1 line
2.16.2
PATCH v2 3/11 block: Introduce blk_queue_flag_{set,clear,test_and_{set,clear}}()
In reply to Bart Van AsscheIntroduce functions that modify the queue flags and that protect these modifications with the request queue lock. Except for moving one wake_up_all() call from inside to outside a critical section, this patch does not change any functionality.
--- block/blk-core.c | 91 +++++++++++++++++++++++++++++++++++++++++--------- block/blk-mq.c | 12 ++----- block/blk-settings.c | 6 ++-- block/blk-sysfs.c | 22 ++++-------- block/blk-timeout.c | 6 ++-- include/linux/blkdev.h | 5 +++ 6 files changed, 93 insertions(+), 49 deletions(-)
block/blk-core.c +75 -16
@@ -72,6 +72,78 @@ struct kmem_cache *blk_requestq_cachep;*/ static struct workqueue_struct *kblockd_workqueue; +/** +* blk_queue_flag_set - atomically set a queue flag +* @flag: flag to be set +* @q: request queue +*/ +void blk_queue_flag_set (unsigned int flag,struct request_queue *q) +{ +unsigned long flags; + +spin_lock_irqsave (q->queue_lock, flags); +queue_flag_set (flag, q); +spin_unlock_irqrestore (q->queue_lock, flags); +} +EXPORT_SYMBOL (blk_queue_flag_set); + +/** +* blk_queue_flag_clear - atomically clear a queue flag +* @flag: flag to be cleared +* @q: request queue +*/ +void blk_queue_flag_clear (unsigned int flag,struct request_queue *q) +{ +unsigned long flags; + +spin_lock_irqsave (q->queue_lock, flags); +queue_flag_clear (flag, q); +spin_unlock_irqrestore (q->queue_lock, flags); +} +EXPORT_SYMBOL (blk_queue_flag_clear); + +/** +* blk_queue_flag_test_and_set - atomically test and set a queue flag +* @flag: flag to be set +* @q: request queue +* +* Returns the previous value of @flag - 0 if the flag was not set and 1 if +* the flag was already set. +*/ +bool blk_queue_flag_test_and_set (unsigned int flag,struct request_queue *q) +{ +unsigned long flags; +bool res; + +spin_lock_irqsave (q->queue_lock, flags); + res =queue_flag_test_and_set (flag, q); +spin_unlock_irqrestore (q->queue_lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (blk_queue_flag_test_and_set); + +/** +* blk_queue_flag_test_and_clear - atomically test and clear a queue flag +* @flag: flag to be cleared +* @q: request queue +* +* Returns the previous value of @flag - 0 if the flag was not set and 1 if +* the flag was set. +*/ +bool blk_queue_flag_test_and_clear (unsigned int flag,struct request_queue *q) +{ +unsigned long flags; +bool res; + +spin_lock_irqsave (q->queue_lock, flags); + res =queue_flag_test_and_clear (flag, q); +spin_unlock_irqrestore (q->queue_lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (blk_queue_flag_test_and_clear); +static void blk_clear_congested (struct request_list *rl,int sync) {#ifdef CONFIG_CGROUP_WRITEBACK
@@ -362,25 +434,14 @@ EXPORT_SYMBOL(blk_sync_queue);*/ int blk_set_preempt_only (struct request_queue *q) { -unsigned long flags; -int res; - -spin_lock_irqsave (q->queue_lock, flags); - res =queue_flag_test_and_set (QUEUE_FLAG_PREEMPT_ONLY , q); -spin_unlock_irqrestore (q->queue_lock, flags); - -return res; +return blk_queue_flag_test_and_set (QUEUE_FLAG_PREEMPT_ONLY , q); }EXPORT_SYMBOL_GPL (blk_set_preempt_only);void blk_clear_preempt_only (struct request_queue *q) { -unsigned long flags; - -spin_lock_irqsave (q->queue_lock, flags); -queue_flag_clear (QUEUE_FLAG_PREEMPT_ONLY , q); +blk_queue_flag_clear (QUEUE_FLAG_PREEMPT_ONLY , q);wake_up_all (&q->mq_freeze_wq); -spin_unlock_irqrestore (q->queue_lock, flags); }EXPORT_SYMBOL_GPL (blk_clear_preempt_only);
@@ -630,9 +691,7 @@ EXPORT_SYMBOL_GPL(blk_queue_bypass_end);void blk_set_queue_dying (struct request_queue *q) { -spin_lock_irq (q->queue_lock); -queue_flag_set (QUEUE_FLAG_DYING , q); -spin_unlock_irq (q->queue_lock); +blk_queue_flag_set (QUEUE_FLAG_DYING , q);/* * When queue DYING flag is set, we need to block new req
block/blk-mq.c +2 -10
@@ -198,11 +198,7 @@ EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);*/ void blk_mq_quiesce_queue_nowait (struct request_queue *q) { -unsigned long flags; - -spin_lock_irqsave (q->queue_lock, flags); -queue_flag_set (QUEUE_FLAG_QUIESCED , q); -spin_unlock_irqrestore (q->queue_lock, flags); +blk_queue_flag_set (QUEUE_FLAG_QUIESCED , q); }EXPORT_SYMBOL_GPL (blk_mq_quiesce_queue_nowait);
@@ -243,11 +239,7 @@ EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue);*/ void blk_mq_unquiesce_queue (struct request_queue *q) { -unsigned long flags; - -spin_lock_irqsave (q->queue_lock, flags); -queue_flag_clear (QUEUE_FLAG_QUIESCED , q); -spin_unlock_irqrestore (q->queue_lock, flags); +blk_queue_flag_clear (QUEUE_FLAG_QUIESCED , q);/* dispatch requests which are inserted during quiescing */ blk_mq_run_hw_queues (q, true);
block/blk-settings.c +2 -4
@@ -859,12 +859,10 @@ EXPORT_SYMBOL(blk_queue_update_dma_alignment);void blk_queue_flush_queueable (struct request_queue *q,bool queueable) { -spin_lock_irq (q->queue_lock);if (queueable) -queue_flag_clear (QUEUE_FLAG_FLUSH_NQ , q); +blk_queue_flag_clear (QUEUE_FLAG_FLUSH_NQ , q);else -queue_flag_set (QUEUE_FLAG_FLUSH_NQ , q); -spin_unlock_irq (q->queue_lock); +blk_queue_flag_set (QUEUE_FLAG_FLUSH_NQ , q); }EXPORT_SYMBOL_GPL (blk_queue_flush_queueable);
block/blk-sysfs.c +7 -15
@@ -276,12 +276,10 @@ queue_store_##name(struct request_queue *q, const char *page, size_t count) \if (neg) \ val = !val; \ \ -spin_lock_irq (q->queue_lock); \ if (val) \ - queue_flag_set(QUEUE_FLAG_##flag, q); \ + blk_queue_flag_set(QUEUE_FLAG_##flag, q); \ else \ - queue_flag_clear(QUEUE_FLAG_##flag, q); \ - spin_unlock_irq(q->queue_lock); \ + blk_queue_flag_clear(QUEUE_FLAG_##flag, q); \ return ret; \ }
@@ -414,12 +412,10 @@ static ssize_t queue_poll_store(struct request_queue *q, const char *page,if (ret <0 )return ret; -spin_lock_irq (q->queue_lock);if (poll_on) -queue_flag_set (QUEUE_FLAG_POLL , q); +blk_queue_flag_set (QUEUE_FLAG_POLL , q);else -queue_flag_clear (QUEUE_FLAG_POLL , q); -spin_unlock_irq (q->queue_lock); +blk_queue_flag_clear (QUEUE_FLAG_POLL , q);return ret; }
@@ -487,12 +483,10 @@ static ssize_t queue_wc_store(struct request_queue *q, const char *page,if (set ==-1 )return -EINVAL ; -spin_lock_irq (q->queue_lock);if (set) -queue_flag_set (QUEUE_FLAG_WC , q); +blk_queue_flag_set (QUEUE_FLAG_WC , q);else -queue_flag_clear (QUEUE_FLAG_WC , q); -spin_unlock_irq (q->queue_lock); +blk_queue_flag_clear (QUEUE_FLAG_WC , q);return count; }
@@ -948,9 +942,7 @@ void blk_unregister_queue(struct gendisk *disk)*/ mutex_lock (&q->sysfs_lock); -spin_lock_irq (q->queue_lock); -queue_flag_clear (QUEUE_FLAG_REGISTERED , q); -spin_unlock_irq (q->queue_lock); +blk_queue_flag_clear (QUEUE_FLAG_REGISTERED , q);/* * Remove the sysfs attributes before unregistering the queue data
block/blk-timeout.c +2 -4
@@ -57,12 +57,10 @@ ssize_t part_timeout_store(struct device *dev, struct device_attribute *attr,char *p = (char *) buf; val =simple_strtoul (p, &p,10 ); -spin_lock_irq (q->queue_lock);if (val) -queue_flag_set (QUEUE_FLAG_FAIL_IO , q); +blk_queue_flag_set (QUEUE_FLAG_FAIL_IO , q);else -queue_flag_clear (QUEUE_FLAG_FAIL_IO , q); -spin_unlock_irq (q->queue_lock); +blk_queue_flag_clear (QUEUE_FLAG_FAIL_IO , q); }return count;
include/linux/blkdev.h +5 -0
@@ -705,6 +705,11 @@ struct request_queue { (1 << QUEUE_FLAG_SAME_COMP) | \ (1 << QUEUE_FLAG_POLL)) +void blk_queue_flag_set (unsigned int flag,struct request_queue *q); +void blk_queue_flag_clear (unsigned int flag,struct request_queue *q); +bool blk_queue_flag_test_and_set (unsigned int flag,struct request_queue *q); +bool blk_queue_flag_test_and_clear (unsigned int flag,struct request_queue *q); +/* * @q->queue_lock is set while a queue is being initialized. Since we know * that no other threads access the queue object before @q->queue_lock has
Signature · 1 line
2.16.2
PATCH v2 5/11 mtip32xx: Use the blk_queue_flag_*() functions
In reply to Bart Van AsscheUse the blk_queue_flag_*() functions instead of open-coding these.
--- drivers/block/mtip32xx/mtip32xx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +4 -4
@@ -159,7 +159,7 @@ static bool mtip_check_surprise_removal(struct pci_dev *pdev)if (vendor_id ==0xFFFF ) { dd->sr = true;if (dd->queue) -set_bit (QUEUE_FLAG_DEAD , &dd->queue->queue_flags); +blk_queue_flag_set (QUEUE_FLAG_DEAD , dd->queue);else dev_warn (&dd->pdev->dev,"%s: dd->queue is NULL\n" , __func__);
@@ -3855,8 +3855,8 @@ static int mtip_block_initialize(struct driver_data *dd) goto start_service_thread;/* Set device limits. */ -set_bit (QUEUE_FLAG_NONROT , &dd->queue->queue_flags); -clear_bit (QUEUE_FLAG_ADD_RANDOM , &dd->queue->queue_flags); +blk_queue_flag_set (QUEUE_FLAG_NONROT , dd->queue); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , dd->queue);blk_queue_max_segments (dd->queue,MTIP_MAX_SG );blk_queue_physical_block_size (dd->queue,4096 );blk_queue_max_hw_sectors (dd->queue,0xffff );
@@ -3866,7 +3866,7 @@ static int mtip_block_initialize(struct driver_data *dd)/* Signal trim support */ if (dd->trim_supp == true) { -set_bit (QUEUE_FLAG_DISCARD , &dd->queue->queue_flags); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , dd->queue); dd->queue->limits.discard_granularity =4096 ;blk_queue_max_discard_sectors (dd->queue,MTIP_MAX_TRIM_ENTRY_LEN *MTIP_MAX_TRIM_ENTRIES );
Signature · 1 line
2.16.2
PATCH v2 6/11 bcache: Use the blk_queue_flag_{set,clear}() functions
In reply to Bart Van AsscheUse the blk_queue_flag_{set,clear}() functions instead of open-coding these.
--- drivers/md/bcache/super.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/bcache/super.c +3 -3
@@ -833,9 +833,9 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, q->limits.io_min = block_size; q->limits.logical_block_size = block_size; q->limits.physical_block_size = block_size; -set_bit (QUEUE_FLAG_NONROT , &d->disk->queue->queue_flags); -clear_bit (QUEUE_FLAG_ADD_RANDOM , &d->disk->queue->queue_flags); -set_bit (QUEUE_FLAG_DISCARD , &d->disk->queue->queue_flags); +blk_queue_flag_set (QUEUE_FLAG_NONROT , d->disk->queue); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , d->disk->queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , d->disk->queue);blk_queue_write_cache (q, true, true);
Signature · 1 line
2.16.2
PATCH v2 8/11 target/tcm_loop: Use blk_queue_flag_set()
In reply to Bart Van AsscheUse blk_queue_flag_set() instead of open-coding this function.
--- drivers/target/loopback/tcm_loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/loopback/tcm_loop.c +1 -1
@@ -309,7 +309,7 @@ static int tcm_loop_target_reset(struct scsi_cmnd *sc)static int tcm_loop_slave_alloc (struct scsi_device *sd) { -set_bit (QUEUE_FLAG_BIDI , &sd->request_queue->queue_flags); +blk_queue_flag_set (QUEUE_FLAG_BIDI , sd->request_queue);return 0 ; }
Signature · 1 line
2.16.2
PATCH v2 10/11 block: Complain if queue_flag_(set|clear)_unlocked() is abused
In reply to Bart Van AsscheSince it is not safe to use queue_flag_(set|clear)_unlocked() without holding the queue lock after the sysfs entries for a queue have been created, complain if this happens.
--- include/linux/blkdev.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/blkdev.h +6 -0
@@ -726,12 +726,18 @@ static inline void queue_lockdep_assert_held(struct request_queue *q)static inline void queue_flag_set_unlocked (unsigned int flag,struct request_queue *q) { +if (test_bit (QUEUE_FLAG_INIT_DONE , &q->queue_flags) && +kref_read (&q->kobj.kref)) +lockdep_assert_held (q->queue_lock);__set_bit (flag, &q->queue_flags); }static inline void queue_flag_clear_unlocked (unsigned int flag,struct request_queue *q) { +if (test_bit (QUEUE_FLAG_INIT_DONE , &q->queue_flags) && +kref_read (&q->kobj.kref)) +lockdep_assert_held (q->queue_lock);__clear_bit (flag, &q->queue_flags); }
Signature · 1 line
2.16.2
PATCH v2 4/11 block: Protect queue flag changes with the queue lock
In reply to Bart Van AsscheSince 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.
--- block/blk-mq.c | 2 +- block/blk-stat.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
block/blk-mq.c +1 -1
@@ -3025,7 +3025,7 @@ EXPORT_SYMBOL_GPL(blk_mq_update_nr_hw_queues);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)) +blk_queue_flag_test_and_set (QUEUE_FLAG_POLL_STATS , q))return true;blk_stat_add_callback (q, q->poll_cb);return false;
block/blk-stat.c +3 -3
@@ -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); }
Signature · 1 line
2.16.2
PATCH v2 7/11 iscsi: Use blk_queue_flag_set()
In reply to Bart Van AsscheUse blk_queue_flag_set() instead of open-coding this function.
--- drivers/scsi/iscsi_tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/iscsi_tcp.c +1 -1
@@ -948,7 +948,7 @@ static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param)static int iscsi_sw_tcp_slave_alloc (struct scsi_device *sdev) { -set_bit (QUEUE_FLAG_BIDI , &sdev->request_queue->queue_flags); +blk_queue_flag_set (QUEUE_FLAG_BIDI , sdev->request_queue);return 0 ; }
Signature · 1 line
2.16.2
PATCH v2 9/11 block: Use blk_queue_flag_*() in drivers instead of queue_flag_*()
In reply to Bart Van AsscheThis patch has been generated as follows:
for verb in set_unlocked clear_unlocked set clear; do
replace-in-files queue_flag_${verb} blk_queue_flag_${verb%_unlocked} \
$(git grep -lw queue_flag_${verb} drivers block/bsg*)done
Except for protecting all queue flag changes with the queue lock this patch does not change any functionality.
--- block/bsg-lib.c | 4 ++-- drivers/block/drbd/drbd_nl.c | 4 ++-- drivers/block/loop.c | 10 +++++----- drivers/block/nbd.c | 8 ++++---- drivers/block/null_blk.c | 6 +++--- drivers/block/rbd.c | 4 ++-- drivers/block/rsxx/dev.c | 6 +++--- drivers/block/skd_main.c | 4 ++-- drivers/block/xen-blkfront.c | 10 +++++----- drivers/block/zram/zram_drv.c | 6 +++--- drivers/ide/ide-disk.c | 4 ++-- drivers/ide/ide-probe.c | 2 +- drivers/lightnvm/pblk-init.c | 2 +- drivers/md/dm-table.c | 16 ++++++++-------- drivers/md/md-linear.c | 4 ++-- drivers/md/md.c | 4 ++-- drivers/md/raid0.c | 4 ++-- drivers/md/raid1.c | 6 +++--- drivers/md/raid10.c | 6 +++--- drivers/md/raid5.c | 4 ++-- drivers/mmc/core/queue.c | 8 ++++---- drivers/mtd/mtd_blkdevs.c | 6 +++--- drivers/nvdimm/blk.c | 2 +- drivers/nvdimm/btt.c | 2 +- drivers/nvdimm/pmem.c | 4 ++-- drivers/nvme/host/core.c | 4 ++-- drivers/nvme/host/multipath.c | 2 +- drivers/s390/block/dasd.c | 4 ++-- drivers/s390/block/dcssblk.c | 2 +- drivers/s390/block/scm_blk.c | 4 ++-- drivers/s390/block/xpram.c | 4 ++-- drivers/scsi/megaraid/megaraid_sas_base.c | 2 +- drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 +- drivers/scsi/scsi_debug.c | 2 +- drivers/scsi/scsi_lib.c | 2 +- drivers/scsi/scsi_transport_sas.c | 4 ++-- drivers/scsi/sd.c | 8 ++++---- 38 files changed, 89 insertions(+), 89 deletions(-)
block/bsg-lib.c +2 -2
@@ -275,8 +275,8 @@ struct request_queue *bsg_setup_queue(struct device *dev, const char *name, q->queuedata = dev; q->bsg_job_fn = job_fn; -queue_flag_set_unlocked (QUEUE_FLAG_BIDI , q); -queue_flag_set_unlocked (QUEUE_FLAG_SCSI_PASSTHROUGH , q); +blk_queue_flag_set (QUEUE_FLAG_BIDI , q); +blk_queue_flag_set (QUEUE_FLAG_SCSI_PASSTHROUGH , q);blk_queue_softirq_done (q, bsg_softirq_done);blk_queue_rq_timeout (q,BLK_DEFAULT_SG_TIMEOUT );
drivers/block/drbd/drbd_nl.c +2 -2
@@ -1212,10 +1212,10 @@ static void decide_on_discard_support(struct drbd_device *device,* topology on all peers. */ blk_queue_discard_granularity (q,512 ); q->limits.max_discard_sectors =drbd_max_discard_sectors (connection); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , q); q->limits.max_write_zeroes_sectors =drbd_max_discard_sectors (connection); }else { -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , q);blk_queue_discard_granularity (q,0 ); q->limits.max_discard_sectors =0 ; q->limits.max_write_zeroes_sectors =0 ;
drivers/block/loop.c +5 -5
@@ -214,10 +214,10 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)blk_mq_freeze_queue (lo->lo_queue); lo->use_dio = use_dio;if (use_dio) { -queue_flag_clear_unlocked (QUEUE_FLAG_NOMERGES , lo->lo_queue); +blk_queue_flag_clear (QUEUE_FLAG_NOMERGES , lo->lo_queue); lo->lo_flags |=LO_FLAGS_DIRECT_IO ; }else { -queue_flag_set_unlocked (QUEUE_FLAG_NOMERGES , lo->lo_queue); +blk_queue_flag_set (QUEUE_FLAG_NOMERGES , lo->lo_queue); lo->lo_flags &= ~LO_FLAGS_DIRECT_IO ; }blk_mq_unfreeze_queue (lo->lo_queue);
@@ -817,7 +817,7 @@ static void loop_config_discard(struct loop_device *lo) q->limits.discard_alignment =0 ;blk_queue_max_discard_sectors (q,0 );blk_queue_max_write_zeroes_sectors (q,0 ); -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , q);return ; }
@@ -826,7 +826,7 @@ static void loop_config_discard(struct loop_device *lo)blk_queue_max_discard_sectors (q,UINT_MAX >>9 );blk_queue_max_write_zeroes_sectors (q,UINT_MAX >>9 ); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , q); }static void loop_unprepare_queue (struct loop_device *lo)
@@ -1808,7 +1808,7 @@ static int loop_add(struct loop_device **l, int i)* page. For directio mode, merge does help to dispatch bigger request * to underlayer disk. We will enable merge once directio is enabled. */ -queue_flag_set_unlocked (QUEUE_FLAG_NOMERGES , lo->lo_queue); +blk_queue_flag_set (QUEUE_FLAG_NOMERGES , lo->lo_queue); err = -ENOMEM ; disk = lo->lo_disk =alloc_disk (1 << part_shift);
drivers/block/nbd.c +4 -4
@@ -964,7 +964,7 @@ static void nbd_parse_flags(struct nbd_device *nbd)else set_disk_ro (nbd->disk, false);if (config->flags &NBD_FLAG_SEND_TRIM ) -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , nbd->disk->queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , nbd->disk->queue);if (config->flags &NBD_FLAG_SEND_FLUSH ) {if (config->flags &NBD_FLAG_SEND_FUA )blk_queue_write_cache (nbd->disk->queue, true, true);
@@ -1040,7 +1040,7 @@ static void nbd_config_put(struct nbd_device *nbd) nbd->config =NULL ; nbd->tag_set.timeout =0 ; -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , nbd->disk->queue); +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , nbd->disk->queue);mutex_unlock (&nbd->config_lock);nbd_put (nbd);
@@ -1488,8 +1488,8 @@ static int nbd_dev_add(int index)/* * Tell the block layer that we are not a rotational device */ -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , disk->queue); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , disk->queue); +blk_queue_flag_set (QUEUE_FLAG_NONROT , disk->queue); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , disk->queue); disk->queue->limits.discard_granularity =512 ;blk_queue_max_discard_sectors (disk->queue,UINT_MAX );blk_queue_max_segment_size (disk->queue,UINT_MAX );
drivers/block/null_blk.c +3 -3
@@ -1523,7 +1523,7 @@ static void null_config_discard(struct nullb *nullb) nullb->q->limits.discard_granularity = nullb->dev->blocksize; nullb->q->limits.discard_alignment = nullb->dev->blocksize;blk_queue_max_discard_sectors (nullb->q,UINT_MAX >>9 ); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , nullb->q); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , nullb->q); }static int null_open (struct block_device *bdev,fmode_t mode)
@@ -1808,8 +1808,8 @@ static int null_add_dev(struct nullb_device *dev) } nullb->q->queuedata = nullb; -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , nullb->q); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , nullb->q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , nullb->q); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , nullb->q);mutex_lock (&lock); nullb->index =ida_simple_get (&nullb_indexes,0 ,0 ,GFP_KERNEL );
drivers/block/rbd.c +2 -2
@@ -4361,7 +4361,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev) goto out_tag_set; } -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q);/* QUEUE_FLAG_ADD_RANDOM is off by default for blk-mq */ /* set io sizes to object size */
@@ -4374,7 +4374,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)blk_queue_io_opt (q, segment_size);/* enable the discard support */ -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , q); q->limits.discard_granularity = segment_size;blk_queue_max_discard_sectors (q, segment_size /SECTOR_SIZE );blk_queue_max_write_zeroes_sectors (q, segment_size /SECTOR_SIZE );
drivers/block/rsxx/dev.c +3 -3
@@ -287,10 +287,10 @@ int rsxx_setup_dev(struct rsxx_cardinfo *card)blk_queue_max_hw_sectors (card->queue, blkdev_max_hw_sectors);blk_queue_physical_block_size (card->queue,RSXX_HW_BLK_SIZE ); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , card->queue); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , card->queue); +blk_queue_flag_set (QUEUE_FLAG_NONROT , card->queue); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , card->queue);if (rsxx_discard_supported (card)) { -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , card->queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , card->queue);blk_queue_max_discard_sectors (card->queue,RSXX_HW_BLK_SIZE >>9 ); card->queue->limits.discard_granularity =RSXX_HW_BLK_SIZE ;
drivers/block/skd_main.c +2 -2
@@ -2858,8 +2858,8 @@ static int skd_cons_disk(struct skd_device *skdev)/* set optimal I/O size to 8KB */ blk_queue_io_opt (q,8192 ); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , q);blk_queue_rq_timeout (q,8 *HZ );
drivers/block/xen-blkfront.c +5 -5
@@ -931,15 +931,15 @@ static void blkif_set_queue_limits(struct blkfront_info *info)unsigned int segments = info->max_indirect_segments ? :BLKIF_MAX_SEGMENTS_PER_REQUEST ; -queue_flag_set_unlocked (QUEUE_FLAG_VIRT , rq); +blk_queue_flag_set (QUEUE_FLAG_VIRT , rq);if (info->feature_discard) { -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , rq); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , rq);blk_queue_max_discard_sectors (rq,get_capacity (gd)); rq->limits.discard_granularity = info->discard_granularity; rq->limits.discard_alignment = info->discard_alignment;if (info->feature_secdiscard) -queue_flag_set_unlocked (QUEUE_FLAG_SECERASE , rq); +blk_queue_flag_set (QUEUE_FLAG_SECERASE , rq); }/* Hard sector size and max sectors impersonate the equiv. hardware. */
@@ -1610,8 +1610,8 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)blkif_req (req)->error =BLK_STS_NOTSUPP ; info->feature_discard =0 ; info->feature_secdiscard =0 ; -queue_flag_clear (QUEUE_FLAG_DISCARD , rq); -queue_flag_clear (QUEUE_FLAG_SECERASE , rq); +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , rq); +blk_queue_flag_clear (QUEUE_FLAG_SECERASE , rq); }break ;case BLKIF_OP_FLUSH_DISKCACHE :
drivers/block/zram/zram_drv.c +3 -3
@@ -1530,8 +1530,8 @@ static int zram_add(void)/* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ set_capacity (zram->disk,0 );/* zram devices sort of resembles non-rotational disks */ -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , zram->disk->queue); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , zram->disk->queue); +blk_queue_flag_set (QUEUE_FLAG_NONROT , zram->disk->queue); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , zram->disk->queue);/* * To ensure that we always get PAGE_SIZE aligned
@@ -1544,7 +1544,7 @@ static int zram_add(void)blk_queue_io_opt (zram->disk->queue,PAGE_SIZE ); zram->disk->queue->limits.discard_granularity =PAGE_SIZE ;blk_queue_max_discard_sectors (zram->disk->queue,UINT_MAX ); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , zram->disk->queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , zram->disk->queue);/* * zram_bio_discard() will clear all logical blocks if logical block
drivers/ide/ide-disk.c +2 -2
@@ -687,8 +687,8 @@ static void ide_disk_setup(ide_drive_t *drive) queue_max_sectors(q) / 2);if (ata_id_is_ssd (id)) { -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , q); }/* calculate drive capacity, and select LBA if possible */
drivers/ide/ide-probe.c +1 -1
@@ -773,7 +773,7 @@ static int ide_init_queue(ide_drive_t *drive) q->request_fn = do_ide_request; q->initialize_rq_fn = ide_initialize_rq; q->cmd_size =sizeof (struct ide_request ); -queue_flag_set_unlocked (QUEUE_FLAG_SCSI_PASSTHROUGH , q); +blk_queue_flag_set (QUEUE_FLAG_SCSI_PASSTHROUGH , q);if (blk_init_allocated_queue (q) <0 ) {blk_cleanup_queue (q);return 1 ;
drivers/lightnvm/pblk-init.c +1 -1
@@ -1067,7 +1067,7 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk, tqueue->limits.discard_granularity = geo->sec_per_chk * geo->sec_size; tqueue->limits.discard_alignment =0 ;blk_queue_max_discard_sectors (tqueue,UINT_MAX >>9 ); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , tqueue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , tqueue); pr_info("pblk(%s): luns:%u, lines:%d, secs:%llu, buf entries:%u\n", tdisk->disk_name,
drivers/md/dm-table.c +8 -8
@@ -1861,7 +1861,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, q->limits = *limits;if (!dm_table_supports_discards (t)) { -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , q);/* Must also clear discard limits... */ q->limits.max_discard_sectors =0 ; q->limits.max_hw_discard_sectors =0 ;
@@ -1869,7 +1869,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, q->limits.discard_alignment =0 ; q->limits.discard_misaligned =0 ; }else -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , q);if (dm_table_supports_flush (t, (1UL <<QUEUE_FLAG_WC ))) { wc = true;
@@ -1879,15 +1879,15 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,blk_queue_write_cache (q, wc, fua);if (dm_table_supports_dax (t)) -queue_flag_set_unlocked (QUEUE_FLAG_DAX , q); +blk_queue_flag_set (QUEUE_FLAG_DAX , q);if (dm_table_supports_dax_write_cache (t))dax_write_cache (t->md->dax_dev, true);/* Ensure that all underlying devices are non-rotational. */ if (dm_table_all_devices_attribute (t, device_is_nonrot)) -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q);else -queue_flag_clear_unlocked (QUEUE_FLAG_NONROT , q); +blk_queue_flag_clear (QUEUE_FLAG_NONROT , q);if (!dm_table_supports_write_same (t)) q->limits.max_write_same_sectors =0 ;
@@ -1895,9 +1895,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, q->limits.max_write_zeroes_sectors =0 ;if (dm_table_all_devices_attribute (t, queue_supports_sg_merge)) -queue_flag_clear_unlocked (QUEUE_FLAG_NO_SG_MERGE , q); +blk_queue_flag_clear (QUEUE_FLAG_NO_SG_MERGE , q);else -queue_flag_set_unlocked (QUEUE_FLAG_NO_SG_MERGE , q); +blk_queue_flag_set (QUEUE_FLAG_NO_SG_MERGE , q);dm_table_verify_integrity (t);
@@ -1908,7 +1908,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,* have it set. */ if (blk_queue_add_random (q) &&dm_table_all_devices_attribute (t, device_is_not_random)) -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , q); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , q); }unsigned int dm_table_get_num_targets (struct dm_table *t)
drivers/md/md-linear.c +2 -2
@@ -138,9 +138,9 @@ static struct linear_conf *linear_conf(struct mddev *mddev, int raid_disks) }if (!discard_supported) -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , mddev->queue); +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , mddev->queue);else -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , mddev->queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , mddev->queue);/* * Here we calculate the device offsets.
drivers/md/md.c +2 -2
@@ -5608,9 +5608,9 @@ int md_run(struct mddev *mddev)if (mddev->degraded) nonrot = false;if (nonrot) -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , mddev->queue); +blk_queue_flag_set (QUEUE_FLAG_NONROT , mddev->queue);else -queue_flag_clear_unlocked (QUEUE_FLAG_NONROT , mddev->queue); +blk_queue_flag_clear (QUEUE_FLAG_NONROT , mddev->queue); mddev->queue->backing_dev_info->congested_data = mddev; mddev->queue->backing_dev_info->congested_fn = md_congested; }
drivers/md/raid0.c +2 -2
@@ -399,9 +399,9 @@ static int raid0_run(struct mddev *mddev) discard_supported = true; }if (!discard_supported) -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , mddev->queue); +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , mddev->queue);else -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , mddev->queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , mddev->queue); }/* calculate array device size */
drivers/md/raid1.c +3 -3
@@ -1760,7 +1760,7 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev) } }if (mddev->queue &&blk_queue_discard (bdev_get_queue (rdev->bdev))) -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , mddev->queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , mddev->queue);print_conf (conf);return err; }
@@ -3099,10 +3099,10 @@ static int raid1_run(struct mddev *mddev)if (mddev->queue) {if (discard_supported) -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , +blk_queue_flag_set (QUEUE_FLAG_DISCARD , mddev->queue);else -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , mddev->queue); }
drivers/md/raid10.c +3 -3
@@ -1845,7 +1845,7 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)break ; }if (mddev->queue &&blk_queue_discard (bdev_get_queue (rdev->bdev))) -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , mddev->queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , mddev->queue);print_conf (conf);return err;
@@ -3844,10 +3844,10 @@ static int raid10_run(struct mddev *mddev)if (mddev->queue) {if (discard_supported) -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , +blk_queue_flag_set (QUEUE_FLAG_DISCARD , mddev->queue);else -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , mddev->queue); }/* need to check that every block has at least one working mirror */
drivers/md/raid5.c +2 -2
@@ -7444,10 +7444,10 @@ static int raid5_run(struct mddev *mddev)if (devices_handle_discard_safely && mddev->queue->limits.max_discard_sectors >= (stripe >>9 ) && mddev->queue->limits.discard_granularity >= stripe) -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , +blk_queue_flag_set (QUEUE_FLAG_DISCARD , mddev->queue);else -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , mddev->queue);blk_queue_max_hw_sectors (mddev->queue,UINT_MAX );
drivers/mmc/core/queue.c +4 -4
@@ -185,14 +185,14 @@ static void mmc_queue_setup_discard(struct request_queue *q,if (!max_discard)return ; -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , q);blk_queue_max_discard_sectors (q, max_discard); q->limits.discard_granularity = card->pref_erase <<9 ;/* granularity must not be greater than max. discard */ if (card->pref_erase > max_discard) q->limits.discard_granularity =0 ;if (mmc_can_secure_erase_trim (card)) -queue_flag_set_unlocked (QUEUE_FLAG_SECERASE , q); +blk_queue_flag_set (QUEUE_FLAG_SECERASE , q); }/**
@@ -356,8 +356,8 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)if (mmc_dev (host)->dma_mask && *mmc_dev (host)->dma_mask) limit = (u64 )dma_max_pfn (mmc_dev (host)) <<PAGE_SHIFT ; -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , mq->queue); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , mq->queue); +blk_queue_flag_set (QUEUE_FLAG_NONROT , mq->queue); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , mq->queue);if (mmc_can_erase (card))mmc_queue_setup_discard (mq->queue, card);
drivers/mtd/mtd_blkdevs.c +3 -3
@@ -419,11 +419,11 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)blk_queue_logical_block_size (new->rq, tr->blksize);blk_queue_bounce_limit (new->rq,BLK_BOUNCE_HIGH ); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , new->rq); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , new->rq); +blk_queue_flag_set (QUEUE_FLAG_NONROT , new->rq); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , new->rq);if (tr->discard) { -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , new->rq); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , new->rq);blk_queue_max_discard_sectors (new->rq,UINT_MAX ); }
drivers/nvdimm/blk.c +1 -1
@@ -266,7 +266,7 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)blk_queue_make_request (q, nd_blk_make_request);blk_queue_max_hw_sectors (q,UINT_MAX );blk_queue_logical_block_size (q,nsblk_sector_size (nsblk)); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q); q->queuedata = nsblk; disk =alloc_disk (0 );
drivers/nvdimm/btt.c +1 -1
@@ -1542,7 +1542,7 @@ static int btt_blk_init(struct btt *btt)blk_queue_make_request (btt->btt_queue, btt_make_request);blk_queue_logical_block_size (btt->btt_queue, btt->sector_size);blk_queue_max_hw_sectors (btt->btt_queue,UINT_MAX ); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , btt->btt_queue); +blk_queue_flag_set (QUEUE_FLAG_NONROT , btt->btt_queue); btt->btt_queue->queuedata = btt;set_capacity (btt->btt_disk,0 );
drivers/nvdimm/pmem.c +2 -2
@@ -388,8 +388,8 @@ static int pmem_attach_disk(struct device *dev,blk_queue_physical_block_size (q,PAGE_SIZE );blk_queue_logical_block_size (q,pmem_sector_size (ndns));blk_queue_max_hw_sectors (q,UINT_MAX ); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); -queue_flag_set_unlocked (QUEUE_FLAG_DAX , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q); +blk_queue_flag_set (QUEUE_FLAG_DAX , q); q->queuedata = pmem; disk =alloc_disk_node (0 , nid);
drivers/nvme/host/core.c +2 -2
@@ -1358,7 +1358,7 @@ static void nvme_config_discard(struct nvme_ctrl *ctrl,blk_queue_max_discard_sectors (queue,UINT_MAX );blk_queue_max_discard_segments (queue,NVME_DSM_MAX_RANGES ); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , queue); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , queue);if (ctrl->quirks &NVME_QUIRK_DEALLOCATE_ZEROES )blk_queue_max_write_zeroes_sectors (queue,UINT_MAX );
@@ -2949,7 +2949,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ns->queue =blk_mq_init_queue (ctrl->tagset);if (IS_ERR (ns->queue)) goto out_free_ns; -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , ns->queue); +blk_queue_flag_set (QUEUE_FLAG_NONROT , ns->queue); ns->queue->queuedata = ns; ns->ctrl = ctrl;
drivers/nvme/host/multipath.c +1 -1
@@ -168,7 +168,7 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head) q->queuedata = head;blk_queue_make_request (q, nvme_ns_head_make_request); q->poll_fn = nvme_ns_head_poll; -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q);/* set to a default value for 512 until disk is validated */ blk_queue_logical_block_size (q,512 );
drivers/s390/block/dasd.c +2 -2
@@ -3210,7 +3210,7 @@ static void dasd_setup_queue(struct dasd_block *block) }else { max = block->base->discipline->max_blocks << block->s2b_shift; } -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q); q->limits.max_dev_sectors = max;blk_queue_logical_block_size (q, logical_block_size);blk_queue_max_hw_sectors (q, max);
@@ -3233,7 +3233,7 @@ static void dasd_setup_queue(struct dasd_block *block)blk_queue_max_discard_sectors (q, max_discard_sectors);blk_queue_max_write_zeroes_sectors (q, max_discard_sectors); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , q); } }
drivers/s390/block/dcssblk.c +1 -1
@@ -633,7 +633,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char dev_info->gd->private_data = dev_info;blk_queue_make_request (dev_info->dcssblk_queue, dcssblk_make_request);blk_queue_logical_block_size (dev_info->dcssblk_queue,4096 ); -queue_flag_set_unlocked (QUEUE_FLAG_DAX , dev_info->dcssblk_queue); +blk_queue_flag_set (QUEUE_FLAG_DAX , dev_info->dcssblk_queue); seg_byte_size = (dev_info->end - dev_info->start +1 );set_capacity (dev_info->gd, seg_byte_size >>9 );// size in sectors
drivers/s390/block/scm_blk.c +2 -2
@@ -472,8 +472,8 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)blk_queue_logical_block_size (rq,1 <<12 );blk_queue_max_hw_sectors (rq, nr_max_blk <<3 );/* 8 * 512 = blk_size */ blk_queue_max_segments (rq, nr_max_blk); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , rq); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , rq); +blk_queue_flag_set (QUEUE_FLAG_NONROT , rq); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , rq); bdev->gendisk =alloc_disk (SCM_NR_PARTS );if (!bdev->gendisk) {
drivers/s390/block/xpram.c +2 -2
@@ -348,8 +348,8 @@ static int __init xpram_setup_blkdev(void)put_disk (xpram_disks[i]); goto out; } -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , xpram_queues[i]); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , xpram_queues[i]); +blk_queue_flag_set (QUEUE_FLAG_NONROT , xpram_queues[i]); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , xpram_queues[i]);blk_queue_make_request (xpram_queues[i], xpram_make_request);blk_queue_logical_block_size (xpram_queues[i],4096 ); }
drivers/scsi/megaraid/megaraid_sas_base.c +1 -1
@@ -1864,7 +1864,7 @@ megasas_set_nvme_device_properties(struct scsi_device *sdev, u32 max_io_size)blk_queue_max_hw_sectors (sdev->request_queue, (max_io_size /512 )); -queue_flag_set_unlocked (QUEUE_FLAG_NOMERGES , sdev->request_queue); +blk_queue_flag_set (QUEUE_FLAG_NOMERGES , sdev->request_queue);blk_queue_virt_boundary (sdev->request_queue, mr_nvme_pg_size -1 ); }
drivers/scsi/megaraid/megaraid_sas_fusion.c +1 -1
@@ -1908,7 +1908,7 @@ megasas_is_prp_possible(struct megasas_instance *instance,* then sending IOs with holes. * * Though driver can request block layer to disable IO merging by calling- -* queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue) but +* blk_queue_flag_set(QUEUE_FLAG_NOMERGES, sdev->request_queue) but * user may tune sysfs parameter- nomerges again to 0 or 1. * * If in future IO scheduling is enabled with SCSI BLK MQ,
drivers/scsi/mpt3sas/mpt3sas_scsih.c +1 -1
@@ -2352,7 +2352,7 @@ scsih_slave_configure(struct scsi_device *sdev)** merged and can eliminate holes created during merging ** operation. **/ -queue_flag_set_unlocked (QUEUE_FLAG_NOMERGES , +blk_queue_flag_set (QUEUE_FLAG_NOMERGES , sdev->request_queue);blk_queue_virt_boundary (sdev->request_queue, ioc->page_size -1 );
drivers/scsi/scsi_debug.c +1 -1
@@ -3897,7 +3897,7 @@ static int scsi_debug_slave_alloc(struct scsi_device *sdp)if (sdebug_verbose)pr_info ("slave_alloc <%u %u %u %llu>\n" , sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); -queue_flag_set_unlocked (QUEUE_FLAG_BIDI , sdp->request_queue); +blk_queue_flag_set (QUEUE_FLAG_BIDI , sdp->request_queue);return 0 ; }
drivers/scsi/scsi_lib.c +1 -1
@@ -2140,7 +2140,7 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) {struct device *dev = shost->dma_dev; -queue_flag_set_unlocked (QUEUE_FLAG_SCSI_PASSTHROUGH , q); +blk_queue_flag_set (QUEUE_FLAG_SCSI_PASSTHROUGH , q);/* * this limit is imposed by hardware restrictions
drivers/scsi/scsi_transport_sas.c +2 -2
@@ -227,8 +227,8 @@ static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy)* by default assume old behaviour and bounce for any highmem page */ blk_queue_bounce_limit (q,BLK_BOUNCE_HIGH ); -queue_flag_set_unlocked (QUEUE_FLAG_BIDI , q); -queue_flag_set_unlocked (QUEUE_FLAG_SCSI_PASSTHROUGH , q); +blk_queue_flag_set (QUEUE_FLAG_BIDI , q); +blk_queue_flag_set (QUEUE_FLAG_SCSI_PASSTHROUGH , q);return 0 ; }
drivers/scsi/sd.c +4 -4
@@ -714,7 +714,7 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)case SD_LBP_FULL :case SD_LBP_DISABLE :blk_queue_max_discard_sectors (q,0 ); -queue_flag_clear_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_clear (QUEUE_FLAG_DISCARD , q);return ;case SD_LBP_UNMAP :
@@ -747,7 +747,7 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode) }blk_queue_max_discard_sectors (q, max_blocks * (logical_block_size >>9 )); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q); +blk_queue_flag_set (QUEUE_FLAG_DISCARD , q); }static int sd_setup_unmap_cmnd (struct scsi_cmnd *cmd)
@@ -2952,8 +2952,8 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) rot =get_unaligned_be16 (&buffer[4 ]);if (rot ==1 ) { -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , q); +blk_queue_flag_set (QUEUE_FLAG_NONROT , q); +blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , q); }if (sdkp->device->type ==TYPE_ZBC ) {
Signature · 1 line
2.16.2
PATCH v2 11/11 block: Move the queue_flag_*() functions from a public into a private header file
In reply to Bart Van AsscheThis patch helps to avoid that new code gets introduced in block drivers that manipulates queue flags without holding the queue lock when that lock should be held.
--- block/blk.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 69 -------------------------------------------------- 2 files changed, 69 insertions(+), 69 deletions(-)
block/blk.h +69 -0
@@ -41,6 +41,75 @@ extern struct kmem_cache *request_cachep;extern struct kobj_type blk_queue_ktype;extern struct ida blk_queue_ida; +/* +* @q->queue_lock is set while a queue is being initialized. Since we know +* that no other threads access the queue object before @q->queue_lock has +* been set, it is safe to manipulate queue flags without holding the +* queue_lock if @q->queue_lock == NULL. See also blk_alloc_queue_node() and +* blk_init_allocated_queue(). +*/ +static inline void queue_lockdep_assert_held (struct request_queue *q) +{ +if (q->queue_lock) +lockdep_assert_held (q->queue_lock); +} + +static inline void queue_flag_set_unlocked (unsigned int flag, +struct request_queue *q) +{ +if (test_bit (QUEUE_FLAG_INIT_DONE , &q->queue_flags) && +kref_read (&q->kobj.kref)) +lockdep_assert_held (q->queue_lock); +__set_bit (flag, &q->queue_flags); +} + +static inline void queue_flag_clear_unlocked (unsigned int flag, +struct request_queue *q) +{ +if (test_bit (QUEUE_FLAG_INIT_DONE , &q->queue_flags) && +kref_read (&q->kobj.kref)) +lockdep_assert_held (q->queue_lock); +__clear_bit (flag, &q->queue_flags); +} + +static inline int queue_flag_test_and_clear (unsigned int flag, +struct request_queue *q) +{ +queue_lockdep_assert_held (q); + +if (test_bit (flag, &q->queue_flags)) { +__clear_bit (flag, &q->queue_flags); +return 1 ; + } + +return 0 ; +} + +static inline int queue_flag_test_and_set (unsigned int flag, +struct request_queue *q) +{ +queue_lockdep_assert_held (q); + +if (!test_bit (flag, &q->queue_flags)) { +__set_bit (flag, &q->queue_flags); +return 0 ; + } + +return 1 ; +} + +static inline void queue_flag_set (unsigned int flag,struct request_queue *q) +{ +queue_lockdep_assert_held (q); +__set_bit (flag, &q->queue_flags); +} + +static inline void queue_flag_clear (unsigned int flag,struct request_queue *q) +{ +queue_lockdep_assert_held (q); +__clear_bit (flag, &q->queue_flags); +} +static inline struct blk_flush_queue *blk_get_flush_queue (struct request_queue *q,struct blk_mq_ctx *ctx) {
include/linux/blkdev.h +0 -69
75 lines not on this page · raw message
Signature · 1 line
2.16.2
Re: [PATCH v2 09/11] block: Use blk_queue_flag_*() in drivers instead of queue_flag_*()
In reply to Bart Van AsscheLooks good,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH v2 04/11] block: Protect queue flag changes with the queue lock
In reply to Bart Van AsscheLooks good,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Jens Axboe
maintainerQuoted 12 lines · Bart Van Assche
Hello Jens,
As you probably know there is considerable confusion in the block layer core and in block drivers about how to protect queue flag changes against concurrent modifications. Some code protects these changes with the queue lock, other code uses atomic operations and some code does not protect queue flag changes against concurrent changes at all. Hence this patch series that protects all queue flag changes consistently with the queue lock and that removes functions that are not safe in a concurrent context from the public block layer header files.
Quoted 4 lines
Please consider these patches for kernel v4.17.
Note: it may be a good idea to postpone patch 11 until after the kernel v4.17 merge window to avoid merge conflicts.
Applied for 4.17. Not too worried about a conflict with that patch, so applied 11/11 as well.
Signature · 1 line
Jens Axboe