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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67D8EEEEC00 for ; Fri, 15 Sep 2023 19:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bsWUZBtNeafE7FZAE6Sx7aU8sAPuPEmQMjW41UZszvA=; b=VqWf9ZCdbpJgfs qeYbGMNVfM5JX7gScwk2pG7S5sD8AUdyBLGiDmJq4pHRjIrdAAjQNzcgBDK9Yq3l4Kz1SgQHuj7Rn uBEG4mETRKhoMgkCvC5U70V866PjtuQzQaj/FVoeaGgHYGg04AzUPrpKhwC9J/lxg29p3NsvCX+OX X3Bx2uyYKBSFOgfTfkG+dIjx1l3umus74gsvtwqTPDFaUGYlgf+lr5RShrEyXfvgr8P7AUrEk9Ze2 pdu4vRY+EcAfiqPJvwFYHeHULLUEEkmiImj4CrLVVA/2vDjkFVNQIhA7+Wx9Vvu4RDtgilVchwAjh +klw77t6Gtb6JlefECkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qhEP8-00BG0h-2l; Fri, 15 Sep 2023 19:23:02 +0000 Received: from out-214.mta0.migadu.com ([91.218.175.214]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qhEP6-00BFzV-0L for linux-arm-kernel@lists.infradead.org; Fri, 15 Sep 2023 19:23:01 +0000 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-Disposition: inline In-Reply-To: <20230817003029.3073210-2-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230915_122300_556757_B9B5B7BC X-CRM114-Status: GOOD ( 26.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel