Skip to contentSkip to conversation

FAILED: patch "[PATCH] sched/cache: Skip kernel threads for cache aware scheduling" failed to apply to 7.2-stable tree

PATCH [email protected] 2 participants 4 messages Sep 29 – Sep 30

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 7.2-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.2.y
git checkout FETCH_HEAD
git cherry-pick -x 65efcccddc83d6a19e8a2e2a6117811e39e589bf
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092935-angelic-kick-1d0a@gregkh' --subject-prefix 'PATCH 7.2.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 65efcccddc83d6a19e8a2e2a6117811e39e589bf Mon Sep 17 00:00:00 2001
From: Chen Yu <[email protected]>
Date: Mon, 21 Sep 2026 17:37:26 -0700
Subject: [PATCH] sched/cache: Skip kernel threads for cache aware scheduling
to rubustify the code

Kernel thread should not be covered by cache aware scheduling as it borrows the statistics from the user space thread. Filter the kernel thread in account_mm_sched().

In theory a kernel thread does not have any valid cache group, so !grp should gate the kernel thread. Add the PF_KTHREAD check explicitly here for safety reasons, to guard against future modifications and to pair with task_tick_cache().

kernel/sched/fair.c +7 -1
index 974a7dfe3215..57360f5cdde4 100644
@@ -1907,8 +1907,14 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
 	/*
 	 * init_task, kthreads and user thread created
 	 * by user_mode_thread() don't have a cache group.
+	 * In theory a kernel thread does not have any valid
+	 * cache group, because sched_cache_fork() is not
+	 * invoked for a kernel thread - !grp should gate the
+	 * kernel thread. Use the PF_KTHREAD check explicitly
+	 * here for safety reasons, to guard against future
+	 * modifications and to pair with task_tick_cache().
 	 */
-	if (!grp || !grp->pcpu_sched)
+	if (p->flags & PF_KTHREAD || !grp || !grp->pcpu_sched)
 		return;
 
 	pcpu_sched = per_cpu_ptr(grp->pcpu_sched, cpu_of(rq));
#1 lore raw
Quoted 7 lines · On Tue, 2026-09-29 at 13:43 +0200, [email protected] wrote:

The patch below does not apply to the 7.2-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

Quoted 9 lines

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.2.y
git checkout FETCH_HEAD
git cherry-pick -x 65efcccddc83d6a19e8a2e2a6117811e39e589bf
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092935-angelic-kick-1d0a@gregkh' --subject-prefix 'PATCH 7.2.y' 'HEAD^..'

Possible dependencies:

These patches in upstream needs to be applied first before this patch:
f0d243a96f268 sched/fair: Avoid creating misfits during cache-aware balancing (should be included in stable) 28f9c0e0a0b94 sched/cache: Decouple sched_cache_group from mm to fix UAF (just merged in stable) b636fef85bda7 sched/cache: Introduce task_struct->sched_cache_grp to fix UAF (should be included in stable)

Thanks.

Tim

Quoted 52 lines

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 65efcccddc83d6a19e8a2e2a6117811e39e589bf Mon Sep 17 00:00:00 2001
From: Chen Yu <[email protected]>
Date: Mon, 21 Sep 2026 17:37:26 -0700
Subject: [PATCH] sched/cache: Skip kernel threads for cache aware scheduling
to rubustify the code

Kernel thread should not be covered by cache aware scheduling as it borrows the statistics from the user space thread. Filter the kernel thread in account_mm_sched().

In theory a kernel thread does not have any valid cache group, so !grp should gate the kernel thread. Add the PF_KTHREAD check explicitly here for safety reasons, to guard against future modifications and to pair with task_tick_cache().

kernel/sched/fair.c +7 -1
index 974a7dfe3215..57360f5cdde4 100644
@@ -1907,8 +1907,14 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
 	/*
 	 * init_task, kthreads and user thread created
 	 * by user_mode_thread() don't have a cache group.
+	 * In theory a kernel thread does not have any valid
+	 * cache group, because sched_cache_fork() is not
+	 * invoked for a kernel thread - !grp should gate the
+	 * kernel thread. Use the PF_KTHREAD check explicitly
+	 * here for safety reasons, to guard against future
+	 * modifications and to pair with task_tick_cache().
 	 */
-	if (!grp || !grp->pcpu_sched)
+	if (p->flags & PF_KTHREAD || !grp || !grp->pcpu_sched)
 		return;
 
 	pcpu_sched = per_cpu_ptr(grp->pcpu_sched, cpu_of(rq));
author maintainer
#2 lore raw
Quoted 15 lines · Tim Chen
Quoted 14 lines · On Tue, 2026-09-29 at 13:43 +0200, [email protected] wrote:

The patch below does not apply to the 7.2-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.2.y
git checkout FETCH_HEAD
git cherry-pick -x 65efcccddc83d6a19e8a2e2a6117811e39e589bf
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092935-angelic-kick-1d0a@gregkh' --subject-prefix 'PATCH 7.2.y' 'HEAD^..'

Quoted 7 lines
Quoted 2 lines

Possible dependencies:

These patches in upstream needs to be applied first before this patch:
f0d243a96f268 sched/fair: Avoid creating misfits during cache-aware balancing (should be included in stable) 28f9c0e0a0b94 sched/cache: Decouple sched_cache_group from mm to fix UAF (just merged in stable) b636fef85bda7 sched/cache: Introduce task_struct->sched_cache_grp to fix UAF (should be included in stable)

Can you send a proper series?

thanks,

greg k-h

#3 lore raw
Quoted 19 lines · Greg KH
Quoted 18 lines · Tim Chen
Quoted 16 lines · On Tue, 2026-09-29 at 13:43 +0200, [email protected] wrote:

The patch below does not apply to the 7.2-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.2.y
git checkout FETCH_HEAD
git cherry-pick -x 65efcccddc83d6a19e8a2e2a6117811e39e589bf
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092935-angelic-kick-1d0a@gregkh' --subject-prefix 'PATCH 7.2.y' 'HEAD^..'

Possible dependencies:

Quoted 6 lines
Quoted 4 lines

These patches in upstream needs to be applied first before this patch:
f0d243a96f268 sched/fair: Avoid creating misfits during cache-aware balancing (should be included in stable) 28f9c0e0a0b94 sched/cache: Decouple sched_cache_group from mm to fix UAF (just merged in stable) b636fef85bda7 sched/cache: Introduce task_struct->sched_cache_grp to fix UAF (should be included in stable)

Can you send a proper series?

Hi Greg,

Sorry for the troubles. I have sent you a series that included all the patches. Some you may have already applied but I still included them so show the order of the patches.

Thanks.

Tim

Quoted 4 lines

thanks,

greg k-h