Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6884801rwr; Tue, 25 Apr 2023 05:25:19 -0700 (PDT) X-Google-Smtp-Source: AKy350bCylpdrQNZZdR2ZZLNuu+36zyrpHmYOGLiJKz+0MB8okrYjTQUwEjCJc9spW7wSt6HR/kM X-Received: by 2002:a17:90a:2904:b0:246:75c8:f071 with SMTP id g4-20020a17090a290400b0024675c8f071mr17432714pjd.3.1682425519296; Tue, 25 Apr 2023 05:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682425519; cv=none; d=google.com; s=arc-20160816; b=fkxdQ8o3JQwYamF1N5Plo8MFJAapiVNY0KEFFh98vP5/L3skqb010mAXHAbkIgZQUY DWX6ClSKCQzzbAhsuPblbNxfHs9zlU/Iq0HGcLtBheVBOzB/5u/j5i6THorrN6rHeLVQ FboSop88rULQkq6F0pU0c/ny9jbl9sv7Sp5eP5u5uuIBy17KzM0VaEJs6lEPbhZQc6FQ p1pQzKXqvp0IQ1HTn4kqgw1xW2WiUW6e14VjOufhr2SOv40orJe5JQCMeyw1knrcSqGi J5ph45pIZtPJ6aL55ds6kEOCFFFs44CCV06DTA4v75AT2SAr6Cj7FnkbsptBirHYGbDG KGWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:date :subject:cc:to:from:message-id:dkim-signature; bh=meMe2T6KKbX+l3+HBOMKvPki3tbvHHhySN0Qss7JmnY=; b=CkJwM675r5se++b2uGgT+wPfIH19fepeEEFZPaUZ6oX0dJbG0aFotWoCGX+iYNRSOa fD+ZiX2bPRZIpW4m0qZBm42MCf/RDtfT+Tt9GJh6Hldgv1Hgk/1PemZzw01ua9v+htvt 2vLDW13km7tQIXP7q2HFKDwv8eGcgCO2neM2tMLNqCyME6AipsPaEicpXBvfgzHs1b4Z t0o5kT/+zCPNCRByvarV884UQ9lyzxVe9ddsrwsEUpc71QcHkpqT2yv+AsCeFCt3aNBK Psq/g9/q+kbg2wxR8Cb/nUgQUyzRVm6f9Os9JS9qXy3t/83BhQZWUVT01zyU5MPnalwK QMGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=A+4faKHU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x14-20020a17090abc8e00b002474101aa7esi13836475pjr.163.2023.04.25.05.25.07; Tue, 25 Apr 2023 05:25:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=A+4faKHU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233801AbjDYMBL (ORCPT + 99 others); Tue, 25 Apr 2023 08:01:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233308AbjDYMBH (ORCPT ); Tue, 25 Apr 2023 08:01:07 -0400 Received: from out162-62-57-137.mail.qq.com (out162-62-57-137.mail.qq.com [162.62.57.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09B4110F3 for ; Tue, 25 Apr 2023 05:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1682424049; bh=meMe2T6KKbX+l3+HBOMKvPki3tbvHHhySN0Qss7JmnY=; h=From:To:Cc:Subject:Date; b=A+4faKHURxUGtMw3r+rPlgzNJjnDWniodlm/n136XHJVmdzEKCPaiKbgmwSXH+B9j r0YYm+b0VWcR8Ant6LppLxgNoYJlIAGUYa5v5IjPAA9sm7a4GxxjMDb13r9/dN372T UjPBaxGvFKoFdcSuCZybxUpYPmT0v1HtsRhxoGpw= Received: from cyy-pc.lan ([2001:da8:c800:d084:c65a:644a:13d7:e72c]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 1235043; Tue, 25 Apr 2023 20:00:18 +0800 X-QQ-mid: xmsmtpt1682424018txcilf7bg Message-ID: X-QQ-XMAILINFO: MmpliBmRb3iCj/22F3Hkzg44Cma8g01zlNRT4DRJwi4CfhvQ5DYbNHtDz9LzPC mnwGEhmCouvCVQvGtB0o9RBIZ2mqU7tJVVkrmdBy9jZfSCT0wAI3Htz7WCF005Xwr1S/QO2qDUJs nlT3WXhuaV06q4Ag9f5yRvF2WIPkwXW24IZXF8Jvw1eTk7fgWDAthhZ8BVzCl1uilaad7w7w8L7h Mgxh4x+F7nvNVwsgB1tOKneigLiV0J/jxGUQ/O6td/k+Gnev/yUnh3hDNiGaXeW6inDu2uvmGelv HC1OkyBYHkabv9HJNP/4TZ2b4GBSlGQm1gK19LlimUp4lfVJyrV0NBk2eNPxgk/Bp+v2OTOLk5zM WcOJC8j5TolnmjXyu2OB46Lt6WtGIVn5uV/xdfv+eqem9PAl4FWPy2/zYJIhNhJCOtobs01F4HFJ c4ulEpwErguY3goPnfQYXTqFd1WtPm8794KUig73wkVCPKUwHmaXv3i8O3QrWqmzjqyZdK3YOXji CpbGQPGLqjH3bvpQ5Rvmhis6wM2KM6OpUpySopq590lNv5YOPyPnSve28F/MqMoGc5b/IIBzRsrI jpIHsHJmPN7POteRvPRREOQAJlwF4o9JN16aUycfO7kXGJ7WklbcavLifNv8g3k35TldJtuGugMc UXthK+w4gJp40TF5n0+Mh+xUBAgcHpPLpKwy9ccHWbFYz7bK9IG+nrmzJuQ9FA3FWIzEF/r7JBcq KL/NsfRE0jfZ3i7HAYwduBPWx+8hfVIHehBtANGV2gfNnbXFaYH0hQHiKwXJkw84IN1r652A3Hnn 8CqbgVuAH/QM45Hlw1dIBEKOnwt+0ux2G3kWhEs5rdVNTtZAZb2fcyzNfP6MMmdMpECdhhEspFoV p6PRkVRn1yE4XVy1E/nlco3j1keqBTv097uIJsZ+emDz0Co3jeN0dQoU3Fs4b55cEDuiRX2G70mC 3mJBDy7Ip/+HyGV2rPTSuljU5Us7IUFnRWe/CGqoWB88a+CGSOb5EBjyR6vS5VK8JCO23M35whVF rSdLPX+Qx13F+clTxuYeDJyiAMT88= From: Yangyu Chen To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Wende Tan , Soha Jin , Hongren Zheng , Yangyu Chen Subject: [PATCH 0/2] Allow case-insensitive RISC-V ISA string Date: Tue, 25 Apr 2023 20:00:14 +0800 X-OQ-MSGID: <20230425120016.187010-1-cyy@cyyself.name> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, RDNS_DYNAMIC,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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 According to RISC-V ISA specification, the ISA naming strings are case insensitive. The kernel docs require the riscv,isa string must be all lowercase to simplify parsing currently. However, this limitation is not consistent with RISC-V ISA Spec. The motivation for this patch series is that some SoC generators will provide ISA strings with uppercase letters in the device tree. For example, the rocket-chip will have "Zicsr_Zifencei_Zihpm_Xrocket" in the ISA string. If we did not modify the ISA string manually, the parser in the current kernel will have errors when the pointer meets uppercase letters because it assumes the string only has digits, lowercase letters, and underscores. Then, the parser will fail and the pointer of the parser will continue at the next position, which will confuse the parser and cause the kernel to misbehave. For example, "Zifencei" will be parsed as "ifc" since the parser will fail at 'Z' and then continue at 'i'. Then, if we disable the FPU in the CPU hardware and remove the "fd" from the device tree but leave the CONFIG_FPU=y in the kernel, the kernel will panic at `__fstate_restore` function since the "Zifencei" (parsed as "ifc") will confuse the current kernel that the CPU has "f", and the kernel will save and restore the FPU registers during the context switch, leading to illegal instruction exceptions. However, it is not necessary to require the ISA string must be all lowercase. The case-insensitive parser can be easily implemented using `strncasecmp` and `tolower` functions. Moreover, the kernel parser implementation should match the ISA specification rather than using a more strict rule. This patch series allows case-insensitive RISC-V ISA string: * Patch 1 modifies the ISA string parser in the kernel to support case-insensitive ISA string parsing. It replaces `strncmp` with `strncasecmp`, replaces `islower` with `isalpha`, and wraps the dereferenced char in the parser with `tolower`. * Patch 2 modifies the docs to no longer require the riscv,isa string to be all lowercase. Yangyu Chen (2): riscv: allow case-insensitive ISA string parsing docs: dt: allow case-insensitive RISC-V ISA string .../devicetree/bindings/riscv/cpus.yaml | 7 +++---- arch/riscv/kernel/cpu.c | 6 ++++-- arch/riscv/kernel/cpufeature.c | 20 +++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) -- 2.40.0