Skip to content

Commit 3f3041b

Browse files
committed
Merge tag 'perf-urgent-2025-05-04' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull misc perf fixes from Ingo Molnar: - Require group events for branch counter groups and PEBS counter snapshotting groups to be x86 events. - Fix the handling of counter-snapshotting of non-precise events, where counter values may move backwards a bit, temporarily, confusing the code. - Restrict perf/KVM PEBS to guest-owned events. * tag 'perf-urgent-2025-05-04' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/x86/intel: KVM: Mask PEBS_ENABLE loaded for guest with vCPU's value. perf/x86/intel/ds: Fix counter backwards of non-precise events counters-snapshotting perf/x86/intel: Check the X86 leader for pebs_counter_event_group perf/x86/intel: Only check the group flag for X86 leader
2 parents 5aac99c + 58f6217 commit 3f3041b

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

arch/x86/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ void x86_pmu_enable_all(int added)
754754
}
755755
}
756756

757-
static inline int is_x86_event(struct perf_event *event)
757+
int is_x86_event(struct perf_event *event)
758758
{
759759
int i;
760760

arch/x86/events/intel/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4395,7 +4395,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data)
43954395
arr[pebs_enable] = (struct perf_guest_switch_msr){
43964396
.msr = MSR_IA32_PEBS_ENABLE,
43974397
.host = cpuc->pebs_enabled & ~cpuc->intel_ctrl_guest_mask,
4398-
.guest = pebs_mask & ~cpuc->intel_ctrl_host_mask,
4398+
.guest = pebs_mask & ~cpuc->intel_ctrl_host_mask & kvm_pmu->pebs_enable,
43994399
};
44004400

44014401
if (arr[pebs_enable].host) {

arch/x86/events/intel/ds.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,8 +2379,25 @@ __intel_pmu_pebs_last_event(struct perf_event *event,
23792379
*/
23802380
intel_pmu_save_and_restart_reload(event, count);
23812381
}
2382-
} else
2383-
intel_pmu_save_and_restart(event);
2382+
} else {
2383+
/*
2384+
* For a non-precise event, it's possible the
2385+
* counters-snapshotting records a positive value for the
2386+
* overflowed event. Then the HW auto-reload mechanism
2387+
* reset the counter to 0 immediately, because the
2388+
* pebs_event_reset is cleared if the PERF_X86_EVENT_AUTO_RELOAD
2389+
* is not set. The counter backwards may be observed in a
2390+
* PMI handler.
2391+
*
2392+
* Since the event value has been updated when processing the
2393+
* counters-snapshotting record, only needs to set the new
2394+
* period for the counter.
2395+
*/
2396+
if (is_pebs_counter_event_group(event))
2397+
static_call(x86_pmu_set_period)(event);
2398+
else
2399+
intel_pmu_save_and_restart(event);
2400+
}
23842401
}
23852402

23862403
static __always_inline void

arch/x86/events/perf_event.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,21 @@ static inline bool is_topdown_event(struct perf_event *event)
110110
return is_metric_event(event) || is_slots_event(event);
111111
}
112112

113+
int is_x86_event(struct perf_event *event);
114+
115+
static inline bool check_leader_group(struct perf_event *leader, int flags)
116+
{
117+
return is_x86_event(leader) ? !!(leader->hw.flags & flags) : false;
118+
}
119+
113120
static inline bool is_branch_counters_group(struct perf_event *event)
114121
{
115-
return event->group_leader->hw.flags & PERF_X86_EVENT_BRANCH_COUNTERS;
122+
return check_leader_group(event->group_leader, PERF_X86_EVENT_BRANCH_COUNTERS);
116123
}
117124

118125
static inline bool is_pebs_counter_event_group(struct perf_event *event)
119126
{
120-
return event->group_leader->hw.flags & PERF_X86_EVENT_PEBS_CNTR;
127+
return check_leader_group(event->group_leader, PERF_X86_EVENT_PEBS_CNTR);
121128
}
122129

123130
struct amd_nb {

0 commit comments

Comments
 (0)