From: Dmitry Safonov <dsafonov@virtuozzo.com>
To: <linux-kernel@vger.kernel.org>
Cc: <luto@amacapital.net>, <tglx@linutronix.de>, <mingo@redhat.com>,
<hpa@zytor.com>, <x86@kernel.org>, <rric@kernel.org>,
<oprofile-list@lists.sf.net>, <0x7f454c46@gmail.com>,
Dmitry Safonov <dsafonov@virtuozzo.com>
Subject: [PATCH 3/4] x86/intel lbr: down with test_thread_flag(TIF_IA32)
Date: Thu, 14 Apr 2016 21:10:13 +0300 [thread overview]
Message-ID: <1460657414-12530-4-git-send-email-dsafonov@virtuozzo.com> (raw)
In-Reply-To: <1460657414-12530-1-git-send-email-dsafonov@virtuozzo.com>
Use user_mode64_bit to check process state. For that pass
interrupt register set from irq handler.
This should fix opcode decoder misinterpreting ABI for
tasks that change their code selector.
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
---
arch/x86/events/intel/core.c | 2 +-
arch/x86/events/intel/lbr.c | 17 ++++++++++-------
arch/x86/events/perf_event.h | 2 +-
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 68fa55b4d42e..df13d1d6dbf6 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -1860,7 +1860,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)
loops = 0;
again:
- intel_pmu_lbr_read();
+ intel_pmu_lbr_read(regs);
intel_pmu_ack_status(status);
if (++loops > 100) {
static bool warned = false;
diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
index 6c3b7c1780c9..f1a1dbc77dea 100644
--- a/arch/x86/events/intel/lbr.c
+++ b/arch/x86/events/intel/lbr.c
@@ -136,7 +136,9 @@ enum {
X86_BR_IRQ |\
X86_BR_INT)
-static void intel_pmu_lbr_filter(struct cpu_hw_events *cpuc);
+
+static void
+intel_pmu_lbr_filter(struct pt_regs *regs, struct cpu_hw_events *cpuc);
/*
* We only support LBR implementations that have FREEZE_LBRS_ON_PMI
@@ -500,7 +502,7 @@ static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
cpuc->lbr_stack.nr = out;
}
-void intel_pmu_lbr_read(void)
+void intel_pmu_lbr_read(struct pt_regs *regs)
{
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
@@ -512,7 +514,7 @@ void intel_pmu_lbr_read(void)
else
intel_pmu_lbr_read_64(cpuc);
- intel_pmu_lbr_filter(cpuc);
+ intel_pmu_lbr_filter(regs, cpuc);
}
/*
@@ -658,7 +660,8 @@ int intel_pmu_setup_lbr_filter(struct perf_event *event)
* decoded (e.g., text page not present), then X86_BR_NONE is
* returned.
*/
-static int branch_type(unsigned long from, unsigned long to, int abort)
+static int branch_type(unsigned long from, unsigned long to, int abort,
+ struct pt_regs *regs)
{
struct insn insn;
void *addr;
@@ -724,7 +727,7 @@ static int branch_type(unsigned long from, unsigned long to, int abort)
* on 64-bit systems running 32-bit apps
*/
#ifdef CONFIG_X86_64
- is64 = kernel_ip((unsigned long)addr) || !test_thread_flag(TIF_IA32);
+ is64 = kernel_ip((unsigned long)addr) || user_64bit_mode(regs);
#endif
insn_init(&insn, addr, bytes_read, is64);
insn_get_opcode(&insn);
@@ -830,7 +833,7 @@ static int branch_type(unsigned long from, unsigned long to, int abort)
* in PERF_SAMPLE_BRANCH_STACK sample may vary.
*/
static void
-intel_pmu_lbr_filter(struct cpu_hw_events *cpuc)
+intel_pmu_lbr_filter(struct pt_regs *regs, struct cpu_hw_events *cpuc)
{
u64 from, to;
int br_sel = cpuc->br_sel;
@@ -846,7 +849,7 @@ intel_pmu_lbr_filter(struct cpu_hw_events *cpuc)
from = cpuc->lbr_entries[i].from;
to = cpuc->lbr_entries[i].to;
- type = branch_type(from, to, cpuc->lbr_entries[i].abort);
+ type = branch_type(from, to, cpuc->lbr_entries[i].abort, regs);
if (type != X86_BR_NONE && (br_sel & X86_BR_ANYTX)) {
if (cpuc->lbr_entries[i].in_tx)
type |= X86_BR_IN_TX;
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index ad4dc7ffffb5..da1ec8240097 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -899,7 +899,7 @@ void intel_pmu_lbr_enable_all(bool pmi);
void intel_pmu_lbr_disable_all(void);
-void intel_pmu_lbr_read(void);
+void intel_pmu_lbr_read(struct pt_regs *regs);
void intel_pmu_lbr_init_core(void);
--
2.8.0
next prev parent reply other threads:[~2016-04-14 18:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-14 18:10 [PATCH 0/4] drop test_thread_flag checks Dmitry Safonov
2016-04-14 18:10 ` [PATCH 1/4] x86/events: down with test_thread_flag(TIF_IA32) Dmitry Safonov
2016-04-14 18:32 ` Andy Lutomirski
2016-04-20 11:15 ` Peter Zijlstra
2016-04-14 18:10 ` [PATCH 2/4] x86/intel: " Dmitry Safonov
2016-04-14 18:10 ` Dmitry Safonov [this message]
2016-04-14 19:29 ` [PATCH 3/4] x86/intel lbr: " Andy Lutomirski
2016-04-20 11:21 ` Peter Zijlstra
2016-04-20 13:43 ` Dmitry Safonov
2016-04-14 18:10 ` [PATCH 4/4] x86/oprofile: " Dmitry Safonov
2016-04-14 19:29 ` Andy Lutomirski
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=1460657414-12530-4-git-send-email-dsafonov@virtuozzo.com \
--to=dsafonov@virtuozzo.com \
--cc=0x7f454c46@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=oprofile-list@lists.sf.net \
--cc=rric@kernel.org \
--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®