From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>, linux-kernel@vger.kernel.org
Cc: linux-tip-commits@vger.kernel.org, x86@kernel.org
Subject: Re: [tip: perf/core] perf/x86: Reset the dirty counter to prevent the leak for an RDPMC task
Date: Fri, 16 Apr 2021 15:50:43 -0400 [thread overview]
Message-ID: <2d470931-a077-5e45-479d-019061c11665@linux.intel.com> (raw)
In-Reply-To: <YHm/M4za2LpRYePw@hirez.programming.kicks-ass.net>
On 4/16/2021 12:45 PM, Peter Zijlstra wrote:
> 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
If it's a preemptible env, I think we should disable the interrupts and
preemption to protect the sched_cb_list.
Seems we don't need perf_ctx_lock() here. I don't think we touch the
area in NMI. I think disabling the interrupts should be good enough to
protect the cpuctx.
How about the below patch?
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index e34eb72..45630beed 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2333,6 +2333,8 @@ static void x86_pmu_clear_dirty_counters(void)
static void x86_pmu_event_mapped(struct perf_event *event, struct
mm_struct *mm)
{
+ unsigned long flags;
+
if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED))
return;
@@ -2341,8 +2343,10 @@ static void x86_pmu_event_mapped(struct
perf_event *event, struct mm_struct *mm)
* and clear the existing dirty counters.
*/
if (x86_pmu.sched_task && event->hw.target) {
+ local_irq_save(flags);
perf_sched_cb_inc(event->ctx->pmu);
x86_pmu_clear_dirty_counters();
+ local_irq_restore(flags);
}
/*
@@ -2363,12 +2367,16 @@ static void x86_pmu_event_mapped(struct
perf_event *event, struct mm_struct *mm)
static void x86_pmu_event_unmapped(struct perf_event *event, struct
mm_struct *mm)
{
+ unsigned long flags;
if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED))
return;
- if (x86_pmu.sched_task && event->hw.target)
+ if (x86_pmu.sched_task && event->hw.target) {
+ local_irq_save(flags);
perf_sched_cb_dec(event->ctx->pmu);
+ local_irq_restore(flags);
+ }
if (atomic_dec_and_test(&mm->context.perf_rdpmc_allowed))
on_each_cpu_mask(mm_cpumask(mm), cr4_update_pce, NULL, 1);
Thanks,
Kan
next prev parent reply other threads:[~2021-04-16 19:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-14 14:36 [PATCH V4 1/2] perf/x86: Move cpuc->running into P4 specific code kan.liang
2021-04-14 14:36 ` [PATCH V4 2/2] perf/x86: Reset the dirty counter to prevent the leak for an RDPMC task kan.liang
2021-04-16 15:01 ` [tip: perf/core] " tip-bot2 for Kan Liang
2021-04-16 16:45 ` Peter Zijlstra
2021-04-16 19:50 ` Liang, Kan [this message]
2021-04-16 15:01 ` [tip: perf/core] perf/x86: Move cpuc->running into P4 specific code tip-bot2 for Kan Liang
2021-06-14 17:59 [RESEND PATCH V8] perf/x86: Reset the dirty counter to prevent the leak for an RDPMC task kan.liang
2021-06-18 8:46 ` [tip: perf/core] " tip-bot2 for Kan Liang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d470931-a077-5e45-479d-019061c11665@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome