Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp443519rdg; Tue, 10 Oct 2023 15:26:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZLw44hiCBfyCBb7kD9ormrcSpO8qorowzIV9K//jpJjoksx+CuwCKwZCRJO4wqih/46cd X-Received: by 2002:a05:6a00:17a1:b0:690:c1a6:1c3b with SMTP id s33-20020a056a0017a100b00690c1a61c3bmr19370597pfg.33.1696976777486; Tue, 10 Oct 2023 15:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976777; cv=none; d=google.com; s=arc-20160816; b=e8PsJqPacFtr6ddima/jDYVOM+UD63BxIKQIeQc0VT9I3ZIwpG148icerMTsCAWEaR VcuIumqSxiAq0b8F6fbichPlLbzqsugT9nSaPwKNRSaKZH6QBlieo8bgwrJ6RDhg8d5r DYx2xECZ3g3fNqHV0WOL1JKKgg7726szPIXev4wKt7FC1CUMgO/30eZb4VqV7zigMNN8 NV56cqFCGPXT0me+tVQwBVLjfztv5Qgtciuoa3Z9Lsu8Ogb5BOA8yggV0Q3nT6JLPTKt hXLB2gyb6e3n9nIMmT8/Qbex/GHlBJ//HIwi9GkecHPGdT9VN/105lGNviyVgtO+hrS+ o/uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=SPUkQY0+AWZGfvqgoiXnqvkeNR+nXAzCmXpNk7WkSXo=; fh=4I6BNv7iobpZrRcbueKA7r9RD02xPQmynyU/PeDFguM=; b=ZtsZ6p5xqToLx9yf9MDkszS4Uipiayw8s78iBhvRcUja8IM9WASDA+23BGo6PlNihm TGMKzOMwe7xVx9V6sCEeTgXLT7SUKfz9axwX2gjkCKx5MyGw8v0c7FiMWBFNEma/CRoi 4BYffAkbp1I/hiCT62DTOq2ZfzYYjZp+Pstwgl1WLxnM2aGO6wQjEyjwD42ezObNDMbV 8JOavV76Lri3b+oyYS6bA8kTacWGPO5YzsqgU1kM1c9w2WPXYymZVi3HWtYW675jFyA+ d7tNX4nGAwY22zotDvsTcOVxvqE3q+jCl40pPkAganGPMSpZ0D6XZBzaWoeS99mUwNTV Xlrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=M6bGJwHl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id a26-20020a63705a000000b00573f116fba1si12994301pgn.870.2023.10.10.15.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:26:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=M6bGJwHl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 6AB9F802916A; Tue, 10 Oct 2023 15:26:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231358AbjJJW0A (ORCPT + 99 others); Tue, 10 Oct 2023 18:26:00 -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 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 10 Oct 2023 15:26:14 -0700 (PDT) X-Spam-Level: ** 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