Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2291391rdh; Tue, 26 Sep 2023 20:16:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhiB1uiWcZ6CUsU7f+d2YboUq/h+dQxGcu6gqNwcjS790KRDzg+jmEybE3WX/Pc+TZ6eG3 X-Received: by 2002:a81:6c42:0:b0:583:d6bb:4e96 with SMTP id h63-20020a816c42000000b00583d6bb4e96mr1039330ywc.8.1695784609876; Tue, 26 Sep 2023 20:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695784609; cv=none; d=google.com; s=arc-20160816; b=PP10z+/7GQpvcolsvzILD5pKrScZVBQFTHbea3xIfYzpCgcd/ryT+9Q1/WwWZw0CX/ 1QvDxRjJvEuSc/v+Dpfq08wifGfeV36TWtsf/rIEn0oezjNTF7rgWxsZacCopnJRqgIt Yxh+HygMCDp8KpiYvs4223oDIIOhqtHwwEcznlr4Si4Ks0Z4Rju43DvwIbx/AQFqpzuJ ZFWi+VzFQWBHOyaeUQtWDwqA7C36fLPIB/uniUZvUNk+ehzAQsNlu7b+aqElOHEg6Rux gMtrqIRsLEIJ5n9unN5pZrHiCp8WWWR5pYgzGPf0lv+9B4oiz+a+MGvr8B3jPdxnjlyh jeNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=5wBvgde8NqXXedlUolMxmuLFm0wZFB1ciTVf7h91dh0=; fh=nSGf6E5bqeZ4+WG1wtUl4dHMM2T+/oX4atvC7v39NTU=; b=AkcCBWDNdzgLipFI9ScAT3oJ6cE8zoXA1XSUfzkqh9YL6AfYmaGjCX9dv8fDq2VQjQ HoOoUwzxlSqzXZs8SbEi0iDO17zub2zaensHBz+C1LDHkubsf2A17J43lEUF/rm30VtY 3GiUXulzpbFYDtfK162oI1IwtbhZ1WVWId6R6la+sT16pw8iggtSkLB+kKbsTCIi7DrE /q85HtXnj9sGHryUtOt2IcZE5SR6Syx08nruhfE+/D0gfyZFAQxXoT3/6JTA+32g5S/x SpMMgMJWfZdpi4KVExAC9wenycdZS56cx4qKuDoxpqZMOZ3EbBF37cTq2Exbr7Po4Vdk rcOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ckHSCfSd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ca13-20020a056a02068d00b00578e40151basi15649671pgb.662.2023.09.26.20.16.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 20:16:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ckHSCfSd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D3C1D81121F6; Tue, 26 Sep 2023 17:22:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231634AbjI0AV5 (ORCPT + 99 others); Tue, 26 Sep 2023 20:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231875AbjI0ATz (ORCPT ); Tue, 26 Sep 2023 20:19:55 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1A7D18E95 for ; Tue, 26 Sep 2023 16:40:13 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d85fc108f0eso14610683276.2 for ; Tue, 26 Sep 2023 16:40:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695771612; x=1696376412; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5wBvgde8NqXXedlUolMxmuLFm0wZFB1ciTVf7h91dh0=; b=ckHSCfSdzm1jCMOZ3g2CRPCiDw7uxVOtBclevf32YyJl54MDseQwjUITYRMVlb0rLu 4hR/RhQqOOgE59af2WOtJbZSsy5moCcAAzUuy4cVBNAxzLfcwvb+pjXVPwaFA9HMx18V cAqYTL7zcLwpC8/3KJKl/FpAys2/3JQ8sYTb++Kr1Syg6sfwd8Mr2kUf9NRLufpR7HlP IHh+SAYdr49X1lVuD4qWlZpSF6kIRziGfbPrpyGfQ74Y52c21UpQIpzO2bejA1myEakj LotqnE1HJqL+O11zSkXje+xpVwpxB6l1KJyDg3hbKMxJtuI/dXFpQ+vPbhY0VuGdgli/ 9MQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695771612; x=1696376412; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5wBvgde8NqXXedlUolMxmuLFm0wZFB1ciTVf7h91dh0=; b=RhcEGiFYtGmu7f34Zw2U7AjEnUX/9h0oFCaRCsA5lDQZw+A1QN4OwCa4A55oJi47l3 eYiBbTJvOINJow6QLE/Hy+rT2osScEQLP62kDfIuX94oImhRcIyq+l5l0K0AHG2D1zU0 p5OvLNLPAb2GI3Qkfv2wifAkID6yW+HbxVEEgFL6UpGOmZ8P5lkt8uUDyYv7M2IyW5jq PhFb3mSa/nG3AkDKBNQTooGi6vRKTiVfA3Je+zK59y2pzI8/w/Z+QtdiXRrq504EQoGq cimC+MQO5fPaIgHFVJ3CkSdXwiAImbQ+zdwT4clz8rd/bmPghKu3Fp98RYh9cPe1mZlY P2qg== X-Gm-Message-State: AOJu0YzFscEzvlXE/YXcqVe2QDg55iUJFkC61r+xjd1XgPpGGLPLOogO SSc3TB51m3KI7XZZVekCTsv0c6nhcrOe X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:20a1]) (user=rananta job=sendgmr) by 2002:a05:6902:1682:b0:d81:78ec:c403 with SMTP id bx2-20020a056902168200b00d8178ecc403mr4790ybb.12.1695771612735; Tue, 26 Sep 2023 16:40:12 -0700 (PDT) Date: Tue, 26 Sep 2023 23:39:58 +0000 In-Reply-To: <20230926234008.2348607-1-rananta@google.com> Mime-Version: 1.0 References: <20230926234008.2348607-1-rananta@google.com> X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230926234008.2348607-2-rananta@google.com> Subject: [PATCH v6 01/11] KVM: arm64: PMU: Introduce helpers to set the guest's PMU From: Raghavendra Rao Ananta To: Oliver Upton , Marc Zyngier Cc: Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , Shaoqin Huang , Jing Zhang , Reiji Watanabe , Colton Lewis , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 26 Sep 2023 17:22:01 -0700 (PDT) From: Reiji Watanabe Introduce new helper functions to set the guest's PMU (kvm->arch.arm_pmu) either to a default probed instance or to a caller requested one, and use it when the guest's PMU needs to be set. These helpers will make it easier for the following patches to modify the relevant code. No functional change intended. Signed-off-by: Reiji Watanabe Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/kvm/pmu-emul.c | 50 +++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 6b066e04dc5df..fb9817bdfeb57 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -874,6 +874,36 @@ static bool pmu_irq_is_valid(struct kvm *kvm, int irq) return true; } +static void kvm_arm_set_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu) +{ + lockdep_assert_held(&kvm->arch.config_lock); + + kvm->arch.arm_pmu = arm_pmu; +} + +/** + * kvm_arm_set_default_pmu - No PMU set, get the default one. + * @kvm: The kvm pointer + * + * The observant among you will notice that the supported_cpus + * mask does not get updated for the default PMU even though it + * is quite possible the selected instance supports only a + * subset of cores in the system. This is intentional, and + * upholds the preexisting behavior on heterogeneous systems + * where vCPUs can be scheduled on any core but the guest + * counters could stop working. + */ +static int kvm_arm_set_default_pmu(struct kvm *kvm) +{ + struct arm_pmu *arm_pmu = kvm_pmu_probe_armpmu(); + + if (!arm_pmu) + return -ENODEV; + + kvm_arm_set_pmu(kvm, arm_pmu); + return 0; +} + static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id) { struct kvm *kvm = vcpu->kvm; @@ -893,7 +923,7 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id) break; } - kvm->arch.arm_pmu = arm_pmu; + kvm_arm_set_pmu(kvm, arm_pmu); cpumask_copy(kvm->arch.supported_cpus, &arm_pmu->supported_cpus); ret = 0; break; @@ -917,20 +947,10 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) return -EBUSY; if (!kvm->arch.arm_pmu) { - /* - * No PMU set, get the default one. - * - * The observant among you will notice that the supported_cpus - * mask does not get updated for the default PMU even though it - * is quite possible the selected instance supports only a - * subset of cores in the system. This is intentional, and - * upholds the preexisting behavior on heterogeneous systems - * where vCPUs can be scheduled on any core but the guest - * counters could stop working. - */ - kvm->arch.arm_pmu = kvm_pmu_probe_armpmu(); - if (!kvm->arch.arm_pmu) - return -ENODEV; + int ret = kvm_arm_set_default_pmu(kvm); + + if (ret) + return ret; } switch (attr->attr) { -- 2.42.0.582.g8ccd20d70d-goog