Received: by 10.192.165.156 with SMTP id m28csp1078915imm; Wed, 11 Apr 2018 12:01:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/0RCRKzrNwGGOTBX/Cy5wsYQ2qrTQ2a/mBhxUi26QBobz0fdHygZtkoAgwQpwsZCfvzFD+ X-Received: by 2002:a17:902:6c07:: with SMTP id q7-v6mr6312867plk.67.1523473310032; Wed, 11 Apr 2018 12:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523473309; cv=none; d=google.com; s=arc-20160816; b=iSmqxehqjjxTUJ7tNUbqyr7vumkS5PHoMoOh+2aKBm+lKoDnNCb+aso2XsOM/1h9lj gNMhil2/Zn/vx2uaVgRck2At1/U5aADGhQanN96lnSe/+1nZ1s5Blnpyq4MFW5lBbR0c 3zCtjO/gMFhqkO3kodpEkaU7k2x3jQfkV0DtDQTLXViXDGNXylO9JciQdpptN2AR5KuG XrxkMls2WPjLl7J8WGIeK8ifYs1JNmgfLjFoREKv6jw6G8llPGPj/VXVLb0jFCbxFnQe QCAC8sow7jwBhncEvkVIRnduk0vfS3WDc9vC3HeT7nVqlH0nD58CeObvr7/6gIe0ooHB yYgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=QGwEDlfiyOrhEXCMOp0qFmQWXaqmdj/gFuQqEBcnmA0=; b=DUB0zW2gIKxkxePZ6c/yYRsAumx7beEewke4H91wXCnXFl1awP8XbQQhw49qeD/keN T7UXX1sSHbv00P1PfBdVqAaXbwfpnQZPxRVhA3j1u+IbjjuoNFhgK24J0zR6v4ZMhIZ3 2WhzDAUUKIKCjOToESZSiSPL0YI9tlG3zqV6hd4shDxFhZcaxy6h/zBBTTw+m4RWFmZb VHfqWhFwP4fj8y8skYWoD35sDygb3wsdFmFPczGF0+daSB+yn7Uq3TR7AD7gOKO4Wbyh KqZx9ZaasSLWuVZzrUmUCf7A1EVJbt8ZlRovR8ryaA9m9wVFh0l7tyTQuehyRUW8X/Mw HNdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si1101147pga.776.2018.04.11.12.01.12; Wed, 11 Apr 2018 12:01:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933572AbeDKSyq (ORCPT + 99 others); Wed, 11 Apr 2018 14:54:46 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34652 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932754AbeDKSyo (ORCPT ); Wed, 11 Apr 2018 14:54:44 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B4B66C03; Wed, 11 Apr 2018 18:54:43 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ganapatrao Kulkarni , Will Deacon , Catalin Marinas , Sasha Levin Subject: [PATCH 4.9 051/310] arm64: perf: Ignore exclude_hv when kernel is running in HYP Date: Wed, 11 Apr 2018 20:33:10 +0200 Message-Id: <20180411183624.447941950@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ 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 != 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 [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 Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/perf_event.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -871,15 +871,24 @@ static int armv8pmu_set_event_filter(str if (attr->exclude_idle) return -EPERM; - if (is_kernel_in_hyp_mode() && - attr->exclude_kernel != 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 |= 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