From patchwork Tue May 10 09:57:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12844749 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 D94B7C433F5 for ; Tue, 10 May 2022 09:58:37 +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=Bi65zuRI3xzCOhUlTmad5Autsp+S4lfL1i1kRHxe89Q=; b=bBoUK9W1vlKXgAeSIUUJJ033Nw Xp/yxYmAjYJ1MZkfg4DDNi3k+LS9vK3YhdY8qsvRbyVSVca07bOR+mqtOtLSA10rqcyPOkd7bP8ua l5+hRIZjftRxc1BQveDlEFG76A6F6fJN1x0uNMfPTwVMFMjRO6dEpv/c62VLHY436LeE2RoEBJIqC TuWanHasCeJ3Wv31sECXA4tY8uK81bXCW7vKzhITQSI/U9rj9u8SGnPRWRgm8/5ykZIV13YH7hDCh ulPY6efYm+O4aRBx5KPCMmWUpDDMqg8FHKCwhJX7OysOb3CzeTN35bp7K24PEGJp/tkWFOgWyPnlN SdIRvqmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1noMcV-0010tA-LI; Tue, 10 May 2022 09:57:31 +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 1noMcI-0010lG-9T for linux-arm-kernel@lists.infradead.org; Tue, 10 May 2022 09:57:19 +0000 Received: by mail-wm1-x34a.google.com with SMTP id k35-20020a05600c1ca300b003946a9764baso1049142wms.1 for ; Tue, 10 May 2022 02:57:15 -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=7tYpf+XT7mqI5zWxw47YWbNdAk9NQpBh8N59P16iZps=; b=JLXcjvk+IY4Z774b57vzytjw/LTp7NpJOIL/tlbDd9FP+oJ2WSZOpvoLPIZh9M9R2q vy2/eIwg8KGFk1sWxZ0ZGUa6Gn69nTU/XjdsN06Dyew10vGSQ/vs941bDwQGeTbagiE7 4waFgHP+qlXvZGc2EpRhP9IPYvxI48gw7buC1bp9wh3wOmprHaPKkC9HAmWHgTqYdlPS Bak4TpzVI7ZU9268sprBG1Hu8cBzzedrF4CPaOCaNI6Zzahd/+n7lvbYW6ULxexfigOm qGiGJOlRsEtAv96mwVGeeREn3LmSrbVdKiqoBOvuZg4vnKJ+zxZ47jPL5HB4Ks8y92a/ csTQ== 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=7tYpf+XT7mqI5zWxw47YWbNdAk9NQpBh8N59P16iZps=; b=QsFP7WM8hL0lWfESdBXyYlTWpXJAyyMJEchM5/eN0/6QNmv25U0jhiea9PEykI/+6s y2fAeXajeq0Z6o9keYvyvrLAXR1E2RyH6GpLrlb23pcfdCKzLgaicuxMC7ZCHfk3U7Y6 ZGy1ABuoCj8IrB2zj7wCFD0jtUUIxDXcGqYiCI5maXQFBHMHEcM/EpyqwpHyCzwOZdGv MvAjlIb2oCVm31yXfH2rNxVjCNEhboT2ukA6y9AnrqW5AcjAwbMOqqWKaCpXDd0DwdBT qdOQCY3NfYpTuaOUki7dWqe6Es2yEbMuQruhi6Dbzz6xLrgKPwJF/Byhz/eu7WkkpddT baxA== X-Gm-Message-State: AOAM532+H0VCbjARbUclxIN57ZxPBxBZOXCd8KfMEibvYrZ4uLvWMf3R ZGtiki77ISI2cuQeqhbmK/Uo6Z/66g== X-Google-Smtp-Source: ABdhPJweAUnGLDe5eXP7PWtCeinDLLVpuencYzseISdW/noLsSVemwzynd4ZY3BhcPIG0+uLrQnO21B9qQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:1553:b0:394:7642:7927 with SMTP id f19-20020a05600c155300b0039476427927mr21101313wmg.16.1652176633992; Tue, 10 May 2022 02:57:13 -0700 (PDT) Date: Tue, 10 May 2022 09:57:07 +0000 In-Reply-To: <20220510095710.148178-1-tabba@google.com> Message-Id: <20220510095710.148178-2-tabba@google.com> Mime-Version: 1.0 References: <20220510095710.148178-1-tabba@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH v4 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, oupton@google.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-20220510_025718_395463_FDAD7B7A X-CRM114-Status: GOOD ( 12.99 ) 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. Reviewed-by: Oliver Upton Signed-off-by: Fuad Tabba --- 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);