From patchwork Fri May 3 04:50:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13652406 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 401D8C25B10 for ; Fri, 3 May 2024 04:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KOvqvhnEcpHmI8+jmawUY6XkEYEQ0RQDb+fMkULeBpU=; b=iS4lJKePwq0+Sj hhAVbtBuU1qZweXzNNSlVF9L2CWaA4TC0OnsWfQAaUXMNW+oCo6Ep+guYFVu78Qlwqdd/FYPD887f kzfUDjQtNLEC2GmNGpjhVoV+Ctt7BERYaszQG9iiNgkIt5xy9idCbqaslRIBS/FtSKJsep05R1Ry+ zPApsNyFJbv97KqFI7aZzMJRvCClt1gDyI1D9RuRtGNssu1rgXgpEJZhfxkGIRkH68n9dsUH3CSxt YmIX9FujcOYNMbQbWgj0S3Ssd8azNt7CzYV6YzqQKyV/lNN3H3fUsAyW0I9k1tBQ88GXBORYYXq01 vBBWN+GslrkppUsysLyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2ksv-0000000F4dw-1SBV; Fri, 03 May 2024 04:51:01 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2kss-0000000F4cb-0NXE for linux-riscv@lists.infradead.org; Fri, 03 May 2024 04:50:59 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1ecddf96313so15178275ad.2 for ; Thu, 02 May 2024 21:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1714711857; x=1715316657; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7J8+4BPg11tVammG7iU8LBCVcp0HAz7W5E4tQ6iskcc=; b=kQiGQsy19E23rf+tQlCQE14KN7rkfHt8f6mLYyBn6eXzhtnT/HIHpnD4DuNSIdX6xF HtJoSazZ8duBC2iPE60ZjYXRcxYqv2mKTzbq+S717qYcXnxAsvPqIq+lgMnmiCCdFb0N DbxgPYkguq7BnU4iYROIJSsrxa9mpWZrOBVNxaVD0M/rFN9c3GqYNZDK7pRrKzzivFGe tt/jO7+XfjYM7XNwjwdhIkNE0U9sa1aIGIrwqvg0JXqvbV1TcrKR/Z5AHDqGire7M8iP m8Xq9eO9ROgHTWmQSXGYrFYNPrNwH14T2KZBEq5QFvz8YsCHL6E50gQwxT9lxNkMcdu5 /pVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714711857; x=1715316657; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7J8+4BPg11tVammG7iU8LBCVcp0HAz7W5E4tQ6iskcc=; b=eqqfIWZ/uAbGXPP3CA2YE7HmhsOQwH58+EEEhxkOALLPJTdLMAsE4pFjtNBsJMmJ// xFICJ96pzEbRt1miBaG+cxPzSEifEHv/00AaaNI+2j0cb1TWALVPu5V5u6uDSUEY6lak 7B88R4RSmVBF8aUhVjmUhnsRUvBRdp+v+L/SenkqDJxsHryAWPZ8718ybRCit2K2Ylan NsyY8Oq+6cPnLwJgZZw+9W2s9PTRtRGXMhM97kenEgOup/LnYfwQ2AkF1ViRB+ZEm0SF sYQWtPPvyDEOL2BHWZbRfiLJaEIrTWJ6W9Ha1fqVq0fI8mvUgCJaFn+BXWKZdewuuM/q zqXw== X-Forwarded-Encrypted: i=1; AJvYcCWIhCjPE4Zg6kW7dAoE4cZCW7qro75Waycu1+d8q3iYWQtJDv3iBBGdBvzcHB6NwlxWuD2fcMXsCv9IiGK9hucIZI6c57Ow0fduHR8Z7vn0 X-Gm-Message-State: AOJu0Yy5UtzQUHe+8Vhng9lyyJo6FhTSO2JEZmnyXF46x2Lfr0EmEmuN o/fLmee8V9gUsNHiKipjXewMf+f1vGnYIev4ocH99WZ+4oJXjMn43WEbgjSS2Mw= X-Google-Smtp-Source: AGHT+IE2GM/FT0Bn/phAha5Olfrwy5UPqVYHFI/KC1ovLGni/veB92iOt5IkZk5eHeVdspJeej9buw== X-Received: by 2002:a17:903:246:b0:1e5:d021:cf58 with SMTP id j6-20020a170903024600b001e5d021cf58mr1945544plh.36.1714711857409; Thu, 02 May 2024 21:50:57 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id li11-20020a170903294b00b001e3c77db2aesm2276384plb.88.2024.05.02.21.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 21:50:54 -0700 (PDT) From: Charlie Jenkins Date: Thu, 02 May 2024 21:50:50 -0700 Subject: [PATCH v4 1/2] riscv: cpufeature: Fix thead vector hwcap removal MIME-Version: 1.0 Message-Id: <20240502-cpufeature_fixes-v4-1-b3d1a088722d@rivosinc.com> References: <20240502-cpufeature_fixes-v4-0-b3d1a088722d@rivosinc.com> In-Reply-To: <20240502-cpufeature_fixes-v4-0-b3d1a088722d@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Conor Dooley , Conor Dooley , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Evan Green Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714711851; l=4634; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=TuTVSbXhC2+Pf7yEowJN8gfvY+TdoOJRAjnj2qooZU8=; b=QqmJvtQyLn100wNUhTZKNDHlffN3SHuM3dGD+WP+ZSJN+94mkJDGWHu4cu0YHNBzMywFInnmG uKF6sHe4L9OCxlWy+zEPhROi9Hq8yPPqN0T1U2x+j1PsHO3R1wmlm/X X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240502_215058_175608_BF5AEE39 X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 mvendorid/marchid from the boot hart to determine if the DT contains an invalid V. Fixes: d82f32202e0d ("RISC-V: Ignore V from the riscv,isa DT property on older T-Head CPUs") Signed-off-by: Charlie Jenkins Reviewed-by: Conor Dooley Reviewed-by: Guo Ren --- arch/riscv/include/asm/sbi.h | 2 ++ arch/riscv/kernel/cpu.c | 40 ++++++++++++++++++++++++++++++++++++---- arch/riscv/kernel/cpufeature.c | 8 ++++++-- 3 files changed, 44 insertions(+), 6 deletions(-) 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 cpumask *cpu_mask) { return -1 static inline void sbi_init(void) {} #endif /* CONFIG_RISCV_SBI */ +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..c1f3655238fd 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; } +unsigned long __init riscv_get_marchid(void) +{ + struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo); + +#if IS_ENABLED(CONFIG_RISCV_SBI) + ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid(); +#elif IS_ENABLED(CONFIG_RISCV_M_MODE) + ci->marchid = csr_read(CSR_MARCHID); +#else + ci->marchid = 0; +#endif + return ci->marchid; +} + +unsigned long __init riscv_get_mvendorid(void) +{ + struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo); + +#if IS_ENABLED(CONFIG_RISCV_SBI) + ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid(); +#elif IS_ENABLED(CONFIG_RISCV_M_MODE) + ci->mvendorid = csr_read(CSR_MVENDORID); +#else + ci->mvendorid = 0; +#endif + return ci->mvendorid; +} + DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); unsigned long riscv_cached_mvendorid(unsigned int cpu_id) @@ -170,12 +198,16 @@ static int riscv_cpuinfo_starting(unsigned int cpu) struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo); #if IS_ENABLED(CONFIG_RISCV_SBI) - ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid(); - ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid(); + if (!ci->mvendorid) + ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid(); + if (!ci->marchid) + ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid(); ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid(); #elif IS_ENABLED(CONFIG_RISCV_M_MODE) - ci->mvendorid = csr_read(CSR_MVENDORID); - ci->marchid = csr_read(CSR_MARCHID); + if (!ci->mvendorid) + ci->mvendorid = csr_read(CSR_MVENDORID); + if (!ci->marchid) + ci->marchid = csr_read(CSR_MARCHID); ci->mimpid = csr_read(CSR_MIMPID); #else ci->mvendorid = 0; diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 3ed2359eae35..13d4fc0d1817 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(unsigned long *isa2hwcap) struct acpi_table_header *rhct; acpi_status status; unsigned int cpu; + u64 boot_vendorid; + u64 boot_archid; if (!acpi_disabled) { status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct); @@ -497,6 +499,9 @@ static void __init riscv_fill_hwcap_from_isa_string(unsigned long *isa2hwcap) return; } + boot_vendorid = riscv_get_mvendorid(); + boot_archid = riscv_get_marchid(); + for_each_possible_cpu(cpu) { struct riscv_isainfo *isainfo = &hart_isa[cpu]; unsigned long this_hwcap = 0; @@ -544,8 +549,7 @@ static void __init riscv_fill_hwcap_from_isa_string(unsigned long *isa2hwcap) * CPU cores with the ratified spec will contain non-zero * marchid. */ - if (acpi_disabled && riscv_cached_mvendorid(cpu) == THEAD_VENDOR_ID && - riscv_cached_marchid(cpu) == 0x0) { + if (acpi_disabled && boot_vendorid == THEAD_VENDOR_ID && boot_archid == 0x0) { this_hwcap &= ~isa2hwcap[RISCV_ISA_EXT_v]; clear_bit(RISCV_ISA_EXT_v, isainfo->isa); }