lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190206163423.GI17564@hirez.programming.kicks-ass.net>
Date:   Wed, 6 Feb 2019 17:34:23 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Paolo Bonzini <pbonzini@...hat.com>
Cc:     Luwei Kang <luwei.kang@...el.com>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org, tglx@...utronix.de, mingo@...hat.com,
        bp@...en8.de, hpa@...or.com, x86@...nel.org, songliubraving@...com,
        rkrcmar@...hat.com, zsm@...omium.org,
        alexander.shishkin@...ux.intel.com, konrad.wilk@...cle.com,
        ak@...ux.intel.com
Subject: Re: [PATCH 2/3] perf/x86/intel/pt: Inject PMI for KVM guest

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;
 }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ