Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Hubert Mazur <hmazur@google.com>
Cc: Wake Liu <wakel@google.com>, Kazuhiro Inaba <kinaba@google.com>,
	Grzegorz Jaszczyk <jaszczyk@google.com>,
	Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH] sys_cpu_topology02: Drop upper bound on core_id
Date: Tue, 1 Dec 2026 17:24:41 +0100	[thread overview]
Message-ID: <20261201162441.GA80775@pevik> (raw)
In-Reply-To: <20261120093444.609481-1-hmazur@google.com>

Hi Hubert,

> 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:

Good catch, thanks!

>   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().

Indeed, the test gets fixed by this on my laptop. I'm ok with it, @Cyril WDYT?
The main concern I have is that you left poss_max_id variable which is now
useless. This part is not needed any more:

	if (tst_is_virt(VIRT_ANY))
		pkg_max_id = LONG_MAX;
	else
		pkg_max_id = poss_max_id;

(and the variable declaration itself, of course).

With that removed you may add my RBT:
Reviewed-by: Petr Vorel <pvorel@suse.cz>

> Fixes: d19bf8f7dede ("testcases: sysfs: Add sys_cpu_topology02")
> Signed-off-by: Hubert Mazur <hmazur@google.com>
> ---
>  .../kernel/sysfs/devices/system/cpu/sys_cpu_topology02.c   | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)

> diff --git a/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_topology02.c b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_topology02.c
> index 7098da9f3..57353d9d1 100644
> --- a/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_topology02.c
> +++ b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_topology02.c
> @@ -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

Please instead of plain Documentation/ABI/stable/sysfs-devices-system-cpu use
:kernel_tree:`Documentation/ABI/stable/sysfs-devices-system-cpu`

which links it in our doc [1] to kernel doc URL [2]. We could even use official
kernel doc generated from Documentation/ABI/stable/sysfs-devices-system-cpu [3],
but :kernel_tree: would be good for now.

Also, I updated formatting of the docs, please rebase for v2.

Kind regards,
Petr

[1] https://linux-test-project.readthedocs.io/en/latest/users/test_catalog.html#sys-cpu-topology02
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/stable/sysfs-devices-system-cpu
[3] https://docs.kernel.org/admin-guide/abi-stable.html#abi-sys-devices-system-cpu-cpux-topology-core-id

> + *   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 = {

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      parent reply	other threads:[~2026-12-01 16:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:34 [LTP] [PATCH] sys_cpu_topology02: Drop upper bound on core_id Hubert Mazur via ltp
2026-11-20 10:34 ` [LTP] " linuxtestproject.agent
2026-11-30 10:06 ` [LTP] [PATCH] " Hubert Mazur via ltp
2026-12-01 16:24 ` Petr Vorel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201162441.GA80775@pevik \
    --to=pvorel@suse.cz \
    --cc=hmazur@google.com \
    --cc=jaszczyk@google.com \
    --cc=kinaba@google.com \
    --cc=ltp@lists.linux.it \
    --cc=wakel@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox