linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] arm64: perf: Use only exclude_kernel attribute when kernel is running in HYP
@ 2017-04-19 17:44 Ganapatrao Kulkarni
  2017-04-20  8:49 ` Mark Rutland
  0 siblings, 1 reply; 13+ messages in thread
From: Ganapatrao Kulkarni @ 2017-04-19 17:44 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: Will.Deacon, catalin.marinas, mark.rutland, acme,
	alexander.shishkin, peterz, mingo, jnair, gpkulkarni

commit d98ecda (arm64: perf: Count EL2 events if the kernel is running in HYP)
is returning error for perf syscall with mixed attribute set for exclude_kernel
and exclude_hv. This change is breaking some applications (observed with hhvm)
when ran on VHE enabled platforms.

Adding fix to consider only exclude_kernel attribute when kernel is
running in HYP. Also adding sysfs file to notify the bhehaviour
of attribute exclude_hv.

Signed-off-by: Ganapatrao Kulkarni <ganapatrao.kulkarni@cavium.com>
---

Changelog:

V2:
 - Changes as per Will Deacon's suggestion.

V1: Initial patch

 arch/arm64/kernel/perf_event.c | 28 ++++++++++++++++++++++++----
 include/linux/perf/arm_pmu.h   |  1 +
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index 57ae9d9..b35b94c 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -535,6 +535,25 @@
 	.attrs = armv8_pmuv3_format_attrs,
 };
 
+static ssize_t armv8_pmuv3_exclude_hv_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", is_kernel_in_hyp_mode() ? 1 : 0);
+}
+
+static struct device_attribute armv8_pmuv3_exclude_hv_attr =
+		__ATTR(exclude_hv, 0444, armv8_pmuv3_exclude_hv_show, NULL);
+
+static struct attribute *armv8_pmuv3_attrs[] = {
+	&armv8_pmuv3_exclude_hv_attr.attr,
+	NULL,
+};
+
+static struct attribute_group armv8_pmuv3_attr_group = {
+	.name = "attr",
+	.attrs = armv8_pmuv3_attrs,
+};
+
 /*
  * Perf Events' indices
  */
@@ -871,14 +890,13 @@ 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() && !attr->exclude_kernel)
+		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)
+	if (!is_kernel_in_hyp_mode() && !attr->exclude_hv)
 		config_base |= ARMV8_PMU_INCLUDE_EL2;
 
 	/*
@@ -1008,6 +1026,8 @@ static int armv8_pmuv3_init(struct arm_pmu *cpu_pmu)
 		&armv8_pmuv3_events_attr_group;
 	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
 		&armv8_pmuv3_format_attr_group;
+	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_ATTR] =
+		&armv8_pmuv3_attr_group;
 	return armv8pmu_probe_pmu(cpu_pmu);
 }
 
diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
index 8462da2..a26ffc7 100644
--- a/include/linux/perf/arm_pmu.h
+++ b/include/linux/perf/arm_pmu.h
@@ -81,6 +81,7 @@ enum armpmu_attr_groups {
 	ARMPMU_ATTR_GROUP_COMMON,
 	ARMPMU_ATTR_GROUP_EVENTS,
 	ARMPMU_ATTR_GROUP_FORMATS,
+	ARMPMU_ATTR_GROUP_ATTR,
 	ARMPMU_NR_ATTR_GROUPS
 };
 
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-05-01 16:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-19 17:44 [PATCH v2] arm64: perf: Use only exclude_kernel attribute when kernel is running in HYP Ganapatrao Kulkarni
2017-04-20  8:49 ` Mark Rutland
2017-04-20  9:26   ` Ganapatrao Kulkarni
2017-04-24 15:45     ` Will Deacon
2017-04-25  3:43       ` Ganapatrao Kulkarni
2017-04-25 16:53         ` Will Deacon
2017-04-26  6:53           ` Jayachandran C.
     [not found]             ` <CY4PR07MB3415C0CEBB9D3DF0C249DC6793110@CY4PR07MB3415.namprd07.prod.outlook.com>
2017-04-26 10:10               ` Will Deacon
2017-04-26 13:41                 ` Jayachandran C
2017-04-27 17:37                   ` Will Deacon
2017-04-28 13:46                     ` Jayachandran C
2017-04-28 16:38                       ` Will Deacon
2017-05-01 16:10                         ` Jayachandran C

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).