Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2771236rdg; Mon, 16 Oct 2023 14:36:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4E8BjAUSHJTWTi5tTzMJa4fLK3jopGMD6wxT2eTgZnkyNg9PfYv3hfDUunAIyy6dTQoIu X-Received: by 2002:a05:6a00:1a8f:b0:68a:4d66:caf with SMTP id e15-20020a056a001a8f00b0068a4d660cafmr362932pfv.34.1697492179895; Mon, 16 Oct 2023 14:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697492179; cv=none; d=google.com; s=arc-20160816; b=m6rkp7RWNKVHHr8mxVhHPnUx1oZf4zfcZQ/hqdRXUBtwP8R6QUDXeBQCqYrUukD2Vh qJdWn/qWY8dAMUKGk79a24cz9IYcEhwbdZa4wEQqmXhSvBdx7xev1B5J3yk+R2sXURgI 5W1iRls3z3MezmQZeb/tg5DSPSf4MjCQXsCaAlHk5LBRReQ5mbC2xP/QfWIkVWYMeWDo BuOyxsMZM1NwzkskNg4eueBb5bFS6q0AcmHjlsBPBy5bC8AxMlPBOWESr4XvHs2BxHKZ 0ceZtaecNGnw56PKkPITedp4l/Kb7dqQ4XHI0Ec/EYY2/DdnPgE2wIV10G9+0s0nUGxE 3znQ== 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=gG0OkIWDPYdZRvQuvf3btCaImiKQgqO1e18TbAYg8Pg=; fh=OvPCPWmOZlQ11X1Bd0N2T4yM6wYPPrTPc3iW1iqu53w=; b=zAQuMEB9RbmMdMJCUFcHlRTYwDBZtogX+QTOEObl8dJ9Q0MF5I6k7odDn+WSHLGP2g 20+auvTb5gdLxr0R9SKJOIU0VSkGhS4XI6M1yNpXCub1R8p0kh4XT9v1QQa8r/2JQ/62 bB3Qg2XBk0dmgkR5Zn6k69WlIcaEUXgrU72e0KBzeDkgQ0mDlAF8CEaDxTv8KX4UwOpl Ea75r+YJFefThlW5p5HuCFkyLDCM3lJ/jIndMrgngyU6I+MT6nTkXJRFkhajcfH4yXQS KfzoqTTowZXHmXyaYSh3FMRJlNBqXs/uKWYPJ9ARq+Iciu7kHjbjNHg6L8E3q3aYpbSZ UhYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="0hHW1d/7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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. [23.128.96.33]) by mx.google.com with ESMTPS id d3-20020a056a0010c300b006be0e90200dsi71146pfu.374.2023.10.16.14.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 14:36:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="0hHW1d/7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 D90A08038FBC; Mon, 16 Oct 2023 14:36:17 -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 S233956AbjJPVgI (ORCPT + 99 others); Mon, 16 Oct 2023 17:36:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbjJPVgH (ORCPT ); Mon, 16 Oct 2023 17:36:07 -0400 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B342AB for ; Mon, 16 Oct 2023 14:36:05 -0700 (PDT) Received: by mail-qt1-x834.google.com with SMTP id d75a77b69052e-419b53acc11so44681cf.0 for ; Mon, 16 Oct 2023 14:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697492164; x=1698096964; 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=gG0OkIWDPYdZRvQuvf3btCaImiKQgqO1e18TbAYg8Pg=; b=0hHW1d/7AzYtGkXWKlamJWLlz+dMcyRD4KvAOQfrXkAwAu7uewBUozkfLwYDcPSQzq ToUFpDvEm2ghWHmqgesqcR4/DO2oIC4fzBM0AVj5ukCdgijehzH4eDbXeMgADxSKUR/r 0YoG4m5wY0xHsIQQN4jP7RLmn43GxJJLfRi2mQwmX2LyyeNDbOmF1I75D7KpwPCDxDCb Ax303E9zMx7ZWfXlUcahck+XF9sv9X/zjzsd2CUsSTo8d2UeFjbOVfiV7+8XQD7m0Q9S 5bsmdZ2CT3gn4m4ZyenjTTEjaWyhBHWXl1IC25CFJzn83HDbCCrSesuf0AcAW19FwZgG qORQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697492164; x=1698096964; 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=gG0OkIWDPYdZRvQuvf3btCaImiKQgqO1e18TbAYg8Pg=; b=uVWgWsahhE1yHbtdSfOxBGbfimR7PV/JLf066tMmrzJ9wfVaYxRucSTgF0xkSpdcMz P8FfrAMx106LaynA16/lupqk4h9Cg56NIHRtV9e/9YtVpWP7Gcq74NhJPXkHwn1sXg0j foKr0H2sGDNXksB5Wq0xkoQhxArC1W4kb/qsK6umwFrSLcxPHYWG51KAaUOVrZ90dOk4 RX+hY7VoLMO5X7eDBg0/TeCx2fnW2UCG0nfHxkzD9HQwAHG0+VPN//w2oox1CKSQMWxT IgqwGcNCzAZmt1Wh2yz53IxUwxUg6USTKIUdacxKm44ZcU9MrmqKUO/F8hyOkLKFLqgk Z4OA== X-Gm-Message-State: AOJu0Yx5iBMdbkbOaXp7fu5uRbyUPx0pek9Y9YJUFUXJ+bAAZR0gKPZx iBoMeOLM/IObKN1UiaQQdXRvRqWY/Rf5azcnzLeUYw== X-Received: by 2002:a05:622a:760f:b0:410:9855:acd with SMTP id kg15-20020a05622a760f00b0041098550acdmr76659qtb.14.1697492164218; Mon, 16 Oct 2023 14:36:04 -0700 (PDT) MIME-Version: 1.0 References: <20231009230858.3444834-1-rananta@google.com> <20231009230858.3444834-8-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Mon, 16 Oct 2023 14:35:52 -0700 Message-ID: Subject: Re: [PATCH v7 07/12] KVM: arm64: PMU: Set PMCR_EL0.N for vCPU based on the associated PMU To: Oliver Upton 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 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, 16 Oct 2023 14:36:18 -0700 (PDT) On Mon, Oct 16, 2023 at 12:16=E2=80=AFPM Oliver Upton wrote: > > On Mon, Oct 16, 2023 at 12:02:27PM -0700, Raghavendra Rao Ananta wrote: > > On Mon, Oct 16, 2023 at 6:35=E2=80=AFAM 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 =3D __vcpu_sys_reg(vcpu, PMCR_EL0) & > > > > + ~(ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_S= HIFT); > > > > + > > > > + 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, c= onst 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 =3D read_sysreg(pmcr_el0) & (ARMV8_PMU_PMCR_N_MASK << AR= MV8_PMU_PMCR_N_SHIFT); > > > > + pmcr =3D kvm_vcpu_read_pmcr(vcpu) & (ARMV8_PMU_PMCR_N_MASK <<= ARMV8_PMU_PMCR_N_SHIFT); > > > > > > pmcr =3D ((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. > Oh sorry, my bad. > 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. > I guess originally the change replaced read_sysreg(pmcr_el0) with kvm_vcpu_read_pmcr(vcpu) to maintain consistency with others. But if you and Sebastian feel that it's an overkill and directly getting the value via vcpu->kvm->arch.pmcr_n is more readable, I'm happy to make the change. Thank you. Raghavendra > -- > Thanks, > Oliver