From patchwork Tue Mar 2 15:00:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12114227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EB5FC433DB for ; Wed, 3 Mar 2021 20:54:37 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E8E2764EFD for ; Wed, 3 Mar 2021 20:54:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8E2764EFD Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:From:Subject:References:Mime-Version: Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=txHZI8f2WeuhiEANcIrvDJqgSmzAiKsX23BCc6FpRqk=; b=VwATmeB8Z+3lqn ZxTNtefXo5N4MdaJJo5TkEtHksThDPiFS0IF4fcgT5OiWXnk1c2BqYgjIvSoxnkg+oZq0aXi5xMJ5 vQkw0/kXWMcxLDeKLHdXeiD5I/t+x8jHYOgqt2xpaCCDo8SWJkDOAHUjRof7W0NCtNZsopUVlGfSF iM6bSz+TfssGunhI6Arrew7CsUW5flCIs8CmmGipqQvcZ/3A/UcpRdzSxIZryyrN6QpqPsVH1Kn+V HOW6z21oNaWE8rg75ffnqf8H1+P1GlLM6rEzELrGv2PrY+xcligoc8KOP3cghYyoCjq16E1wl5Lw0 sGfCdGDSSpddvkQSVPNA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHYRQ-006U2I-3u; Wed, 03 Mar 2021 20:49:56 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHT75-005JIC-Dp for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 15:08:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=HnBOCbV9VZG795nVKhv9+ovMJqzwdkwkno12utvuuaM=; b=YhovO6ARlh3wd2UAmtwjrvSujW gQ5b0cCc6CjTjn4IxwSPZQ1Tju2mAPWvsGItik4RXGqf0qC6r/WOxL64AMR4FxWpZmfIUTzva1e/w 3vxelDtWF8j4vEWYE5tl0AvEMTqEQWDZvM9Q1dF6uqkFOykM1IjlkltWlgINfjcMllGxGpo1+Kcvo q5k35YURSpUeS7ORF2MslF75GlH26urYnkeGo50Al/4FrzMmzpJ8GV+vvak/D8HDPgml+Hk8S489Q lttaKJrkERf6LfH8bW3iXtu78p96AIAQKFHZ6PDZ4Ds49qtA3sd9sgowrNzp9c/sTGwzUedqZEj21 2JSz11jg==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6Xf-00HJOZ-9H for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 15:02:37 +0000 Received: by mail-qk1-x74a.google.com with SMTP id v184so17007703qkd.22 for ; Tue, 02 Mar 2021 07:02:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=HnBOCbV9VZG795nVKhv9+ovMJqzwdkwkno12utvuuaM=; b=MKbgEjESvYdThRoEkGC8RJg+Cz2zkWhWnC7wgzpWZoobh8AkycND5mEZtaZxNGp2tA qMEecbBNJ3k3ERyG50+v/O8XaK00waLfRVvvbN9E3QmDrCvJ0/93A4GuOQMcQEo8MGCk KW1fqTwiueVCj6eHaOhm9O/4JCquufE/tW2kQHZIkPJNvVz4btOdP6ZSAwQe3mnRfPlP C8g40caoVrU0GmaEVlnlhp/nXz17sJ/jz1XYk3CXeUoxTeSCsR7/po0Rbj/Hjj2JDVka EUIXH/D9Ghscn3/N8tbMa84ZOQHuQsv2ycIjv+zXEQqXRP/n8+aHwHdkJu4dhtp5hMOJ onJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HnBOCbV9VZG795nVKhv9+ovMJqzwdkwkno12utvuuaM=; b=Px/lxIW4khYMwtx4rjAd7VQh/6UGOPFLBsz8cIrVJt+zxFueO9Nne2rCxrupUqcnyh W3XRNsFoDRNLQjghQ7vslK20OnWjcQJHnI3dpxsUKS3zkfERj/TiwsUDDKC94/5AbHfW hUK7PGRK5S9csVhs/9sxHenz5Bv/hHLZpeeJXM73lvYzN7H/F0S1IBkx5+ec+xqoPrir g+u21CaNgqWcqQ5gtyzt8tsOFEyXCalL7IcAZUek+qAarzC4sC2B5tv2yEBVlYaiGDfR nBMtj9IPaOvbpYxPxI5K22hj92G/njySyHwkosAfDxjHJkf/buMgIvlx4LcAckyj8k9+ SBBA== X-Gm-Message-State: AOAM530EhXr1I4qGmWJUy6hRCrXq+Ez+swZJ1wkMKbai1NbLc3xCIL2O pctUC020Ic1J+W0bvclW1g/ZiNL6ENI2 X-Google-Smtp-Source: ABdhPJxomthrvtGXmLscfNQ4jzi8tGZD1QtytMGc0+RJgY/tfETMl/DO5FUjo9TRqk9VS+/6RprJ6oK1LBhx X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:ad4:56e9:: with SMTP id cr9mr20353191qvb.4.1614697276369; Tue, 02 Mar 2021 07:01:16 -0800 (PST) Date: Tue, 2 Mar 2021 15:00:01 +0000 In-Reply-To: <20210302150002.3685113-1-qperret@google.com> Message-Id: <20210302150002.3685113-32-qperret@google.com> Mime-Version: 1.0 References: <20210302150002.3685113-1-qperret@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v3 31/32] KVM: arm64: Disable PMU support in protected mode From: Quentin Perret To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, qperret@google.com, robh+dt@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_150237_585691_9CE60563 X-CRM114-Status: GOOD ( 12.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The host currently writes directly in EL2 per-CPU data sections from the PMU code when running in nVHE. In preparation for unmapping the EL2 sections from the host stage 2, disable PMU support in protected mode as we currently do not have a use-case for it. Signed-off-by: Quentin Perret Acked-by: Will Deacon --- arch/arm64/kvm/perf.c | 3 ++- arch/arm64/kvm/pmu.c | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/perf.c b/arch/arm64/kvm/perf.c index 739164324afe..8f860ae56bb7 100644 --- a/arch/arm64/kvm/perf.c +++ b/arch/arm64/kvm/perf.c @@ -55,7 +55,8 @@ int kvm_perf_init(void) * hardware performance counters. This could ensure the presence of * a physical PMU and CONFIG_PERF_EVENT is selected. */ - if (IS_ENABLED(CONFIG_ARM_PMU) && perf_num_counters() > 0) + if (IS_ENABLED(CONFIG_ARM_PMU) && perf_num_counters() > 0 + && !is_protected_kvm_enabled()) static_branch_enable(&kvm_arm_pmu_available); return perf_register_guest_info_callbacks(&kvm_guest_cbs); diff --git a/arch/arm64/kvm/pmu.c b/arch/arm64/kvm/pmu.c index faf32a44ba04..03a6c1f4a09a 100644 --- a/arch/arm64/kvm/pmu.c +++ b/arch/arm64/kvm/pmu.c @@ -33,7 +33,7 @@ void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) { struct kvm_host_data *ctx = this_cpu_ptr_hyp_sym(kvm_host_data); - if (!ctx || !kvm_pmu_switch_needed(attr)) + if (!kvm_arm_support_pmu_v3() || !ctx || !kvm_pmu_switch_needed(attr)) return; if (!attr->exclude_host) @@ -49,7 +49,7 @@ void kvm_clr_pmu_events(u32 clr) { struct kvm_host_data *ctx = this_cpu_ptr_hyp_sym(kvm_host_data); - if (!ctx) + if (!kvm_arm_support_pmu_v3() || !ctx) return; ctx->pmu_events.events_host &= ~clr; @@ -172,7 +172,7 @@ void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) struct kvm_host_data *host; u32 events_guest, events_host; - if (!has_vhe()) + if (!kvm_arm_support_pmu_v3() || !has_vhe()) return; preempt_disable(); @@ -193,7 +193,7 @@ void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) struct kvm_host_data *host; u32 events_guest, events_host; - if (!has_vhe()) + if (!kvm_arm_support_pmu_v3() || !has_vhe()) return; host = this_cpu_ptr_hyp_sym(kvm_host_data);