Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp288985rdb; Mon, 18 Sep 2023 15:30:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExsiLv2IrwCz6JuIfexO0UaY7REw4oRdD0yLVEXYToLHk1glrZmojmB9OlzqR7yyrGtdaf X-Received: by 2002:a17:902:f689:b0:1c3:2ee6:380d with SMTP id l9-20020a170902f68900b001c32ee6380dmr10797256plg.48.1695076214532; Mon, 18 Sep 2023 15:30:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695076214; cv=none; d=google.com; s=arc-20160816; b=p4CR6bboGQGlzrIKgIKJp/CF1vg5ghIhy2EWSEQxse+tcu6VdpoOB/CKmURfs/BjiW nj6Knbw1qeZGALTuGEG1W1Fxffk4watMXihWcKsRm5SsC+kilD83yKrUnRnWrGXnckK/ ytkDH68B3X/8rj5qzwA+xfenqJ0glvrv8120nre+XvRZUbBRqdmoiv8WhvpGA+7pakBB JZi5XC7TirbFdvJbW95M6moGRhAKla0aOSzA107SI/QblV9AIbVyt2XSDAJYNkQweESx VjxswcWXpj1GIT73dcxbY9d2uHr7sn/vfcDjc8nzagGo+vTgr/y19PdJsmEcwmrA0+tV EnvA== 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=xvvJYFIiUxdYFTdPHEaO0CeIjpRLTphScVUwzbxkZK0=; fh=dMrWgnXzzePbjJ5Lnz3JQ1FNdAF92uv7SkGdCptz9bs=; b=Q+kLDJcAkZzX3hK4Ae9X/V3V/Lhvm7YzXB6kn9WO1C/uXJ0/OEuH8qRaP7GRvdVxKA n7pG/wJU2loonc1n1GAFSy9/3rMTqcMpLZRA9yqvh7F2KjMnL2Qe90yUevMjQqJSZAT4 n6WuWNALAKpdw6sHGAcsQCgWEzaCDJb0V1soFGABnPGb5BKKXoMN49duh/9NTUfLj513 N5vUSh6qeBXWQyuN6TAV+/5/EqkdZFVGh+YWAxz3dW+3brnPhmhsc9F6lugn/tPWI+BC Q8qCxYZidCAa/W2sZzpAwc1aNC9TNKc/xXRTjFg1CYv5JJnSK1xTytSJn2Oo2csJguJ5 XUHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wndlOZ7z; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o12-20020a170902d4cc00b001c56f4dd6b7si2318982plg.150.2023.09.18.15.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 15:30:14 -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=@google.com header.s=20230601 header.b=wndlOZ7z; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C47DE80C03B0; Mon, 18 Sep 2023 10:22:52 -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 S230034AbjIRRWw (ORCPT + 99 others); Mon, 18 Sep 2023 13:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbjIRRWv (ORCPT ); Mon, 18 Sep 2023 13:22:51 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D633DB for ; Mon, 18 Sep 2023 10:22:45 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id d75a77b69052e-414ba610766so22531cf.0 for ; Mon, 18 Sep 2023 10:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695057764; x=1695662564; 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=xvvJYFIiUxdYFTdPHEaO0CeIjpRLTphScVUwzbxkZK0=; b=wndlOZ7zcAzDQaFfix5uVbtaIVLy3pxjyxzT0S+erwGtCKgO7JR5HMn0Lh2iV545k6 R1psIzr8Vy04SxEEFUZwM6KF+oc5KEQwzP66wHJKKWNGGEQJM5HIRdmz5RZxXHfOvyfZ z6LAXfIyTgOfGVHIqaBNu5QMEx0v/mPTvvcNw/TMO0k/M2rVc4X1Y/SFmbWuKI9GxnYc MTMzvuhUxUBu3KpQ6lBZTf6TJM/JFLxR/HJnlyblSrKWVX74uEOEbLIwP1yDHT0GohV0 IyxKbIdsFg5f0v1Okg8uyUKwTz1k3+LmiWpsMWghvwGzjQ8FyApQUGBN6enhMICzDZ/n Qkug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695057764; x=1695662564; 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=xvvJYFIiUxdYFTdPHEaO0CeIjpRLTphScVUwzbxkZK0=; b=JNUkSpYf/HdyT1EcY09vseTPUQQyasd5BUZQJbU5gFF8oEi8iHJ0NOM3DYDwXyCv6v Ecwozsp+hL8vsi6dVX4r4kttYYp8vQ6/xYTAbXoICRM7inwte4O1TAljgE+cb0RjVXGi WC1Y6uCcaksK5uCmwFsriOUUcKTV0Dm/gIAg5CgS5WmreTnxW17PH9xTK23mY6HUDgLc Umw6EmTdYbglglOJcl+8tcc5TgB05poP99RDG//F0uRQhLHg9fggSToOlVhRmT8ed39d njbjAE8QMKQKXhCmAgz/pxv8KBSj1Fd3SS5IrNJiwXsf5iN6HbKa/7X/5DDFaeMF2nBW DFug== X-Gm-Message-State: AOJu0YwyoiQQ8ts6/Zam0uvz5NFnMUxe5EhI6Y7j4NtVNTyKBH9C9U2I MDgLk40jJ+v85BK72jSkKBGSNAh87z57Dd6y6kCDNg== X-Received: by 2002:a05:622a:1049:b0:410:9855:ac6 with SMTP id f9-20020a05622a104900b0041098550ac6mr5770qte.14.1695057764287; Mon, 18 Sep 2023 10:22:44 -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:22:32 -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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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]); Mon, 18 Sep 2023 10:22:53 -0700 (PDT) Hi Oliver, On Mon, Sep 18, 2023 at 10:11=E2=80=AFAM Raghavendra Rao Ananta wrote: > > 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 wrot= e: > > > > 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 = arm_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, c= onst struct sys_reg_desc *r, > > > > return 0; > > > > } > > > > > > > > +static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_de= sc *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 regis= ter > > > fields responsible for feature identification are immutable after the= VM > > > 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)? > Sorry, I just read your earlier comment (one before you detailed the behavior), from which I'm guessing "ignore" means simply disregard the change and return success to userspace. But wouldn't that cause issues in debugging? Thank you. Raghavendra > Thank you. > Raghavendra > > -- > > Thanks, > > Oliver