From patchwork Mon May 9 12:03:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12843374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 131FFC4332F for ; Mon, 9 May 2022 12:05:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=lm057iw/Fm9lkiT/T3sfDYG6hSyc0lZO6E9oKs9NbPI=; b=kv2UGs4spYOr8mRijDKJGJELs/ /jBoyJs/BRTkpLaW9Y895w+DbXRTFH2szgRRc4aa8OCc3eoWurZPYdzUD1RASl57pMpK3Yc0+ohhs DpSueCi7EENEvD3yDQpNfafEFk6usoictpVWpLEdi+Ct+5m5+mXyzFyn7E3jpisaSlDCKg76mNshM kf7xIfPZENZjSQ7k9/o31ozy+ReaFK1LK2VBdQ5LZyD7tpXvFTwGuJQMZNX2QtOeIoWQiwLWgqmEq OOOGWDiuerYq1Tz58iFEYr8JKJyUcZQD5LSXWseRomEWxFf62azeoNte65aL0aU16g6kTWtLcj85V 0jTSQD+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1no27J-00EERv-5Y; Mon, 09 May 2022 12:03:57 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1no271-00EEJQ-QR for linux-arm-kernel@lists.infradead.org; Mon, 09 May 2022 12:03:42 +0000 Received: by mail-wm1-x34a.google.com with SMTP id v9-20020a05600c214900b00393fedddf26so4635257wml.1 for ; Mon, 09 May 2022 05:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=PEsOycq/BqUbO+joqsC0k3/vBLTkPzLqQtgkv0/3GNY=; b=D95TwjidHbGJTlpWhdnQhP8xeyiQM5Wl3Wd6d43amZNHx2r2A0bRj/GdLAJuM20xF2 YuKzDh9HaACaoltlBQOiCRChlO1+sTR7G09M8621qMUyHwDaMzwMby526yVFlLm6fSTh V1BgbzPsxGNfM2qhT2Zt256CCtziEF0KUPKxgwGZbKKexNK98SQYGi6UOKVYleEqNTqO shOSlEvnyNAPZl4Qb9Ed1p6VSucWt6MtLLBGXs0FMpnrUB4ULti6F/RMToRCu7RPpbXc 8eFxOevtMxdZ6YblQP6lMhva0cu1xzFNlqp/V47L0N/eV2gvZtsdan1v2ndtsWvl8iZE eytg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PEsOycq/BqUbO+joqsC0k3/vBLTkPzLqQtgkv0/3GNY=; b=GixTvRZk+AZnXzKxLNLB5xSUpp1HBoCWQKiegKLC2jGqc+t4kmysL82WxJ6qzF4W+r WNA9t40eAp8TMhX4iBOWDHeQZZK0CYlT6c+ylVQRcrCsaTlk36/LWfWD61+p8XhwAmyk 8kuA2OWs/ZNVzMwWkFCwan5TP1nP5lTWS4r4RrpdbqaAVp7JCHaCxRzBcFiSw5W1hrqW kJ3TB8X3PCmQ7ER6OvlV7UxvZE5tvwmHtJoAvihbmbIz/jnJmSTC75YtjTPoALRWAr9r fNxBZxmYaIZPyf2DjJe2QKafM5jYuETPebzVCShjOPe9ECd3uT7lmHq5MiwXgIvZ6j1w urGg== X-Gm-Message-State: AOAM5326NGxbfVfVI2znHyztJqVPboS+eybL6VTfFK509Ti2d5OMUpZS 9qhS9KOnKpzOvuI+XUsxIdAu0Il+Zw== X-Google-Smtp-Source: ABdhPJzex7lNd7SzGwLrdRB/ywArjVyPaFTHaYY7n9Dvh6Sh3zCzZ/8dAh9ayZN24LUXtQ5loKemTuLlvQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:3583:b0:394:77fc:d6a2 with SMTP id p3-20020a05600c358300b0039477fcd6a2mr15673600wmq.63.1652097814110; Mon, 09 May 2022 05:03:34 -0700 (PDT) Date: Mon, 9 May 2022 12:03:27 +0000 In-Reply-To: <20220509120330.3043773-1-tabba@google.com> Message-Id: <20220509120330.3043773-2-tabba@google.com> Mime-Version: 1.0 References: <20220509120330.3043773-1-tabba@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH v3 1/4] KVM: arm64: Wrapper for getting pmu_events From: Fuad Tabba To: kvmarm@lists.cs.columbia.edu Cc: maz@kernel.org, will@kernel.org, qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, drjones@redhat.com, linux-arm-kernel@lists.infradead.org, tabba@google.com, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220509_050339_940466_BACC1CB3 X-CRM114-Status: GOOD ( 13.73 ) 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 Eases migrating away from using hyp data and simplifies the code. No functional change intended. Signed-off-by: Fuad Tabba Reviewed-by: Oliver Upton --- arch/arm64/kvm/pmu.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/arch/arm64/kvm/pmu.c b/arch/arm64/kvm/pmu.c index 03a6c1f4a09a..4bd38ff34221 100644 --- a/arch/arm64/kvm/pmu.c +++ b/arch/arm64/kvm/pmu.c @@ -25,21 +25,31 @@ static bool kvm_pmu_switch_needed(struct perf_event_attr *attr) return (attr->exclude_host != attr->exclude_guest); } +static struct kvm_pmu_events *kvm_get_pmu_events(void) +{ + struct kvm_host_data *ctx = this_cpu_ptr_hyp_sym(kvm_host_data); + + if (!ctx) + return NULL; + + return &ctx->pmu_events; +} + /* * Add events to track that we may want to switch at guest entry/exit * time. */ 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); + struct kvm_pmu_events *pmu = kvm_get_pmu_events(); - if (!kvm_arm_support_pmu_v3() || !ctx || !kvm_pmu_switch_needed(attr)) + if (!kvm_arm_support_pmu_v3() || !pmu || !kvm_pmu_switch_needed(attr)) return; if (!attr->exclude_host) - ctx->pmu_events.events_host |= set; + pmu->events_host |= set; if (!attr->exclude_guest) - ctx->pmu_events.events_guest |= set; + pmu->events_guest |= set; } /* @@ -47,13 +57,13 @@ void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) */ void kvm_clr_pmu_events(u32 clr) { - struct kvm_host_data *ctx = this_cpu_ptr_hyp_sym(kvm_host_data); + struct kvm_pmu_events *pmu = kvm_get_pmu_events(); - if (!kvm_arm_support_pmu_v3() || !ctx) + if (!kvm_arm_support_pmu_v3() || !pmu) return; - ctx->pmu_events.events_host &= ~clr; - ctx->pmu_events.events_guest &= ~clr; + pmu->events_host &= ~clr; + pmu->events_guest &= ~clr; } #define PMEVTYPER_READ_CASE(idx) \ @@ -169,16 +179,16 @@ static void kvm_vcpu_pmu_disable_el0(unsigned long events) */ void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) { - struct kvm_host_data *host; + struct kvm_pmu_events *pmu; u32 events_guest, events_host; if (!kvm_arm_support_pmu_v3() || !has_vhe()) return; preempt_disable(); - host = this_cpu_ptr_hyp_sym(kvm_host_data); - events_guest = host->pmu_events.events_guest; - events_host = host->pmu_events.events_host; + pmu = kvm_get_pmu_events(); + events_guest = pmu->events_guest; + events_host = pmu->events_host; kvm_vcpu_pmu_enable_el0(events_guest); kvm_vcpu_pmu_disable_el0(events_host); @@ -190,15 +200,15 @@ void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) */ void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) { - struct kvm_host_data *host; + struct kvm_pmu_events *pmu; u32 events_guest, events_host; if (!kvm_arm_support_pmu_v3() || !has_vhe()) return; - host = this_cpu_ptr_hyp_sym(kvm_host_data); - events_guest = host->pmu_events.events_guest; - events_host = host->pmu_events.events_host; + pmu = kvm_get_pmu_events(); + events_guest = pmu->events_guest; + events_host = pmu->events_host; kvm_vcpu_pmu_enable_el0(events_host); kvm_vcpu_pmu_disable_el0(events_guest);