Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4901080rdb; Fri, 15 Sep 2023 16:27:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbq0AyV9RGHWnrUBzYHHooMWNY/x7GMrdAO9oSPalRB7wLcLaJdfJJAlGt7vuTI5SgF9Ps X-Received: by 2002:a05:6a20:3d26:b0:154:9222:684a with SMTP id y38-20020a056a203d2600b001549222684amr3979095pzi.24.1694820420610; Fri, 15 Sep 2023 16:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694820420; cv=none; d=google.com; s=arc-20160816; b=jKMUeAe7MPpax5i/EsAMnAw4YRVkmrqGDBweBojKSvhypiGGvj8yvL//7aUDCu7kjt XZUsiu49vskEWn7AMqNshPQ5MAC6q44LcHXZ/AzTA6miI0gBywfzSB1wJ6Y964HUYm4M qH3fc3FIivM52xCClPX71SY0dMbkRT5H42fYJAAMcWcCSMgkveWxp873Di0zN3OSz4Vb +tjJG0ZhLFLpQ08V6bEbiVKRbmYND/IP7C1NfvROK1aRaeLh5MalOGrREJir/vIPbVmI NP4j3nEHzdg7WxTahQVEe3U/eCOLNf/7/4YYxBLTLVbsQbMKFYZLDpbBkqgF/Y72RdHk 2cAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=y7OM5v7blYOAJxEJ3s0YCjQVgdsW57nwTu7RUWwmajk=; fh=4I6BNv7iobpZrRcbueKA7r9RD02xPQmynyU/PeDFguM=; b=rdFpNjtLc0fnsJCfhfN9EnXRKhwJmVuvz8cwheucGlE5UbNDVH3yV2g8Eow0xDQYkE 7Rb9kshGmopcbqmaJ8F04CxNMtMYkeC8vmMOsiOW5IuW1DssTf9JZ2phI0LMCF4fHKlt FM+smZ0kJwz6MbvwdnL7IeZcwM9mOABFbF35GemEhoEGay6N/v1Hd8gadr8LSd8UAiVZ m7mE4RtVfV36OucB23GTcR/DFYZnBsvJZ3+9Jl9ButfQexUPibXdHDrIKH8pOlVHj/KC uzaOjqqQCSpEskopAx2K8Iaeo9kANEhSgOhnlsrrAY/iFGGEsk4a1WS0XHy+BR7pn04+ kv0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WUgTdPy3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id a18-20020a63d212000000b005774d2f4ab5si3771096pgg.807.2023.09.15.16.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 16:27:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WUgTdPy3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4BE938087531; Fri, 15 Sep 2023 13:57:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237481AbjIOU5B (ORCPT + 99 others); Fri, 15 Sep 2023 16:57:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237887AbjIOU4f (ORCPT ); Fri, 15 Sep 2023 16:56:35 -0400 X-Greylist: delayed 5481 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 15 Sep 2023 13:54:17 PDT Received: from out-227.mta0.migadu.com (out-227.mta0.migadu.com [91.218.175.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A5D31AD for ; Fri, 15 Sep 2023 13:54:17 -0700 (PDT) Date: Fri, 15 Sep 2023 20:53:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1694811196; 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=y7OM5v7blYOAJxEJ3s0YCjQVgdsW57nwTu7RUWwmajk=; b=WUgTdPy3r/vauuaDrIYbzKUJBVRiZtdsHsT0S+gxTtgpjItrfnOfVIa5iN5njKOUsxCFwG 3vNVLS+vQx0k1l5eeblNMvEa/3HbVWyRVFq6CPHpqiNYwL+jSnl+uGk9EMrCRNIhTrsGJ5 BuFjAwp4Qecsddpz7fxnU4li3QgtiAk= 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 08/12] KVM: arm64: PMU: Allow userspace to limit PMCR_EL0.N for the guest Message-ID: References: <20230817003029.3073210-1-rananta@google.com> <20230817003029.3073210-9-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230817003029.3073210-9-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Fri, 15 Sep 2023 13:57:44 -0700 (PDT) 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 arm_pmu *arm_pmu) > * while the latter does not. > */ > kvm->arch.pmcr_n = arm_pmu->num_events - 1; > + kvm->arch.pmcr_n_limit = 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, const 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 = vcpu->kvm; > + u64 new_n, mutable_mask; > + int ret = 0; > + > + new_n = FIELD_GET(ARMV8_PMU_PMCR_N, val); > + > + mutex_lock(&kvm->arch.config_lock); > + if (unlikely(new_n != kvm->arch.pmcr_n)) { > + /* > + * The vCPU can't have more counters than the PMU > + * hardware implements. > + */ > + if (new_n <= kvm->arch.pmcr_n_limit) > + kvm->arch.pmcr_n = new_n; > + else > + ret = -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 register fields responsible for feature identification are immutable after the VM has started. -- Thanks, Oliver