Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968662AbdDSRox (ORCPT ); Wed, 19 Apr 2017 13:44:53 -0400 Received: from mail-cys01nam02on0041.outbound.protection.outlook.com ([104.47.37.41]:27680 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S968553AbdDSRot (ORCPT ); Wed, 19 Apr 2017 13:44:49 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=cavium.com; From: Ganapatrao Kulkarni To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Will.Deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, acme@kernel.org, alexander.shishkin@linux.intel.com, peterz@infradead.org, mingo@redhat.com, jnair@caviumnetworks.com, gpkulkarni@gmail.com Subject: [PATCH v2] arm64: perf: Use only exclude_kernel attribute when kernel is running in HYP Date: Wed, 19 Apr 2017 23:14:06 +0530 Message-Id: <1492623846-29335-1-git-send-email-ganapatrao.kulkarni@cavium.com> X-Mailer: git-send-email 1.8.1.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR01CA0046.INDPRD01.PROD.OUTLOOK.COM (10.163.199.18) To CY1PR0701MB1696.namprd07.prod.outlook.com (10.163.20.30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1ab2ee2b-d475-4eb1-c874-08d4874bc58e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:CY1PR0701MB1696; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1696;3:pnzqGYDnjL6mSzTMPLb1pe2MNLEhF5flV6ju0xLPhA8ywkmOiMj6jMABGwkOJBrr5PfCUcAL7hFE3dk18RTlBYMFPRyo3CC2Z3qJBeuh4vfXVznsCvN0euYsezhmIcn3kQ/t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jwMB2CbIRBR1E46X31kdlYIsJMtNXUKMen9PwfjlV1uAWgikKNx6JP9xRa7YycCGLeuxcKJ7pUG49rZykJDEz546hxOZqdo3cgob3DpYnIgRVB6YIm3f6SNgUonkhnfatNRAMpbHQrtxfNXkuNgP28kfO8R9QGXm2rYmkKuuo87884jv3SSgJbhBBDjhgU1jjuChdgG6x2CauHxMdoeB4kmoRZhidBBvDyX04EeOGeRAs4ti///g0ou62xQlA2CigEqEF2zv0NKNRYPmQ917PzbCYoNxysjn8zdFjPyu7dB21HRXBObWG8ebilJc9cvtRwjzIbnEN+RXBW8CZz056djZFD8wF34tNJxvAqegnKQQFPQ7zdKxrsXqinugOoxYI5zo0 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(278428928389397); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(6041248)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123555025)(20161123564025)(6072148);SRVR:CY1PR0701MB1696;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0701MB1696; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1696;4:neSUhLbq+sJXVVS/aR+pHTsEI64oVGw7OAUzH55Xv7IyFJba85CSi6ZgBQWQ59KKGGxG0XMQdPwXE4Eg2E2aSHycmOBJ00I6LfA3xXsz4DWum2L6u6cUYXx7ZVZmons/RXwaUCKwsMbPeJrnfp6VoMFRmmWy2/8RKNbSRnkXvgo7u1jriHiFnY4XAb96DS+gEficWTUz4seUJ92WWveei8y10rQBxpbEUtk0ZHwVDwCVWz+3PQZHKgt/dXYr5lV0YGpc/7xN86JS+U0RiDetcXdnG1N0n/183MqytQUpHzEwnbnFZvz4eWm6a9pFcTm8lQoWfwLeQBZUitYgh2XSF3nFtAVRPS45Ky9eU+6qzHF3rhoWITONjMpT1VlTWjMGFXDMaogNjGLt9wRvF++YXwxmVAwPU5KdgZyNHGMBEcsNDnDMJCMUTBF+Hj5NegONSohOF8ZTdyMUgj7jTkP9B77fNWeNXuZG754KwKKtFz+X2D4QK6tBUEaYtbk+i/QUrMJZdevRFQxXEMt6OPFSYURwzr27s5pdsXa6coIlDndfg20QIxzidXdIOmakiVq1zBl27REwy1In5XUvRqeINNfpSjGNY3XwZ4hZW2mhhJqapAcRVnE6m+/mu8SUKycCDN0/kcEMuiN1dZy3Ve2NgHTTr1wQVvNFqKAuX47APPp91cvR3XS+AOnaB71Pd7bG/gcWlFJsvNBd8ewaKKgToi/X5Om8Ieqmw7Kf8YeIE9YbnisIazanC5HNpIre9HXCVsiTe+f6+FWwA/tbl2SgqA== X-Forefront-PRVS: 028256169F X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39450400003)(39850400002)(39400400002)(39410400002)(39840400002)(54534003)(86362001)(5009440100003)(189998001)(7416002)(36756003)(4720700003)(42186005)(50466002)(6666003)(3846002)(6116002)(5003940100001)(2906002)(33646002)(48376002)(50986999)(5660300001)(38730400002)(53936002)(81166006)(8676002)(6512007)(305945005)(47776003)(4326008)(6486002)(50226002)(25786009)(110136004)(66066001)(6506006);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0701MB1696;H:mypc.cavium.com.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0701MB1696;23:Z+3sgjgfHEtLbcsQXEjMJ3YB2Yd52iWL5t5doyW?= =?us-ascii?Q?QZcxGDovSH7/9TFKDklTd1sIJzs1RwtjC2CKn5TOoniUZUXArx348aLVQYZD?= =?us-ascii?Q?yJENg9mwEPDaQq1PCW3IF4DoxgldtE7cotfen3nW7SRU5vY8812/jtxqGBwF?= =?us-ascii?Q?PL5DaZ06UhbDYhDQaSdMWYYJ/iu0w/c4imPh1AavaKy8wdLxIU0EsBnbUteE?= =?us-ascii?Q?FAlNpBkACC+rzOVIb8adhMJITbs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Lkry1vZ5supRVik+Smp94y3zSpqRiYm6awsNhx0vUELU471ZhUNx1eXiZOz5SM7g4JPdfiw== X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2017 17:44:43.7969 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0701MB1696 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2858 Lines: 94 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 --- 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