From patchwork Tue Jan 23 08:25:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng Yang X-Patchwork-Id: 1889560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=aSUIlcFw; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=USDe9m7e; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=198.137.202.133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TK0j96hrlz1yS7 for ; Tue, 23 Jan 2024 19:33:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Date:Subject:Cc:To:From: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Jfr8pCLqsRchnt8rG8VhhsahTVPmzkvQQdI/Eq6Ebto=; b=aSUIlcFwB3RvAI wOLMlZ/dGL0+ct0K4VJkSVWBUoaYpuj/66PdNlACHveRkaq/AEJRVE3XrriWWA+dMYEixT+x9lv3J TAXelcaUf1w7zZ3Vy04i6vlPXYu+ChiVs1c1rT0eKbnI8IxKz1/FrM6c+/BZGyyYglQsbsWI719Ya tdmK13X6xn1alSfuiWDPNf48kkQW3LnHlq7bvD5Vs6o9ZL7EueQpzlMWfgTphLWyvsf6oM/39LvGn zxHcQe8Vj/Df6y7JOEvon6cJ1DxvU/b+mqnxtql8/KyALzmuNjlDGnZll04XB31/1uxp8zEq7N9lU v06ElitDmk9ZhIXlTY4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSCDC-00FYQT-2B; Tue, 23 Jan 2024 08:32:50 +0000 Received: from out162-62-57-210.mail.qq.com ([162.62.57.210]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSCD9-00FYMF-27 for opensbi@lists.infradead.org; Tue, 23 Jan 2024 08:32:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1705998758; bh=Fk3IqY70lXSE0tyZbWS1Dy+L+gD52qsp6ZuMHOfi41o=; h=From:To:Cc:Subject:Date; b=USDe9m7eTSeKAYCklSfbDz0tnOZMNp/rwRVHNfqupbchOrlSk+X+74bBBDDQ+B/TB N7PLmg4EFV2d5nRJAbs5Jy5nAlHGQrmX/q3oQs2kGteH51G7MzpGAhH/cbjRPMCLTm oCH6PTREwSQlq9aCi27RaclyzLRyzcLZ2DqnPaCA= Received: from yc-home.taila82bd.ts.net ([2409:8a62:e7c:1480:47da:b833:d0bf:6939]) by newxmesmtplogicsvrszc5-2.qq.com (NewEsmtp) with SMTP id 69FA8C3B; Tue, 23 Jan 2024 16:26:31 +0800 X-QQ-mid: xmsmtpt1705998391txuwixzkz Message-ID: X-QQ-XMAILINFO: N7h1OCCDntujmyfRtwyx6I9HbHxuU+UC8rO3LFTDtYQnOb1msj1HkxCwzbV6ul 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work@foxmail.com To: opensbi@lists.infradead.org Cc: anup@brainfault.org, Cheng Yang Subject: [PATCH] lib:firmware: Select preferred boot hart for cold boot. Date: Tue, 23 Jan 2024 16:25:53 +0800 X-OQ-MSGID: <20240123082552.779752-1-yangcheng.work@foxmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_003248_333483_379D9B70 X-CRM114-Status: GOOD ( 17.92 ) X-Spam-Score: 3.4 (+++) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Cheng Yang We now use the boot hart in struct fw_dynamic_info to do relocate, but use a lottery algorithm when selecting the cold boot hart. This may result in using a hart other than the preferred boot hart to [...] Content analysis details: (3.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [162.62.57.210 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [yangcheng.work[at]foxmail.com] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [162.62.57.210 listed in wl.mailspike.net] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 3.2 HELO_DYNAMIC_IPADDR Relay HELO'd using suspicious hostname (IP addr 1) X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Cheng Yang We now use the boot hart in struct fw_dynamic_info to do relocate, but use a lottery algorithm when selecting the cold boot hart. This may result in using a hart other than the preferred boot hart to boot the next stage firmware. sbi_platform_cold_boot_allowed seems to be able to solve this problem, but for most platforms all hartids are allowed to cold boot. In this case, we still cannot guarantee that the hart consistent with the preferred boot hart will be used for cold boot. Therefore, we should also save the preferred boot hart information in scratch, so that we can select it first when making cold start core selection. If no preferred boot hart is specified then the lottery algorithm is used as before. Signed-off-by: Cheng Yang Reviewed-by: Xiang W --- firmware/fw_base.S | 5 +++++ include/sbi/sbi_scratch.h | 11 ++++++++++- lib/sbi/sbi_init.c | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index f7763f4..88abd45 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -333,6 +333,11 @@ _scratch_init: #endif REG_S a0, SBI_SCRATCH_OPTIONS_OFFSET(tp) MOV_3R a0, s0, a1, s1, a2, s2 + /* Store boot hart in scratch space */ + MOV_3R s0, a0, s1, a1, s2, a2 + call fw_boot_hart + REG_S a0, SBI_SCRATCH_BOOT_HART_OFFSET(tp) + MOV_3R a0, s0, a1, s1, a2, s2 /* Move to next scratch space */ add t1, t1, t2 blt t1, s7, _scratch_init diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index e6a33ba..1cf2b5e 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -42,8 +42,10 @@ #define SBI_SCRATCH_TMP0_OFFSET (12 * __SIZEOF_POINTER__) /** Offset of options member in sbi_scratch */ #define SBI_SCRATCH_OPTIONS_OFFSET (13 * __SIZEOF_POINTER__) +/** Offset of boot_hart member in sbi_scratch */ +#define SBI_SCRATCH_BOOT_HART_OFFSET (14 * __SIZEOF_POINTER__) /** Offset of extra space in sbi_scratch */ -#define SBI_SCRATCH_EXTRA_SPACE_OFFSET (14 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_EXTRA_SPACE_OFFSET (15 * __SIZEOF_POINTER__) /** Maximum size of sbi_scratch (4KB) */ #define SBI_SCRATCH_SIZE (0x1000) @@ -83,6 +85,8 @@ struct sbi_scratch { unsigned long tmp0; /** Options for OpenSBI library */ unsigned long options; + /** Preferred boot HART id */ + unsigned long boot_hart; }; /** @@ -144,6 +148,11 @@ _Static_assert( == SBI_SCRATCH_OPTIONS_OFFSET, "struct sbi_scratch definition has changed, please redefine " "SBI_SCRATCH_OPTIONS_OFFSET"); +_Static_assert( + offsetof(struct sbi_scratch, boot_hart) + == SBI_SCRATCH_BOOT_HART_OFFSET, + "struct sbi_scratch definition has changed, please redefine " + "SBI_SCRATCH_BOOT_HART_OFFSET"); /** Possible options for OpenSBI library */ enum sbi_scratch_options { diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 804b01c..2c631f6 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -573,14 +573,20 @@ void __noreturn sbi_init(struct sbi_scratch *scratch) * HART because the coldboot HART will be directly jumping to * the next booting stage. * - * We use a lottery mechanism to select coldboot HART among - * HARTs which satisfy above condition. + * We select coldboot HART among HARTs which satisfy above condition. + * If the preferred boot hart is not specified, we use a lottery + * algorithm to select a cold boot hart, otherwise the preferred + * boot core is selected. */ - if (sbi_platform_cold_boot_allowed(plat, hartid)) { - if (next_mode_supported && - atomic_xchg(&coldboot_lottery, 1) == 0) - coldboot = true; + if (sbi_platform_cold_boot_allowed(plat, hartid) && next_mode_supported) { + if (scratch->boot_hart == -1) { + if (atomic_xchg(&coldboot_lottery, 1) == 0) + coldboot = true; + } else { + if (scratch->boot_hart == hartid) + coldboot = true; + } } /*