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); From patchwork Tue May 10 09:57:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12844751 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 327B3C4332F for ; Tue, 10 May 2022 09:58:41 +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=nqx2tm7ztm1JkV7/VKyvtLV6sbPshNnOzJolAfMGcqM=; b=Q5Y0LwFC+cj861JYLFk/jfuCiF jA7MQQ/a3uL4tWApFNdanHH0hF/ScmozpSIZa4o1/L6VulYXKlpeQ/0BVPrt8dbwHq5+CFouvRUfD QHc7nu5DAZ/WMHXv8pQhnFHF+cuVuTLAfT2JbrGcqN/CnfrQOgX9zK9Tp6x+dpxA41/HW8/p3IAs3 3Wb7nxmfi7c+K9626/yW6hEqsOp/JzMMVp8YUkzLwPTN/dm02QB6nqVSCNHJHcCpHjdsl7gSkzQxl Kqx4a/v1e7lBaSvjJ1WT9wRboSAgUJZd9LXqhCsKsNxHwWXDLEssTO+aqaGPYALozIXHtvgWueFvs giH2Ruvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1noMcg-0010xW-VZ; Tue, 10 May 2022 09:57:43 +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-0010mL-GG 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 bi5-20020a05600c3d8500b0039489e1d18dso1038585wmb.5 for ; Tue, 10 May 2022 02:57:17 -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=4qfi1EyfzrAF17+2Q3vwA2/NLnPP5Sk/AW+fkoZOXmg=; b=Z35kcWzQCyc0/bgmoXEQqd04oE3P3i58RdxLoNVzcFf9aRRH2ZdLk8CKxbpiwmuekE wmQb457pslsukEJOJbgp6RJM5XJAUf1svZqei9GW5UR+07V7fQkMUstay9+aCOsPVwxz qQb8PUj20Ac8wsYwgFiAfCDNOJ/lAQCvXJ9covjO8jGSQhoTfMiIFEY97vShdao+1tym 76DvaTxgSoSmHK6kAGvoeXmi/vXP1lZGfhJdx3vRb1aoGcLp0eEzJNaIO2IyoFftfItv 9kmcuj87Et9SPGkBp4c4vgyqZXB4olQQgPVaTVs7pJ+QMl04tf1DAm0w1BNV8x7Q/mb9 DYUQ== 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=4qfi1EyfzrAF17+2Q3vwA2/NLnPP5Sk/AW+fkoZOXmg=; b=sq2t9rOnHpT3Kz1uwUSS2LwU3DhVKeLbHsKGpOHPY6v8OwCMoQTJb04c2LKqtyqjKU H1lTeewFBSINHloQa/qVGBkR6lGFjmwR62HBjh5MXrsPbhSBTvBUX/TSx6mZ/UDg0Ahz wJI5ftEX1bYGxFY3+/sgFOGd6uk9NKkiS2bcsXWQE8b9QgjH6HvJSjApsHgWfJgUE2WX MkzX6U2ODJ9uY2mtOVpAr3Xcj/d8iQwqBFU6LG7K3I6E/LfGCZMa+HRBxSlvi3fnsc1J uAWY4UcOeoNwrKGZ8c7UYje/bnPktbyhctn6rCDCL8KwTrB1PlmgdVsbtk/ytIGxBZjX 48XQ== X-Gm-Message-State: AOAM533TRaYUG72To5S4RQO/+n+dYwaQ0pNgeVAPYghre1fYAnsuHx98 mIeJxKaxHfqr4KZ+Cj5Cak8tBd9gIA== X-Google-Smtp-Source: ABdhPJx45MlpCKopCtV4MwMconf+bzC+zG0kq7MrmyagGdL8LTEIOWRQrf/j8rQrG1mUQKHBc7UCeGq4Wg== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:4f8d:b0:394:939f:bd2f with SMTP id n13-20020a05600c4f8d00b00394939fbd2fmr8148434wmq.16.1652176636198; Tue, 10 May 2022 02:57:16 -0700 (PDT) Date: Tue, 10 May 2022 09:57:08 +0000 In-Reply-To: <20220510095710.148178-1-tabba@google.com> Message-Id: <20220510095710.148178-3-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 2/4] KVM: arm64: Repack struct kvm_pmu to reduce size 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_578935_5D54F848 X-CRM114-Status: GOOD ( 11.47 ) 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 struct kvm_pmu has 2 holes using 10 bytes. This is instantiated in all vcpus, so it adds up. Repack the structures to remove the holes. No functional change intended. Reviewed-by: Oliver Upton Signed-off-by: Fuad Tabba --- include/kvm/arm_pmu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index 20193416d214..eaa8290b116f 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -21,12 +21,12 @@ struct kvm_pmc { }; struct kvm_pmu { - int irq_num; + struct irq_work overflow_work; struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS]; DECLARE_BITMAP(chained, ARMV8_PMU_MAX_COUNTER_PAIRS); + int irq_num; bool created; bool irq_level; - struct irq_work overflow_work; }; struct arm_pmu_entry { From patchwork Tue May 10 09:57:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12844752 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 0FBE0C433EF for ; Tue, 10 May 2022 09:58:58 +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=vNL8r9GhF9GWrYqF07gYps2SYXWpZ/5RN6scGvwt0UE=; b=UZ4troZgfzFvYCvEitO86YJ6vt Xtwxcw/TtHhMJIPjc9Xb2erhAbZEBmUliEplGigLKZVZmNbuiEuvJU6pkHGydVfJmCLX8hFOJL/rI RSYvg0A5gbgc4PTRrSiMoDWHbbGXluUyLhToQa+modxh2vh90zTs5uOr2TgK5Phrdj8tzrEsmT87q V67ETMi8NC/+XmhR9xoCYtUXcjTZCUvVWexAIxBfuK2QlicnifiYyY6TXYYGyDzyrtTXtWZALWWQY 05F36VAMkzKzySFvMdluLNuuOCjK7JT56olTq9DcHkQbjZ7+UKKo8Utu21Cs5EOAdV4LRTmqmbWb+ 42eTXycQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1noMcr-00112b-3m; Tue, 10 May 2022 09:57:53 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1noMcM-0010ng-Bo for linux-arm-kernel@lists.infradead.org; Tue, 10 May 2022 09:57:24 +0000 Received: by mail-wr1-x449.google.com with SMTP id o11-20020adfca0b000000b0020adc114131so6816368wrh.8 for ; Tue, 10 May 2022 02:57:19 -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=cdS24URiQ9hDODL+n8hjhO6nhNMKCwWb+mMIRmYF2dE=; b=LsxlGn3eK/gaXkjid+4h362uyvEp3HGbkEplRLogSnmiaj0lRIdwKGAgLduIpPBftQ pLmCrau8dDHXNwaHu4HEqCe8Lbi1tgDONAzIMlrWcUTkzeZJjxzxUQD7GZGjUl/OaZIn CpjISr4fHhXotMlUTNR6HVF9p308yrRwu7StRd65i6yFHItM8QuMpJK2lFC/s0bpDekm +YqiVYNfEwhyk+nD6n5R/FEc9hLhk/cpTduDrilN7N4PgsbFlnwRyRRE7Atcd1gnLNdX n43rnbucqe4CkX5f/hXqTU2m4lTHBupGli/msS8c1D5vCb6g+vhCmMKs0WYmYXkqIm4y wWQA== 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=cdS24URiQ9hDODL+n8hjhO6nhNMKCwWb+mMIRmYF2dE=; b=b7bKzK2UsYj3OXNIB1DVbQS5UoM03GR+BOh8KIulc6Uq7HlGjmr1QCyq+xdz2GRPMC 09ayiOv1vM2uyIDtFhqB2N0OxI///epbtZGq2X5eukQjYQ6nndC3i/Ccm0u9ltsAbJdc 3QL2VDOGnFt+uWtvNMyhr6ClFbGwJIPKqaMugNWxq+5xYFqNFDAYgm2ZDgAVIeOd/+qd 9cZBX0quOElDP8r4G1F8MdSXsg9Q479kJOWhckFcAE3maONVjrOO+7b6YkGVQMOfOC3T rIvxmXINj+WHuJs25qQ9eFb1UIZ/hNRnoH5zV1j1bsFHNm4+c4R70ZYNGs4LEle2eddh TuXA== X-Gm-Message-State: AOAM530P+wBOPFnwv8d99imY/VEdQ2wePHyaWtp6tEc58Ere7QsoD88+ XorMlOOEQTUiw2VQsd41tvYeNN3CNQ== X-Google-Smtp-Source: ABdhPJyuURsCidMV8RPOnGu4WXw6fPmyFjVtCY0B1mzQVH/nVZwAMjdQVHwmXycuQXBgUXWOjrvPEfVqLw== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:adf:f9c7:0:b0:20a:dfa9:f4c3 with SMTP id w7-20020adff9c7000000b0020adfa9f4c3mr17960863wrr.289.1652176638133; Tue, 10 May 2022 02:57:18 -0700 (PDT) Date: Tue, 10 May 2022 09:57:09 +0000 In-Reply-To: <20220510095710.148178-1-tabba@google.com> Message-Id: <20220510095710.148178-4-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 3/4] KVM: arm64: Pass pmu events to hyp via vcpu 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_025722_497555_4CB2D5B9 X-CRM114-Status: GOOD ( 18.27 ) 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 Instead of the host accessing hyp data directly, pass the pmu events of the current cpu to hyp via the vcpu. This adds 64 bits (in two fields) to the vcpu that need to be synced before every vcpu run in nvhe and protected modes. However, it isolates the hypervisor from the host, which allows us to use pmu in protected mode in a subsequent patch. No visible side effects in behavior intended. Signed-off-by: Fuad Tabba Reviewed-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 7 +------ arch/arm64/kvm/arm.c | 15 +++++++++++++++ arch/arm64/kvm/hyp/nvhe/switch.c | 20 ++++++-------------- arch/arm64/kvm/pmu.c | 12 ++++-------- include/kvm/arm_pmu.h | 6 ++++++ 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index dfd360404dd8..835dd5ef630b 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -273,14 +273,8 @@ struct kvm_cpu_context { struct kvm_vcpu *__hyp_running_vcpu; }; -struct kvm_pmu_events { - u32 events_host; - u32 events_guest; -}; - struct kvm_host_data { struct kvm_cpu_context host_ctxt; - struct kvm_pmu_events pmu_events; }; struct kvm_host_psci_config { @@ -821,6 +815,7 @@ void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu); void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr); void kvm_clr_pmu_events(u32 clr); +struct kvm_pmu_events *kvm_get_pmu_events(void); void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu); void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu); #else diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 2adb5832a756..86bcdb2a23a8 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -817,6 +817,19 @@ static int noinstr kvm_arm_vcpu_enter_exit(struct kvm_vcpu *vcpu) return ret; } +/* + * Updates the vcpu's view of the pmu events for this cpu. + * Must be called before every vcpu run after disabling interrupts, to ensure + * that an interrupt cannot fire and update the structure. + */ +static void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu) +{ + if (has_vhe() || !kvm_vcpu_has_pmu(vcpu)) + return; + + vcpu->arch.pmu.events = *kvm_get_pmu_events(); +} + /** * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code * @vcpu: The VCPU pointer @@ -882,6 +895,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) kvm_vgic_flush_hwstate(vcpu); + kvm_pmu_update_vcpu_events(vcpu); + /* * Ensure we set mode to IN_GUEST_MODE after we disable * interrupts and before the final VCPU requests check. diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index 0716163313d6..c61120ec8d1a 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -153,13 +153,9 @@ static void __hyp_vgic_restore_state(struct kvm_vcpu *vcpu) /* * Disable host events, enable guest events */ -static bool __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt) +static bool __pmu_switch_to_guest(struct kvm_vcpu *vcpu) { - struct kvm_host_data *host; - struct kvm_pmu_events *pmu; - - host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); - pmu = &host->pmu_events; + struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events; if (pmu->events_host) write_sysreg(pmu->events_host, pmcntenclr_el0); @@ -173,13 +169,9 @@ static bool __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt) /* * Disable guest events, enable host events */ -static void __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt) +static void __pmu_switch_to_host(struct kvm_vcpu *vcpu) { - struct kvm_host_data *host; - struct kvm_pmu_events *pmu; - - host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); - pmu = &host->pmu_events; + struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events; if (pmu->events_guest) write_sysreg(pmu->events_guest, pmcntenclr_el0); @@ -304,7 +296,7 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu) host_ctxt->__hyp_running_vcpu = vcpu; guest_ctxt = &vcpu->arch.ctxt; - pmu_switch_needed = __pmu_switch_to_guest(host_ctxt); + pmu_switch_needed = __pmu_switch_to_guest(vcpu); __sysreg_save_state_nvhe(host_ctxt); /* @@ -366,7 +358,7 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu) __debug_restore_host_buffers_nvhe(vcpu); if (pmu_switch_needed) - __pmu_switch_to_host(host_ctxt); + __pmu_switch_to_host(vcpu); /* Returning to host will clear PSR.I, remask PMR if needed */ if (system_uses_irq_prio_masking()) diff --git a/arch/arm64/kvm/pmu.c b/arch/arm64/kvm/pmu.c index 4bd38ff34221..7887133d15f0 100644 --- a/arch/arm64/kvm/pmu.c +++ b/arch/arm64/kvm/pmu.c @@ -5,7 +5,8 @@ */ #include #include -#include + +static DEFINE_PER_CPU(struct kvm_pmu_events, kvm_pmu_events); /* * Given the perf event attributes and system type, determine @@ -25,14 +26,9 @@ 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_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; + return this_cpu_ptr(&kvm_pmu_events); } /* diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index eaa8290b116f..35a0903cae32 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -20,8 +20,14 @@ struct kvm_pmc { struct perf_event *perf_event; }; +struct kvm_pmu_events { + u32 events_host; + u32 events_guest; +}; + struct kvm_pmu { struct irq_work overflow_work; + struct kvm_pmu_events events; struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS]; DECLARE_BITMAP(chained, ARMV8_PMU_MAX_COUNTER_PAIRS); int irq_num; From patchwork Tue May 10 09:57:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12844753 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 BF0FEC433F5 for ; Tue, 10 May 2022 09:59:20 +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=7+LVFQ1bf1vimrJ5gSYBZBYtdwvl9PIiKR7o/GXjij0=; b=oF3XtHlsEd55JekvO3DjP5RT31 wDnkqSYs894wJYad7dvelxIRjUzLjU1578tTMsbGa+q3KTMimq89PRS+ja8inRcLX0bBVzWCbCs89 k9HHaH2ShjRSCVbxXcSZTWj3cMzawV/O9Hs6hVuJ9Se/vpDUgy5f71vYXk5G0VndSSzjXO6vR8cCW Vlj/WI8KOj2SyvLj2C9BnCCNRqWb5ufVyqXRmXl0co845CADtLYRazH2u3FkWewCWnu8Ie+twuW85 yamYnLTu5b9jszwX23RLztaQ18n9O2Lo+KXyVdY47c5k2tRCiTvNCr43JY8HTuFFmsS3UoJWgNq0o cR3Nmw5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1noMd4-00119O-Nt; Tue, 10 May 2022 09:58:06 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1noMcO-0010od-RQ for linux-arm-kernel@lists.infradead.org; Tue, 10 May 2022 09:57:26 +0000 Received: by mail-wm1-x349.google.com with SMTP id q128-20020a1c4386000000b003942fe15835so5067902wma.6 for ; Tue, 10 May 2022 02:57:21 -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=mKMNvyZBuuA9SLayUryCuhjhpUdoCiXuRmOyn6vDo4I=; b=T/9pE2m91NoXAenAIeFnB7RnZeuYl5qJg/+rpiIScDWS4RmtOIFi9MbPy32BAJeqoW RwcnK57L7upiL7QOz/V5hMywhWMYCQCTbll1Z4T3RPXHP+d1Ojpd2o6+L1S586UQjYJK JT6j+mzFnm41weM8A9dBJRdsS5EtuS0FDEmmtwpTCGCgc5ASwhKeYIUsKnsATbNeWCL6 SBhYzzw0qie0weuXxrZtYDPvAo0qFsNJ3YrNmUUuBYQ3PatAiVMT/OFPaJpG8epyYeOY dDQc8D1bND0SL9afGXin4WqivexrrfLhqe8ejOaw48vlsctcrl9B50jC6zq01ePYjrNr ry2Q== 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=mKMNvyZBuuA9SLayUryCuhjhpUdoCiXuRmOyn6vDo4I=; b=7uIopCbaE9RzBbudOzLuTEdpUG/ERPwXwj8xmFCmH6N/Vxp/I19BhNpp3VDFlO6Asc dhW+UHrn0kuDMyXTYqXAX/itgPOvJ2fmUwygz9MrvvBR2ldLKqHjtLozVsJZUC3G4X14 AUSiKdBogWiDgU2M5LQNS0xMF/0YWfRjHp6FYhCPlCrYm2Ae0teHCXwJ1vb4oxQ/3owQ 2beZLINgk/IUo3vNiJaRIcE31WVBA2UvXMPftDzpWqkaHeY+D+ZUn6ACf9rofhtAPKmV jgXMw4s7SjVHJ8ESl0BVDb6X0KuHwJWn7R7iRsYuWVcUIEbdisdhLVxuQoIbymlABwkl ftZw== X-Gm-Message-State: AOAM530knS7hg8BC5fsEx99ajofG0nFCbaMEPWza7ANUSdbdexfHgAcL 07MZtsgXDzJuKxLghBY7SCxc48+LIg== X-Google-Smtp-Source: ABdhPJxgxLziV5lD00E3d70FP+JsDRwBhJjSHtA0R3ZtNY/VGd2q0FAYdR9UTgDYUJOb/BpOuW//Rhvhug== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a1c:4e0b:0:b0:393:fd8f:e340 with SMTP id g11-20020a1c4e0b000000b00393fd8fe340mr26699159wmh.136.1652176640085; Tue, 10 May 2022 02:57:20 -0700 (PDT) Date: Tue, 10 May 2022 09:57:10 +0000 In-Reply-To: <20220510095710.148178-1-tabba@google.com> Message-Id: <20220510095710.148178-5-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 4/4] KVM: arm64: Reenable pmu in Protected Mode 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_025724_936536_A19E32E9 X-CRM114-Status: GOOD ( 10.88 ) 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 Now that the pmu code does not access hyp data, reenable it in protected mode. Once fully supported, protected VMs will not have pmu support, since that could leak information. However, non-protected VMs in protected mode should have pmu support if available. Signed-off-by: Fuad Tabba Reviewed-by: Oliver Upton --- arch/arm64/kvm/pmu-emul.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 3dc990ac4f44..11c43bed5f97 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -774,8 +774,7 @@ void kvm_host_pmu_init(struct arm_pmu *pmu) { struct arm_pmu_entry *entry; - if (pmu->pmuver == 0 || pmu->pmuver == ID_AA64DFR0_PMUVER_IMP_DEF || - is_protected_kvm_enabled()) + if (pmu->pmuver == 0 || pmu->pmuver == ID_AA64DFR0_PMUVER_IMP_DEF) return; mutex_lock(&arm_pmus_lock);