Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp256577rdb; Mon, 18 Sep 2023 14:13:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGh6vWo+Hv4Di2HaPM+8vY/Ty6HIxcIZJpb3GYbPzJCq52qWYq9yQLVlXeXhOHkReoJnNVp X-Received: by 2002:a05:6a00:1789:b0:68b:fb93:5b48 with SMTP id s9-20020a056a00178900b0068bfb935b48mr9488123pfg.18.1695071629582; Mon, 18 Sep 2023 14:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695071629; cv=none; d=google.com; s=arc-20160816; b=X7vpAEunxI3UV7fNfZTpPl5Y5lart6gwONS5Iq+po0IFMFUvV/u/tkeaZTwHDBOIQS zkGawMrmeW27SJmzqdJblZWInO/zPsT1XLlOPNKXH6OHqVQVuzPpUS81NL9W/eUX12sB xd5sK8+x3zKzWwHo+BGvGc2Q3MZBrRgUS6ElIB50JiiIxvvqZCLdpkGroUSEHtUqK0tv E1AeYEZ2gNtm2SNyrBIHE0M4TZvgWWVBgKY2q61+n9AXrTpAGhGjJA++Y8nUQhtOywTK Z2wEoGNkpstf2GDN+Z8Kc4qNrw+UdwzRWi602kqKZ6mhta1YW+iUjhKC67c7jewX5TKa meQg== 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=3k+upgBrLGSSOmHlswDoCSbrUwpeYXhWKscYPZe5kLQ=; fh=dMrWgnXzzePbjJ5Lnz3JQ1FNdAF92uv7SkGdCptz9bs=; b=QDbq151EJ/yMd5HWNmRz9HM0hfGyrsgbs6PHQDC9qLMLImxfdzE6HXrg3JcCkBTM5u Mxsyl/UIv/EAAbXcbeorbr4uRtOVgX2G51etyGUXvjbavZSZ/7F0k1RW+7Y8nFz2s6Zm BzGqMmfvbRS4BW8PFfEpxRdu0UzVVyQwflOLxWh2FefSMIvv3M83P6oP8Lsz4wsorilD WvlL+H8KJBiYWeuhoIup2O2UKPbjDOZNqrgDlFb2lrcwNKXlBOoBtuDYdcUwf4KERMpL nNiRWY9/OoGC48aGCX5gGljFxwJtJfyoK/jBvzPzhHHaNzgw6Atqqtzn4s3EDeu6Cn27 hQ5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jpuEAafR; 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 201-20020a6301d2000000b0056a290addadsi268593pgb.787.2023.09.18.14.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 14:13:49 -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=jpuEAafR; 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 BC358806293B; Mon, 18 Sep 2023 10:12:04 -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 S231295AbjIRRLi (ORCPT + 99 others); Mon, 18 Sep 2023 13:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230266AbjIRRLg (ORCPT ); Mon, 18 Sep 2023 13:11:36 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82B4190 for ; Mon, 18 Sep 2023 10:11:30 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-34fa117f92bso4235ab.1 for ; Mon, 18 Sep 2023 10:11:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695057090; x=1695661890; 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=3k+upgBrLGSSOmHlswDoCSbrUwpeYXhWKscYPZe5kLQ=; b=jpuEAafRAsD6rveD9aUrpLk1zUqrDaWIyMOp4DdOydmp4GJZLQXUPa3aMBbLR0ej9s ChNwJcbJYAJrrTYHtQOUNzNwrKy238HWQw0UeUn4fmGybS/7cV2gXKohH6GCXm8eRGwc MbShtu+YvojO0J97a7g1Um8g9q33qzgkjHrWTOBm8AK4iH9Ns7CRxJaJ7gYcA+Ny1jsB laoTmjl7CzfwyKjYRwQg1SOSO4wlASlL9WDM6aDYrzz9ccJLFGVPlHmPkcncovOQ1pRv ElT8yuWMjA1sq1JfjQ8L02Yf5COdZWU2NsCGiTIy9Rf8HN3FgzzojRdvKqgqYdEZb8oO MqLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695057090; x=1695661890; 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=3k+upgBrLGSSOmHlswDoCSbrUwpeYXhWKscYPZe5kLQ=; b=wBlddZHOQUFMObbdBfZLJXDzRdSXnPycqcJcdxxjPC7jgzlccIKWKuLV90Xk6K0lST TJrnkN6twJcEZvL5HRY8Qq/Mp0bU/5qDtqDxdOvsHhYBs7HafzQA303KKvahSVBoqF4s gmWKnhOtpXnmYTn+jT57KPK7iQwA5BEr4+e0gA7tEHEpaCkQOyrwFa0Tj2/vw2wxsSLZ 67/PU/kRHfPHya/424bEgjHI2hNvKqCTASdegnGv1eptNm6BSZKND08dzvZIZznz9g6g M9XpCLqz30spDv2JfZbkb8/IPA7+b3AAYseTA+DWHXjuc15ZFCCat4rn4ZoGZse/VSiv kgzA== X-Gm-Message-State: AOJu0YxrA/M/h/TUPmNRkBvAQr2PzAdMGaKJDD5ryPUiFz4eftc3DPgH Pb4ou54zaC3kktgDx2x6uvwgv90Bs9S0tk6vkWGAzQ== X-Received: by 2002:a92:c247:0:b0:346:139d:4549 with SMTP id k7-20020a92c247000000b00346139d4549mr459650ilo.1.1695057089709; Mon, 18 Sep 2023 10:11:29 -0700 (PDT) MIME-Version: 1.0 References: <20230817003029.3073210-1-rananta@google.com> <20230817003029.3073210-9-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Mon, 18 Sep 2023 10:11:17 -0700 Message-ID: Subject: Re: [PATCH v5 08/12] KVM: arm64: PMU: Allow userspace to limit PMCR_EL0.N for the guest 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:12:04 -0700 (PDT) On Fri, Sep 15, 2023 at 2:54=E2=80=AFPM Oliver Upton wrote: > > On Fri, Sep 15, 2023 at 08:53:16PM +0000, Oliver Upton wrote: > > Hi Raghu, > > > > On Thu, Aug 17, 2023 at 12:30:25AM +0000, Raghavendra Rao Ananta wrote: > > > From: Reiji Watanabe > > > > > > KVM does not yet support userspace modifying PMCR_EL0.N (With > > > the previous patch, KVM ignores what is written by upserspace). > > > > typo: userspace > > > > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > > > index ce7de6bbdc967..39ad56a71ad20 100644 > > > --- a/arch/arm64/kvm/pmu-emul.c > > > +++ b/arch/arm64/kvm/pmu-emul.c > > > @@ -896,6 +896,7 @@ int kvm_arm_set_vm_pmu(struct kvm *kvm, struct ar= m_pmu *arm_pmu) > > > * while the latter does not. > > > */ > > > kvm->arch.pmcr_n =3D arm_pmu->num_events - 1; > > > + kvm->arch.pmcr_n_limit =3D arm_pmu->num_events - 1; > > > > Can't we just get at this through the arm_pmu instance rather than > > copying it into kvm_arch? > > > > > return 0; > > > } > > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > > > index 2075901356c5b..c01d62afa7db4 100644 > > > --- a/arch/arm64/kvm/sys_regs.c > > > +++ b/arch/arm64/kvm/sys_regs.c > > > @@ -1086,6 +1086,51 @@ static int get_pmcr(struct kvm_vcpu *vcpu, con= st struct sys_reg_desc *r, > > > return 0; > > > } > > > > > > +static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc= *r, > > > + u64 val) > > > +{ > > > + struct kvm *kvm =3D vcpu->kvm; > > > + u64 new_n, mutable_mask; > > > + int ret =3D 0; > > > + > > > + new_n =3D FIELD_GET(ARMV8_PMU_PMCR_N, val); > > > + > > > + mutex_lock(&kvm->arch.config_lock); > > > + if (unlikely(new_n !=3D kvm->arch.pmcr_n)) { > > > + /* > > > + * The vCPU can't have more counters than the PMU > > > + * hardware implements. > > > + */ > > > + if (new_n <=3D kvm->arch.pmcr_n_limit) > > > + kvm->arch.pmcr_n =3D new_n; > > > + else > > > + ret =3D -EINVAL; > > > + } > > > > Hmm, I'm not so sure about returning an error here. ABI has it that > > userspace can write any value to PMCR_EL0 successfully. Can we just > > ignore writes that attempt to set PMCR_EL0.N to something higher than > > supported by hardware? Our general stance should be that system registe= r > > fields responsible for feature identification are immutable after the V= M > > has started. > > I hacked up my reply and dropped some context; this doesn't read right. > Shaoqin made the point about preventing changes to PMCR_EL0.N after the > VM has started and I firmly agree. The behavior should be: > > - Writes to PMCR always succeed > > - PMCR_EL0.N values greater than what's supported by hardware are > ignored > > - Changes to N after the VM has started are ignored. > Reiji and I were wondering if we should proceed with this as this would change userspace expectation. BTW, when you said "ignored", does that mean we silently return to userspace with a success or with EBUSY (changing the expectations)? Thank you. Raghavendra > -- > Thanks, > Oliver