From nobody Fri Oct 2 07:46:15 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (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 75F6338DC69; Thu, 6 Aug 2026 17:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786038779; cv=pass; b=tl11bw2UalUZf3B+MscOAFLUKw62tV7d9Dfu1iu03boI5kcqfP9toQAWYrjMwgsG/RzMD/IYuPMlM99yI2NW7/LGSvqmG1Gp/N7qha1x2INdYDJQqsh3I8LUo4QHiZT5J5vjtXf00LLwIqDzo1W5fc3RniKP1qf3lWjwf0Qz9Zc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786038779; c=relaxed/simple; bh=nw6Hg7YLELQ9BdIxMV3qE+di7YybAX0C91Rr1B4Lha0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pOaMjBwKsjlRBhZL8ByRX1hryQCkgZesoW24ZU7GtIp88GZazKu5zxi2LpVg+934pCkrIA4mT/NuoaP8IOMhT0jsV4O7JMftp9Fv1mBiAhvr/cDC1tXwFoklwlFB7E67AzFKmT1vjXBgTbtfeeO5BpXkPruycVNcZcVkqPOWG6M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com; spf=pass smtp.mailfrom=iusegentoo.com; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b=h+k08SQ7; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b="h+k08SQ7" ARC-Seal: i=1; a=rsa-sha256; t=1786038768; cv=none; d=zohomail.eu; s=zohoarc; b=O85gvEdHLrAzOtM9VcIytxO58imrW0fDLEXMNkH8MDfUyaznxQCnzjM/8wwmKhFA0zaiAb5JISCcZKSvbYRl/yNWsPY/PZzKBS6RET+Gjq1DKsC3sYQbZOORI3Jeo56qT+w9Cy+QeAZG1DEzoI/o0PdDiuh+IbKyJzcF98AntsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1786038768; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=EVG1GxC4aa6YBkLqzvOOLf4wW5wZ9yRHp3Zmvrwa79U=; b=eS6qbn2RDfi47nyVvfTI4ALS9+aVybfB6U4c8ROweuMDwOM5lF6unw/TFQBFbUMXJZxZ6HNGqmSCRVazP87tBaKh83/nj9qeqVuF5a093Rn9HVkaqg3kwyVoKfXShEZeHF/4qSy/GEPbCiuntuALqJQYzwzzWS/KgYatSlEcijY= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=iusegentoo.com; spf=pass smtp.mailfrom=ali@iusegentoo.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1786038768; s=zmail; d=iusegentoo.com; i=ali@iusegentoo.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=EVG1GxC4aa6YBkLqzvOOLf4wW5wZ9yRHp3Zmvrwa79U=; b=h+k08SQ7BAuqau91tI5feKauhYdI+DTbRdEXfoDHlJ0KD37E1XCoxwCFDb2YljQ8 AZ4i+DTOoQynfGdPmEpJUiy2lxcaup/GV1HA8jQgNwXfJejxjtKTx6StZYrnJgpiy1Q vH0mvDpV/9uS7y16QGTnUjv4OaRLwTIcCkL+ex6o= Received: by mx.zoho.eu with SMTPS id 1786038765266733.2332016240437; Thu, 6 Aug 2026 19:52:45 +0200 (CEST) From: Ali Ahmet Memis To: Shuah Khan , Shuah Khan , Thomas Renninger , "John B . Wyatt IV" , John Kacur Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3 1/3] cpupower: zero the topology array to avoid uninitialized reads Date: Thu, 6 Aug 2026 17:51:38 +0000 Message-ID: <20260806175140.270935-2-ali@iusegentoo.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260803175215.117518-1-ali@iusegentoo.com> References: <20260803175215.117518-1-ali@iusegentoo.com> 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-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" get_cpu_topology() allocates core_info with malloc() and then fills it in per CPU. Three paths leave core_cpu_list untouched: a failed physical_package_id read, a failed core_id read, and a core_cpus_list read that comes back empty, which only prints a warning. The array is then sorted with __compare_core_cpu_list(), which passes core_cpu_list to strcmp(). For the entries above that buffer still holds whatever malloc() returned, so strcmp() reads uninitialized memory, and if the buffer happens to contain no NUL byte it reads past the end of it. Allocate with calloc() so an entry that is never filled in compares as an empty string. Fixes: f89cb9cba7a2 ("cpupower: Implement CPU physical core querying") Cc: stable@vger.kernel.org Signed-off-by: Ali Ahmet Memis --- tools/power/cpupower/lib/cpupower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib= /cpupower.c index d7f7ec6f151c..559b04f4387e 100644 --- a/tools/power/cpupower/lib/cpupower.c +++ b/tools/power/cpupower/lib/cpupower.c @@ -171,7 +171,7 @@ int get_cpu_topology(struct cpupower_topology *cpu_top) char path[SYSFS_PATH_MAX]; char *last_cpu_list; =20 - cpu_top->core_info =3D malloc(sizeof(struct cpuid_core_info) * cpus); + cpu_top->core_info =3D calloc(cpus, sizeof(struct cpuid_core_info)); if (cpu_top->core_info =3D=3D NULL) return -ENOMEM; cpu_top->pkgs =3D cpu_top->cores =3D 0; --=20 2.55.0 From nobody Fri Oct 2 07:46:15 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (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 F00A2423E81; Mon, 3 Aug 2026 17:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785779585; cv=pass; b=snKu0dUi4BEOPA1OsjBT94hElCEFO7Ayt3cwCMPTXa4XfLpkdvoiUo55sxiNBpnEUYQZz9D3qDyfdnRtPALIy7e0MRrPsuta8IAIvRKhsJsd6BiZTv2j8fb5f9tj8x6bHYBvErDUTuLJPA/tsDg4btH90muPVfLIiMgYxFokuIk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785779585; c=relaxed/simple; bh=nw6Hg7YLELQ9BdIxMV3qE+di7YybAX0C91Rr1B4Lha0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B6oiAL1N+IJ9lCiYd3xpSV9GH1pl69fTJpkTu3z/2ehaJB0PI+0VvPvh5sc9gti97FCUE+cx1UtLtknDtZaZphSTeFunrTEdTgiwq3lQOtmsy9mehskY9WugYx5FjL7iSts9tbSvNQecUIl8lsgYCODbJjp5MI7kM5Lffux8N9w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com; spf=pass smtp.mailfrom=iusegentoo.com; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b=l+OTMB6r; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b="l+OTMB6r" ARC-Seal: i=1; a=rsa-sha256; t=1785779572; cv=none; d=zohomail.eu; s=zohoarc; b=A/bM7nm5zYyHs7a/28X1Yczn6mBnYnFq8tshaNnY3QlDx796KAslw4KJUXkY0mRmT13g/Ov5nEN3mM/p0nVjlQBs+58dPo9Ff4At8aH3gfm1kB7oz3+6XUM0H8PS/5Kpl1wc3Lq9ahFQN+JUKjvn+dzXmB0EkdgCcY0KdCo+tzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1785779572; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=EVG1GxC4aa6YBkLqzvOOLf4wW5wZ9yRHp3Zmvrwa79U=; b=FBNG443fppOQ51iUoBX7wNqg11cksbd7SQ3Brl3G60IbLctDDs3cmWCyehjcQACFptUDkx1pt4Lzw7VrdXwSWEhtxojA4/S7kz35o/AU4ZAYEyJOlBcRuEFAezB4ZeoVyA2KBELRGFuzVPkoZNQbZAOgl76K9WuRUjTdaBYLRLY= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=iusegentoo.com; spf=pass smtp.mailfrom=ali@iusegentoo.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1785779572; s=zmail; d=iusegentoo.com; i=ali@iusegentoo.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=EVG1GxC4aa6YBkLqzvOOLf4wW5wZ9yRHp3Zmvrwa79U=; b=l+OTMB6rEhU36iM7FvBO8mcQ/kF95lEQCHtLzNf++ROlUtpA3SecYDuM75KWVe0s 1ouJJnzSSRiOaaSfzIipDdmdwnuMlBX0sJDyhPb85M0vEUSomJ9Q2ziNDqPEOKjjwlA jo+0Vgky1jjyVSz2HzQuDHrJvca8oiTwFNBN28DY= Received: by mx.zoho.eu with SMTPS id 1785779569212974.6282702602255; Mon, 3 Aug 2026 19:52:49 +0200 (CEST) From: Ali Ahmet Memis To: Thomas Renninger , Shuah Khan , "John B . Wyatt IV" , John Kacur Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 1/2] cpupower: zero the topology array to avoid uninitialized reads Date: Mon, 3 Aug 2026 17:52:07 +0000 Message-ID: <20260803175215.117518-2-ali@iusegentoo.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260803175215.117518-1-ali@iusegentoo.com> References: <20260803175215.117518-1-ali@iusegentoo.com> 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-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" get_cpu_topology() allocates core_info with malloc() and then fills it in per CPU. Three paths leave core_cpu_list untouched: a failed physical_package_id read, a failed core_id read, and a core_cpus_list read that comes back empty, which only prints a warning. The array is then sorted with __compare_core_cpu_list(), which passes core_cpu_list to strcmp(). For the entries above that buffer still holds whatever malloc() returned, so strcmp() reads uninitialized memory, and if the buffer happens to contain no NUL byte it reads past the end of it. Allocate with calloc() so an entry that is never filled in compares as an empty string. Fixes: f89cb9cba7a2 ("cpupower: Implement CPU physical core querying") Cc: stable@vger.kernel.org Signed-off-by: Ali Ahmet Memis --- tools/power/cpupower/lib/cpupower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib= /cpupower.c index d7f7ec6f151c..559b04f4387e 100644 --- a/tools/power/cpupower/lib/cpupower.c +++ b/tools/power/cpupower/lib/cpupower.c @@ -171,7 +171,7 @@ int get_cpu_topology(struct cpupower_topology *cpu_top) char path[SYSFS_PATH_MAX]; char *last_cpu_list; =20 - cpu_top->core_info =3D malloc(sizeof(struct cpuid_core_info) * cpus); + cpu_top->core_info =3D calloc(cpus, sizeof(struct cpuid_core_info)); if (cpu_top->core_info =3D=3D NULL) return -ENOMEM; cpu_top->pkgs =3D cpu_top->cores =3D 0; --=20 2.55.0 From nobody Fri Oct 2 07:46:15 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (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 6295F486B81; Thu, 6 Aug 2026 17:53:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786038782; cv=pass; b=cAgNNbq9gS8oY2r7CNEOLYmIlbVl6xGoGdZF1nPpfFhnVblsr5gfMAIkXCYM4tm7/nKNJAKCoSuvqyIyRubJjn/6hgtR69ge1W2WJPgmbrE8351r/9ZC06BC1/GlxXIOPZoquSxW9bpQP+1eBrEI02mIMWUsjQRixjzJFyDLJLQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786038782; c=relaxed/simple; bh=NPeV05VN2Q0m0jGasmNg0LOBo6pBEGcCRFWfCNqtMCc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GnCioBqJg58t3RJiqGiTbhP2RePyCrPHOkMGIx7vXnYHX2n2Yvkn2RnYSfXRzj4IFvyOky6bcT6PSr5a1nwfI3IxRcHlhwlkxtmCkrgHza8p77+OhL6biANJWNr4QChWqrltuF89dErp5FPPHL0c3RAxPNh6hAqm+b3MxNXW6zs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com; spf=pass smtp.mailfrom=iusegentoo.com; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b=nAvDTGwr; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b="nAvDTGwr" ARC-Seal: i=1; a=rsa-sha256; t=1786038769; cv=none; d=zohomail.eu; s=zohoarc; b=Brwnmvm7jTeXnyCSPLcqE5h7ICrHloLx0AU6C+uLHhkhR5AXl5ozVp9toMtFDrXXFuoCApu3GjfZbSh9PENx4yl6PZypiwkX0kzh4ygZaAxnvbVv0rojpuF3UnGErlFrzcOJ48JRakfyFE9rKXVNBpQ7AQdMIFO34ekwCvKNQQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1786038769; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=urS3ZJ7s9lTN82OPa2CAKOLVBQaanTrheAG+VfgV1cA=; b=WRDZ4+W1UIr8YejLzRZJobgo2KpZ4uCZ+Yn2L4TNNLi32/yVbE7rhf11JhaZsmWfT5YtjqC0slXSdQqe9ZI3Vt4ifEuOWnyEjR+R3JokCWHdzbQTda77qDzvUuwRzuGuyOTTXlMJH+/unS1cbvEUpH19XO6cvqXZixS77yhae98= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=iusegentoo.com; spf=pass smtp.mailfrom=ali@iusegentoo.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1786038769; s=zmail; d=iusegentoo.com; i=ali@iusegentoo.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=urS3ZJ7s9lTN82OPa2CAKOLVBQaanTrheAG+VfgV1cA=; b=nAvDTGwrJXgy414XN9dNdPHfg78oGOjyJmpGeHOnWDKScvggK6rIHOW2Si4HdwY2 E3bgLO4WrYyMCm7SPlyr/HmPtENQ9/2FfOJO/xBXlUWZBabT5llrTFRSHt7jhgnhPvh WH0baEq3CXtyZ1tG1xkoaR9AcWO8kQfLMRASFFk4= Received: by mx.zoho.eu with SMTPS id 1786038767555754.9783520765928; Thu, 6 Aug 2026 19:52:47 +0200 (CEST) From: Ali Ahmet Memis To: Shuah Khan , Shuah Khan , Thomas Renninger , "John B . Wyatt IV" , John Kacur Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] cpupower: let the core == -1 check handle failed topology reads Date: Thu, 6 Aug 2026 17:51:39 +0000 Message-ID: <20260806175140.270935-3-ali@iusegentoo.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260803175215.117518-1-ali@iusegentoo.com> References: <20260803175215.117518-1-ali@iusegentoo.com> 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-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" When physical_package_id or core_id cannot be read, get_cpu_topology() sets pkg and core to -1 and skips the rest of the iteration. The check below them exists to give such an entry a defined core_cpu_list: if (cpu_top->core_info[cpu].core =3D=3D -1) { strncpy(cpu_top->core_info[cpu].core_cpu_list, "-1", CPULIST_BUFFER); continue; } The two continue statements above it mean it never runs for the entries it was written for, since a CPU whose topology cannot be read is exactly the case it describes. Nothing between the reads and that check needs skipping, so drop the continue statements and let it do its job. Suggested-by: Shuah Khan Signed-off-by: Ali Ahmet Memis --- tools/power/cpupower/lib/cpupower.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib= /cpupower.c index 559b04f4387e..3d7e22ed1fd7 100644 --- a/tools/power/cpupower/lib/cpupower.c +++ b/tools/power/cpupower/lib/cpupower.c @@ -184,7 +184,6 @@ int get_cpu_topology(struct cpupower_topology *cpu_top) &(cpu_top->core_info[cpu].pkg)) < 0) { cpu_top->core_info[cpu].pkg =3D -1; cpu_top->core_info[cpu].core =3D -1; - continue; } if(sysfs_topology_read_file( cpu, @@ -192,7 +191,6 @@ int get_cpu_topology(struct cpupower_topology *cpu_top) &(cpu_top->core_info[cpu].core)) < 0) { cpu_top->core_info[cpu].pkg =3D -1; cpu_top->core_info[cpu].core =3D -1; - continue; } if (cpu_top->core_info[cpu].core =3D=3D -1) { strncpy(cpu_top->core_info[cpu].core_cpu_list, "-1", CPULIST_BUFFER); --=20 2.55.0 From nobody Fri Oct 2 07:46:15 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (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 EFF4640A940; Mon, 3 Aug 2026 17:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785779585; cv=pass; b=Wrl4D6wFuA6ExUFBvgpjtMCcXBWriZTuPlJzw61XDtyR0KvZ6czIINs4NGnh89CuER5XIz2WRlLTLHhXbD6nmK7vhmVo6n9G5K1N/wgQe0ArlCJxompBp0Mf8C7hmi00IvxurGx6t3QsR0ylLUrzxC9LOKAefU28EOGTrZeCjzo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785779585; c=relaxed/simple; bh=dW/rFN6UQszISJxpbWexXiVebV0ZdzGTTToSdoraeX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QPlW0AQjFoz2kupTLZaDHn5MmoF4V+1/t9en3NUJiqTR4TfKbXiKiZNaE2WSf4RQe0M+fSkqF5KVn9kDT0AVSgY3ILBJGNT1VeGMX2UfofxP8g4oprhvhHsmrqRcpHCbZ0gj/m8Cf5E8hnBOnK71rEwFongTmnntFY1g65ANq9c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com; spf=pass smtp.mailfrom=iusegentoo.com; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b=NiP7nJLi; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b="NiP7nJLi" ARC-Seal: i=1; a=rsa-sha256; t=1785779573; cv=none; d=zohomail.eu; s=zohoarc; b=EKRjsiIwBhX7Hsdyy6Cfd/x04rIq9pZ3/NChvDSbXaGOXQqGuKLcEmcWScrCKCJS8bkAYtWGT9xcNjqbwB4y9b7gbEI0XdyPnklaR/gmx3psW7JnY5CwOOsKMrld/GEFFfBRye2DETYH9SriOV5npuL5EyaDp8A99AX5DvFTBis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1785779573; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=gjD6ruQIHBNzIgsVh4WW/czh/4yYBJQ/RaFhBsssmkM=; b=LL+gQi/9rkfVZNVTzfj/qvhUTlTLcWfpn3fVd7GXnxeag1qVM6cGc1Y0tgAtr0dd9xj9xSMEiD0ZT0Jfuv0fWRAuFf2x9Q8Z8Ud5BSuw5W7IbF6pSFLNtEP9lZmkLYMLEmjpBgHbQ634u9DdRW2ESB0ZSYNiRxxJQrfukF0/Q/M= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=iusegentoo.com; spf=pass smtp.mailfrom=ali@iusegentoo.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1785779573; s=zmail; d=iusegentoo.com; i=ali@iusegentoo.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=gjD6ruQIHBNzIgsVh4WW/czh/4yYBJQ/RaFhBsssmkM=; b=NiP7nJLis4lRhJLwq0wRMSLZvNObYIEa4DKmxPx1rFLUQrdgl54w6lsU6ymF4hBQ 1s4brVloWOv6LEFiwqHWywS7UO/PhklRYg5KF+/KJ65GB/XfThszmQyQtfrd22fq5+U ULY5RJHd19P77R8lqTuoryyZQQCLDD8JpMGxLB74= Received: by mx.zoho.eu with SMTPS id 178577957017337.401196725483146; Mon, 3 Aug 2026 19:52:50 +0200 (CEST) From: Ali Ahmet Memis To: Thomas Renninger , Shuah Khan , "John B . Wyatt IV" , John Kacur Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] cpupower: do not count incomplete topology entries as physical cores Date: Mon, 3 Aug 2026 17:52:08 +0000 Message-ID: <20260803175215.117518-3-ali@iusegentoo.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260803175215.117518-1-ali@iusegentoo.com> References: <20260803175215.117518-1-ali@iusegentoo.com> 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-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" The physical core count is derived by sorting core_info by core_cpu_list and counting how many distinct lists there are. The loop seeds the count with entry 0 unconditionally: last_cpu_list =3D cpu_top->core_info[0].core_cpu_list; cpu_top->cores =3D 1; An entry whose topology could not be read is still a member of the array, carrying pkg and core of -1 and either an empty core_cpu_list or the literal "-1". After the sort such an entry can land at index 0, where it is counted as a physical core even though the pkg check inside the loop was meant to exclude it. The check is also applied only to the entries that follow, so the seed is never validated. Skip entries without complete topology data and count from zero, so only CPUs with a package, a core and a core list contribute. Fixes: f89cb9cba7a2 ("cpupower: Implement CPU physical core querying") Signed-off-by: Ali Ahmet Memis --- tools/power/cpupower/lib/cpupower.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib= /cpupower.c index 559b04f4387e..a8ee304bdcc0 100644 --- a/tools/power/cpupower/lib/cpupower.c +++ b/tools/power/cpupower/lib/cpupower.c @@ -214,11 +214,17 @@ int get_cpu_topology(struct cpupower_topology *cpu_to= p) qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info), __compare_core_cpu_list); =20 - last_cpu_list =3D cpu_top->core_info[0].core_cpu_list; - cpu_top->cores =3D 1; - for (cpu =3D 1; cpu < cpus; cpu++) { - if (strcmp(cpu_top->core_info[cpu].core_cpu_list, last_cpu_list) !=3D 0 = && - cpu_top->core_info[cpu].pkg !=3D -1) { + last_cpu_list =3D NULL; + cpu_top->cores =3D 0; + for (cpu =3D 0; cpu < cpus; cpu++) { + if (cpu_top->core_info[cpu].pkg =3D=3D -1 || + cpu_top->core_info[cpu].core =3D=3D -1 || + cpu_top->core_info[cpu].core_cpu_list[0] =3D=3D '\0') + continue; + + if (!last_cpu_list || + strcmp(cpu_top->core_info[cpu].core_cpu_list, + last_cpu_list) !=3D 0) { last_cpu_list =3D cpu_top->core_info[cpu].core_cpu_list; cpu_top->cores++; } --=20 2.55.0 From nobody Fri Oct 2 07:46:15 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (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 B37FE488DA0; Thu, 6 Aug 2026 17:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786038783; cv=pass; b=ca4ru1VDE7lxeMjYeuOynq4Y9MycqGW22t853dSHu5AL6UNLBo7ljRLzpKOjE5u9U6sKwNCZURigkyn/SyZ1ndfsHGgWv8JQKBuKHBfuC/vIVx2eNBqmEp7zw/I52DxRqyDaLwuarNqvwVF36au7zClkA0RlzqScKauy57N2cwc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786038783; c=relaxed/simple; bh=EHhbCVevOeBscWI01IhLo1jCKu5Z9Cq5gdkjjH5gg2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rRZ/vFm2vEu9lTaK4rgD3iImL4epFRREp+/llOrIEx2xUXRSFfDQAbIqFm2y+BN8KsZYAKWUfePwA8NP+ifo6fGHnAejONRT4PC5VmXM4JxkFtWljmkLo/2Z72nVG4IMleW+jaP7L1HGsI5a8qZHt6rcxFl9+lfoos9+BLR+Qsw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com; spf=pass smtp.mailfrom=iusegentoo.com; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b=pRUZMSmx; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iusegentoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iusegentoo.com header.i=ali@iusegentoo.com header.b="pRUZMSmx" ARC-Seal: i=1; a=rsa-sha256; t=1786038772; cv=none; d=zohomail.eu; s=zohoarc; b=LXDrQE5DRtOmnOdT/vCGdUecPqEDwuhhyXZotAhYMSQxAftf1kzznOrBYnv1t2TCH+O7vh8mTA9eSMIEIOobeZg5iurlmNFt71EsbneA7fSqjPaBRdTFwLmOhDitIYwfg1a/2KGshEf+iiY+KAZ365Tl+ZWh+xBTjXayTSvbBow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1786038772; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z6WATQx7HFOLER/80FIk8wzVJDGzY5WQorFbOQe4yZs=; b=MW9iV72uf5GLe3fNy9PO1t8L+F6FBcOd/NAqsS/e06+Xwb9/sBFqiI65UM/bCVZ3f8HnvGRhtJOjWu+XQilYUYb7oNf7FytjPNm94hFpxh8aB4hDznOlUZP22hmtlscWOKZVRafxjJ8I9yO6LnHTna/Vbsiiv++f7dilrhWfl9A= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=iusegentoo.com; spf=pass smtp.mailfrom=ali@iusegentoo.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1786038772; s=zmail; d=iusegentoo.com; i=ali@iusegentoo.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=Z6WATQx7HFOLER/80FIk8wzVJDGzY5WQorFbOQe4yZs=; b=pRUZMSmxDTFSaAvKFqt1wwGAJLPcYQfExXggD+JI+rk6oqWOxnQdC1dlbBL6kIp5 J8x9QW79IWm4Qs5sM1j5lxgpqcBdykhFkth7fcG0QKnWe6NwK9fQ13rShvGFq8uRWgJ CEU4x1/k12f31wYma85AUf0We01l6E19dyrEWftg= Received: by mx.zoho.eu with SMTPS id 1786038769940664.4531870277694; Thu, 6 Aug 2026 19:52:49 +0200 (CEST) From: Ali Ahmet Memis To: Shuah Khan , Shuah Khan , Thomas Renninger , "John B . Wyatt IV" , John Kacur Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] cpupower: do not count incomplete topology entries as physical cores Date: Thu, 6 Aug 2026 17:51:40 +0000 Message-ID: <20260806175140.270935-4-ali@iusegentoo.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260803175215.117518-1-ali@iusegentoo.com> References: <20260803175215.117518-1-ali@iusegentoo.com> 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-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" The physical core count is derived by sorting core_info by core_cpu_list and counting how many distinct lists there are. The loop seeds the count with entry 0 unconditionally: last_cpu_list =3D cpu_top->core_info[0].core_cpu_list; cpu_top->cores =3D 1; A CPU whose topology could not be read is still a member of the array, carrying pkg and core of -1 and a core_cpu_list of "-1". That sorts ahead of any real cpu list, so after the qsort it is entry 0 and it seeds the count as if it were a core. The pkg check inside the loop only guards the entries that follow, never the one the count started from. An offline CPU is enough to reach this. The topology attribute group is added and removed by a CPU hotplug callback in drivers/base/topology.c, so physical_package_id and core_id are absent while a CPU is offline and both reads fail. Skip entries without complete topology data and count from zero, so only CPUs with a package and a core contribute. Fixes: f89cb9cba7a2 ("cpupower: Implement CPU physical core querying") Signed-off-by: Ali Ahmet Memis --- tools/power/cpupower/lib/cpupower.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib= /cpupower.c index 3d7e22ed1fd7..7784eb499435 100644 --- a/tools/power/cpupower/lib/cpupower.c +++ b/tools/power/cpupower/lib/cpupower.c @@ -212,11 +212,16 @@ int get_cpu_topology(struct cpupower_topology *cpu_to= p) qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info), __compare_core_cpu_list); =20 - last_cpu_list =3D cpu_top->core_info[0].core_cpu_list; - cpu_top->cores =3D 1; - for (cpu =3D 1; cpu < cpus; cpu++) { - if (strcmp(cpu_top->core_info[cpu].core_cpu_list, last_cpu_list) !=3D 0 = && - cpu_top->core_info[cpu].pkg !=3D -1) { + last_cpu_list =3D NULL; + cpu_top->cores =3D 0; + for (cpu =3D 0; cpu < cpus; cpu++) { + if (cpu_top->core_info[cpu].pkg =3D=3D -1 || + cpu_top->core_info[cpu].core =3D=3D -1) + continue; + + if (!last_cpu_list || + strcmp(cpu_top->core_info[cpu].core_cpu_list, + last_cpu_list) !=3D 0) { last_cpu_list =3D cpu_top->core_info[cpu].core_cpu_list; cpu_top->cores++; } --=20 2.55.0