Merge tag 'perf-urgent-2022-10-02' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull misc perf fixes from Ingo Molnar:

- Fix a PMU enumeration/initialization bug on Intel Alder Lake CPUs

- Fix KVM guest PEBS register handling

- Fix race/reentry bug in perf_output_read_group() reading of PMU
counters

* tag 'perf-urgent-2022-10-02' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/core: Fix reentry problem in perf_output_read_group()
perf/x86/core: Completely disable guest PEBS via guest's global_ctrl
perf/x86/intel: Fix unchecked MSR access error for Alder Lake N

+57 -3
+39 -1
arch/x86/events/intel/core.c
··· 2102 EVENT_EXTRA_END 2103 }; 2104 2105 static struct extra_reg intel_grt_extra_regs[] __read_mostly = { 2106 /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ 2107 INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x3fffffffffull, RSP_0), ··· 5984 name = "Tremont"; 5985 break; 5986 5987 case INTEL_FAM6_WESTMERE: 5988 case INTEL_FAM6_WESTMERE_EP: 5989 case INTEL_FAM6_WESTMERE_EX: ··· 6356 6357 case INTEL_FAM6_ALDERLAKE: 6358 case INTEL_FAM6_ALDERLAKE_L: 6359 - case INTEL_FAM6_ALDERLAKE_N: 6360 case INTEL_FAM6_RAPTORLAKE: 6361 case INTEL_FAM6_RAPTORLAKE_P: 6362 /*
··· 2102 EVENT_EXTRA_END 2103 }; 2104 2105 + EVENT_ATTR_STR(mem-loads, mem_ld_grt, "event=0xd0,umask=0x5,ldlat=3"); 2106 + EVENT_ATTR_STR(mem-stores, mem_st_grt, "event=0xd0,umask=0x6"); 2107 + 2108 + static struct attribute *grt_mem_attrs[] = { 2109 + EVENT_PTR(mem_ld_grt), 2110 + EVENT_PTR(mem_st_grt), 2111 + NULL 2112 + }; 2113 + 2114 static struct extra_reg intel_grt_extra_regs[] __read_mostly = { 2115 /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ 2116 INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x3fffffffffull, RSP_0), ··· 5975 name = "Tremont"; 5976 break; 5977 5978 + case INTEL_FAM6_ALDERLAKE_N: 5979 + x86_pmu.mid_ack = true; 5980 + memcpy(hw_cache_event_ids, glp_hw_cache_event_ids, 5981 + sizeof(hw_cache_event_ids)); 5982 + memcpy(hw_cache_extra_regs, tnt_hw_cache_extra_regs, 5983 + sizeof(hw_cache_extra_regs)); 5984 + hw_cache_event_ids[C(ITLB)][C(OP_READ)][C(RESULT_ACCESS)] = -1; 5985 + 5986 + x86_pmu.event_constraints = intel_slm_event_constraints; 5987 + x86_pmu.pebs_constraints = intel_grt_pebs_event_constraints; 5988 + x86_pmu.extra_regs = intel_grt_extra_regs; 5989 + 5990 + x86_pmu.pebs_aliases = NULL; 5991 + x86_pmu.pebs_prec_dist = true; 5992 + x86_pmu.pebs_block = true; 5993 + x86_pmu.lbr_pt_coexist = true; 5994 + x86_pmu.flags |= PMU_FL_HAS_RSP_1; 5995 + x86_pmu.flags |= PMU_FL_INSTR_LATENCY; 5996 + 5997 + intel_pmu_pebs_data_source_grt(); 5998 + x86_pmu.pebs_latency_data = adl_latency_data_small; 5999 + x86_pmu.get_event_constraints = tnt_get_event_constraints; 6000 + x86_pmu.limit_period = spr_limit_period; 6001 + td_attr = tnt_events_attrs; 6002 + mem_attr = grt_mem_attrs; 6003 + extra_attr = nhm_format_attr; 6004 + pr_cont("Gracemont events, "); 6005 + name = "gracemont"; 6006 + break; 6007 + 6008 case INTEL_FAM6_WESTMERE: 6009 case INTEL_FAM6_WESTMERE_EP: 6010 case INTEL_FAM6_WESTMERE_EX: ··· 6317 6318 case INTEL_FAM6_ALDERLAKE: 6319 case INTEL_FAM6_ALDERLAKE_L: 6320 case INTEL_FAM6_RAPTORLAKE: 6321 case INTEL_FAM6_RAPTORLAKE_P: 6322 /*
+7 -2
arch/x86/events/intel/ds.c
··· 110 __intel_pmu_pebs_data_source_skl(pmem, pebs_data_source); 111 } 112 113 - static void __init intel_pmu_pebs_data_source_grt(u64 *data_source) 114 { 115 data_source[0x05] = OP_LH | P(LVL, L3) | LEVEL(L3) | P(SNOOP, HIT); 116 data_source[0x06] = OP_LH | P(LVL, L3) | LEVEL(L3) | P(SNOOP, HITM); 117 data_source[0x08] = OP_LH | P(LVL, L3) | LEVEL(L3) | P(SNOOPX, FWD); 118 } 119 120 void __init intel_pmu_pebs_data_source_adl(void) ··· 132 133 data_source = x86_pmu.hybrid_pmu[X86_HYBRID_PMU_ATOM_IDX].pebs_data_source; 134 memcpy(data_source, pebs_data_source, sizeof(pebs_data_source)); 135 - intel_pmu_pebs_data_source_grt(data_source); 136 } 137 138 static u64 precise_store_data(u64 status)
··· 110 __intel_pmu_pebs_data_source_skl(pmem, pebs_data_source); 111 } 112 113 + static void __init __intel_pmu_pebs_data_source_grt(u64 *data_source) 114 { 115 data_source[0x05] = OP_LH | P(LVL, L3) | LEVEL(L3) | P(SNOOP, HIT); 116 data_source[0x06] = OP_LH | P(LVL, L3) | LEVEL(L3) | P(SNOOP, HITM); 117 data_source[0x08] = OP_LH | P(LVL, L3) | LEVEL(L3) | P(SNOOPX, FWD); 118 + } 119 + 120 + void __init intel_pmu_pebs_data_source_grt(void) 121 + { 122 + __intel_pmu_pebs_data_source_grt(pebs_data_source); 123 } 124 125 void __init intel_pmu_pebs_data_source_adl(void) ··· 127 128 data_source = x86_pmu.hybrid_pmu[X86_HYBRID_PMU_ATOM_IDX].pebs_data_source; 129 memcpy(data_source, pebs_data_source, sizeof(pebs_data_source)); 130 + __intel_pmu_pebs_data_source_grt(data_source); 131 } 132 133 static u64 precise_store_data(u64 status)
+2
arch/x86/events/perf_event.h
··· 1516 1517 void intel_pmu_pebs_data_source_adl(void); 1518 1519 int intel_pmu_setup_lbr_filter(struct perf_event *event); 1520 1521 void intel_pt_interrupt(void);
··· 1516 1517 void intel_pmu_pebs_data_source_adl(void); 1518 1519 + void intel_pmu_pebs_data_source_grt(void); 1520 + 1521 int intel_pmu_setup_lbr_filter(struct perf_event *event); 1522 1523 void intel_pt_interrupt(void);
+9
kernel/events/core.c
··· 6893 { 6894 struct perf_event *leader = event->group_leader, *sub; 6895 u64 read_format = event->attr.read_format; 6896 u64 values[6]; 6897 int n = 0; 6898 6899 values[n++] = 1 + leader->nr_siblings; 6900 ··· 6938 6939 __output_copy(handle, values, n * sizeof(u64)); 6940 } 6941 } 6942 6943 #define PERF_FORMAT_TOTAL_TIMES (PERF_FORMAT_TOTAL_TIME_ENABLED|\
··· 6893 { 6894 struct perf_event *leader = event->group_leader, *sub; 6895 u64 read_format = event->attr.read_format; 6896 + unsigned long flags; 6897 u64 values[6]; 6898 int n = 0; 6899 + 6900 + /* 6901 + * Disabling interrupts avoids all counter scheduling 6902 + * (context switches, timer based rotation and IPIs). 6903 + */ 6904 + local_irq_save(flags); 6905 6906 values[n++] = 1 + leader->nr_siblings; 6907 ··· 6931 6932 __output_copy(handle, values, n * sizeof(u64)); 6933 } 6934 + 6935 + local_irq_restore(flags); 6936 } 6937 6938 #define PERF_FORMAT_TOTAL_TIMES (PERF_FORMAT_TOTAL_TIME_ENABLED|\