mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Luwei Kang <luwei.kang@intel.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de,
	mingo@redhat.com, hpa@zytor.com, x86@kernel.org,
	linux-kernel@vger.kernel.org,
	Chao Peng <chao.p.peng@linux.intel.com>,
	Luwei Kang <luwei.kang@intel.com>
Subject: [PATCH 4/9] perf/x86/intel/pt: add Intel processor trace virtualization call backs
Date: Mon, 16 Oct 2017 20:13:10 +0800	[thread overview]
Message-ID: <1508155990-4799-1-git-send-email-luwei.kang@intel.com> (raw)

From: Chao Peng <chao.p.peng@linux.intel.com>

Add Intel processor trace virtualization call backs to
suppress host event in guest only mode.

Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
Signed-off-by: Luwei Kang <luwei.kang@intel.com>
---
 arch/x86/events/intel/pt.c      | 21 +++++++++++++++++++++
 arch/x86/include/asm/intel_pt.h |  9 +++++++++
 2 files changed, 30 insertions(+)

diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index a5a7e44..ec54bba 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -36,6 +36,7 @@
 static DEFINE_PER_CPU(struct pt, pt_ctx);
 
 static struct pt_pmu pt_pmu;
+static struct pt_virt_ops *virt_ops;
 
 /*
  * Capabilities of Intel PT hardware, such as number of address bits or
@@ -177,6 +178,18 @@ static ssize_t pt_cap_show(struct device *cdev,
 	NULL,
 };
 
+void pt_register_virt_ops(struct pt_virt_ops *ops)
+{
+	virt_ops = ops;
+}
+EXPORT_SYMBOL_GPL(pt_register_virt_ops);
+
+void pt_unregister_virt_ops(void)
+{
+	virt_ops = NULL;
+}
+EXPORT_SYMBOL_GPL(pt_unregister_virt_ops);
+
 static int __init pt_pmu_hw_init(void)
 {
 	struct dev_ext_attribute *de_attrs;
@@ -1244,6 +1257,9 @@ void intel_pt_interrupt(void)
 	struct pt_buffer *buf;
 	struct perf_event *event = pt->handle.event;
 
+	if (virt_ops && virt_ops->pmi && virt_ops->pmi())
+		return;
+
 	/*
 	 * There may be a dangling PT bit in the interrupt status register
 	 * after PT has been disabled by pt_event_stop(). Make sure we don't
@@ -1444,6 +1460,11 @@ static void pt_event_destroy(struct perf_event *event)
 
 static int pt_event_init(struct perf_event *event)
 {
+	/* suppress host event in guest only mode */
+	if (virt_ops && virt_ops->get_mode &&
+		virt_ops->get_mode() == PT_MODE_GUEST)
+		return -EPERM;
+
 	if (event->attr.type != pt_pmu.pmu.type)
 		return -ENOENT;
 
diff --git a/arch/x86/include/asm/intel_pt.h b/arch/x86/include/asm/intel_pt.h
index b5dd33c..6a5d475 100644
--- a/arch/x86/include/asm/intel_pt.h
+++ b/arch/x86/include/asm/intel_pt.h
@@ -26,12 +26,21 @@ enum pt_capabilities {
 	PT_CAP_psb_periods,
 };
 
+struct pt_virt_ops {
+	enum pt_mode (*get_mode)(void);
+	bool (*pmi)(void);
+};
+
 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
 void cpu_emergency_stop_pt(void);
 extern u32 pt_cap_get(enum pt_capabilities cap);
+extern void pt_register_virt_ops(struct pt_virt_ops *ops);
+extern void pt_unregister_virt_ops(void);
 #else
 static inline void cpu_emergency_stop_pt(void) {}
 static inline u32 pt_cap_get(enum pt_capabilities cap) { return 0; }
+static void pt_register_virt_ops(struct pt_virt_ops *ops) { }
+static void pt_unregister_virt_ops(void) { }
 #endif
 
 #endif /* _ASM_X86_INTEL_PT_H */
-- 
1.8.3.1

                 reply	other threads:[~2017-10-17  1:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1508155990-4799-1-git-send-email-luwei.kang@intel.com \
    --to=luwei.kang@intel.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.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®