Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp662485lqd; Wed, 24 Apr 2024 13:01:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW1dRPMQOLAPmX+yWUeoEZYev/SI2CZO+ms7HC10hZsbN9bNWF2NjCIXXq4D+Ky+58HLzXXYhUX9KJvNiBK+FT/S7aPBUcujIw1XgcIsg== X-Google-Smtp-Source: AGHT+IF/pwr8leu0tfWU1hmvWOaUevAD/WcVvgfnUDdrLwQqIovIiRBAc9hErR9Glz9b3yf+OFKj X-Received: by 2002:ac8:584c:0:b0:43a:3691:9d2 with SMTP id h12-20020ac8584c000000b0043a369109d2mr1660098qth.37.1713988903480; Wed, 24 Apr 2024 13:01:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713988903; cv=pass; d=google.com; s=arc-20160816; b=0zEthAcWq14wJd/RyoPH6eEpHdsQqiDTv5yEfI4de+QIRCgj/66F+kVsxbolTfDthP RLGz9YTTI6KdNO5dGiT/5Lb7Fs3aWbS2FIUkVG9Q8Am/0AvxUos62QMbKG9MJmRuVNPN LeXdQgx72HSz6uSeKaHjP2QzpUSt4qkWfu0IFjQe7Il+TI++4XN5ldh0+gHi/03TuKLY yrPYUXIw8WAe2rYC7toZjXRXoQuaH9mcMeiLIJKt3ln0hF784Zjyd7Vly8CwpNlJt7Qz ZR+/195yOrK1bWx4FPRE5v3Q6VEqN87LOtwdoRcpsqCZjpTsK2ISYJfSgo2Iryrb842I n4qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=iijH2aCb9Q03G911FdDl9qEUu9R2M0yhrRltjE0bQOo=; fh=l3vgU53QzbdnwUyf+QLWDrU0WCgFQc4hbELOK7OIIQs=; b=nbymUnG7mo4CEi3PUmCp+ZGWWvd36MLO5ckNrOCXbSoZkcjmgZtsg71aTGqIELK6OU 4/IVtjWcrxK2dPFXf0mv1j8eOnLDfi+4Bk/Ycuoiho7W+iBy24Qe5etdf95GZUlYUZdb jVN3J/y+fp1WLPkVXseyw3yuZmqlzTARbIF7XhFz3d7h95bUwLcyhvHetDYG6FFsPxmc /qra9Pck79ZClWA4Mmh6rdz0EM9h0bCLwmrZZ7YTVLqCde+07XRtCL99BwUZy1vhPjQu nxoO5Gvz9v4fQWcA+PnpiznW6qlvx7dlF2+MUb8u6/P44BaA5Sg3U/cm+QPdLfCg/opc i8nw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-157640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157640-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d15-20020ac85d8f000000b00437a01eb05bsi16533827qtx.25.2024.04.24.13.01.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 13:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-157640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157640-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 369861C22F3F for ; Wed, 24 Apr 2024 20:01:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6133B13CAB5; Wed, 24 Apr 2024 20:01:31 +0000 (UTC) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAFF613BC19; Wed, 24 Apr 2024 20:01:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713988890; cv=none; b=L+fThRa4GfuxQMaYFVbP0lwPIwzhqUKFRAEFdJM989ihStM4gYv3mRS6GtMdsTwy+ke7JdBQAyDiAmF4n/BMmakVGye6F/GCnwfEdXnAVb18GkTqGMJZ/ApaFsVQ8QkEKeCnghq4cLgtx1CmhuTxIcOXMSq/pFieMQ9wfzHh5LE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713988890; c=relaxed/simple; bh=lVUzeWoRGC6Liw5e4wRBgAQt06rT4cQ/EvqQQrQhdRg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kH3HIrwRM5GG7/6uYDMevdzGK0ko9DhIer52eaU/eS17u4ySuWz+WjdxxaxeZWoLwb+NnRzpGM/BFcOo6IUeOVH+6hDq/9MKTBYH7vlzfq7E8NHhuqloT11vKeIFXXVmdCHIi7lq3gitX9P5KJfKuCRdSI+1NrL/AVLhoUI2+Ls= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id CB2E1240004; Wed, 24 Apr 2024 20:01:15 +0000 (UTC) Message-ID: <4acc62d0-d62b-4d42-805b-0bc7f663a81c@ghiti.fr> Date: Wed, 24 Apr 2024 22:01:15 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/9] riscv: smp: fail booting up smp if inconsistent vlen is detected Content-Language: en-US To: Andy Chiu , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Heiko Stuebner , Guo Ren , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Evan Green , =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , 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 References: <20240412-zve-detection-v4-0-e0c45bb6b253@sifive.com> <20240412-zve-detection-v4-2-e0c45bb6b253@sifive.com> From: Alexandre Ghiti In-Reply-To: <20240412-zve-detection-v4-2-e0c45bb6b253@sifive.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-GND-Sasl: alex@ghiti.fr Hi Andy, On 12/04/2024 08:48, Andy Chiu wrote: > 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(); > > /* > So this should go into -fixes, would you mind sending a single patch for this fix? Your patch 8 is actually already fixed by Clement's patch https://lore.kernel.org/linux-riscv/20240409143839.558784-1-cleger@rivosinc.com/ and I already mentioned this one to Palmer. Thanks, Alex