xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT
v7 cover xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT
Hello,
This patch series integrates CPU topology discovery into the Xen hypervisor for both ACPI and Device Tree platforms.
While the primary PPTT parsing logic was introduced in v5, this v7 focuses on hardening error checking, enforcing strict table validation.
Changes in v7:
- PPTT Table Validation & Hardening:
* find_pptt_node(): Added leaf node verification (ACPI 6.3+).
* acpi_init_cpu_topology(): Added bounds checks to ensure proc->parent validly references memory strictly inside the PPTT table bounds.
* Factored out shared table checking helper functions used by both find_pptt_node() and acpi_init_cpu_topology().
* Added subtable alignment checks and strengthened processor structure size validation.
- Graceful Fallback & Allocation:
* Treated missing topology definitions as benign conditions.
* Used xvzalloc_array() for temporary memory allocations during initialization.
- Build & Kconfig Adjustments:
* Updated Kconfig to use "depends on UNSUPPORTED" instead of "if UNSUPPORTED".
- Code Cleanups & Style Conformance:
* Used designated initializers for structure data initializations.
* Consolidated topology helpers with IS_ENABLED().
* Removed redundant error checks and reduced unnecessary pointer casts.
* Switched type-based sizeof(type) to variable-based sizeof(*var).
* Added leading spaces before labels ( out:)
Changes in v6:
- Renamed the series subject from "xen/arm: Device Tree based CPU topology support" to reflect the inclusion of generic ACPI PPTT topology parsing.
- Infrastructure & Kconfig:
* Updated Kconfig to make both DT_CPU_TOPOLOGY and ACPI_CPU_TOPOLOGY select GENERIC_CPU_TOPOLOGY.
* Ensured that if topology parsing from either DT or ACPI PPTT fails, the CPU topology table is freed to fall back to the non-topology behavior.
* Moved the cpu_topology definition to cpu.c so that variables and functions in cpu-topology.c can be completely freed after Xen init.
- Topology Logic (DT / ACPI):
* Set the cluster ID to 0 when the cluster definition is missing from the Device Tree cpu-map node.
* Handled cases where cluster info is missing upon reaching a physical package in the PPTT parser by assuming one cluster per socket.
* Split out the import of ACPI PPTT definitions from the Linux kernel (including unused definitions) into a separate standalone patch.
- Robustness & Safety:
* Avoided assuming np becomes NULL after exiting dt_for_each_child_node(); explicitly return NULL instead.
* Added bounds-checking ASSERTs for values returned by cpumask_first().
* Added explicit braces {} to nested if statements to clarify else scoping and maintain style symmetry.
* Enforced an upper limit on the PPTT parsing loop iterations to prevent infinite loops on corrupted tables.
* Treat the absence of a physical package node definition in PPTT as a parsing error.
- Optimization & Efficiency:
* Optimized setup_siblings_masks() to eliminate redundant loop iterations.
* Dynamically allocate the temporary data storage used during ACPI PPTT parsing.
- Code Cleanup & Refactoring:
* Replaced the invalid_topo_id constant with the INVALID_TOPO_ID macro.
* Initialized all members of the cpu_map array with INVALID_TOPO_ID.
* Added a blank line between <xen/...> and <asm/...> header groups.
* Reordered #ifdef blocks to prioritize generic logic over architecture- specific ones.
* Corrected code indentation.
* Applied the static specifier to file-local data structures and functions.
* Minimized the use of fixed-width uint32_t types, restricting its use only where strictly required by the 32-bit ACPI ID specification.
* Declared map_cpu_acpiid[] as static and introduced the helper function acpi_map_cpu_acpiid() for managed access.
* Renamed local variables to more intuitive names.
* Simplified the implementation of get_logical_id().
* Refactored PPTT parsing to reduce type casting by using container_of() and switching from char * to void * pointers.
* Removed redundant error checks.
* Cleaned up unused variables and eliminated debug print statements.
Changes in v5:
- Extracted CPU topology information from the ACPI PPTT.
- Corrected the erroneous use of CONFIG_CPU_TOPOLOGY to CONFIG_GENERIC_CPU_TOPOLOGY.
Changes in v4:
- Only display the CPU topology configuration prompt in common/Kconfig if the architecture defines HAS_GENERIC_CPU_TOPOLOGY.
- Move the definition of the global 'cpu_topology' pointer to common/cpu-topology.c.
- Update the Makefile to explicitly build objects as .init.o when all functions and data within a file are annotated with __init/__initdata, ensuring their memory is reclaimed after system initialization.
- Add an error log in the CPU-to-node mapping function for out-of-bounds cases.
- Use ARRAY_SIZE() instead of raw macros when guarding array accesses.
- Rename variables and functions to avoid ambiguous or misleading terms:
- Avoid 'cpuid' to prevent confusion with x86 CPUID features/instructions.
- Avoid 'node' where it could be confused with a NUMA node, explicitly renaming them to clarify they refer to a Device Tree node.
- Move local variable declarations into the narrowest possible scope.
- Replace the unsupported "%pOF" printk format specifier with "%s" and explicit node name retrieval.
- Remove #include <dt-cpu-topology.h> from cpu-topology.h, and ensure the header directly includes only what its definitions require.
- Remove #include <xen/device_tree.h> from dt-cpu-topology.h, replacing it with a forward declaration of 'struct dt_device_node'.
- Use 'const' qualifiers for pointer declarations where the pointed-to structure is not modified.
- Explicitly #include <asm/processor.h> in cpu-topology.h to guarantee that arch-specific definitions of cpu_to_core() and cpu_to_socket() take precedence over the generic fallbacks.
- Introduce inline initialization functions for cpu_sibling_mask and cpu_core_mask in cpu-topology.h, providing separate variants for both when CONFIG_GENERIC_CPU_TOPOLOGY is enabled and disabled.
Changes in v3:
- Use (nr_cpu_ids - 1) as the maximum CPU ID here. The fix for the sparse map mismatch issue on ARM Xen has been split out into a separate patch.
- Switch topology sibling masks to cpumask_var_t for dynamic allocation.
- Allow the system to keep running with a degraded fallback even if the topology table allocation fails.
- Remove the temporary definitions of cpu_to_core() and cpu_to_socket() from RISC-V and PPC processor.h.
- Minimize the use of #ifdef blocks, leveraging compiler Dead Code Elimination (DCE) where possible.
- Clean up the code to follow the Xen coding style. Please let me know if I missed any style nits!
- Verify successful builds across x86, RISC-V, and PPC environments.
Changes in v2:
- Generate topology information even when ACPI is enabled. Note that this is a temporary implementation and doesn't yet parse the PPTT (Processor Properties Topology Table).
- Added support for cpu-map node in Device Tree that doesn't contain explicit cluster node definitions.
Changes in v1 from the previous series "Introduce Device Tree based NUMA support for ARM Xen":
1. Optimized Memory Allocation:
The series now allocates only the minimum required memory area to manage the essential data for the CPUs.
2. Flexible Device Tree Parsing:
The parsing logic no longer depends on the definition order of the 'cpu' nodes and 'cpu-map' nodes in the Device Tree. They can now be read correctly even if their orders do not match.
3. CPU Hotplug Readiness:
To support future CPU hotplug, the system assumes that inactive CPUs are also described in the Device Tree. Xen will pre-load and generate the topology information for these inactive CPUs during the boot phase so it stays available in memory.
Thank you,
Hirokazu Takahashi
Hirokazu Takahashi (5):
xen/device-tree: Parse 'cpu-map' node for CPU topology exploration xen/sched: Link CPU topology to scheduler
xen/sched: Make cpu_nr_siblings() architecture-specific xen/acpi: Import PPTT definitions from Linux
xen/acpi: Parse PPTT to initialize CPU topology
xen/arch/arm/Kconfig | 1 + xen/arch/arm/acpi/boot.c | 2 + xen/arch/arm/include/asm/acpi.h | 2 + xen/arch/arm/include/asm/processor.h | 4 - xen/arch/arm/smpboot.c | 15 +- xen/arch/ppc/include/asm/processor.h | 4 - xen/arch/riscv/include/asm/processor.h | 4 - xen/arch/x86/include/asm/processor.h | 1 + xen/common/Kconfig | 22 ++ xen/common/Makefile | 1 + xen/common/cpu-topology.c | 62 ++++ xen/common/cpu.c | 4 + xen/common/device-tree/Makefile | 1 + xen/common/device-tree/cpu-topology.c | 409 +++++++++++++++++++++++++ xen/common/sched/credit2.c | 21 +- xen/common/sysctl.c | 1 + xen/drivers/acpi/Kconfig | 3 + xen/drivers/acpi/Makefile | 1 + xen/drivers/acpi/topology.c | 330 ++++++++++++++++++++ xen/include/acpi/actbl2.h | 113 +++++++ xen/include/xen/acpi.h | 15 + xen/include/xen/cpu-topology.h | 76 +++++ xen/include/xen/dt-cpu-topology.h | 35 +++ 23 files changed, 1091 insertions(+), 36 deletions(-) create mode 100644 xen/common/cpu-topology.c create mode 100644 xen/common/device-tree/cpu-topology.c create mode 100644 xen/drivers/acpi/topology.c create mode 100644 xen/include/xen/cpu-topology.h create mode 100644 xen/include/xen/dt-cpu-topology.h
Signature · 1 line
2.43.0
PATCH v7 1/5 xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Parse the 'cpu-map' node in the Device Tree to extract CPU topology information. If the 'cpu-map' node is absent, fall back to generating the topology data from the NUMA information. This generation assumes exactly one socket per NUMA node and that SMT is unsupported.
---
Changes in v7
- Graceful Fallback & Allocation:
* Treated missing topology definitions as benign conditions.
* Used xvzalloc_array() for temporary memory allocations during initialization.
- Build & Kconfig Adjustments:
* Updated Kconfig to use "depends on UNSUPPORTED" instead of "if UNSUPPORTED".
- Code Cleanups & Style Conformance:
* Used designated initializers for structure data initializations.
xen/arch/arm/Kconfig | 1 + xen/arch/arm/smpboot.c | 7 + xen/common/Kconfig | 22 ++ xen/common/Makefile | 1 + xen/common/cpu-topology.c | 62 +++++ xen/common/cpu.c | 4 + xen/common/device-tree/Makefile | 1 + xen/common/device-tree/cpu-topology.c | 344 ++++++++++++++++++++++++++ xen/drivers/acpi/Kconfig | 3 + xen/drivers/acpi/Makefile | 1 + xen/drivers/acpi/topology.c | 41 +++ xen/include/xen/acpi.h | 13 + xen/include/xen/cpu-topology.h | 34 +++ xen/include/xen/dt-cpu-topology.h | 35 +++ 14 files changed, 569 insertions(+) create mode 100644 xen/common/cpu-topology.c create mode 100644 xen/common/device-tree/cpu-topology.c create mode 100644 xen/drivers/acpi/topology.c create mode 100644 xen/include/xen/cpu-topology.h create mode 100644 xen/include/xen/dt-cpu-topology.h
xen/arch/arm/Kconfig +1 -0
@@ -19,6 +19,7 @@ config ARM select HAS_ALTERNATIVE if HAS_VMAP select HAS_DEVICE_TREE_DISCOVERY select HAS_DOM0LESS + select HAS_GENERIC_CPU_TOPOLOGY select HAS_GRANT_CACHE_FLUSH if GRANT_TABLE select HAS_STACK_PROTECTOR select HAS_STATIC_MEMORY
xen/arch/arm/smpboot.c +7 -0
@@ -9,10 +9,12 @@#include <xen/acpi.h> #include <xen/cpu.h> +#include <xen/cpu-topology.h> #include <xen/cpumask.h> #include <xen/delay.h> #include <xen/device_tree.h> #include <xen/domain_page.h> +#include <xen/dt-cpu-topology.h> #include <xen/errno.h> #include <xen/init.h> #include <xen/mm.h>
@@ -244,6 +246,9 @@ static void __init dt_smp_init_cpus(void) }else tmp_map[i] = hwid; + +/* Pass the info to dt_init_cpu_topology() */ +map_cpu_to_dt_node (i, cpu); }if ( !bootcpu_valid )
@@ -280,6 +285,8 @@ void __init smp_init_cpus(void)else acpi_smp_init_cpus (); +init_cpu_topology (); +if ( opt_hmp_unsafe )warning_add ("WARNING: HMP COMPUTING HAS BEEN ENABLED.\n" "It has implications on the security and stability of the system,\n"
xen/common/Kconfig +22 -0
@@ -140,6 +140,9 @@ config HAS_EX_TABLE config HAS_FAST_MULTIPLY bool +config HAS_GENERIC_CPU_TOPOLOGY + bool + config HAS_IOPORTS bool
@@ -191,6 +194,25 @@ config VM_EVENT config NEEDS_LIBELF bool +config GENERIC_CPU_TOPOLOGY + bool + +config DT_CPU_TOPOLOGY + bool "Device tree based CPU topology support (UNSUPPORTED)" + depends on HAS_GENERIC_CPU_TOPOLOGY && DEVICE_TREE_PARSE && UNSUPPORTED + select GENERIC_CPU_TOPOLOGY + help + Retrieve CPU topology information from the device tree to optimize + vCPU scheduling. + +config ACPI_CPU_TOPOLOGY + bool "ACPI based CPU topology support (UNSUPPORTED)" + depends on HAS_GENERIC_CPU_TOPOLOGY && ACPI && UNSUPPORTED + select GENERIC_CPU_TOPOLOGY + help + Retrieve CPU topology information from the ACPI PPTT to optimize + vCPU scheduling. + config NUMA bool
xen/common/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_GENERIC_BUG_FRAME) += bug.o obj-$(CONFIG_HYPFS_CONFIG) += config_data.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o +obj-$(CONFIG_GENERIC_CPU_TOPOLOGY) += cpu-topology.init.o obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += device.o obj-$(filter-out $(CONFIG_X86),$(CONFIG_ACPI)) += device.o
xen/common/cpu-topology.c new file +62 -0
62 lines not on this page · raw message
xen/common/cpu.c +4 -0
@@ -46,6 +46,10 @@ const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {#undef MASK_DECLARE_2#undef MASK_DECLARE_1 +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY +struct cpu_topology *__ro_after_init cpu_topology; +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ +static DEFINE_RWLOCK (cpu_add_remove_lock);bool get_cpu_maps (void )
xen/common/device-tree/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-y += bootfdt.init.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += bootinfo-fdt.init.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += bootinfo.init.o +obj-$(CONFIG_DT_CPU_TOPOLOGY) += cpu-topology.init.o obj-y += device-tree.o obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += domain-build.init.o obj-$(filter $(CONFIG_DOM0LESS_BOOT),$(CONFIG_HAS_DEVICE_TREE_DISCOVERY)) += dom0less-build.init.o
xen/common/device-tree/cpu-topology.c new file +344 -0
344 lines not on this page · raw message
xen/drivers/acpi/Kconfig +3 -0
@@ -2,6 +2,9 @@ config ACPI bool +config ACPI_CPU_TOPOLOGY + bool + config ACPI_LEGACY_TABLES_LOOKUP bool
xen/drivers/acpi/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_NUMA) += numa.o obj-y += osl.o obj-$(CONFIG_PM_STATS) += pmstat.o obj-$(CONFIG_PM_OP) += pm-op.o +obj-$(CONFIG_ACPI_CPU_TOPOLOGY) += topology.init.o obj-$(CONFIG_X86) += hwregs.o obj-$(CONFIG_X86) += reboot.o
xen/drivers/acpi/topology.c new file +41 -0
41 lines not on this page · raw message
xen/include/xen/acpi.h +13 -0
@@ -135,6 +135,19 @@ static inline int acpi_boot_table_init(void)#endif /*!CONFIG_ACPI*/ +#ifdef CONFIG_ACPI_CPU_TOPOLOGY + +int acpi_init_cpu_topology (void ); + +#else /* CONFIG_ACPI_CPU_TOPOLOGY */ + +static inline int acpi_init_cpu_topology (void ) +{ +return -EOPNOTSUPP ; +} + +#endif /* CONFIG_ACPI_CPU_TOPOLOGY */ +int get_cpu_id (u32 acpi_id);unsigned int acpi_register_gsi (u32 gsi,int edge_level,int active_high_low);
xen/include/xen/cpu-topology.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_CPU_TOPOLOGY_H +#define XEN_CPU_TOPOLOGY_H + +#include <xen/cpumask.h> + +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY + +struct cpu_topology { +cpumask_var_t thread_sibling; +cpumask_var_t core_sibling; +cpumask_var_t cluster_sibling; +}; + +extern struct cpu_topology *cpu_topology; +void init_cpu_topology (void ); + +#else /* CONFIG_GENERIC_CPU_TOPOLOGY */ + +static inline void init_cpu_topology (void ) {} + +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ + +#endif /* XEN_CPU_TOPOLOGY_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/xen/dt-cpu-topology.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_DT_CPU_TOPOLOGY_H +#define XEN_DT_CPU_TOPOLOGY_H + +#include <xen/errno.h> + +struct dt_device_node ; + +#ifdef CONFIG_DT_CPU_TOPOLOGY + +void map_cpu_to_dt_node (unsigned int cpu,struct dt_device_node *cpu_node); +int dt_init_cpu_topology (void ); + +#else /* CONFIG_DT_CPU_TOPOLOGY */ + +static inline void map_cpu_to_dt_node (unsigned int cpu, +struct dt_device_node *cpu_node) {} +static inline int dt_init_cpu_topology (void ) +{ +return -EOPNOTSUPP ; +} + +#endif /* CONFIG_DT_CPU_TOPOLOGY */ + +#endif /* XEN_DT_CPU_TOPOLOGY_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v7 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Quoted 30 lines · Hirokazu Takahashi
xen/common/cpu-topology.c new file +27
-0@@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <xen/acpi.h> +#include <xen/cpu-topology.h> +#include <xen/cpumask.h> +#include <xen/dt-cpu-topology.h> +#include <xen/init.h> +#include <xen/xvmalloc.h> + +static void __init free_topology_table (void ) +{ +unsigned int cpu; + +for ( cpu =0 ; cpu < nr_cpu_ids; cpu++ ) + { +free_cpumask_var (cpu_topology[cpu].thread_sibling); +free_cpumask_var (cpu_topology[cpu].core_sibling); +free_cpumask_var (cpu_topology[cpu].cluster_sibling); + } + +XVFREE (cpu_topology); +} + +void __init init_cpu_topology (void ) +{ +unsigned int cpu; +int ret;
xen/common/cpu-topology.c line 37
Quoted 10 lines
xen/common/cpu-topology.c new file +10
-0+ + cpu_topology = xvzalloc_array(struct cpu_topology, nr_cpu_ids); +if ( !cpu_topology ) +return ; + +for ( cpu =0 ; cpu < nr_cpu_ids; cpu++ ) + { +if ( !zalloc_cpumask_var (&cpu_topology[cpu].thread_sibling) + || !zalloc_cpumask_var (&cpu_topology[cpu].core_sibling) + || !zalloc_cpumask_var (&cpu_topology[cpu].cluster_sibling) )
In v6 the || here were correctly placed. Why did they move?
xen/common/cpu.c const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = { · line 51
Quoted 9 lines
xen/common/cpu.c +3
-0@@ -46,6 +46,10 @@ const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {#undef MASK_DECLARE_2#undef MASK_DECLARE_1 +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY +struct cpu_topology *__ro_after_init cpu_topology; +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */
Looks like you also need to include xen/cpu-topology.h here. I can't see it being included implicitly.
xen/drivers/acpi/Kconfig line 10
Quoted 12 lines
xen/drivers/acpi/Kconfig +3
-0@@ -2,6 +2,9 @@ config ACPI bool +config ACPI_CPU_TOPOLOGY + bool + config ACPI_LEGACY_TABLES_LOOKUP bool
Did you forget to undo this change?
With all three adjustments:
Jan
RE: [PATCH v7 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Hi Jan,
Thank you for the reviewing.
Quoted 7 lines
xen/common/cpu-topology.c line 37
Quoted 5 lines
xen/common/cpu-topology.c new file +5
-0+for ( cpu =0 ; cpu < nr_cpu_ids; cpu++ ) + { +if ( !zalloc_cpumask_var (&cpu_topology[cpu].thread_sibling) + || !zalloc_cpumask_var (&cpu_topology[cpu].core_sibling) + || !zalloc_cpumask_var (&cpu_topology[cpu].cluster_sibling) )In v6 the || here were correctly placed. Why did they move?
I saw other code using leading || and tried to match that, but I'll revert it back.
Quoted 7 lines
xen/common/cpu.c const unsigned long
Quoted 3 lines
xen/common/cpu.c +0
-0@@ -46,6 +46,10 @@ const unsigned longcpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
Quoted 3 lines
xen/common/cpu.c +0
-0#undef MASK_DECLARE_2#undef MASK_DECLARE_1
Quoted 6 lines
xen/common/cpu.c const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = { · line 51
Quoted 3 lines
xen/common/cpu.c +3
-0+#ifdef CONFIG_GENERIC_CPU_TOPOLOGY +struct cpu_topology *__ro_after_init cpu_topology; +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ Looks like you also need to include
xen/cpu-topology.hhere. I can't see it being included implicitly.
Okay,
Quoted 6 lines
Quoted 6 lines
xen/drivers/acpi/Kconfig +0
-0@@ -2,6 +2,9 @@ config ACPI bool
Quoted 8 lines
xen/drivers/acpi/Kconfig line 10
Quoted 6 lines
xen/drivers/acpi/Kconfig +3
-0+config ACPI_CPU_TOPOLOGY + bool + config ACPI_LEGACY_TABLES_LOOKUP boolDid you forget to undo this change?
Oops, I will remove it.
Quoted 2 lines
With all three adjustments:
Reviewed-by Jan Beulich <[email protected]> # common, acpi
Thank you,
Hirokazu Takahashi.
Re: [PATCH v7 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Quoted 9 lines · Hirokazu Takahashi
Quoted 7 lines
xen/common/cpu-topology.c line 37
Quoted 5 lines
xen/common/cpu-topology.c new file +5
-0+for ( cpu =0 ; cpu < nr_cpu_ids; cpu++ ) + { +if ( !zalloc_cpumask_var (&cpu_topology[cpu].thread_sibling) + || !zalloc_cpumask_var (&cpu_topology[cpu].core_sibling) + || !zalloc_cpumask_var (&cpu_topology[cpu].cluster_sibling) )In v6 the || here were correctly placed. Why did they move?
I saw other code using leading || and tried to match that, but I'll revert it back.
Just to clarify: Looking at surrounding code and matching style is perfectly valid. We generally (there are exceptions, e.g. when we try to slowly transition style of a file) aim at having consistent style within a file. However, our own style is still preferred, and mandated when new files are added which aren't taken from elsewhere. Hence ./CODING_STYLE is still your primary reference. And from other style aspects of the tiny snippet above it is already clear that it is written in Xen style. Hence ./CODING_STYLE is it for the case here, plus (sadly) any unwritten rules (like, unfortunately, that of placing operators in line-wrapped expressions).
Jan
PATCH v7 2/5 xen/sched: Link CPU topology to scheduler
In reply to Hirokazu TakahashiMake CPU topology information available to the Xen scheduler. Additionally, ensure that this topology information is displayed when executing the 'xl info -n' command.
---
Changes in v7:
- Code Cleanups & Style Conformance:
* Consolidated topology helpers with IS_ENABLED().
xen/arch/arm/include/asm/processor.h | 4 -- xen/arch/arm/smpboot.c | 8 +--- xen/arch/ppc/include/asm/processor.h | 4 -- xen/arch/riscv/include/asm/processor.h | 4 -- xen/common/device-tree/cpu-topology.c | 65 ++++++++++++++++++++++++++ xen/common/sched/credit2.c | 6 +++ xen/common/sysctl.c | 1 + xen/drivers/acpi/topology.c | 3 ++ xen/include/xen/cpu-topology.h | 39 +++++++++++++++- 9 files changed, 114 insertions(+), 20 deletions(-)
xen/arch/arm/include/asm/processor.h +0 -4
@@ -613,10 +613,6 @@ void show_stack(const struct cpu_user_regs *regs);#define cpu_relax () barrier()/* Could yield? */ -/* All a bit UP for the moment */ -#define cpu_to_core (_cpu) (0) -#define cpu_to_socket (_cpu) (0) -struct vcpu ;void vcpu_regs_hyp_to_user (const struct vcpu *vcpu,struct vcpu_guest_core_regs *regs);
xen/arch/arm/smpboot.c +1 -7
@@ -92,13 +92,7 @@ static int setup_cpu_sibling_map(int cpu) !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) ) return -ENOMEM; -/* -* Currently we assume there is no multithread and NUMA, so -* a CPU is a sibling with itself, and the all possible CPUs -* are supposed to belong to the same socket (NUMA node). -*/ -cpumask_set_cpu (cpu,per_cpu (cpu_sibling_mask, cpu)); -cpumask_copy (per_cpu (cpu_core_mask, cpu), &cpu_possible_map); +init_cpu_sibling_map (cpu);return 0 ; }
xen/arch/ppc/include/asm/processor.h +0 -4
@@ -141,10 +141,6 @@/* Macro to adjust thread priority for hardware multithreading */ #define HMT_very_low () asm volatile ( "or %r31, %r31, %r31" ) -/* TODO: This isn't correct */ -#define cpu_to_core (cpu) (0) -#define cpu_to_socket (cpu) (0) -/* * User-accessible registers: most of these need to be saved/restored * for every nested Xen invocation.
xen/arch/riscv/include/asm/processor.h +0 -4
@@ -54,10 +54,6 @@ struct cpu_user_regsunsigned long pregs; }; -/* TODO: need to implement */ -#define cpu_to_core (cpu) 0 -#define cpu_to_socket (cpu) 0 -static inline void cpu_relax (void ) {#ifdef __riscv_zihintpause
xen/common/device-tree/cpu-topology.c +65 -0
80 lines not on this page · raw message
xen/common/sched/credit2.c +6 -0
@@ -9,6 +9,7 @@* Based on an earlier verson by Emmanuel Ackaouy. */ +#include <xen/cpu-topology.h> #include <xen/errno.h> #include <xen/init.h> #include <xen/lib.h>
@@ -35,6 +36,11 @@*/ static unsigned int cpu_nr_siblings (unsigned int cpu) { +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY +if ( cpu_topology ) +return cpu_topology[cpu].num_siblings; +#endif +#ifdef CONFIG_X86 return cpu_data[cpu].x86_num_siblings;#else
xen/common/sysctl.c +1 -0
@@ -28,6 +28,7 @@#include <xen/pmstat.h> #include <xen/livepatch.h> #include <xen/coverage.h> +#include <xen/cpu-topology.h> long do_sysctl (XEN_GUEST_HANDLE_PARAM (xen_sysctl_t) u_sysctl) {
xen/drivers/acpi/topology.c +3 -0
@@ -22,6 +22,9 @@ int __init acpi_init_cpu_topology(void) {struct cpu_topology *topo = &cpu_topology[cpu]; + topo->phys_core_id = cpu; + topo->num_siblings =1 ; +cpumask_set_cpu (cpu, topo->thread_sibling);cpumask_copy (topo->core_sibling, &cpu_possible_map);cpumask_copy (topo->cluster_sibling, &cpu_possible_map);
xen/include/xen/cpu-topology.h +38 -1
@@ -4,22 +4,59 @@#define XEN_CPU_TOPOLOGY_H #include <xen/cpumask.h> +#include <xen/percpu.h> -#ifdef CONFIG_GENERIC_CPU_TOPOLOGY +#include <asm/processor.h> +#include <asm/smp.h> struct cpu_topology {cpumask_var_t thread_sibling;cpumask_var_t core_sibling;cpumask_var_t cluster_sibling; +unsigned int phys_core_id; +unsigned int phys_cluster_id; +unsigned int phys_socket_id; +unsigned int num_siblings; };extern struct cpu_topology *cpu_topology; + +static inline void init_cpu_sibling_map (unsigned int cpu) +{ +if (IS_ENABLED (CONFIG_GENERIC_CPU_TOPOLOGY ) && cpu_topology ) + { +cpumask_copy (per_cpu (cpu_sibling_mask, cpu), + cpu_topology[cpu].thread_sibling); +cpumask_copy (per_cpu (cpu_core_mask, cpu), + cpu_topology[cpu].core_sibling); + } +else + { +/* Assume all CPUs reside in the same socket and no threading. */ +cpumask_set_cpu (cpu,per_cpu (cpu_sibling_mask, cpu)); +cpumask_copy (per_cpu (cpu_core_mask, cpu), &cpu_possible_map); + } +} + +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY +void init_cpu_topology (void ); +#define cpu_to_core (cpu) (cpu_topology ? cpu_topology[cpu].phys_core_id : 0) +#define cpu_to_socket (cpu) (cpu_topology ? cpu_topology[cpu].phys_socket_id : 0) +#else /* CONFIG_GENERIC_CPU_TOPOLOGY */ static inline void init_cpu_topology (void ) {} +#ifndef cpu_to_core +#define cpu_to_core (cpu) (0) +#endif + +#ifndef cpu_to_socket +#define cpu_to_socket (cpu) (0) +#endif +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ #endif /* XEN_CPU_TOPOLOGY_H */
Signature · 1 line
2.43.0
Re: [PATCH v7 2/5] xen/sched: Link CPU topology to scheduler
Quoted 5 lines · Hirokazu Takahashi
Make CPU topology information available to the Xen scheduler. Additionally, ensure that this topology information is displayed when executing the 'xl info -n' command.
Signed-off-by Hirokazu Takahashi <[email protected]>
Re: [PATCH v7 2/5] xen/sched: Link CPU topology to scheduler
In reply to Hirokazu TakahashiQuoted 5 lines · Hirokazu Takahashi
Make CPU topology information available to the Xen scheduler. Additionally, ensure that this topology information is displayed when executing the 'xl info -n' command.
Signed-off-by Hirokazu Takahashi <[email protected]>
Juergen
PATCH v7 3/5 xen/sched: Make cpu_nr_siblings() architecture-specific
In reply to Hirokazu TakahashiMake cpu_nr_siblings() an architecture-specific function. This patch provides the implementation for x86 and a common version for Device Tree-based architectures.
--- xen/arch/x86/include/asm/processor.h | 1 + xen/common/sched/credit2.c | 25 +++---------------------- xen/include/xen/cpu-topology.h | 5 +++++ 3 files changed, 9 insertions(+), 22 deletions(-)
xen/arch/x86/include/asm/processor.h +1 -0
@@ -106,6 +106,7 @@ extern void intel_init_arat(void);#define cpu_to_core (_cpu) (cpu_data[_cpu].cpu_core_id)#define cpu_to_socket (_cpu) (cpu_data[_cpu].phys_proc_id) +#define cpu_nr_siblings (_cpu) (cpu_data[_cpu].x86_num_siblings)unsigned int apicid_to_socket (unsigned int apicid);
xen/common/sched/credit2.c +3 -22
@@ -29,25 +29,6 @@/* #define d2printk printk */ #define d2printk(x...) -/* -* TODO: Abstract this properly, and figure out what Credit2 wants to do with -* the fact that x86_num_siblings doesn't even have the same meaning -* between x86 vendors. -*/ -static unsigned int cpu_nr_siblings (unsigned int cpu) -{ -#ifdef CONFIG_GENERIC_CPU_TOPOLOGY -if ( cpu_topology ) -return cpu_topology[cpu].num_siblings; -#endif - -#ifdef CONFIG_X86 -return cpu_data[cpu].x86_num_siblings; -#else -return 1 ; -#endif -} -/* * Credit2 tracing events ("only" 512 available!). Check * include/public/trace.h for more details.
@@ -885,9 +866,9 @@ cpu_runqueue_match(const struct csched2_runqueue_data *rqd, unsigned int cpu)/* * Additional checks, to avoid separating siblings in different runqueues. -* This deals with both Intel's HTs and AMD's CUs. An arch that does not have -* any similar concept will just have cpu_nr_siblings() always return 1, and -* setup the cpu_sibling_mask-s acordingly (as currently does ARM), and things +* This deals with Intel's HTs, AMD's CUs and ARM's SMT. An arch that +* does not have similar concept will just have cpu_nr_siblings() always +* return 1, and setup the cpu_sibling_mask-s accordingly, and things * will just work as well. */ static bool
xen/include/xen/cpu-topology.h +5 -0
@@ -44,6 +44,7 @@ void init_cpu_topology(void);#define cpu_to_core (cpu) (cpu_topology ? cpu_topology[cpu].phys_core_id : 0)#define cpu_to_socket (cpu) (cpu_topology ? cpu_topology[cpu].phys_socket_id : 0) +#define cpu_nr_siblings (cpu) (cpu_topology ? cpu_topology[cpu].num_siblings : 1)#else /* CONFIG_GENERIC_CPU_TOPOLOGY */
@@ -57,6 +58,10 @@ static inline void init_cpu_topology(void) {}#define cpu_to_socket (cpu) (0)#endif +#ifndef cpu_nr_siblings +#define cpu_nr_siblings (cpu) (1) +#endif +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ #endif /* XEN_CPU_TOPOLOGY_H */
Signature · 1 line
2.43.0
Re: [PATCH v7 3/5] xen/sched: Make cpu_nr_siblings() architecture-specific
Quoted 6 lines · Hirokazu Takahashi
Make
cpu_nr_siblings()an architecture-specific function. This patch provides the implementation for x86 and a common version for Device Tree-based architectures.Signed-off-by Hirokazu Takahashi <[email protected]>Acked-by Jan Beulich <[email protected]>
Juergen
PATCH v7 4/5 xen/acpi: Import PPTT definitions from Linux
In reply to Hirokazu TakahashiImport the Processor Properties Topology Table (PPTT) definitions from the Linux kernel header (include/acpi/actbl2.h) into Xen.
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git b8355bcac253
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git e62f8227851d
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git 091c4af3562d
--- xen/include/acpi/actbl2.h | 113 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+)
xen/include/acpi/actbl2.h +113 -0
@@ -72,6 +72,7 @@#define ACPI_SIG_IVRS "IVRS"/* I/O Virtualization Reporting Structure */ #define ACPI_SIG_MCFG "MCFG"/* PCI Memory Mapped Configuration table */ #define ACPI_SIG_MCHI "MCHI"/* Management Controller Host Interface table */ +#define ACPI_SIG_PPTT "PPTT"/* Processor Properties Topology Table */ #define ACPI_SIG_SLIC "SLIC"/* Software Licensing Description Table */ #define ACPI_SIG_SPCR "SPCR"/* Serial Port Console Redirection table */ #define ACPI_SIG_SPMI "SPMI"/* Server Platform Management Interface table */
@@ -937,6 +938,118 @@ struct acpi_table_mchi {u8 pci_function; }; +/******************************************************************************* +* +* PPTT - Processor Properties Topology Table (ACPI 6.2) +* Version 1 +* +******************************************************************************/ + +struct acpi_table_pptt { +struct acpi_table_header header;/* Common ACPI table header */ +}; + +/* Values for Type field above */ + +enum acpi_pptt_type { +ACPI_PPTT_TYPE_PROCESSOR =0 , +ACPI_PPTT_TYPE_CACHE =1 , +ACPI_PPTT_TYPE_ID =2 , +ACPI_PPTT_TYPE_RESERVED =3 +}; + +/* 0: Processor Hierarchy Node Structure */ + +struct acpi_pptt_processor { +struct acpi_subtable_header header; +u16 reserved; +u32 flags; +u32 parent; +u32 acpi_processor_id; +u32 number_of_priv_resources; +}; + +/* Flags */ + +#define ACPI_PPTT_PHYSICAL_PACKAGE (1) +#define ACPI_PPTT_ACPI_PROCESSOR_ID_VALID (1<<1) +#define ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD (1<<2)/* ACPI 6.3 */ +#define ACPI_PPTT_ACPI_LEAF_NODE (1<<3)/* ACPI 6.3 */ +#define ACPI_PPTT_ACPI_IDENTICAL (1<<4)/* ACPI 6.3 */ + +/* 1: Cache Type Structure */ + +struct acpi_pptt_cache { +struct acpi_subtable_header header; +u16 reserved; +u32 flags; +u32 next_level_of_cache; +u32 size; +u32 number_of_sets; +u8 associativity; +u8 attributes; +u16 line_size; +}; + +/* 1: Cache Type Structure for PPTT version 3 */ + +struct acpi_pptt_cache_v1 { +struct acpi_subtable_header header; +u16 reserved; +u32 flags; +u32 next_level_of_cache; +u32 size; +u32 number_of_sets; +u8 associativity; +u8 attributes; +u16 line_size; +u32 cache_id; +}; + +/* Flags */ + +#define ACPI_PPTT_SIZE_PROPERTY_VALID (1)/* Physical property valid */ +#define ACPI_PPTT_NUMBER_OF_SETS_VALID (1<<1)/* Number of sets valid */ +#define ACPI_PPTT_ASSOCIATIVITY_VALID (1<<2)/* Associativity valid */ +#define ACPI_PPTT_ALLOCATION_TYPE_VALID (1<<3)/* Allocation type valid */ +#define ACPI_PPTT_CACHE_TYPE_VALID (1<<4)/* Cache type valid */ +#define ACPI_PPTT_WRITE_POLICY_VALID (1<<5)/* Write policy valid */ +#define ACPI_PPTT_LINE_SIZE_VALID (1<<6)/* Line size valid */ +#define ACPI_PPTT_CACHE_ID_VALID (1<<7)/* Cache ID valid */ + +/* Masks for Attributes */ + +#define ACPI_PPTT_MASK_ALLOCATION_TYPE (0x03)/* Allocation type */ +#define ACPI_PPTT_MASK_CACHE_TYPE (0x0C)/* Cache type */ +#define ACPI_PPTT_MASK_WRITE_POLICY (0x10)/* Write policy */ + +/* Attributes describing cache */ +#define ACPI_PPTT_CACHE_READ_ALLOCATE (0x0)/* Cache line is allocated on read */ +#define ACPI_PPTT_CACHE_WRITE_ALLOCATE (0x01)/* Cache line is allocated on write */ +#define ACPI_PPTT_CACHE_RW_ALLOCATE (0x02)/* Cache line is allocated on read and write */ +#define ACPI_PPTT_CACHE_RW_ALLOCATE_ALT (0x03)/* Alternate representation of above */ + +#define ACPI_PPTT_CACHE_TYPE_DATA (0x0)/* Data cache */ +#define ACPI_PPTT_CACHE_TYPE_INSTR (1<<2)/* Instruction cache */ +#define ACPI_PPTT_CACHE_TYPE_UNIFIED (2<<2)/* Unified I & D cache */ +#define ACPI_PPTT_CACHE_TYPE_UNIFIED_ALT (3<<2)/* Alternate representation of above */ + +#define ACPI_PPTT_CACHE_POLICY_WB (0x0)/* Cache is write back */ +#define ACPI_PPTT_CACHE_POLICY_WT (1<<4)/* Cache is write through */ + +/* 2: ID Structure */ + +struct acpi_pptt_id { +struct acpi_subtable_header header; +u16 reserved; +u32 vendor_id; +u64 level1_id; +u64 level2_id; +u16 major_rev; +u16 minor_rev; +u16 spin_rev; +}; +/******************************************************************************* * * SLIC - Software Licensing Description Table
Signature · 1 line
2.43.0
PATCH v7 5/5 xen/acpi: Parse PPTT to initialize CPU topology
In reply to Hirokazu TakahashiParse the ACPI PPTT (Processor Properties Topology Table) to initialize the CPU topology.
For ACPI 6.3 and later, the ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD flag is checked to determine the presence of threading. For ACPI 6.2 and earlier, CPUs are assumed not to support threading.
---
Changes in v7:
- PPTT Table Validation & Hardening:
* find_pptt_node(): Added leaf node verification (ACPI 6.3+).
* acpi_init_cpu_topology(): Added bounds checks to ensure proc->parent validly references memory strictly inside the PPTT table bounds.
* Factored out shared table checking helper functions used by both find_pptt_node() and acpi_init_cpu_topology().
* Added subtable alignment checks and strengthened processor structure size validation.
- Graceful Fallback & Allocation:
* Treated missing topology definitions as benign conditions.
* Used xvzalloc_array() for temporary memory allocations during initialization.
- Code Cleanups & Style Conformance:
* Removed redundant error checks and reduced unnecessary pointer casts.
* Switched type-based sizeof(type) to variable-based sizeof(*var).
* Added leading spaces before labels ( out:)
xen/arch/arm/acpi/boot.c | 2 + xen/arch/arm/include/asm/acpi.h | 2 + xen/drivers/acpi/topology.c | 312 ++++++++++++++++++++++++++++++-- xen/include/xen/acpi.h | 2 + 4 files changed, 305 insertions(+), 13 deletions(-)
xen/arch/arm/acpi/boot.c +2 -0
@@ -85,6 +85,7 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor)return ; } bootcpu_valid = true; +acpi_map_cpu_acpiid (0 , processor->uid);return ; }
@@ -119,6 +120,7 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor)/* map the logical cpu id to cpu MPIDR */ cpu_logical_map (enabled_cpus) = mpidr; +acpi_map_cpu_acpiid (enabled_cpus, processor->uid); enabled_cpus++; }
xen/arch/arm/include/asm/acpi.h +2 -0
@@ -61,6 +61,8 @@ paddr_t acpi_get_table_offset(struct membank tbl_add[], EFI_MEM_RES index); (!(entry) || (unsigned long )(entry) +sizeof (*(entry)) > (end) || \ (entry)->header.length != ACPI_MADT_GICC_LENGTH) +#define INVALID_ACPIID (-1U) +#ifdef CONFIG_ACPI extern bool acpi_disabled;/* Basic configuration for ACPI */
xen/drivers/acpi/topology.c +299 -13
332 lines not on this page · raw message
xen/include/xen/acpi.h +2 -0
@@ -137,10 +137,12 @@ static inline int acpi_boot_table_init(void)#ifdef CONFIG_ACPI_CPU_TOPOLOGY +void acpi_map_cpu_acpiid (unsigned int cpu,uint32_t acpi_id);int acpi_init_cpu_topology (void );#else /* CONFIG_ACPI_CPU_TOPOLOGY */ +static inline void acpi_map_cpu_acpiid (unsigned int cpu,uint32_t acpi_id) {}static inline int acpi_init_cpu_topology (void ) {return -EOPNOTSUPP ;
Signature · 1 line
2.43.0
Re: [PATCH v7 5/5] xen/acpi: Parse PPTT to initialize CPU topology
xen/arch/arm/include/asm/acpi.h paddr_t acpi_get_table_offset(struct membank tbl_add[], EFI_MEM_RES index); · line 64
Quoted 7 lines · Hirokazu Takahashi
xen/arch/arm/include/asm/acpi.h +1
-0@@ -61,6 +61,8 @@ paddr_t acpi_get_table_offset(struct membank tbl_add[], EFI_MEM_RES index); (!(entry) || (unsigned long )(entry) +sizeof (*(entry)) > (end) || \ (entry)->header.length != ACPI_MADT_GICC_LENGTH) +#define INVALID_ACPIID (-1U)
This way the constant is becoming available only on Arm, but ...
xen/drivers/acpi/topology.c line 12
Quoted 12 lines
xen/drivers/acpi/topology.c +6
-0@@ -4,33 +4,319 @@#include <xen/cpu-topology.h> #include <xen/cpumask.h> #include <xen/init.h> +#include <xen/xvmalloc.h> + +#define ACPI_PPTT_MAX_LEVELS 16 + +static uint32_t __initdata map_cpu_acpiid[NR_CPUS ] = { + [0 ...NR_CPUS -1 ] =INVALID_ACPIID
... you use it in code which (in principle) isn't Arm-specific (it only happens to be right now).
xen/drivers/acpi/topology.c line 18
Quoted 8 lines
xen/drivers/acpi/topology.c +4
-2+};/* -* TODO: Populate the topology information by scanning the ACPI -* PPTT (Processor Properties Topology Table). +* The first argument 'cpu' is the logical CPU ID assigned by Xen, +* and the second argument 'acpi_id' is passed the 'uid' field from +* the ACPI MADT Generic Interrupt subtable.
This comment also looks to be (in part) Arm-specific, which it shouldn't be here.
Quoted 19 lines
xen/drivers/acpi/topology.c +15
-2*/ -int __init acpi_init_cpu_topology (void ) +void __init acpi_map_cpu_acpiid (unsigned int cpu,uint32_t acpi_id) { -unsigned int cpu; + map_cpu_acpiid[cpu] = acpi_id; +} + +static unsigned int __init get_logical_id (unsigned int key, +unsigned int *map, +unsigned int *count) +{ +unsigned int id; + +for ( id =0 ; id < *count; id++ ) +if ( map[id] == key ) +return id; + + map[*count] = key;
xen/drivers/acpi/topology.c line 45
Quoted 10 lines
xen/drivers/acpi/topology.c +10
-0+ +return (*count)++; +} + +static bool __init verify_subtable (const struct acpi_subtable_header *entry, +const struct acpi_table_pptt *pptt) +{ +unsigned long table_end = (unsigned long )pptt + pptt->header.length; + +if ( entry->length <sizeof (*entry) || entry->length &3 )
Parentheses please around & or alike within || or alike.
xen/drivers/acpi/topology.c line 47
Quoted 2 lines
xen/drivers/acpi/topology.c +2
-0+ { +printk (XENLOG_ERR "ACPI: PPTT subtable length is invalid\n" );
Like you have it here, ...
xen/drivers/acpi/topology.c line 53
Quoted 6 lines
xen/drivers/acpi/topology.c +6
-0+return false; + } + +if ( (unsigned long )entry + entry->length > table_end ) + { +printk (XENLOG_ERR "ACPI: PPTT subtable extends beyond table end.\n" );
... no full stop please in log messages (applies elsewhere as well).
Quoted 17 lines
xen/drivers/acpi/topology.c +15
-0+return false; + } + +return true; +} + +static bool __init verify_proc (const struct acpi_pptt_processor *proc) +{ +unsigned long table_size; + +if ( proc->header.length <sizeof (*proc) ) + { +printk (XENLOG_ERR "ACPI: PPTT processor node length is too small.\n" ); +return false; + }/*
xen/drivers/acpi/topology.c line 77
Quoted 10 lines
xen/drivers/acpi/topology.c +6
-3-* Generate temporary cpu topology information for now. -* It assumes that the cpu doesn't have SMT and all CPUs -* belong to the same socket. +* Each private resource is represented by a 32-bit resource ID. +* Ensure the structure length accurately accounts for the trailing array. */ + table_size =sizeof (*proc) + + (unsigned long )proc->number_of_priv_resources *sizeof (uint32_t ); + +if ( proc->header.length != table_size )
Isn't != overly strict?
Quoted 8 lines
xen/drivers/acpi/topology.c +8
-0+ { +printk (XENLOG_ERR "ACPI: PPTT processor node length invalid.\n" ); +return false; + } + +return true; +} +
xen/drivers/acpi/topology.c line 95
Quoted 10 lines
xen/drivers/acpi/topology.c +10
-0+static const struct acpi_pptt_processor *__init find_pptt_node ( +const struct acpi_table_pptt *pptt,uint32_t acpi_id) +{ +const struct acpi_subtable_header *entry; +unsigned long table_end; +const void *ptr; + + table_end = (unsigned long )pptt + pptt->header.length; + + ptr = pptt +1 ;
Make these the initializers of their variables?
Quoted 15 lines
xen/drivers/acpi/topology.c +15
-0+while ( (unsigned long )ptr +sizeof (*entry) <= table_end ) + { + entry = ptr; + +if ( !verify_subtable (entry, pptt) ) +break ; + +if ( entry->type ==ACPI_PPTT_TYPE_PROCESSOR ) + { +const struct acpi_pptt_processor *proc; + + proc = container_of(entry, const struct acpi_pptt_processor, + header); + +if ( !verify_proc (proc) )
xen/drivers/acpi/topology.c line 121
Quoted 10 lines
xen/drivers/acpi/topology.c +10
-0+break ; + +/* +* Leaf node verification is only required for ACPI 6.3 +* (PPTT revision 2) or later. +*/ +if ( (proc->flags &ACPI_PPTT_ACPI_PROCESSOR_ID_VALID ) + && proc->acpi_processor_id == acpi_id + && (pptt->header.revision <2 + || (proc->flags &ACPI_PPTT_ACPI_LEAF_NODE )) )
Misplaced binary operators (also elsewhere). On continued lines they go at the end of the earlier line.
Quoted 51 lines
xen/drivers/acpi/topology.c +48
-0+return proc; + } + + ptr += entry->length; + } + +return NULL ; +} + +/* +* Populate the topology information by scanning the ACPI PPTT +* (Processor Properties Topology Table). +*/ +int __init acpi_init_cpu_topology (void ) +{ +acpi_status status; +struct acpi_table_header *table_header; +const struct acpi_table_pptt *pptt; +unsigned int num_sockets =0 ; +unsigned int num_clusters =0 ; +unsigned int num_cores =0 ; + unsigned int *socket_map = xvzalloc_array(unsigned int, nr_cpu_ids); + unsigned int *cluster_map = xvzalloc_array(unsigned int, nr_cpu_ids); + unsigned int *core_map = xvzalloc_array(unsigned int, nr_cpu_ids); +unsigned int cpu; +int ret =0 ; + + status =acpi_get_table (ACPI_SIG_PPTT ,0 , &table_header); +if (ACPI_FAILURE (status) ) + { +/* A missing PPTT is benign; fall back to the default topology. */ + ret = -ENODEV ; + goto out; + } + +if ( !socket_map || !cluster_map || !core_map ) + { +printk (XENLOG_ERR +"ACPI: Failed to allocate memory for topology parsing.\n" ); + ret = -ENOMEM ; + goto out; + } + + pptt = container_of(table_header, const struct acpi_table_pptt, header); +for_each_possible_cpu (cpu) { +uint32_t acpi_id = map_cpu_acpiid[cpu];struct cpu_topology *topo = &cpu_topology[cpu]; +const struct acpi_pptt_processor *proc; +unsigned int level;
xen/drivers/acpi/topology.c line 182
Quoted 10 lines
xen/drivers/acpi/topology.c +10
-0+unsigned int core_group_key =0 ; +unsigned int cluster_group_key =0 ; +unsigned int socket_group_key =0 ; +bool threading = false; + + proc =find_pptt_node (pptt, acpi_id); +if ( !proc ) + { + printk(XENLOG_WARNING + "ACPI: No PPTT leaf node for CPU %u (ACPI ID 0x%u)\n",
Please prefer the slightly shorter %#x (and definitely please don't mix a 0x prefix with %u). Again applies elsewhere as well.
Jan
RE: [PATCH v7 5/5] xen/acpi: Parse PPTT to initialize CPU topology
Hi Jan,
Quoted 10 lines
xen/arch/arm/include/asm/acpi.h paddr_t acpi_get_table_offset(struct membank tbl_add[], EFI_MEM_RES index); · line 64
Quoted 7 lines
xen/arch/arm/include/asm/acpi.h +1
-0@@ -61,6 +61,8 @@ paddr_t acpi_get_table_offset(struct membank tbl_add[], EFI_MEM_RES index); (!(entry) || (unsigned long )(entry) +sizeof (*(entry)) > (end) || \ (entry)->header.length != ACPI_MADT_GICC_LENGTH) +#define INVALID_ACPIID (-1U)This way the constant is becoming available only on Arm, but ...
Quoted 15 lines
xen/drivers/acpi/topology.c line 12
Quoted 12 lines
xen/drivers/acpi/topology.c +6
-0@@ -4,33 +4,319 @@#include <xen/cpu-topology.h> #include <xen/cpumask.h> #include <xen/init.h> +#include <xen/xvmalloc.h> + +#define ACPI_PPTT_MAX_LEVELS 16 + +static uint32_t __initdata map_cpu_acpiid[NR_CPUS ] = { + [0 ...NR_CPUS -1 ] =INVALID_ACPIID ... you use it in code which (in principle) isn't Arm-specific (it only happens to be right now).
Okay, I will move the definition in xen/acpi.h.
Quoted 9 lines
xen/drivers/acpi/topology.c line 18
Quoted 6 lines
xen/drivers/acpi/topology.c +3
-2/* -* TODO: Populate the topology information by scanning the ACPI -* PPTT (Processor Properties Topology Table). +* The first argument 'cpu' is the logical CPU ID assigned by Xen, +* and the second argument 'acpi_id' is passed the 'uid' field from +* the ACPI MADT Generic Interrupt subtable. This comment also looks to be (in part) Arm-specific, which it shouldn't be here.
Okay.
Quoted 8 lines
xen/drivers/acpi/topology.c line 45
Quoted 6 lines
xen/drivers/acpi/topology.c +6
-0+static bool __init verify_subtable (const struct acpi_subtable_header *entry, +const struct acpi_table_pptt *pptt) +{ +unsigned long table_end = (unsigned long )pptt + pptt->header.length; + +if ( entry->length <sizeof (*entry) || entry->length &3 )Parentheses please around & or alike within || or alike.
Okay.
Quoted 5 lines
xen/drivers/acpi/topology.c line 24
Quoted 2 lines
xen/drivers/acpi/topology.c +2
-0+ { +printk (XENLOG_ERR "ACPI: PPTT subtable length is invalid\n" );Like you have it here, ...
Quoted 8 lines
xen/drivers/acpi/topology.c line 53
Quoted 6 lines
xen/drivers/acpi/topology.c +6
-0+return false; + } + +if ( (unsigned long )entry + entry->length > table_end ) + { +printk (XENLOG_ERR "ACPI: PPTT subtable extends beyond table end.\n" );... no full stop please in log messages (applies elsewhere as well).
Okay.
Quoted 10 lines
Quoted 10 lines
xen/drivers/acpi/topology.c +9
-0+static bool __init verify_proc (const struct acpi_pptt_processor *proc) +{ +unsigned long table_size; + +if ( proc->header.length <sizeof (*proc) ) + { +printk (XENLOG_ERR "ACPI: PPTT processor node length is too small.\n" ); +return false; + }
Quoted 13 lines
xen/drivers/acpi/topology.c line 77
Quoted 11 lines
xen/drivers/acpi/topology.c +6
-3/* -* Generate temporary cpu topology information for now. -* It assumes that the cpu doesn't have SMT and all CPUs -* belong to the same socket. +* Each private resource is represented by a 32-bit resource ID. +* Ensure the structure length accurately accounts for the trailing array. */ + table_size =sizeof (*proc) + + (unsigned long )proc->number_of_priv_resources *sizeof (uint32_t ); + +if ( proc->header.length != table_size )Isn't != overly strict?
I will replace it with "if ( proc->header.length < table_size )."
Quoted 4 lines
Quoted 4 lines
xen/drivers/acpi/topology.c +4
-0+static const struct acpi_pptt_processor *__init find_pptt_node ( +const struct acpi_table_pptt *pptt,uint32_t acpi_id) +{ +const struct acpi_subtable_header *entry;
Quoted 8 lines
xen/drivers/acpi/topology.c line 95
Quoted 6 lines
xen/drivers/acpi/topology.c +6
-0+unsigned long table_end; +const void *ptr; + + table_end = (unsigned long )pptt + pptt->header.length; + + ptr = pptt +1 ;Make these the initializers of their variables?
Okay.
Quoted 7 lines
xen/drivers/acpi/topology.c line 121
Quoted 4 lines
xen/drivers/acpi/topology.c +4
-0+if ( (proc->flags &ACPI_PPTT_ACPI_PROCESSOR_ID_VALID ) + && proc->acpi_processor_id == acpi_id + && (pptt->header.revision <2 + || (proc->flags &ACPI_PPTT_ACPI_LEAF_NODE )) )Misplaced binary operators (also elsewhere). On continued lines they go at the end of the earlier line.
Okay.
Quoted 8 lines
xen/drivers/acpi/topology.c line 182
Quoted 5 lines
xen/drivers/acpi/topology.c +5
-0+ proc =find_pptt_node (pptt, acpi_id); +if ( !proc ) + { + printk(XENLOG_WARNING + "ACPI: No PPTT leaf node for CPU %u (ACPI ID 0x%u)\n",Please prefer the slightly shorter %#x (and definitely please don't mix a 0x prefix with %u). Again applies elsewhere as well.
Okay.
Thank you,
Hirokazu Takahashi.