Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1129838rda; Mon, 23 Oct 2023 03:41:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGifXMc5j1GztXvA87SC8/zAynisBBLoa7K7SsEv1PAtrTptkBQotxkO4vgJ+7jzDJzw3MZ X-Received: by 2002:a05:6358:2591:b0:168:eb13:807d with SMTP id h17-20020a056358259100b00168eb13807dmr21449rwc.14.1698057684286; Mon, 23 Oct 2023 03:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698057684; cv=none; d=google.com; s=arc-20160816; b=ZsjfR66jnKwv4pWn8a/JqCmJ7dw5ev+doIdh5kUbMEWz5R95nf+rMMdAPBIG3G058a iLSiG0xiUDw5Ls3hc9RzQlo+hf9kyLN+/Ct4sBo5/ZW28VjhPBVYvS69piXywy2cD+0H FECxVF4xd+e0TZLAeWiVJ2HZmVwvttUn/tU4IHGN6rXf0UWyR825+Fn5nuHCazmVNCdu bykKF3FhxMLY2RcIlo6DRi/TLC7sod1h+pTJwMsx1a7tvT9NxMhjQsLyTvbtf+q0dEXf A4UnLmfh6E8gR4Jg8oKDfkDcZr1ZEIJ6iPkegxuHh6vmzHCpbuQpqlg55Yq9xV+CyIxd vBEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=3GW+u+DodRdZtNdVfJnghpL6HZxdq5DpKQHM9IAbzFc=; fh=DFPnDq2cx+hgqp1yrQ9Laae/MsEoRqwrGgkRKdTDxsQ=; b=GOJWkEBIWZLyvVp7FwAzRCbTk0oYtgJ2DcgDMaQytTYEa0EDF9ZsKfdlGDqRCB7i1+ ERmZKIw/V8z1erldc25+FzZQNyphoGa3z6MD6phB5dPzZDMM9mdHPSsK+M+uYCXm8xdf 5gup60FruDg35qouRtE994On71B/Te1eErAe8E6VQfBBFDXTAMcH6Y9C5Oea9oXVSh/j yD7FMftg9gOPcBvAEXJv/zjuQXy+blWP/n6MflRMV9KmJ2fZ345oUSMr8Gy0+OdZ96WG SKd19PAFgi2O4yb1Tf7/WyJaPSHVeI1eI273yjcsymfkM3lU+SQF1yFtHy/rFZR2nD6+ ZNBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d8sUNXPv; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id i191-20020a6387c8000000b0056a1ed17deasi6144459pge.675.2023.10.23.03.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 03:41:24 -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=@kernel.org header.s=k20201202 header.b=d8sUNXPv; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A65FB80ABB32; Mon, 23 Oct 2023 03:41:21 -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 S230070AbjJWKk7 (ORCPT + 99 others); Mon, 23 Oct 2023 06:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbjJWKk5 (ORCPT ); Mon, 23 Oct 2023 06:40:57 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 080E2D65; Mon, 23 Oct 2023 03:40:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 932A5C433C7; Mon, 23 Oct 2023 10:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698057654; bh=dLDu4Z9DGcX4lMCPJLO64Bez7E60sRC9AOdA72H5GcM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=d8sUNXPvI9rfDXLpyPBktUT2kiWykiZvBA+zpi6kkBEnoC88t1g2ReKTn1s5ZgAj0 otouI1rKZ5pPPzOsLXh3KvAvHpT8raygEIWt4cVVbp/Ic6JQSM9XF2lwUSQEV29Yd6 gR/1wrcn2SOldfRAvCK/MFfGrL1PDfM6SF4eHQiQPArZoBrtD3KbvkCTCFANdtq7Tl qZMyJ633giEZYLRMb1gr+ERjIId+B2TuCQdwYzqc5VJuDxtJWKpbQdjEW/O4iBOy41 h4WPV80MizmBFFn+BLuCteMnlMYl2VkliVVrqTjSmiUK6dH6ZKzWGL3e8YPciPN1vk bH/1wC3MUDRWg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qusMe-006oJw-7Q; Mon, 23 Oct 2023 11:40:52 +0100 Date: Mon, 23 Oct 2023 11:40:50 +0100 Message-ID: <8634y162q5.wl-maz@kernel.org> From: Marc Zyngier To: Raghavendra Rao Ananta Cc: Oliver Upton , Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , Shaoqin Huang , Jing Zhang , Reiji Watanabe , Colton Lewis , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v8 02/13] KVM: arm64: PMU: Set the default PMU for the guest before vCPU reset In-Reply-To: <20231020214053.2144305-3-rananta@google.com> References: <20231020214053.2144305-1-rananta@google.com> <20231020214053.2144305-3-rananta@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: rananta@google.com, oliver.upton@linux.dev, alexandru.elisei@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, pbonzini@redhat.com, yuzenghui@huawei.com, shahuang@redhat.com, jingzhangos@google.com, reijiw@google.com, coltonlewis@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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]); Mon, 23 Oct 2023 03:41:21 -0700 (PDT) On Fri, 20 Oct 2023 22:40:42 +0100, Raghavendra Rao Ananta wrote: > > From: Reiji Watanabe > > The following patches will use the number of counters information > from the arm_pmu and use this to set the PMCR.N for the guest > during vCPU reset. However, since the guest is not associated > with any arm_pmu until userspace configures the vPMU device > attributes, and a reset can happen before this event, assign a > default PMU to the guest just before doing the reset. > > Signed-off-by: Reiji Watanabe > Signed-off-by: Raghavendra Rao Ananta > --- > arch/arm64/kvm/arm.c | 19 +++++++++++++++++++ > arch/arm64/kvm/pmu-emul.c | 16 ++++------------ > include/kvm/arm_pmu.h | 6 ++++++ > 3 files changed, 29 insertions(+), 12 deletions(-) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index c6cad400490f9..08c2f76983b9d 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1319,6 +1319,21 @@ static bool kvm_vcpu_init_changed(struct kvm_vcpu *vcpu, > KVM_VCPU_MAX_FEATURES); > } > > +static int kvm_setup_vcpu(struct kvm_vcpu *vcpu) > +{ > + struct kvm *kvm = vcpu->kvm; > + > + /* > + * When the vCPU has a PMU, but no PMU is set for the guest > + * yet, set the default one. > + */ > + if (kvm_vcpu_has_pmu(vcpu) && !kvm->arch.arm_pmu && > + kvm_arm_set_default_pmu(kvm)) > + return -EINVAL; nit: I'm not keen on re-interpreting the error code. If kvm_arm_set_default_pmu() returns an error, we should return *that* particular error, and not any other. Something like: static int kvm_setup_vcpu(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; int err = 0; /* * When the vCPU has a PMU, but no PMU is set for the guest * yet, set the default one. */ if (kvm_vcpu_has_pmu(vcpu) && !kvm->arch.arm_pmu) err = kvm_arm_set_default_pmu(kvm); return err; } > + > + return 0; > +} > + > static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu, > const struct kvm_vcpu_init *init) > { > @@ -1334,6 +1349,10 @@ static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu, > > bitmap_copy(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES); > > + ret = kvm_setup_vcpu(vcpu); > + if (ret) > + goto out_unlock; > + Hmmm. Contrary to what the commit message says, the default PMU is not picked at reset time, but at the point where the target is set (the very first vcpu init). Which is pretty different from reset, which happens more than once. I also can't say I'm over the moon with yet another function that does a very tiny bit of initialisation outside of the rest of the code that performs the vcpu init. Following things is an absolute maze... > /* Now we know what it is, we can reset it. */ > kvm_reset_vcpu(vcpu); > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > index eb5dcb12dafe9..66c244021ff08 100644 > --- a/arch/arm64/kvm/pmu-emul.c > +++ b/arch/arm64/kvm/pmu-emul.c > @@ -717,10 +717,9 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void) > * It is still necessary to get a valid cpu, though, to probe for the > * default PMU instance as userspace is not required to specify a PMU > * type. In order to uphold the preexisting behavior KVM selects the > - * PMU instance for the core where the first call to the > - * KVM_ARM_VCPU_PMU_V3_CTRL attribute group occurs. A dependent use case > - * would be a user with disdain of all things big.LITTLE that affines > - * the VMM to a particular cluster of cores. > + * PMU instance for the core just before the vcpu reset. A dependent use > + * case would be a user with disdain of all things big.LITTLE that > + * affines the VMM to a particular cluster of cores. Same problem, see above. Thanks, M. -- Without deviation from the norm, progress is not possible.