From patchwork Wed Jun 7 04:28:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Raghavendra X-Patchwork-Id: 1791506 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.a=rsa-sha256 header.s=ti-com-17Q1 header.b=VGgCLqrW; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QbZ9f0bcPz20Ty for ; Wed, 7 Jun 2023 14:29:08 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F170D84788; Wed, 7 Jun 2023 06:28:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="VGgCLqrW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 229C18471C; Wed, 7 Jun 2023 06:28:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 7EA528471C for ; Wed, 7 Jun 2023 06:28:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=vigneshr@ti.com Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 3574SmfU024027; Tue, 6 Jun 2023 23:28:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1686112128; bh=BlumBDhe51gcoLVclXql9SiGEBvgg5wqeNyzwDHMkkk=; h=From:To:CC:Subject:Date; b=VGgCLqrWWdgwPuGj9sz5ruDaqhMv6I/71KQRM7xvIiwucH85ESCX3fAQTcPNKOdhF reIe7/mP9SA8R3/4ILpsIEJPtvMiPuQUkry7Scc3E2tCgiQR0JtzWfDFxfebGeY7de 7ykNPQSPE4lJDCkePL09aNZfxF6Q2jWpEK2AAzKs= Received: from DFLE111.ent.ti.com (dfle111.ent.ti.com [10.64.6.32]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 3574SmCm010916 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 6 Jun 2023 23:28:48 -0500 Received: from DFLE106.ent.ti.com (10.64.6.27) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 6 Jun 2023 23:28:47 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Tue, 6 Jun 2023 23:28:47 -0500 Received: from uda0132425.dhcp.ti.com (ileaxei01-snat.itg.ti.com [10.180.69.5]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 3574SkrN010103; Tue, 6 Jun 2023 23:28:46 -0500 From: Vignesh Raghavendra To: Tom Rini CC: , Vignesh Raghavendra Subject: [PATCH] common: spl: Warn about overflow of SRAM stack Date: Wed, 7 Jun 2023 09:58:41 +0530 Message-ID: <20230607042841.2906576-1-vigneshr@ti.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 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 If early stack usage is exactly same as SIZE_LIMIT_PROVIDE_STACK, then its most likely to have overflowed beyond this limit and corrupted any regions beyond stack. Warn about this to the user. Signed-off-by: Vignesh Raghavendra Reviewed-by: Kamlesh Gurudasani --- I found this useful when debugging slient corruption of code/data leading to random failures post relocation. common/spl/spl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/spl/spl.c b/common/spl/spl.c index 72078a8ebc8e..9a9c8fad7673 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -950,6 +950,13 @@ __weak void spl_relocate_stack_check(void) } printf("SPL initial stack usage: %lu bytes\n", CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK) - i); + + /* + * If we used up all of the SIZE_LIMIT_PROVIDE_STACK, then here is high + * possibility of stack overflow, warn the user accordingly + */ + if (!i) + printf("SPL possible initial stack overflow detected!!\n"); #endif }