lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 12 Nov 2021 17:57:43 +0800
From:   Like Xu <like.xu.linux@...il.com>
To:     Song Liu <songliubraving@...com>, bpf <bpf@...r.kernel.org>
Cc:     kernel-team@...com, Peter Zijlstra <peterz@...radead.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] x86/perf: fix snapshot_branch_stack warning in VM

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@...il.com>
> Cc: Peter Zijlstra (Intel) <peterz@...radead.org>
> Signed-off-by: Song Liu <songliubraving@...com>

Tested-by: Like Xu <likexu@...cent.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);
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ