Re: [PATCH] sched/topology: Do not override sd->shared allocation
From: K Prateek Nayak
Date: Fri Aug 14 2026 - 10:50:47 EST
Hello Peter,
On 7/13/2026 12:26 PM, K Prateek Nayak wrote:
> 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@xxxxxxxxxx>
> Closes: https://lore.kernel.org/lkml/akeMbyZGmbjWSZqp@xxxxxxxxx/
> Fixes: 9e005ed21152d ("sched/topology: Allow multiple domains to claim sched_domain_shared")
> Tested-by: Breno Leitao <leitao@xxxxxxxxxx>
> Tested-by: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
> Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
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.
> ---
> 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
--
Thanks and Regards,
Prateek