Skip to contentSkip to conversation

block: remove test of io priority level

PATCH Superseded Aaron Lu 2 participants 4 messages Apr 29, 2025 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Aaron Lu

author
#0 lore raw

PATCH 1/1 block: remove test of io priority level

Ever since commit eca2040972b4("scsi: block: ioprio: Clean up interface definition"), the io priority level is masked and can no longer be larger than IOPRIO_NR_LEVELS so remove this now useless test.

The actual test of io prio level is done in ioprio_value() where any invalid input of class/level/hint will result in an invalid class being passed to the syscall, this is introduced in commit 01584c1e2337("scsi:
block: Improve ioprio value validity checks").

---
Kexin reported a LTP/ioprio_set03 case failure, where the test would pass IOPRIO_CLASS_BE with priority level 8 and see if kernel would return error. Turned out she is using an old kernel header where the change introduced in commit 01584c1e2337("scsi: block: Improve ioprio value validity checks") isn't available. During troubleshooting, I find this priority level test confusing and misleading so I think it should be removed.

 block/ioprio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
block/ioprio.c +1 -4
index 73301a261429f..60364d3faf800 100644
@@ -46,11 +46,8 @@ int ioprio_check_cap(int ioprio)
 			 */
 			if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE))
 				return -EPERM;
-			fallthrough;
-			/* rt has prio field too */
+			break;
 		case IOPRIO_CLASS_BE:
-			if (level >= IOPRIO_NR_LEVELS)
-				return -EINVAL;
 			break;
 		case IOPRIO_CLASS_IDLE:
 			break;
Signature · 1 line
2.39.5
#1 lore raw
Quoted 12 lines · Aaron Lu

Ever since commit eca2040972b4("scsi: block: ioprio: Clean up interface definition"), the io priority level is masked and can no longer be larger than IOPRIO_NR_LEVELS so remove this now useless test.

The actual test of io prio level is done in ioprio_value() where any invalid input of class/level/hint will result in an invalid class being passed to the syscall, this is introduced in commit 01584c1e2337("scsi:
block: Improve ioprio value validity checks").

Quoted 8 lines

---
Kexin reported a LTP/ioprio_set03 case failure, where the test would pass IOPRIO_CLASS_BE with priority level 8 and see if kernel would return error. Turned out she is using an old kernel header where the change introduced in commit 01584c1e2337("scsi: block: Improve ioprio value validity checks") isn't available. During troubleshooting, I find this priority level test confusing and misleading so I think it should be removed.

What is confusing and misleading about the fact that we support only 8 priority levels (0 to 7) and should check for it ?

With that said, the test is indeed redundant for the BE and RT class because we have:

int ioprio_check_cap(int ioprio)

{
	int class = IOPRIO_PRIO_CLASS(ioprio);
	int level = IOPRIO_PRIO_LEVEL(ioprio);

And the macro IOPRIO_PRIO_LEVEL() will mask the level value to something between 0 and 7, always. So necessarily, level will always be lower than IOPRIO_NR_LEVELS. So please reword your commit message to explain that rather than describe what a user may or may not use when setting an ioprio field. And also simplify the patch:

block/ioprio.c +1 -5
index 73301a261429..f0ee2798539c 100644
@@ -46,12 +46,8 @@ int ioprio_check_cap(int ioprio)
                         */
                        if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE))
                                return -EPERM;
-                       fallthrough;
-                       /* rt has prio field too */
-               case IOPRIO_CLASS_BE:
-                       if (level >= IOPRIO_NR_LEVELS)
-                               return -EINVAL;
                        break;
+               case IOPRIO_CLASS_BE:
                case IOPRIO_CLASS_IDLE:
                        break;
                case IOPRIO_CLASS_NONE:
Quoted 20 lines
 block/ioprio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
block/ioprio.c +1 -4
index 73301a261429f..60364d3faf800 100644
@@ -46,11 +46,8 @@ int ioprio_check_cap(int ioprio)
 			 */
 			if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE))
 				return -EPERM;
-			fallthrough;
-			/* rt has prio field too */
+			break;
 		case IOPRIO_CLASS_BE:
-			if (level >= IOPRIO_NR_LEVELS)
-				return -EINVAL;
 			break;
 		case IOPRIO_CLASS_IDLE:
 			break;
Signature · 2 lines
Damien Le Moal
Western Digital Research
author
#2 lore raw
Quoted 22 lines · Damien Le Moal
Quoted 12 lines · Aaron Lu

Ever since commit eca2040972b4("scsi: block: ioprio: Clean up interface definition"), the io priority level is masked and can no longer be larger than IOPRIO_NR_LEVELS so remove this now useless test.

The actual test of io prio level is done in ioprio_value() where any invalid input of class/level/hint will result in an invalid class being passed to the syscall, this is introduced in commit 01584c1e2337("scsi:
block: Improve ioprio value validity checks").

Quoted 8 lines

---
Kexin reported a LTP/ioprio_set03 case failure, where the test would pass IOPRIO_CLASS_BE with priority level 8 and see if kernel would return error. Turned out she is using an old kernel header where the change introduced in commit 01584c1e2337("scsi: block: Improve ioprio value validity checks") isn't available. During troubleshooting, I find this priority level test confusing and misleading so I think it should be removed.

Quoted 2 lines

What is confusing and misleading about the fact that we support only 8 priority levels (0 to 7) and should check for it ?

I meant when I'm troubleshooting this LTP issue, I looked at this level test and had no idea why it didn't work.

Quoted 4 lines

With that said, the test is indeed redundant for the BE and RT class because we have:

int ioprio_check_cap(int ioprio)

Quoted 8 lines
{
	int class = IOPRIO_PRIO_CLASS(ioprio);
	int level = IOPRIO_PRIO_LEVEL(ioprio);

And the macro IOPRIO_PRIO_LEVEL() will mask the level value to something between 0 and 7, always. So necessarily, level will always be lower than IOPRIO_NR_LEVELS. So please reword your commit message to explain that rather than describe what a user may or may not use when setting an ioprio field.

No problem. Does something below look OK to you?

"
Ever since commit eca2040972b4("scsi: block: ioprio: Clean up interface definition"), the macro IOPRIO_PRIO_LEVEL() will mask the level value to something between 0 and 7 so necessarily, level will always be lower than IOPRIO_NR_LEVELS.

Remove this obsolete check.
"

Quoted 12 lines

And also simplify the patch:

block/ioprio.c +0 -0
index 73301a261429..f0ee2798539c 100644
@@ -46,12 +46,8 @@ int ioprio_check_cap(int ioprio)
                         */
                        if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE))
                                return -EPERM;

block/ioprio.c int ioprio_check_cap(int ioprio) · line 53

Quoted 10 lines
block/ioprio.c +1 -5
-                       fallthrough;
-                       /* rt has prio field too */
-               case IOPRIO_CLASS_BE:
-                       if (level >= IOPRIO_NR_LEVELS)
-                               return -EINVAL;
                        break;
+               case IOPRIO_CLASS_BE:
                case IOPRIO_CLASS_IDLE:
                        break;
                case IOPRIO_CLASS_NONE:

Will do.

Thanks,
Aaron

Quoted 20 lines
Quoted 20 lines
 block/ioprio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
block/ioprio.c +1 -4
index 73301a261429f..60364d3faf800 100644
@@ -46,11 +46,8 @@ int ioprio_check_cap(int ioprio)
 			 */
 			if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE))
 				return -EPERM;
-			fallthrough;
-			/* rt has prio field too */
+			break;
 		case IOPRIO_CLASS_BE:
-			if (level >= IOPRIO_NR_LEVELS)
-				return -EINVAL;
 			break;
 		case IOPRIO_CLASS_IDLE:
 			break;
#3 lore raw
Quoted 23 lines · Aaron Lu
Quoted 22 lines · Damien Le Moal
Quoted 20 lines · Aaron Lu

Ever since commit eca2040972b4("scsi: block: ioprio: Clean up interface definition"), the io priority level is masked and can no longer be larger than IOPRIO_NR_LEVELS so remove this now useless test.

The actual test of io prio level is done in ioprio_value() where any invalid input of class/level/hint will result in an invalid class being passed to the syscall, this is introduced in commit 01584c1e2337("scsi:
block: Improve ioprio value validity checks").

---
Kexin reported a LTP/ioprio_set03 case failure, where the test would pass IOPRIO_CLASS_BE with priority level 8 and see if kernel would return error. Turned out she is using an old kernel header where the change introduced in commit 01584c1e2337("scsi: block: Improve ioprio value validity checks") isn't available. During troubleshooting, I find this priority level test confusing and misleading so I think it should be removed.

Quoted 5 lines
Quoted 2 lines

What is confusing and misleading about the fact that we support only 8 priority levels (0 to 7) and should check for it ?

I meant when I'm troubleshooting this LTP issue, I looked at this level test and had no idea why it didn't work.

OK. I understand the "confusing" now :)

Quoted 15 lines
Quoted 4 lines

With that said, the test is indeed redundant for the BE and RT class because we have:

int ioprio_check_cap(int ioprio)

Quoted 8 lines
{
	int class = IOPRIO_PRIO_CLASS(ioprio);
	int level = IOPRIO_PRIO_LEVEL(ioprio);

And the macro IOPRIO_PRIO_LEVEL() will mask the level value to something between 0 and 7, always. So necessarily, level will always be lower than IOPRIO_NR_LEVELS. So please reword your commit message to explain that rather than describe what a user may or may not use when setting an ioprio field.

No problem. Does something below look OK to you?

Quoted 8 lines

"
Ever since commit eca2040972b4("scsi: block: ioprio: Clean up interface definition"), the macro IOPRIO_PRIO_LEVEL() will mask the level value to something between 0 and 7 so necessarily, level will always be lower than IOPRIO_NR_LEVELS.

Remove this obsolete check.
"

Yes, looks much better !

Signature · 2 lines
Damien Le Moal
Western Digital Research