Skip to contentSkip to conversation

block: mark GFP_NOIO around sysfs ->store()

PATCH Applied Ming Lei 5 participants 5 messages Jan 13, 2025

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block: mark GFP_NOIO around sysfs ->store()

sysfs ->store is called with queue freezed, meantime we have several ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate memory with GFP_KERNEL which may run into direct reclaim code path, then potential deadlock can be caused.

Fix the issue by marking NOIO around sysfs ->store()

---
 block/blk-sysfs.c | 3 +++
 1 file changed, 3 insertions(+)
block/blk-sysfs.c +3 -0
index e828be777206..e09b455874bf 100644
@@ -681,6 +681,7 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
 	struct queue_sysfs_entry *entry = to_queue(attr);
 	struct gendisk *disk = container_of(kobj, struct gendisk, queue_kobj);
 	struct request_queue *q = disk->queue;
+	unsigned int noio_flag;
 	ssize_t res;
 
 	if (!entry->store_limit && !entry->store)
@@ -711,7 +712,9 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
 
 	mutex_lock(&q->sysfs_lock);
 	blk_mq_freeze_queue(q);
+	noio_flag = memalloc_noio_save();
 	res = entry->store(disk, page, length);
+	memalloc_noio_restore(noio_flag);
 	blk_mq_unfreeze_queue(q);
 	mutex_unlock(&q->sysfs_lock);
 	return res;
Signature · 1 line
2.44.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Ming Lei

sysfs ->store is called with queue freezed, meantime we have several ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate memory with GFP_KERNEL which may run into direct reclaim code path, then potential deadlock can be caused.

Fix the issue by marking NOIO around sysfs ->store()

Yes, that's a good thing, and we should aim for more of that for block layer code that requires NOIO:

Reviewed-by on v1 1/1
#2 lore raw
In reply to Ming Lei
Quoted 10 lines · Ming Lei

sysfs ->store is called with queue freezed, meantime we have several ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate memory with GFP_KERNEL which may run into direct reclaim code path, then potential deadlock can be caused.

Fix the issue by marking NOIO around sysfs ->store()

I guess that you should be including a link to https://lore.kernel.org/linux-block/Z4RkemI9f6N5zoEF@fedora/T/#mc774c65eeca5c024d29695f9ac6152b87763f305

Regardless, FWIW:

#3 lore raw
Quoted 6 lines · John Garry
Quoted 5 lines · Ming Lei

sysfs ->store is called with queue freezed, meantime we have several ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate memory with GFP_KERNEL which may run into direct reclaim code path, then potential deadlock can be caused.

Quoted 8 lines
Quoted 5 lines

Fix the issue by marking NOIO around sysfs ->store()

I guess that you should be including a link to https://lore.kernel.org/linux-block/Z4RkemI9f6N5zoEF@fedora/T/#mc774c65eeca5c024d29695f9ac6152b87763f305

Indeed, I will add a Closes tag in V2.

Quoted 2 lines

Regardless, FWIW:

Thanks,

Signature · 1 line
Ming
maintainer Applied
#4 lore raw
In reply to Ming Lei
Quoted 8 lines · Ming Lei

sysfs ->store is called with queue freezed, meantime we have several ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate memory with GFP_KERNEL which may run into direct reclaim code path, then potential deadlock can be caused.

Fix the issue by marking NOIO around sysfs ->store()

[...]

Applied, thanks!

[1/1] block: mark GFP_NOIO around sysfs ->store()

      commit: 7c0be4ead1f8f5f8be0803f347de0de81e3b8e1c

Best regards,

Signature · 1 line
Jens Axboe