Skip to contentSkip to conversation

block: Fix elv_iosched_local_module handling of "none" scheduler

PATCH Applied Damien Le Moal 4 participants 7 messages Sep 17, 2024 – Oct 8, 2024 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 ignoring the return value of the request_module() call done by elv_iosched_load_module(). This restores the behavior before commit 734e1a860312, which was to ignore the request_module() result and instead rely on elevator_change() to handle the "none" scheduler case.

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

---
Changes from v1:
- Switch to ignoring the return value of request_module() instead of doing nothing if the scheduler name is "none".

 block/elevator.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/elevator.c +3 -1
index c355b55d0107..4122026b11f1 100644
@@ -715,7 +715,9 @@ int elv_iosched_load_module(struct gendisk *disk, const char *buf,
 
 	strscpy(elevator_name, buf, sizeof(elevator_name));
 
-	return request_module("%s-iosched", strstrip(elevator_name));
+	request_module("%s-iosched", strstrip(elevator_name));
+
+	return 0;
 }
 
 ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
Signature · 1 line
2.46.0
maintainer Applied
#2 lore raw
In reply to Damien Le Moal
Quoted 9 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.

[...]

Applied, thanks!

[1/1] block: Fix elv_iosched_local_module handling of "none" scheduler

      commit: e3accac1a976e65491a9b9fba82ce8ddbd3d2389

Best regards,

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Damien Le Moal

Hi Damien,

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.

The commit message here is a bit misleading. The problem is not that request_module can fail, the problem is that some failure modes cause this function to return a positive integer. This is not caught by callers and it ends up causing all kinds of problems in user space.

Perhaps it makes sense to check for a positive return value at the call site of the load_module pointer in queue_attr_store, so this does not repeat at some point in the future?

Or maybe document that load_module implementations should not return a positive value unless it actually wants to send this to user space as the result of a write to the scheduler sysfs file?

Best regards,
Andreas

#4 lore raw
Quoted 12 lines · Andreas Hindborg

Hi Damien,

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.

Quoted 8 lines

The commit message here is a bit misleading. The problem is not that request_module can fail, the problem is that some failure modes cause this function to return a positive integer. This is not caught by callers and it ends up causing all kinds of problems in user space.

Perhaps it makes sense to check for a positive return value at the call site of the load_module pointer in queue_attr_store, so this does not repeat at some point in the future?

Well, the patch version that went upstream totally ignores the return value of request_module(), as it did before. So I do not think there are any issues anymore... ? Might be good to add a comment about it above that request_module() call in elv_iosched_load_module().

Quoted 4 lines

Or maybe document that load_module implementations should not return a positive value unless it actually wants to send this to user space as the result of a write to the scheduler sysfs file?

Yes, ->load_module() should return 0 on success and negative error code on error. Otherwise, a positive error may be interpreted by user space as a success write to the sysfs attribute. Adding a comment for that will be good too.

Care to send a patch ?

Signature · 2 lines
Damien Le Moal
Western Digital Research
#5 lore raw
Quoted 5 lines · Damien Le Moal

Yes, ->load_module() should return 0 on success and negative error code on error. Otherwise, a positive error may be interpreted by user space as a success write to the sysfs attribute. Adding a comment for that will be good too.

Care to send a patch ?

It should not return anything at all as alreaday said last round. Jens just asked for that to be sent layer, so I guess I'll do it now.

#6 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Damien Le Moal

Yes, ->load_module() should return 0 on success and negative error code on error. Otherwise, a positive error may be interpreted by user space as a success write to the sysfs attribute. Adding a comment for that will be good too.

Care to send a patch ?

It should not return anything at all as alreaday said last round. Jens just asked for that to be sent layer, so I guess I'll do it now.

Ah, yes, that is even better.

Signature · 2 lines
Damien Le Moal
Western Digital Research