x86/cpufeature: Add facility to check for min microcode revisions
Subsystems (2)
PATCH v7 1/5 x86/cpufeature: Add facility to check for min microcode revisions
From: Kan Liang <[email protected]>
For bug workarounds or checks, it is useful to check for specific microcode revisions.
Add a new generic function to match the CPU with stepping. Add the other function to check the min microcode revisions for the matched CPU.
A new table format is introduced to facilitate the quirk to fill the related information.
This does not change the existing x86_cpu_id because it's an ABI shared with modules, and also has quite different requirements, as in no wildcards, but everything has to be matched exactly.
---
No changes since V6
arch/x86/include/asm/cpu_device_id.h | 28 ++++++++++++++++++++++++++++ arch/x86/kernel/cpu/match.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
arch/x86/include/asm/cpu_device_id.h +28 -0
@@ -11,4 +11,32 @@extern const struct x86_cpu_id *x86_match_cpu (const struct x86_cpu_id *match); +/* +* Match specific microcode revisions. +* +* vendor/family/model/stepping must be all set. +* +* only checks against the boot CPU. When mixed-stepping configs are +* valid for a CPU model, add a quirk for every valid stepping and +* do the fine-tuning in the quirk handler. +*/ + +struct x86_cpu_desc { +__u8 x86;/* CPU family */ +__u8 x86_vendor;/* CPU vendor */ +__u8 x86_model; +__u8 x86_stepping; +__u32 x86_microcode_rev; +}; + +#define INTEL_CPU_DESC (mod, step, rev) { \ + .x86 = 6, \ + .x86_vendor = X86_VENDOR_INTEL, \ + .x86_model = mod, \ + .x86_stepping = step, \ + .x86_microcode_rev = rev, \ +} + +extern bool x86_cpu_has_min_microcode_rev (const struct x86_cpu_desc *table); +#endif
arch/x86/kernel/cpu/match.c +31 -0
@@ -48,3 +48,34 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)return NULL ; }EXPORT_SYMBOL (x86_match_cpu); + +static const struct x86_cpu_desc * +x86_match_cpu_with_stepping (const struct x86_cpu_desc *match) +{ +struct cpuinfo_x86 *c = &boot_cpu_data; +const struct x86_cpu_desc *m; + +for (m = match; m->x86 | m->x86_model; m++) { +if (c->x86_vendor != m->x86_vendor) +continue ; +if (c->x86 != m->x86) +continue ; +if (c->x86_model != m->x86_model) +continue ; +if (c->x86_stepping != m->x86_stepping) +continue ; +return m; + } +return NULL ; +} + +bool x86_cpu_has_min_microcode_rev (const struct x86_cpu_desc *table) +{ +const struct x86_cpu_desc *res =x86_match_cpu_with_stepping (table); + +if (!res || res->x86_microcode_rev > boot_cpu_data.microcode) +return false; + +return true; +} +EXPORT_SYMBOL_GPL (x86_cpu_has_min_microcode_rev);
Signature · 1 line
2.7.4
PATCH v7 2/5 perf/x86/kvm: Avoid unnecessary work in guest filtering
From: Andi Kleen <[email protected]>
KVM added a workaround for PEBS events leaking into guests with commit 26a4f3c08de4 ("perf/x86: disable PEBS on a guest entry.") This uses the VT entry/exit list to add an extra disable of the PEBS_ENABLE MSR.
Intel also added a fix for this issue to microcode updates on Haswell/Broadwell/Skylake.
It turns out using the MSR entry/exit list makes VM exits significantly slower. The list is only needed for disabling PEBS, because the GLOBAL_CTRL change gets optimized by KVM into changing the VMCS.
Check for the microcode updates that have the microcode fix for leaking PEBS, and disable the extra entry/exit list entry for PEBS_ENABLE. In addition we always clear the GLOBAL_CTRL for the PEBS counter while running in the guest, which is enough to make them never fire at the wrong side of the host/guest transition.
The overhead for VM exits with the filtering active with the patch is reduced from 8% to 4%.
The microcode patch has already been merged into future platforms. This patch is one-off thing. The quirks is used here.
For other old platforms which doesn't have microcode patch and quirks, extra disable of the PEBS_ENABLE MSR is still required.
---
Changes since V6:
- Remove check for CANNONLAKE
- Move pebs_no_isolation to intel_ds_init() to reduce the noisy
- Rename intel_check_isolation() to intel_check_pebs_isolation() and intel_isolation_quirk() to intel_pebs_isolation_quirk()
Keep the KABYLAKE check as is. Because it is one off.
arch/x86/events/intel/core.c | 74 ++++++++++++++++++++++++++++++++++++++------ arch/x86/events/intel/ds.c | 2 ++ arch/x86/events/perf_event.h | 15 ++++----- 3 files changed, 75 insertions(+), 16 deletions(-)
arch/x86/events/intel/core.c +65 -9
@@ -18,6 +18,7 @@#include <asm/hardirq.h> #include <asm/intel-family.h> #include <asm/apic.h> +#include <asm/cpu_device_id.h> #include "../perf_event.h"
@@ -3206,16 +3207,27 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) arr[0 ].msr =MSR_CORE_PERF_GLOBAL_CTRL ; arr[0 ].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask; arr[0 ].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask; -/* -* If PMU counter has PEBS enabled it is not enough to disable counter -* on a guest entry since PEBS memory write can overshoot guest entry -* and corrupt guest memory. Disabling PEBS solves the problem. -*/ - arr[1 ].msr =MSR_IA32_PEBS_ENABLE ; - arr[1 ].host = cpuc->pebs_enabled; - arr[1 ].guest =0 ; +if (x86_pmu.flags &PMU_FL_PEBS_ALL ) + arr[0 ].guest &= ~cpuc->pebs_enabled; +else + arr[0 ].guest &= ~(cpuc->pebs_enabled &PEBS_COUNTER_MASK ); + *nr =1 ; + +if (x86_pmu.pebs && x86_pmu.pebs_no_isolation) { +/* +* If PMU counter has PEBS enabled it is not enough to +* disable counter on a guest entry since PEBS memory +* write can overshoot guest entry and corrupt guest +* memory. Disabling PEBS solves the problem. +* +* Don't do this if the CPU already enforces it. +*/ + arr[1 ].msr =MSR_IA32_PEBS_ENABLE ; + arr[1 ].host = cpuc->pebs_enabled; + arr[1 ].guest =0 ; + *nr =2 ; + } - *nr =2 ;return arr; }
@@ -3733,6 +3745,47 @@ static __init void intel_clovertown_quirk(void) x86_pmu.pebs_constraints =NULL ; } +static const struct x86_cpu_desc isolation_ucodes[] = { +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_CORE ,3 ,0x0000001f ), +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_ULT ,1 ,0x0000001e ), +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_GT3E ,1 ,0x00000015 ), +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_X ,2 ,0x00000037 ), +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_X ,4 ,0x0000000a ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_CORE ,4 ,0x00000023 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_GT3E ,1 ,0x00000014 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_XEON_D ,2 ,0x00000010 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_XEON_D ,3 ,0x07000009 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_XEON_D ,4 ,0x0f000009 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_XEON_D ,5 ,0x0e000002 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_X ,2 ,0x0b000014 ), +INTEL_CPU_DESC (INTEL_FAM6_SKYLAKE_X ,3 ,0x00000021 ), +INTEL_CPU_DESC (INTEL_FAM6_SKYLAKE_X ,4 ,0x00000000 ), +INTEL_CPU_DESC (INTEL_FAM6_SKYLAKE_MOBILE ,3 ,0x0000007c ), +INTEL_CPU_DESC (INTEL_FAM6_SKYLAKE_DESKTOP ,3 ,0x0000007c ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,9 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_MOBILE ,9 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_MOBILE ,10 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_MOBILE ,11 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_MOBILE ,12 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,10 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,11 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,12 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,13 ,0x0000004e ), + {} +}; + +static void intel_check_pebs_isolation (void ) +{ + x86_pmu.pebs_no_isolation = !x86_cpu_has_min_microcode_rev (isolation_ucodes); +} + +static __init void intel_pebs_isolation_quirk (void ) +{ +WARN_ON_ONCE (x86_pmu.check_microcode); + x86_pmu.check_microcode = intel_check_pebs_isolation; +intel_check_pebs_isolation (); +} +static int intel_snb_pebs_broken (int cpu) {u32 rev =UINT_MAX ;/* default to broken for unknown models */
@@ -4425,6 +4478,7 @@ __init int intel_pmu_init(void)case INTEL_FAM6_HASWELL_ULT :case INTEL_FAM6_HASWELL_GT3E :x86_add_quirk (intel_ht_bug); +x86_add_quirk (intel_pebs_isolation_quirk); x86_pmu.late_ack = true;memcpy (hw_cache_event_ids, hsw_hw_cache_event_ids,sizeof (hw_cache_event_ids));memcpy (hw_cache_extra_regs, hsw_hw_cache_extra_regs,sizeof (hw_cache_extra_regs));
@@ -4456,6 +4510,7 @@ __init int intel_pmu_init(void)case INTEL_FAM6_BROADWELL_XEON_D :case INTEL_FAM6_BROADWELL_GT3E :case INTEL_FAM6_BROADWELL_X : +x86_add_quirk (intel_pebs_isolation_quirk); x86_pmu.late_ack = true;memcpy (hw_cache_event_ids, hsw_hw_cache_event_ids,sizeof (hw_cache_event_ids));memcpy (hw_cache_extra_regs, hsw_hw_cache_extra_regs,sizeof (hw_cache_extra_regs));
@@ -4518,6 +4573,7 @@ __init int intel_pmu_init(void)case INTEL_FAM6_SKYLAKE_X :case INTEL_FAM6_KABYLAKE_MOBILE :case INTEL_FAM6_KABYLAKE_DESKTOP : +x86_add_quirk (intel_pebs_isolation_quirk); x86_pmu.late_ack = true;memcpy (hw_cache_event_ids, skl_hw_cache_event_ids,sizeof (hw_cache_event_ids));memcpy (hw_cache_extra_regs, skl_hw_cache_extra_regs,sizeof (hw_cache_extra_regs));
arch/x86/events/intel/ds.c +2 -0
@@ -1628,6 +1628,8 @@ void __init intel_ds_init(void) x86_pmu.bts =boot_cpu_has (X86_FEATURE_BTS ); x86_pmu.pebs =boot_cpu_has (X86_FEATURE_PEBS ); x86_pmu.pebs_buffer_size =PEBS_BUFFER_SIZE ; +if (x86_pmu.version <5 ) + x86_pmu.pebs_no_isolation =1 ;if (x86_pmu.pebs) {char pebs_type = x86_pmu.intel_cap.pebs_trap ?'+' :'-' ;int format = x86_pmu.intel_cap.pebs_format;
arch/x86/events/perf_event.h +8 -7
@@ -601,13 +601,14 @@ struct x86_pmu {/* * Intel DebugStore bits */ - unsigned int bts :1, - bts_active :1, - pebs :1, - pebs_active :1, - pebs_broken :1, - pebs_prec_dist :1, - pebs_no_tlb :1; + unsigned int bts :1, + bts_active :1, + pebs :1, + pebs_active :1, + pebs_broken :1, + pebs_prec_dist :1, + pebs_no_tlb :1, + pebs_no_isolation :1;int pebs_record_size;int pebs_buffer_size;void (*drain_pebs)(struct pt_regs *regs);
Signature · 1 line
2.7.4
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf/x86/kvm: Avoid unnecessary work in guest filtering
perf/x86/kvm: Avoid unnecessary work in guest filtering
Commit-ID: 9b545c04abd4f7246a3bde040efde587abebb23c Gitweb: https://git.kernel.org/tip/9b545c04abd4f7246a3bde040efde587abebb23c Author: Andi Kleen <[email protected]> AuthorDate: Mon, 4 Feb 2019 14:23:30 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 11 Feb 2019 08:00:39 +0100
perf/x86/kvm: Avoid unnecessary work in guest filtering
KVM added a workaround for PEBS events leaking into guests with commit:
26a4f3c08de4 ("perf/x86: disable PEBS on a guest entry.")
This uses the VT entry/exit list to add an extra disable of the PEBS_ENABLE MSR.
Intel also added a fix for this issue to microcode updates on Haswell/Broadwell/Skylake.
It turns out using the MSR entry/exit list makes VM exits significantly slower. The list is only needed for disabling PEBS, because the GLOBAL_CTRL change gets optimized by KVM into changing the VMCS.
Check for the microcode updates that have the microcode fix for leaking PEBS, and disable the extra entry/exit list entry for PEBS_ENABLE. In addition we always clear the GLOBAL_CTRL for the PEBS counter while running in the guest, which is enough to make them never fire at the wrong side of the host/guest transition.
The overhead for VM exits with the filtering active with the patch is reduced from 8% to 4%.
The microcode patch has already been merged into future platforms. This patch is one-off thing. The quirks is used here.
For other old platforms which doesn't have microcode patch and quirks, extra disable of the PEBS_ENABLE MSR is still required.
--- arch/x86/events/intel/core.c | 74 ++++++++++++++++++++++++++++++++++++++------ arch/x86/events/intel/ds.c | 2 ++ arch/x86/events/perf_event.h | 15 ++++----- 3 files changed, 75 insertions(+), 16 deletions(-)
arch/x86/events/intel/core.c +65 -9
@@ -18,6 +18,7 @@#include <asm/hardirq.h> #include <asm/intel-family.h> #include <asm/apic.h> +#include <asm/cpu_device_id.h> #include "../perf_event.h"
@@ -3206,16 +3207,27 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) arr[0 ].msr =MSR_CORE_PERF_GLOBAL_CTRL ; arr[0 ].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask; arr[0 ].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask; -/* -* If PMU counter has PEBS enabled it is not enough to disable counter -* on a guest entry since PEBS memory write can overshoot guest entry -* and corrupt guest memory. Disabling PEBS solves the problem. -*/ - arr[1 ].msr =MSR_IA32_PEBS_ENABLE ; - arr[1 ].host = cpuc->pebs_enabled; - arr[1 ].guest =0 ; +if (x86_pmu.flags &PMU_FL_PEBS_ALL ) + arr[0 ].guest &= ~cpuc->pebs_enabled; +else + arr[0 ].guest &= ~(cpuc->pebs_enabled &PEBS_COUNTER_MASK ); + *nr =1 ; + +if (x86_pmu.pebs && x86_pmu.pebs_no_isolation) { +/* +* If PMU counter has PEBS enabled it is not enough to +* disable counter on a guest entry since PEBS memory +* write can overshoot guest entry and corrupt guest +* memory. Disabling PEBS solves the problem. +* +* Don't do this if the CPU already enforces it. +*/ + arr[1 ].msr =MSR_IA32_PEBS_ENABLE ; + arr[1 ].host = cpuc->pebs_enabled; + arr[1 ].guest =0 ; + *nr =2 ; + } - *nr =2 ;return arr; }
@@ -3739,6 +3751,47 @@ static __init void intel_clovertown_quirk(void) x86_pmu.pebs_constraints =NULL ; } +static const struct x86_cpu_desc isolation_ucodes[] = { +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_CORE ,3 ,0x0000001f ), +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_ULT ,1 ,0x0000001e ), +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_GT3E ,1 ,0x00000015 ), +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_X ,2 ,0x00000037 ), +INTEL_CPU_DESC (INTEL_FAM6_HASWELL_X ,4 ,0x0000000a ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_CORE ,4 ,0x00000023 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_GT3E ,1 ,0x00000014 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_XEON_D ,2 ,0x00000010 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_XEON_D ,3 ,0x07000009 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_XEON_D ,4 ,0x0f000009 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_XEON_D ,5 ,0x0e000002 ), +INTEL_CPU_DESC (INTEL_FAM6_BROADWELL_X ,2 ,0x0b000014 ), +INTEL_CPU_DESC (INTEL_FAM6_SKYLAKE_X ,3 ,0x00000021 ), +INTEL_CPU_DESC (INTEL_FAM6_SKYLAKE_X ,4 ,0x00000000 ), +INTEL_CPU_DESC (INTEL_FAM6_SKYLAKE_MOBILE ,3 ,0x0000007c ), +INTEL_CPU_DESC (INTEL_FAM6_SKYLAKE_DESKTOP ,3 ,0x0000007c ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,9 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_MOBILE ,9 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_MOBILE ,10 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_MOBILE ,11 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_MOBILE ,12 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,10 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,11 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,12 ,0x0000004e ), +INTEL_CPU_DESC (INTEL_FAM6_KABYLAKE_DESKTOP ,13 ,0x0000004e ), + {} +}; + +static void intel_check_pebs_isolation (void ) +{ + x86_pmu.pebs_no_isolation = !x86_cpu_has_min_microcode_rev (isolation_ucodes); +} + +static __init void intel_pebs_isolation_quirk (void ) +{ +WARN_ON_ONCE (x86_pmu.check_microcode); + x86_pmu.check_microcode = intel_check_pebs_isolation; +intel_check_pebs_isolation (); +} +static int intel_snb_pebs_broken (int cpu) {u32 rev =UINT_MAX ;/* default to broken for unknown models */
@@ -4431,6 +4484,7 @@ __init int intel_pmu_init(void)case INTEL_FAM6_HASWELL_ULT :case INTEL_FAM6_HASWELL_GT3E :x86_add_quirk (intel_ht_bug); +x86_add_quirk (intel_pebs_isolation_quirk); x86_pmu.late_ack = true;memcpy (hw_cache_event_ids, hsw_hw_cache_event_ids,sizeof (hw_cache_event_ids));memcpy (hw_cache_extra_regs, hsw_hw_cache_extra_regs,sizeof (hw_cache_extra_regs));
@@ -4462,6 +4516,7 @@ __init int intel_pmu_init(void)case INTEL_FAM6_BROADWELL_XEON_D :case INTEL_FAM6_BROADWELL_GT3E :case INTEL_FAM6_BROADWELL_X : +x86_add_quirk (intel_pebs_isolation_quirk); x86_pmu.late_ack = true;memcpy (hw_cache_event_ids, hsw_hw_cache_event_ids,sizeof (hw_cache_event_ids));memcpy (hw_cache_extra_regs, hsw_hw_cache_extra_regs,sizeof (hw_cache_extra_regs));
@@ -4524,6 +4579,7 @@ __init int intel_pmu_init(void)case INTEL_FAM6_SKYLAKE_X :case INTEL_FAM6_KABYLAKE_MOBILE :case INTEL_FAM6_KABYLAKE_DESKTOP : +x86_add_quirk (intel_pebs_isolation_quirk); x86_pmu.late_ack = true;memcpy (hw_cache_event_ids, skl_hw_cache_event_ids,sizeof (hw_cache_event_ids));memcpy (hw_cache_extra_regs, skl_hw_cache_extra_regs,sizeof (hw_cache_extra_regs));
arch/x86/events/intel/ds.c +2 -0
@@ -1628,6 +1628,8 @@ void __init intel_ds_init(void) x86_pmu.bts =boot_cpu_has (X86_FEATURE_BTS ); x86_pmu.pebs =boot_cpu_has (X86_FEATURE_PEBS ); x86_pmu.pebs_buffer_size =PEBS_BUFFER_SIZE ; +if (x86_pmu.version <=4 ) + x86_pmu.pebs_no_isolation =1 ;if (x86_pmu.pebs) {char pebs_type = x86_pmu.intel_cap.pebs_trap ?'+' :'-' ;int format = x86_pmu.intel_cap.pebs_format;
arch/x86/events/perf_event.h +8 -7
@@ -601,13 +601,14 @@ struct x86_pmu {/* * Intel DebugStore bits */ - unsigned int bts :1, - bts_active :1, - pebs :1, - pebs_active :1, - pebs_broken :1, - pebs_prec_dist :1, - pebs_no_tlb :1; + unsigned int bts :1, + bts_active :1, + pebs :1, + pebs_active :1, + pebs_broken :1, + pebs_prec_dist :1, + pebs_no_tlb :1, + pebs_no_isolation :1;int pebs_record_size;int pebs_buffer_size;void (*drain_pebs)(struct pt_regs *regs);
PATCH v7 3/5 perf/x86/intel: Clean up SNB pebs quirk
In reply to [email protected]From: Kan Liang <[email protected]>
Clean up SNB pebs quirk to use the new facility to check for min microcode revisions.
Only check the boot CPU, assuming models and features are consistent over all CPUs.
---
No changes since V6
arch/x86/events/intel/core.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-)
arch/x86/events/intel/core.c +10 -25
@@ -3786,36 +3786,21 @@ static __init void intel_pebs_isolation_quirk(void)intel_check_pebs_isolation (); } -static int intel_snb_pebs_broken (int cpu) -{ -u32 rev =UINT_MAX ;/* default to broken for unknown models */ - -switch (cpu_data (cpu).x86_model) { -case INTEL_FAM6_SANDYBRIDGE : - rev =0x28 ; -break ; - -case INTEL_FAM6_SANDYBRIDGE_X : -switch (cpu_data (cpu).x86_stepping) { -case 6 : rev =0x618 ;break ; -case 7 : rev =0x70c ;break ; - } - } +static const struct x86_cpu_desc pebs_ucodes[] = { +INTEL_CPU_DESC (INTEL_FAM6_SANDYBRIDGE ,7 ,0x00000028 ), +INTEL_CPU_DESC (INTEL_FAM6_SANDYBRIDGE_X ,6 ,0x00000618 ), +INTEL_CPU_DESC (INTEL_FAM6_SANDYBRIDGE_X ,7 ,0x0000070c ), + {} +}; -return (cpu_data (cpu).microcode < rev); +static bool intel_snb_pebs_broken (void ) +{ +return !x86_cpu_has_min_microcode_rev (pebs_ucodes); }static void intel_snb_check_microcode (void ) { -int pebs_broken =0 ; -int cpu; - -for_each_online_cpu (cpu) { -if ((pebs_broken =intel_snb_pebs_broken (cpu))) -break ; - } - -if (pebs_broken == x86_pmu.pebs_broken) +if (intel_snb_pebs_broken () == x86_pmu.pebs_broken)return ;/*
Signature · 1 line
2.7.4
tip-bot for Kan Liang
merge bot[tip:perf/core] perf/x86/intel: Clean up SNB PEBS quirk
perf/x86/intel: Clean up SNB PEBS quirk
Commit-ID: a96fff8df28ddd2f6710e5af454a45014c73183c Gitweb: https://git.kernel.org/tip/a96fff8df28ddd2f6710e5af454a45014c73183c Author: Kan Liang <[email protected]> AuthorDate: Mon, 4 Feb 2019 14:23:31 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 11 Feb 2019 08:00:40 +0100
perf/x86/intel: Clean up SNB PEBS quirk
Clean up SNB PEBS quirk to use the new facility to check for min microcode revisions.
Only check the boot CPU, assuming models and features are consistent over all CPUs.
--- arch/x86/events/intel/core.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-)
arch/x86/events/intel/core.c +10 -25
@@ -3792,36 +3792,21 @@ static __init void intel_pebs_isolation_quirk(void)intel_check_pebs_isolation (); } -static int intel_snb_pebs_broken (int cpu) -{ -u32 rev =UINT_MAX ;/* default to broken for unknown models */ - -switch (cpu_data (cpu).x86_model) { -case INTEL_FAM6_SANDYBRIDGE : - rev =0x28 ; -break ; - -case INTEL_FAM6_SANDYBRIDGE_X : -switch (cpu_data (cpu).x86_stepping) { -case 6 : rev =0x618 ;break ; -case 7 : rev =0x70c ;break ; - } - } +static const struct x86_cpu_desc pebs_ucodes[] = { +INTEL_CPU_DESC (INTEL_FAM6_SANDYBRIDGE ,7 ,0x00000028 ), +INTEL_CPU_DESC (INTEL_FAM6_SANDYBRIDGE_X ,6 ,0x00000618 ), +INTEL_CPU_DESC (INTEL_FAM6_SANDYBRIDGE_X ,7 ,0x0000070c ), + {} +}; -return (cpu_data (cpu).microcode < rev); +static bool intel_snb_pebs_broken (void ) +{ +return !x86_cpu_has_min_microcode_rev (pebs_ucodes); }static void intel_snb_check_microcode (void ) { -int pebs_broken =0 ; -int cpu; - -for_each_online_cpu (cpu) { -if ((pebs_broken =intel_snb_pebs_broken (cpu))) -break ; - } - -if (pebs_broken == x86_pmu.pebs_broken) +if (intel_snb_pebs_broken () == x86_pmu.pebs_broken)return ;/*
PATCH v7 4/5 perf/x86/intel: Clean up counter freezing quirk
In reply to [email protected]From: Kan Liang <[email protected]>
Clean up counter freezing quirk to use the new facility to check for min microcode revisions.
Rename the counter freezing quirk related functions. Because other platforms, e.g. Goldmont, also needs to call the quirk.
Only check the boot CPU, assuming models and features are consistent over all CPUs.
---
No changes since V6
arch/x86/events/intel/core.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
arch/x86/events/intel/core.c +11 -16
@@ -3917,23 +3917,18 @@ static __init void intel_nehalem_quirk(void) } } -static bool intel_glp_counter_freezing_broken (int cpu) -{ -u32 rev =UINT_MAX ;/* default to broken for unknown stepping */ - -switch (cpu_data (cpu).x86_stepping) { -case 1 : - rev =0x28 ; -break ; -case 8 : - rev =0x6 ; -break ; - } +static const struct x86_cpu_desc counter_freezing_ucodes[] = { +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,1 ,0x00000028 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,8 ,0x00000006 ), + {} +}; -return (cpu_data (cpu).microcode < rev); +static bool intel_counter_freezing_broken (void ) +{ +return !x86_cpu_has_min_microcode_rev (counter_freezing_ucodes); } -static __init void intel_glp_counter_freezing_quirk (void ) +static __init void intel_counter_freezing_quirk (void ) {/* Check if it's already disabled */ if (disable_counter_freezing)
@@ -3943,7 +3938,7 @@ static __init void intel_glp_counter_freezing_quirk(void)* If the system starts with the wrong ucode, leave the * counter-freezing feature permanently disabled. */ -if (intel_glp_counter_freezing_broken (raw_smp_processor_id ())) { +if (intel_counter_freezing_broken ()) {pr_info ("PMU counter freezing disabled due to CPU errata," "please upgrade microcode\n" ); x86_pmu.counter_freezing = false;
@@ -4320,7 +4315,7 @@ __init int intel_pmu_init(void)break ;case INTEL_FAM6_ATOM_GOLDMONT_PLUS : -x86_add_quirk (intel_glp_counter_freezing_quirk); +x86_add_quirk (intel_counter_freezing_quirk);memcpy (hw_cache_event_ids, glp_hw_cache_event_ids,sizeof (hw_cache_event_ids)); memcpy(hw_cache_extra_regs, glp_hw_cache_extra_regs,
Signature · 1 line
2.7.4
tip-bot for Kan Liang
merge bot[tip:perf/core] perf/x86/intel: Clean up counter freezing quirk
perf/x86/intel: Clean up counter freezing quirk
Commit-ID: bef9f2714f8cf036af3af52a15f534d2cc40c230 Gitweb: https://git.kernel.org/tip/bef9f2714f8cf036af3af52a15f534d2cc40c230 Author: Kan Liang <[email protected]> AuthorDate: Mon, 4 Feb 2019 14:23:32 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 11 Feb 2019 08:00:41 +0100
perf/x86/intel: Clean up counter freezing quirk
Clean up counter freezing quirk to use the new facility to check for min microcode revisions.
Rename the counter freezing quirk related functions. Because other platforms, e.g. Goldmont, also needs to call the quirk.
Only check the boot CPU, assuming models and features are consistent over all CPUs.
--- arch/x86/events/intel/core.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
arch/x86/events/intel/core.c +11 -16
@@ -3923,23 +3923,18 @@ static __init void intel_nehalem_quirk(void) } } -static bool intel_glp_counter_freezing_broken (int cpu) -{ -u32 rev =UINT_MAX ;/* default to broken for unknown stepping */ - -switch (cpu_data (cpu).x86_stepping) { -case 1 : - rev =0x28 ; -break ; -case 8 : - rev =0x6 ; -break ; - } +static const struct x86_cpu_desc counter_freezing_ucodes[] = { +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,1 ,0x00000028 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,8 ,0x00000006 ), + {} +}; -return (cpu_data (cpu).microcode < rev); +static bool intel_counter_freezing_broken (void ) +{ +return !x86_cpu_has_min_microcode_rev (counter_freezing_ucodes); } -static __init void intel_glp_counter_freezing_quirk (void ) +static __init void intel_counter_freezing_quirk (void ) {/* Check if it's already disabled */ if (disable_counter_freezing)
@@ -3949,7 +3944,7 @@ static __init void intel_glp_counter_freezing_quirk(void)* If the system starts with the wrong ucode, leave the * counter-freezing feature permanently disabled. */ -if (intel_glp_counter_freezing_broken (raw_smp_processor_id ())) { +if (intel_counter_freezing_broken ()) {pr_info ("PMU counter freezing disabled due to CPU errata," "please upgrade microcode\n" ); x86_pmu.counter_freezing = false;
@@ -4326,7 +4321,7 @@ __init int intel_pmu_init(void)break ;case INTEL_FAM6_ATOM_GOLDMONT_PLUS : -x86_add_quirk (intel_glp_counter_freezing_quirk); +x86_add_quirk (intel_counter_freezing_quirk);memcpy (hw_cache_event_ids, glp_hw_cache_event_ids,sizeof (hw_cache_event_ids)); memcpy(hw_cache_extra_regs, glp_hw_cache_extra_regs,
PATCH v7 5/5 perf/x86/intel: Add counter freezing quirk for Goldmont
In reply to [email protected]From: Kan Liang <[email protected]>
A microcode patch is also needed for Goldmont while counter freezing feature is enabled. Otherwise, there will be some issues, e.g. PMI lost.
---
No changes since V6
arch/x86/events/intel/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/events/intel/core.c +7 -2
@@ -3918,8 +3918,12 @@ static __init void intel_nehalem_quirk(void) }static const struct x86_cpu_desc counter_freezing_ucodes[] = { -INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,1 ,0x00000028 ), -INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,8 ,0x00000006 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT ,2 ,0x0000000e ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT ,9 ,0x0000002e ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT ,10 ,0x00000008 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_X ,1 ,0x00000028 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,1 ,0x00000028 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,8 ,0x00000006 ), {} };
@@ -4289,6 +4293,7 @@ __init int intel_pmu_init(void)case INTEL_FAM6_ATOM_GOLDMONT :case INTEL_FAM6_ATOM_GOLDMONT_X : +x86_add_quirk (intel_counter_freezing_quirk);memcpy (hw_cache_event_ids, glm_hw_cache_event_ids,sizeof (hw_cache_event_ids)); memcpy(hw_cache_extra_regs, glm_hw_cache_extra_regs,
Signature · 1 line
2.7.4
tip-bot for Kan Liang
merge bot[tip:perf/core] perf/x86/intel: Add counter freezing quirk for Goldmont
perf/x86/intel: Add counter freezing quirk for Goldmont
Commit-ID: af63147c1edacfb75a28885a7cd7e6f44e626164 Gitweb: https://git.kernel.org/tip/af63147c1edacfb75a28885a7cd7e6f44e626164 Author: Kan Liang <[email protected]> AuthorDate: Mon, 4 Feb 2019 14:23:33 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 11 Feb 2019 08:00:42 +0100
perf/x86/intel: Add counter freezing quirk for Goldmont
A microcode patch is also needed for Goldmont while counter freezing feature is enabled. Otherwise, there will be some issues, e.g. PMI lost.
--- arch/x86/events/intel/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/events/intel/core.c +7 -2
@@ -3924,8 +3924,12 @@ static __init void intel_nehalem_quirk(void) }static const struct x86_cpu_desc counter_freezing_ucodes[] = { -INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,1 ,0x00000028 ), -INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,8 ,0x00000006 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT ,2 ,0x0000000e ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT ,9 ,0x0000002e ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT ,10 ,0x00000008 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_X ,1 ,0x00000028 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,1 ,0x00000028 ), +INTEL_CPU_DESC (INTEL_FAM6_ATOM_GOLDMONT_PLUS ,8 ,0x00000006 ), {} };
@@ -4295,6 +4299,7 @@ __init int intel_pmu_init(void)case INTEL_FAM6_ATOM_GOLDMONT :case INTEL_FAM6_ATOM_GOLDMONT_X : +x86_add_quirk (intel_counter_freezing_quirk);memcpy (hw_cache_event_ids, glm_hw_cache_event_ids,sizeof (hw_cache_event_ids)); memcpy(hw_cache_extra_regs, glm_hw_cache_extra_regs,
Peter Zijlstra
maintainerQuoted 5 lines · On Mon, Feb 04, 2019 at 02:23:29PM -0800, [email protected] wrote:
extern const struct
x86_cpu_id*x86_match_cpu(const structx86_cpu_id*match);arch/x86/include/asm/cpu_device_id.h +3
-0+/* +* Match specific microcode revisions. +*
arch/x86/include/asm/cpu_device_id.h line 26
Quoted 10 lines
arch/x86/include/asm/cpu_device_id.h +10
-0+* vendor/family/model/stepping must be all set. +* +* only checks against the boot CPU. When mixed-stepping configs are +* valid for a CPU model, add a quirk for every valid stepping and +* do the fine-tuning in the quirk handler. +*/ + +struct x86_cpu_desc { +__u8 x86;/* CPU family */ +__u8 x86_vendor;/* CPU vendor */
So Boris asked me to remove the tail comments (done), but what about I
do: % s/\<x86\>/&_family/g, on the rest of this too? I know we have cpuinfo_x86::x86 history, but at some point we should rename that too.
Quoted 4 lines
arch/x86/include/asm/cpu_device_id.h +4
-0+__u8 x86_model; +__u8 x86_stepping; +__u32 x86_microcode_rev; +};
Borislav Petkov
maintainerQuoted 3 lines · Peter Zijlstra
So Boris asked me to remove the tail comments (done), but what about I
do: % s/\<x86\>/&_family/g, on the rest of this too? I know we havecpuinfo_x86::x86history, but at some point we should rename that too.
My argument was to keep them the same as cpuinfo_x86's members so that there's no confusion.
But renaming the family member to x86_family makes sense to me. We should do it some flag day.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.tip-bot for Kan Liang
merge botx86/cpufeature: Add facility to check for min microcode revisions
Commit-ID: 0f42b790c9ba5ec2f25b7da8b0b6d361082d67b0 Gitweb: https://git.kernel.org/tip/0f42b790c9ba5ec2f25b7da8b0b6d361082d67b0 Author: Kan Liang <[email protected]> AuthorDate: Mon, 4 Feb 2019 14:23:29 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 11 Feb 2019 07:59:23 +0100
x86/cpufeature: Add facility to check for min microcode revisions
For bug workarounds or checks, it is useful to check for specific microcode revisions.
Add a new generic function to match the CPU with stepping. Add the other function to check the min microcode revisions for the matched CPU.
A new table format is introduced to facilitate the quirk to fill the related information.
This does not change the existing x86_cpu_id because it's an ABI shared with modules, and also has quite different requirements, as in no wildcards, but everything has to be matched exactly.
--- arch/x86/include/asm/cpu_device_id.h | 28 ++++++++++++++++++++++++++++ arch/x86/kernel/cpu/match.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
arch/x86/include/asm/cpu_device_id.h +28 -0
@@ -11,4 +11,32 @@extern const struct x86_cpu_id *x86_match_cpu (const struct x86_cpu_id *match); +/* +* Match specific microcode revisions. +* +* vendor/family/model/stepping must be all set. +* +* Only checks against the boot CPU. When mixed-stepping configs are +* valid for a CPU model, add a quirk for every valid stepping and +* do the fine-tuning in the quirk handler. +*/ + +struct x86_cpu_desc { +__u8 x86_family; +__u8 x86_vendor; +__u8 x86_model; +__u8 x86_stepping; +__u32 x86_microcode_rev; +}; + +#define INTEL_CPU_DESC (mod, step, rev) { \ + .x86_family = 6, \ + .x86_vendor = X86_VENDOR_INTEL, \ + .x86_model = mod, \ + .x86_stepping = step, \ + .x86_microcode_rev = rev, \ +} + +extern bool x86_cpu_has_min_microcode_rev (const struct x86_cpu_desc *table); +#endif
arch/x86/kernel/cpu/match.c +31 -0
@@ -48,3 +48,34 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)return NULL ; }EXPORT_SYMBOL (x86_match_cpu); + +static const struct x86_cpu_desc * +x86_match_cpu_with_stepping (const struct x86_cpu_desc *match) +{ +struct cpuinfo_x86 *c = &boot_cpu_data; +const struct x86_cpu_desc *m; + +for (m = match; m->x86_family | m->x86_model; m++) { +if (c->x86_vendor != m->x86_vendor) +continue ; +if (c->x86 != m->x86_family) +continue ; +if (c->x86_model != m->x86_model) +continue ; +if (c->x86_stepping != m->x86_stepping) +continue ; +return m; + } +return NULL ; +} + +bool x86_cpu_has_min_microcode_rev (const struct x86_cpu_desc *table) +{ +const struct x86_cpu_desc *res =x86_match_cpu_with_stepping (table); + +if (!res || res->x86_microcode_rev > boot_cpu_data.microcode) +return false; + +return true; +} +EXPORT_SYMBOL_GPL (x86_cpu_has_min_microcode_rev);