Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp159755rdb; Mon, 18 Sep 2023 10:58:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAUbYup1teCiflHOrGx7S+SFmjqIb7+KiwTQrPhG8QWnYJVgNNx0V+i1a4dQspsbXKLABh X-Received: by 2002:a17:90a:5aa5:b0:26d:40ec:3cf3 with SMTP id n34-20020a17090a5aa500b0026d40ec3cf3mr8483597pji.0.1695059915686; Mon, 18 Sep 2023 10:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695059915; cv=none; d=google.com; s=arc-20160816; b=ikQ04VqJAKWtvXsjl6z3Ro5NngR1AnbL39psG5i4IFaW/IAIllyk6iIjQUko7OAFP+ dqJ2Ta5nj9Np0VtSgvBl1HNZrhiszQXawaBqwWMKcqNKpDCo9i2VOXjxsp7ZQjYSzoo9 3yfiL1N64tySWA4F2q6WMPJdZdTk/VsD1DXZri17uOTGQesTaZjLVYdwme7bDkzbKQnt AZdjXQ2zVs1zkeUnNuYICwaOLnp0ppcBS4YN7dOFwbmNziJU4p65L7e3vEmIxWKmUPI7 wSY4KR+TEGfH3wz9D7vijXRHWGAllSyLM4tgguy1+PQU1HvmIlx6HGKZoq+c5u/ynZqQ bLJw== 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=oHHBXB7OiO4Q0/ZpersSkTeisz2ge4lrD5qNMR0qqNg=; fh=JcVaRa/YBYvL/5mVSXL3hVSuJ83USqvvjX/xV9Is+JY=; b=IjgI4wRu1loB6/BjziVvmnB845+YYAKce7WdxCqvP10S1+P7+nW0MDCLFfODWf6meu /Avs8jD78Zo8WeNtqRwTaIY2Fip4+GXnPzft/cwahamOIsE8RxtF/G2XHD5ETseADDiR 3irqOrrufg2a7mYR1PTePgp68YRILFij5NMkxw/RBYlKAKv7+lk7FacnCgH/AEabbell 1c0ErbkBdA1tGr9AJczfFgR918zh6wJGkZMPsDFSiKjTErL7EXJYMvz3Co0fUIgOI5Y/ Qlm7z9CEoPWoG2h40bHeyeBI0j5Xtcr6ONiex0HZJvRhi5hPHPDnLNBKA2WFvq1u+5V8 +TYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xWI2gTSu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id oo11-20020a17090b1c8b00b0026d4e16c957si1554169pjb.77.2023.09.18.10.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 10:58:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xWI2gTSu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 4B03781BFCE9; Mon, 18 Sep 2023 09:54:30 -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 S230498AbjIRQyK (ORCPT + 99 others); Mon, 18 Sep 2023 12:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbjIRQyH (ORCPT ); Mon, 18 Sep 2023 12:54:07 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AA9C94 for ; Mon, 18 Sep 2023 09:54:01 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-34fa117f92bso1755ab.1 for ; Mon, 18 Sep 2023 09:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695056041; x=1695660841; 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=oHHBXB7OiO4Q0/ZpersSkTeisz2ge4lrD5qNMR0qqNg=; b=xWI2gTSuw6ufOhOV6L0lK0d/4g1LxKHokKok+8TaFnCb3+6YgksntfSdbbaYPF6tQp pjAJqVC0chNyx3sBRUdeKgtHYNNySrmMDqKWQoaWBPpVPAPTC9jNzQ6b9Dg6JCoSocJP 58Zw/QgLcMSuqFxGj7S61OEhZJUU3hkqT6+flFgLGPlgP6b6hdtMM9P1gcq4+Hxlo5W1 d4qVoxC1rLxdwjZ7iAxSu8ap/77+CA33QUEzLSHfV4D+wC8wdZ97Ny/1d+X7eaTJ4iNu btyiRCmkOIbi1jMvOBfuHZVYlWYPjmurPSfv4Dte9qrHcd+RGWrNVced3v72+lH1LIVU SdAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695056041; x=1695660841; 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=oHHBXB7OiO4Q0/ZpersSkTeisz2ge4lrD5qNMR0qqNg=; b=cP9oKtEaP76XEzfrCfOe3DCrqgpaHPoMwiFfBo/qktGYVtDFOP5eanzXw+bocmoSk9 9w95qKnYos6fTZbxUmRJp6kOoXO/czZUTmOoGJ8Fh7BPLCbkiowMYaskVQ6e7nz4z9ow KiYyADXRRNcPIZ7Xk6JpbkOVP0H2vrCaquAi3xr0DCe544JWeUwFXyKFhJEJus3vyx/6 7Biy0nrMQrywo8y4Wi0/YaUu8dHQXrOm0lCqxgWPb5rtt1JV//G0rE7EikukHFFIj0Vp MjW6BpE4b0TI6Eb1704uhDsLsHBhfRrdwbR/15sIl9uw7wS1jOf5Jq7HFSL+dA2VbHz6 MuCA== X-Gm-Message-State: AOJu0YyLFJn+z5ubdqwot2VBTOTiNIE4Yd5aCtb/1d8A+zCkuMQc3Acb DsA2V91IJmBziwE42vSid851Qx0YWjaYDIaLX/cnQw== X-Received: by 2002:a05:6e02:1947:b0:34f:21e9:7239 with SMTP id x7-20020a056e02194700b0034f21e97239mr549614ilu.23.1695056040706; Mon, 18 Sep 2023 09:54:00 -0700 (PDT) MIME-Version: 1.0 References: <20230817003029.3073210-1-rananta@google.com> <20230817003029.3073210-6-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Mon, 18 Sep 2023 09:53:48 -0700 Message-ID: Subject: Re: [PATCH v5 05/12] KVM: arm64: PMU: Simplify extracting PMCR_EL0.N 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, Will Deacon , Mark Rutland 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 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]); Mon, 18 Sep 2023 09:54:30 -0700 (PDT) Hi Oliver, On Fri, Sep 15, 2023 at 12:56=E2=80=AFPM Oliver Upton wrote: > > +cc will, rutland > > Hi Raghu, > > Please make sure you cc the right folks for changes that poke multiple > subsystems. > > The diff looks OK, but I'm somewhat dubious of the need for this change > in the context of what you're trying to accomplish for KVM. I'd prefer > we either leave the existing definition/usage intact or rework *all* of > the PMUv3 masks to be of the shifted variety. > I believe the original intention was to make accessing the PMCR.N field simple. However, if you feel its redundant and is unnecessary for this series I'm happy to drop the patch. Thank you. Raghavendra > On Thu, Aug 17, 2023 at 12:30:22AM +0000, Raghavendra Rao Ananta wrote: > > From: Reiji Watanabe > > > > Some code extracts PMCR_EL0.N using ARMV8_PMU_PMCR_N_SHIFT and > > ARMV8_PMU_PMCR_N_MASK. Define ARMV8_PMU_PMCR_N (0x1f << 11), > > and simplify those codes using FIELD_GET() and/or ARMV8_PMU_PMCR_N. > > The following patches will also use these macros to extract PMCR_EL0.N. > > Changelog is a bit wordy: > > Define a shifted mask for accessing PMCR_EL0.N amenable to the use of > bitfield accessors and convert the existing, open-coded mask shifts to > the new definition. > > > No functional change intended. > > > > Signed-off-by: Reiji Watanabe > > Signed-off-by: Raghavendra Rao Ananta > > --- > > arch/arm64/kvm/pmu-emul.c | 3 +-- > > arch/arm64/kvm/sys_regs.c | 7 +++---- > > drivers/perf/arm_pmuv3.c | 3 +-- > > include/linux/perf/arm_pmuv3.h | 2 +- > > 4 files changed, 6 insertions(+), 9 deletions(-) > > > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > > index b87822024828a..f7b5fa16341ad 100644 > > --- a/arch/arm64/kvm/pmu-emul.c > > +++ b/arch/arm64/kvm/pmu-emul.c > > @@ -245,9 +245,8 @@ void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) > > > > u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu) > > { > > - u64 val =3D __vcpu_sys_reg(vcpu, PMCR_EL0) >> ARMV8_PMU_PMCR_N_SH= IFT; > > + u64 val =3D FIELD_GET(ARMV8_PMU_PMCR_N, __vcpu_sys_reg(vcpu, PMCR= _EL0)); > > > > - val &=3D ARMV8_PMU_PMCR_N_MASK; > > if (val =3D=3D 0) > > return BIT(ARMV8_PMU_CYCLE_IDX); > > else > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > > index 39e9248c935e7..30108f09e088b 100644 > > --- a/arch/arm64/kvm/sys_regs.c > > +++ b/arch/arm64/kvm/sys_regs.c > > @@ -750,7 +750,7 @@ static u64 reset_pmcr(struct kvm_vcpu *vcpu, const = struct sys_reg_desc *r) > > return 0; > > > > /* Only preserve PMCR_EL0.N, and reset the rest to 0 */ > > - pmcr =3D read_sysreg(pmcr_el0) & (ARMV8_PMU_PMCR_N_MASK << ARMV8_= PMU_PMCR_N_SHIFT); > > + pmcr =3D read_sysreg(pmcr_el0) & ARMV8_PMU_PMCR_N; > > if (!kvm_supports_32bit_el0()) > > pmcr |=3D ARMV8_PMU_PMCR_LC; > > > > @@ -858,10 +858,9 @@ static bool access_pmceid(struct kvm_vcpu *vcpu, s= truct sys_reg_params *p, > > > > static bool pmu_counter_idx_valid(struct kvm_vcpu *vcpu, u64 idx) > > { > > - u64 pmcr, val; > > + u64 val; > > > > - pmcr =3D __vcpu_sys_reg(vcpu, PMCR_EL0); > > - val =3D (pmcr >> ARMV8_PMU_PMCR_N_SHIFT) & ARMV8_PMU_PMCR_N_MASK; > > + val =3D FIELD_GET(ARMV8_PMU_PMCR_N, __vcpu_sys_reg(vcpu, PMCR_EL0= )); > > if (idx >=3D val && idx !=3D ARMV8_PMU_CYCLE_IDX) { > > kvm_inject_undefined(vcpu); > > return false; > > diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c > > index 08b3a1bf0ef62..7618b0adc0b8c 100644 > > --- a/drivers/perf/arm_pmuv3.c > > +++ b/drivers/perf/arm_pmuv3.c > > @@ -1128,8 +1128,7 @@ static void __armv8pmu_probe_pmu(void *info) > > probe->present =3D true; > > > > /* Read the nb of CNTx counters supported from PMNC */ > > - cpu_pmu->num_events =3D (armv8pmu_pmcr_read() >> ARMV8_PMU_PMCR_N= _SHIFT) > > - & ARMV8_PMU_PMCR_N_MASK; > > + cpu_pmu->num_events =3D FIELD_GET(ARMV8_PMU_PMCR_N, armv8pmu_pmcr= _read()); > > > > /* Add the CPU cycles counter */ > > cpu_pmu->num_events +=3D 1; > > diff --git a/include/linux/perf/arm_pmuv3.h b/include/linux/perf/arm_pm= uv3.h > > index e3899bd77f5cc..ecbcf3f93560c 100644 > > --- a/include/linux/perf/arm_pmuv3.h > > +++ b/include/linux/perf/arm_pmuv3.h > > @@ -216,7 +216,7 @@ > > #define ARMV8_PMU_PMCR_LC (1 << 6) /* Overflow on 64 bit cycle coun= ter */ > > #define ARMV8_PMU_PMCR_LP (1 << 7) /* Long event counter enable */ > > #define ARMV8_PMU_PMCR_N_SHIFT 11 /* Number of counters support= ed */ > > -#define ARMV8_PMU_PMCR_N_MASK 0x1f > > +#define ARMV8_PMU_PMCR_N (0x1f << ARMV8_PMU_PMCR_N_SHIFT) > > #define ARMV8_PMU_PMCR_MASK 0xff /* Mask for writable bits */ > > > > /* > > -- > > 2.41.0.694.ge786442a9b-goog > > > > > > -- > Thanks, > Oliver