Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4B8FC77B7A for ; Tue, 16 May 2023 13:54:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7E30B8609C; Tue, 16 May 2023 15:54:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="I7DuvTBd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 93B43860ED; Tue, 16 May 2023 15:54:49 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2822985E53 for ; Tue, 16 May 2023 15:54:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 1BEB43F232 for ; Tue, 16 May 2023 13:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1684245280; bh=ccRVvSriVKtzM4hh6oFp6KqXttIQdUMlKsWmRZ6sxyE=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=I7DuvTBdclUs36Nl69nJPGvHA+aCqzOYLTGT7zu98Rf4B901RvdP1U4AlrKHRLpRm BcB4pwnt4ZgEZXMV4agXaXLNUVdAeg3NYtvv5xQExuq+rlD4Z/gnOhohFL/wRE+Gt5 GBNwLHgeeiB+3dLVHBHbxR8+xqU6Nnl0NWkLBr6OBSjK+V0UrLZWHW4dluWSGhAail CpyqaajWSJKelpc5wNrp0d1C2yBmC1C8vc11rI4HnPBVq2HfTirRmpz3WOK+Ph7SEM tawliJJdUnwoXNr8Z/e44H76w2+AwYSq0xxgMBmVcJdzGX1Jer58G3WXk/cGi42Rg3 umr96gma4ZDJw== Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f50aa22cd2so14621205e9.1 for ; Tue, 16 May 2023 06:54:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684245279; x=1686837279; h=content-transfer-encoding:in-reply-to:from:cc:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ccRVvSriVKtzM4hh6oFp6KqXttIQdUMlKsWmRZ6sxyE=; b=IVkJsKXUtkBGOeoWlDRCR+TQYG3pQB0+TR+VkAR2HEx1L+xDqq+kiPT3i4b9+VKRQJ Kgz5+4xHQQxyEGxGOqtIvOMcWQ0e7l0hEtztyliTFqfXliki0NFHvbSu+efZWdBV2TdQ jKyjWw56B/EKYCb/eXgg/fI973jNchyn0rBwt6adVQDpGZ5MZNElpl0Kqk3DkK3h/aSV pYz9WVrffQ4Bv+gSgzwT834n08dltx8c0r7Y2nDm9cJetBB5G5LuE/02H7psorR5D3yb RW4VDGBV5p2KfIkkWNfGX9LutDosPsmGNXNVMbE6yHyEbeKBzqvAmW+TtQc9yAWF9j4J +nDg== X-Gm-Message-State: AC+VfDyjisv4Nr68sauGHhYbptnPbXm88v95n+gxHd4Ekf3cS2oNB5B8 ENN2G/kd2sfntf06Uf3NUPtgWwZUn6uldEwiXCNnvkf5pGSZfsc4I/NScSjrLzXSdGdAEpHvcA8 SGFWU/MazcpRbtOLzcBF+ELabYVdgWJc= X-Received: by 2002:adf:e483:0:b0:2cf:e517:c138 with SMTP id i3-20020adfe483000000b002cfe517c138mr26423528wrm.66.1684245279577; Tue, 16 May 2023 06:54:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6j5PSZjB3eYDU2L2HtSBwm2s0LcqWSqlTbCLhR61seTg4w1dRp8rpGdGnFBjZJ30qXM67TtQ== X-Received: by 2002:adf:e483:0:b0:2cf:e517:c138 with SMTP id i3-20020adfe483000000b002cfe517c138mr26423519wrm.66.1684245279138; Tue, 16 May 2023 06:54:39 -0700 (PDT) Received: from [192.168.123.67] (ip-088-152-145-137.um26.pools.vodafone-ip.de. [88.152.145.137]) by smtp.gmail.com with ESMTPSA id e4-20020a05600c218400b003f4289b18a7sm2446348wme.5.2023.05.16.06.54.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 06:54:38 -0700 (PDT) Message-ID: <9ebfb81d-ea55-e6e3-269e-56bf8cc21499@canonical.com> Date: Tue, 16 May 2023 15:54:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [V3,1/1] riscv: Increase the upper bound of NR_CPUS to 4095 Content-Language: en-US To: Leo Yu-Chi Liang References: <20230213084313.10419-1-ycliang@andestech.com> Cc: u-boot@lists.denx.de, Xiang W , David Abdurachmanov , Rick Chen From: Heinrich Schuchardt In-Reply-To: <20230213084313.10419-1-ycliang@andestech.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On 2/13/23 09:43, Leo Yu-Chi Liang wrote: > From: Xiang W > > The maximum hart number is 32 and is determined by > the type of gd->arch.available_harts. However, various > RISC-V specifications allow the hart number to be greater > than 32. We can eliminate this limitation through bitmaps. > > The patch modifies the upper bound of the hart number to 4095, > which is also the maximum hart number RISC-V Advanced Core Local > Interruptor Specification gives. > > Some defconfigs, (e.g. qemu-riscv32_smode_defconfig, > qemu-riscv64_smode_defconfig, openpiton_riscv64_defconfig, ...) > do not define CONFIG_NR_CPUS, and may result in compile error, > so define CONFIG_NR_CPUS to be 1 if CONFIG_NR_CPUS is not defined. > > Tested on sifive unmatched. > > Signed-off-by: Xiang W > Signed-off-by: Leo Yu-Chi Liang > --- > Changes v2 -> v3: > - Fix the calculation of the GD_AVAILABLE_HARTS start address > - Fix compilation error for defconfigs that do not define CONFIG_NR_CPUS > --- > arch/riscv/Kconfig | 4 ++-- > arch/riscv/cpu/start.S | 20 +++++++++++++++----- > arch/riscv/include/asm/global_data.h | 8 +++++++- > arch/riscv/lib/smp.c | 2 +- > 4 files changed, 25 insertions(+), 9 deletions(-) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index ebc4bef220..063734cbb9 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -232,8 +232,8 @@ config SPL_SMP > all, single processor machines. > > config NR_CPUS > - int "Maximum number of CPUs (2-32)" > - range 2 32 > + int "Maximum number of CPUs (2-4095)" > + range 2 4095 Looking at patch 776e8aca0bad ("riscv: alloc space exhausted") SYS_MALLOC_F_LEN needs to be increased if the number of CPUs is increased. You could add an architecture specific rule to config.mk to adjust SYS_MALLOC_F_LEN. > depends on SMP || SPL_SMP > default 8 > help > diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S > index 4687bca3c9..ae19c2b43d 100644 > --- a/arch/riscv/cpu/start.S > +++ b/arch/riscv/cpu/start.S > @@ -172,11 +172,21 @@ wait_for_gd_init: > bnez t1, 1b > > /* register available harts in the available_harts mask */ > - li t1, 1 > - sll t1, t1, tp > - LREG t2, GD_AVAILABLE_HARTS(gp) > - or t2, t2, t1 > - SREG t2, GD_AVAILABLE_HARTS(gp) > + li t1, GD_AVAILABLE_HARTS > + add t1, t1, gp > +#if defined(CONFIG_ARCH_RV64I) > + srli t2, tp, 6 > + slli t2, t2, 3 > +#elif defined(CONFIG_ARCH_RV32I) > + srli t2, tp, 5 > + slli t2, t2, 2 > +#endif If QEMU provides > XLEN harts, this will result in a buffer overrun. You must check against the size of available_harts. > + add t1, t1, t2 > + LREG t2, 0(t1) > + li t3, 1 > + sll t3, t3, tp > + or t2, t2, t3 > + SREG t2, 0(t1) > > amoswap.w.rl zero, zero, 0(t0) > #endif > diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h > index 6fdc86dd8b..7e37e90db0 100644 > --- a/arch/riscv/include/asm/global_data.h > +++ b/arch/riscv/include/asm/global_data.h > @@ -10,9 +10,15 @@ > #ifndef __ASM_GBL_DATA_H > #define __ASM_GBL_DATA_H > > +#include > #include > #include > #include > +#include > + > +#ifndef CONFIG_NR_CPUS > +#define CONFIG_NR_CPUS 1 CONFIG_ constants should not be defined in C code. Please, move this to Kconfig. The chosen value will create problems for QEMU. The fallback value should be XLEN (BITS_PER_LONG) at least. Best regards Heinrich > +#endif > > /* Architecture-specific global data */ > struct arch_global_data { > @@ -29,7 +35,7 @@ struct arch_global_data { > #endif > #if !CONFIG_IS_ENABLED(XIP) > #ifdef CONFIG_AVAILABLE_HARTS > - ulong available_harts; > + ulong available_harts[BITS_TO_LONGS(CONFIG_NR_CPUS)]; > #endif > #endif > }; > diff --git a/arch/riscv/lib/smp.c b/arch/riscv/lib/smp.c > index 4f073a016f..511e3ed98d 100644 > --- a/arch/riscv/lib/smp.c > +++ b/arch/riscv/lib/smp.c > @@ -48,7 +48,7 @@ static int send_ipi_many(struct ipi_data *ipi, int wait) > #if !CONFIG_IS_ENABLED(XIP) > #ifdef CONFIG_AVAILABLE_HARTS > /* skip if hart is not available */ > - if (!(gd->arch.available_harts & (1 << reg))) > + if (!test_bit(reg, gd->arch.available_harts)) > continue; > #endif > #endif