From patchwork Tue Dec 3 21:39:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 1203853 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47SG4D20QJz9s4Y for ; Wed, 4 Dec 2019 08:55:08 +1100 (AEDT) Received: by phobos.denx.de (Postfix, from userid 109) id 88FD4816F8; Tue, 3 Dec 2019 22:54:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C998781678; Tue, 3 Dec 2019 22:41:43 +0100 (CET) Authentication-Results: mail.denx.de; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Authentication-Results: mail.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 427BF80668; Tue, 3 Dec 2019 22:40:29 +0100 (CET) Received: from mail-edgeKA27.fraunhofer.de (mail-edgeka27.fraunhofer.de [153.96.1.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EFC908089E for ; Tue, 3 Dec 2019 22:40:24 +0100 (CET) Authentication-Results: mail.denx.de; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Authentication-Results: mail.denx.de; spf=none smtp.mailfrom=lukas.auer@aisec.fraunhofer.de X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2FJAwCT1eZd/xoHYZllHAEBAQEBBwEBEQEEBAEBgX6CIIFBAR88Co0ko0sJAQEBAQEBAQEBBwEvAQGEQAKCDiQ4EwIQAQEFAQEBAQEFBAICaYVDhigGJwsBRhBRVwYOBYMigncBswsziHuBSAkBgSyHPYRZD4FMP4FHgxuEEoEEhSEEjQqCV55iB4FEbW4EhUqPEQwbjkKLYqhnAgQCBAUCFYFpI4FYMxokgztQERSMchcVjg9AAQExAY89gTGBEAEB X-IPAS-Result: A2FJAwCT1eZd/xoHYZllHAEBAQEBBwEBEQEEBAEBgX6CIIFBAR88Co0ko0sJAQEBAQEBAQEBBwEvAQGEQAKCDiQ4EwIQAQEFAQEBAQEFBAICaYVDhigGJwsBRhBRVwYOBYMigncBswsziHuBSAkBgSyHPYRZD4FMP4FHgxuEEoEEhSEEjQqCV55iB4FEbW4EhUqPEQwbjkKLYqhnAgQCBAUCFYFpI4FYMxokgztQERSMchcVjg9AAQExAY89gTGBEAEB X-IronPort-AV: E=Sophos;i="5.69,275,1571695200"; d="scan'208";a="18789690" Received: from mail-mtas26.fraunhofer.de ([153.97.7.26]) by mail-edgeKA27.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2019 22:40:24 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0ATAgCT1eZdfRBhWMBlHAEBAQEBBwEBEQEEBAEBgX6DYAEBHzwKjSSjSwkBAwEBAQEBBwEvAQGEQAKCMTgTAhABAQQBAQECAQUEFAEBFjqFSoVTAwMnCwFGEFFXBg4FgyKCeLMLM4h7gUgJAYEshz2EaIFMP4FHgxuEEoEEhSEEjQqCV55iB4FEbW4EhUqPEQwbjkKLYqhnAgQCBAUCFYFpIYFZMxokgztQERSMchcVjg9AAQEBMAGPPYExgRABAQ X-IronPort-AV: E=Sophos;i="5.69,275,1571695200"; d="scan'208";a="98933315" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP12EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaS26.fraunhofer.de with ESMTP/TLS/AES256-SHA; 03 Dec 2019 22:40:23 +0100 Received: from xch-onprem-07.ads.fraunhofer.de (10.225.16.45) by FGDEMUCIMP12EXC.ads.fraunhofer.de (10.80.232.43) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 3 Dec 2019 22:40:22 +0100 Received: from localhost.localdomain (10.225.16.62) by xch-onprem-07.ads.fraunhofer.de (10.225.16.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Tue, 3 Dec 2019 22:40:22 +0100 From: Lukas Auer To: Subject: [PATCH 4/4] spl: opensbi: wait for ack from secondary harts before entering OpenSBI Date: Tue, 3 Dec 2019 22:39:56 +0100 Message-ID: <20191203213956.24339-5-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191203213956.24339-1-lukas.auer@aisec.fraunhofer.de> References: <20191203213956.24339-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-Originating-IP: [10.225.16.62] X-ClientProxiedBy: xch-onprem-05.ads.fraunhofer.de (10.225.16.54) To xch-onprem-07.ads.fraunhofer.de (10.225.16.45) X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-25080.006 X-TM-AS-Result: No--3.774700-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at mail.denx.de X-Virus-Status: Clean At the start, OpenSBI relocates itself to its link address. If the link address ranges of U-Boot SPL and OpenSBI overlap, the relocation can lead to code corruption if a hart is still running U-Boot SPL during relocation. To avoid this problem, the main hart is specified as the preferred boot hart to perform the relocation. This fixes the code corruption problems based on the assumption that since the main hart schedules the secondary harts to enter OpenSBI, it will be the last to enter OpenSBI. However it was reported that this assumption is not always correct. To make sure the assumption always holds true, wait for all secondary harts to acknowledge the call-function request before entering OpenSBI on the main hart. Reported-by: Rick Chen Signed-off-by: Lukas Auer Reviewed-by: Rick Chen Tested-by: Rick Chen Reviewed-by: Anup Patel --- common/spl/spl_opensbi.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/spl/spl_opensbi.c b/common/spl/spl_opensbi.c index 91a411a3db..5ea59d423f 100644 --- a/common/spl/spl_opensbi.c +++ b/common/spl/spl_opensbi.c @@ -75,9 +75,19 @@ void spl_invoke_opensbi(struct spl_image_info *spl_image) invalidate_icache_all(); #ifdef CONFIG_SMP + /* + * Start OpenSBI on all secondary harts and wait for acknowledgment. + * + * OpenSBI first relocates itself to its link address. This is done by + * the main hart. To make sure no hart is still running U-Boot SPL + * during relocation, we wait for all secondary harts to acknowledge + * the call-function request before entering OpenSBI on the main hart. + * Otherwise, code corruption can occur if the link address ranges of + * U-Boot SPL and OpenSBI overlap. + */ ret = smp_call_function((ulong)spl_image->entry_point, (ulong)spl_image->fdt_addr, - (ulong)&opensbi_info, 0); + (ulong)&opensbi_info, 1); if (ret) hang(); #endif