Return-Path: Received: from mail-by2nam03on0129.outbound.protection.outlook.com ([104.47.42.129]:62208 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965114AbeCSP70 (ORCPT ); Mon, 19 Mar 2018 11:59:26 -0400 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Ganapatrao Kulkarni , Will Deacon , Catalin Marinas , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 052/281] arm64: perf: Ignore exclude_hv when kernel is running in HYP Date: Mon, 19 Mar 2018 15:58:51 +0000 Message-ID: <20180319155742.13731-52-alexander.levin@microsoft.com> References: <20180319155742.13731-1-alexander.levin@microsoft.com> In-Reply-To: <20180319155742.13731-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Ganapatrao Kulkarni [ Upstream commit 78a19cfdf37d19002c83c8790853c1cc10feccdc ] commit d98ecdaca296 ("arm64: perf: Count EL2 events if the kernel is running in HYP") returns -EINVAL when perf system call perf_event_open is called with exclude_hv !=3D exclude_kernel. This change breaks applications on VHE enabled ARMv8.1 platforms. The issue was observed with HHVM application, which calls perf_event_open with exclude_hv =3D 1 and exclude_kernel =3D 0. There is no separate hypervisor privilege level when VHE is enabled, the host kernel runs at EL2. So when VHE is enabled, we should ignore exclude_hv from the application. This behaviour is consistent with PowerPC where the exclude_hv is ignored when the hypervisor is not present and with x86 where this flag is ignored. Signed-off-by: Ganapatrao Kulkarni [will: added comment to justify the behaviour of exclude_hv] Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin --- arch/arm64/kernel/perf_event.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.= c index 57ae9d9ed9bb..199a23f058d5 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -871,15 +871,24 @@ static int armv8pmu_set_event_filter(struct hw_perf_e= vent *event, =20 if (attr->exclude_idle) return -EPERM; - if (is_kernel_in_hyp_mode() && - attr->exclude_kernel !=3D attr->exclude_hv) - return -EINVAL; + + /* + * If we're running in hyp mode, then we *are* the hypervisor. + * Therefore we ignore exclude_hv in this configuration, since + * there's no hypervisor to sample anyway. This is consistent + * with other architectures (x86 and Power). + */ + if (is_kernel_in_hyp_mode()) { + if (!attr->exclude_kernel) + config_base |=3D ARMV8_PMU_INCLUDE_EL2; + } else { + if (attr->exclude_kernel) + config_base |=3D ARMV8_PMU_EXCLUDE_EL1; + if (!attr->exclude_hv) + config_base |=3D ARMV8_PMU_INCLUDE_EL2; + } if (attr->exclude_user) config_base |=3D ARMV8_PMU_EXCLUDE_EL0; - if (!is_kernel_in_hyp_mode() && attr->exclude_kernel) - config_base |=3D ARMV8_PMU_EXCLUDE_EL1; - if (!attr->exclude_hv) - config_base |=3D ARMV8_PMU_INCLUDE_EL2; =20 /* * Install the filter into config_base as this is used to --=20 2.14.1