Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1833527lqp; Mon, 15 Apr 2024 21:13:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWP97KCOA/gZElKE46H8+4lttuOjQb3xOPmSE+l2zHXW8Iq3yosiGSFI/VeGykMeaHsZIKM7hJETR9rKxC71reZvT+XlpvZwRnm0idKQ== X-Google-Smtp-Source: AGHT+IExotk7TL2fXuohLKluU+crV0kg5NzM45Don2OLwbDNRikA9HUh8YTBWob5OSq/7+2keJl5 X-Received: by 2002:a17:902:d509:b0:1e3:e220:d433 with SMTP id b9-20020a170902d50900b001e3e220d433mr2287556plg.2.1713240797986; Mon, 15 Apr 2024 21:13:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713240797; cv=pass; d=google.com; s=arc-20160816; b=rhgPEKvOJmGYow8r6ftjXq4eT8jIT0Vnpc4/88b9lpEdJSESlhSFeEtMu1O944zagA QbFfzloHqVZZWwkzLVWyy8dh/VyZPp/bo8kfV7kdxGAKRPSe8tMtwQ9Shlw1X8Botn1s JOHcIbgKnaxyVr267lYidz+wHzceZ8TGiOzKA2zFcmKoECKPV58UIHy06Xg3mUFFKSRK +xfTaG1lZUltTcUsFMYtjE9c22i6rs32WcJyNKO2xWAU9ViuWaiLT1IqhSFG44JQcukE PDLB3j95UxCoUNER54YMOtCQtLD1inBMJRVrMxbofIC5ppl8QGpuWM+Dzssw+tQXPpqK jl+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=++xZy+ObBNE3KB89/8huI8TuSwtQKmJYk1fAnGCjGI8=; fh=HjZS0357SXgukNmVSL3Jsy2DwdjAFNrLDB+/zYnfflA=; b=wtf66j/A9szalObF/IF6c4ruQxwOBQHRJqlmjtMo4BtoEslmldfu6A4fEfDoDN5yg3 XB0nTEXWlF6cUsuvsNg4zTeUMaXz+BEdZNkaK7l3vKZhQQoHaAaAubi88pWcy0Y0bDrV yGZvzDJn2r+21w8fIWd5gQ9kKbGBDgsNDEKEaEvTiPmJdRlE1GBuPYqp0jGSsxEk3NPw rFn/KH3Yi/xexcKxuJ6d/z9vrDs1fUASKLp4oJv60yH3V2UTW7q4VgkCbbNSlQNVcTSw xFr27A/8MyW8fiozJUhrzZx9vB8U/Nbf+gwKdKgEJle8JPkD6jFwSHCKE0ii1VEWI4+8 kd8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=pRgGQUHu; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-146203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146203-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a18-20020a170902ecd200b001e480e78014si9227520plh.593.2024.04.15.21.13.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:13:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=pRgGQUHu; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-146203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146203-linux.lists.archive=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4E235B23824 for ; Tue, 16 Apr 2024 04:12:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D4EB219E1; Tue, 16 Apr 2024 04:12:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="pRgGQUHu" Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 869B222309 for ; Tue, 16 Apr 2024 04:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713240725; cv=none; b=FGypBa94Mg0Ib1bmd1f5uMTqwq2/PZXIQr24km/kIhiJ64s5+WIIkVgyFcvD3hbF+teOXbFabVa7fZOd4wunX9v4ziSlu2lR3AQ7ZyK/fRtP9ztCaJlPGJxDjKpEWNe+K1AK6G4J2EepDJ4vBhC4gxJBDFR6sDCdl02WPv4u2jE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713240725; c=relaxed/simple; bh=dkmMwSQhSZqqA7hvCp11OQAJEfKHO37CqENn3GjjXso=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M6JGa/6Y/ZwRUequWNzEe+iLaZeXHa2gXqNCjS9IFFSCaE37oGKCfNiZ2oNnRVVrdhLG8kp8oH7GQdMZ/lpSC1551/xVBuXVc5dpgsM7FC60dVKEhn8N5NYVD1sbaC3whIsOTWg6jtHy8K6sYXrY1++Y/ZF6b94AvHNgcPD2O0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=pRgGQUHu; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6ecf8ebff50so2612117b3a.1 for ; Mon, 15 Apr 2024 21:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713240723; x=1713845523; darn=vger.kernel.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=++xZy+ObBNE3KB89/8huI8TuSwtQKmJYk1fAnGCjGI8=; b=pRgGQUHu/xwOo8sWYbpY0O/5eYzb7hprPq53GeZ9TOOInzGSYB+XrsCpWGXNFLVp+b dPKc/PG9cHbqgi9d9Tx6g0CUpoDtbgVVcSZ7gUeYA4nwr3ycze0oGHVLZfr+15rQMNp5 A5jdr2BNgc3+B4wBF/MXeMlxJ+i/T62TtaAYfFCi0TDC6QFbL3ynZTBxiCVynrfkL6bu 0vyR05Ofk3tpOZC59LOadjE/gVIXQzBQftIWEzC6/RXrMUamdR71rfMlfHOggiRe7Tr6 Rx0CKlwaSvk60G73xMu3t5tVGcn2XScQNs9EgFh+FHNmAGrWDI0oC4d7oDzg2/JAU8GZ V4fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713240723; x=1713845523; 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=++xZy+ObBNE3KB89/8huI8TuSwtQKmJYk1fAnGCjGI8=; b=PHdrxetqlS3eg8a8yKjJRZ4hrpNhp5BQLOHqSTp1hHnnAdoTJgBEVFwQdOam9y9feX kzo/3Hgd3vzB91kykXqBXmN+vFomzlTKXkn7pOEAR/1nKignFofiaFTl6Qn9+DAFq8ZB Sd5ek76RfhHJGEgxfA3bJEpErTUgnaWqaX1yiv8jwSlMnranfpykLt9VPKWBaZQrocoZ WKRsWxf+yzowwxoBFcUM5usQhbF5E1B7cJAdUYg9kRM5nzrie7rJN0/OGzYsBXowfr5l DzjPFT+wbNeg0koNfDImSUYC/xjQPrcN7aiy6D9qbEYnLqcZpM3T1oy5lJEBA6oMV1TI cZtA== X-Forwarded-Encrypted: i=1; AJvYcCXwCvrUQA0ZUEBGl8HRte85sxoZkCOVwBlpC5WwJnnd+1Mz+hwD3RfJE3CjpFCHHAiASFDDPSdGjeWnYMFmFfG7Eispydvu3wPWl0Hl X-Gm-Message-State: AOJu0Yw6cN9kFcaeCH5gzqYY+sRqRKq4GdPOKtkskC6IHTwA5izRWu8w MJgcFFvruGV4sVmmDZt1Yo/Uv2rvtUdmAxXybt21JsFYvL5xMZKnFk97yo5VhfA= X-Received: by 2002:a05:6a00:2382:b0:6ed:ca65:68b with SMTP id f2-20020a056a00238200b006edca65068bmr2125216pfc.4.1713240722785; Mon, 15 Apr 2024 21:12:02 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id z184-20020a6265c1000000b006ed4c430acesm8383149pfb.40.2024.04.15.21.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:12:02 -0700 (PDT) From: Charlie Jenkins Date: Mon, 15 Apr 2024 21:11:58 -0700 Subject: [PATCH v2 01/17] riscv: cpufeature: Fix thead vector hwcap removal Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240415-dev-charlie-support_thead_vector_6_9-v2-1-c7d68c603268@rivosinc.com> References: <20240415-dev-charlie-support_thead_vector_6_9-v2-0-c7d68c603268@rivosinc.com> In-Reply-To: <20240415-dev-charlie-support_thead_vector_6_9-v2-0-c7d68c603268@rivosinc.com> To: Conor Dooley , 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 , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jonathan Corbet , Shuah Khan Cc: 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, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1713240719; l=4708; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=dkmMwSQhSZqqA7hvCp11OQAJEfKHO37CqENn3GjjXso=; b=RyAuMqKhMsNmgEPKgOmQFKT3iEAhF8iXw8f0UHK9Bdd0JU5h75VVCNI96WA048tjLZiiqaCDT Uw/yH0Jd01nCawauWBIhP1sdCDA+K4rGlevzJ9wvQyEf7//qeTPo3ZQ X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= 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. 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(-) 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..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; } +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,12 @@ 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(); + ci->mvendorid = ci->mvendorid ? ci->mvendorid : sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid(); + ci->marchid = 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); + ci->mvendorid = ci->mvendorid ? ci->mvendorid : csr_read(CSR_MVENDORID); + ci->marchid = 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..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(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,13 @@ static void __init riscv_fill_hwcap_from_isa_string(unsigned long *isa2hwcap) return; } + /* + * Naively assume that all harts have the same mvendorid/marchid as the + * boot hart. + */ + 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 +553,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); } -- 2.44.0