Skip to content

Commit 2aef6f3

Browse files
sean-jcPeter Zijlstra
authored andcommitted
perf: Force architectures to opt-in to guest callbacks
Introduce GUEST_PERF_EVENTS and require architectures to select it to allow registering and using guest callbacks in perf. This will hopefully make it more difficult for new architectures to add useless "support" for guest callbacks, e.g. via copy+paste. Stubbing out the helpers has the happy bonus of avoiding a load of perf_guest_cbs when GUEST_PERF_EVENTS=n on arm64/x86. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1c34305 commit 2aef6f3

File tree

6 files changed

+15
-0
lines changed

6 files changed

+15
-0
lines changed

arch/arm64/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ menuconfig KVM
3939
select HAVE_KVM_IRQ_BYPASS
4040
select HAVE_KVM_VCPU_RUN_PID_CHANGE
4141
select SCHED_INFO
42+
select GUEST_PERF_EVENTS if PERF_EVENTS
4243
help
4344
Support hosting virtualized guest machines.
4445

arch/x86/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ config KVM
3636
select KVM_MMIO
3737
select SCHED_INFO
3838
select PERF_EVENTS
39+
select GUEST_PERF_EVENTS
3940
select HAVE_KVM_MSI
4041
select HAVE_KVM_CPU_RELAX_INTERCEPT
4142
select HAVE_KVM_NO_POLL

arch/x86/xen/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config XEN_PV
2323
select PARAVIRT_XXL
2424
select XEN_HAVE_PVMMU
2525
select XEN_HAVE_VPMU
26+
select GUEST_PERF_EVENTS
2627
help
2728
Support running as a Xen PV guest.
2829

include/linux/perf_event.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,7 @@ extern void perf_event_bpf_event(struct bpf_prog *prog,
12421242
enum perf_bpf_event_type type,
12431243
u16 flags);
12441244

1245+
#ifdef CONFIG_GUEST_PERF_EVENTS
12451246
extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
12461247
static inline struct perf_guest_info_callbacks *perf_get_guest_cbs(void)
12471248
{
@@ -1280,6 +1281,11 @@ static inline unsigned int perf_guest_handle_intel_pt_intr(void)
12801281
}
12811282
extern void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
12821283
extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
1284+
#else
1285+
static inline unsigned int perf_guest_state(void) { return 0; }
1286+
static inline unsigned long perf_guest_get_ip(void) { return 0; }
1287+
static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; }
1288+
#endif /* CONFIG_GUEST_PERF_EVENTS */
12831289

12841290
extern void perf_event_exec(void);
12851291
extern void perf_event_comm(struct task_struct *tsk, bool exec);

init/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,10 @@ config HAVE_PERF_EVENTS
18041804
help
18051805
See tools/perf/design.txt for details.
18061806

1807+
config GUEST_PERF_EVENTS
1808+
bool
1809+
depends on HAVE_PERF_EVENTS
1810+
18071811
config PERF_USE_VMALLOC
18081812
bool
18091813
help

kernel/events/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6521,6 +6521,7 @@ static void perf_pending_event(struct irq_work *entry)
65216521
perf_swevent_put_recursion_context(rctx);
65226522
}
65236523

6524+
#ifdef CONFIG_GUEST_PERF_EVENTS
65246525
struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
65256526

65266527
void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
@@ -6541,6 +6542,7 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
65416542
synchronize_rcu();
65426543
}
65436544
EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks);
6545+
#endif
65446546

65456547
static void
65466548
perf_output_sample_regs(struct perf_output_handle *handle,

0 commit comments

Comments
 (0)