[PATCH] x86/topology: Add missing declarations and attribute dependencies

Ricardo Neri posted 1 patch 2 months, 3 weeks ago
arch/x86/include/asm/topology.h | 3 +++
1 file changed, 3 insertions(+)
[PATCH] x86/topology: Add missing declarations and attribute dependencies
Posted by Ricardo Neri 2 months, 3 weeks ago
The prototypes for get_topology_cpu_type_name() and
get_topology_cpu_type() take a pointer to struct cpuinfo_x86, but
asm/topology.h does not include nor forward-declares the structure. A
translation unit that includes asm/topology.h, directly or indirectly,
without including asm/processor.h triggers a warning:

     ./arch/x86/include/asm/topology.h:159:47: error: ‘struct cpuinfo_x86’
     declared inside parameter list will not be visible outside of this
     definition or declaration [-Werror]
     159 | const char *get_topology_cpu_type_name(struct cpuinfo_x86 *c);
         |                                               ^~~~~~~~~~~

Since only a pointer is needed and no structure members are accessed,
add a forward declaration of struct cpuinfo_x86.

Similarly, sysctl_sched_itmt_enabled is declared in asm/topology.h with
the __read_mostly attribute, but the header does not include linux/cache.h.
This causes a build failure when a file includes asm/topology.h without
including linux/cache.h:

     ./arch/x86/include/asm/topology.h:264:27: error: expected ‘=’, ‘,’,
      ‘;’, ‘asm’ or ‘__attribute__’ before ‘sysctl_sched_itmt_enabled’
     264 | extern bool __read_mostly sysctl_sched_itmt_enabled;
         |                           ^~~~~~~~~~~~~~~~~~~~~~~~~

Include the needed header.

Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
I found this issue while working on a patchset for Hyper-V support [1]. In
that case, the file arch/x86/hyperv/hv_vtl.c would now include asm/acpi.h,
which implicitly includes asm/topology.h but not asm/processor.h nor linux/
cache.h.

[1]. https://lore.kernel.org/r/20251117-rneri-wakeup-mailbox-v7-0-4a8b82ab7c2c@linux.intel.com
---
 arch/x86/include/asm/topology.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index 1fadf0cf520c..630521a03982 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -156,6 +156,8 @@ extern unsigned int __max_threads_per_core;
 extern unsigned int __num_threads_per_package;
 extern unsigned int __num_cores_per_package;
 
+struct cpuinfo_x86;
+
 const char *get_topology_cpu_type_name(struct cpuinfo_x86 *c);
 enum x86_topology_cpu_type get_topology_cpu_type(struct cpuinfo_x86 *c);
 
@@ -259,6 +261,7 @@ extern bool x86_topology_update;
 
 #ifdef CONFIG_SCHED_MC_PRIO
 #include <asm/percpu.h>
+#include <linux/cache.h>
 
 DECLARE_PER_CPU_READ_MOSTLY(int, sched_core_priority);
 extern bool __read_mostly sysctl_sched_itmt_enabled;

---
base-commit: 6f85aad74a70d17919a64ecd93037aa51c08698d
change-id: 20251115-rneri-topology-cpuinfo-bug-7044934968d1

Best regards,
-- 
Ricardo Neri <ricardo.neri-calderon@linux.intel.com>

Re: [PATCH] x86/topology: Add missing declarations and attribute dependencies
Posted by Ricardo Neri 3 weeks, 1 day ago
On Mon, Nov 17, 2025 at 08:50:50PM -0800, Ricardo Neri wrote:
> The prototypes for get_topology_cpu_type_name() and
> get_topology_cpu_type() take a pointer to struct cpuinfo_x86, but
> asm/topology.h does not include nor forward-declares the structure. A
> translation unit that includes asm/topology.h, directly or indirectly,
> without including asm/processor.h triggers a warning:
> 
>      ./arch/x86/include/asm/topology.h:159:47: error: ‘struct cpuinfo_x86’
>      declared inside parameter list will not be visible outside of this
>      definition or declaration [-Werror]
>      159 | const char *get_topology_cpu_type_name(struct cpuinfo_x86 *c);
>          |                                               ^~~~~~~~~~~
> 
> Since only a pointer is needed and no structure members are accessed,
> add a forward declaration of struct cpuinfo_x86.
> 
> Similarly, sysctl_sched_itmt_enabled is declared in asm/topology.h with
> the __read_mostly attribute, but the header does not include linux/cache.h.
> This causes a build failure when a file includes asm/topology.h without
> including linux/cache.h:
> 
>      ./arch/x86/include/asm/topology.h:264:27: error: expected ‘=’, ‘,’,
>       ‘;’, ‘asm’ or ‘__attribute__’ before ‘sysctl_sched_itmt_enabled’
>      264 | extern bool __read_mostly sysctl_sched_itmt_enabled;
>          |                           ^~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Include the needed header.
> 
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> ---
> I found this issue while working on a patchset for Hyper-V support [1]. In
> that case, the file arch/x86/hyperv/hv_vtl.c would now include asm/acpi.h,
> which implicitly includes asm/topology.h but not asm/processor.h nor linux/
> cache.h.
> 
> [1]. https://lore.kernel.org/r/20251117-rneri-wakeup-mailbox-v7-0-4a8b82ab7c2c@linux.intel.com

Hi,

I incorporated this patch in a new version of my patchset to use the ACPI
mailbox with Device-Tree based firmware. It can be found here:

https://lore.kernel.org/r/20260107-rneri-wakeup-mailbox-v8-0-2f5b6785f2f5@linux.intel.com

Thanks and BR,
Ricardo