Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp31345lqb; Tue, 16 Apr 2024 08:03:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWP5rLyfAjyj1uTo+oZDyOtLtTzeGtmeZ1cc9kMow+5LJik8eulwBdq0TEV/verakP7Jxd3jCI4uUqxs90RTcUrxKkiC6fQRlY8iInWFQ== X-Google-Smtp-Source: AGHT+IH15BoMQ3PJwETvnSDIqDN/G8xv6wR04VBIvMkzHMXFRpvwsQkarAkgKjmYM1bxInuIanHX X-Received: by 2002:a17:906:1c05:b0:a52:182b:dee9 with SMTP id k5-20020a1709061c0500b00a52182bdee9mr1641037ejg.35.1713279817664; Tue, 16 Apr 2024 08:03:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713279817; cv=pass; d=google.com; s=arc-20160816; b=CbAm9se7uFh/wzZ2OIeB6qhZEg1SOe0o8R0s+3EkX/XMsGfBiwGj9K2/JdkUSRK0tu TfYfZ9jvr2VacEjeTOzXKHWmEFUI0J/4eoCVmMRlOcQnC0HXKKCtGWU3PSmIb1+FV+lc AxF2H0nudoVmJfN5HVs9m/qVPRuEhkwoFYNjb8Odb2t8xMI+d6t8p+43vx+Iv0l0KF6U sEwzFJurwvSfqp5bkN0qWNE9mOWL9F2G+LehXRP/u7b+Iqrdu0Iu5UsMxN5+EP0HeW7Q /mfLutla2kqk8UvlAEKKFmv3xl8Fv+jIXvSUaJhak4CVkZF5WsQD1WwOl+PdDMJRQj8t uGtw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=MUeFtUxDF8ootxxgCsC9c9UHAxanWMtTcKtndAlCY+8=; fh=mBwwpQbay9vhzTgPULjjDn+LkmwbaBeNVRczdYQ/Av4=; b=PXkY3lPcISBSN5a62cFg0OHnd9NglQ8RddtsyB78wxGBule2t7cjK25Up/7w6cd82N U/ykeQ2BFTNUB3BM72oqrSMJjDggYrQS1Xeerk5Qe/Jg64doC6OluS3LyYCxoYRgzNSy Q8obcYeWhMcePcaKIjSWWeglTi5ES4DVaQOG4ZdagGpcY1LhaJz/inLMiQiatWVbmZLT +B9ba1c7X3lC7gcMonaU1OwRzzRKF/nuqUyD78rsHy6fvRgvZqKdZMbWwWZY7x/KgeDl L3btGK/Xi6eEdzKH3MzIaDMMjSNzHA7tTQ3X5yELcri1ap/PTJg9GjDDyUBqwtu3YZEN NF9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d1EqWvM4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-147086-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147086-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id nb17-20020a1709071c9100b00a46a9425fd0si5793274ejc.627.2024.04.16.08.03.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 08:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147086-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d1EqWvM4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-147086-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147086-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3B71D1F21C5E for ; Tue, 16 Apr 2024 15:03:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3DCB13048F; Tue, 16 Apr 2024 15:03:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d1EqWvM4" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF9B212C47A; Tue, 16 Apr 2024 15:03:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713279808; cv=none; b=KPNA/zk5UcfMaSaPnr8cB/Np2gpqC9pvjstoJ9nFmgcg9c/ROw+QpjrwmfjDkjHk8zw5csA+gJFawI5xfxdeTTyOReBKqyhOUAnMbMSeGUkBLJayk/qUNrxQSHC2YFHsZEzXk5F/zN2dlAeiaPpgqHea3IZ8zKsFq/3OSLU2gA4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713279808; c=relaxed/simple; bh=0dFehR7bAofXvwdhbQHUWpVwxNS4jlbytNrjxajS/Pg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hs5MoXZHwUfWUwQj15pwRco7LA3j6dTuBf5CqMZ9YERMPKwc//W3NFqHf8SJ3L0WPOvI4zCxKisHt2fVQK3K51iU+6weopSu3AsEhVirFte9CzpgrJEKp1O9LThMk757OCHESk3Z3K3SH7/93aqsqUk+DGcwyzu1bJGtnB5qcWw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d1EqWvM4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBA14C113CE; Tue, 16 Apr 2024 15:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713279807; bh=0dFehR7bAofXvwdhbQHUWpVwxNS4jlbytNrjxajS/Pg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=d1EqWvM4R01QG++RsWmY7K55v0olQvvgXIenexsbrc4JKA4nwVfDNHbXnpJ2hODiu uKXP42Z5t3X8ceOGrFIX++T91LRgNZrljeuacqKst+uLTaMHaV99gERfLC1bHjBbod uCrU9jKaCvpAs4YTPg8bY4yfClF1wx8tsQqjMthQc5BA0EToSY6K1fPSqef/N+PSro ozaY5pPAqJBmIuxx6sHAeyRk60Mr9DyVOlmvpu+y3z4jVI9aHvcO3wiChQu9vPek6+ ANtnjbfUJ/4nZQqhFLpPwXnHN61iI1y9UYuY2KOIzVPTHSIbTmXWfY9vUYJGk1R2cL GwKYqAUJQnPDg== Date: Tue, 16 Apr 2024 16:03:20 +0100 From: Conor Dooley To: Charlie Jenkins Cc: Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Conor Dooley , Evan Green , =?iso-8859-1?Q?Cl=E9ment_L=E9ger?= , Jonathan Corbet , Shuah Khan , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 01/17] riscv: cpufeature: Fix thead vector hwcap removal Message-ID: <20240416-swipe-flattered-7cdccc01f0fe@spud> References: <20240415-dev-charlie-support_thead_vector_6_9-v2-0-c7d68c603268@rivosinc.com> <20240415-dev-charlie-support_thead_vector_6_9-v2-1-c7d68c603268@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="RbQjJEERG41bUbGr" Content-Disposition: inline In-Reply-To: <20240415-dev-charlie-support_thead_vector_6_9-v2-1-c7d68c603268@rivosinc.com> --RbQjJEERG41bUbGr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 15, 2024 at 09:11:58PM -0700, Charlie Jenkins wrote: > The riscv_cpuinfo struct that contains mvendorid and marchid is not > populated until all harts are booted which happens after the DT parsing. > Use the vendorid/archid values from the DT if available or assume all > harts have the same values as the boot hart as a fallback. >=20 > Fixes: d82f32202e0d ("RISC-V: Ignore V from the riscv,isa DT property on = older T-Head CPUs") > Signed-off-by: Charlie Jenkins > --- > arch/riscv/include/asm/sbi.h | 2 ++ > arch/riscv/kernel/cpu.c | 36 ++++++++++++++++++++++++++++++++---- > arch/riscv/kernel/cpufeature.c | 12 ++++++++++-- > 3 files changed, 44 insertions(+), 6 deletions(-) >=20 > diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h > index 6e68f8dff76b..0fab508a65b3 100644 > --- a/arch/riscv/include/asm/sbi.h > +++ b/arch/riscv/include/asm/sbi.h > @@ -370,6 +370,8 @@ static inline int sbi_remote_fence_i(const struct cpu= mask *cpu_mask) { return -1 > static inline void sbi_init(void) {} > #endif /* CONFIG_RISCV_SBI */ > =20 > +unsigned long riscv_get_mvendorid(void); > +unsigned long riscv_get_marchid(void); > unsigned long riscv_cached_mvendorid(unsigned int cpu_id); > unsigned long riscv_cached_marchid(unsigned int cpu_id); > unsigned long riscv_cached_mimpid(unsigned int cpu_id); > diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c > index d11d6320fb0d..8c8250b98752 100644 > --- a/arch/riscv/kernel/cpu.c > +++ b/arch/riscv/kernel/cpu.c > @@ -139,6 +139,34 @@ int riscv_of_parent_hartid(struct device_node *node,= unsigned long *hartid) > return -1; > } > =20 > +unsigned long __init riscv_get_marchid(void) > +{ > + struct riscv_cpuinfo *ci =3D this_cpu_ptr(&riscv_cpuinfo); > + > +#if IS_ENABLED(CONFIG_RISCV_SBI) > + ci->marchid =3D sbi_spec_is_0_1() ? 0 : sbi_get_marchid(); > +#elif IS_ENABLED(CONFIG_RISCV_M_MODE) > + ci->marchid =3D csr_read(CSR_MARCHID); > +#else > + ci->marchid =3D 0; > +#endif > + return ci->marchid; > +} > + > +unsigned long __init riscv_get_mvendorid(void) > +{ > + struct riscv_cpuinfo *ci =3D this_cpu_ptr(&riscv_cpuinfo); > + > +#if IS_ENABLED(CONFIG_RISCV_SBI) > + ci->mvendorid =3D sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid(); > +#elif IS_ENABLED(CONFIG_RISCV_M_MODE) > + ci->mvendorid =3D csr_read(CSR_MVENDORID); > +#else > + ci->mvendorid =3D 0; > +#endif > + return ci->mvendorid; > +} > + > DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); > =20 > unsigned long riscv_cached_mvendorid(unsigned int cpu_id) > @@ -170,12 +198,12 @@ static int riscv_cpuinfo_starting(unsigned int cpu) > struct riscv_cpuinfo *ci =3D this_cpu_ptr(&riscv_cpuinfo); > =20 > #if IS_ENABLED(CONFIG_RISCV_SBI) > - ci->mvendorid =3D sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid(); > - ci->marchid =3D sbi_spec_is_0_1() ? 0 : sbi_get_marchid(); > + ci->mvendorid =3D ci->mvendorid ? ci->mvendorid : sbi_spec_is_0_1() ? 0= : sbi_get_mvendorid(); > + ci->marchid =3D ci->marchid ? ci->marchid : sbi_spec_is_0_1() ? 0 : sbi= _get_marchid(); Can we please not have double ternary stuff? This is awful to grok :( Can you do if (!ci->m*id) sbi_spec_is_0_1() ? 0 : sbi_get_m*id(); instead? I think that is much easier to understand. Otherwise, Reviewed-by: Conor Dooley Cheers, Conor. > ci->mimpid =3D sbi_spec_is_0_1() ? 0 : sbi_get_mimpid(); > #elif IS_ENABLED(CONFIG_RISCV_M_MODE) > - ci->mvendorid =3D csr_read(CSR_MVENDORID); > - ci->marchid =3D csr_read(CSR_MARCHID); > + ci->mvendorid =3D ci->mvendorid ? ci->mvendorid : csr_read(CSR_MVENDORI= D); > + ci->marchid =3D ci->marchid ? ci->marchid : csr_read(CSR_MARCHID); > ci->mimpid =3D csr_read(CSR_MIMPID); > #else > ci->mvendorid =3D 0; > diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeatur= e.c > index 3ed2359eae35..c6e27b45e192 100644 > --- a/arch/riscv/kernel/cpufeature.c > +++ b/arch/riscv/kernel/cpufeature.c > @@ -490,6 +490,8 @@ static void __init riscv_fill_hwcap_from_isa_string(u= nsigned long *isa2hwcap) > struct acpi_table_header *rhct; > acpi_status status; > unsigned int cpu; > + u64 boot_vendorid; > + u64 boot_archid; > =20 > if (!acpi_disabled) { > status =3D acpi_get_table(ACPI_SIG_RHCT, 0, &rhct); > @@ -497,6 +499,13 @@ static void __init riscv_fill_hwcap_from_isa_string(= unsigned long *isa2hwcap) > return; > } > =20 > + /* > + * Naively assume that all harts have the same mvendorid/marchid as the > + * boot hart. > + */ > + boot_vendorid =3D riscv_get_mvendorid(); > + boot_archid =3D riscv_get_marchid(); > + > for_each_possible_cpu(cpu) { > struct riscv_isainfo *isainfo =3D &hart_isa[cpu]; > unsigned long this_hwcap =3D 0; > @@ -544,8 +553,7 @@ static void __init riscv_fill_hwcap_from_isa_string(u= nsigned long *isa2hwcap) > * CPU cores with the ratified spec will contain non-zero > * marchid. > */ > - if (acpi_disabled && riscv_cached_mvendorid(cpu) =3D=3D THEAD_VENDOR_I= D && > - riscv_cached_marchid(cpu) =3D=3D 0x0) { > + if (acpi_disabled && boot_vendorid =3D=3D THEAD_VENDOR_ID && boot_arch= id =3D=3D 0x0) { > this_hwcap &=3D ~isa2hwcap[RISCV_ISA_EXT_v]; > clear_bit(RISCV_ISA_EXT_v, isainfo->isa); > } >=20 > --=20 > 2.44.0 >=20 --RbQjJEERG41bUbGr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZh6TOAAKCRB4tDGHoIJi 0ugHAP9wq53A/rRMZA7YNcwk3t+YkspiOROzoX/lB6mQceQcywEA6kOQ31DLs19U K7NuAGuzzBkZ9AZreTReZw47pw/tXwo= =YaUr -----END PGP SIGNATURE----- --RbQjJEERG41bUbGr--