From nobody Sat Apr 4 00:24:02 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010068.outbound.protection.outlook.com [52.101.61.68]) (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 C9C352D8760 for ; Sat, 21 Mar 2026 16:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774111157; cv=fail; b=qkVQ4hXmWfDVuoiy1YywnkCjNZ/sAzK8MkDUl1yoKyowsBSFiKE6HYBip9TEVuIAKpR2lmrRohRClj7FtEi3RxwLmSwjd7CS0Gdu5zo9V97PZJ4FDiUHC+hqgDoAthvGIWKI1Z5r/G43brHipoKxvNH1GCxPMt3le6LuVL72qkM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774111157; c=relaxed/simple; bh=fTFmmFVk3VK9D7okz6Q7rUdixY/gRy6ZeXRtNiO4HB0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M8kEZ8FDaHXhvmPSb8LeyZXcz7IE2/dh0C1YYHVhqVqdD946Ja56NO8+QIzrQ4rVYmyF6Q1x7peKG+8t754O37DOIE71qklHQEWOIKrg0nmhooprcPjaXO3/7kNLkxU4Akd9/Wm+4gNgvAfnPZFqwwKf7BkTC2Z8LYRRyWe/Evg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=bH2ZDGTp; arc=fail smtp.client-ip=52.101.61.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="bH2ZDGTp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ugqr9fxRlhD6fsyw1X/NMo65KAIEuoremy2yFrB+D9Mrjd0AJJy/K6HBQ5FMMP72E5hLWN5GlyWFr386V414bjpZbfAl76nLNGMLaXVTXzl6TUr07ixsx31uUQ27DdHN2ohsT6H+EahGxtmZqhAXnS0X1a9VS5I2567xNRdl9x7UgCxzi3/4wCSGIoN0okYMvg33qOFQN9dkbi1NF2a1SSud9u/FZfMC6E7gd9QH+WI8CZp23QFPefYuni0lnlFy/G3n4ls5tFZAqMe3yBHj2zuRc/1c5YnS68iPBwxUtV07FsLZIsNz7IRxwVGCRi3iBT40eQLv83L/OU8vi/8TFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qR6O2SFr6yR+5f24vT+xKEapWjDIllQQNkwTJPossSc=; b=L0HpNq5OJcZaJnhopkwqPEI1mtse71aU3WX1BVQ81xyk5/alKqCwAmsCE1KNZesSf54j94wq/RKdaap8cpfuKjyiMsyJLHKTw89E6GTVMIanhOMdodX3mlDO0FBFzrR8Q3YZS0+wT1GPrMvXZWojKUk5iDrTjy3MyqOb4ljNJYPCokLwFgwaZ4XdgDPYNJL36G1QeCIbPn+hTUNB+QGTzdbyObYt54nfo27FTPURCTC+nmwaVxStHK1B3/vfarXOgSD1jF9lNgXyYlgnrlBOlrjwvBVXJep1J4Ox61PI0uKEYmIT3aHH6gbKkb8gz2niDxZe9rtnz8wJsssMsPHrCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qR6O2SFr6yR+5f24vT+xKEapWjDIllQQNkwTJPossSc=; b=bH2ZDGTpClV8YmYwHuhtma/K1Lwj+KKF87glW23V17Jn63Y/E8sjAXfd5BkkpqfHzkm0TxK11FYbwaAcOOvCXjKxb38cJCFdKdc93z9xD56ZXQdWNXLP8ANBl6EBjmPkEhC+a3gAQFkv//DsH6x2SUAnSuXqRUGXw0OJmYc4SWM= Received: from SA1P222CA0132.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c2::15) by PH7PR12MB8180.namprd12.prod.outlook.com (2603:10b6:510:2b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.15; Sat, 21 Mar 2026 16:39:11 +0000 Received: from SA2PEPF00003AE6.namprd02.prod.outlook.com (2603:10b6:806:3c2:cafe::c3) by SA1P222CA0132.outlook.office365.com (2603:10b6:806:3c2::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9723.25 via Frontend Transport; Sat, 21 Mar 2026 16:39:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003AE6.mail.protection.outlook.com (10.167.248.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.19 via Frontend Transport; Sat, 21 Mar 2026 16:39:11 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Sat, 21 Mar 2026 11:39:06 -0500 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Nathan Chancellor , "Valentin Schneider" , Dietmar Eggemann , Shrikanth Hegde , Chen Yu , CC: Steven Rostedt , Ben Segall , "Mel Gorman" , "Gautham R. Shenoy" , , K Prateek Nayak Subject: [PATCH] sched/topology: Initialize sd_span after assignment to *sd Date: Sat, 21 Mar 2026 16:38:52 +0000 Message-ID: <20260321163852.11102-1-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260320235824.GA1176840@ax162> References: <20260320235824.GA1176840@ax162> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AE6:EE_|PH7PR12MB8180:EE_ X-MS-Office365-Filtering-Correlation-Id: 818dcc34-82a1-4e79-ea36-08de8768616c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700016|1800799024|82310400026|30052699003|921020|13003099007|22082099003|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: wBuepjGrq8gV+NHpzFiQ1+fypLK3Ta4HkRWfneVW3WmXP2SCCsWm1lUmSjoMJfNowNM0v/FkM5H79rXxEQEODtUn669pxr+SUsbnO2jFNggcJxK7zhh5+/7qnZxOTekwwvGMODrAaa3LTuhLV6QfMr3+5hEBa/Py9N4QJDI9tQ9n33bHHvUOuIrtOaJZ+BGOfgra3T0p9+NtjjDte60hRKCcTUpqPYlNmBU39sV+kxSrDpaWoa3fjjVRqAoUW+fuQK3RqNwqCAcyJSu3mhrNYjLyy7R7ZThXQATb6gJvtkn6HVVqJHr/lkAj9YVIK07xuNNXYU/rfdzGoaGInvYe05W0IZ9BFmpNI54NpmDx5OW8o9gaY+SwdTd+S0MKBUDb2mOLuu3ZjT6PDOFREzLCd/X4KBI4lod7i/ySpyVRJhV7bND12xlvx05+4Nk/LwJczyppgmrvVANHsMeL5wl2Hul8nvxUdQHC5O/bHn8exOSfPZVWLf39nFnpHVNVpJvcFoHXbM6g3fRJZjDccK8jIzwuvcWzYQIQHjTqn3rulKCkt+4bxKB/wM5XZVTinq9J0b9OSAIcEzve/HR8Ime7O0dw+xv1UAVH8Q2cjZdZ+3iiUVEv3wx2WxLEnf+UPr0rFhaHYwdEb/s9Esp/ZX+yMB1Id31Q2rPCe0APR+5KFX7vy4R1Z5o1m3ygCSvs/f6RyR97s9xt0SiPo7nHqo5p9iI6Zk6R09XaMll3d5mjMnF8UcWt0CBsXv7jKBSl7PBCSacplvRScSpsRyvvkTzQlbbfWcuFsnGjCHVYsOnpqpQVE0mSBmLrZbTDUUFEJbLM1ur3yAY+bP6ZdpNjgD3iEw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(36860700016)(1800799024)(82310400026)(30052699003)(921020)(13003099007)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2fK5WDRfqKfA/6mlm6mpzQzc6syOZp4xN7ibEWMaeAJf98+nb97T5HHmU8JTTBlaezIVyTIfXOF/+FOFalzlRtnJ7ONRZLNFxU6WGcJd/w7xzBK1x+gy3WYavPi4hbJ5HzlZ0ic4scngr+/pRTBunPQtwFtfrvjWHuq39dM5TLJT1hZPq3xd0cFs43iNis1kM6+Ok4HtFHZ7SMQijNsqYjqCAI9pLGWFFN8nhvhdjOQveBcjQ4gOuQ1bkjMRn68frzRF+RSUQINzxMz0/0FbY/y4RcQ9rAK5d9oEj/8879a/cMnhYdGlhgSDF/5vFh7Mu1exQsGCPSDtKyvv4y5liq1xuPMw1Q4ykw/+1Arm1cK6qi7APkCwBMy5yJnMhVSfAiKIlEE+JbeEVWTQ8TYCyVUIDupRcDvYYfW77jBpwRlWwaDRwaPE7s+bILDjO9vi X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2026 16:39:11.3417 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 818dcc34-82a1-4e79-ea36-08de8768616c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003AE6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8180 Content-Type: text/plain; charset="utf-8" Nathan reported a kernel panic on his ARM builds after commit 8e8e23dea43e ("sched/topology: Compute sd_weight considering cpuset partitions") which was root caused to the compiler zeroing out the first few bytes of sd->span. During the debug [1], it was discovered that, on some configs, offsetof(struct sched_domain, span) at 292 was less than sizeof(struct sched_domain) at 296 resulting in: *sd =3D { ... } assignment clearing out first 4 bytes of sd->span which was initialized before. The official GCC specification for "Arrays of Length Zero" [2] says: Although the size of a zero-length array is zero, an array member of this kind may increase the size of the enclosing type as a result of tail padding. which means the relative offset of the variable length array at the end of the sturct can indeed be less than sizeof() the struct as a result of tail padding thus overwriting that data of the flexible array that overlapped with the padding whenever the struct is initialized as whole. Partially revert commit 8e8e23dea43e ("sched/topology: Compute sd_weight considering cpuset partitions") to initialize sd_span after the fixed memebers of sd. Use cpumask_weight_and(cpu_map, tl->mask(tl, cpu)) to calculate span_weight before initializing the sd_span. cpumask_and_weight() is of same complexity as cpumask_and() and the additional overhead is negligible. While at it, also initialize sd->span_weight in sd_init() since sd_weight now captures the cpu_map constraints. Fixup the sd->span_weight whenever sd_span is fixed up by the generic topology layer. Reported-by: Nathan Chancellor Closes: https://lore.kernel.org/all/20260320235824.GA1176840@ax162/ Fixes: 8e8e23dea43e ("sched/topology: Compute sd_weight considering cpuset = partitions") Link: https://lore.kernel.org/all/a8c125fd-960d-4b35-b640-95a33584eb08@amd.= com/ [1] Link: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] Signed-off-by: K Prateek Nayak Reviewed-by: Shrikanth Hegde Tested-by: Chen Yu Tested-by: Jon Hunter Tested-by: K Prateek Nayak Tested-by: Nathan Chancellor --- Nathan, can you please check if this fixes the issue you are observing - it at least fixed one that I'm observing ;-) Peter, if you would like to keep revert and enhancements separate, let me know and I'll spin a v2. --- kernel/sched/topology.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 43150591914b..721ed9b883b8 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1669,17 +1669,13 @@ sd_init(struct sched_domain_topology_level *tl, struct cpumask *sd_span; u64 now =3D sched_clock(); =20 - sd_span =3D sched_domain_span(sd); - cpumask_and(sd_span, cpu_map, tl->mask(tl, cpu)); - sd_weight =3D cpumask_weight(sd_span); - sd_id =3D cpumask_first(sd_span); + sd_weight =3D cpumask_weight_and(cpu_map, tl->mask(tl, cpu)); =20 if (tl->sd_flags) sd_flags =3D (*tl->sd_flags)(); if (WARN_ONCE(sd_flags & ~TOPOLOGY_SD_FLAGS, "wrong sd_flags in topology description\n")) sd_flags &=3D TOPOLOGY_SD_FLAGS; - sd_flags |=3D asym_cpu_capacity_classify(sd_span, cpu_map); =20 *sd =3D (struct sched_domain){ .min_interval =3D sd_weight, @@ -1715,8 +1711,15 @@ sd_init(struct sched_domain_topology_level *tl, .last_decay_max_lb_cost =3D jiffies, .child =3D child, .name =3D tl->name, + .span_weight =3D sd_weight, }; =20 + sd_span =3D sched_domain_span(sd); + cpumask_and(sd_span, cpu_map, tl->mask(tl, cpu)); + sd_id =3D cpumask_first(sd_span); + + sd->flags |=3D asym_cpu_capacity_classify(sd_span, cpu_map); + WARN_ONCE((sd->flags & (SD_SHARE_CPUCAPACITY | SD_ASYM_CPUCAPACITY)) =3D= =3D (SD_SHARE_CPUCAPACITY | SD_ASYM_CPUCAPACITY), "CPU capacity asymmetry not supported on SMT\n"); @@ -2518,6 +2521,8 @@ static struct sched_domain *build_sched_domain(struct= sched_domain_topology_leve cpumask_or(sched_domain_span(sd), sched_domain_span(sd), sched_domain_span(child)); + + sd->span_weight =3D cpumask_weight(sched_domain_span(sd)); } =20 } @@ -2697,7 +2702,6 @@ build_sched_domains(const struct cpumask *cpu_map, st= ruct sched_domain_attr *att /* Build the groups for the domains */ for_each_cpu(i, cpu_map) { for (sd =3D *per_cpu_ptr(d.sd, i); sd; sd =3D sd->parent) { - sd->span_weight =3D cpumask_weight(sched_domain_span(sd)); if (sd->flags & SD_NUMA) { if (build_overlap_sched_groups(sd, i)) goto error; base-commit: fe7171d0d5dfbe189e41db99580ebacafc3c09ce --=20 2.34.1