From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752806AbcBOS1s (ORCPT ); Mon, 15 Feb 2016 13:27:48 -0500 Received: from foss.arm.com ([217.140.101.70]:47151 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752756AbcBOS1r (ORCPT ); Mon, 15 Feb 2016 13:27:47 -0500 Date: Mon, 15 Feb 2016 18:27:51 +0000 From: Will Deacon To: Marc Zyngier Cc: Catalin Marinas , Mark Rutland , Christoffer Dall , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH v4 20/23] arm64: perf: Count EL2 events if the kernel is running in HYP Message-ID: <20160215182751.GP6298@arm.com> References: <1455216004-19499-1-git-send-email-marc.zyngier@arm.com> <1455216004-19499-21-git-send-email-marc.zyngier@arm.com> <20160215172247.GL6298@arm.com> <56C217A7.5020105@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56C217A7.5020105@arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 15, 2016 at 06:23:35PM +0000, Marc Zyngier wrote: > On 15/02/16 17:22, Will Deacon wrote: > > On Thu, Feb 11, 2016 at 06:40:01PM +0000, Marc Zyngier wrote: > >> When the kernel is running in HYP (with VHE), it is necessary to > >> include EL2 events if the user requests counting kernel or > >> hypervisor events. > >> > >> Reviewed-by: Christoffer Dall > >> Acked-by: Catalin Marinas > >> Signed-off-by: Marc Zyngier > >> --- > >> arch/arm64/kernel/perf_event.c | 14 ++++++++++---- > >> 1 file changed, 10 insertions(+), 4 deletions(-) > >> > >> diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c > >> index f7ab14c..6013a38 100644 > >> --- a/arch/arm64/kernel/perf_event.c > >> +++ b/arch/arm64/kernel/perf_event.c > >> @@ -20,6 +20,7 @@ > >> */ > >> > >> #include > >> +#include > >> > >> #include > >> #include > >> @@ -693,10 +694,15 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event, > >> return -EPERM; > >> if (attr->exclude_user) > >> config_base |= ARMV8_EXCLUDE_EL0; > >> - if (attr->exclude_kernel) > >> - config_base |= ARMV8_EXCLUDE_EL1; > >> - if (!attr->exclude_hv) > >> - config_base |= ARMV8_INCLUDE_EL2; > >> + if (is_kernel_in_hyp_mode()) { > >> + if (!attr->exclude_kernel || !attr->exclude_hv) > >> + config_base |= ARMV8_INCLUDE_EL2; > > > > Hmm, so if userspace sets exclude_kernel but not exclude_user and > > exclude_hv, what should we do? I'm slightly tempted to reject the > > filter with -EINVAL... > > I was angling for the minimum level of surprise for the user, but > I guess that the results are going to be troubling anyway. > > How about something like this on top: > > diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c > index 6013a38..8c00ed4 100644 > --- a/arch/arm64/kernel/perf_event.c > +++ b/arch/arm64/kernel/perf_event.c > @@ -695,7 +695,10 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event, > if (attr->exclude_user) > config_base |= ARMV8_EXCLUDE_EL0; > if (is_kernel_in_hyp_mode()) { > - if (!attr->exclude_kernel || !attr->exclude_hv) > + /* Demand that kernel and hv are consistent */ > + if (attr->exclude_kernel != attr->exclude_hv) > + return -EINVAL; > + if (!attr->exclude_hv) > config_base |= ARMV8_INCLUDE_EL2; > } else { > if (attr->exclude_kernel) Looks like the right idea, and you can probably refactor things slightly to avoid having two codepaths dealing with ARMV8_INCLUDE_EL2. Note that I've got a couple of outstanding questions with the architects that I should have answers to later in the week. Will