kernel/sched/topology.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
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().
Reported-by: Breno Leitao <leitao@debian.org>
Closes: https://lore.kernel.org/lkml/akeMbyZGmbjWSZqp@gmail.com/
Fixes: 9e005ed21152d ("sched/topology: Allow multiple domains to claim sched_domain_shared")
Tested-by: Breno Leitao <leitao@debian.org>
Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
---
kernel/sched/topology.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 622e2e01974c4..b761ecda790a8 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -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
--
2.34.1
© 2016 - 2026 Red Hat, Inc.