Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp176124rdb; Mon, 18 Sep 2023 11:26:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtUwPosXVnmbpiT2H1hR4TXgid/NSFYQnhewshRzLMF5Xj4D9BLz+Rx7rtdk/1BmDvhePe X-Received: by 2002:a05:6a20:914e:b0:15a:3eaa:b7ea with SMTP id x14-20020a056a20914e00b0015a3eaab7eamr12371656pzc.5.1695061578340; Mon, 18 Sep 2023 11:26:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695061578; cv=none; d=google.com; s=arc-20160816; b=V8Xxt6LofEiRCIGscdD5EIzUAj6QXevY7E14Wj3DI+h0OqoRIwo3L390SDcCCdp0ha AzNOHWlBwc9uthQcoCwqnDbO8TAR1k9pK8rJSyxmdPSNoHpC05DSuBNA3lRuvxMsafp3 LyiwlU7k3ryJfJjV/PXDNdlTtaWpKuxGskEXH60N+gyrB19A2bklvYjutOWel6t7kkyl TnMe3nHb8CbeYy1vuJXWleMhT1XhNVrYIeqP09b2DW4q9S3x/jAwU1TdKDMoy4luF8xm WWmBpNDIs7dOMeu0MA4aFpO0C8L/lfQDLIyx9Kv1ZUwkRimnkeaBz/vGLL7lWP5r4+YY yPiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=JpfHnxzUVMMWabALTl0v26Xf5DOzz1X5VHLZhINkdjo=; fh=dMrWgnXzzePbjJ5Lnz3JQ1FNdAF92uv7SkGdCptz9bs=; b=j4kWdLnCfIPuXF3O/KM0cRFBGNBYTe5oDRO1vjXc8oXV+8dmXGBxSaNsY9kU+ZUEp8 jO/01debyLNGLIlYp0WN6Aw7pxck8GLIBJTho7TCS8X0orozp8xTViIAWr0yPeTPKpZg UhGs1h1PAXmzE/Oj0YyMaulPjkPV8AiG5M8bos5tihMI1+edkSCOcAhEUjiPKEdlvBq0 hQGBsYxEi/WG7W+0i7cwUarSHf6M++rENvGoryIdJfJNSGmqM/+NWkA1DvAsjUPooq7l CzNlar9yU3o9UETQJwN103xUQzFSjc/FD7+svu0+5xytQbiojUaf01jUDZeI2z/KV96k u1jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Rx7BWbbs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id f29-20020a63101d000000b00573feb1e7c6si8087240pgl.888.2023.09.18.11.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:26:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Rx7BWbbs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2F7BF8078661; Mon, 18 Sep 2023 10:25:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbjIRRZN (ORCPT + 99 others); Mon, 18 Sep 2023 13:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbjIRRZM (ORCPT ); Mon, 18 Sep 2023 13:25:12 -0400 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94F44103 for ; Mon, 18 Sep 2023 10:25:06 -0700 (PDT) Received: by mail-qt1-x82e.google.com with SMTP id d75a77b69052e-414ba610766so23621cf.0 for ; Mon, 18 Sep 2023 10:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695057905; x=1695662705; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JpfHnxzUVMMWabALTl0v26Xf5DOzz1X5VHLZhINkdjo=; b=Rx7BWbbsqSZUN3PlfQCPOn0ru+O9NrYRPW+FT3auwtXTMBE6kxtr3EGnc6ujY2qs4j EyS5QoVem2C9Fm3S/RQsjW5mFOXqKP3OJ/4Y98+FiZRGHfpECcXpc3Hi/ObQ8gKS393p BgRypIto5q6EOFDiL9ScWOJpyZPH1fOgoMC3JbJz2vUVY83kh55JZdS94pcGzZyARZXR 3+XK2XLEZYU1vlzLCJnlxWdJbMgiM99nOQahjDZBaDxeMEQa08aJ/afoQGwzUJlYH9aB eoHJSX72vJuRIonKnpV8HqOz1QRr6hEk0VUtywxNP1YcdNx1+ZIEMwOPWZyVb0rYLcFU kA0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695057905; x=1695662705; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JpfHnxzUVMMWabALTl0v26Xf5DOzz1X5VHLZhINkdjo=; b=VsfVwGBIOnn9iUDuRUiZJpVTTEa7MomFMb7kvP+pE8Fcp2t48VoHcuvP5OENo3xddI CtIy2Xj+ArDkz1VffRjW8HpCpQ/K4Dkom+/QozWTHT2p0t5oSSzczBsv8EXBzktTf/zl LrDjsK5LggJ4dfDwa9UML1UvJ7fIWNyxVfh/Vld93p6H/ijBw2/Sn6Kl02e6qJdvOHDi KfQ5NWKttw3hEwmIORVIr+gBxTylNUYRXbMHN4Ea9ySYn2RsPERsAX/ubyN5XejX2Ng3 J1KH8785vIHl+7fXB3fmcU8sy7JrHcyhsKjCF8wxyl/sYxgQDH1ZxTxilGjSKwX7teM6 AqUA== X-Gm-Message-State: AOJu0YwXqXkh3ph3J1jdP/7vEs2wVZUybvEuZZJMZeRNg+Rgj8gQ3X4i aE5sqbn4jEifvJ3Ac8m1tC1mnjLg9MkGA95wOADHmg== X-Received: by 2002:a05:622a:1b9f:b0:3de:1aaa:42f5 with SMTP id bp31-20020a05622a1b9f00b003de1aaa42f5mr440373qtb.15.1695057905499; Mon, 18 Sep 2023 10:25:05 -0700 (PDT) MIME-Version: 1.0 References: <20230817003029.3073210-1-rananta@google.com> <20230817003029.3073210-2-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Mon, 18 Sep 2023 10:24:53 -0700 Message-ID: Subject: Re: [PATCH v5 01/12] KVM: arm64: PMU: Introduce a helper to set the guest's PMU To: Oliver Upton 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 10:25:14 -0700 (PDT) On Fri, Sep 15, 2023 at 12:22=E2=80=AFPM Oliver Upton wrote: > > 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 tho= ugh it > > + * is quite possible the selected instance supports only = a > > + * subset of cores in the system. This is intentional, an= d > > + * upholds the preexisting behavior on heterogeneous syst= ems > > + * where vCPUs can be scheduled on any core but the guest > > + * counters could stop working. > > + */ > > + arm_pmu =3D kvm_pmu_probe_armpmu(); > > + if (!arm_pmu) > > + return -ENODEV; > > + } > > + > > + kvm->arch.arm_pmu =3D 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 =3D 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 =3D kvm_pmu_probe_armpmu(); > > if (!arm_pmu) > return -ENODEV; > > kvm_arm_set_pmu(kvm, arm_pmu); > return 0; > } > Sounds good. We can adapt to your suggestion. Thank you. Raghavendra > -- > Thanks, > Oliver