x86/topology: Add support for Low Power cpu_type
Subsystems (6)
cover x86/topology: Add support for Low Power cpu_type
This series extends the x86 topology cpu_type classification to support a Low Power core type, in addition to the existing Performance and Efficiency types.
AMD heterogeneous parts report the core type via CPUID Fn0x80000026 EBX[31:28] (Extended CPU Topology, Core Type). Value 2 identifies a low-power core designed for minimal power consumption during background or idle workloads. Distinguishing it from a regular efficiency core matters for:
- user space exposure via /sys/kernel/debug/x86/topo/cpus/*, which today reports cpu_type "unknown" for low-power cores
- amd_get_boost_ratio_numerator(): on every X86_FEATURE_AMD_HTR_CORES-capable AMD/Hygon part, low-power cores must scale by amd_get_highest_perf() rather than the fixed CPPC_HIGHEST_PERF_PERFORMANCE ceiling, matching the existing efficiency-core path
The series is structured as:
1/2 Pre-patch: replace the bare 0/1 in get_topology_cpu_type() with
named enum amd_cpu_type constants, mirroring the existing Intel side. No functional change.
2/2 Add TOPO_CPU_TYPE_LOW_POWER, wire it through
get_topology_cpu_type(), get_topology_cpu_type_name() and the switch in amd_get_boost_ratio_numerator() so allmodconfig builds cleanly under -Werror=switch.
Vishal Badole (2):
x86/topology: Name the AMD core-type values
x86/topology: Add TOPO_CPU_TYPE_LOW_POWER
arch/x86/include/asm/topology.h | 7 +++++++ arch/x86/kernel/acpi/cppc.c | 3 ++- arch/x86/kernel/cpu/topology_common.c | 7 +++++-- 3 files changed, 14 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 x86/topology: Name the AMD core-type values
Replace the bare 0/1 in get_topology_cpu_type() with named constants that mirror what the AMD APM publishes for CPUID Fn0x80000026 EBX[31:28] (Extended CPU Topology, Core Type):
0 - Performance core
1 - Efficient core
2 - Low-power core (used by a follow-up)
No functional change.
--- arch/x86/include/asm/topology.h | 6 ++++++ arch/x86/kernel/cpu/topology_common.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
arch/x86/include/asm/topology.h +6 -0
@@ -120,6 +120,12 @@ enum x86_topology_cpu_type { TOPO_CPU_TYPE_UNKNOWN, }; +enum amd_cpu_type { +AMD_CPU_TYPE_PERFORMANCE =0 , +AMD_CPU_TYPE_EFFICIENCY =1 , +AMD_CPU_TYPE_LOW_POWER =2 , +}; +struct x86_topology_system {unsigned int dom_shifts[TOPO_MAX_DOMAIN ];unsigned int dom_size[TOPO_MAX_DOMAIN ];
arch/x86/kernel/cpu/topology_common.c +2 -2
@@ -42,8 +42,8 @@ enum x86_topology_cpu_type get_topology_cpu_type(struct cpuinfo_x86 *c) }if (c->x86_vendor ==X86_VENDOR_AMD ) {switch (c->topo.amd_type) { -case 0 :return TOPO_CPU_TYPE_PERFORMANCE ; -case 1 :return TOPO_CPU_TYPE_EFFICIENCY ; +case AMD_CPU_TYPE_PERFORMANCE :return TOPO_CPU_TYPE_PERFORMANCE ; +case AMD_CPU_TYPE_EFFICIENCY :return TOPO_CPU_TYPE_EFFICIENCY ; } }
Signature · 1 line
2.34.1
Borislav Petkov
maintainerRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 22 lines · Vishal Badole
Replace the bare 0/1 in
get_topology_cpu_type()with named constants that mirror what the AMD APM publishes for CPUID Fn0x80000026 EBX[31:28] (Extended CPU Topology, Core Type):0 - Performance core
1 - Efficient core
2 - Low-power core (used by a follow-up)No functional change.
Suggested-by Borislav Petkov (AMD) <[email protected]>Signed-off-by Vishal Badole <[email protected]>--- arch/x86/include/asm/topology.h | 6 ++++++ arch/x86/kernel/cpu/topology_common.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)arch/x86/include/asm/topology.h +0
-0
arch/x86/include/asm/topology.h enum x86_topology_cpu_type { · line 124
Quoted 5 lines
arch/x86/include/asm/topology.h +2
-0@@ -120,6 +120,12 @@ enum x86_topology_cpu_type { TOPO_CPU_TYPE_UNKNOWN, }; +enum amd_cpu_type { +AMD_CPU_TYPE_PERFORMANCE =0 ,
Sashiko says here:
---
Will this break CPU matching if a driver attempts to target only AMD performance cores?
The x86_cpu_id matching infrastructure treats 0 as the X86_CPU_TYPE_ANY wildcard. If a developer uses AMD_CPU_TYPE_PERFORMANCE (which evaluates to 0) in an x86_cpu_id match table, the infrastructure will interpret it as a wildcard:
arch/x86/kernel/cpu/match.c:x86_match_vendor_cpu_type() {
...
if (m->type == X86_CPU_TYPE_ANY)
return true;
...
}
Could this cause drivers to silently bind to all AMD core types, including efficiency and low-power cores, instead of just the performance cores?
---
see https://sashiko.dev/#/patchset/20260629094349.533301-1-Vishal.Badole%40amd.com
And it does make sense to me - x86_match_vendor_cpu_type() is supposed to receive the *hardware* defined CPU type - not the generic ones. And I think that was a mistake because the value 0 on AMD means a performance core type but in the kernel we called it X86_CPU_TYPE_ANY. Which is also not surprising
- all our ANY types are 0.
Now, one fix would be if we define X86_CPU_TYPE_ANY as 0xff and hope that Intel will never define it.
On AMD that value is guaranteed to be invalid because the core type field is only 4 bits.
But it can happen that one vendor's core type field can match another core type of the other vendor. Which would mean that we cannot use X86_VENDOR_ANY in any of the match_id tables when using a core type.
Or, we do the proper fix and we map all vendor core types to the kernel's, vendor-agnostic TOPO_CPU_TYPE_* enums and then we're all good - we'd only need to convert the vendor ones to the generic ones on comparison but we do that anyway.
Thoughts?
Quoted 25 lines
arch/x86/include/asm/topology.h +4
-0+AMD_CPU_TYPE_EFFICIENCY =1 , + AMD_CPU_TYPE_LOW_POWER = 2, +}; +struct x86_topology_system {unsigned int dom_shifts[TOPO_MAX_DOMAIN ];unsigned int dom_size[TOPO_MAX_DOMAIN ];arch/x86/kernel/cpu/topology_common.c +2
-2@@ -42,8 +42,8 @@ enum x86_topology_cpu_type get_topology_cpu_type(struct cpuinfo_x86 *c) }if (c->x86_vendor ==X86_VENDOR_AMD ) {switch (c->topo.amd_type) { -case 0 :return TOPO_CPU_TYPE_PERFORMANCE ; -case 1 :return TOPO_CPU_TYPE_EFFICIENCY ; +case AMD_CPU_TYPE_PERFORMANCE :return TOPO_CPU_TYPE_PERFORMANCE ; +case AMD_CPU_TYPE_EFFICIENCY :return TOPO_CPU_TYPE_EFFICIENCY ; } }Signature · 1 line
2.34.1
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteThomas Gleixner
maintainerRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 13 lines · Borislav Petkov
On Mon, Jun 29, 2026 at 03:13:48PM +0530, Vishal Badole wrote:
And it does make sense to me -x86_match_vendor_cpu_type()is supposed to receive the *hardware* defined CPU type - not the generic ones. And I think that was a mistake because the value 0 on AMD means a performance core type but in the kernel we called itX86_CPU_TYPE_ANY. Which is also not surprising
- all our ANY types are 0.Now, one fix would be if we define
X86_CPU_TYPE_ANYas0xffand hope that Intel will never define it.On AMD that value is guaranteed to be invalid because the core type field is only 4 bits.
Quoted 8 lines
But it can happen that one vendor's core type field can match another core type of the other vendor. Which would mean that we cannot use
X86_VENDOR_ANYin any of thematch_idtables when using a core type.Or, we do the proper fix and we map all vendor core types to the kernel's, vendor-agnostic TOPO_CPU_TYPE_* enums and then we're all good - we'd only need to convert the vendor ones to the generic ones on comparison but we do that anyway.
Just do the mapping to vendor-agnostic types _once_ when you enumerate the CPU and store that information in the per CPU data.
Then you can do proper vendor agnostic matching against that and define the TYPE_ANY value as you want without ever colliding with vendor muck.
As a bonus get_topology_cpu_type() goes away too as the translation has been done already.
Thanks,
tglx
Borislav Petkov
maintainerRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 9 lines · Thomas Gleixner
Just do the mapping to vendor-agnostic types _once_ when you enumerate the CPU and store that information in the per CPU data.
Then you can do proper vendor agnostic matching against that and define the
TYPE_ANYvalue as you want without ever colliding with vendor muck.As a bonus
get_topology_cpu_type()goes away too as the translation has been done already.
Yeah, we should've done it from the very beginning this way. Lemme hack it up and see how it looks like.
Thanks for the cool idea.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
+ Dave and Pawan.
Quoted 8 lines · Borislav Petkov
Quoted 7 lines · Thomas Gleixner
Just do the mapping to vendor-agnostic types _once_ when you enumerate the CPU and store that information in the per CPU data.
Then you can do proper vendor agnostic matching against that and define the
TYPE_ANYvalue as you want without ever colliding with vendor muck.
Quoted 7 lines
Quoted 2 lines
As a bonus
get_topology_cpu_type()goes away too as the translation has been done already.Yeah, we should've done it from the very beginning this way. Lemme hack it up and see how it looks like.
Thanks for the cool idea.
Something like the totally untested below - but it builds at least.
We've allocated a u8 for the struct x86_cpu_id member type and we compare that to enum x86_topology_cpu_type cpu_type. I guess that's ok for now...
There's potential for more cleanup by removing the ->intel_type and ->amd_type and converting them all to our internal represenation of CPU_TYPE but that's for later and other patches anyway.
Thoughts?
arch/x86/include/asm/processor.h +14 -4
@@ -68,9 +68,13 @@ extern u16 __read_mostly tlb_lld_2m;extern u16 __read_mostly tlb_lld_4m;extern u16 __read_mostly tlb_lld_1g; -/* -* CPU type and hardware bug flags. Kept separately for each CPU. -*/ +enum x86_topology_cpu_type { +/* X86_CPU_TYPE_ANY */ +TOPO_CPU_TYPE_ANY =0 , +TOPO_CPU_TYPE_PERFORMANCE , +TOPO_CPU_TYPE_EFFICIENCY , +TOPO_CPU_TYPE_UNKNOWN , +};struct cpuinfo_topology {// Real APIC ID read from the local APIC
@@ -104,7 +108,7 @@ struct cpuinfo_topology {// Hardware defined CPU-type union { -u32 cpu_type; +u32 hw_cpu_type;struct {// CPUID.1A.EAX[23-0] u32 intel_native_model_id :24 ;
@@ -119,8 +123,14 @@ struct cpuinfo_topology { amd_type :4 ; }; }; + +// Linux vendor-agnostic CPU type +enum x86_topology_cpu_type cpu_type; }; +/* +* CPU type and hardware bug flags. Kept separately for each CPU. +*/ struct cpuinfo_x86 { union { /*
arch/x86/include/asm/topology.h +0 -7
@@ -114,12 +114,6 @@ enum x86_topology_domains { TOPO_MAX_DOMAIN, }; -enum x86_topology_cpu_type { -TOPO_CPU_TYPE_PERFORMANCE , -TOPO_CPU_TYPE_EFFICIENCY , -TOPO_CPU_TYPE_UNKNOWN , -}; -struct x86_topology_system {unsigned int dom_shifts[TOPO_MAX_DOMAIN ];unsigned int dom_size[TOPO_MAX_DOMAIN ];
@@ -160,7 +154,6 @@ extern unsigned int __num_nodes_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);static inline unsigned int topology_max_packages (void ) {
arch/x86/kernel/acpi/cppc.c +2 -2
@@ -241,7 +241,6 @@ EXPORT_SYMBOL_GPL(amd_detect_prefcore);*/ int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) { -enum x86_topology_cpu_type core_type =get_topology_cpu_type (&cpu_data (cpu));bool prefcore;int ret;u32 tmp;
@@ -273,8 +272,9 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)/* detect if running on heterogeneous design */ if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { -switch (core_type) { +switch (cpu_data (cpu).topo.cpu_type) {case TOPO_CPU_TYPE_UNKNOWN : +case TOPO_CPU_TYPE_ANY :pr_warn ("Undefined core type found for cpu %d\n" , cpu);break ;case TOPO_CPU_TYPE_PERFORMANCE :
arch/x86/kernel/cpu/match.c +1 -29
@@ -5,34 +5,6 @@#include <linux/export.h> #include <linux/slab.h> -/** -* x86_match_vendor_cpu_type - helper function to match the hardware defined -* cpu-type for a single entry in the x86_cpu_id -* table. Note, this function does not match the -* generic cpu-types TOPO_CPU_TYPE_EFFICIENCY and -* TOPO_CPU_TYPE_PERFORMANCE. -* @c: Pointer to the cpuinfo_x86 structure of the CPU to match. -* @m: Pointer to the x86_cpu_id entry to match against. -* -* Return: true if the cpu-type matches, false otherwise. -*/ -static bool x86_match_vendor_cpu_type (struct cpuinfo_x86 *c,const struct x86_cpu_id *m) -{ -if (m->type ==X86_CPU_TYPE_ANY ) -return true; - -/* Hybrid CPUs are special, they are assumed to match all cpu-types */ -if (cpu_feature_enabled (X86_FEATURE_HYBRID_CPU )) -return true; - -if (c->x86_vendor ==X86_VENDOR_INTEL ) -return m->type == c->topo.intel_type; -if (c->x86_vendor ==X86_VENDOR_AMD ) -return m->type == c->topo.amd_type; - -return false; -} -/** * x86_match_cpu - match current CPU against an array of x86_cpu_ids * @match: Pointer to array of x86_cpu_ids. Last entry terminated with
@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)continue ;return m; }
arch/x86/kernel/cpu/topology.h +1 -0
@@ -22,6 +22,7 @@ void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,bool cpu_parse_topology_ext (struct topo_scan *tscan);void cpu_parse_topology_amd (struct topo_scan *tscan);void cpu_topology_fixup_amd (struct topo_scan *tscan); +enum x86_topology_cpu_type get_topology_cpu_type (struct cpuinfo_x86 *c);static inline u32 topo_shift_apicid (u32 apicid,enum x86_topology_domains dom) {
arch/x86/kernel/cpu/topology_amd.c +4 -2
@@ -177,8 +177,10 @@ static void topoext_fixup(struct topo_scan *tscan)static void parse_topology_amd (struct topo_scan *tscan) { -if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) - tscan->c->topo.cpu_type =cpuid_ebx (0x80000026 ); +if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { + tscan->c->topo.hw_cpu_type =cpuid_ebx (0x80000026 ); + tscan->c->topo.cpu_type =get_topology_cpu_type (tscan->c); + }/* * Try to get SMT, CORE, TILE, and DIE shifts from extended
arch/x86/kernel/cpu/topology_common.c +6 -2
@@ -168,8 +168,12 @@ static void parse_topology(struct topo_scan *tscan, bool early)case X86_VENDOR_INTEL :if (!IS_ENABLED (CONFIG_CPU_SUP_INTEL ) || !cpu_parse_topology_ext (tscan))parse_legacy (tscan); -if (c->cpuid_level >=0x1a ) - c->topo.cpu_type =cpuid_eax (0x1a ); + +if (c->cpuid_level >=0x1a ) { + c->topo.hw_cpu_type =cpuid_eax (0x1a ); + c->topo.cpu_type =get_topology_cpu_type (c); + } +break ; } }
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteThomas Gleixner
maintainerRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 10 lines · Borislav Petkov
Something like the totally untested below - but it builds at least.
We've allocated a u8 for the struct
x86_cpu_idmember type and we compare that to enumx86_topology_cpu_typecpu_type. I guess that's ok for now...There's potential for more cleanup by removing the ->intel_type and ->amd_type and converting them all to our internal represenation of
CPU_TYPEbut that's for later and other patches anyway.Thoughts?
Looks reasonable to me and should avoid all the nonsense you had to work around before.
Re: [PATCH 1/2] x86/topology: Name the AMD core-type values
In reply to Borislav PetkovQuoted 61 lines · Borislav Petkov
+ Dave and Pawan.
Quoted 8 lines · Borislav Petkov
Quoted 7 lines · Thomas Gleixner
Just do the mapping to vendor-agnostic types _once_ when you enumerate the CPU and store that information in the per CPU data.
Then you can do proper vendor agnostic matching against that and define the
TYPE_ANYvalue as you want without ever colliding with vendor muck.Quoted 7 lines
Quoted 2 lines
As a bonus
get_topology_cpu_type()goes away too as the translation has been done already.Yeah, we should've done it from the very beginning this way. Lemme hack it up and see how it looks like.
Thanks for the cool idea.
Something like the totally untested below - but it builds at least.
We've allocated a u8 for the struct
x86_cpu_idmember type and we compare that to enumx86_topology_cpu_typecpu_type. I guess that's ok for now...There's potential for more cleanup by removing the ->intel_type and ->amd_type and converting them all to our internal represenation of
CPU_TYPEbut that's for later and other patches anyway.Thoughts?
arch/x86/include/asm/processor.h +8
-4@@ -68,9 +68,13 @@ extern u16 __read_mostly tlb_lld_2m;extern u16 __read_mostly tlb_lld_4m;extern u16 __read_mostly tlb_lld_1g; -/* -* CPU type and hardware bug flags. Kept separately for each CPU. -*/ +enum x86_topology_cpu_type { +/* X86_CPU_TYPE_ANY */ +TOPO_CPU_TYPE_ANY =0 , +TOPO_CPU_TYPE_PERFORMANCE , +TOPO_CPU_TYPE_EFFICIENCY , +TOPO_CPU_TYPE_UNKNOWN , +};struct cpuinfo_topology {// Real APIC ID read from the local APIC @@ -104,7 +108,7 @@ struct cpuinfo_topology {// Hardware defined CPU-type union { -u32 cpu_type; +u32 hw_cpu_type;struct {// CPUID.1A.EAX[23-0] u32 intel_native_model_id :24 ;
arch/x86/include/asm/processor.h struct cpuinfo_topology { · line 128
Quoted 6 lines
arch/x86/include/asm/processor.h +3
-0@@ -119,8 +123,14 @@ struct cpuinfo_topology { amd_type :4 ; }; }; + +// Linux vendor-agnostic CPU type +enum x86_topology_cpu_type cpu_type;
This looks good to me. However, we need to take care of some special cases like ...
Quoted 96 lines
arch/x86/include/asm/processor.h +3
-0}; +/* +* CPU type and hardware bug flags. Kept separately for each CPU. +*/ struct cpuinfo_x86 { union { /*arch/x86/include/asm/topology.h +0
-7@@ -114,12 +114,6 @@ enum x86_topology_domains { TOPO_MAX_DOMAIN, }; -enum x86_topology_cpu_type { -TOPO_CPU_TYPE_PERFORMANCE , -TOPO_CPU_TYPE_EFFICIENCY , -TOPO_CPU_TYPE_UNKNOWN , -}; -struct x86_topology_system {unsigned int dom_shifts[TOPO_MAX_DOMAIN ];unsigned int dom_size[TOPO_MAX_DOMAIN ];@@ -160,7 +154,6 @@ extern unsigned int __num_nodes_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);static inline unsigned int topology_max_packages (void ) {arch/x86/kernel/acpi/cppc.c +2
-2@@ -241,7 +241,6 @@ EXPORT_SYMBOL_GPL(amd_detect_prefcore);*/ int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) { -enum x86_topology_cpu_type core_type =get_topology_cpu_type (&cpu_data (cpu));bool prefcore;int ret;u32 tmp;@@ -273,8 +272,9 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)/* detect if running on heterogeneous design */ if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { -switch (core_type) { +switch (cpu_data (cpu).topo.cpu_type) {case TOPO_CPU_TYPE_UNKNOWN : +case TOPO_CPU_TYPE_ANY :pr_warn ("Undefined core type found for cpu %d\n" , cpu);break ;case TOPO_CPU_TYPE_PERFORMANCE :arch/x86/kernel/cpu/match.c +0
-28@@ -5,34 +5,6 @@#include <linux/export.h> #include <linux/slab.h> -/** -* x86_match_vendor_cpu_type - helper function to match the hardware defined -* cpu-type for a single entry in the x86_cpu_id -* table. Note, this function does not match the -* generic cpu-types TOPO_CPU_TYPE_EFFICIENCY and -* TOPO_CPU_TYPE_PERFORMANCE. -* @c: Pointer to the cpuinfo_x86 structure of the CPU to match. -* @m: Pointer to the x86_cpu_id entry to match against. -* -* Return: true if the cpu-type matches, false otherwise. -*/ -static bool x86_match_vendor_cpu_type (struct cpuinfo_x86 *c,const struct x86_cpu_id *m) -{ -if (m->type ==X86_CPU_TYPE_ANY ) -return true; - -/* Hybrid CPUs are special, they are assumed to match all cpu-types */ -if (cpu_feature_enabled (X86_FEATURE_HYBRID_CPU )) -return true; - -if (c->x86_vendor ==X86_VENDOR_INTEL ) -return m->type == c->topo.intel_type; -if (c->x86_vendor ==X86_VENDOR_AMD ) -return m->type == c->topo.amd_type; - -return false; -} -/** * x86_match_cpu - match current CPU against an array of x86_cpu_ids * @match: Pointer to array of x86_cpu_ids. Last entry terminated with
arch/x86/kernel/cpu/match.c const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · line 56
Quoted 5 lines
arch/x86/kernel/cpu/match.c +1
-1@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)
... matching a hybrid CPU to any cpu_type.
Also, I think now cpu_vuln_blacklist[] needs TOPO_CPU_TYPE_EFFICIENCY instead of ATOM.
VULNBL_INTEL_TYPE(INTEL_ALDERLAKE, ATOM, RFDS | VMSCAPE), VULNBL_INTEL_STEPS(INTEL_ALDERLAKE, X86_STEP_MAX, VMSCAPE), VULNBL_INTEL_STEPS(INTEL_ALDERLAKE_L, X86_STEP_MAX, RFDS | VMSCAPE), VULNBL_INTEL_TYPE(INTEL_RAPTORLAKE, ATOM, RFDS | VMSCAPE),
Borislav Petkov
maintainerRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 11 lines · Pawan Gupta
arch/x86/kernel/cpu/match.c const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · line 56
Quoted 9 lines
/**
*x86_match_cpu- match current CPU against an array ofx86_cpu_ids
* @match: Pointer to array ofx86_cpu_ids. Last entry terminated witharch/x86/kernel/cpu/match.c +1
-1@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)... matching a hybrid CPU to any
cpu_type.
I don't know what you mean here.
enum x86_topology_cpu_type {
/* X86_CPU_TYPE_ANY */
TOPO_CPU_TYPE_ANY = 0,
TOPO_CPU_TYPE_PERFORMANCE,
TOPO_CPU_TYPE_EFFICIENCY,
TOPO_CPU_TYPE_UNKNOWN,
};
These are the Linux-specific CPU types and all vendor CPU types will be mapped to them. I hope 255 are enough.
Quoted 7 lines
Also, I think now cpu_vuln_blacklist[] needs
TOPO_CPU_TYPE_EFFICIENCYinstead of ATOM.VULNBL_INTEL_TYPE(INTEL_ALDERLAKE, ATOM, RFDS | VMSCAPE), VULNBL_INTEL_STEPS(INTEL_ALDERLAKE, X86_STEP_MAX, VMSCAPE), VULNBL_INTEL_STEPS(INTEL_ALDERLAKE_L, X86_STEP_MAX, RFDS | VMSCAPE), VULNBL_INTEL_TYPE(INTEL_RAPTORLAKE, ATOM, RFDS | VMSCAPE),
Ack, right, ATOM == EFFICIENCY in Intel-speak, so I'd need to convert those.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 13 lines · Borislav Petkov
Quoted 11 lines · Pawan Gupta
arch/x86/kernel/cpu/match.c const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · line 56
Quoted 9 lines
/**
*x86_match_cpu- match current CPU against an array ofx86_cpu_ids
* @match: Pointer to array ofx86_cpu_ids. Last entry terminated witharch/x86/kernel/cpu/match.c +1
-1@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)... matching a hybrid CPU to any
cpu_type.
Quoted 1 line
I don't know what you mean here.
Vulnerability enumeration is done on the BSP, for a hybrid system with BSP as a performance-core, a vulnerability that only affects efficiency-cores would not be enumerated. So, x86_match_cpu() currently returns a match for any cpu-type on a hybrid system.
Quoted 10 lines
enum x86_topology_cpu_type { /* X86_CPU_TYPE_ANY */ TOPO_CPU_TYPE_ANY = 0, TOPO_CPU_TYPE_PERFORMANCE, TOPO_CPU_TYPE_EFFICIENCY, TOPO_CPU_TYPE_UNKNOWN, };These are the Linux-specific CPU types and all vendor CPU types will be mapped to them. I hope 255 are enough.
255 should be more than enough, but it doesn't take resolve the problem of matching a hybrid CPU to any cpu_type.
Apart from struct cpuinfo_x86 for each CPU, we have separate boot_cpu_data for BSP. One possible solution is to set cpu_type to TOPO_CPU_TYPE_ANY in BSP specific struct for hybrid systems.
For more accurate matching, x86_topology_cpu_type could be a u32 with bit-fields for each CPU type. And boot_cpu_data can have:
boot_cpu_data.topo.cpu_type = (TOPO_CPU_TYPE_PERFORMANCE | TOPO_CPU_TYPE_EFFICIENCY | ...)
on a hybrid system. Problem with this approach is, unless secondary CPUs are brought up, BSP will not know what all cpu-types are present in the system. Also with bit-fields, possible cpu-types are further limited.
To circumvent this problem, current implementation matches a hybrid CPU with any cpu_type.
Quoted 17 lines
Quoted 7 lines
Also, I think now cpu_vuln_blacklist[] needs
TOPO_CPU_TYPE_EFFICIENCYinstead of ATOM.VULNBL_INTEL_TYPE(INTEL_ALDERLAKE, ATOM, RFDS | VMSCAPE), VULNBL_INTEL_STEPS(INTEL_ALDERLAKE, X86_STEP_MAX, VMSCAPE), VULNBL_INTEL_STEPS(INTEL_ALDERLAKE_L, X86_STEP_MAX, RFDS | VMSCAPE), VULNBL_INTEL_TYPE(INTEL_RAPTORLAKE, ATOM, RFDS | VMSCAPE),Ack, right, ATOM == EFFICIENCY in Intel-speak, so I'd need to convert those.
Thx.
Signature · 4 lines
Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Thomas Gleixner
maintainerRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 14 lines · Pawan Gupta
Quoted 13 lines · Borislav Petkov
Quoted 11 lines · Pawan Gupta
arch/x86/kernel/cpu/match.c const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · line 56
Quoted 9 lines
/**
*x86_match_cpu- match current CPU against an array ofx86_cpu_ids
* @match: Pointer to array ofx86_cpu_ids. Last entry terminated witharch/x86/kernel/cpu/match.c +1
-1@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)... matching a hybrid CPU to any
cpu_type.
Quoted 6 lines
Quoted 1 line
I don't know what you mean here.
Vulnerability enumeration is done on the BSP, for a hybrid system with BSP as a performance-core, a vulnerability that only affects efficiency-cores would not be enumerated. So,
x86_match_cpu()currently returns a match for any cpu-type on a hybrid system.
Abusing the type, which enumerates performance properties, for vulnerability crystal ball logic is simply broken.
The type is a per CPU property and has nothing to do with hybrid or not. Hybrid is a packet property.
Just because it is convenient does not make it more correct. If you need to enable mitigations on hybrid systems, then explicitely check for the hybrid property.
Thanks,
tglx
Re: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 25 lines · Thomas Gleixner
Quoted 14 lines · Pawan Gupta
Quoted 13 lines · Borislav Petkov
Quoted 11 lines · Pawan Gupta
Review const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · line 56
Quoted 9 lines
/**
*x86_match_cpu- match current CPU against an array ofx86_cpu_ids
* @match: Pointer to array ofx86_cpu_ids. Last entry terminated with(quoted diff) +1
-1@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) continue; if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature)) continue; - if (!x86_match_vendor_cpu_type(c, m)) + if (m->type != X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)... matching a hybrid CPU to any
cpu_type.Quoted 6 lines
Quoted 1 line
I don't know what you mean here.
Vulnerability enumeration is done on the BSP, for a hybrid system with BSP as a performance-core, a vulnerability that only affects efficiency-cores would not be enumerated. So,
x86_match_cpu()currently returns a match for any cpu-type on a hybrid system.Abusing the type, which enumerates performance properties, for vulnerability crystal ball logic is simply broken.
Quoted 6 lines
The type is a per CPU property and has nothing to do with hybrid or not. Hybrid is a packet property.
Just because it is convenient does not make it more correct. If you need to enable mitigations on hybrid systems, then explicitely check for the hybrid property.
Right, I was convoluting 2 different goals. Vulnerability enumeration should explicitly check for hybrid.
Currently, only RFDS needs to check for hybrid. It is probably not worth creating a new mechanism for cpu_type check for vulnerability enumeration. Below should work with current set of CPUs. Please let me know if there is a better way to handle this:
---
arch/x86/kernel/cpu/common.c +14 -3
@@ -1316,10 +1316,8 @@ static const struct x86_cpu_id cpu_vuln_blacklist[] __initconst = {VULNBL_INTEL_STEPS (INTEL_TIGERLAKE ,X86_STEP_MAX ,GDS |ITS |ITS_NATIVE_ONLY ),VULNBL_INTEL_STEPS (INTEL_LAKEFIELD ,X86_STEP_MAX ,MMIO |MMIO_SBDS |RETBLEED ),VULNBL_INTEL_STEPS (INTEL_ROCKETLAKE ,X86_STEP_MAX ,MMIO |RETBLEED |GDS |ITS |ITS_NATIVE_ONLY ), -VULNBL_INTEL_TYPE (INTEL_ALDERLAKE ,ATOM ,RFDS |VMSCAPE ),VULNBL_INTEL_STEPS (INTEL_ALDERLAKE ,X86_STEP_MAX ,VMSCAPE ),VULNBL_INTEL_STEPS (INTEL_ALDERLAKE_L ,X86_STEP_MAX ,RFDS |VMSCAPE ), -VULNBL_INTEL_TYPE (INTEL_RAPTORLAKE ,ATOM ,RFDS |VMSCAPE ),VULNBL_INTEL_STEPS (INTEL_RAPTORLAKE ,X86_STEP_MAX ,VMSCAPE ),VULNBL_INTEL_STEPS (INTEL_RAPTORLAKE_P ,X86_STEP_MAX ,RFDS |VMSCAPE ), VULNBL_INTEL_STEPS(INTEL_RAPTORLAKE_S, X86_STEP_MAX, RFDS | VMSCAPE),
@@ -1388,7 +1386,20 @@ static bool __init vulnerable_to_rfds(u64 x86_arch_cap_msr)return true;/* Only consult the blacklist when there is no enumeration: */ -return cpu_matches (cpu_vuln_blacklist,RFDS ); +if (!cpu_matches (cpu_vuln_blacklist,RFDS )) +return false; + +/* +* ADL and RPL are only affected if they have Atom CPUs. +* Hybrids have both Core and Atom CPUs, mark them vulnerable. +*/ +if ((boot_cpu_data.x86_model ==0x97 || + boot_cpu_data.x86_model ==0xB7 ) && + boot_cpu_data.topo.hw_cpu_type ==INTEL_CPU_TYPE_CORE && + !boot_cpu_has (X86_FEATURE_HYBRID_CPU )) +return false; + +return true; }static bool __init vulnerable_to_its (u64 x86_arch_cap_msr)
Thomas Gleixner
maintainerRe: [PATCH 1/2] x86/topology: Name the AMD core-type values
Quoted 5 lines · Pawan Gupta
Quoted 3 lines · Thomas Gleixner
Just because it is convenient does not make it more correct. If you need to enable mitigations on hybrid systems, then explicitely check for the hybrid property.
Quoted 7 lines
Right, I was convoluting 2 different goals. Vulnerability enumeration should explicitly check for hybrid.
Currently, only RFDS needs to check for hybrid. It is probably not worth creating a new mechanism for
cpu_typecheck for vulnerability enumeration. Below should work with current set of CPUs. Please let me know if there is a better way to handle this:
If that's the only case to handle, then sure that open coded check is fine.
Borislav Petkov
maintainerPATCH 1/1 x86/topo: Map vendor CPU types to generic Linux such types
Quoted 2 lines · Thomas Gleixner
If that's the only case to handle, then sure that open coded check is fine.
This is ontop of tip:x86/cpu which already has Pawan's change that drops the one Intel-specific CPU type use.
It boots here so... :-P
---
From: "Borislav Petkov (AMD)" <[email protected]>
Date: Thu, 2 Jul 2026 17:00:28 -0700
Subject: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Sashiko reported¹ that a confusion could ensue if a vendor-specific CPU type 0 (performance) gets attempted to be used in a x86_cpu_id match table. The current logic treats 0 as the wildcard X86_CPU_TYPE_ANY and such a thing would end up matching the wrong CPUs.
This is all backwards because we started using the vendor-specific CPU type number instead of using a Linux-defined, generic CPU type which is agnostic.
Convert the current logic to it before users start appearing.
¹https://sashiko.dev/#/patchset/20260629094349.533301-1-Vishal.Badole%40amd.com
--- arch/x86/include/asm/processor.h | 18 ++++++++++++---- arch/x86/include/asm/topology.h | 7 ------- arch/x86/kernel/acpi/cppc.c | 4 ++-- arch/x86/kernel/cpu/match.c | 30 +-------------------------- arch/x86/kernel/cpu/topology.h | 1 + arch/x86/kernel/cpu/topology_amd.c | 6 ++++-- arch/x86/kernel/cpu/topology_common.c | 8 +++++-- 7 files changed, 28 insertions(+), 46 deletions(-)
arch/x86/include/asm/processor.h +14 -4
@@ -68,9 +68,13 @@ extern u16 __read_mostly tlb_lld_2m;extern u16 __read_mostly tlb_lld_4m;extern u16 __read_mostly tlb_lld_1g; -/* -* CPU type and hardware bug flags. Kept separately for each CPU. -*/ +enum x86_topology_cpu_type { +/* X86_CPU_TYPE_ANY */ +TOPO_CPU_TYPE_ANY =0 , +TOPO_CPU_TYPE_PERFORMANCE , +TOPO_CPU_TYPE_EFFICIENCY , +TOPO_CPU_TYPE_UNKNOWN , +};struct cpuinfo_topology {// Real APIC ID read from the local APIC
@@ -104,7 +108,7 @@ struct cpuinfo_topology {// Hardware defined CPU-type union { -u32 cpu_type; +u32 hw_cpu_type;struct {// CPUID.1A.EAX[23-0] u32 intel_native_model_id :24 ;
@@ -119,8 +123,14 @@ struct cpuinfo_topology { amd_type :4 ; }; }; + +// Linux vendor-agnostic CPU type +enum x86_topology_cpu_type cpu_type; }; +/* +* CPU type and hardware bug flags. Kept separately for each CPU. +*/ struct cpuinfo_x86 { union { /*
arch/x86/include/asm/topology.h +0 -7
@@ -114,12 +114,6 @@ enum x86_topology_domains { TOPO_MAX_DOMAIN, }; -enum x86_topology_cpu_type { -TOPO_CPU_TYPE_PERFORMANCE , -TOPO_CPU_TYPE_EFFICIENCY , -TOPO_CPU_TYPE_UNKNOWN , -}; -struct x86_topology_system {unsigned int dom_shifts[TOPO_MAX_DOMAIN ];unsigned int dom_size[TOPO_MAX_DOMAIN ];
@@ -160,7 +154,6 @@ extern unsigned int __num_nodes_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);static inline unsigned int topology_max_packages (void ) {
arch/x86/kernel/acpi/cppc.c +2 -2
@@ -241,7 +241,6 @@ EXPORT_SYMBOL_GPL(amd_detect_prefcore);*/ int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) { -enum x86_topology_cpu_type core_type =get_topology_cpu_type (&cpu_data (cpu));bool prefcore;int ret;u32 tmp;
@@ -273,8 +272,9 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)/* detect if running on heterogeneous design */ if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { -switch (core_type) { +switch (cpu_data (cpu).topo.cpu_type) {case TOPO_CPU_TYPE_UNKNOWN : +case TOPO_CPU_TYPE_ANY :pr_warn ("Undefined core type found for cpu %d\n" , cpu);break ;case TOPO_CPU_TYPE_PERFORMANCE :
arch/x86/kernel/cpu/match.c +1 -29
@@ -5,34 +5,6 @@#include <linux/export.h> #include <linux/slab.h> -/** -* x86_match_vendor_cpu_type - helper function to match the hardware defined -* cpu-type for a single entry in the x86_cpu_id -* table. Note, this function does not match the -* generic cpu-types TOPO_CPU_TYPE_EFFICIENCY and -* TOPO_CPU_TYPE_PERFORMANCE. -* @c: Pointer to the cpuinfo_x86 structure of the CPU to match. -* @m: Pointer to the x86_cpu_id entry to match against. -* -* Return: true if the cpu-type matches, false otherwise. -*/ -static bool x86_match_vendor_cpu_type (struct cpuinfo_x86 *c,const struct x86_cpu_id *m) -{ -if (m->type ==X86_CPU_TYPE_ANY ) -return true; - -/* Hybrid CPUs are special, they are assumed to match all cpu-types */ -if (cpu_feature_enabled (X86_FEATURE_HYBRID_CPU )) -return true; - -if (c->x86_vendor ==X86_VENDOR_INTEL ) -return m->type == c->topo.intel_type; -if (c->x86_vendor ==X86_VENDOR_AMD ) -return m->type == c->topo.amd_type; - -return false; -} -/** * x86_match_cpu - match current CPU against an array of x86_cpu_ids * @match: Pointer to array of x86_cpu_ids. Last entry terminated with
@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)continue ;return m; }
arch/x86/kernel/cpu/topology.h +1 -0
@@ -22,6 +22,7 @@ void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,bool cpu_parse_topology_ext (struct topo_scan *tscan);void cpu_parse_topology_amd (struct topo_scan *tscan);void cpu_topology_fixup_amd (struct topo_scan *tscan); +enum x86_topology_cpu_type get_topology_cpu_type (struct cpuinfo_x86 *c);static inline u32 topo_shift_apicid (u32 apicid,enum x86_topology_domains dom) {
arch/x86/kernel/cpu/topology_amd.c +4 -2
@@ -177,8 +177,10 @@ static void topoext_fixup(struct topo_scan *tscan)static void parse_topology_amd (struct topo_scan *tscan) { -if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) - tscan->c->topo.cpu_type =cpuid_ebx (0x80000026 ); +if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { + tscan->c->topo.hw_cpu_type =cpuid_ebx (0x80000026 ); + tscan->c->topo.cpu_type =get_topology_cpu_type (tscan->c); + }/* * Try to get SMT, CORE, TILE, and DIE shifts from extended
arch/x86/kernel/cpu/topology_common.c +6 -2
@@ -168,8 +168,12 @@ static void parse_topology(struct topo_scan *tscan, bool early)case X86_VENDOR_INTEL :if (!IS_ENABLED (CONFIG_CPU_SUP_INTEL ) || !cpu_parse_topology_ext (tscan))parse_legacy (tscan); -if (c->cpuid_level >=0x1a ) - c->topo.cpu_type =cpuid_eax (0x1a ); + +if (c->cpuid_level >=0x1a ) { + c->topo.hw_cpu_type =cpuid_eax (0x1a ); + c->topo.cpu_type =get_topology_cpu_type (c); + } +break ; } }
Signature · 7 lines
2.53.0
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
Quoted 47 lines · Borislav Petkov
Quoted 2 lines · Thomas Gleixner
If that's the only case to handle, then sure that open coded check is fine.
This is ontop of tip:x86/cpu which already has Pawan's change that drops the one Intel-specific CPU type use.
It boots here so... :-P
---
From: "Borislav Petkov (AMD)" <[email protected]>
Date: Thu, 2 Jul 2026 17:00:28 -0700
Subject: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitSashiko reported¹ that a confusion could ensue if a vendor-specific CPU type 0 (performance) gets attempted to be used in a
x86_cpu_idmatch table. The current logic treats 0 as the wildcardX86_CPU_TYPE_ANYand such a thing would end up matching the wrong CPUs.This is all backwards because we started using the vendor-specific CPU type number instead of using a Linux-defined, generic CPU type which is agnostic.
Convert the current logic to it before users start appearing.
¹https://sashiko.dev/#/patchset/20260629094349.533301-1-Vishal.Badole%40amd.com
Signed-off-by Borislav Petkov (AMD) <[email protected]>--- arch/x86/include/asm/processor.h | 18 ++++++++++++---- arch/x86/include/asm/topology.h | 7 ------- arch/x86/kernel/acpi/cppc.c | 4 ++-- arch/x86/kernel/cpu/match.c | 30 +-------------------------- arch/x86/kernel/cpu/topology.h | 1 + arch/x86/kernel/cpu/topology_amd.c | 6 ++++-- arch/x86/kernel/cpu/topology_common.c | 8 +++++-- 7 files changed, 28 insertions(+), 46 deletions(-)arch/x86/include/asm/processor.h +0
-0
arch/x86/include/asm/processor.h extern u16 __read_mostly tlb_lld_2m; · line 73
Quoted 9 lines
arch/x86/include/asm/processor.h +3
-3@@ -68,9 +68,13 @@ extern u16 __read_mostly tlb_lld_2m;extern u16 __read_mostly tlb_lld_4m;extern u16 __read_mostly tlb_lld_1g; -/* -* CPU type and hardware bug flags. Kept separately for each CPU. -*/ +enum x86_topology_cpu_type { +/* X86_CPU_TYPE_ANY */ +TOPO_CPU_TYPE_ANY =0 ,
I don't really understand the purpose of TOPO_CPU_TYPE_ANY here. In the cpu matching infrastructure, X86_CPU_TYPE_ANY makes sense. Here I fail to understand how is TOPO_CPU_TYPE_ANY different from UNKNOWN? A table passed to x86_match_cpu() with X86_CPU_TYPE_ANY entry will match any CPU type including TOPO_CPU_TYPE_UNKNOWN.
Quoted 44 lines
arch/x86/include/asm/processor.h +11
-1+TOPO_CPU_TYPE_PERFORMANCE , +TOPO_CPU_TYPE_EFFICIENCY , + TOPO_CPU_TYPE_UNKNOWN, +}; struct cpuinfo_topology {// Real APIC ID read from the local APIC @@ -104,7 +108,7 @@ struct cpuinfo_topology {// Hardware defined CPU-type union { -u32 cpu_type; +u32 hw_cpu_type;struct {// CPUID.1A.EAX[23-0] u32 intel_native_model_id :24 ;@@ -119,8 +123,14 @@ struct cpuinfo_topology { amd_type :4 ; }; }; + +// Linux vendor-agnostic CPU type +enum x86_topology_cpu_type cpu_type; }; +/* +* CPU type and hardware bug flags. Kept separately for each CPU. +*/ struct cpuinfo_x86 { union { /*arch/x86/include/asm/topology.h +0
-5@@ -114,12 +114,6 @@ enum x86_topology_domains { TOPO_MAX_DOMAIN, }; -enum x86_topology_cpu_type { -TOPO_CPU_TYPE_PERFORMANCE , -TOPO_CPU_TYPE_EFFICIENCY , -TOPO_CPU_TYPE_UNKNOWN , -};
...
arch/x86/include/asm/topology.h const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · line 56
Quoted 9 lines
/**
*x86_match_cpu- match current CPU against an array ofx86_cpu_ids
* @match: Pointer to array ofx86_cpu_ids. Last entry terminated witharch/x86/include/asm/topology.h +1
-1@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)
In line with what Thomas pointed that cpu_type is not a system property, I suggest matching cpu_type should be dropped from x86_match_cpu(). More so because it only uses boot_cpu_data and misses the other types of secondary CPUs. I feel it is not a reliable way to match CPU types. Thoughts?
Quoted 20 lines
arch/x86/include/asm/topology.h +0
-0continue ;return m; }arch/x86/kernel/cpu/topology.h +1
-0@@ -22,6 +22,7 @@ void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,bool cpu_parse_topology_ext (struct topo_scan *tscan);void cpu_parse_topology_amd (struct topo_scan *tscan);void cpu_topology_fixup_amd (struct topo_scan *tscan); +enum x86_topology_cpu_type get_topology_cpu_type (struct cpuinfo_x86 *c);static inline u32 topo_shift_apicid (u32 apicid,enum x86_topology_domains dom) {arch/x86/kernel/cpu/topology_amd.c +0
-0
arch/x86/kernel/cpu/topology_amd.c static void topoext_fixup(struct topo_scan *tscan) · line 180
Quoted 6 lines
arch/x86/kernel/cpu/topology_amd.c +1
-2@@ -177,8 +177,10 @@ static void topoext_fixup(struct topo_scan *tscan)static void parse_topology_amd (struct topo_scan *tscan) { -if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) - tscan->c->topo.cpu_type =cpuid_ebx (0x80000026 ); +if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) {
Slightly unrelated to this patch, on AMD is it that hw_cpu_type only available on hybrid systems? On Intel ...
Quoted 11 lines
arch/x86/kernel/cpu/topology_amd.c +3
-0+ tscan->c->topo.hw_cpu_type =cpuid_ebx (0x80000026 ); + tscan->c->topo.cpu_type =get_topology_cpu_type (tscan->c); + }/* * Try to get SMT, CORE, TILE, and DIE shifts from extended arch/x86/kernel/cpu/topology_common.c +0
-0
arch/x86/kernel/cpu/topology_common.c static void parse_topology(struct topo_scan *tscan, bool early) · line 174
Quoted 9 lines
arch/x86/kernel/cpu/topology_common.c +4
-2@@ -168,8 +168,12 @@ static void parse_topology(struct topo_scan *tscan, bool early)case X86_VENDOR_INTEL :if (!IS_ENABLED (CONFIG_CPU_SUP_INTEL ) || !cpu_parse_topology_ext (tscan))parse_legacy (tscan); -if (c->cpuid_level >=0x1a ) - c->topo.cpu_type =cpuid_eax (0x1a ); + +if (c->cpuid_level >=0x1a ) { + c->topo.hw_cpu_type =cpuid_eax (0x1a ); + c->topo.cpu_type =get_topology_cpu_type (c);
... hw_cpu_type could be enumerated on non-hybrid parts.
Quoted 5 lines
arch/x86/kernel/cpu/topology_common.c +2
-0+ } +break ; } }
Borislav Petkov
maintainerRe: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
Quoted 9 lines · Pawan Gupta
arch/x86/include/asm/processor.h extern u16 __read_mostly tlb_lld_2m; · line 73
Quoted 3 lines
arch/x86/include/asm/processor.h +3
-0+enum x86_topology_cpu_type { +/* X86_CPU_TYPE_ANY */ +TOPO_CPU_TYPE_ANY =0 ,I don't really understand the purpose of
TOPO_CPU_TYPE_ANYhere. In the cpu matching infrastructure,X86_CPU_TYPE_ANYmakes sense. Here I fail to understand how isTOPO_CPU_TYPE_ANYdifferent from UNKNOWN? A table passed tox86_match_cpu()withX86_CPU_TYPE_ANYentry will match any CPU type includingTOPO_CPU_TYPE_UNKNOWN.
This will go away in future patches. We do one logical thing per patch and removing UNKNOWN is not it. I have it on my TODO list to clean up everything here.
Quoted 5 lines
Quoted 5 lines
arch/x86/include/asm/processor.h +4
-0+TOPO_CPU_TYPE_PERFORMANCE , +TOPO_CPU_TYPE_EFFICIENCY , + TOPO_CPU_TYPE_UNKNOWN, +};
...
Quoted 11 lines
arch/x86/kernel/cpu/match.c const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · line 56
Quoted 6 lines
arch/x86/kernel/cpu/match.c +1
-1@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)In line with what Thomas pointed that
cpu_typeis not a system property, I suggest matchingcpu_typeshould be dropped fromx86_match_cpu(). More so because it only usesboot_cpu_dataand misses the other types of secondary CPUs. I feel it is not a reliable way to match CPU types. Thoughts?
How do you suggest we match CPU types on the whole system?
I.e., "do this workaround only on the performance cores", for example.
c->topo.cpu_type is perfect for that then.
Quoted 2 lines
Slightly unrelated to this patch, on AMD is it that
hw_cpu_typeonly available on hybrid systems?
No idea. I will dig through that later, when cleaning up.
If only available on hybrid systems, we will have to fake something there, X86_CPU_TYPE_ANY perhaps.
:-)
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
Quoted 11 lines · Borislav Petkov
Quoted 9 lines · Pawan Gupta
arch/x86/include/asm/processor.h extern u16 __read_mostly tlb_lld_2m; · line 73
Quoted 3 lines
arch/x86/include/asm/processor.h +3
-0+enum x86_topology_cpu_type { +/* X86_CPU_TYPE_ANY */ +TOPO_CPU_TYPE_ANY =0 ,I don't really understand the purpose of
TOPO_CPU_TYPE_ANYhere. In the cpu matching infrastructure,X86_CPU_TYPE_ANYmakes sense. Here I fail to understand how isTOPO_CPU_TYPE_ANYdifferent from UNKNOWN? A table passed tox86_match_cpu()withX86_CPU_TYPE_ANYentry will match any CPU type includingTOPO_CPU_TYPE_UNKNOWN.
Quoted 3 lines
This will go away in future patches. We do one logical thing per patch and removing UNKNOWN is not it. I have it on my TODO list to clean up everything here.
Unless I am misreading, TOPO_CPU_TYPE_ANY is introduced in this patch. X86_*_ANY in x86_match_cpu() are much needed wildcards, I dont really understand why x86_topology_cpu_type needs to carry a wildcard. It should reflect the true state, PERFORMANCE, EFFICIENCY or UNKNOWN.
Between ANY and UNKNOWN, I would prefer UNKNOWN when CPU did not report a type.
Quoted 20 lines
Quoted 5 lines
Quoted 5 lines
arch/x86/include/asm/processor.h +4
-0+TOPO_CPU_TYPE_PERFORMANCE , +TOPO_CPU_TYPE_EFFICIENCY , + TOPO_CPU_TYPE_UNKNOWN, +};...
Quoted 11 lines
arch/x86/kernel/cpu/match.c const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · line 56
Quoted 6 lines
arch/x86/kernel/cpu/match.c +1
-1@@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)In line with what Thomas pointed that
cpu_typeis not a system property, I suggest matchingcpu_typeshould be dropped fromx86_match_cpu(). More so because it only usesboot_cpu_dataand misses the other types of secondary CPUs. I feel it is not a reliable way to match CPU types. Thoughts?
Quoted 5 lines
How do you suggest we match CPU types on the whole system?
I.e., "do this workaround only on the performance cores", for example.
c->topo.cpu_typeis perfect for that then.
Ya. If need be, a mask of each possible cpu_type can be built for dispatching work selectively.
Borislav Petkov
maintainerRe: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
Quoted 7 lines · Pawan Gupta
Unless I am misreading,
TOPO_CPU_TYPE_ANYis introduced in this patch. X86_*_ANY inx86_match_cpu()are much needed wildcards, I dont really understand whyx86_topology_cpu_typeneeds to carry a wildcard. It should reflect the true state, PERFORMANCE, EFFICIENCY or UNKNOWN.Between ANY and UNKNOWN, I would prefer UNKNOWN when CPU did not report a type.
Because X86_CPU_TYPE_ANY is already there and it is 0 and TOPO_CPU_TYPE_ANY is supposed to be the same and mirror it.
Did you even read my mail where I explain that we don't do multiple things in one patch?
Quoted 2 lines
Ya. If need be, a mask of each possible
cpu_typecan be built for dispatching work selectively.
Instead of doing the completely sensible thing and keeping a per-CPU type?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
Quoted 11 lines · Borislav Petkov
Quoted 7 lines · Pawan Gupta
Unless I am misreading,
TOPO_CPU_TYPE_ANYis introduced in this patch. X86_*_ANY inx86_match_cpu()are much needed wildcards, I dont really understand whyx86_topology_cpu_typeneeds to carry a wildcard. It should reflect the true state, PERFORMANCE, EFFICIENCY or UNKNOWN.Between ANY and UNKNOWN, I would prefer UNKNOWN when CPU did not report a type.
Because
X86_CPU_TYPE_ANYis already there and it is 0 andTOPO_CPU_TYPE_ANYis supposed to be the same and mirror it.
This is exactly what I don't understand. For a wildcard X86_CPU_TYPE_ANY that matches TOPO_CPU_TYPE_*, do we really need TOPO_CPU_TYPE_ANY for matching to work?
Quoted 2 lines
Did you even read my mail where I explain that we don't do multiple things in one patch?
Yes, but my main concern is about addition of TOPO_CPU_TYPE_ANY. If we don't add TOPO_CPU_TYPE_ANY, second patch will not be needed. Sorry if I am mis-interpreting things.
Quoted 4 lines
Quoted 2 lines
Ya. If need be, a mask of each possible
cpu_typecan be built for dispatching work selectively.Instead of doing the completely sensible thing and keeping a per-CPU type?
My earlier comment was unnecessary, and putting us off-track here. Please ignore this part.
(Just to clarify what I meant: For dispatching work to all P-cores in your example scenario with something like on_each_cpu_mask() we would need a mask of all P-cores. Such a mask can be built/cached using the per-CPU type information).
Borislav Petkov
maintainerRe: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
Quoted 3 lines · Pawan Gupta
Yes, but my main concern is about addition of
TOPO_CPU_TYPE_ANY. If we don't addTOPO_CPU_TYPE_ANY, second patch will not be needed. Sorry if I am mis-interpreting things.
Well, I have no idea too what are you even fighting for? It sounds like a giant waste of time to me for something as trivial as this.
What second patch?
Once the cleanup is done, only one of the two will survive - either TOPO_CPU_TYPE_ANY or TOPO_CPU_TYPE_UNKNOWN. I'm calling the former "ANY" to denote that it is the *same* ANY as X86_CPU_TYPE_ANY.
I don't know how else to explain it to you.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerRe: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
Here's the cleanup ontop, lemme know pls whether that makes sense.
Some noteworthy things:
* this basically switches to TOPO_CPU_TYPE and only the detection code knows about the vendor-specific ones. The generic types are union set of both.
* We do some CPUID calls where needed:
- native_id = c->topo.intel_native_model_id;
+ native_id = cpuid_eax(0x1a) & GENMASK(23, 0);
and in get_topology_cpu_type() but those will go away too with Ahmed's rework
The rest is just manual conversion labour. Oh, and TOPO_CPU_TYPE_ANY is gone too, so that Pawan can sleep at night :-P
Thoughts?
I think it is better this way instead of carrying intel_type and amd_type in cpuinfo - now the topology code is preparing things for us.
I'll split it into proper patches if people are ok with it.
Thx.
---
arch/x86/events/intel/core.c +7 -7
@@ -5682,9 +5682,9 @@ static int adl_hw_config(struct perf_event *event)return -EOPNOTSUPP ; } -static enum intel_cpu_type adl_get_hybrid_cpu_type (void ) +static enum x86_topology_cpu_type adl_get_hybrid_cpu_type (void ) { -return INTEL_CPU_TYPE_CORE ; +return TOPO_CPU_TYPE_EFFICIENCY ; }static inline bool erratum_hsw11 (struct perf_event *event)
@@ -6292,7 +6292,7 @@ static void intel_pmu_check_hybrid_pmus(struct x86_hybrid_pmu *pmu)static struct x86_hybrid_pmu *find_hybrid_pmu_for_cpu (void ) {struct cpuinfo_x86 *c = &cpu_data (smp_processor_id ()); -enum intel_cpu_type cpu_type = c->topo.intel_type; +enum x86_topology_cpu_type cpu_type = c->topo.cpu_type;int i;/*
@@ -6301,7 +6301,7 @@ static struct x86_hybrid_pmu *find_hybrid_pmu_for_cpu(void)* on it. There should be a fixup function provided for these * troublesome CPUs (->get_hybrid_cpu_type). */ -if (cpu_type ==INTEL_CPU_TYPE_UNKNOWN ) { +if (cpu_type ==TOPO_CPU_TYPE_UNKNOWN ) {if (x86_pmu.get_hybrid_cpu_type) cpu_type = x86_pmu.get_hybrid_cpu_type ();else
@@ -6318,13 +6318,13 @@ static struct x86_hybrid_pmu *find_hybrid_pmu_for_cpu(void)enum hybrid_pmu_type pmu_type = x86_pmu.hybrid_pmu[i].pmu_type;u32 native_id; -if (cpu_type ==INTEL_CPU_TYPE_CORE && pmu_type == hybrid_big) +if (cpu_type ==TOPO_CPU_TYPE_PERFORMANCE && pmu_type == hybrid_big)return &x86_pmu.hybrid_pmu[i]; -if (cpu_type ==INTEL_CPU_TYPE_ATOM ) { +if (cpu_type ==TOPO_CPU_TYPE_EFFICIENCY ) {if (x86_pmu.num_hybrid_pmus ==2 && pmu_type == hybrid_small)return &x86_pmu.hybrid_pmu[i]; - native_id = c->topo.intel_native_model_id; + native_id =cpuid_eax (0x1a ) &GENMASK (23 ,0 );if (native_id ==INTEL_ATOM_SKT_NATIVE_ID && pmu_type == hybrid_small)return &x86_pmu.hybrid_pmu[i];if (native_id ==INTEL_ATOM_CMT_NATIVE_ID && pmu_type == hybrid_tiny)
arch/x86/events/perf_event.h +1 -1
@@ -1051,7 +1051,7 @@ struct x86_pmu {*/ int num_hybrid_pmus;struct x86_hybrid_pmu *hybrid_pmu; -enum intel_cpu_type (*get_hybrid_cpu_type) (void ); +enum x86_topology_cpu_type (*get_hybrid_cpu_type) (void ); };struct x86_perf_task_context_opt {
arch/x86/include/asm/intel-family.h +0 -14
@@ -207,20 +207,6 @@#define INTEL_P4_PRESCOTT_2M IFM(15, 0x04)#define INTEL_P4_CEDARMILL IFM(15, 0x06)/* Also Xeon Dempsey */ -/* -* Intel CPU core types -* -* CPUID.1AH.EAX[31:0] uniquely identifies the microarchitecture -* of the core. Bits 31-24 indicates its core type (Core or Atom) -* and Bits [23:0] indicates the native model ID of the core. -* Core type and native model ID are defined in below enumerations. -*/ -enum intel_cpu_type { -INTEL_CPU_TYPE_UNKNOWN , -INTEL_CPU_TYPE_ATOM =0x20 , -INTEL_CPU_TYPE_CORE =0x40 , -}; -enum intel_native_id {INTEL_ATOM_CMT_NATIVE_ID =0x2 ,/* Crestmont */ INTEL_ATOM_SKT_NATIVE_ID =0x3 ,/* Skymont */
arch/x86/include/asm/processor.h +2 -21
@@ -69,12 +69,11 @@ extern u16 __read_mostly tlb_lld_4m;extern u16 __read_mostly tlb_lld_1g;enum x86_topology_cpu_type { -/* X86_CPU_TYPE_ANY */ -TOPO_CPU_TYPE_ANY =0 , +/* Must remain 0 like X86_CPU_TYPE_ANY for x86_match_cpu() to work */ +TOPO_CPU_TYPE_UNKNOWN =0 ,TOPO_CPU_TYPE_PERFORMANCE ,TOPO_CPU_TYPE_EFFICIENCY ,TOPO_CPU_TYPE_LOW_POWER , -TOPO_CPU_TYPE_UNKNOWN , };struct cpuinfo_topology {
@@ -107,24 +106,6 @@ struct cpuinfo_topology {u32 llc_id;u32 l2c_id; -// Hardware defined CPU-type -union { -u32 hw_cpu_type; -struct { -// CPUID.1A.EAX[23-0] -u32 intel_native_model_id :24 ; -// CPUID.1A.EAX[31-24] -u32 intel_type :8 ; - }; -struct { -// CPUID 0x80000026.EBX -u32 amd_num_processors :16 , - amd_power_eff_ranking :8 , - amd_native_model_id :4 , - amd_type :4 ; - }; - }; -// Linux vendor-agnostic CPU type enum x86_topology_cpu_type cpu_type; };
arch/x86/include/asm/topology.h +0 -6
@@ -114,12 +114,6 @@ enum x86_topology_domains { TOPO_MAX_DOMAIN, }; -enum amd_cpu_type { -AMD_CPU_TYPE_PERFORMANCE =0 , -AMD_CPU_TYPE_EFFICIENCY =1 , -AMD_CPU_TYPE_LOW_POWER =2 , -}; -struct x86_topology_system {unsigned int dom_shifts[TOPO_MAX_DOMAIN ];unsigned int dom_size[TOPO_MAX_DOMAIN ];
arch/x86/kernel/acpi/cppc.c +0 -1
@@ -274,7 +274,6 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) {switch (cpu_data (cpu).topo.cpu_type) {case TOPO_CPU_TYPE_UNKNOWN : -case TOPO_CPU_TYPE_ANY :pr_warn ("Undefined core type found for cpu %d\n" , cpu);break ;case TOPO_CPU_TYPE_PERFORMANCE :
arch/x86/kernel/cpu/common.c +1 -1
@@ -1394,7 +1394,7 @@ static bool __init vulnerable_to_rfds(u64 x86_arch_cap_msr)*/ if ((boot_cpu_data.x86_model ==0x97 || boot_cpu_data.x86_model ==0xB7 ) && - boot_cpu_data.topo.intel_type !=INTEL_CPU_TYPE_ATOM && + boot_cpu_data.topo.cpu_type !=TOPO_CPU_TYPE_EFFICIENCY && !boot_cpu_has (X86_FEATURE_HYBRID_CPU ))return false;
arch/x86/kernel/cpu/topology.h +19 -0
@@ -2,6 +2,25 @@ #ifndef ARCH_X86_TOPOLOGY_H #define ARCH_X86_TOPOLOGY_H +/* + * Intel CPU core types + * + * CPUID.1AH.EAX[31:0] uniquely identifies the microarchitecture + * of the core. Bits 31-24 indicates its core type (Core or Atom) + * and Bits [23:0] indicates the native model ID of the core. + */ +enum intel_cpu_type { + INTEL_CPU_TYPE_UNKNOWN, + INTEL_CPU_TYPE_ATOM = 0x20, + INTEL_CPU_TYPE_CORE = 0x40, +}; + +enum amd_cpu_type { + AMD_CPU_TYPE_PERFORMANCE = 0, + AMD_CPU_TYPE_EFFICIENCY = 1, + AMD_CPU_TYPE_LOW_POWER = 2, +}; + struct topo_scan { struct cpuinfo_x86 *c; unsigned int dom_shifts[TOPO_MAX_DOMAIN];
arch/x86/kernel/cpu/topology_amd.c +2 -4
@@ -177,10 +177,8 @@ static void topoext_fixup(struct topo_scan *tscan)static void parse_topology_amd (struct topo_scan *tscan) { -if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { - tscan->c->topo.hw_cpu_type =cpuid_ebx (0x80000026 ); - tscan->c->topo.cpu_type =get_topology_cpu_type (tscan->c); - } +if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) + tscan->c->topo.cpu_type =get_topology_cpu_type (tscan->c);/* * Try to get SMT, CORE, TILE, and DIE shifts from extended
arch/x86/kernel/cpu/topology_common.c +8 -6
@@ -35,13 +35,17 @@ void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,enum x86_topology_cpu_type get_topology_cpu_type (struct cpuinfo_x86 *c) {if (c->x86_vendor ==X86_VENDOR_INTEL ) { -switch (c->topo.intel_type) { +unsigned int type = (cpuid_eax (0x1a ) >>24 ) &0xff ; + +switch (type) {case INTEL_CPU_TYPE_ATOM :return TOPO_CPU_TYPE_EFFICIENCY ;case INTEL_CPU_TYPE_CORE :return TOPO_CPU_TYPE_PERFORMANCE ; } }if (c->x86_vendor ==X86_VENDOR_AMD ) { -switch (c->topo.amd_type) { +unsigned int type = (cpuid_ebx (0x80000026 ) >>28 ) &0xf ; + +switch (type) {case AMD_CPU_TYPE_PERFORMANCE :return TOPO_CPU_TYPE_PERFORMANCE ;case AMD_CPU_TYPE_EFFICIENCY :return TOPO_CPU_TYPE_EFFICIENCY ;case AMD_CPU_TYPE_LOW_POWER :return TOPO_CPU_TYPE_LOW_POWER ;
@@ -172,10 +176,8 @@ static void parse_topology(struct topo_scan *tscan, bool early)if (!IS_ENABLED (CONFIG_CPU_SUP_INTEL ) || !cpu_parse_topology_ext (tscan))parse_legacy (tscan); -if (c->cpuid_level >=0x1a ) { - c->topo.hw_cpu_type =cpuid_eax (0x1a ); - c->topo.cpu_type =get_topology_cpu_type (c); - } +if (c->cpuid_level >=0x1a ) + c->topo.cpu_type =get_topology_cpu_type (c);break ; }
drivers/cpufreq/intel_pstate.c +3 -3
@@ -868,7 +868,7 @@ static struct freq_attr *hwp_cpufreq_attrs[] = {static u8 hybrid_get_cpu_type (unsigned int cpu) { -return cpu_data (cpu).topo.intel_type; +return cpu_data (cpu).topo.cpu_type; }static bool no_cas__ro_after_init ;
@@ -931,7 +931,7 @@ static int hybrid_get_cost(struct device *dev, unsigned long freq,* capacity. Similarly, P-cores start to be populated when E-cores are * utilized above 60% of the capacity. */ -if (hybrid_get_cpu_type (dev->id) ==INTEL_CPU_TYPE_CORE )/* P-core */ +if (hybrid_get_cpu_type (dev->id) ==TOPO_CPU_TYPE_PERFORMANCE )/* P-core */ *cost +=2 ;else if (hybrid_has_l3 (dev->id))/* E-core */ *cost +=1 ;
@@ -2235,7 +2235,7 @@ static int hwp_get_cpu_scaling(int cpu)* Return the hybrid scaling factor for P-cores and use the * default core scaling for E-cores. */ -if (hybrid_get_cpu_type (cpu) !=INTEL_CPU_TYPE_ATOM ) +if (hybrid_get_cpu_type (cpu) !=TOPO_CPU_TYPE_EFFICIENCY )return hybrid_scaling_factor;return core_get_scaling ();
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
Quoted 12 lines · Borislav Petkov
Here's the cleanup ontop, lemme know pls whether that makes sense.
Some noteworthy things:
* this basically switches to
TOPO_CPU_TYPEand only the detection code knows about the vendor-specific ones. The generic types are union set of both.* We do some CPUID calls where needed:
arch/x86/events/intel/core.c +1
-1- native_id = c->topo.intel_native_model_id; + native_id =cpuid_eax (0x1a ) &GENMASK (23 ,0 );
Quoted 4 lines
and in
get_topology_cpu_type()but those will go away too with Ahmed's reworkThe rest is just manual conversion labour. Oh, and
TOPO_CPU_TYPE_ANYis gone too, so that Pawan can sleep at night :-P
And put my OCD to rest :-)
(BTW, some of that is acquired occupational hazard.)
Quoted 1 line
Thoughts?
Overall, looks like a good cleanup to me.
Quoted 6 lines
I think it is better this way instead of carrying
intel_typeandamd_typein cpuinfo - now the topology code is preparing things for us.I'll split it into proper patches if people are ok with it.
Thx.
...
arch/x86/kernel/cpu/topology_common.c void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, · line 38
Quoted 8 lines
arch/x86/kernel/cpu/topology_common.c +1
-1@@ -35,13 +35,17 @@ void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,enum x86_topology_cpu_type get_topology_cpu_type (struct cpuinfo_x86 *c) {if (c->x86_vendor ==X86_VENDOR_INTEL ) { -switch (c->topo.intel_type) { +unsigned int type = (cpuid_eax (0x1a ) >>24 ) &0xff ;
You already mentioned about the cpuid taken care elsewhere, just noting that this needs a (c->cpuid_level >= 0x1a) check.
arch/x86/kernel/cpu/topology_common.c void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, · line 44
Quoted 5 lines
arch/x86/kernel/cpu/topology_common.c +1
-0+switch (type) {case INTEL_CPU_TYPE_ATOM :return TOPO_CPU_TYPE_EFFICIENCY ;case INTEL_CPU_TYPE_CORE :return TOPO_CPU_TYPE_PERFORMANCE ; } }
Since x86_match_cpu() matches with boot_cpu_data, one rough edge remaining is, a secondary cpu_type in a hybrid system can never be matched. For this reason X86_MATCH_VFM_CPU_TYPE() is of little use now.
Re: [PATCH] x86/topo: Map vendor CPU types to generic Linux such types
In reply to Borislav Petkovarch/x86/events/intel/core.c static int adl_hw_config(struct perf_event *event) · line 5687
Quoted 13 lines · Borislav Petkov
arch/x86/events/intel/core.c +2
-2@@ -5682,9 +5682,9 @@ static int adl_hw_config(struct perf_event *event)return -EOPNOTSUPP ; } -static enum intel_cpu_type adl_get_hybrid_cpu_type (void ) +static enum x86_topology_cpu_type adl_get_hybrid_cpu_type (void ) { -return INTEL_CPU_TYPE_CORE ; +return TOPO_CPU_TYPE_EFFICIENCY ;
Should be:
return TOPO_CPU_TYPE_PERFORMANCE;
Re: [PATCH 1/2] x86/topology: Name the AMD core-type values
In reply to Borislav PetkovQuoted 210 lines · Borislav Petkov
+ Dave and Pawan.
Quoted 8 lines · Borislav Petkov
Quoted 7 lines · Thomas Gleixner
Just do the mapping to vendor-agnostic types _once_ when you enumerate the CPU and store that information in the per CPU data.
Then you can do proper vendor agnostic matching against that and define the
TYPE_ANYvalue as you want without ever colliding with vendor muck.Quoted 7 lines
Quoted 2 lines
As a bonus
get_topology_cpu_type()goes away too as the translation has been done already.Yeah, we should've done it from the very beginning this way. Lemme hack it up and see how it looks like.
Thanks for the cool idea.
Something like the totally untested below - but it builds at least.
We've allocated a u8 for the struct
x86_cpu_idmember type and we compare that to enumx86_topology_cpu_typecpu_type. I guess that's ok for now...There's potential for more cleanup by removing the ->intel_type and ->amd_type and converting them all to our internal represenation of
CPU_TYPEbut that's for later and other patches anyway.Thoughts?
arch/x86/include/asm/processor.h +14
-4@@ -68,9 +68,13 @@ extern u16 __read_mostly tlb_lld_2m;extern u16 __read_mostly tlb_lld_4m;extern u16 __read_mostly tlb_lld_1g; -/* -* CPU type and hardware bug flags. Kept separately for each CPU. -*/ +enum x86_topology_cpu_type { +/* X86_CPU_TYPE_ANY */ +TOPO_CPU_TYPE_ANY =0 , +TOPO_CPU_TYPE_PERFORMANCE , +TOPO_CPU_TYPE_EFFICIENCY , +TOPO_CPU_TYPE_UNKNOWN , +};struct cpuinfo_topology {// Real APIC ID read from the local APIC @@ -104,7 +108,7 @@ struct cpuinfo_topology {// Hardware defined CPU-type union { -u32 cpu_type; +u32 hw_cpu_type;struct {// CPUID.1A.EAX[23-0] u32 intel_native_model_id :24 ;@@ -119,8 +123,14 @@ struct cpuinfo_topology { amd_type :4 ; }; }; + +// Linux vendor-agnostic CPU type +enum x86_topology_cpu_type cpu_type; }; +/* +* CPU type and hardware bug flags. Kept separately for each CPU. +*/ struct cpuinfo_x86 { union { /*arch/x86/include/asm/topology.h +0
-7@@ -114,12 +114,6 @@ enum x86_topology_domains { TOPO_MAX_DOMAIN, }; -enum x86_topology_cpu_type { -TOPO_CPU_TYPE_PERFORMANCE , -TOPO_CPU_TYPE_EFFICIENCY , -TOPO_CPU_TYPE_UNKNOWN , -}; -struct x86_topology_system {unsigned int dom_shifts[TOPO_MAX_DOMAIN ];unsigned int dom_size[TOPO_MAX_DOMAIN ];@@ -160,7 +154,6 @@ extern unsigned int __num_nodes_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);static inline unsigned int topology_max_packages (void ) {arch/x86/kernel/acpi/cppc.c +2
-2@@ -241,7 +241,6 @@ EXPORT_SYMBOL_GPL(amd_detect_prefcore);*/ int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) { -enum x86_topology_cpu_type core_type =get_topology_cpu_type (&cpu_data (cpu));bool prefcore;int ret;u32 tmp;@@ -273,8 +272,9 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)/* detect if running on heterogeneous design */ if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { -switch (core_type) { +switch (cpu_data (cpu).topo.cpu_type) {case TOPO_CPU_TYPE_UNKNOWN : +case TOPO_CPU_TYPE_ANY :pr_warn ("Undefined core type found for cpu %d\n" , cpu);break ;case TOPO_CPU_TYPE_PERFORMANCE :arch/x86/kernel/cpu/match.c +1
-29@@ -5,34 +5,6 @@#include <linux/export.h> #include <linux/slab.h> -/** -* x86_match_vendor_cpu_type - helper function to match the hardware defined -* cpu-type for a single entry in the x86_cpu_id -* table. Note, this function does not match the -* generic cpu-types TOPO_CPU_TYPE_EFFICIENCY and -* TOPO_CPU_TYPE_PERFORMANCE. -* @c: Pointer to the cpuinfo_x86 structure of the CPU to match. -* @m: Pointer to the x86_cpu_id entry to match against. -* -* Return: true if the cpu-type matches, false otherwise. -*/ -static bool x86_match_vendor_cpu_type (struct cpuinfo_x86 *c,const struct x86_cpu_id *m) -{ -if (m->type ==X86_CPU_TYPE_ANY ) -return true; - -/* Hybrid CPUs are special, they are assumed to match all cpu-types */ -if (cpu_feature_enabled (X86_FEATURE_HYBRID_CPU )) -return true; - -if (c->x86_vendor ==X86_VENDOR_INTEL ) -return m->type == c->topo.intel_type; -if (c->x86_vendor ==X86_VENDOR_AMD ) -return m->type == c->topo.amd_type; - -return false; -} -/** * x86_match_cpu - match current CPU against an array of x86_cpu_ids * @match: Pointer to array of x86_cpu_ids. Last entry terminated with @@ -81,7 +53,7 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)continue ;if (m->feature !=X86_FEATURE_ANY && !cpu_has (c, m->feature))continue ; -if (!x86_match_vendor_cpu_type (c, m)) +if (m->type !=X86_CPU_TYPE_ANY && c->topo.cpu_type != m->type)continue ;return m; }arch/x86/kernel/cpu/topology.h +1
-0@@ -22,6 +22,7 @@ void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,bool cpu_parse_topology_ext (struct topo_scan *tscan);void cpu_parse_topology_amd (struct topo_scan *tscan);void cpu_topology_fixup_amd (struct topo_scan *tscan); +enum x86_topology_cpu_type get_topology_cpu_type (struct cpuinfo_x86 *c);static inline u32 topo_shift_apicid (u32 apicid,enum x86_topology_domains dom) {arch/x86/kernel/cpu/topology_amd.c +4
-2@@ -177,8 +177,10 @@ static void topoext_fixup(struct topo_scan *tscan)static void parse_topology_amd (struct topo_scan *tscan) { -if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) - tscan->c->topo.cpu_type =cpuid_ebx (0x80000026 ); +if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { + tscan->c->topo.hw_cpu_type =cpuid_ebx (0x80000026 ); + tscan->c->topo.cpu_type =get_topology_cpu_type (tscan->c); + }/* * Try to get SMT, CORE, TILE, and DIE shifts from extended arch/x86/kernel/cpu/topology_common.c +0
-1@@ -168,8 +168,12 @@ static void parse_topology(struct topo_scan *tscan, bool early)case X86_VENDOR_INTEL :if (!IS_ENABLED (CONFIG_CPU_SUP_INTEL ) || !cpu_parse_topology_ext (tscan))parse_legacy (tscan); -if (c->cpuid_level >=0x1a )
arch/x86/kernel/cpu/topology_common.c static void parse_topology(struct topo_scan *tscan, bool early) · line 179
Quoted 10 lines
arch/x86/kernel/cpu/topology_common.c +6
-1- c->topo.cpu_type =cpuid_eax (0x1a ); + +if (c->cpuid_level >=0x1a ) { + c->topo.hw_cpu_type =cpuid_eax (0x1a ); + c->topo.cpu_type =get_topology_cpu_type (c); + } +break ; } }
Ack! I will send a V2 patch set that includes suggested changes and the LP core patches.
PATCH 2/2 x86/topology: Add TOPO_CPU_TYPE_LOW_POWER
In reply to Vishal BadoleAMD heterogeneous parts report a third core type via CPUID Fn0x80000026 EBX[31:28] (Extended CPU Topology, Core Type):
0 - Performance
1 - Efficiency
2 - Low Power
get_topology_cpu_type() only translates the first two, so on parts that ship low-power cores the third type falls through to TOPO_CPU_TYPE_UNKNOWN. That has two visible effects:
- /sys/kernel/debug/x86/topo/cpus/* reports cpu_type "unknown" via get_topology_cpu_type_name().
- amd_get_boost_ratio_numerator() hits the default arm of its x86_topology_cpu_type switch and uses the CPPC_HIGHEST_PERF_PREFCORE fallback instead of scaling by amd_get_highest_perf() as efficiency cores do.
Add TOPO_CPU_TYPE_LOW_POWER, translate AMD_CPU_TYPE_LOW_POWER to it in get_topology_cpu_type(), and expose a "low_power" name via get_topology_cpu_type_name().
In amd_get_boost_ratio_numerator(), share the efficiency-core arm of the switch with the new type so low-power cores scale by amd_get_highest_perf() rather than the performance-core ceiling. The new case sits under the existing cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES) gate and therefore applies to every HTR_CORES-capable AMD/Hygon part that reports core type 2.
--- arch/x86/include/asm/topology.h | 1 + arch/x86/kernel/acpi/cppc.c | 3 ++- arch/x86/kernel/cpu/topology_common.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-)
arch/x86/include/asm/topology.h +1 -0
@@ -117,6 +117,7 @@ enum x86_topology_domains {enum x86_topology_cpu_type {TOPO_CPU_TYPE_PERFORMANCE ,TOPO_CPU_TYPE_EFFICIENCY , +TOPO_CPU_TYPE_LOW_POWER ,TOPO_CPU_TYPE_UNKNOWN , };
arch/x86/kernel/acpi/cppc.c +2 -1
@@ -281,8 +281,9 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)/* use the max scale for performance cores */ *numerator =CPPC_HIGHEST_PERF_PERFORMANCE ;return 0 ; +case TOPO_CPU_TYPE_LOW_POWER :case TOPO_CPU_TYPE_EFFICIENCY : -/* use the highest perf value for efficiency cores */ +/* use the highest perf value for efficiency and low-power cores */ ret =amd_get_highest_perf (cpu, &tmp);if (ret)return ret;
arch/x86/kernel/cpu/topology_common.c +3 -0
@@ -44,6 +44,7 @@ enum x86_topology_cpu_type get_topology_cpu_type(struct cpuinfo_x86 *c)switch (c->topo.amd_type) {case AMD_CPU_TYPE_PERFORMANCE :return TOPO_CPU_TYPE_PERFORMANCE ;case AMD_CPU_TYPE_EFFICIENCY :return TOPO_CPU_TYPE_EFFICIENCY ; +case AMD_CPU_TYPE_LOW_POWER :return TOPO_CPU_TYPE_LOW_POWER ; } }
@@ -57,6 +58,8 @@ const char *get_topology_cpu_type_name(struct cpuinfo_x86 *c)return "performance" ;case TOPO_CPU_TYPE_EFFICIENCY :return "efficiency" ; +case TOPO_CPU_TYPE_LOW_POWER : +return "low_power" ;default :return "unknown" ; }
Signature · 1 line
2.34.1