From patchwork Thu Nov 7 15:01:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 2008177 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=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=tPgBaSJK; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=t2ScEpqD; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XkwnC6Pn5z1xyk for ; Fri, 8 Nov 2024 08:53:30 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D03E088DB6; Thu, 7 Nov 2024 22:53:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linutronix.de 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; secure) header.d=linutronix.de header.i=@linutronix.de header.b="tPgBaSJK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="t2ScEpqD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AC07D89246; Thu, 7 Nov 2024 16:01:19 +0100 (CET) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 CC5ED89293 for ; Thu, 7 Nov 2024 16:01:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=namcao@linutronix.de From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1730991677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lkugnngs4hy2THmLYjCUdSsijCIQW5weUplOaJdqlYQ=; b=tPgBaSJKouoKd9E44Q0o1vPEeDXX52EkEJtAxSFrGgvvgT6iJAPRTYB+uddon5m94/9Pha aZBo4fyOsghR90DJLDhudAqr54ho0uUI44qkNjJ1TeQTs/gtu1F0WdGsIGVK1l8Izu3g1c 0ZNM4E/rcquVUpCwe8Pl48dl9TYu17B/VmKuwFVimC7WyiYlmnkJjQTocUDNhJY8IzLZuE ZmfBv4/Z18NzYjW5HyamY5QpXMCwpBAk7K3J+vV2S/1BqWMduuFQo8NF32NRbpvzFSPZqq DsLrV7gfFicDGYyI4TgUjpeD+GlBq6AQXorC7JYYQN59VdbcldCaQ2RrwuP1RQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1730991677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lkugnngs4hy2THmLYjCUdSsijCIQW5weUplOaJdqlYQ=; b=t2ScEpqDre9xPW8Iu/N5s/ajZe/1AgyAV0ylbk2eBDwXDAHLWafs6Sa3yD8D+N//j95XTN KkLmLCX5YP/VqtDA== To: Simon Glass , Tom Rini , Mattijs Korpershoek , Ion Agorria , Svyatoslav Ryhel , Nam Cao , Mayuresh Chitale , Sean Anderson , AKASHI Takahiro , Javier Fernandez Pastrana , u-boot@lists.denx.de Subject: [PATCH v2 1/2] boot: extlinux: Fix unaligned buffer for reading data from file system Date: Thu, 7 Nov 2024 16:01:05 +0100 Message-Id: <1eb402380414c2b8f1b25d0c63d894efefce4ab9.1730988601.git.namcao@linutronix.de> In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 07 Nov 2024 22:53:17 +0100 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 extlinux_read_bootflow() allocates a buffer to read from file system without any alignment. But for some block devices which transfer data via DMA, ARCH_DMA_MINALIGN alignment is required. For example, due to misaligned buffer, the below boot failure is observed. => boot CACHE: Misaligned operation at range [9efa25f8, 9efa27f8] CACHE: Misaligned operation at range [9efa25f8, 9efa27f8] CACHE: Misaligned operation at range [9efa25f8, 9efa27f8] CACHE: Misaligned operation at range [9efa25f8, 9efa27f8] ** Booting bootflow 'mmc@2194000.bootdev.part_1' with extlinux Ignoring unknown command: �D���D�� Boot failed (err=-14) Change the buffer alignment to ARCH_DMA_MINALIGN. Fixes: 31aefaf89a5b ("bootstd: Add an implementation of distro boot") Signed-off-by: Nam Cao Tested-by: Javier Fernandez Pastrana --- v2: - use ARCH_DMA_MINALIGN to be consistent with bootmeth_script [Simon] boot/bootmeth_extlinux.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c index ae0ad1d53e3..ac046705033 100644 --- a/boot/bootmeth_extlinux.c +++ b/boot/bootmeth_extlinux.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY UCLASS_BOOTSTD +#include #include #include #include @@ -127,7 +128,7 @@ static int extlinux_read_bootflow(struct udevice *dev, struct bootflow *bflow) return log_msg_ret("try", ret); size = bflow->size; - ret = bootmeth_alloc_file(bflow, 0x10000, 1); + ret = bootmeth_alloc_file(bflow, 0x10000, ARCH_DMA_MINALIGN); if (ret) return log_msg_ret("read", ret); From patchwork Thu Nov 7 15:01:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 2008178 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=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=VHhx91aE; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=Rl2j+7E0; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XkwnG2jqZz1xy0 for ; Fri, 8 Nov 2024 08:53:38 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3F76F88E39; Thu, 7 Nov 2024 22:53:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linutronix.de 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; secure) header.d=linutronix.de header.i=@linutronix.de header.b="VHhx91aE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Rl2j+7E0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5753989293; Thu, 7 Nov 2024 16:01:21 +0100 (CET) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) (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 37F51892D9 for ; Thu, 7 Nov 2024 16:01:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=namcao@linutronix.de From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1730991677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lMJECLMM4wLwTiZodooCl2eFTpJMFcrRPc42lf0yjM4=; b=VHhx91aE73TdirBS+YkTVBwt7bQMusY8B0xoghkMbdRz7MoGQWyKEu7Wn+n837fPks/5nD dXMQI4R+YhoRB865RpDl3CA9pU+o3HgzrsWAu4WgUMahAkrKPT7HHHTwmpxyFdbEPs8Iq3 4SRJ91JhCT08UaTdxTKU7W9eNb1sjJ4dpX740ePJ1s0VLcQflWJqLObua+p01CJmDsR5Oz fAuIwXhQ0fqeh0AQuPUV4zTtszTgLa1MnxwNoVlixFuaoHQfybow2UcSzmbh/AVUiHwttz Cumx7nFRGoYtz2KL0JSpekaBGz4celsuUjDPJFVScJlUAQsVVOmGGu4ROPBy8Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1730991677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lMJECLMM4wLwTiZodooCl2eFTpJMFcrRPc42lf0yjM4=; b=Rl2j+7E0JF26lc5GnfYkr8HKGrioyc3o1Wi27r+yw3uK/3AexFWbhsAnOr+4hE7+VPpjfI z61RmGwcE4lPEmDQ== To: Simon Glass , Tom Rini , Mattijs Korpershoek , Ion Agorria , Svyatoslav Ryhel , Nam Cao , Mayuresh Chitale , Sean Anderson , AKASHI Takahiro , Javier Fernandez Pastrana , u-boot@lists.denx.de Subject: [PATCH v2 2/2] fs: Use ARCH_DMA_MINALIGN as default alignment for fs_read_alloc() Date: Thu, 7 Nov 2024 16:01:06 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 07 Nov 2024 22:53:17 +0100 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 The comment above fs_read_alloc() explains: @align: Alignment to use for memory allocation (0 for default) However, in the actual implementation, there is no alignment when @align is zero. This current default is probably fine for most cases. But for some block devices which transfer data via DMA, ARCH_DMA_MINALIGN is needed. Change the default alignment to ARCH_DMA_MINALIGN. Fixes: de7b5a8a1ac0 ("fs: Create functions to load and allocate a file") Signed-off-by: Nam Cao Tested-by: Javier Fernandez Pastrana --- v2: - mention the default value in function comment [Simon] fs/fs.c | 4 ++++ include/fs.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/fs.c b/fs/fs.c index acf465bdd80..bfa51c89d40 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1001,6 +1002,9 @@ int fs_read_alloc(const char *fname, ulong size, uint align, void **bufp) char *buf; int ret; + if (!align) + align = ARCH_DMA_MINALIGN; + buf = memalign(align, size + 1); if (!buf) return log_msg_ret("buf", -ENOMEM); diff --git a/include/fs.h b/include/fs.h index ef540e7c23d..2f879968d0c 100644 --- a/include/fs.h +++ b/include/fs.h @@ -309,7 +309,7 @@ int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); * * @fname: Filename to read * @size: Size of file to read (must be correct!) - * @align: Alignment to use for memory allocation (0 for default) + * @align: Alignment to use for memory allocation (0 for default: ARCH_DMA_MINALIGN) * @bufp: On success, returns the allocated buffer with the nul-terminated file * in it * Return: 0 if OK, -ENOMEM if out of memory, -EIO if read failed