Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2708020rdg; Mon, 16 Oct 2023 12:16:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbo4+u+LRnoJ14I7U69940PVw54NIaulKfdEYmvhdjDruJxsAr5pBrrA0X0sKzYjvsToBd X-Received: by 2002:a17:90a:ce02:b0:27d:3e8f:26dc with SMTP id f2-20020a17090ace0200b0027d3e8f26dcmr51451pju.9.1697483791571; Mon, 16 Oct 2023 12:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697483791; cv=none; d=google.com; s=arc-20160816; b=ngNulHkdy88OdyiyDmxujyzChL0CIa4ib/9KyYyaV+avIOMJh33frojyV10AtqFLzr mxUgca5DMqKrTUn6c1N2giUUPMp8RSDXjIHys7cIuZ0SWGKF/27gyuW4EbeksjA05dvb bQQ72jnEVdLFgLtd40tYL+u6BjZ14ZmHjJw66Upbi/QNqK00lXzHTMKUFrjT98eJA0Wf aVb+iUuao9U5497MGhlU2MREu/pTJTHmyYKiEl+UlmxZsuVsqslu1Vswkep7uYGcoZiX xRm0BR9ljR96ORDZ5wTDz2dLn0pAtkrO7jSteZ1de+NQp+HkfyVFrcbHWoTpmncS4bJ5 aTxA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:date; bh=aNCjn8kZsLzkn2TfATd/Tc8lLJ9tbwTjRnLW2H/5Bjc=; fh=w0flhQl7mctFcbI2b5EuDMWx0RWmm/SggScYTmVZk3E=; b=DqOUPIyIrA7eZzumi26EtUgaT0nB77tjJ0/0fVFoYOnyHhrHwp33U3czEePw7RKOQ3 4vrpxWHQEM/YLaFkoOFgl0EaYY8QoL6Kv6MGfZGBrTb6i5/9jvgq9vUskrJI3jeu3Vtv k7XEZMce14rUB/XWx+yqhmmkYW6oOOf3nxqFrwjM9jXnu8CqB5cDdQqiGr4r6mjCyhpi WAz/hWa7YAOFVaC1KXnYEqOipcwbqaEf6fAfcAf1ASag+WYdrHR4xi1aodtTSYjygsd3 XqX3L+/6rzEw8fV46hXnbBg0+muKc2bqeQGWaB9f9QdTjyGEa208bWaBTOuFsK5GKuLx Eerw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=NRdd9h+V; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id g14-20020a17090a708e00b0027d567be2e5si6191642pjk.92.2023.10.16.12.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 12:16:31 -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=@linux.dev header.s=key1 header.b=NRdd9h+V; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 43753809D3D8; Mon, 16 Oct 2023 12:16:19 -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 S233168AbjJPTQG (ORCPT + 99 others); Mon, 16 Oct 2023 15:16:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbjJPTQF (ORCPT ); Mon, 16 Oct 2023 15:16:05 -0400 Received: from out-193.mta1.migadu.com (out-193.mta1.migadu.com [IPv6:2001:41d0:203:375::c1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E4D183 for ; Mon, 16 Oct 2023 12:16:02 -0700 (PDT) Date: Mon, 16 Oct 2023 19:15:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1697483760; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aNCjn8kZsLzkn2TfATd/Tc8lLJ9tbwTjRnLW2H/5Bjc=; b=NRdd9h+VWrbgIUGM4R3jmxHqx88SFaakKg/7Te5xg/KGj1dAwk2Z6vmwxV3StaAY887AG4 JAJDTMNcwD4JpEoRrSLACsOhXablsrOtCuDdYSzxS7J4sCXa7Zbshj5rPOjdvqdXd2h8Co mexLF+4BOrVRGGYNMsbrRQ97E0sEBGc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Raghavendra Rao Ananta Cc: Sebastian Ott , 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 v7 07/12] KVM: arm64: PMU: Set PMCR_EL0.N for vCPU based on the associated PMU Message-ID: References: <20231009230858.3444834-1-rananta@google.com> <20231009230858.3444834-8-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS 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, 16 Oct 2023 12:16:19 -0700 (PDT) On Mon, Oct 16, 2023 at 12:02:27PM -0700, Raghavendra Rao Ananta wrote: > On Mon, Oct 16, 2023 at 6:35 AM Sebastian Ott wrote: > > > > On Mon, 9 Oct 2023, Raghavendra Rao Ananta wrote: > > > u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *vcpu) > > > { > > > - return __vcpu_sys_reg(vcpu, PMCR_EL0); > > > + u64 pmcr = __vcpu_sys_reg(vcpu, PMCR_EL0) & > > > + ~(ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_SHIFT); > > > + > > > + return pmcr | ((u64)vcpu->kvm->arch.pmcr_n << ARMV8_PMU_PMCR_N_SHIFT); > > > } > > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > > > index ff0f7095eaca..c750722fbe4a 100644 > > > --- a/arch/arm64/kvm/sys_regs.c > > > +++ b/arch/arm64/kvm/sys_regs.c > > > @@ -745,12 +745,8 @@ static u64 reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) > > > { > > > u64 pmcr; > > > > > > - /* No PMU available, PMCR_EL0 may UNDEF... */ > > > - if (!kvm_arm_support_pmu_v3()) > > > - return 0; > > > - > > > /* Only preserve PMCR_EL0.N, and reset the rest to 0 */ > > > - pmcr = read_sysreg(pmcr_el0) & (ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_SHIFT); > > > + pmcr = kvm_vcpu_read_pmcr(vcpu) & (ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_SHIFT); > > > > pmcr = ((u64)vcpu->kvm->arch.pmcr_n << ARMV8_PMU_PMCR_N_SHIFT); > > Would that maybe make it more clear what is done here? > > > Since we require the entire PMCR register, and not just the PMCR.N > field, I think using kvm_vcpu_read_pmcr() would be technically > correct, don't you think? No, this isn't using the entire PMCR value, it is just grabbing PMCR_EL0.N. What's the point of doing this in the first place? The implementation of kvm_vcpu_read_pmcr() is populating PMCR_EL0.N using the VM-scoped value. -- Thanks, Oliver