Re: [tip: perf/core] perf/x86: Reset the dirty counter to prevent the leak for an RDPMC task
From: Peter Zijlstra
Date: Fri Apr 16 2021 - 12:45:48 EST
On Fri, Apr 16, 2021 at 03:01:48PM -0000, tip-bot2 for Kan Liang wrote:
> @@ -2331,6 +2367,9 @@ static void x86_pmu_event_unmapped(struct perf_event *event, struct mm_struct *m
> if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED))
> return;
>
> + if (x86_pmu.sched_task && event->hw.target)
> + perf_sched_cb_dec(event->ctx->pmu);
> +
> if (atomic_dec_and_test(&mm->context.perf_rdpmc_allowed))
> on_each_cpu_mask(mm_cpumask(mm), cr4_update_pce, NULL, 1);
> }
'perf test' on a kernel with CONFIG_DEBUG_PREEMPT=y gives:
[ 244.439538] BUG: using smp_processor_id() in preemptible [00000000] code: perf/1771
[ 244.448144] caller is perf_sched_cb_dec+0xa/0x70
[ 244.453314] CPU: 28 PID: 1771 Comm: perf Not tainted 5.12.0-rc3-00026-gb04c0cddff6d #595
[ 244.462347] Hardware name: Intel Corporation S2600GZ/S2600GZ, BIOS SE5C600.86B.02.02.0002.122320131210 12/23/2013
[ 244.473804] Call Trace:
[ 244.476535] dump_stack+0x6d/0x89
[ 244.480237] check_preemption_disabled+0xc8/0xd0
[ 244.485394] perf_sched_cb_dec+0xa/0x70
[ 244.489677] x86_pmu_event_unmapped+0x35/0x60
[ 244.494541] perf_mmap_close+0x76/0x580
[ 244.498833] remove_vma+0x31/0x70
[ 244.502535] __do_munmap+0x2e8/0x4e0
[ 244.506531] __vm_munmap+0x7e/0x120
[ 244.510429] __x64_sys_munmap+0x28/0x30
[ 244.514712] do_syscall_64+0x33/0x80
[ 244.518701] entry_SYSCALL_64_after_hwframe+0x44/0xae
Obviously I tested that after I pushed it out :/