* [PATCH] x86/perf: fix snapshot_branch_stack warning in VM
@ 2021-11-12 5:45 Song Liu
2021-11-12 9:57 ` Like Xu
2021-11-17 13:59 ` [tip: perf/urgent] x86/perf: Fix " tip-bot2 for Song Liu
0 siblings, 2 replies; 3+ messages in thread
From: Song Liu @ 2021-11-12 5:45 UTC (permalink / raw)
To: linux-kernel, bpf; +Cc: kernel-team, Song Liu, Like Xu, Peter Zijlstra
When running in VM intel_pmu_snapshot_branch_stack triggers WRMSR warning
like:
[ 252.599708] unchecked MSR access error: WRMSR to 0x3f1 (tried to write 0x0000000000000000) at rIP: 0xffffffff81011a5b (intel_pmu_snapshot_branch_stack+0x3b/0xd0)
[ 252.601886] Call Trace:
[ 252.602215] <TASK>
[ 252.602516] bpf_get_branch_snapshot+0x17/0x40
[ 252.603109] bpf_prog_5c58f41f99af93ce_test1+0x33/0xd54
[ 252.603777] bpf_trampoline_15032502913_0+0x4c/0x1000
[ 252.604435] bpf_testmod_loop_test+0x5/0x20 [bpf_testmod]
[ 252.605127] bpf_testmod_test_read+0x8f/0x3b0 [bpf_testmod]
[ 252.605864] ? bpf_testmod_loop_test+0x20/0x20 [bpf_testmod]
[ 252.606612] ? __kasan_kmalloc+0x84/0xa0
[ 252.607146] ? lock_is_held_type+0xd8/0x130
[ 252.607736] ? sysfs_kf_bin_read+0xbe/0x110
[ 252.608513] ? bpf_testmod_loop_test+0x20/0x20 [bpf_testmod]
[ 252.609332] kernfs_fop_read_iter+0x1ac/0x2c0
[ 252.609901] ? kernfs_create_link+0x110/0x110
[ 252.610509] new_sync_read+0x25a/0x380
[ 252.610994] ? __x64_sys_llseek+0x1e0/0x1e0
[ 252.611538] ? rcu_read_lock_sched_held+0xa1/0xd0
[ 252.612165] ? find_held_lock+0xac/0xd0
[ 252.612700] ? security_file_permission+0xe7/0x2c0
[ 252.613326] vfs_read+0x1a4/0x2a0
[ 252.613780] ksys_read+0xc0/0x160
[ 252.614218] ? vfs_write+0x510/0x510
[ 252.614684] ? ktime_get_coarse_real_ts64+0xe4/0xf0
[ 252.615423] do_syscall_64+0x3a/0x80
[ 252.615886] entry_SYSCALL_64_after_hwframe+0x44/0xae
[ 252.616553] RIP: 0033:0x7f62aa7f08b2
[ 252.617011] Code: 97 20 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b6 0f 1f 80 00 00 00 00 f3 0f 1e fa 8b 05 96 db 20 00 85 c0 75 12 31 c0 0f 05 <48> 3d 00 f0 ff ff 77 56 c3 0f 1f 44 00 00 41 54 49 89 d4 55 48 89
[ 252.619333] RSP: 002b:00007ffe72c83628 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
[ 252.620252] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f62aa7f08b2
[ 252.621138] RDX: 0000000000000064 RSI: 0000000000000000 RDI: 0000000000000028
[ 252.622035] RBP: 00007ffe72c83660 R08: 0000000000000000 R09: 00007ffe72c83507
[ 252.622951] R10: 0000000000000000 R11: 0000000000000246 R12: 000000000040d090
[ 252.623890] R13: 00007ffe72c83900 R14: 0000000000000000 R15: 0000000000000000
[ 252.624829] </TASK>
This can be triggered with BPF selftests:
tools/testing/selftests/bpf/test_progs -t get_branch_snapshot
This warning is caused by __intel_pmu_pebs_disable_all() in the VM. Since
it is not necessary to disable PEBs for LBR, remove it from
intel_pmu_snapshot_branch_stack and intel_pmu_snapshot_arch_branch_stack.
Fixes: c22ac2a3d4bd ("perf: Enable branch record for software events")
Cc: Like Xu <like.xu.linux@gmail.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
arch/x86/events/intel/core.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 42cf01ecdd131..ec6444f2c9dcb 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -2211,7 +2211,6 @@ intel_pmu_snapshot_branch_stack(struct perf_branch_entry *entries, unsigned int
/* must not have branches... */
local_irq_save(flags);
__intel_pmu_disable_all(false); /* we don't care about BTS */
- __intel_pmu_pebs_disable_all();
__intel_pmu_lbr_disable();
/* ... until here */
return __intel_pmu_snapshot_branch_stack(entries, cnt, flags);
@@ -2225,7 +2224,6 @@ intel_pmu_snapshot_arch_branch_stack(struct perf_branch_entry *entries, unsigned
/* must not have branches... */
local_irq_save(flags);
__intel_pmu_disable_all(false); /* we don't care about BTS */
- __intel_pmu_pebs_disable_all();
__intel_pmu_arch_lbr_disable();
/* ... until here */
return __intel_pmu_snapshot_branch_stack(entries, cnt, flags);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/perf: fix snapshot_branch_stack warning in VM
2021-11-12 5:45 [PATCH] x86/perf: fix snapshot_branch_stack warning in VM Song Liu
@ 2021-11-12 9:57 ` Like Xu
2021-11-17 13:59 ` [tip: perf/urgent] x86/perf: Fix " tip-bot2 for Song Liu
1 sibling, 0 replies; 3+ messages in thread
From: Like Xu @ 2021-11-12 9:57 UTC (permalink / raw)
To: Song Liu, bpf; +Cc: kernel-team, Peter Zijlstra, linux-kernel
On 12/11/2021 1:45 pm, Song Liu wrote:
> When running in VM intel_pmu_snapshot_branch_stack triggers WRMSR warning
> like:
>
> [ 252.599708] unchecked MSR access error: WRMSR to 0x3f1 (tried to write 0x0000000000000000) at rIP: 0xffffffff81011a5b (intel_pmu_snapshot_branch_stack+0x3b/0xd0)
> [ 252.601886] Call Trace:
> [ 252.602215] <TASK>
> [ 252.602516] bpf_get_branch_snapshot+0x17/0x40
> [ 252.603109] bpf_prog_5c58f41f99af93ce_test1+0x33/0xd54
> [ 252.603777] bpf_trampoline_15032502913_0+0x4c/0x1000
> [ 252.604435] bpf_testmod_loop_test+0x5/0x20 [bpf_testmod]
> [ 252.605127] bpf_testmod_test_read+0x8f/0x3b0 [bpf_testmod]
> [ 252.605864] ? bpf_testmod_loop_test+0x20/0x20 [bpf_testmod]
> [ 252.606612] ? __kasan_kmalloc+0x84/0xa0
> [ 252.607146] ? lock_is_held_type+0xd8/0x130
> [ 252.607736] ? sysfs_kf_bin_read+0xbe/0x110
> [ 252.608513] ? bpf_testmod_loop_test+0x20/0x20 [bpf_testmod]
> [ 252.609332] kernfs_fop_read_iter+0x1ac/0x2c0
> [ 252.609901] ? kernfs_create_link+0x110/0x110
> [ 252.610509] new_sync_read+0x25a/0x380
> [ 252.610994] ? __x64_sys_llseek+0x1e0/0x1e0
> [ 252.611538] ? rcu_read_lock_sched_held+0xa1/0xd0
> [ 252.612165] ? find_held_lock+0xac/0xd0
> [ 252.612700] ? security_file_permission+0xe7/0x2c0
> [ 252.613326] vfs_read+0x1a4/0x2a0
> [ 252.613780] ksys_read+0xc0/0x160
> [ 252.614218] ? vfs_write+0x510/0x510
> [ 252.614684] ? ktime_get_coarse_real_ts64+0xe4/0xf0
> [ 252.615423] do_syscall_64+0x3a/0x80
> [ 252.615886] entry_SYSCALL_64_after_hwframe+0x44/0xae
> [ 252.616553] RIP: 0033:0x7f62aa7f08b2
> [ 252.617011] Code: 97 20 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b6 0f 1f 80 00 00 00 00 f3 0f 1e fa 8b 05 96 db 20 00 85 c0 75 12 31 c0 0f 05 <48> 3d 00 f0 ff ff 77 56 c3 0f 1f 44 00 00 41 54 49 89 d4 55 48 89
> [ 252.619333] RSP: 002b:00007ffe72c83628 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
> [ 252.620252] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f62aa7f08b2
> [ 252.621138] RDX: 0000000000000064 RSI: 0000000000000000 RDI: 0000000000000028
> [ 252.622035] RBP: 00007ffe72c83660 R08: 0000000000000000 R09: 00007ffe72c83507
> [ 252.622951] R10: 0000000000000000 R11: 0000000000000246 R12: 000000000040d090
> [ 252.623890] R13: 00007ffe72c83900 R14: 0000000000000000 R15: 0000000000000000
> [ 252.624829] </TASK>
>
> This can be triggered with BPF selftests:
>
> tools/testing/selftests/bpf/test_progs -t get_branch_snapshot
>
> This warning is caused by __intel_pmu_pebs_disable_all() in the VM. Since
> it is not necessary to disable PEBs for LBR, remove it from
> intel_pmu_snapshot_branch_stack and intel_pmu_snapshot_arch_branch_stack.
>
> Fixes: c22ac2a3d4bd ("perf: Enable branch record for software events")
> Cc: Like Xu <like.xu.linux@gmail.com>
> Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Song Liu <songliubraving@fb.com>
Tested-by: Like Xu <likexu@tencent.com>
I guess bpf users will be happier with the usages of Intel PT snapshot mode.
> ---
> arch/x86/events/intel/core.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 42cf01ecdd131..ec6444f2c9dcb 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -2211,7 +2211,6 @@ intel_pmu_snapshot_branch_stack(struct perf_branch_entry *entries, unsigned int
> /* must not have branches... */
> local_irq_save(flags);
> __intel_pmu_disable_all(false); /* we don't care about BTS */
> - __intel_pmu_pebs_disable_all();
> __intel_pmu_lbr_disable();
> /* ... until here */
> return __intel_pmu_snapshot_branch_stack(entries, cnt, flags);
> @@ -2225,7 +2224,6 @@ intel_pmu_snapshot_arch_branch_stack(struct perf_branch_entry *entries, unsigned
> /* must not have branches... */
> local_irq_save(flags);
> __intel_pmu_disable_all(false); /* we don't care about BTS */
> - __intel_pmu_pebs_disable_all();
> __intel_pmu_arch_lbr_disable();
> /* ... until here */
> return __intel_pmu_snapshot_branch_stack(entries, cnt, flags);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: perf/urgent] x86/perf: Fix snapshot_branch_stack warning in VM
2021-11-12 5:45 [PATCH] x86/perf: fix snapshot_branch_stack warning in VM Song Liu
2021-11-12 9:57 ` Like Xu
@ 2021-11-17 13:59 ` tip-bot2 for Song Liu
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Song Liu @ 2021-11-17 13:59 UTC (permalink / raw)
To: linux-tip-commits
Cc: Song Liu, Peter Zijlstra (Intel), Like Xu, x86, linux-kernel
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: f3fd84a3b7754b60df67ebfe64e1d90623895111
Gitweb: https://git.kernel.org/tip/f3fd84a3b7754b60df67ebfe64e1d90623895111
Author: Song Liu <songliubraving@fb.com>
AuthorDate: Thu, 11 Nov 2021 21:45:10 -08:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 17 Nov 2021 14:48:43 +01:00
x86/perf: Fix snapshot_branch_stack warning in VM
When running in VM intel_pmu_snapshot_branch_stack triggers WRMSR warning
like:
[ ] unchecked MSR access error: WRMSR to 0x3f1 (tried to write 0x0000000000000000) at rIP: 0xffffffff81011a5b (intel_pmu_snapshot_branch_stack+0x3b/0xd0)
This can be triggered with BPF selftests:
tools/testing/selftests/bpf/test_progs -t get_branch_snapshot
This warning is caused by __intel_pmu_pebs_disable_all() in the VM.
Since it is not necessary to disable PEBS for LBR, remove it from
intel_pmu_snapshot_branch_stack and intel_pmu_snapshot_arch_branch_stack.
Fixes: c22ac2a3d4bd ("perf: Enable branch record for software events")
Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Like Xu <likexu@tencent.com>
Link: https://lore.kernel.org/r/20211112054510.2667030-1-songliubraving@fb.com
---
arch/x86/events/intel/core.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 42cf01e..ec6444f 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -2211,7 +2211,6 @@ intel_pmu_snapshot_branch_stack(struct perf_branch_entry *entries, unsigned int
/* must not have branches... */
local_irq_save(flags);
__intel_pmu_disable_all(false); /* we don't care about BTS */
- __intel_pmu_pebs_disable_all();
__intel_pmu_lbr_disable();
/* ... until here */
return __intel_pmu_snapshot_branch_stack(entries, cnt, flags);
@@ -2225,7 +2224,6 @@ intel_pmu_snapshot_arch_branch_stack(struct perf_branch_entry *entries, unsigned
/* must not have branches... */
local_irq_save(flags);
__intel_pmu_disable_all(false); /* we don't care about BTS */
- __intel_pmu_pebs_disable_all();
__intel_pmu_arch_lbr_disable();
/* ... until here */
return __intel_pmu_snapshot_branch_stack(entries, cnt, flags);
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-17 14:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 5:45 [PATCH] x86/perf: fix snapshot_branch_stack warning in VM Song Liu
2021-11-12 9:57 ` Like Xu
2021-11-17 13:59 ` [tip: perf/urgent] x86/perf: Fix " tip-bot2 for Song Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).