From patchwork Thu Feb 10 21:40:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 541550 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CCB4C433FE for ; Thu, 10 Feb 2022 21:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344742AbiBJVkg (ORCPT ); Thu, 10 Feb 2022 16:40:36 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344718AbiBJVkd (ORCPT ); Thu, 10 Feb 2022 16:40:33 -0500 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3795EBBC for ; Thu, 10 Feb 2022 13:40:34 -0800 (PST) Received: by mail-oi1-x235.google.com with SMTP id r27so7492841oiw.4 for ; Thu, 10 Feb 2022 13:40:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gfak+qx3drveGV1Pvkzt57Jl+W0jEgrAmoVtloDMaBw=; b=b5WIG4HsEF5Iod1jlBRBnYuxQFaXxoMA8iP1rJdZ9dXaGNSGjPXSPmZnGU7z+N98i3 PFUIm+xNgTyD24P1KmltetZbCHaWJt9LqJEf5KV+Rq949EsJphUQp5Q+jf2tZt7Qy7c2 Zt9J61HUTUscpV0smpFM2mhfbNXsZxcRZ828cU4AB7GvTUvUHmVhPml1mkHo4ptzYRRB o2+8U3fQcZMV6Mjj4RR8QjhftLH50cjfmPJgOWDqPVNlM1Ri2IQ6mTlaEx+U0p0RgBOn UlGy3tsfSb1cSMykpj9Vgdw6vDPziX7U52avE88Xpuwl3zSPHr9RwkywA8TqDnBQxfFl PYcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gfak+qx3drveGV1Pvkzt57Jl+W0jEgrAmoVtloDMaBw=; b=0eT2bXAEZi8M77Uo+I3rl9EWfdEla7NX1D61tw00+Byee2jbX64XZsUvauZGDdbiDq FKuVjsSwUY8TrCSAgfj8QNMd0/yAtSCoGT/TIM15Fvrrpm3wxJdXTEu2+Q5BRLJsuGbY tJX75psOfDXXOAD5NioncRT4QY7SbyE9yhjgOe0130fqNZ9ZRubqYSkTUz4E8bdrkcyj EMSEnfeiPF1OmcPbQM4CQVTm7pnTEdR/6WHhvGFs5OkvSVSwFcJqmv2hMJ+NuqLqZ68a BCG+MypCijKk9TiWxnJygXIng8QL7G/LD/gth0vkRRjozu/36vPSZieC0UHyCCGKVXBb YzUQ== X-Gm-Message-State: AOAM533ohIYA6DiOlHAiBKBP8/vAKWAZc6nMnGrFg+IEXw4zAyoM8mNo dNjpzHDjHX10BFPEStGJfVh4gg== X-Google-Smtp-Source: ABdhPJykAnYvG8sqBibAI7XjH1k9J0mAOKTMUjlZygKx4hyhEIURQ1Wi20CpxOC5ed/s+MjwLZlz4g== X-Received: by 2002:a05:6808:229f:: with SMTP id bo31mr1819283oib.107.1644529233614; Thu, 10 Feb 2022 13:40:33 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id u5sm8700000ooo.46.2022.02.10.13.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:40:33 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Tsukasa OI , Atish Patra , Albert Ou , Atish Patra , Anup Patel , Damien Le Moal , devicetree@vger.kernel.org, Jisheng Zhang , Krzysztof Kozlowski , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring Subject: [PATCH v2 3/6] RISC-V: Extract multi-letter extension names from "riscv,isa" Date: Thu, 10 Feb 2022 13:40:15 -0800 Message-Id: <20220210214018.55739-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210214018.55739-1-atishp@rivosinc.com> References: <20220210214018.55739-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Tsukasa OI Currently, there is no usage for version numbers in extensions as any ratified non base ISA extension will always at v1.0. Extract the extension names in place for future parsing. Signed-off-by: Tsukasa OI [Improved commit text and comments] Signed-off-by: Atish Patra --- arch/riscv/kernel/cpufeature.c | 41 +++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index e19ae4391a9b..e9e3b0693d16 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -102,6 +102,7 @@ void __init riscv_fill_hwcap(void) #endif for (; *isa; ++isa) { const char *ext = isa++; + const char *ext_end = isa; bool ext_long, ext_err = false; switch (*ext) { @@ -119,19 +120,39 @@ void __init riscv_fill_hwcap(void) ext_long = true; /* Multi-letter extension must be delimited */ for (; *isa && *isa != '_'; ++isa) - if (!islower(*isa) && !isdigit(*isa)) + if (unlikely(!islower(*isa) + && !isdigit(*isa))) ext_err = true; - /* ... but must be ignored. */ + /* Parse backwards */ + ext_end = isa; + if (unlikely(ext_err)) + break; + if (!isdigit(ext_end[-1])) + break; + /* Skip the minor version */ + while (isdigit(*--ext_end)) + ; + if (ext_end[0] != 'p' + || !isdigit(ext_end[-1])) { + /* Advance it to offset the pre-decrement */ + ++ext_end; + break; + } + /* Skip the major version */ + while (isdigit(*--ext_end)) + ; + ++ext_end; break; default: ext_long = false; - if (!islower(*ext)) { + if (unlikely(!islower(*ext))) { ext_err = true; break; } /* Find next extension */ if (!isdigit(*isa)) break; + /* Skip the minor version */ while (isdigit(*++isa)) ; if (*isa != 'p') @@ -140,20 +161,20 @@ void __init riscv_fill_hwcap(void) --isa; break; } + /* Skip the major version */ while (isdigit(*++isa)) ; break; } if (*isa != '_') --isa; - /* - * TODO: Full version-aware handling including - * multi-letter extensions will be added in-future. - */ - if (ext_err || ext_long) + + if (unlikely(ext_err)) continue; - this_hwcap |= isa2hwcap[(unsigned char)(*ext)]; - this_isa |= (1UL << (*ext - 'a')); + if (!ext_long) { + this_hwcap |= isa2hwcap[(unsigned char)(*ext)]; + this_isa |= (1UL << (*ext - 'a')); + } } /* From patchwork Thu Feb 10 21:40:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 541549 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8858EC433FE for ; Thu, 10 Feb 2022 21:40:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344743AbiBJVkq (ORCPT ); Thu, 10 Feb 2022 16:40:46 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344699AbiBJVkh (ORCPT ); Thu, 10 Feb 2022 16:40:37 -0500 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89F5426C2 for ; Thu, 10 Feb 2022 13:40:37 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id x193so7554598oix.0 for ; Thu, 10 Feb 2022 13:40:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3nB7qzXaFNatnaTZQJRAInnjQf9KiqCTDZAFaYuusV0=; b=L+ZGFYNRoNLbHVhM3KhtWzMWcXEDYyJA7aw1jmcFUNm9LwjalIvnug5gAOBoaVsGAi XAfgYWak1dxQzZ5ghazPUUea8fGTUL4XYyIyS3b6NW+CmQgYLVmzlmTGPyvdu36ntJE9 p/WWwPx2fjkcKd0nUagR9y6sxwOG6zjfJTQ/wWjLi9u+NSP/xV0hSdCGSkoc8CSEy4Zh Xfmpchix/fMksPHav7pOiVse8m4TiWBP74rJVn9fBN60F/vQOUJa2ip5dMXv/LouxZAc odHYF6dZ+iuK1KlWP32f8JPsVtkzl9VjkswCDQuIxLTMaPXm3Tnh3rK4m5SBJ5wSZl2Y E93g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3nB7qzXaFNatnaTZQJRAInnjQf9KiqCTDZAFaYuusV0=; b=FZVSjH0f4VmoyakyT3Of8/QEPZfqp+oomfnmQ+hLZOx2v0+59K3wmSYtnAgGeyNZeG GGPnsaOtzWCvmT3naJLmO+MWPAKNjK0nwfWUWn75cXcsWEvP/rE8oyLp58eEhr3M3NCh 7bjyKtoXCrpOTB3XF7ewYxUc5oHVlObogQoULo5o82p4QHXaqhPTaKgur3AX/etEi/YX Q85S6wwrFQBD3Fv2T6KfVuW+BvcwO9+BM4SDee2199DG9mf/qmKZMgyhNbG2pHg3gIv0 UtquUVMDEyJKbtzBbk2XCTK9Gl3RrQ6uh2L/lAiiUbVMbpBUT3g0aWahvq9a8n2Po+P2 c7Cg== X-Gm-Message-State: AOAM530n6WvLRR3R2njcwngbFgZhszorlJ6Edt7fh3QF/x77z3g3zw0Q YalaVL2CnVEXnQaK+LkRZI3Ceg== X-Google-Smtp-Source: ABdhPJxnj59RepTjd/uznzgrpDdO30O9r7af3cgqYy9BVCSUocaHEleDWBfL7GJ76jB38zMSSwzmAQ== X-Received: by 2002:a05:6808:11ca:: with SMTP id p10mr1942733oiv.74.1644529236740; Thu, 10 Feb 2022 13:40:36 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id u5sm8700000ooo.46.2022.02.10.13.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:40:36 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Atish Patra , Anup Patel , Damien Le Moal , devicetree@vger.kernel.org, Jisheng Zhang , Krzysztof Kozlowski , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring Subject: [PATCH v2 5/6] RISC-V: Do no continue isa string parsing without correct XLEN Date: Thu, 10 Feb 2022 13:40:17 -0800 Message-Id: <20220210214018.55739-6-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210214018.55739-1-atishp@rivosinc.com> References: <20220210214018.55739-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The isa string should begin with either rv64 or rv32. Otherwise, it is an incorrect isa string. Currently, the string parsing continues even if it doesnot begin with current XLEN. Fix this by checking if it found "rv64" or "rv32" in the beginning. Signed-off-by: Atish Patra --- arch/riscv/kernel/cpufeature.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 469b9739faf7..cca579bae8a0 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -84,6 +84,7 @@ void __init riscv_fill_hwcap(void) for_each_of_cpu_node(node) { unsigned long this_hwcap = 0; uint64_t this_isa = 0; + char *temp; if (riscv_of_processor_hartid(node) < 0) continue; @@ -93,6 +94,7 @@ void __init riscv_fill_hwcap(void) continue; } + temp = (char *)isa; #if IS_ENABLED(CONFIG_32BIT) if (!strncmp(isa, "rv32", 4)) isa += 4; @@ -100,6 +102,9 @@ void __init riscv_fill_hwcap(void) if (!strncmp(isa, "rv64", 4)) isa += 4; #endif + /* The riscv,isa DT property must start with rv64 or rv32 */ + if (temp == isa) + continue; for (; *isa; ++isa) { const char *ext = isa++; const char *ext_end = isa;