Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4839589rdb; Fri, 15 Sep 2023 14:04:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9xCLgZM4suOh1lUcqstILrHP5AN+qw5jHGxd1OYzjVavix09x2PEi+uB8Stw9skokX+15 X-Received: by 2002:a17:903:1cf:b0:1b5:522a:1578 with SMTP id e15-20020a17090301cf00b001b5522a1578mr8640528plh.29.1694811884575; Fri, 15 Sep 2023 14:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694811884; cv=none; d=google.com; s=arc-20160816; b=igGxESj0ac5ens19uFMQ9HohfYTvyQxeo+jh7/Ff9AKcDpmlltHo50el4YcVJSewls OEYxYshYroNJygxzRqerDS1LKtMqbvib8nuK1HKIPntdk5bPKjkvmW1HF4bUolQZfjei KR84Dz5z6tmJpxf3zAuXDehJGy9UFflxerndV11snV8aZJuyImG4BQN4k9nEPA32JhkE LU5IOwh2N0/ruiEiRYtwvP05+NsRKDtWaYyGPEnuvYTyvYYGQNMquMFzAciAY/rPzcoX ZPSn2NUEfiLnNd1DzucqutIk4F0YHtYZm6gtm0iv0aj6tHm+vGZdnIvFHmhPbLSa7SVF jz3g== 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=f6A1k8x4/KZw+o1a8WwOEfU/+PCk8Ghi0Fb9Ywzdmuc=; fh=4I6BNv7iobpZrRcbueKA7r9RD02xPQmynyU/PeDFguM=; b=t1SCZzE9RzJawMnpAw5tmh9QzFwp54Xih8+J+t64IeI0pWjh2oDjj6lZIUf4MjS/5g We3ItWIA5FwsOH5/UNNBNlYjkFmMBB2nsIb581cLb2AywkuPBYptD6mcR4Z4szHVcZPC yWsg6etcVYwpvDrYHXAw5gNImbwqSyc1hIu0v+vZoupxjAu/UD1a48eJHPTVyNhQXhS0 UgwxzsqtsKu9Ussn+q45oG6wWdEaZkJCT7lSlliv5lA5PxkUtYUwackf5zWiSshc7k/a SJn+m2n2SFem3vOfhevusLptl06SzwTGFTvmyG3h6uUVJik8tebcQIfVnni365P1mlWc hcAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=u8sqfMd5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id jz14-20020a170903430e00b001b831d26f32si3823288plb.590.2023.09.15.14.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 14:04:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=u8sqfMd5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 1793083A8A0E; Fri, 15 Sep 2023 12:23:47 -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 S236897AbjIOTXO (ORCPT + 99 others); Fri, 15 Sep 2023 15:23:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237050AbjIOTXH (ORCPT ); Fri, 15 Sep 2023 15:23:07 -0400 Received: from out-216.mta0.migadu.com (out-216.mta0.migadu.com [IPv6:2001:41d0:1004:224b::d8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E60A31FFE for ; Fri, 15 Sep 2023 12:22:58 -0700 (PDT) Date: Fri, 15 Sep 2023 19:22:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1694805774; 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=f6A1k8x4/KZw+o1a8WwOEfU/+PCk8Ghi0Fb9Ywzdmuc=; b=u8sqfMd5XvQFcuyvVmb00KMHIveZCJpd1PJ/o6SPWEWjThqR1m6L9Od8mQk4TgzRyIBrkm b+TXHCJkNTPKVPlMZ7+o5IfMeQ0xESl0/ZLnxKUehTAf2NOWtXhyGSReXf56VKj+X+uRkx P/b6Y7DyjadqHA0r48vCRcethFP4WRc= 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 v5 01/12] KVM: arm64: PMU: Introduce a helper to set the guest's PMU Message-ID: References: <20230817003029.3073210-1-rananta@google.com> <20230817003029.3073210-2-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230817003029.3073210-2-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 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]); Fri, 15 Sep 2023 12:23:48 -0700 (PDT) Hi Raghu, On Thu, Aug 17, 2023 at 12:30:18AM +0000, Raghavendra Rao Ananta wrote: > From: Reiji Watanabe > > Introduce a new helper function to set the guest's PMU > (kvm->arch.arm_pmu), and use it when the guest's PMU needs > to be set. This helper 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 | 52 +++++++++++++++++++++++++++------------ > 1 file changed, 36 insertions(+), 16 deletions(-) > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > index 5606509724787..0ffd1efa90c07 100644 > --- a/arch/arm64/kvm/pmu-emul.c > +++ b/arch/arm64/kvm/pmu-emul.c > @@ -865,6 +865,32 @@ static bool pmu_irq_is_valid(struct kvm *kvm, int irq) > return true; > } > > +static int kvm_arm_set_vm_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu) > +{ > + lockdep_assert_held(&kvm->arch.config_lock); > + > + if (!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. > + */ > + arm_pmu = kvm_pmu_probe_armpmu(); > + if (!arm_pmu) > + return -ENODEV; > + } > + > + kvm->arch.arm_pmu = arm_pmu; > + > + return 0; > +} > + I'm not too big of a fan of adding the 'default' path to this helper. I'd prefer it if kvm_arm_set_vm_pmu() does all the necessary initialization for a valid pmu instance. You then avoid introducing unexpected error handling where it didn't exist before. 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; } /* * Blurb about default PMUs I'm too lazy to copy/paste */ 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; } -- Thanks, Oliver