Skip to content

Commit 86e0389

Browse files
author
Fox Snowpatch
committedSep 12, 2024·
1 parent 56e2adc commit 86e0389

File tree

15 files changed

+95
-99
lines changed

15 files changed

+95
-99
lines changed
 

‎arch/arm/include/asm/perf_event.h

-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
#ifndef __ARM_PERF_EVENT_H__
99
#define __ARM_PERF_EVENT_H__
1010

11-
#ifdef CONFIG_PERF_EVENTS
12-
struct pt_regs;
13-
extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
14-
extern unsigned long perf_misc_flags(struct pt_regs *regs);
15-
#define perf_misc_flags(regs) perf_misc_flags(regs)
16-
#endif
17-
1811
#define perf_arch_fetch_caller_regs(regs, __ip) { \
1912
(regs)->ARM_pc = (__ip); \
2013
frame_pointer((regs)) = (unsigned long) __builtin_frame_address(0); \

‎arch/arm/kernel/perf_callchain.c

-17
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,3 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re
9696
arm_get_current_stackframe(regs, &fr);
9797
walk_stackframe(&fr, callchain_trace, entry);
9898
}
99-
100-
unsigned long perf_instruction_pointer(struct pt_regs *regs)
101-
{
102-
return instruction_pointer(regs);
103-
}
104-
105-
unsigned long perf_misc_flags(struct pt_regs *regs)
106-
{
107-
int misc = 0;
108-
109-
if (user_mode(regs))
110-
misc |= PERF_RECORD_MISC_USER;
111-
else
112-
misc |= PERF_RECORD_MISC_KERNEL;
113-
114-
return misc;
115-
}

‎arch/arm64/include/asm/perf_event.h

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
#include <asm/ptrace.h>
1111

1212
#ifdef CONFIG_PERF_EVENTS
13-
struct pt_regs;
14-
extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
15-
extern unsigned long perf_misc_flags(struct pt_regs *regs);
16-
#define perf_misc_flags(regs) perf_misc_flags(regs)
1713
#define perf_arch_bpf_user_pt_regs(regs) &regs->user_regs
1814
#endif
1915

‎arch/arm64/kernel/perf_callchain.c

-28
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,3 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
3838

3939
arch_stack_walk(callchain_trace, entry, current, regs);
4040
}
41-
42-
unsigned long perf_instruction_pointer(struct pt_regs *regs)
43-
{
44-
if (perf_guest_state())
45-
return perf_guest_get_ip();
46-
47-
return instruction_pointer(regs);
48-
}
49-
50-
unsigned long perf_misc_flags(struct pt_regs *regs)
51-
{
52-
unsigned int guest_state = perf_guest_state();
53-
int misc = 0;
54-
55-
if (guest_state) {
56-
if (guest_state & PERF_GUEST_USER)
57-
misc |= PERF_RECORD_MISC_GUEST_USER;
58-
else
59-
misc |= PERF_RECORD_MISC_GUEST_KERNEL;
60-
} else {
61-
if (user_mode(regs))
62-
misc |= PERF_RECORD_MISC_USER;
63-
else
64-
misc |= PERF_RECORD_MISC_KERNEL;
65-
}
66-
67-
return misc;
68-
}

‎arch/powerpc/include/asm/perf_event_server.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ struct power_pmu {
102102
int __init register_power_pmu(struct power_pmu *pmu);
103103

104104
struct pt_regs;
105-
extern unsigned long perf_misc_flags(struct pt_regs *regs);
106-
extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
105+
extern unsigned long perf_arch_misc_flags(struct pt_regs *regs);
106+
extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs);
107107
extern unsigned long int read_bhrb(int n);
108108

109109
/*
110110
* Only override the default definitions in include/linux/perf_event.h
111111
* if we have hardware PMU support.
112112
*/
113113
#ifdef CONFIG_PPC_PERF_CTRS
114-
#define perf_misc_flags(regs) perf_misc_flags(regs)
114+
#define perf_arch_misc_flags(regs) perf_misc_flags(regs)
115115
#endif
116116

117117
/*

‎arch/powerpc/perf/callchain.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re
5151

5252
lr = regs->link;
5353
sp = regs->gpr[1];
54-
perf_callchain_store(entry, perf_instruction_pointer(regs));
54+
perf_callchain_store(entry, perf_arch_instruction_pointer(regs));
5555

5656
if (!validate_sp(sp, current))
5757
return;

‎arch/powerpc/perf/callchain_32.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
139139
long level = 0;
140140
unsigned int __user *fp, *uregs;
141141

142-
next_ip = perf_instruction_pointer(regs);
142+
next_ip = perf_arch_instruction_pointer(regs);
143143
lr = regs->link;
144144
sp = regs->gpr[1];
145145
perf_callchain_store(entry, next_ip);

‎arch/powerpc/perf/callchain_64.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry,
7474
struct signal_frame_64 __user *sigframe;
7575
unsigned long __user *fp, *uregs;
7676

77-
next_ip = perf_instruction_pointer(regs);
77+
next_ip = perf_arch_instruction_pointer(regs);
7878
lr = regs->link;
7979
sp = regs->gpr[1];
8080
perf_callchain_store(entry, next_ip);

‎arch/powerpc/perf/core-book3s.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val,
23322332
* Called from generic code to get the misc flags (i.e. processor mode)
23332333
* for an event_id.
23342334
*/
2335-
unsigned long perf_misc_flags(struct pt_regs *regs)
2335+
unsigned long perf_arch_misc_flags(struct pt_regs *regs)
23362336
{
23372337
u32 flags = perf_get_misc_flags(regs);
23382338

@@ -2346,7 +2346,7 @@ unsigned long perf_misc_flags(struct pt_regs *regs)
23462346
* Called from generic code to get the instruction pointer
23472347
* for an event_id.
23482348
*/
2349-
unsigned long perf_instruction_pointer(struct pt_regs *regs)
2349+
unsigned long perf_arch_instruction_pointer(struct pt_regs *regs)
23502350
{
23512351
unsigned long siar = mfspr(SPRN_SIAR);
23522352

‎arch/s390/include/asm/perf_event.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ extern ssize_t cpumf_events_sysfs_show(struct device *dev,
3737

3838
/* Perf callbacks */
3939
struct pt_regs;
40-
extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
41-
extern unsigned long perf_misc_flags(struct pt_regs *regs);
42-
#define perf_misc_flags(regs) perf_misc_flags(regs)
40+
extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs);
41+
extern unsigned long perf_arch_misc_flags(struct pt_regs *regs);
42+
#define perf_arch_misc_flags(regs) perf_misc_flags(regs)
4343
#define perf_arch_bpf_user_pt_regs(regs) &regs->user_regs
4444

4545
/* Perf pt_regs extension for sample-data-entry indicators */

‎arch/s390/kernel/perf_event.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static unsigned long instruction_pointer_guest(struct pt_regs *regs)
5757
return sie_block(regs)->gpsw.addr;
5858
}
5959

60-
unsigned long perf_instruction_pointer(struct pt_regs *regs)
60+
unsigned long perf_arch_instruction_pointer(struct pt_regs *regs)
6161
{
6262
return is_in_guest(regs) ? instruction_pointer_guest(regs)
6363
: instruction_pointer(regs);
@@ -84,7 +84,7 @@ static unsigned long perf_misc_flags_sf(struct pt_regs *regs)
8484
return flags;
8585
}
8686

87-
unsigned long perf_misc_flags(struct pt_regs *regs)
87+
unsigned long perf_arch_misc_flags(struct pt_regs *regs)
8888
{
8989
/* Check if the cpum_sf PMU has created the pt_regs structure.
9090
* In this case, perf misc flags can be easily extracted. Otherwise,

‎arch/x86/events/core.c

+27-20
Original file line numberDiff line numberDiff line change
@@ -2940,33 +2940,40 @@ static unsigned long code_segment_base(struct pt_regs *regs)
29402940
return 0;
29412941
}
29422942

2943-
unsigned long perf_instruction_pointer(struct pt_regs *regs)
2943+
unsigned long perf_arch_instruction_pointer(struct pt_regs *regs)
29442944
{
2945-
if (perf_guest_state())
2946-
return perf_guest_get_ip();
2947-
29482945
return regs->ip + code_segment_base(regs);
29492946
}
29502947

2951-
unsigned long perf_misc_flags(struct pt_regs *regs)
2948+
static unsigned long common_misc_flags(struct pt_regs *regs)
29522949
{
2953-
unsigned int guest_state = perf_guest_state();
2954-
int misc = 0;
2950+
if (regs->flags & PERF_EFLAGS_EXACT)
2951+
return PERF_RECORD_MISC_EXACT_IP;
29552952

2956-
if (guest_state) {
2957-
if (guest_state & PERF_GUEST_USER)
2958-
misc |= PERF_RECORD_MISC_GUEST_USER;
2959-
else
2960-
misc |= PERF_RECORD_MISC_GUEST_KERNEL;
2961-
} else {
2962-
if (user_mode(regs))
2963-
misc |= PERF_RECORD_MISC_USER;
2964-
else
2965-
misc |= PERF_RECORD_MISC_KERNEL;
2966-
}
2953+
return 0;
2954+
}
29672955

2968-
if (regs->flags & PERF_EFLAGS_EXACT)
2969-
misc |= PERF_RECORD_MISC_EXACT_IP;
2956+
unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs)
2957+
{
2958+
unsigned long guest_state = perf_guest_state();
2959+
unsigned long flags = common_misc_flags(regs);
2960+
2961+
if (guest_state & PERF_GUEST_USER)
2962+
flags |= PERF_RECORD_MISC_GUEST_USER;
2963+
else if (guest_state & PERF_GUEST_ACTIVE)
2964+
flags |= PERF_RECORD_MISC_GUEST_KERNEL;
2965+
2966+
return flags;
2967+
}
2968+
2969+
unsigned long perf_arch_misc_flags(struct pt_regs *regs)
2970+
{
2971+
unsigned long misc = common_misc_flags(regs);
2972+
2973+
if (user_mode(regs))
2974+
misc |= PERF_RECORD_MISC_USER;
2975+
else
2976+
misc |= PERF_RECORD_MISC_KERNEL;
29702977

29712978
return misc;
29722979
}

‎arch/x86/include/asm/perf_event.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -536,15 +536,17 @@ struct x86_perf_regs {
536536
u64 *xmm_regs;
537537
};
538538

539-
extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
540-
extern unsigned long perf_misc_flags(struct pt_regs *regs);
541-
#define perf_misc_flags(regs) perf_misc_flags(regs)
539+
extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs);
540+
extern unsigned long perf_arch_misc_flags(struct pt_regs *regs);
541+
extern unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs);
542+
#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs)
543+
#define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs)
542544

543545
#include <asm/stacktrace.h>
544546

545547
/*
546-
* We abuse bit 3 from flags to pass exact information, see perf_misc_flags
547-
* and the comment with PERF_EFLAGS_EXACT.
548+
* We abuse bit 3 from flags to pass exact information, see
549+
* perf_arch_misc_flags() and the comment with PERF_EFLAGS_EXACT.
548550
*/
549551
#define perf_arch_fetch_caller_regs(regs, __ip) { \
550552
(regs)->ip = (__ip); \

‎include/linux/perf_event.h

+23-3
Original file line numberDiff line numberDiff line change
@@ -1633,15 +1633,35 @@ extern void perf_tp_event(u16 event_type, u64 count, void *record,
16331633
struct task_struct *task);
16341634
extern void perf_bp_event(struct perf_event *event, void *data);
16351635

1636-
#ifndef perf_misc_flags
1637-
# define perf_misc_flags(regs) \
1636+
extern unsigned long perf_misc_flags(struct perf_event *event, struct pt_regs *regs);
1637+
extern unsigned long perf_instruction_pointer(struct perf_event *event,
1638+
struct pt_regs *regs);
1639+
1640+
#ifndef perf_arch_misc_flags
1641+
# define perf_arch_misc_flags(regs) \
16381642
(user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
1639-
# define perf_instruction_pointer(regs) instruction_pointer(regs)
1643+
# define perf_arch_instruction_pointer(regs) instruction_pointer(regs)
16401644
#endif
16411645
#ifndef perf_arch_bpf_user_pt_regs
16421646
# define perf_arch_bpf_user_pt_regs(regs) regs
16431647
#endif
16441648

1649+
#ifndef perf_arch_guest_misc_flags
1650+
static inline unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs)
1651+
{
1652+
unsigned long guest_state = perf_guest_state();
1653+
1654+
if (guest_state & PERF_GUEST_USER)
1655+
return PERF_RECORD_MISC_GUEST_USER;
1656+
1657+
if (guest_state & PERF_GUEST_ACTIVE)
1658+
return PERF_RECORD_MISC_GUEST_KERNEL;
1659+
1660+
return 0;
1661+
}
1662+
# define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs)
1663+
#endif
1664+
16451665
static inline bool has_branch_stack(struct perf_event *event)
16461666
{
16471667
return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;

‎kernel/events/core.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -6915,6 +6915,29 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
69156915
EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks);
69166916
#endif
69176917

6918+
static bool should_sample_guest(struct perf_event *event)
6919+
{
6920+
return !event->attr.exclude_guest && perf_guest_state();
6921+
}
6922+
6923+
unsigned long perf_misc_flags(struct perf_event *event,
6924+
struct pt_regs *regs)
6925+
{
6926+
if (should_sample_guest(event))
6927+
return perf_arch_guest_misc_flags(regs);
6928+
6929+
return perf_arch_misc_flags(regs);
6930+
}
6931+
6932+
unsigned long perf_instruction_pointer(struct perf_event *event,
6933+
struct pt_regs *regs)
6934+
{
6935+
if (should_sample_guest(event))
6936+
return perf_guest_get_ip();
6937+
6938+
return perf_arch_instruction_pointer(regs);
6939+
}
6940+
69186941
static void
69196942
perf_output_sample_regs(struct perf_output_handle *handle,
69206943
struct pt_regs *regs, u64 mask)
@@ -7727,7 +7750,7 @@ void perf_prepare_sample(struct perf_sample_data *data,
77277750
__perf_event_header__init_id(data, event, filtered_sample_type);
77287751

77297752
if (filtered_sample_type & PERF_SAMPLE_IP) {
7730-
data->ip = perf_instruction_pointer(regs);
7753+
data->ip = perf_instruction_pointer(event, regs);
77317754
data->sample_flags |= PERF_SAMPLE_IP;
77327755
}
77337756

@@ -7891,7 +7914,7 @@ void perf_prepare_header(struct perf_event_header *header,
78917914
{
78927915
header->type = PERF_RECORD_SAMPLE;
78937916
header->size = perf_sample_data_size(data, event);
7894-
header->misc = perf_misc_flags(regs);
7917+
header->misc = perf_misc_flags(event, regs);
78957918

78967919
/*
78977920
* If you're adding more sample types here, you likely need to do

0 commit comments

Comments
 (0)
Please sign in to comment.