From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D911FCD98C0 for ; Tue, 10 Oct 2023 22:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232993AbjJJW0B (ORCPT ); Tue, 10 Oct 2023 18:26:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230034AbjJJWZ6 (ORCPT ); Tue, 10 Oct 2023 18:25:58 -0400 Received: from out-196.mta0.migadu.com (out-196.mta0.migadu.com [91.218.175.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 536419D for ; Tue, 10 Oct 2023 15:25:56 -0700 (PDT) Date: Tue, 10 Oct 2023 22:25:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1696976754; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=SPUkQY0+AWZGfvqgoiXnqvkeNR+nXAzCmXpNk7WkSXo=; b=M6bGJwHlM4DNvasAm3eeWnkSTFUPhb8DvM6ttqwv7ZfLe4GjXUd38gb6KJbAK8Joda0Fyr fHoCs/Qxd59GxA6CpXozmj3pM2vfKnh+XEywCTsFlbpvupoSfy5CUdJuPvP2H9tBSS8Ntv BqVlgm8ddPKCZiGR8NXiU5pGFIYonlc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Raghavendra Rao Ananta Cc: Marc Zyngier , 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 v7 02/12] KVM: arm64: PMU: Set the default PMU for the guest before vCPU reset Message-ID: References: <20231009230858.3444834-1-rananta@google.com> <20231009230858.3444834-3-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009230858.3444834-3-rananta@google.com> X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Raghu, On Mon, Oct 09, 2023 at 11:08:48PM +0000, 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 | 20 ++++++++++++++++++++ > arch/arm64/kvm/pmu-emul.c | 12 ++---------- > include/kvm/arm_pmu.h | 6 ++++++ > 3 files changed, 28 insertions(+), 10 deletions(-) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 78b0970eb8e6..708a53b70a7b 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1313,6 +1313,23 @@ static bool kvm_vcpu_init_changed(struct kvm_vcpu *vcpu, > KVM_VCPU_MAX_FEATURES); > } > > +static int kvm_vcpu_set_pmu(struct kvm_vcpu *vcpu) > +{ > + struct kvm *kvm = vcpu->kvm; > + > + if (!kvm_arm_support_pmu_v3()) > + return -EINVAL; This check is pointless; the vCPU feature flags have been sanitised at this point, and a requirement of having PMUv3 is that this predicate is true. > + /* > + * When the vCPU has a PMU, but no PMU is set for the guest > + * yet, set the default one. > + */ > + if (unlikely(!kvm->arch.arm_pmu)) > + return kvm_arm_set_default_pmu(kvm); > + > + return 0; > +} > + Apologies, I believe I was unclear last time around as to what I was wanting here. Let's call this thing kvm_setup_vcpu() such that we can add other one-time setup activities to it in the future. Something like: diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 96641e442039..4896a44108e0 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1265,19 +1265,17 @@ static bool kvm_vcpu_init_changed(struct kvm_vcpu *vcpu, KVM_VCPU_MAX_FEATURES); } -static int kvm_vcpu_set_pmu(struct kvm_vcpu *vcpu) +static int kvm_setup_vcpu(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; - if (!kvm_arm_support_pmu_v3()) - return -EINVAL; - /* * When the vCPU has a PMU, but no PMU is set for the guest * yet, set the default one. */ - if (unlikely(!kvm->arch.arm_pmu)) - return kvm_arm_set_default_pmu(kvm); + if (kvm_vcpu_has_pmu(vcpu) && !kvm->arch.arm_pmu && + kvm_arm_set_default_pmu(kvm)) + return -EINVAL; return 0; } @@ -1297,7 +1295,8 @@ static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu, bitmap_copy(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES); - if (kvm_vcpu_has_pmu(vcpu) && kvm_vcpu_set_pmu(vcpu)) + ret = kvm_setup_vcpu(vcpu); + if (ret) goto out_unlock; /* Now we know what it is, we can reset it. */ -- Thanks, Oliver