* [PATCH v3] arm64: perf: Ignore exclude_hv when kernel is running in HYP
@ 2017-05-02 16:29 Ganapatrao Kulkarni
2017-05-15 9:01 ` Ganapatrao Kulkarni
0 siblings, 1 reply; 2+ messages in thread
From: Ganapatrao Kulkarni @ 2017-05-02 16:29 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: Will.Deacon, catalin.marinas, mark.rutland, acme,
alexander.shishkin, peterz, mingo, jnair, gpkulkarni
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 != 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 = 1 and
exclude_kernel = 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 <ganapatrao.kulkarni@cavium.com>
---
Changelog:
V2/V3:
- Changes as per Will Deacon's suggestions.
V1: Initial patch
arch/arm64/kernel/perf_event.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index 57ae9d9..f6748c0 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -871,15 +871,17 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event,
if (attr->exclude_idle)
return -EPERM;
- if (is_kernel_in_hyp_mode() &&
- attr->exclude_kernel != attr->exclude_hv)
- return -EINVAL;
+ if (is_kernel_in_hyp_mode()) {
+ if (!attr->exclude_kernel)
+ config_base |= ARMV8_PMU_INCLUDE_EL2;
+ } else {
+ if (attr->exclude_kernel)
+ config_base |= ARMV8_PMU_EXCLUDE_EL1;
+ if (!attr->exclude_hv)
+ config_base |= ARMV8_PMU_INCLUDE_EL2;
+ }
if (attr->exclude_user)
config_base |= ARMV8_PMU_EXCLUDE_EL0;
- if (!is_kernel_in_hyp_mode() && attr->exclude_kernel)
- config_base |= ARMV8_PMU_EXCLUDE_EL1;
- if (!attr->exclude_hv)
- config_base |= ARMV8_PMU_INCLUDE_EL2;
/*
* Install the filter into config_base as this is used to
--
1.8.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] arm64: perf: Ignore exclude_hv when kernel is running in HYP
2017-05-02 16:29 [PATCH v3] arm64: perf: Ignore exclude_hv when kernel is running in HYP Ganapatrao Kulkarni
@ 2017-05-15 9:01 ` Ganapatrao Kulkarni
0 siblings, 0 replies; 2+ messages in thread
From: Ganapatrao Kulkarni @ 2017-05-15 9:01 UTC (permalink / raw)
To: Ganapatrao Kulkarni, Will Deacon
Cc: linux-kernel, linux-arm-kernel, Catalin Marinas, Mark Rutland,
acme, alexander.shishkin, peterz, Ingo Molnar, Jayachandran C
Hi Will,
if this patch looks good, can it go in 4.12-rc2 as bug fix?
or can it be queued for 4.13?
On Tue, May 2, 2017 at 9:59 PM, Ganapatrao Kulkarni
<ganapatrao.kulkarni@cavium.com> wrote:
> 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 != 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 = 1 and
> exclude_kernel = 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 <ganapatrao.kulkarni@cavium.com>
> ---
>
> Changelog:
>
> V2/V3:
> - Changes as per Will Deacon's suggestions.
>
> V1: Initial patch
>
> arch/arm64/kernel/perf_event.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
> index 57ae9d9..f6748c0 100644
> --- a/arch/arm64/kernel/perf_event.c
> +++ b/arch/arm64/kernel/perf_event.c
> @@ -871,15 +871,17 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event,
>
> if (attr->exclude_idle)
> return -EPERM;
> - if (is_kernel_in_hyp_mode() &&
> - attr->exclude_kernel != attr->exclude_hv)
> - return -EINVAL;
> + if (is_kernel_in_hyp_mode()) {
> + if (!attr->exclude_kernel)
> + config_base |= ARMV8_PMU_INCLUDE_EL2;
> + } else {
> + if (attr->exclude_kernel)
> + config_base |= ARMV8_PMU_EXCLUDE_EL1;
> + if (!attr->exclude_hv)
> + config_base |= ARMV8_PMU_INCLUDE_EL2;
> + }
> if (attr->exclude_user)
> config_base |= ARMV8_PMU_EXCLUDE_EL0;
> - if (!is_kernel_in_hyp_mode() && attr->exclude_kernel)
> - config_base |= ARMV8_PMU_EXCLUDE_EL1;
> - if (!attr->exclude_hv)
> - config_base |= ARMV8_PMU_INCLUDE_EL2;
>
> /*
> * Install the filter into config_base as this is used to
> --
> 1.8.1.4
>
thanks
Ganapat
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-05-15 9:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02 16:29 [PATCH v3] arm64: perf: Ignore exclude_hv when kernel is running in HYP Ganapatrao Kulkarni
2017-05-15 9:01 ` Ganapatrao Kulkarni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).