mirror of
				git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
				synced 2025-10-31 08:44:41 +00:00 
			
		
		
		
	block: fix nr_hw_queue update racing with disk addition/removal
The nr_hw_queue update could potentially race with disk addtion/removal while registering/unregistering hctx sysfs files. The __blk_mq_update_ nr_hw_queues() runs with q->tag_list_lock held and so to avoid it racing with disk addition/removal we should acquire q->tag_list_lock while registering/unregistering hctx sysfs files. With this patch, blk_mq_sysfs_register() (called during disk addition) and blk_mq_sysfs_unregister() (called during disk removal) now runs with q->tag_list_lock held so that it avoids racing with __blk_mq_update _nr_hw_queues(). Signed-off-by: Nilay Shroff <nilay@linux.ibm.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/r/20250128143436.874357-3-nilay@linux.ibm.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
		
							parent
							
								
									fe66286086
								
							
						
					
					
						commit
						14ef49657f
					
				
					 1 changed files with 9 additions and 8 deletions
				
			
		|  | @ -225,25 +225,25 @@ int blk_mq_sysfs_register(struct gendisk *disk) | |||
| 
 | ||||
| 	ret = kobject_add(q->mq_kobj, &disk_to_dev(disk)->kobj, "mq"); | ||||
| 	if (ret < 0) | ||||
| 		goto out; | ||||
| 		return ret; | ||||
| 
 | ||||
| 	kobject_uevent(q->mq_kobj, KOBJ_ADD); | ||||
| 
 | ||||
| 	mutex_lock(&q->tag_set->tag_list_lock); | ||||
| 	queue_for_each_hw_ctx(q, hctx, i) { | ||||
| 		ret = blk_mq_register_hctx(hctx); | ||||
| 		if (ret) | ||||
| 			goto unreg; | ||||
| 			goto out_unreg; | ||||
| 	} | ||||
| 	mutex_unlock(&q->tag_set->tag_list_lock); | ||||
| 	return 0; | ||||
| 
 | ||||
| 
 | ||||
| out: | ||||
| 	return ret; | ||||
| 
 | ||||
| unreg: | ||||
| out_unreg: | ||||
| 	queue_for_each_hw_ctx(q, hctx, j) { | ||||
| 		if (j < i) | ||||
| 			blk_mq_unregister_hctx(hctx); | ||||
| 	} | ||||
| 	mutex_unlock(&q->tag_set->tag_list_lock); | ||||
| 
 | ||||
| 	kobject_uevent(q->mq_kobj, KOBJ_REMOVE); | ||||
| 	kobject_del(q->mq_kobj); | ||||
|  | @ -256,9 +256,10 @@ void blk_mq_sysfs_unregister(struct gendisk *disk) | |||
| 	struct blk_mq_hw_ctx *hctx; | ||||
| 	unsigned long i; | ||||
| 
 | ||||
| 
 | ||||
| 	mutex_lock(&q->tag_set->tag_list_lock); | ||||
| 	queue_for_each_hw_ctx(q, hctx, i) | ||||
| 		blk_mq_unregister_hctx(hctx); | ||||
| 	mutex_unlock(&q->tag_set->tag_list_lock); | ||||
| 
 | ||||
| 	kobject_uevent(q->mq_kobj, KOBJ_REMOVE); | ||||
| 	kobject_del(q->mq_kobj); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Nilay Shroff
						Nilay Shroff