Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp262909lqn; Thu, 11 Apr 2024 23:57:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVh8VnjKthH/NBorui46nPy5NET6WEqk3OJ+YT3cfB5FJo2ngkYghOuQl3mPvon2S5r908AwyGx+nz/Kwzf+FLO/jQ6zyQVWtRYV+7Sg== X-Google-Smtp-Source: AGHT+IFnJJTukU7r5+7qwisEM4DWYvKrREcbxXj80C61DfEhxJi6i9PehooBIUHKwBvAOdgQsc6m X-Received: by 2002:a05:6870:b619:b0:22b:5bc1:66f5 with SMTP id cm25-20020a056870b61900b0022b5bc166f5mr1838256oab.16.1712905065664; Thu, 11 Apr 2024 23:57:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712905065; cv=pass; d=google.com; s=arc-20160816; b=Z4p+pN+qtMffPoEZD5U3JGrxOm/slwxtlPFsdk37YyHEsKyxqZIKjQ/kl/YzpOFyN2 tllXAJBzKQtQtlHtZul7vU+Ucf/4MYb3WY2XMorLyTNdYds4eKzFdzdZO7GV/I1+5GOu YehYCvhNmM6YZuQJHt9DrNEdo1OAmQywvmZLnk2RPV8CCLis7tnv863t8tLwc6MXPtIQ NzD0PwpuoJ2sLlQr6mbP29POqrFXanKuqHU94D4jgrTF1+T9dnO+javCFHVK15nNtoPs fnsTsQjsq97tC5CyGzYqFX+HYl+Im9v8H8R6dH+sMURgj30J5HQ9PGsj0an8u+LhTehr JZGg== 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=IE7PNdtEhi9KW+zIWld3aHVp99xlyaQhdGOlf9pdhFA=; fh=ZouIYvIwAltPPneIO9TSWuj3x6SFTrFuV4FUSS8kgKs=; b=lg6yRG1BsPIl5xu438eo0wDIPtnDFHG8qvOQckogjqgbXRnkSzmQJi1oZxiQ5njwc0 n3GjdIwuHtqVEG3oaIHFhNw5xSsZNZ/EOITdMzpTS3rrp6Qtlyv9XPNjAKb6ZyXbHcat 5oagMQh03bHkMK0yFCmaSAwUcl98qEVb4jZFqoKzLMY0n9Spo5oPJUbX20RagVYoXSWc mdo+vBuQY2/gw8Q0PUQzCL9J6ghtco3TJTpmtOZJhlXTdKYEFFyDpGjj6jQ99FXXrbX/ sCWY76WiwF0M0vLQWmo1A0HWILygnhTEaTMdUa5tqJhFrzsomJtq+9YE5AYZEsYfZotC +PCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=EfP5Y3JD; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-142067-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142067-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p8-20020a056a000b4800b006ed59d3df46si2879110pfo.120.2024.04.11.23.57.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 23:57:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142067-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=@sifive.com header.s=google header.b=EfP5Y3JD; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-142067-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142067-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com 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 A2005288E1E for ; Fri, 12 Apr 2024 06:49:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1C7C4C624; Fri, 12 Apr 2024 06:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="EfP5Y3JD" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 E919F48CE0 for ; Fri, 12 Apr 2024 06:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712904553; cv=none; b=ryQ41nRIXdv05iNS1TBSG569ZVVKpLx6mHK9dPID/YPXuL2jimFFQ0yVR6qj+B2bm57MppEHrMkZAFIeWc2FrLynOwFtx6bFR8WSFLTmVc4E+/+x+X3EHviostDoGd0/9W8LveV6G671xWr78EsYqWpbOejwungXEeI+EprPE/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712904553; c=relaxed/simple; bh=NsUylxIFobwN7mTvqQ5dHkwxBlT1LzawwF+eu4628ng=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HsBARdaRoGXt1UJySy1A6aJ+d2ZGIX69ukcrACiY8RJJVdmjXPvLJR+1whK8hj8kqbMkjh7YXcMGHRsYNAwuSyPTxhVI/USVIajMYJnYFIqjtgjrzkbPHFoji6ot5NNgUpTbiP18PxTrrH9mbi25lVXMxm1wa+8Zt7KOopZW34g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=EfP5Y3JD; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1e3f6f03594so4545205ad.0 for ; Thu, 11 Apr 2024 23:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1712904550; x=1713509350; 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=IE7PNdtEhi9KW+zIWld3aHVp99xlyaQhdGOlf9pdhFA=; b=EfP5Y3JDJcAe3tp3DTSUggpyZaJor/q98gZCEQUdgAz2B742tFl7gL6XB5A8jPl83X t/cq5/mYqlupYPA2nkkEpGi58eeWbDOGCxgJHkkun7ryfQxJ6vDhrSVUVKci8XR5ZST0 pNDXJHSW9aaZUQeaIosZ3lsU6vbL/4V0ZqG3HhDPStFEQK2hinQgXGdMDRttpm4R9Vmt lcxA26iVYR3qfUH5yyNDQf6j8/Yz5aGXwVa8FbV6i/pRDzPWzeKwpJIpFoZkeBsFOy16 AsD6uyniZIXyAt8ttgQpv9CWkodxziNibHSHr1pM6PyfjaMUQk60nNtsJ5J+KsEdGJ0q wN4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712904550; x=1713509350; 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=IE7PNdtEhi9KW+zIWld3aHVp99xlyaQhdGOlf9pdhFA=; b=tUXFk/NV1uPfi00xuOEoijTyzd4wfLJeaZtuUAEylC6nVmVjcPgubMg7zYdCEOvGZR 7oRUvYqPfLVLLwweRgdTDK2MV7R1EjzTGndEnKr28i2BWcSZXbyy3exA5RE0Q1zC7Akk q7xfrlCAgHJDYsEjuGxtXA7FkFss196KtJhwFyottcysACwdYCGmE9LI4sKDYPvnKZh7 z6SAEpMaY58w8bSU+UXiDjsqQnZa5/9sNvW0y01W7sOIG2RnDqRbDB5UyYxtB7XMnNgE 26cZxbt8EpxMzmHBiwUcnJLB9O89asFTzx4IM1hpkam0p49Be/0qenJsEWOVE/P9gwT2 SkEA== X-Forwarded-Encrypted: i=1; AJvYcCVMP7MUihHyRYzspdV8n+fll5CC/iuInjBkPPUhmMsO31z1Zqgx6OPvvuh2XD8rXHULOBQnXLAyoqLnB9vAuUv7MR/xXrDimKprlO4x X-Gm-Message-State: AOJu0YyoBpFTq3J8ENuEDwAGjyVqgCiVUI7XWY4gClRjUWDHnOfyQIy/ nKzz6AoH/KA3ostmcLqrazp+YoYQFn6sSExLf358b7K749a7Hjr4JAnM103L7ic= X-Received: by 2002:a17:903:1210:b0:1e2:adad:75f4 with SMTP id l16-20020a170903121000b001e2adad75f4mr2046388plh.28.1712904550318; Thu, 11 Apr 2024 23:49:10 -0700 (PDT) Received: from [127.0.1.1] (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id q8-20020a170902b10800b001e107222eb5sm2258818plr.191.2024.04.11.23.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 23:49:10 -0700 (PDT) From: Andy Chiu Date: Fri, 12 Apr 2024 14:48:58 +0800 Subject: [PATCH v4 2/9] riscv: smp: fail booting up smp if inconsistent vlen is detected 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: <20240412-zve-detection-v4-2-e0c45bb6b253@sifive.com> References: <20240412-zve-detection-v4-0-e0c45bb6b253@sifive.com> In-Reply-To: <20240412-zve-detection-v4-0-e0c45bb6b253@sifive.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Heiko Stuebner , Andy Chiu , Guo Ren , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Evan Green , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Shuah Khan Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , Vincent Chen , Greentime Hu , devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org X-Mailer: b4 0.13-dev-a684c Currently we only support Vector for SMP platforms, that is, all SMP cores have the same vlenb. If we happen to detect a mismatching vlen, it is better to just fail bootting it up to prevent further race/scheduling issues. Also, move .Lsecondary_park forward and chage `tail smp_callin` into a regular call in the early assembly. So a core would be parked right after a return from smp_callin. Note that a successful smp_callin does not return. Fixes: 7017858eb2d7 ("riscv: Introduce riscv_v_vsize to record size of Vector context") Reported-by: Conor Dooley Closes: https://lore.kernel.org/linux-riscv/20240228-vicinity-cornstalk-4b8eb5fe5730@spud/ Signed-off-by: Andy Chiu --- Changelog v4: - update comment also in the assembly code (Yunhui) Changelog v2: - update commit message to explain asm code change (Conor) --- arch/riscv/kernel/head.S | 19 ++++++++++++------- arch/riscv/kernel/smpboot.c | 14 +++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 4236a69c35cb..a00f7523cb91 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -165,9 +165,20 @@ secondary_start_sbi: #endif call .Lsetup_trap_vector scs_load_current - tail smp_callin + call smp_callin #endif /* CONFIG_SMP */ +.align 2 +.Lsecondary_park: + /* + * Park this hart if we: + * - have too many harts on CONFIG_RISCV_BOOT_SPINWAIT + * - receive an early trap, before setup_trap_vector finished + * - fail in smp_callin(), as a successful one wouldn't return + */ + wfi + j .Lsecondary_park + .align 2 .Lsetup_trap_vector: /* Set trap vector to exception handler */ @@ -181,12 +192,6 @@ secondary_start_sbi: csrw CSR_SCRATCH, zero ret -.align 2 -.Lsecondary_park: - /* We lack SMP support or have too many harts, so park this hart */ - wfi - j .Lsecondary_park - SYM_CODE_END(_start) SYM_CODE_START(_start_kernel) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index d41090fc3203..673437ccc13d 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -214,6 +214,15 @@ asmlinkage __visible void smp_callin(void) struct mm_struct *mm = &init_mm; unsigned int curr_cpuid = smp_processor_id(); + if (has_vector()) { + /* + * Return as early as possible so the hart with a mismatching + * vlen won't boot. + */ + if (riscv_v_setup_vsize()) + return; + } + /* All kernel threads share the same mm context. */ mmgrab(mm); current->active_mm = mm; @@ -226,11 +235,6 @@ asmlinkage __visible void smp_callin(void) numa_add_cpu(curr_cpuid); set_cpu_online(curr_cpuid, 1); - if (has_vector()) { - if (riscv_v_setup_vsize()) - elf_hwcap &= ~COMPAT_HWCAP_ISA_V; - } - riscv_user_isa_enable(); /* -- 2.44.0.rc2