Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp242975rdb; Mon, 18 Sep 2023 13:43:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYWaS9ENZQL09BzhodOVwPq5Zttd/uu2WzKmz9CYc9KVzXVeTXD2Q5st5QDzeIv1CY3nPN X-Received: by 2002:a05:6300:8088:b0:13f:5234:24ce with SMTP id ap8-20020a056300808800b0013f523424cemr10023861pzc.28.1695069838561; Mon, 18 Sep 2023 13:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695069838; cv=none; d=google.com; s=arc-20160816; b=U6LHj5a+D7S/RYIbeOfxeZEJr2HObYfblxt965dIkja+Mc4GIDWRSax44P7ACs8HGO X3+BT0VFzjslwfnUoj84t6GeXHDrMB8CQh4eaB3lrUP510i4vnoDh4Ar98IqZrfQ0/1t Z6Ss3RdQsot+S9v9yn/9pfRzsFPpjUSYet2bxWJHcgEz/eDnRUE7mwJkG96i4FB6Suv4 eS46LSks02vN0uYH3mwRFFs2+UC5sDOr8ZeDQGvr/mEvyThVK2QJ9S9Y6CVbZt6h0hRB C20gwxWs8YdXXzX6zr/MAR+NQ8oYqOtP3bkMMOBlT8W76c6Pc6twjbhXqDyO1VnEZNs8 6sJg== 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=5aqGbaeNMJotwM7iCcNvbcrR77QfKFKAxShP18uzRjU=; fh=dMrWgnXzzePbjJ5Lnz3JQ1FNdAF92uv7SkGdCptz9bs=; b=p8z+mR32fEMKAy83eOz11QxCp/9ALg2ySapyVppkQb1d7DzR73Ablv9831fPlpf0R2 6PFuHqfnOgVKxVi2XXVTpOFutg+0zruy08XLMi9IJowQYWe690UHRYfSj37vhf7Et/0T BfFvXyh6mDnS1uadqMJKXrYoK7BfQPEWxhn6HWj4JxUVGDAcZGFAViXNevIfSmZdIwwo l2ON1a8XiMiYcUKCbYDKeKujidjStxuNHiyJ8JDP3TzPgf8+QxVzfvw4NZGf+36Gb2ul m5pl69H1NC+rzqAnVc6ZCHj4ZyexYrI/36XO7DvplaoIz3fENvJcz7DwnfBFcUpqTCyQ hGPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tNuoE0oJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id w6-20020a637b06000000b005696a8e371csi8155886pgc.35.2023.09.18.13.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 13:43:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tNuoE0oJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id E81F08039FC0; Mon, 18 Sep 2023 09:43:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230492AbjIRQnT (ORCPT + 99 others); Mon, 18 Sep 2023 12:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbjIRQm5 (ORCPT ); Mon, 18 Sep 2023 12:42:57 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24777527B for ; Mon, 18 Sep 2023 09:41:15 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-34fa117f92bso305ab.1 for ; Mon, 18 Sep 2023 09:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695055274; x=1695660074; 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=5aqGbaeNMJotwM7iCcNvbcrR77QfKFKAxShP18uzRjU=; b=tNuoE0oJZd6v0I5ZWDU8sWRBCXs4uE92N9710haM8INO1mWr4SsLpW5RMGgDzqJy3J XVEy3yg7q2kkWecgHzV3lYysEHqelkLxwYEgXyVIWkBwT4jMzrn6sF6jrdA+y89Ao0Zz ApjBR5S23RiWvFxhIunYE2jxRWxQ1yXBCw00lEk6Xx+GId+xpvufF3EiSU0XUVM45V+M eEjr723F10sZL9XnbUy/spjZt7PtV02lk8g+ZvKz5bH6Yvtkvf4XbU8HZeFRFV6/OhnC 21Tl6Ld6iYZy/zBJxK/vHq8DsRK4GfsEM1BtBMBBwvwqNxr37lbgVyBxVPwZyoTxK1NI EHhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695055274; x=1695660074; 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=5aqGbaeNMJotwM7iCcNvbcrR77QfKFKAxShP18uzRjU=; b=jOz4ttsu/FcfKBoApn45zVGjdWZDYi0sYhDxTyM7gYsy2+E8vToa4M9Zji0S38EBXL QphmV/ipZ1gZzbPSmfn7uzscg8zILrDm+j1AvMVPZZwlSePTlffBPzgvaki5vQrA5mZM 0pkGqFxez45CORQvDIw4JKeqiasMhdDSTQXawAvP2K5BHpxHyfTmXNS104We1r0jmcOp HlZAKMPhBdokCWksxOVzMGfHIIPzCruExphxqQ9NoaHtlTJGeVg+CVs7MykRDufmoNs3 7zD0l6d1MRX4VCpADsyFKERuSUQPhIi0l+zHgF6A4tJaxSX/Oeu34pxDmUuUrwsajvmU iSXw== X-Gm-Message-State: AOJu0YxDgXjl8MLxEwgVDIst0TV2c8Oimt8J4JnHkf8sjYKwcDwJXNqd WzJaysYhiXyo/JukiJNKnT4oVsxu4pAk0NSOVINxHg== X-Received: by 2002:a05:6e02:1c47:b0:34d:ec9d:df60 with SMTP id d7-20020a056e021c4700b0034dec9ddf60mr409293ilg.17.1695055274260; Mon, 18 Sep 2023 09:41:14 -0700 (PDT) MIME-Version: 1.0 References: <20230817003029.3073210-1-rananta@google.com> <20230817003029.3073210-3-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Mon, 18 Sep 2023 09:41:02 -0700 Message-ID: Subject: Re: [PATCH v5 02/12] KVM: arm64: PMU: Set the default PMU for the guest on vCPU reset 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:43:25 -0700 (PDT) On Fri, Sep 15, 2023 at 12:33=E2=80=AFPM Oliver Upton wrote: > > On Thu, Aug 17, 2023 at 12:30:19AM +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, call > > kvm_arm_support_pmu_v3() just before doing the reset. > > > > No functional change intended. > > But there absolutely is a functional change here, and user visible at > that. KVM_ARM_VCPU_INIT ioctls can now fail with -ENODEV, which is not > part of the documented errors for the interface. > > > Signed-off-by: Reiji Watanabe > > Signed-off-by: Raghavendra Rao Ananta > > --- > > arch/arm64/kvm/pmu-emul.c | 9 +-------- > > arch/arm64/kvm/reset.c | 18 +++++++++++++----- > > include/kvm/arm_pmu.h | 6 ++++++ > > 3 files changed, 20 insertions(+), 13 deletions(-) > > > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > > index 0ffd1efa90c07..b87822024828a 100644 > > --- a/arch/arm64/kvm/pmu-emul.c > > +++ b/arch/arm64/kvm/pmu-emul.c > > @@ -865,7 +865,7 @@ static bool pmu_irq_is_valid(struct kvm *kvm, int i= rq) > > return true; > > } > > > > -static int kvm_arm_set_vm_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu= ) > > +int kvm_arm_set_vm_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu) > > { > > lockdep_assert_held(&kvm->arch.config_lock); > > > > @@ -937,13 +937,6 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu,= struct kvm_device_attr *attr) > > if (vcpu->arch.pmu.created) > > return -EBUSY; > > > > - if (!kvm->arch.arm_pmu) { > > - int ret =3D kvm_arm_set_vm_pmu(kvm, NULL); > > - > > - if (ret) > > - return ret; > > - } > > - > > switch (attr->attr) { > > case KVM_ARM_VCPU_PMU_V3_IRQ: { > > int __user *uaddr =3D (int __user *)(long)attr->addr; > > diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c > > index bc8556b6f4590..4c20f1ccd0789 100644 > > --- a/arch/arm64/kvm/reset.c > > +++ b/arch/arm64/kvm/reset.c > > @@ -206,6 +206,7 @@ static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu = *vcpu) > > */ > > int kvm_reset_vcpu(struct kvm_vcpu *vcpu) > > { > > + struct kvm *kvm =3D vcpu->kvm; > > struct vcpu_reset_state reset_state; > > int ret; > > bool loaded; > > @@ -216,6 +217,18 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) > > vcpu->arch.reset_state.reset =3D false; > > spin_unlock(&vcpu->arch.mp_state_lock); > > > > + /* > > + * When the vCPU has a PMU, but no PMU is set for the guest > > + * yet, set the default one. > > + */ > > + if (kvm_vcpu_has_pmu(vcpu) && unlikely(!kvm->arch.arm_pmu)) { > > + ret =3D -EINVAL; > > + if (kvm_arm_support_pmu_v3()) > > + ret =3D kvm_arm_set_vm_pmu(kvm, NULL); > > + if (ret) > > + return ret; > > + } > > + > > On top of my prior suggestion w.r.t. the default PMU helper, I'd rather > see this block look like: > > if (kvm_vcpu_has_pmu(vcpu)) { > 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) && kvm_set_default_pmu(k= vm)) > return -EINVAL; > } > > This would eliminate the possibility of returning ENODEV to userspace > where we shouldn't. > I understand that we'll be breaking the API contract and userspace may have to adapt to this change, but is it not acceptable to document and return ENODEV, since ENODEV may offer more clarity to userspace as to why the ioctl failed? In general, do we never extend the APIs? Thank you. Raghavendra > -- > Thanks, > Oliver