From: Zhou Chengming <zhouchengming1@huawei.com>
To: <tglx@linutronix.de>, <mingo@redhat.com>, <hpa@zytor.com>,
<x86@kernel.org>, <peterz@infradead.org>, <ak@linux.intel.com>,
<eranian@google.com>, <kan.liang@intel.com>, <davidcc@google.com>,
<dave.hansen@linux.intel.com>, <linux-kernel@vger.kernel.org>
Cc: <qiaonuohan@huawei.com>, <zhouchengming1@huawei.com>,
<guohanjun@huawei.com>
Subject: [PATCH] fix race caused by hyperthreads when online an offline cpu
Date: Thu, 12 Jan 2017 17:32:32 +0800 [thread overview]
Message-ID: <1484213552-46680-1-git-send-email-zhouchengming1@huawei.com> (raw)
After online an offline cpu, cpu_hw_events.excl_thread_id will always be
set to 1 in intel_pmu_cpu_starting() even when its sibling's excl_thread_id
is also 1. Then the two siblings will use the same state in their shared
hw_hw_events.excl_cntrs, it will cause race problem.
The race senario is like this:
Two cpu (7 and 19) are siblings, excl_thread_id of 7 and 19 are 0 and 1.
After offline and online cpu 7, intel_pmu_cpu_starting() will set excl_thread_id
of cpu 7 to 1. Then both cpu 7 and 19 will use the same state in their
shared hw_hw_events.excl_cntrs.
cpu7 cpu19
--- ---
intel_start_scheduling()
set state->sched_started = true
intel_put_excl_constraints() {
if (!state->sched_started)
spin_lock // not executed
intel_stop_scheduling()
set state->sched_started = false
if (!state->sched_started)
spin_unlock // excuted
Signed-off-by: NuoHan Qiao <qiaonuohan@huawei.com>
Signed-off-by: Zhou Chengming <zhouchengming1@huawei.com>
---
arch/x86/events/intel/core.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index a74a2db..593d8c9 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3164,13 +3164,16 @@ static void intel_pmu_cpu_starting(int cpu)
if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
for_each_cpu(i, topology_sibling_cpumask(cpu)) {
+ struct cpu_hw_events *sibling;
struct intel_excl_cntrs *c;
- c = per_cpu(cpu_hw_events, i).excl_cntrs;
+ sibling = &per_cpu(cpu_hw_events, i);
+ c = sibling->excl_cntrs;
if (c && c->core_id == core_id) {
cpuc->kfree_on_online[1] = cpuc->excl_cntrs;
cpuc->excl_cntrs = c;
- cpuc->excl_thread_id = 1;
+ if (!sibling->excl_thread_id)
+ cpuc->excl_thread_id = 1;
break;
}
}
--
1.7.7
next reply other threads:[~2017-01-12 9:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-12 9:32 Zhou Chengming [this message]
2017-01-14 1:33 ` qiaonuohan
2017-01-14 11:21 Zhou Chengming
2017-01-16 3:21 Zhou Chengming
2017-01-16 9:05 ` Thomas Gleixner
2017-01-16 9:53 ` zhouchengming
2017-01-16 18:36 ` Stephane Eranian
2017-01-17 10:05 ` Thomas Gleixner
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=1484213552-46680-1-git-send-email-zhouchengming1@huawei.com \
--to=zhouchengming1@huawei.com \
--cc=ak@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=davidcc@google.com \
--cc=eranian@google.com \
--cc=guohanjun@huawei.com \
--cc=hpa@zytor.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=qiaonuohan@huawei.com \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®