Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1300051rdb; Fri, 20 Oct 2023 14:41:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/DrLvf+8/eFWyGEbxPD1dWGSLViyjgAZqqaa6FGMy9w/auJVsncg3PIFxtBNkbrhNLDmB X-Received: by 2002:a05:6a00:2e87:b0:6be:5a6c:d3f7 with SMTP id fd7-20020a056a002e8700b006be5a6cd3f7mr3276833pfb.2.1697838099903; Fri, 20 Oct 2023 14:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697838099; cv=none; d=google.com; s=arc-20160816; b=ffmhj5vVpKzJ6buJ55TVdZQzwC2gS0y2m2cSBKX0DLmuIqZl+cT6+GKiGbRwiGhx5x 8OlkECMGV9QL+u0NfsCn7ugNDZ87Jsvg8JAu1/Qjl0lHmPSO2fA44tUJQp1XrT26yrb6 w+BmlyvPjkf5awWB3tb7c6NkDpX9wH5477+uDzcIc3htldi7LHTZNF2PIPqY/aVNdIGO k36JyVzsvf4cOePpwNcJP0VHyuwqgrYh3CzfuY51N5pB0sScIXUINqXMcRKQ7dijrq+X IiDM7hExHgnse+p+OGh7mwAjdyCLe1PY/R6yAPZLs9v4MC//Ir7juo/5qoDNVfqz256C fokg== 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=fRZJl825jTe4bNk4e/h0EcnYD7OOEsJ4orW3IfNwdD4=; fh=7eK26T1m6z+gvZ7Bmv9BJPHcmUnOjzPIeEgwjA/TI3E=; b=jfdis1piGefxzFZZcEIOErTHrkBui23JtDkmgkjbow1YBbjThZLoRkMHo17zZ+wIXM 66yLgI9USDsiKCFD8UjjHEmqUyYwT0GkCFVmgTjgopazi/SDp1E60/082CmaKgI3A+AJ SYj4/vIh4I8mWe8DBRXY2elVrxKLY5IFZsW5mg2zc8Wq+rYz2mDqsSJf8QYuQ7bWLgI4 lPv02K7prqunlToy1C+BeoppT2rcjsR1psg4ImC95kqefuaT5MYtCNtocKzBsFT3yQ6Q WrOptuu1ptG5j/NsPQ70IlRD+yk2KmeSKq5iYDhefqr5MK/1l0ph+0ak3u+8vbxPUiq6 /k5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GFt2h0oU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l62-20020a639141000000b005aa9a561867si2650042pge.621.2023.10.20.14.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 14:41:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GFt2h0oU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id E013182B1A2D; Fri, 20 Oct 2023 14:41:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345199AbjJTVlN (ORCPT + 99 others); Fri, 20 Oct 2023 17:41:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345261AbjJTVlJ (ORCPT ); Fri, 20 Oct 2023 17:41:09 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2DA7D7F for ; Fri, 20 Oct 2023 14:40:58 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a828bdcfbaso18750737b3.2 for ; Fri, 20 Oct 2023 14:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697838058; x=1698442858; 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=fRZJl825jTe4bNk4e/h0EcnYD7OOEsJ4orW3IfNwdD4=; b=GFt2h0oUOpCAeqIf56JfA/hb+414FjMqTiNto4ntFBD3x92sd7Hy+jLuZxkkVfYVqQ j+uNxXMQzNKJ3M3lF9UJpYWdKR6lBYVV+pfbtrz7lpVBAyxLbjRCXxX3WpmZm6QLjamG H7PSWIDroNc1YANPohvGSmH1HzRaZ3EmbAZTmSea85C8TV+04vOCKSKfvegRLF+QjU/m J12ls22GdHTlSIc8d9xEqCH/nt23rfHzXTukM80cS8vmwxGKQy+q3+Ulkr5AauWQRg0D MWXGJGNEp+dCs6x2yltwk3FGbNTaYuvDh3hviqdJSg7VZpTmtncf89F070VRZtB75aTU imYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697838058; x=1698442858; 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=fRZJl825jTe4bNk4e/h0EcnYD7OOEsJ4orW3IfNwdD4=; b=Dz96XAIyeJ2/wlYCvhvKhjv84PR9ofOVhTPgjXN0M4dT2OUveD5QKofMOmlkIE4vbd GSBtXXxdZe60lnWoZ7TQAoNq8fXhU7s7sba0ivLzcPfg50EBiL92GjZKy3VtuCULT8HD abKgLoZySMkWPKA/6uxRz0/8xI+YRSHrtBVlS8k4rJO061bbg8tIWsFS+6uXoWx4VTJE Ox+IFnYWUQ5WesEYiFN0bSTGPs5yrmXNFC4TQY7yLoZi+d+2MBNUXIgh9rZsCX6b5S28 w5JrRu7xCMHiUsk38wpY7EHQsoi/SChRRBmFSVCxQB2TyQXJpXeXuJgdVEwAAS4wpqbq cRJg== X-Gm-Message-State: AOJu0Yy2HA3JbmKuaboZ1xnDQpn7wwIIoyF63eDQe9bTFEXrGdJovQe8 lohp9jsuM5K/HuiuLS3McWNHBz6XiiiQ X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:20a1]) (user=rananta job=sendgmr) by 2002:a0d:dd10:0:b0:577:619e:d3c9 with SMTP id g16-20020a0ddd10000000b00577619ed3c9mr76387ywe.10.1697838058021; Fri, 20 Oct 2023 14:40:58 -0700 (PDT) Date: Fri, 20 Oct 2023 21:40:41 +0000 In-Reply-To: <20231020214053.2144305-1-rananta@google.com> Mime-Version: 1.0 References: <20231020214053.2144305-1-rananta@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020214053.2144305-2-rananta@google.com> Subject: [PATCH v8 01/13] 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, Eric Auger Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Fri, 20 Oct 2023 14:41:30 -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 Reviewed-by: Eric Auger --- 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 3afb281ed8d2c..eb5dcb12dafe9 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.655.g421f12c284-goog