Add support for Hygon family 18h models 4h-8h
Subsystems (4)
v4 cover Add support for Hygon family 18h models 4h-8h
This patch series introduce support for the new-generation Hygon processor models 0x4–0x8, addressing five key areas:
1. CPU Topology Updates
The new processor introduces a revised CPU topology hierarchy compared to previous generations. This patch updates the kernel's topology detection logic to correctly identify core/socket relationships and cache sharing patterns.
2. L3 Performance Monitoring Updates
The L3 perf registers of model 6h differ from those of the previous processor.
3. Microcode loading
Add microcode loading support for Hygon processor.
4. Audio Controller Driver
Add initial support for the integrated HD-Audio controller.
5. New SB IOAPIC information support
The southbridge IOAPIC of Hygon's new-generation processors is located at 00:0b.0.
v3->v4:
- Rebase to 7.2-rc2.
- Refine the commit messages and comments for patch x86/cpu/hygon.
- Add bounds checks to the microcode patch.
- The HD-Audio patch has been applied to for-next branch.
v2->v3:
- Refine the commit messages for patch x86/cpu/hygon.
- Update the logic for deriving the LLC ID from the APIC ID on Hygon processors.
- Clean up and refine Hygon microcode support code.
- Refine the code of Hygon HD-Audio device ID.
- The iommu/hygon patch has been accepted and merged into iommu branch.
v1->v2:
- Refine the patch x86/cpu/hygon.
- Do a separate compilation unit on hygon microcode loading support.
- Use "access_sdnctl_in_dword" instead of "hygon_dword_acess" for accessing the HDA registers.
Fu Hao (5):
x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon models
0x4 through 0x8
x86/cpu: Get LLC ID for Hygon processor models 0x6 through 0x8 x86/cpu/hygon: Remove Spectral Chicken for Hygon processors perf/x86/uncore: Add L3 PMU support for Hygon family 18h model 6h x86/microcode/hygon: Add microcode loading support for Hygon
processors
arch/x86/Kconfig | 2 +- arch/x86/events/amd/uncore.c | 48 +- arch/x86/include/asm/perf_event.h | 8 + arch/x86/kernel/cpu/cacheinfo.c | 21 +- arch/x86/kernel/cpu/hygon.c | 19 +- arch/x86/kernel/cpu/microcode/Makefile | 1 + arch/x86/kernel/cpu/microcode/core.c | 17 +- arch/x86/kernel/cpu/microcode/hygon.c | 824 +++++++++++++++++++++++ arch/x86/kernel/cpu/microcode/internal.h | 20 + 9 files changed, 948 insertions(+), 12 deletions(-) create mode 100644 arch/x86/kernel/cpu/microcode/hygon.c
Signature · 1 line
2.34.1
PATCH v4 1/5 x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon models 0x4 through 0x8
For Hygon processor models 0x4–0x8, the die ID should be obtained from the NodeId field in ECX of CPUID leaf 0x8000001e.
Starting with these models, Hygon CPUs support CPUID leaf 0xb but do not support leaf 0x80000026. Consequently, the die ID and logical die ID cannot be derived from the APIC ID space. CPUID leaf 0xb only supports core and package levels, it cannot enumerate die IDs within a socket.
However, we found that CPUID leaf 0x8000001e (ECX) provides the necessary information. In Hygon CPU design, the NodeId field [7:0] encodes both socket and die IDs in the format:
Bits [7:4]: socket ID
Bits [3:0]: die ID
We can calculate the correct IDs(die_id and logical_die_id) by parsing this field.
--- arch/x86/kernel/cpu/hygon.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/x86/kernel/cpu/hygon.c +13 -0
@@ -192,6 +192,19 @@ static void init_hygon(struct cpuinfo_x86 *c)init_hygon_cacheinfo (c); +/* +* Adjust the die_id and logical_die_id for Hygon models 0x4-0x8. +* In Hygon CPU design, the NodeId field of CPUID leaf 0x8000001e (ECX) +* is now fixed to represent the socket ID and die ID, allocated as +* 4 bits each: socket ID = NodeId[7:4], die ID = NodeId[3:0]. +*/ +if (c->x86_model >=0x4 && c->x86_model <=0x8 ) { + c->topo.die_id =cpuid_ecx (0x8000001e ) &0xff ; + c->topo.logical_die_id = (c->topo.die_id >>4 ) * +topology_amd_nodes_per_pkg () + + (c->topo.die_id &0xf ); + } +if (cpu_has (c,X86_FEATURE_SVM )) {rdmsrq (MSR_VM_CR , vm_cr);if (vm_cr &SVM_VM_CR_SVM_DIS_MASK ) {
Signature · 1 line
2.34.1
PATCH v4 2/5 x86/cpu: Get LLC ID for Hygon processor models 0x6 through 0x8
In reply to Fu HaoFor Hygon processors, the LLC ID comes from fixed bit of APIC ID regardless of whether SMT is enabled or not. Add support for Hygon processor models 0x6–0x8.
--- arch/x86/kernel/cpu/cacheinfo.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/cacheinfo.c +18 -3
@@ -342,10 +342,25 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c)return ;/* -* Hygons are similar to AMD Family 17h up to 1F models: LLC is -* at the core complex level. Core complex ID is ApicId[3]. +* LLC is at the core complex level. For Hygon processor +* models 0x0–0x5, core complex ID is similar to AMD Family +* 17h up to 1F models, which is ApicId[3]. For Hygon +* processor models 0x6 and 0x7/0x8, core complex ID is +* derived from APIC ID bit 4 and bit 5, respectively. */ - c->topo.llc_id = c->topo.apicid >>3 ; + +switch (c->x86_model) { +case 0x6 : + c->topo.llc_id = c->topo.apicid >>4 ; +break ; +case 0x7 : +case 0x8 : + c->topo.llc_id = c->topo.apicid >>5 ; +break ; +default : + c->topo.llc_id = c->topo.apicid >>3 ; +break ; + } }void init_amd_cacheinfo (struct cpuinfo_x86 *c)
Signature · 1 line
2.34.1
PATCH v4 3/5 x86/cpu/hygon: Remove Spectral Chicken for Hygon processors
In reply to Fu HaoIt's no need to set the Spectral chicken bit for all Hygon processors.
--- arch/x86/kernel/cpu/hygon.c | 6 ------ 1 file changed, 6 deletions(-)
arch/x86/kernel/cpu/hygon.c +0 -6
@@ -177,12 +177,6 @@ static void init_hygon(struct cpuinfo_x86 *c)set_cpu_cap (c,X86_FEATURE_REP_GOOD ); -/* -* XXX someone from Hygon needs to confirm this DTRT -* -init_spectral_chicken(c); -*/ -set_cpu_cap (c,X86_FEATURE_ZEN );set_cpu_cap (c,X86_FEATURE_CPB );
Signature · 1 line
2.34.1
PATCH v4 4/5 perf/x86/uncore: Add L3 PMU support for Hygon family 18h model 6h
In reply to Fu HaoAdjust the L3 PMU slicemask and threadmask for Hygon family 18h model 6h processor.
--- arch/x86/events/amd/uncore.c | 48 ++++++++++++++++++++++++++++++- arch/x86/include/asm/perf_event.h | 8 ++++++ 2 files changed, 55 insertions(+), 1 deletion(-)
arch/x86/events/amd/uncore.c +47 -1
@@ -309,6 +309,14 @@ amd_f17h_uncore_is_visible(struct kobject *kobj, struct attribute *attr, int i) attr->mode : 0; } +static umode_t +hygon_f18h_m6h_uncore_is_visible (struct kobject *kobj,struct attribute *attr,int i) +{ +return boot_cpu_data.x86 ==0x18 && + boot_cpu_data.x86_model >=0x6 && boot_cpu_data.x86_model <=0xf ? + attr->mode :0 ; +} +static umode_t amd_f19h_uncore_is_visible (struct kobject *kobj,struct attribute *attr,int i) {
@@ -360,6 +368,8 @@ DEFINE_UNCORE_FORMAT_ATTR(enallslices, enallslices, "config:46"); /* F19h L3DEFINE_UNCORE_FORMAT_ATTR (enallcores, enallcores,"config:47" );/* F19h L3 */ DEFINE_UNCORE_FORMAT_ATTR (sliceid, sliceid,"config:48-50" );/* F19h L3 */ DEFINE_UNCORE_FORMAT_ATTR (rdwrmask, rdwrmask,"config:8-9" );/* PerfMonV2 UMC */ +DEFINE_UNCORE_FORMAT_ATTR (slicemask4, slicemask,"config:28-31" );/* F18h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (threadmask32, threadmask,"config:32-63" );/* F18h L3 */ /* Common DF and NB attributes */ static struct attribute *amd_uncore_df_format_attr[] = {
@@ -389,6 +399,12 @@ static struct attribute *amd_f17h_uncore_l3_format_attr[] = { NULL, }; +/* F18h M06h unique L3 attributes */ +static struct attribute *hygon_f18h_m6h_uncore_l3_format_attr[] = { + &format_attr_slicemask4.attr,/* slicemask */ +NULL , +}; +/* F19h unique L3 attributes */ static struct attribute *amd_f19h_uncore_l3_format_attr[] = { &format_attr_coreid.attr,/* coreid */
@@ -414,6 +430,12 @@ static struct attribute_group amd_f17h_uncore_l3_format_group = { .is_visible = amd_f17h_uncore_is_visible, }; +static struct attribute_group hygon_f18h_m6h_uncore_l3_format_group = { + .name ="format" , + .attrs = hygon_f18h_m6h_uncore_l3_format_attr, + .is_visible = hygon_f18h_m6h_uncore_is_visible, +}; +static struct attribute_group amd_f19h_uncore_l3_format_group = { .name ="format" , .attrs = amd_f19h_uncore_l3_format_attr,
@@ -443,6 +465,11 @@ static const struct attribute_group *amd_uncore_l3_attr_update[] = { NULL, }; +static const struct attribute_group *hygon_uncore_l3_attr_update[] = { + &hygon_f18h_m6h_uncore_l3_format_group, +NULL , +}; +static const struct attribute_group *amd_uncore_umc_attr_groups[] = { &amd_uncore_attr_group, &amd_uncore_umc_format_group,
@@ -821,6 +848,12 @@ static int amd_uncore_l3_event_init(struct perf_event *event) mask =AMD64_L3_F19H_THREAD_MASK |AMD64_L3_EN_ALL_SLICES |AMD64_L3_EN_ALL_CORES ; +if (boot_cpu_data.x86 ==0x18 && + boot_cpu_data.x86_model >=0x6 && + boot_cpu_data.x86_model <=0xf ) + mask = ((config &HYGON_L3_SLICE_MASK ) ? :HYGON_L3_SLICE_MASK ) | + ((config &HYGON_L3_THREAD_MASK ) ? :HYGON_L3_THREAD_MASK ); + hwc->config |= mask;return 0 ;
@@ -878,7 +911,8 @@ int amd_uncore_l3_ctx_init(struct amd_uncore *uncore, unsigned int cpu) pmu->rdpmc_base =RDPMC_BASE_LLC ; pmu->group =amd_uncore_ctx_gid (uncore, cpu); -if (boot_cpu_data.x86 >=0x17 ) { +if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD && + boot_cpu_data.x86 >=0x17 ) { *l3_attr++ = &format_attr_event8.attr; *l3_attr++ = &format_attr_umask8.attr; *l3_attr++ = boot_cpu_data.x86 >= 0x19 ?
@@ -905,6 +939,18 @@ int amd_uncore_l3_ctx_init(struct amd_uncore *uncore, unsigned int cpu) .module = THIS_MODULE, }; +if (boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON && + boot_cpu_data.x86 ==0x18 ) { + *l3_attr++ = &format_attr_event8.attr; + *l3_attr++ = &format_attr_umask8.attr; +if (boot_cpu_data.x86_model >=0x6 && boot_cpu_data.x86_model <=0xf ) { + *l3_attr++ = &format_attr_threadmask32.attr; + pmu->pmu.attr_update = hygon_uncore_l3_attr_update; + }else { + *l3_attr++ = &format_attr_threadmask8.attr; + } + } +if (perf_pmu_register (&pmu->pmu, pmu->pmu.name,-1 )) {free_percpu (pmu->ctx); pmu->ctx =NULL ;
arch/x86/include/asm/perf_event.h +8 -0
@@ -91,6 +91,14 @@#define AMD64_L3_COREID_MASK \ (0x7ULL << AMD64_L3_COREID_SHIFT) +#define HYGON_L3_SLICE_SHIFT 28 +#define HYGON_L3_SLICE_MASK \ + (0xFULL << HYGON_L3_SLICE_SHIFT) + +#define HYGON_L3_THREAD_SHIFT 32 +#define HYGON_L3_THREAD_MASK \ + (0xFFFFFFFFULL << HYGON_L3_THREAD_SHIFT) +#define X86_RAW_EVENT_MASK \ (ARCH_PERFMON_EVENTSEL_EVENT | \ ARCH_PERFMON_EVENTSEL_UMASK | \
Signature · 1 line
2.34.1
PATCH v4 5/5 x86/microcode/hygon: Add microcode loading support for Hygon processors
In reply to Fu HaoAdd support for loading Hygon microcode.
There are two loading methods:
1. Loading from the initrd/builtin.
2. Late loading, which depends on the kernel configuration option CONFIG_MICROCODE_LATE_LOADING being enabled, and this option is usually disabled by default, so it's not recommended.
--- arch/x86/Kconfig | 2 +- arch/x86/kernel/cpu/microcode/Makefile | 1 + arch/x86/kernel/cpu/microcode/core.c | 17 +- arch/x86/kernel/cpu/microcode/hygon.c | 824 +++++++++++++++++++++++ arch/x86/kernel/cpu/microcode/internal.h | 20 + 5 files changed, 862 insertions(+), 2 deletions(-) create mode 100644 arch/x86/kernel/cpu/microcode/hygon.c
arch/x86/Kconfig +1 -1
@@ -1313,7 +1313,7 @@ config X86_REBOOTFIXUPS config MICROCODE def_bool y - depends on CPU_SUP_AMD || CPU_SUP_INTEL + depends on CPU_SUP_AMD || CPU_SUP_INTEL || CPU_SUP_HYGON select CRYPTO_LIB_SHA256 if CPU_SUP_AMD config MICROCODE_INITRD32
arch/x86/kernel/cpu/microcode/Makefile +1 -0
@@ -3,3 +3,4 @@ microcode-y := core.o obj-$(CONFIG_MICROCODE) += microcode.o microcode-$(CONFIG_CPU_SUP_INTEL) += intel.o microcode-$(CONFIG_CPU_SUP_AMD) += amd.o +microcode-$(CONFIG_CPU_SUP_HYGON) += hygon.o
arch/x86/kernel/cpu/microcode/core.c +16 -1
@@ -194,6 +194,9 @@ void __init load_ucode_bsp(void)return ; intel = false;break ; +case X86_VENDOR_HYGON : + intel = false; +break ;default :return ;
@@ -202,7 +205,11 @@ void __init load_ucode_bsp(void)if (intel)load_ucode_intel_bsp (&early_data);else -load_ucode_amd_bsp (&early_data, cpuid_1_eax); +if (x86_cpuid_vendor () ==X86_VENDOR_HYGON ) +load_ucode_hygon_bsp (&early_data, cpuid_1_eax); +else +load_ucode_amd_bsp (&early_data, cpuid_1_eax); + }void load_ucode_ap (void )
@@ -228,6 +235,9 @@ void load_ucode_ap(void)if (x86_family (cpuid_1_eax) >=0x10 )load_ucode_amd_ap (cpuid_1_eax);break ; +case X86_VENDOR_HYGON : +load_ucode_hygon_ap (cpuid_1_eax); +break ;default :break ; }
@@ -287,6 +297,9 @@ static void reload_early_microcode(unsigned int cpu)if (family >=0x10 )reload_ucode_amd (cpu);break ; +case X86_VENDOR_HYGON : +reload_ucode_hygon (cpu); +break ;default :break ; }
@@ -894,6 +907,8 @@ static int __init microcode_init(void) microcode_ops =init_intel_microcode (); else if (c->x86_vendor == X86_VENDOR_AMD) microcode_ops =init_amd_microcode (); + else if (c->x86_vendor == X86_VENDOR_HYGON) + microcode_ops =init_hygon_microcode (); else pr_err("no support for this CPU vendor\n");
arch/x86/kernel/cpu/microcode/hygon.c new file +824 -0
824 lines not on this page · raw message
arch/x86/kernel/cpu/microcode/internal.h +20 -0
@@ -60,6 +60,9 @@ struct cpio_data find_microcode_in_initrd(const char *path);#define CPUID_AMD1 QCHAR('A', 'u', 't', 'h')#define CPUID_AMD2 QCHAR('e', 'n', 't', 'i')#define CPUID_AMD3 QCHAR('c', 'A', 'M', 'D') +#define CPUID_HYGON1 QCHAR('H', 'y', 'g', 'o') +#define CPUID_HYGON2 QCHAR('n', 'G', 'e', 'n') +#define CPUID_HYGON3 QCHAR('u', 'i', 'n', 'e')#define CPUID_IS (a, b, c, ebx, ecx, edx) \ (!(((ebx) ^ (a)) | ((edx) ^ (b)) | ((ecx) ^ (c))))
@@ -86,6 +89,9 @@ static inline int x86_cpuid_vendor(void)if (CPUID_IS (CPUID_AMD1 ,CPUID_AMD2 ,CPUID_AMD3 , ebx, ecx, edx))return X86_VENDOR_AMD ; +if (CPUID_IS (CPUID_HYGON1 ,CPUID_HYGON2 ,CPUID_HYGON3 , ebx, ecx, edx)) +return X86_VENDOR_HYGON ; +return X86_VENDOR_UNKNOWN ; }
@@ -127,6 +133,20 @@ static inline void reload_ucode_intel(void) { }static inline struct microcode_ops *init_intel_microcode (void ) {return NULL ; }#endif /* !CONFIG_CPU_SUP_INTEL */ +#ifdef CONFIG_CPU_SUP_HYGON +void load_ucode_hygon_bsp (struct early_load_data *ed,unsigned int family); +void load_ucode_hygon_ap (unsigned int family); +void reload_ucode_hygon (unsigned int cpu); +struct microcode_ops *init_hygon_microcode (void ); +void exit_hygon_microcode (void ); +#else /* CONFIG_CPU_SUP_HYGON */ +static inline void load_ucode_hygon_bsp (struct early_load_data *ed,unsigned int family) { } +static inline void load_ucode_hygon_ap (unsigned int family) { } +static inline void reload_ucode_hygon (unsigned int cpu) { } +static inline struct microcode_ops *init_hygon_microcode (void ) {return NULL ; } +static inline void exit_hygon_microcode (void ) { } +#endif /* !CONFIG_CPU_SUP_HYGON */ +#define ucode_dbg (fmt, ...) \ ({ \ if (IS_ENABLED(CONFIG_MICROCODE_DBG)) \
Signature · 1 line
2.34.1
Borislav Petkov
maintainerQuoted 2 lines · Fu Hao
This patch series introduce support for the new-generation Hygon processor models 0x4–0x8, addressing five key areas:
Sashiko flagged a bunch of things:
https://sashiko.dev/#/patchset/cover.1783653390.git.fuhao%40open-hieco.net
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 8 lines · Borislav Petkov
Quoted 2 lines · Fu Hao
This patch series introduce support for the new-generation Hygon processor models 0x4–0x8, addressing five key areas:
Sashiko flagged a bunch of things:
https://sashiko.dev/#/patchset/cover.1783653390.git.fuhao%40open-hieco.net
Hi Boris,
Thanks. I went through the feedback from Sashiko carefully. Here is the clarification from the Hygon side:
For the current Hygon processor models 0x4 through 0x8, the hardware dose not support the 0x80000026 CPUID leaf. Because of this, the true die ID cannot be obtained correctly through the generic x86 topology subsystem. Prior to this patch, the generic x86 topology code would wrongly resolve both the die ID and the socket ID to the same value on Hygon parts, so the die-level topology information was effectively lost.
Regarding your concern that logical IDs must remain contiguous: based on the current Hygon implementation of CPUID 0x8000001e (ECX), contiguity is in fact guaranteed. The lower 4 bits of ECX are laid out sequentially and contiguously, and this layout stays compatible with __amd_nodes_per_pkg.
So we believe the logical ID constraint is satisfied by the existing hardware behavior, and this patch does not introduce any discontinuity for Hygon processor.
We will add a !boot_cpu_has(X86_FEATURE_HYPERVISOR) check in the v5 patch series(for patch 1 and patch 2). In a virtualized guest the 0x8000001e ECX layout is not guaranteed to be contiguous (the VMM owns that value), so we should simply fall back to the generic topology path there.
For the microcode part of the patch, some areas need adjustment and will be updated in v5.
Signature · 2 lines
Regards, Fu Hao