From patchwork Mon May 9 09:54:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12843275 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 DC42AC433EF for ; Mon, 9 May 2022 09:56:54 +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=k8eBa+gzfIlnTiHDGqSQracgj5 0PsQFWiIx7DNyChdfE5tpxECUm9HkeMvHLYJmFE6s3QkH3kx3w/1hJIBICVsxNKnogzNOTG+UI0va s+xyddfrUOiPxnPmjWXTL+T+0/C9H8/FgI4G+9r2yg16G/sRR6tiumrqc76vba5M4Zj+JNkbQplWJ NPome0kZAVTjVhOdNyEdajJc/73oI/t6/MQvpip5D7eWbLWkH/yS9m5Q3GmVO+gO6GVTiwjx/kQZn HtCD/QS2gNpmLiCsp4HgWBoaCGblY7/ziR5Y4z+QoYHjz4clzE4AFYwiC1xg7c1PZb0DYVDCt7VgT NIE417dQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1no07F-00Dbew-1W; Mon, 09 May 2022 09:55:45 +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 1no06d-00DbJ5-3O for linux-arm-kernel@lists.infradead.org; Mon, 09 May 2022 09:55:09 +0000 Received: by mail-wm1-x34a.google.com with SMTP id g3-20020a7bc4c3000000b0039409519611so4045593wmk.9 for ; Mon, 09 May 2022 02:55:06 -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=g+c+j7bSPEpCCZWJ0yc4bDlMeBuvKdOYSdoiinO/IP2PCsLySXUFR9IAdRQs1S3tvu PgLelUeE6kn8ZAGqxtbMk1YS+txI61vJkl2yOo5l08EGPAqXYXL9OqlhTUxIcidp9P8z 8ufEBABduWfAeM35eMBwGg7LiRpbESdvrQr8EMslXoQf8Fc/5y5mCPAg1aTLCpuAU3/x MvYNCvh6ohHRKwPFkSOBYdz+PQltzP3+xMSTb9J2Oo8KrkRiiSwaB71oTSjUqrHkFTiJ Xq/kxtHzkmPNttJ2KDJ3qCYCH+BG2GU4xdC8JvCD3VC8owBEPj+/ir2Uu4erigZ2waIl zgMA== 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=aIr/IzZa4dR0vuIMqsdJ5Ve0afdTxWjMwSR1mV+n9bN0UyYBgXwpcRALX5/AGN0/MS svCAgJS1O8GNwwfuS1RU6GOvnnTEhR9Vkjj0DRE0kdjvkQsq2lZQnpx0S8XjbgR0qVGQ f/T89jNAbytQ0szSyD4YsCL81hl4Yc+4TYY0gDgyWFH9sjfYQvgyDi9I5QRqrZDp2D89 Pe3axhNPcVz6Qp5TS9f8F3vJsbG//QcPt7RS/wpmQcrMHAmeSrmTqysYPJd5B04/g1eY 2KGfGSE6CjYrc/GYutSW8KXyyfUegkWo+XBZ1o1KqcPYVStpT8zbM76+/FGqKyaW6V+d lLLg== X-Gm-Message-State: AOAM531mk2q7s18W//QqfEs/w8i50qjgwf0ApjkfEf10FpCxinB81CTJ 75xtDdkpDecvfgcPHoVU7y6Bg4xhfg== X-Google-Smtp-Source: ABdhPJxhIl2GDHdXdY+j+1yX7XXlnMRyoArPiWnJ3Wu4rUcVSpHT51MLikxuqb9gd5v+xhTwR4aNmcQfAw== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a1c:35c7:0:b0:38e:4c59:6788 with SMTP id c190-20020a1c35c7000000b0038e4c596788mr941361wma.1.1652090104665; Mon, 09 May 2022 02:55:04 -0700 (PDT) Date: Mon, 9 May 2022 09:54:57 +0000 In-Reply-To: <20220509095500.2408785-1-tabba@google.com> Message-Id: <20220509095500.2408785-2-tabba@google.com> Mime-Version: 1.0 References: <20220509095500.2408785-1-tabba@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH v2 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_025507_171549_FE208BDA 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 --- 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);