From patchwork Wed Mar 10 17:57:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12128963 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=-17.0 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 2900CC433DB for ; Wed, 10 Mar 2021 18:15:27 +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 3E12764DC4 for ; Wed, 10 Mar 2021 18:15:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E12764DC4 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=VRlzB8uBj/qjvPGQm3YzZJxyfyETuwC0pLRvPeTRKSU=; b=okuISzam81KGxc uKPQhUN/CxbmRe8NQSVl0VjVXFiRLYCXEnX+RFdzPc8dn4Pc7v/zrzlxjShVo6VOpLcYHltmzVtq5 36EB++Qf8sNho4whBGEOGyae/kbhVAGLrtuqB/1dIimn9SraKTrLVDKdUKF4oFYU9yyMwzOaMJxF0 jonaoTN2FtmhhWfwt9hZkRgRWJKblysEJ+yQf4svvfdkXuqYGasUtG5AC42AG8qo0d5P32bY+0T8s W+2gApNsSUUKqPAFmaJtsG6RkuHi7TGXc2fvPS+Yj0feKQYO5rpZ7wR6EYOWiPEyjRHizvcmPxUJt Q7l/AxGHBLijhyoXMG1Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lK3L1-007ToS-KO; Wed, 10 Mar 2021 18:13:39 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lK36y-007Oba-Ed for linux-arm-kernel@lists.infradead.org; Wed, 10 Mar 2021 17:59:11 +0000 Received: by mail-wr1-x44a.google.com with SMTP id z17so8301909wrv.23 for ; Wed, 10 Mar 2021 09:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4EIGP2sevMQZpUEhabq0vC76HCNx6QyIyPvKeAoptlw=; b=IUQjACmevhkq9a+GZxx+Ua4aB9ez1Bug28fxYTbFk46qxQU32oTjX7DRLGH9l/Il7X FqP7G7yyiuLPnHPSwII8NLcc8xT3okF4VsOdVhhzD45KhzQKh06Ri+jitNWpfqbLNjbH s7lNBTP16IEnv0g+B92roDljctBUXo4JJN1l3q5jmxXNKvjrw4EX2MUG2YyqiyXTFc0v efw7ExzmKbpVMP1Qf7AqwLiKwmBN9zmwUKW/Xurj/d027vYb3d6dQtC+WGD06I7JSB1Y AFj0gkGVkEn9NnTYZK0YUmw6ye4NL3Qrs3yQ4hcfmWyjyO/wYe696C31It5TCXguX2XH NObg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4EIGP2sevMQZpUEhabq0vC76HCNx6QyIyPvKeAoptlw=; b=COkfR5bt+CDeCQDDboI5ocPLnrH1Bf6F0RW2AuTa9qNFrUN4eKCoAvmg19KPtwrwp9 KFlI3WkFHKSzk7bP5pCd4qL6b+vINmSa7Sojgptsej1gFzyby/JhNX6thTyYq8aN2Cc4 yTizy2/xjcpRY1WYXDzoFuxE6Utjzoj8Ebgpht/NAQmimEfZwhX1xcGOczEzEa/fVS4C GGMmTCmM6iuAdtghzYa9Q7hp5H5E9SG4kILQsCJyjJZ6CTDQvz7ThvJemtP5HVt3FlA2 9MIK79Nqk97tS9wFZq0DR9pYFj94ryAoyqhCOL2GPAKIWfDDmliCJ6aLT5Zh4CURwM5B FiUA== X-Gm-Message-State: AOAM530M/xZZ2IlXHHziZH096YylWyPcWeUNShOy4zWckM0ecpe6h9C6 Th2eyLsFULre3x3Txdua5ATojggHNgbm X-Google-Smtp-Source: ABdhPJxqMXK+TnYtjOGnCmi+0PPkd0E3rU72V4cOYCFhyuU5o0IeGdkRrDs5euTQUF4Pwmy1O7cEd08Y9MWQ X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a05:6000:1803:: with SMTP id m3mr4806187wrh.50.1615399147126; Wed, 10 Mar 2021 09:59:07 -0800 (PST) Date: Wed, 10 Mar 2021 17:57:50 +0000 In-Reply-To: <20210310175751.3320106-1-qperret@google.com> Message-Id: <20210310175751.3320106-34-qperret@google.com> Mime-Version: 1.0 References: <20210310175751.3320106-1-qperret@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v4 33/34] 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, ardb@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210310_175908_815056_73BB1BCE X-CRM114-Status: GOOD ( 14.81 ) 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. Acked-by: Will Deacon Signed-off-by: Quentin Perret --- 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);