Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1659500lqa; Mon, 29 Apr 2024 15:30:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWRrh2IUMm0C7D3mgVgGOumdLLvnBNMHIhB15BNaIx00JVpf0EZTtVr30Vs6feqE2sB1oE+4Sqa3atVwRmTZw32T8/jOTlojrqW6VniLg== X-Google-Smtp-Source: AGHT+IFJd0pzSN8fD5IsWRbODuTQFFIPyJGLjGMH6R+eESToN0bNxEbU6bK5nCMpeu0vUpW0BneS X-Received: by 2002:a05:6870:b148:b0:22e:ddcb:b59e with SMTP id a8-20020a056870b14800b0022eddcbb59emr14528625oal.40.1714429823112; Mon, 29 Apr 2024 15:30:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714429823; cv=pass; d=google.com; s=arc-20160816; b=b+4B7qAbAueSzTNb1/Xs4IoxB9kn4m03QMah/u7E89DAJ5wd/MDxeNZZ7yQ8xsPpjL uoQU+Jwc9KoVjuCAr8fQe0KrvLi/y+8N7rPBwuKHtTgWFCa89ILRutYHIJIq0TLrv82z z2qjnxNTegkzDmVmD2JETiPpN48904mU7ziT0EX+cgLaJHMyFNrzD1KI8D7yATBdEafZ hk9Ooz5nDgROCArhJGSMRIRjtPTI8vPeU+cRfNVaRYcyW0HrIjErMFOopDzvKN+4bdwG C9zTIoJQMEFjzhT4Gy3F7iekmxTfz03UN6fJpBVsElvF+VNAqbX/Jv2+RLyCGfIUXFO4 H3Kw== 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=rRzF3Dpp7TOSCdwhyYociPGfChYhZSWehQ64aWjvABY=; fh=Yxj7iXdjxyNcPZR2COTRdZxCkDzXhEfgwcuh44iYOhc=; b=vCqMmYJbJ9qT8kro7GQ2ALBXsvwohhNr47ZMQ/EVUM6RWIsvvpHK/KJot0rIaHrjKV mbwB18CwdrBI9qiVi4UYMlwUL7vJhRPVv5eBkTB7jMi2+qDHGlSJw6zdhgMMfh6N9Meb KKKpRex6lq0APtlvcZT5xp9xZG6g6knGe+Ag0J/3tc51OK6D4xb/RsW1TJxuBBhWryPw XHA3+jhYvQFXI0Vx8ZKL368XDkE6fjnOTMm5iYdDL2YTLH90Fih7MiEIjhOqH2szVWmh JFBbF/SNK6Dj+2HTTO2Fa0uF/gQ9YGDQ/8n/GYh6qxloyrwU52sfOsRmBRxZO28SJ1bd Hylg==; 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=wBxvFWbF; 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-163104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163104-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b135-20020a63348d000000b005f79f184149si19147561pga.315.2024.04.29.15.30.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 15:30:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=wBxvFWbF; 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-163104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163104-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B1563282B66 for ; Mon, 29 Apr 2024 22:30:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C1CE194C76; Mon, 29 Apr 2024 22:30: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="wBxvFWbF" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 A68F3194C6A for ; Mon, 29 Apr 2024 22:30:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714429805; cv=none; b=gsFQRBThUUER5ILE8dO+bdMU8A5XSBUBAPc1V+C+lo4i905QEQmdZXuG88sfmpX0gGeSlBYPAKKk5SkeDgjWst3A7EfIsGkfQP+CNyrFslBzsvjyqlztF8ombX+S8gw7y6DqVwaIjcf2MTJnQDMHtgPI9T1BECs1fAkFrzsYUFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714429805; c=relaxed/simple; bh=7Qk+r0hY+lSGzO4QuKkjhPXKa0g3xMDQRnHfBKCgIOw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MaGqU5ZxHiSGDAfpKpy/gptDQ2WUSD9kB255oCuQcnx92QFHI6lgeN4PjVkAXU/Dvrk5ulQDUBeZD/3MFaGo/9W+NjpAQzFs6G/vWqOmZpTkYFqIL/DziAMCKur+MloawUGZgKVAo/isNERS/cIqa7LArjDM+LU8jfniaPztXEw= 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=wBxvFWbF; arc=none smtp.client-ip=209.85.214.181 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-pl1-f181.google.com with SMTP id d9443c01a7336-1e65a1370b7so46957905ad.3 for ; Mon, 29 Apr 2024 15:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1714429803; x=1715034603; 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=rRzF3Dpp7TOSCdwhyYociPGfChYhZSWehQ64aWjvABY=; b=wBxvFWbFxDZkIEKb29Hv+3KXdBjC7tiXgbsFGiW1XyyI7AO4dQI1G6+2EI9vg6YEom 5koinf+VQIeyaDJtzM1AIo7+7Utp0EstnmeYtMUXYOIXpVpDvDFROFjdWIBMG8AMNgMU c0i1OpFmtlJa2wGghnGvWTZZBSUJiJaFKETLjJ9ITtYQMGEg8uewCNCqsOygUBa6WXuZ siqGDWsyb151+GFZYKzPLGEXj5t9FOwYEIbZw++hfXxXGEoQ87XPWUtQDP9oKvKXMQnr l2kqa8rKyYqunOGkgowJ2r/NcbHtapJQO+JftbUlMPo3qAupomOnYsbaVe+9sNG32HQ4 GiGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714429803; x=1715034603; 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=rRzF3Dpp7TOSCdwhyYociPGfChYhZSWehQ64aWjvABY=; b=SnzrSBTUzS0q8oeeJwv4wBN+9wmwN56xYyyJzQgrCcUuT6eTpzRk75HUt4Q+V+JWO6 t5c1VQPg39uibWX0ABBICdK8ougV1RftlISSdlqWGLgRWaS7u3JcLmwQ+eyQl83z7H6B 1aBnnQ4rsJxab8loQNG22Z0F5faZn809qbxuizqUzTg2+BEZTYQAUU1u5Wdnbuhy1wkZ ASlU9kvC3EjXu2hGEtkOIc6B1j/eak8rO+NYvXGFt9MxU0Q/0NK4MGSR9aNBTsonjKMY DxjwOORHs1qT1lsYhmSpS/1rG88KOXBRx+9jaljOa5RDOWDsPPOAQj85bwUrPKNMuvup IbAw== X-Forwarded-Encrypted: i=1; AJvYcCVoooQyfsW0KFOkwReUFNzrJY+GCVtyC6/spP+/kmihZnhP6VfXgg/ir/FgtA16pUl3Wmf9FQlRF0xmtyvi9lkk56Spj1H8ES83gqil X-Gm-Message-State: AOJu0YytZ+nUvVdefBvsr8lsgn5IeiVxgLtENQC/ZVMNyNK0wQ7E8tfs 5+vaFkcJ07eQi01GJ1EpDdElQRcJvQEYyIdd4aecTG3ql/IjUp+FforeHdYiTjfgoPyJm45jWWf G X-Received: by 2002:a17:902:d4cd:b0:1eb:77ed:8fba with SMTP id o13-20020a170902d4cd00b001eb77ed8fbamr8414418plg.17.1714429802983; Mon, 29 Apr 2024 15:30:02 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id a13-20020a170902b58d00b001e0942da6c7sm20794013pls.284.2024.04.29.15.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 15:30:01 -0700 (PDT) From: Charlie Jenkins Date: Mon, 29 Apr 2024 15:29:51 -0700 Subject: [PATCH v3 1/2] 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: <20240429-cpufeature_fixes-v3-1-6aa11dde513b@rivosinc.com> References: <20240429-cpufeature_fixes-v3-0-6aa11dde513b@rivosinc.com> In-Reply-To: <20240429-cpufeature_fixes-v3-0-6aa11dde513b@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Conor Dooley , Conor Dooley , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , 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=1714429799; l=4794; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=7Qk+r0hY+lSGzO4QuKkjhPXKa0g3xMDQRnHfBKCgIOw=; b=+2nEFf9AqjedtM6uvaTMr19dbCCI+Az5OGT9+vcdmI1d4cqQUSYea4mKCVpZSYhyl1fUVl/jV ozmKSOUV/cKB0UXVlhKJzLI6/qMfiKqgBNPTdHb/BQU2vIcQCbykLve 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 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 | 10 ++++++++-- 3 files changed, 46 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..818adb0d388e 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; @@ -543,9 +548,10 @@ static void __init riscv_fill_hwcap_from_isa_string(unsigned long *isa2hwcap) * version of the vector specification put "v" into their DTs. * CPU cores with the ratified spec will contain non-zero * marchid. + * + * Disable vector if the boot hart has a T-Head mvendorid and an marchid of 0. */ - 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