From: Peter Zijlstra <peterz@infradead.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Luwei Kang <luwei.kang@intel.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
hpa@zytor.com, x86@kernel.org, songliubraving@fb.com,
rkrcmar@redhat.com, zsm@chromium.org,
alexander.shishkin@linux.intel.com, konrad.wilk@oracle.com,
ak@linux.intel.com
Subject: Re: [PATCH 2/3] perf/x86/intel/pt: Inject PMI for KVM guest
Date: Wed, 6 Feb 2019 17:34:23 +0100 [thread overview]
Message-ID: <20190206163423.GI17564@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <94fdce1b-9c42-e551-3099-ef7c4071a6ba@redhat.com>
On Wed, Jan 30, 2019 at 06:02:27PM +0100, Paolo Bonzini wrote:
> On 19/01/19 21:04, Luwei Kang wrote:
> > static struct pt_pmu pt_pmu;
> >
> > @@ -1260,6 +1262,14 @@ void intel_pt_interrupt(void)
> > struct pt_buffer *buf;
> > struct perf_event *event = pt->handle.event;
> >
> > + if (pt->vcpu) {
> > + /* Inject PMI to Guest */
> > + kvm_make_request(KVM_REQ_PMI, pt->vcpu);
> > + __set_bit(MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT,
> > + (unsigned long *)&pt->vcpu->arch.pmu.global_status);
> > + return;
> > + }
> > +
>
> There is no need to touch struct pt and to know details of KVM in
> arch/x86/events. Please add a function pointer
>
> void (*kvm_handle_pt_interrupt)(void);
>
> to some header, and in handle_pmi_common do
>
> if (unlikely(kvm_handle_intel_pt_interrupt))
> kvm_handle_intel_pt_interrupt();
> else
> intel_pt_interrupt();
>
> The function pointer can be assigned in
> kvm_before_interrupt/kvm_after_interrupt just like you do now.
>
> This should be a simpler patch too.
I know we do this in other places too; but it really is a very bad
pattern.
Exported function pointers are a fscking disaster waiting to happen.
There is nothing that limits access to kvm.o, any random module can try
and poke at it.
How about we extend perf_guest_info_callback with an arch section and
add:
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5aeb4c74fb99..76ce804e72c1 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5835,6 +5835,9 @@ struct perf_guest_info_callbacks *perf_guest_cbs;
int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
{
+ if (WARN_ON_ONCE(perf_guest_cbs))
+ return -EBUSY;
+
perf_guest_cbs = cbs;
return 0;
}
@@ -5842,6 +5845,9 @@ EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
{
+ if (WARN_ON_ONCE(perf_guest_cbs != cbs))
+ return -EINVAL;
+
perf_guest_cbs = NULL;
return 0;
}
next prev parent reply other threads:[~2019-02-06 16:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-19 20:04 [PATCH 0/3] Inject a PMI for KVM Guest when ToPA buffer is filled Luwei Kang
2019-01-19 20:04 ` [PATCH 1/3] perf/x86/intel/pt: Move pt structure to global header Luwei Kang
2019-01-19 20:04 ` [PATCH 2/3] perf/x86/intel/pt: Inject PMI for KVM guest Luwei Kang
2019-01-30 17:02 ` Paolo Bonzini
2019-02-06 16:34 ` Peter Zijlstra [this message]
2019-02-07 8:42 ` Paolo Bonzini
2019-01-19 20:04 ` [PATCH 3/3] KVM: x86: Add support of clear Trace_ToPA_PMI status Luwei Kang
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=20190206163423.GI17564@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=konrad.wilk@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luwei.kang@intel.com \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=songliubraving@fb.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=zsm@chromium.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