From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84F80381AE9 for ; Mon, 23 Mar 2026 22:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774305687; cv=none; b=GT9hRNg6xvCAcp41xbprnU01flrjphrRYs+SnQBP1scxs16MjaJjF+TocMQBSOikQUBJT2ErvAVrOPSCUDdWX7v2PVwpk8AYW/rRBWfqHQ58rTexcnEdRrRyFIhg77mBrQZtIGyhgwNpYF2s09ExCPC3KL66fYRzccfdkTGtZrI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774305687; c=relaxed/simple; bh=Rm7WBs/ZyF3pUsK7bipnREdBNA7faYOzAvgBOzUZASc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cxwmAKsbHwCPB8US6+NC0PPaTS3gIvcPvmv0QGxDz1sGY+rjigwDcEXEUHpm9H9343pD6xvk0oxd7BpDV7SvNNRBslgf0ONRWrP/NbLszu3MAL8tfmrS55TSn2P9aL9rp/1nY0Z/GyqpxvdD62VnYyiJJkqy0m6u2ocfqiE1iPA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Vu+eViYY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Vu+eViYY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09324C2BC9E; Mon, 23 Mar 2026 22:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774305687; bh=Rm7WBs/ZyF3pUsK7bipnREdBNA7faYOzAvgBOzUZASc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Vu+eViYYQ6p9EuMnokHuo5LeoqJV02m3j/T6ObLwl68pjcCVp6w9Qi/q+VUAuAGOd JF87LVQMNWvrM4s3y+zqZQRSgvcE0WwVZwk3FE64BIlfFfr0SuunIf1lcW+72TxN9u SwEfUlADwoInZqQWRtZXkvB4skkAiG57zeE2q9/GGN08YDBuzvfYu08lMtyIl+e+TH ZrdkJ+szOALaelt00OwOTbZm7R7cKqEK8OI3caj9ahRW5EGc9j67gMeUZM2nNA5uhs Ax9OjEZIFAuTsPnDRoCvMhB1jiYeyuHJc0vctCS7RwhjzqNypOpQ6/2xKZgBJJOvY2 1qeHQ0dn6JKvQ== Date: Mon, 23 Mar 2026 15:41:21 -0700 From: Nathan Chancellor To: Peter Zijlstra Cc: K Prateek Nayak , Ingo Molnar , Juri Lelli , Vincent Guittot , Valentin Schneider , Dietmar Eggemann , Shrikanth Hegde , Chen Yu , linux-kernel@vger.kernel.org, Steven Rostedt , Ben Segall , Mel Gorman , "Gautham R. Shenoy" , x86@kernel.org, Kees Cook Subject: Re: [PATCH] sched/topology: Initialize sd_span after assignment to *sd Message-ID: <20260323224121.GA1420432@ax162> References: <20260320235824.GA1176840@ax162> <20260321163852.11102-1-kprateek.nayak@amd.com> <20260323093627.GY3738010@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260323093627.GY3738010@noisy.programming.kicks-ass.net> On Mon, Mar 23, 2026 at 10:36:27AM +0100, Peter Zijlstra wrote: > Does this work? Yes, that avoids the initial panic I reported. Tested-by: Nathan Chancellor > diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h > index 51c29581f15e..defa86ed9b06 100644 > --- a/include/linux/sched/topology.h > +++ b/include/linux/sched/topology.h > @@ -153,7 +153,21 @@ struct sched_domain { > > static inline struct cpumask *sched_domain_span(struct sched_domain *sd) > { > - return to_cpumask(sd->span); > + /* > + * Because C is an absolutely broken piece of shit, it is allowed for > + * offsetof(*sd, span) < sizeof(*sd), this means that structure > + * initialzation *sd = { ... }; which will clear every unmentioned > + * member, can over-write the start of the flexible array member. > + * > + * Luckily, the way we allocate the flexible array is by: > + * > + * sizeof(*sd) + count * sizeof(*sd->span) > + * > + * this means that we have sufficient space for the whole flex array > + * *outside* of sizeof(*sd). So use that, and avoid using sd->span. > + */ > + unsigned long *bitmap = (void *)sd + sizeof(*sd); > + return to_cpumask(bitmap); > } > > extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],