From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7AD6C433FE for ; Mon, 14 Nov 2022 00:51:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D5AEC8516F; Mon, 14 Nov 2022 01:51:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=andestech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id D356284D45; Mon, 14 Nov 2022 01:51:27 +0100 (CET) Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D8F9485170 for ; Mon, 14 Nov 2022 01:51:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=andestech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peterlin@andestech.com Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 2AE0pCaH024395; Mon, 14 Nov 2022 08:51:12 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from APC323 (10.0.12.98) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Mon, 14 Nov 2022 08:51:11 +0800 Date: Mon, 14 Nov 2022 08:48:18 +0000 From: Yu-Chien Peter Lin To: Samuel Holland CC: Subject: Re: [PATCH v2] riscv: Fix detecting FPU support in standard extension Message-ID: References: <20221105060214.2526-1-peterlin@andestech.com> <9377cc11-9c47-ed7e-a439-0464b792b93c@sholland.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <9377cc11-9c47-ed7e-a439-0464b792b93c@sholland.org> User-Agent: Mutt/2.2.6 (2022-06-05) X-Originating-IP: [10.0.12.98] X-DNSRBL: X-MAIL: Atcsqr.andestech.com 2AE0pCaH024395 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On Sun, Nov 13, 2022 at 03:47:38PM -0600, Samuel Holland wrote: > On 11/5/22 01:02, Yu Chien Peter Lin wrote: > > We should check the string until it hits underscore, in case it > > searches for the letters in the custom extension. For example, > > "rv64imac_xandes" will be treated as D extension support since > > there is a "d" in "andes", resulting illegal instruction caused > > by initializing FCSR. > > > > Signed-off-by: Yu Chien Peter Lin > > --- > > arch/riscv/cpu/cpu.c | 14 +++++++++++--- > > 1 file changed, 11 insertions(+), 3 deletions(-) > > > > diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c > > index 52ab02519f..d34c8efce0 100644 > > --- a/arch/riscv/cpu/cpu.c > > +++ b/arch/riscv/cpu/cpu.c > > @@ -36,6 +36,7 @@ static inline bool supports_extension(char ext) > > #ifdef CONFIG_CPU > > struct udevice *dev; > > char desc[32]; > > + int i; > > > > uclass_find_first_device(UCLASS_CPU, &dev); > > if (!dev) { > > @@ -43,9 +44,16 @@ static inline bool supports_extension(char ext) > > return false; > > } > > if (!cpu_get_desc(dev, desc, sizeof(desc))) { > > - /* skip the first 4 characters (rv32|rv64) */ > > - if (strchr(desc + 4, ext)) > > - return true; > > + /* > > + * skip the first 4 characters (rv32|rv64) and > > + * check until underscore > > + */ > > This probably works for the intended usage, but it is not guaranteed to > work. Underscores are allowed even between single-letter extensions. See > section 29.5 ("Underscores") of the unprivileged spec. Still, this is an > improvement, so: > > Reviewed-by: Samuel Holland Aah, I missed that case. I supposed the strings always match the pattern stated in riscv cpus binding [1], the detection logic here needs to be updated once the case is also allowed. [1] https://github.com/torvalds/linux/blob/v6.1-rc5/Documentation/devicetree/bindings/riscv/cpus.yaml#L83 Thanks for your review! Best regards, Peter Lin > > > + for (i = 4; i < sizeof(desc); i++) { > > + if (desc[i] == '_' || desc[i] == '\0') > > + break; > > + if (desc[i] == ext) > > + return true; > > + } > > } > > > > return false; >