sys_cpu_topology02: Drop upper bound on core_id
PATCH 1/1 sys_cpu_topology02: Drop upper bound on core_id
sys_cpu_topology02 currently checks that each online CPU's /sys/devices/system/cpu/cpuN/topology/core_id is in the range [0, poss_max_id], assuming that core_id is a dense 0-based index bounded by the highest possible CPU id.
Per Linux Documentation/ABI/stable/sysfs-devices-system-cpu, core_id is:
"Typically it is the hardware platform's identifier (rather than the kernel's). The actual value is architecture and platform dependent."
- On x86, arch/x86/kernel/cpu/topology_common.c derives core_id from the hardware APIC ID domain bits. On Intel hybrid CPUs, APIC IDs are sparsely allocated across core types and clusters; for example, on an 8-CPU Intel hybrid system (possible: 0-7), core_id values are 0, 4, 8, 12, 32, 33, 34, 35, causing sys_cpu_topology02 to fail on cpu2..cpu7:
sys_cpu_topology02.c:83: TFAIL:
/sys/devices/system/cpu/cpu2/topology/core_id = 8 out of range [0, 7] /sys/devices/system/cpu/cpu3/topology/core_id = 12 out of range [0, 7] /sys/devices/system/cpu/cpu4/topology/core_id = 32 out of range [0, 7]
- On arm64 with ACPI PPTT, drivers/acpi/pptt.c populates core_id from the firmware ACPI processor UID or the PPTT table byte offset, neither of which is bounded by the CPU count.
Drop the upper bound on core_id to LONG_MAX (preserving the >= 0 sanity check), update the test documentation comment accordingly, and remove the now-unused poss_max_id parameter from check_cpu_topology().
--- .../kernel/sysfs/devices/system/cpu/sys_cpu_topology02.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
testcases/kernel/sysfs/devices/system/cpu/sys_cpu_topology02.c +9 -5
@@ -22,8 +22,12 @@* in sync on every architecture, and avoids a spurious failure if a * sibling CPU is hot-unplugged concurrently with this test running. * - the CPU itself is contained in its own thread_siblings_list -* - core_id is in [0, highest possible CPU id], since there can be at most -* as many cores as possible CPUs (every core has at least one thread) +* - core_id is non-negative. Per +* Documentation/ABI/stable/sysfs-devices-system-cpu, core_id is typically +* the hardware platform's identifier rather than a dense kernel index, so +* it is not bounded by the highest possible CPU id (e.g. x86 derives it +* from the hardware APIC ID, which is sparse on Intel hybrid CPUs, and +* arm64 ACPI PPTT may export a firmware UID or table byte offset). * - physical_package_id is in [-1, highest possible CPU id] on physical * hardware, or just at least -1 under virtualization (see below). -1 is a * legitimate value here, not just a range extension for safety: per
@@ -66,7 +70,7 @@ static void check_self_in_threads(int cpu) PATH_SYS_CPU "/cpu%d/topology/thread_siblings_list", cpu); } -static void check_cpu_topology (int cpu,int poss_max_id,long pkg_max_id) +static void check_cpu_topology (int cpu,long pkg_max_id) {char sub[PATH_MAX ], super[PATH_MAX ];
@@ -80,7 +84,7 @@ static void check_cpu_topology(int cpu, int poss_max_id, long pkg_max_id)tst_res (TINFO ,"Checking cpu%d topology" , cpu); -TST_SYSFS_ASSERT_RANGELL (0 , poss_max_id, +TST_SYSFS_ASSERT_RANGELL (0 ,LONG_MAX ,PATH_SYS_CPU "/cpu%d/topology/core_id" , cpu); TST_SYSFS_ASSERT_RANGELL(-1, pkg_max_id,
@@ -124,7 +128,7 @@ static void do_test(void) pkg_max_id = poss_max_id;for (cpu =0 ; cpu <= max_id; cpu++) -check_cpu_topology (cpu, poss_max_id, pkg_max_id); +check_cpu_topology (cpu, pkg_max_id); }static struct tst_test test = {
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Hubert,
Quoted 1 line · Hubert Mazur
sys_cpu_topology02: Drop upper bound oncore_id
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp