From bdd7e4161cbbfe9a7653b8800df49212fe75ce5a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 3 Aug 2022 14:11:10 +0200 Subject: [PATCH] 5.15-stable patches added patches: block-fix-default-io-priority-handling-again.patch --- ...x-default-io-priority-handling-again.patch | 86 +++++++++++++++++++ queue-5.15/series | 1 + 2 files changed, 87 insertions(+) create mode 100644 queue-5.15/block-fix-default-io-priority-handling-again.patch diff --git a/queue-5.15/block-fix-default-io-priority-handling-again.patch b/queue-5.15/block-fix-default-io-priority-handling-again.patch new file mode 100644 index 00000000000..5efb46c3189 --- /dev/null +++ b/queue-5.15/block-fix-default-io-priority-handling-again.patch @@ -0,0 +1,86 @@ +From e589f46445960c274cc813a1cc8e2fc73b2a1849 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Thu, 23 Jun 2022 09:48:26 +0200 +Subject: block: fix default IO priority handling again + +From: Jan Kara + +commit e589f46445960c274cc813a1cc8e2fc73b2a1849 upstream. + +Commit e70344c05995 ("block: fix default IO priority handling") +introduced an inconsistency in get_current_ioprio() that tasks without +IO context return IOPRIO_DEFAULT priority while tasks with freshly +allocated IO context will return 0 (IOPRIO_CLASS_NONE/0) IO priority. +Tasks without IO context used to be rare before 5a9d041ba2f6 ("block: +move io_context creation into where it's needed") but after this commit +they became common because now only BFQ IO scheduler setups task's IO +context. Similar inconsistency is there for get_task_ioprio() so this +inconsistency is now exposed to userspace and userspace will see +different IO priority for tasks operating on devices with BFQ compared +to devices without BFQ. Furthemore the changes done by commit +e70344c05995 change the behavior when no IO priority is set for BFQ IO +scheduler which is also documented in ioprio_set(2) manpage: + +"If no I/O scheduler has been set for a thread, then by default the I/O +priority will follow the CPU nice value (setpriority(2)). In Linux +kernels before version 2.6.24, once an I/O priority had been set using +ioprio_set(), there was no way to reset the I/O scheduling behavior to +the default. Since Linux 2.6.24, specifying ioprio as 0 can be used to +reset to the default I/O scheduling behavior." + +So make sure we default to IOPRIO_CLASS_NONE as used to be the case +before commit e70344c05995. Also cleanup alloc_io_context() to +explicitely set this IO priority for the allocated IO context to avoid +future surprises. Note that we tweak ioprio_best() to maintain +ioprio_get(2) behavior and make this commit easily backportable. + +CC: stable@vger.kernel.org +Fixes: e70344c05995 ("block: fix default IO priority handling") +Reviewed-by: Damien Le Moal +Tested-by: Damien Le Moal +Signed-off-by: Jan Kara +Reviewed-by: Christoph Hellwig +Link: https://lore.kernel.org/r/20220623074840.5960-1-jack@suse.cz +Signed-off-by: Jens Axboe +Signed-off-by: Greg Kroah-Hartman +--- + block/blk-ioc.c | 1 + + block/ioprio.c | 4 ++-- + include/linux/ioprio.h | 2 +- + 3 files changed, 4 insertions(+), 3 deletions(-) + +--- a/block/blk-ioc.c ++++ b/block/blk-ioc.c +@@ -265,6 +265,7 @@ int create_task_io_context(struct task_s + INIT_RADIX_TREE(&ioc->icq_tree, GFP_ATOMIC); + INIT_HLIST_HEAD(&ioc->icq_list); + INIT_WORK(&ioc->release_work, ioc_release_fn); ++ ioc->ioprio = IOPRIO_DEFAULT; + + /* + * Try to install. ioc shouldn't be installed if someone else +--- a/block/ioprio.c ++++ b/block/ioprio.c +@@ -189,9 +189,9 @@ out: + int ioprio_best(unsigned short aprio, unsigned short bprio) + { + if (!ioprio_valid(aprio)) +- aprio = IOPRIO_DEFAULT; ++ aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM); + if (!ioprio_valid(bprio)) +- bprio = IOPRIO_DEFAULT; ++ bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM); + + return min(aprio, bprio); + } +--- a/include/linux/ioprio.h ++++ b/include/linux/ioprio.h +@@ -11,7 +11,7 @@ + /* + * Default IO priority. + */ +-#define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM) ++#define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0) + + /* + * Check that a priority value has a valid class. diff --git a/queue-5.15/series b/queue-5.15/series index 9ff183a5001..4f226cadbee 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -1,3 +1,4 @@ x86-speculation-make-all-retbleed-mitigations-64-bit-only.patch selftests-bpf-extend-verifier-and-bpf_sock-tests-for-dst_port-loads.patch selftests-bpf-check-dst_port-only-on-the-client-socket.patch +block-fix-default-io-priority-handling-again.patch -- 2.47.3