Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp802783ima; Wed, 6 Feb 2019 08:35:18 -0800 (PST) X-Google-Smtp-Source: AHgI3IaWMbXJaqYGyYaAv7oil0jPavKm1jgywC9czcJi6dfm4xpkILbbE7WoGuK5k+GvRTPvmtFy X-Received: by 2002:a62:53c5:: with SMTP id h188mr11183266pfb.190.1549470918257; Wed, 06 Feb 2019 08:35:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549470918; cv=none; d=google.com; s=arc-20160816; b=vr6smnUxzhCmA8OKtGDOg3rCyR4f1x3c4NHQiZmQsRgkKZYRU3r7lSMaztLeF44Dk1 M03dwo1weh6SV7k5Vt7wmYX3rO56XIK/XwO1ydlKKUymty7i3ZyBSGT3aAtrnZQvTXyz NRNMZ0CG3bbcemvZfE1YXRE61N5O+gDiPca+Fwkxm9stBSmmCib2mvTb3t/w5PXuyDIs JlCiyMV7OJScAz7BkBR08UDxDLFJolDamzWIiZltcAHeTzWYtdWdhoqRJ+1e9962TlCa ksyxTqrjYHzzelA4LPXbE5iNOiHJ8v1uKvfjPUufFTepck7K2a3AOqhutV+DYxcFUg8u WpzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yaqrHMtkzU0QfS0XgeidGPWlqi4N+n6MDShva+367LA=; b=iIbJ0FUaByk0TyGZ9XcfVw7lYM5/IsPjZN59pq6HFa1KyqAB+IPaYIHROqKGKF0T4f 1dVydqc976qyWc5c9QxIS5LOPtQx5jpNvUKGs2iaMwiE/aiTdJMtYEARnqaq+Gh/2sNx 1kKGE7Bs9sJ7JZfrSpm6+8yAx3EMpuEtdPEjELIyM+toRls8Mp9cYvaSkWm3Y9WkcWgN ACGnjwTn6zf5RajtUIy6YINqBpzP5j/QpEopZC0EhJXO0gM8Ja/P/XD8+jwWnf4Q8c/2 ghRe1twMB+sE9DMpvtuKq01t8iAmInMWN6ols4XaqcYL5NMYL+iZqP80ITznng4QxnK0 pkqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=TIxnOEO1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si6115676plc.383.2019.02.06.08.35.00; Wed, 06 Feb 2019 08:35:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=TIxnOEO1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730999AbfBFQer (ORCPT + 99 others); Wed, 6 Feb 2019 11:34:47 -0500 Received: from merlin.infradead.org ([205.233.59.134]:57604 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730520AbfBFQeq (ORCPT ); Wed, 6 Feb 2019 11:34:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=yaqrHMtkzU0QfS0XgeidGPWlqi4N+n6MDShva+367LA=; b=TIxnOEO1Xs8s96dWklBgmEcOd G722pzE2uOrLogJBUCSYeZi7ZdL682QVAYxFRB9BB7brmIq+OYRzNFYWDpg1B3Pe4WLMVpGHpzbUI dPYE5p/X7WYKhWg6pdAmNGV/Hwh5A5ag64BADhof0WweGrTv65PFTOq8eLHZdHV1fS4JPXoD+RDmY GHYp6t2P9eibkf72gK3LlbM+2SxRuH4q63/h5Bq7HfY7Hb4EGb7kWd5ukB55RZUYd2WhSx2QbK2Wq fnH0tv1HPPahErKkrPAipv6p4+Lm9Zku3k8y0Zj2IHzoewl4EhnLVtj4j4byuNQ3Ipgw/0eo9gRN3 d3kkatEyw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1grQ9Z-0003uP-4e; Wed, 06 Feb 2019 16:34:25 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 977382029F1D4; Wed, 6 Feb 2019 17:34:23 +0100 (CET) Date: Wed, 6 Feb 2019 17:34:23 +0100 From: Peter Zijlstra To: Paolo Bonzini Cc: Luwei Kang , 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 Message-ID: <20190206163423.GI17564@hirez.programming.kicks-ass.net> References: <1547928284-2915-1-git-send-email-luwei.kang@intel.com> <1547928284-2915-3-git-send-email-luwei.kang@intel.com> <94fdce1b-9c42-e551-3099-ef7c4071a6ba@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <94fdce1b-9c42-e551-3099-ef7c4071a6ba@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; }