Skip to contentSkip to conversation

block: Fix elv_iosched_local_module handling of "none" scheduler

PATCH Superseded Damien Le Moal 5 participants 12 messages Sep 17, 2024 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Fix elv_iosched_local_module handling of "none" scheduler

Commit 734e1a860312 ("block: Prevent deadlocks when switching elevators") introduced the function elv_iosched_load_module() to allow loading an elevator module outside of elv_iosched_store() with the target device queue not frozen, to avoid deadlocks. However, the "none" scheduler does not have a module and as a result, elv_iosched_load_module() always returns an error when trying to switch to this valid scheduler.

Fix this by checking that the requested scheduler is "none" and doing nothing in that case.

Fixes 734e1a860312 ("block: Prevent deadlocks when switching elevators")
---
 block/elevator.c | 2 ++
 1 file changed, 2 insertions(+)
block/elevator.c +2 -0
index c355b55d0107..d0ee9c0aaed2 100644
@@ -714,6 +714,8 @@ int elv_iosched_load_module(struct gendisk *disk, const char *buf,
 		return -EOPNOTSUPP;
 
 	strscpy(elevator_name, buf, sizeof(elevator_name));
+	if (!strncmp(elevator_name, "none", 4))
+		return 0;
 
 	return request_module("%s-iosched", strstrip(elevator_name));
 }
Signature · 1 line
2.46.0
#1 lore raw
Quoted 10 lines · Damien Le Moal

Commit 734e1a860312 ("block: Prevent deadlocks when switching elevators") introduced the function elv_iosched_load_module() to allow loading an elevator module outside of elv_iosched_store() with the target device queue not frozen, to avoid deadlocks. However, the "none" scheduler does not have a module and as a result, elv_iosched_load_module() always returns an error when trying to switch to this valid scheduler.

Fix this by checking that the requested scheduler is "none" and doing nothing in that case.

The old code before this commit simply ignored the request_module, just as most callers of it do. I think that's the right approach here as well.

Tested-by on v1 1/1
#11 lore raw
In reply to Damien Le Moal
Quoted 7 lines · Damien Le Moal

Commit 734e1a860312 ("block: Prevent deadlocks when switching elevators") introduced the function elv_iosched_load_module() to allow loading an elevator module outside of elv_iosched_store() with the target device queue not frozen, to avoid deadlocks. However, the "none" scheduler does not have a module and as a result, elv_iosched_load_module() always returns an error when trying to switch to this valid scheduler.

This unexpected behavior (setting none scheduler has no effect) was found by the blktests test case scsi/008 failure. This test case invokes the fio command with the --ioscheduler=none option.

Quoted 3 lines

Fix this by checking that the requested scheduler is "none" and doing nothing in that case.

I confirmed this fix patch avoids the unexpected behavior, and makes scsi/008 pass.

Quoted 5 lines
Fixes 734e1a860312 ("block: Prevent deadlocks when switching elevators")

I also run whole blktests applying this patch on top of the v6.11 kernel, and observed no regression. Looks good from testing point of view.

#2 lore raw
In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Damien Le Moal

Commit 734e1a860312 ("block: Prevent deadlocks when switching elevators") introduced the function elv_iosched_load_module() to allow loading an elevator module outside of elv_iosched_store() with the target device queue not frozen, to avoid deadlocks. However, the "none" scheduler does not have a module and as a result, elv_iosched_load_module() always returns an error when trying to switch to this valid scheduler.

Quoted 6 lines
Quoted 2 lines

Fix this by checking that the requested scheduler is "none" and doing nothing in that case.

The old code before this commit simply ignored the request_module, just as most callers of it do. I think that's the right approach here as well.

freeze queue is actually easy to cause deadlock, and old code is to not do it everywhere.

Probably it may be more reliable to replace 'load_module' with 'no_freeze', and not to freeze queue in case that 'no_freeze' is set in queue_attr_store().

queue_wb_lat_store() need no_freeze too since there is GFP_KERNEL allocation involved.

Thanks,

#3 lore raw
Quoted 18 lines · Ming Lei
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Damien Le Moal

Commit 734e1a860312 ("block: Prevent deadlocks when switching elevators") introduced the function elv_iosched_load_module() to allow loading an elevator module outside of elv_iosched_store() with the target device queue not frozen, to avoid deadlocks. However, the "none" scheduler does not have a module and as a result, elv_iosched_load_module() always returns an error when trying to switch to this valid scheduler.

Quoted 6 lines
Quoted 2 lines

Fix this by checking that the requested scheduler is "none" and doing nothing in that case.

The old code before this commit simply ignored the request_module, just as most callers of it do. I think that's the right approach here as well.

Quoted 5 lines

freeze queue is actually easy to cause deadlock, and old code is to not do it everywhere.

Probably it may be more reliable to replace 'load_module' with 'no_freeze', and not to freeze queue in case that 'no_freeze' is set in queue_attr_store().

load_module or whatever the name you prefer, should NOT imply that freezing the queue is not necessary. Switching the IO scheduler is really one such case. Switching the scheduler really needs to be done with the queue frozen, but the scheduler module loading needs to be done with the queue live.

Quoted 2 lines

queue_wb_lat_store() need no_freeze too since there is GFP_KERNEL allocation involved.

No, because again the attribute may need to have the queue frozen to correctly be changed. To avoid hangs, what is needed is to force a GFP_NOIO context before calling the attribute ->store() operation. Doing so, any memory allocation that the attribute change may need will not cause re-entry into a frozen queue (which would result in a hang).

This is easy to do with memalloc_noio_save()/memalloc_noio_restore().

Quoted 3 lines

Thanks,

Signature · 2 lines
Damien Le Moal
Western Digital Research
#4 lore raw
Quoted 22 lines · Damien Le Moal
Quoted 21 lines · Ming Lei
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Damien Le Moal

Commit 734e1a860312 ("block: Prevent deadlocks when switching elevators") introduced the function elv_iosched_load_module() to allow loading an elevator module outside of elv_iosched_store() with the target device queue not frozen, to avoid deadlocks. However, the "none" scheduler does not have a module and as a result, elv_iosched_load_module() always returns an error when trying to switch to this valid scheduler.

Quoted 6 lines
Quoted 2 lines

Fix this by checking that the requested scheduler is "none" and doing nothing in that case.

The old code before this commit simply ignored the request_module, just as most callers of it do. I think that's the right approach here as well.

freeze queue is actually easy to cause deadlock, and old code is to not do it everywhere.

Quoted 7 lines
Quoted 2 lines

Probably it may be more reliable to replace 'load_module' with 'no_freeze', and not to freeze queue in case that 'no_freeze' is set in queue_attr_store().

load_module or whatever the name you prefer, should NOT imply that freezing the queue is not necessary. Switching the IO scheduler is really one such case. Switching the scheduler really needs to be done with the queue frozen, but the scheduler module loading needs to be done with the queue live.

Here 'no_freeze' means that automatic 'freeze queue' isn't needed, or it can be named as 'no_auto_freeze'.

Again, 'load_module' is one bad name from interface viewpoint, which is just needed by 'scheduler' only.

Quoted 11 lines
Quoted 3 lines

queue_wb_lat_store() need no_freeze too since there is GFP_KERNEL allocation involved.

No, because again the attribute may need to have the queue frozen to correctly be changed. To avoid hangs, what is needed is to force a GFP_NOIO context before calling the attribute ->store() operation. Doing so, any memory allocation that the attribute change may need will not cause re-entry into a frozen queue (which would result in a hang).

This is easy to do with memalloc_noio_save()/memalloc_noio_restore().

But why do we need that? Just for paper over the problem caused by the unnecessary freeze queue?

Thanks,
Ming

#5 lore raw
Quoted 6 lines · Ming Lei

Here 'no_freeze' means that automatic 'freeze queue' isn't needed, or it can be named as 'no_auto_freeze'.

Again, 'load_module' is one bad name from interface viewpoint, which is just needed by 'scheduler' only.

If we want to reshuffle this we could have a ->store_unfrozen method that does all the work. But as long as the elevator loading is the only thing that needs do to unfrozen work I'd just keep things as it and not rock the boat.

maintainer
#6 lore raw
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Ming Lei

Here 'no_freeze' means that automatic 'freeze queue' isn't needed, or it can be named as 'no_auto_freeze'.

Quoted 7 lines
Quoted 2 lines

Again, 'load_module' is one bad name from interface viewpoint, which is just needed by 'scheduler' only.

If we want to reshuffle this we could have a ->store_unfrozen method that does all the work. But as long as the elevator loading is the only thing that needs do to unfrozen work I'd just keep things as it and not rock the boat.

Whatever reshuffling people have in mind, that needs to happen AFTER this bug is sorted out.

Signature · 1 line
Jens Axboe
#7 lore raw
Quoted 2 lines · Jens Axboe

Whatever reshuffling people have in mind, that needs to happen AFTER this bug is sorted out.

Yes. The fix from Damien will work, but reverting to the old behavior of ignoring the request_module return value feel much better. I can prepare a patch, but I didn't want to steal the credits from Damien.

maintainer
#8 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

Whatever reshuffling people have in mind, that needs to happen AFTER this bug is sorted out.

Yes. The fix from Damien will work, but reverting to the old behavior of ignoring the request_module return value feel much better. I can prepare a patch, but I didn't want to steal the credits from Damien.

Oh I agree, I think we should just ignore that and that would be the better patch. My point is just that larger reworking should be done after the fix, not advocating for a particular solution.

That said, someone did just email me privately because they ran into this with 6.11. So we should do a clean simple patch to help facilitate getting it to -stable sooner rather than later.

Signature · 1 line
Jens Axboe
#9 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

Whatever reshuffling people have in mind, that needs to happen AFTER this bug is sorted out.

Yes. The fix from Damien will work, but reverting to the old behavior of ignoring the request_module return value feel much better. I can prepare a patch, but I didn't want to steal the credits from Damien.

OK. I can send a v2 ignoring the request_module() result, as it was before.

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#10 lore raw
Quoted 11 lines · Damien Le Moal
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

Whatever reshuffling people have in mind, that needs to happen AFTER this bug is sorted out.

Yes. The fix from Damien will work, but reverting to the old behavior of ignoring the request_module return value feel much better. I can prepare a patch, but I didn't want to steal the credits from Damien.

OK. I can send a v2 ignoring the request_module() result, as it was before.

Sounds good, let's do that.

Signature · 1 line
Jens Axboe