Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp431690lqt; Thu, 18 Apr 2024 23:09:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxEBmgLwYR6jnqjmhEu0H/dzuIG8WK7GWoMsHKIkrq1li2j5gUDoeooz3s8i6tF334biimVqU9bwHS7Zyq6ktqnBtLGYRw40UMCEpXhQ== X-Google-Smtp-Source: AGHT+IE8owo8+yAzqKha1skK8ahFyxLTp2A+xDTccEbjoWDzZ+fiMwU0EtVdYkxMtA9CWtLsCP2T X-Received: by 2002:a05:6870:e98e:b0:221:793a:3b9a with SMTP id r14-20020a056870e98e00b00221793a3b9amr1173283oao.40.1713506971304; Thu, 18 Apr 2024 23:09:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713506971; cv=pass; d=google.com; s=arc-20160816; b=qXngCaBiGwEbBMQ8NcO+BCkHE7xkyTGcxXo20irCM3B045s5kagtIFYKErq/YTQjz9 hkd6GXa81q5Pxkd3AHNp+OYTcRIW0zl2idhsAM4UNcl7gBgs0G5qkHrQTr9x5w5SABFE H7EFlHZcJmaB20Eg3bR9e0Sviq922+slR/i47liehXvNWw4zMgZhyzW3qvAAzNVNofPA QDERCIpr3Z+fgOFFWGcMFUyhcrfwAN7FUNoXqabLfxtZOo2vUMmH6rO8a9wHb+N6W80h lqIl1lpE+TYAO0aGzb9rRbNDBY/+xuPn2OFsC/g2GuYG27TOMbDpSwsWUV6yELGCOTtL TzGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=7kErwDd2As93lkNVtXxpSNeg6N1vaOM5yfF2rI/SIas=; fh=3/MAO9w5JL0eMfScVoIyiHxm5lWAOq5nX5hQ9WwVdD4=; b=IM+jc9GFTVD3OXkVu4RnK7J4gzNAO+J0uEHXzKKfFZI7RqOmlrMQ3Hn3HlfDRkc07k FeB9nFymWsYB3twIka7LBlv00bsBT1sYGZo0JZWHfPUSYRkYKU8XWueHwLmHxE/lLXRM uhBTNgtvvZ//ckXwlAS+BemXqqR4Fu3E6hOLU9N5vXTgSd8QWAxoBHE6nj41RNt1C7L1 CvhL/48+bnqxbB1bd0jbGIJGZ6CdVI5iJ33XeQlBKk83rh7nBIq3PQ3iYzE3S+a+gG2E VJ/iUTrPYPRvfgBnBRMdwz0DnJiMJqHgGJ40NceslPJCT0ieVP09utdxiyoT9dtTMSDV BmdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=VbNi7X53; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-151041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151041-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i20-20020aa78b54000000b006e6fdb8f0b5si2698842pfd.265.2024.04.18.23.09.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 23:09:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=VbNi7X53; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-151041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151041-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.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 DD178283358 for ; Fri, 19 Apr 2024 06:09:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFC4ED51A; Fri, 19 Apr 2024 06:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="VbNi7X53" Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) (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 07BC2C127 for ; Fri, 19 Apr 2024 06:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713506964; cv=none; b=rrNHtgH82+yyZ96cjqkL1FdlmZneCJ73qlEnXdTr65en25qJXmGCqnm9bnoO0xJefaNYlTCCMzwh/Gay3a/urue0Tdyr5ToL+UR5XGFYAs+Ca7Wop6xu4Q9I74WDPPBGgT+jlUn6vdnkZFrCwUPw4uVeUsgRvQXXRY0WWBAwOBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713506964; c=relaxed/simple; bh=elPfsV609mZWZMdsMAwYLpbQHMPL6SUn7OhzB1+3T1k=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=gLq7nY+vFwKzXkOY68+IwzdVEsl9SDpTPBDa/oKpslERPloPhYKLgbBgL+wYW/+GAEgScWvp6zBOtdLt7PeVHM40r1YlShyMBJ/BklvBchvNsnlJjjnLRSHwZN8yXcGhkOIiR2ukE6WYsyGLMIdBFBLYD1m2ytqvNg6AbMFp7kk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=VbNi7X53; arc=none smtp.client-ip=209.85.160.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-23935d89261so366129fac.1 for ; Thu, 18 Apr 2024 23:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1713506961; x=1714111761; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7kErwDd2As93lkNVtXxpSNeg6N1vaOM5yfF2rI/SIas=; b=VbNi7X53rWtX79EOjlQGwTGaV0PdQu+Qai3Q86Gb+xdJ5A/VlK2s9vCqiPH/E9m9t2 ShsAoadciOUnaMwPhjOPyAkdK3T7TIUVINKSuoFYs7jWbF6kdHrBxih3yaRUo+EmOyFI UVH3Ql8DREoEEoDI1nMoJYwJ9g3a2iFkeQSLLlaoYVPxC2JM5SFHiCakWSDv+rUS6JGi R3gLEV4hihEg4+Za021JzcSrEjLEyscTmqmaIpb/lPXfFQz6ibTTMaBw+fso9EaUD4o6 YsO5IOsU8RsPuK05rc6zbImXNVVL5fSqIB1iQeS/oZYGl/FiUT/Q9YrcvPZ5A3I6RcDP aphg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713506961; x=1714111761; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7kErwDd2As93lkNVtXxpSNeg6N1vaOM5yfF2rI/SIas=; b=HuUEwBZHBeV2fd90iI6vRmQerFNEfWc/K8l4fft2ZXMnN+HIMJbY16foqsWDTOSlAX VrSze//L8B37U7fOsCPjo/AI5PEArOEW9UP0dPVA1ms2Tx3QZkBN8gjTG2kSze5KCiSg 2GVK8npx+eRrgRp0d31M2AatzGAr5LZNVIlG1KyL29mMNKJ04XJhs32SXrrEqdw4DTDe dQNN1nMYTvQw+Jb+40+iOZwCYimyyHKbc2ojgPZI+aNZELUCiLWfGANFCVFdwurLjOiT Q4QLsZK5K/JqKr/h6NcHvSQ9dLPlNYTQQUZZqHLJsp4m0HkImdsJFZf3Rsvsr0b28Vz/ 8bvw== X-Forwarded-Encrypted: i=1; AJvYcCXON5ltef7r9vQLa/iwSys86EizkvpiHt5mnRNIARhkPHEmmraik8gr9l70EeI7OPWUdbFKvzuiOt+qH5/YAFiFMYlIA3ozVh2afs39 X-Gm-Message-State: AOJu0YzstU+hVB1QEUzC67yqLOxmPF02rEKNpqnDGJ5wph7MyKIip+ZV NGG7a2uyQgb0V8pfaLO2zxKuFvRIJew7buE8kEcBBJRLyM4iqYCLRoYtbUoWM9Kat7NacQvS+1C raHXSLn0uFqvcE/CemmHqrZneLvvUXL0+pL5zuA== X-Received: by 2002:a05:6870:968e:b0:22e:7d06:d489 with SMTP id o14-20020a056870968e00b0022e7d06d489mr1319197oaq.19.1713506961126; Thu, 18 Apr 2024 23:09:21 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240412-zve-detection-v4-0-e0c45bb6b253@sifive.com> <20240412-zve-detection-v4-2-e0c45bb6b253@sifive.com> In-Reply-To: <20240412-zve-detection-v4-2-e0c45bb6b253@sifive.com> From: yunhui cui Date: Fri, 19 Apr 2024 14:09:10 +0800 Message-ID: Subject: Re: [External] [PATCH v4 2/9] riscv: smp: fail booting up smp if inconsistent vlen is detected To: Andy Chiu Cc: 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 , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Andy, On Fri, Apr 12, 2024 at 2:50=E2=80=AFPM Andy Chiu wr= ote: > > 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 Ve= ctor context") > Reported-by: Conor Dooley > Closes: https://lore.kernel.org/linux-riscv/20240228-vicinity-cornstalk-4= b8eb5fe5730@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 =3D &init_mm; > unsigned int curr_cpuid =3D smp_processor_id(); > > + if (has_vector()) { > + /* > + * Return as early as possible so the hart with a mismatc= hing > + * vlen won't boot. > + */ > + if (riscv_v_setup_vsize()) > + return; > + } > + > /* All kernel threads share the same mm context. */ > mmgrab(mm); > current->active_mm =3D 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 &=3D ~COMPAT_HWCAP_ISA_V; > - } > - > riscv_user_isa_enable(); > > /* > > -- > 2.44.0.rc2 > > Reviewed-by: Yunhui Cui Thanks, Yunhui