From patchwork Sun Oct 20 18:53:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 1180057 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=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.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 lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46x8806nmyz9sPh for ; Mon, 21 Oct 2019 05:54:22 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 6A875C21BE5; Sun, 20 Oct 2019 18:54:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BADB6C21C2C; Sun, 20 Oct 2019 18:54:13 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0AB35C21C2C; Sun, 20 Oct 2019 18:54:11 +0000 (UTC) Received: from mail-edgeKA24.fraunhofer.de (mail-edgeka24.fraunhofer.de [153.96.1.24]) by lists.denx.de (Postfix) with ESMTPS id 4B2ABC21BE5 for ; Sun, 20 Oct 2019 18:54:09 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2F6AQCjrKxd/xoHYZllHAEBAQEBBwEBEQEEBAEBgWkFAQELAYFuMWxUAR88h3CFOIVqhEEBln2BewkBAQEBAQEBAQEIGxQBAYEEgzyDECQ2Bw4CDAEBBQEBAQEBBQQCAmmFLQyEMIEzdgFGgR4gDgWDIgGCdgGwGIN7hH+BSAkBgSwBhzWEWYFYP4EQAYNQhA6BBIUhBIxoglOeHAeBP2hpBIYhjgwMG44Niz4Bo3+EJIFYATOBWDMaJIM7CUcQFIFcF4cOhxc/ATIBjg6CVAEB X-IPAS-Result: A2F6AQCjrKxd/xoHYZllHAEBAQEBBwEBEQEEBAEBgWkFAQELAYFuMWxUAR88h3CFOIVqhEEBln2BewkBAQEBAQEBAQEIGxQBAYEEgzyDECQ2Bw4CDAEBBQEBAQEBBQQCAmmFLQyEMIEzdgFGgR4gDgWDIgGCdgGwGIN7hH+BSAkBgSwBhzWEWYFYP4EQAYNQhA6BBIUhBIxoglOeHAeBP2hpBIYhjgwMG44Niz4Bo3+EJIFYATOBWDMaJIM7CUcQFIFcF4cOhxc/ATIBjg6CVAEB X-IronPort-AV: E=Sophos;i="5.67,320,1566856800"; d="scan'208";a="17745344" Received: from mail-mtas26.fraunhofer.de ([153.97.7.26]) by mail-edgeKA24.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Oct 2019 20:54:06 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CIAAAMraxdfRBhWMBlHAEBAQEBBwEBEQEEBAEBgWkFAQELAYFugR1TASA8jSihKYF7CQEDAQEBAQEIGxQBAYRAgzM2Bw4CDAEBBAEBAQIBBQQUAQEWOoU0DIYEAUaBHiAOBYMiAYJ3sByIeoFICQGBLAGHNYYxP4EQAYNQhA6BBIUhBIxoglOeHAeBP2hpBIYhjgwMG44Niz4BqCOBWAExgVkzGiSDOwlHEBSBXBeHDocXPwMwAY4OglQBAQ X-IronPort-AV: E=Sophos;i="5.67,320,1566856800"; d="scan'208";a="93590267" 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; 20 Oct 2019 20:54:01 +0200 Received: from localhost.de (10.80.233.51) by FGDEMUCIMP12EXC.ads.fraunhofer.de (10.80.232.43) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 20 Oct 2019 20:54:00 +0200 From: Lukas Auer To: Date: Sun, 20 Oct 2019 20:53:47 +0200 Message-ID: <20191020185347.11475-1-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24972.000 X-TM-AS-Result: No--0.016600-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Cc: David Abdurachmanov , Alistair Francis , Aurelien Jarno Subject: [U-Boot] [PATCH] riscv: increase stack size to avoid a stack overflow during distro boot X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This fixes a problem, where booting Linux using distro boot will sometimes lead to an invalid instruction exception on the main hart. The secondary harts are not affected and boot Linux successfully. The root cause of this problem is a stack overflow on the main hart. With distro boot, the current default stack size of 8KiB on RISC-V is not sufficient and will cause a stack overflow. The stacks are allocated sequentially. In the case of a stack overflow the stack of the main hart can reach into that of another hart and be corrupted. The stack overflow previously did not cause any problems, because only stack frames, which are not used anymore since the hart enters Linux, were corrupted. Starting with GCC 9, the stack usage has decreased. Now, only the most recent stack frame overflows into the stack of a secondary hart and is corrupted. The illegal instruction exception is caused by the secondary hart overwriting the return address in the stack frame of the main hart with an address that does not include valid code. Increase the default stack size of each hart to 16KiB to avoid this problem. Reported-by: Aurelien Jarno Signed-off-by: Lukas Auer Tested-by: David Abdurachmanov Tested-by: Aurelien Jarno Reviewed-by: Rick Chen --- arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 01975d7c60..85e15ebffa 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -224,7 +224,7 @@ config XIP config STACK_SIZE_SHIFT int - default 13 + default 14 config SPL_LDSCRIPT default "arch/riscv/cpu/u-boot-spl.lds"