Skip to contentSkip to conversation

sched/topology: Do not override sd->shared allocation

PATCH In review K Prateek Nayak 1 participant 2 messages Jul 13 – Aug 14 Scheduler

lore
Share & tools
lore

K Prateek Nayak

author reviewer
#0 lore raw

PATCH 1/1 sched/topology: Do not override sd->shared allocation

Breno reported a kmemleak for sd->shared assignment on an asymmetric system with a single LLC.

Post the unconditional assignment of sd->shared for sd_llc in commit 9e005ed21152d ("sched/topology: Allow multiple domains to claim sched_domain_shared"), init_sched_domain_shared() can overrwrite the sd->shared assignment for as_asym_cpucapacity when sd_llc and as_asym_cpucapacity point to the same domain.

Return early from init_sched_domain_shared() if a valid sd->shared assignment is detected. Since the degeneration path only decrements the refcount by 1, it is correct to only account the sd->shared assignment once per sched-domain level, even if the flags overlap.

While at it, correct a typo in init_sched_domain_shared().

Fixes 9e005ed21152d ("sched/topology: Allow multiple domains to claim sched_domain_shared")
---
 kernel/sched/topology.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/sched/topology.c +9 -1
index 622e2e01974c4..b761ecda790a8 100644
@@ -2942,6 +2942,14 @@ init_sched_domain_shared(struct s_data *d, struct sched_domain *sd, int flags)
 	struct sched_domain_shared *sds = NULL;
 	int cpu;
 
+	/*
+	 * sd->shared is already assigned for this domain level for a
+	 * different flag. Nothing to do since this allocation is
+	 * already accounted for.
+	 */
+	if (sd->shared)
+		return;
+
 	/*
 	 * Multiple domains can try to claim a shared object like
 	 * SD_ASYM_CPUCAPACITY and SD_SHARE_LLC which can alias to
@@ -2970,7 +2978,7 @@ init_sched_domain_shared(struct s_data *d, struct sched_domain *sd, int flags)
 
 	/*
 	 * Use the sd_shared corresponding to the last
-	 * CPU in the span if none are avaialable.
+	 * CPU in the span if none are available.
 	 */
 	if (WARN_ON_ONCE(!sd->shared))
 		sd->shared = sds;

base-commit: 04998aa54848f15332202d0bea008d2ca1ed1713

Signature · 1 line
2.34.1
author reviewer
#1 lore raw

Hello Peter,

Quoted 14 lines · K Prateek Nayak

Breno reported a kmemleak for sd->shared assignment on an asymmetric system with a single LLC.

Post the unconditional assignment of sd->shared for sd_llc in commit 9e005ed21152d ("sched/topology: Allow multiple domains to claim sched_domain_shared"), init_sched_domain_shared() can overrwrite the sd->shared assignment for as_asym_cpucapacity when sd_llc and as_asym_cpucapacity point to the same domain.

Return early from init_sched_domain_shared() if a valid sd->shared assignment is detected. Since the degeneration path only decrements the refcount by 1, it is correct to only account the sd->shared assignment once per sched-domain level, even if the flags overlap.

Quoted 8 lines

While at it, correct a typo in init_sched_domain_shared().

Fixes 9e005ed21152d ("sched/topology: Allow multiple domains to claim sched_domain_shared")

Sorry for the late notice! Was stuck with some internal fire but in case sched/urgent is still open, could you stick this fix for a memory leak on top.

sched/core is good too otherwise - AUTOSEL should pick this up for stable, and if it doesn't, I'll send out a patch to Greg for v7.2. Sorry again for the late ping.

Quoted 34 lines
---
 kernel/sched/topology.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/sched/topology.c +9 -1
index 622e2e01974c4..b761ecda790a8 100644
@@ -2942,6 +2942,14 @@ init_sched_domain_shared(struct s_data *d, struct sched_domain *sd, int flags)
 	struct sched_domain_shared *sds = NULL;
 	int cpu;
 
+	/*
+	 * sd->shared is already assigned for this domain level for a
+	 * different flag. Nothing to do since this allocation is
+	 * already accounted for.
+	 */
+	if (sd->shared)
+		return;
+
 	/*
 	 * Multiple domains can try to claim a shared object like
 	 * SD_ASYM_CPUCAPACITY and SD_SHARE_LLC which can alias to
@@ -2970,7 +2978,7 @@ init_sched_domain_shared(struct s_data *d, struct sched_domain *sd, int flags)
 
 	/*
 	 * Use the sd_shared corresponding to the last
-	 * CPU in the span if none are avaialable.
+	 * CPU in the span if none are available.
 	 */
 	if (WARN_ON_ONCE(!sd->shared))
 		sd->shared = sds;

base-commit: 04998aa54848f15332202d0bea008d2ca1ed1713

Signature · 2 lines
Thanks and Regards,
Prateek