From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59C2AC433F5 for ; Thu, 12 May 2022 18:41:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BF38683961; Thu, 12 May 2022 20:41:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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; unprotected) header.d=kernel.org header.i=@kernel.org header.b="oDKGkJK0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D744D83618; Thu, 12 May 2022 20:41:26 +0200 (CEST) Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) (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 1020680584 for ; Thu, 12 May 2022 20:41:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 7667FCE29A8; Thu, 12 May 2022 18:41:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84071C34100; Thu, 12 May 2022 18:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652380878; bh=4WWca0u/FvXec8LAQrxqvAqROIxUfCTq5zYUbRrBa9Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oDKGkJK0X1s9EIhGx0JzxDdUs22cyliE4xhFkq6VvavLe/mB+rxxYA/MfvrzXBx9Z SDJ3sfPQDiAnHoctqWa3mFHgJWHxI6PHQz54bA3RwzTEvMiu4ZeGByqnFsywNkryLh /NerPTb6OnrzsNkoAyI+LZB4oreIRWzkwMcOytEHviOomRwW7cm/4RhoSSjAfZSpuj v80+PaWL1vgo/G4smHl7e3wRzcFERMQzqnUm8KxC0vQlRkeUszpDKvBzYZzvg6RW7C 7k7nld75SZdFbYrojQxz8fwtPQ+MeiQccSV4OTzJ7UtJyRqoluCX+3TnkaD8w9nJp+ Ngxz4F3mYY2zA== Received: by pali.im (Postfix) id 7BD732B6B; Thu, 12 May 2022 20:41:15 +0200 (CEST) Date: Thu, 12 May 2022 20:41:15 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Sean Nyekjaer Cc: Miquel Raynal , Tom Rini , Joao Marcos Costa , Thomas Petazzoni , u-boot@lists.denx.de, Sean Nyekjaer Subject: Re: [PATCH] fs/squashfs: use do_div function for math Message-ID: <20220512184115.bufjsu4hgq7rsqf3@pali> References: <20220505092637.1856223-1-sean@geanix.com> <20220505131500.GF3580959@bill-the-cat> <20220509150815.43d7543c@xps13> <20220512101901.egbghfpf76f23tfs@pali> <20220512102401.3zcyvcek6nytxc7d@pali> <20220512180233.vzvfnx5jlco57ck3@Seans-MBP.hadsten> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220512180233.vzvfnx5jlco57ck3@Seans-MBP.hadsten> User-Agent: NeoMutt/20180716 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.5 at phobos.denx.de X-Virus-Status: Clean On Thursday 12 May 2022 20:02:33 Sean Nyekjaer wrote: > On Thu, May 12, 2022 at 12:24:01PM +0200, Pali Rohár wrote: > > On Thursday 12 May 2022 12:19:01 Pali Rohár wrote: > > > On Monday 09 May 2022 15:08:15 Miquel Raynal wrote: > > > > Hello, > > > > > > > > trini@konsulko.com wrote on Thu, 5 May 2022 09:15:00 -0400: > > > > > > > > > On Thu, May 05, 2022 at 11:26:37AM +0200, Sean Nyekjaer wrote: > > > > > > > > > > > From: Sean Nyekjaer > > > > > > > > > > > > When compling for x86: > > > > > > ld.bfd: fs/squashfs/sqfs.o: in function `sqfs_read': > > > > > > u-boot/fs/squashfs/sqfs.c:1443: undefined reference to `__udivmoddi4' > > > > > > ld.bfd: u-boot/fs/squashfs/sqfs.c:1521: undefined reference to `__udivmoddi4' > > > > > > > > > > > > Signed-off-by: Sean Nyekjaer > > > > > > --- > > > > > > fs/squashfs/sqfs.c | 5 +++-- > > > > > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > > > > > > > > > diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c > > > > > > index 5d9c52af80..6405db4ff3 100644 > > > > > > --- a/fs/squashfs/sqfs.c > > > > > > +++ b/fs/squashfs/sqfs.c > > > > > > @@ -8,6 +8,7 @@ > > > > > > */ > > > > > > > > > > > > #include > > > > > > +#include > > > > > > #include > > > > > > #include > > > > > > #include > > > > > > @@ -1440,7 +1441,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, > > > > > > } > > > > > > > > > > > > for (j = 0; j < datablk_count; j++) { > > > > > > - start = data_offset / ctxt.cur_dev->blksz; > > > > > > + start = do_div(data_offset, ctxt.cur_dev->blksz); > > > > > > table_size = SQFS_BLOCK_SIZE(finfo.blk_sizes[j]); > > > > > > table_offset = data_offset - (start * ctxt.cur_dev->blksz); > > > > > > n_blks = DIV_ROUND_UP(table_size + table_offset, > > > > > > @@ -1516,7 +1517,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, > > > > > > goto out; > > > > > > } > > > > > > > > > > > > - start = frag_entry.start / ctxt.cur_dev->blksz; > > > > > > + start = do_div(frag_entry.start, ctxt.cur_dev->blksz); > > > > > > table_size = SQFS_BLOCK_SIZE(frag_entry.size); > > > > > > table_offset = frag_entry.start - (start * ctxt.cur_dev->blksz); > > > > > > n_blks = DIV_ROUND_UP(table_size + table_offset, ctxt.cur_dev->blksz); > > > > > > > > > > Adding maintainers... > > > > > > > > I guess that's a correct fix, so > > > > > > > > Reviewed-by: Miquel Raynal > > > > > > > > Thanks, > > > > Miquèl > > > > > > Hello! do_div() macro modifies its first argument. It is correct? > > > Because previous code did not modify anything. > > > > * The semantics of do_div() are: > > * > > * u32 do_div(u64 *n, u32 base) > > * { > > * u32 remainder = *n % base; > > * *n = *n / base; > > * return remainder; > > * } > > > > And this patch replaced: > > > > start = data_offset / ctxt.cur_dev->blksz; > > > > by: > > > > start = do_div(data_offset, ctxt.cur_dev->blksz); > > > > which expands to: > > > > start = data_offset % ctxt.cur_dev->blksz; > > data_offset = data_offset / ctxt.cur_dev->blksz; > > > > Which is wrong as it calculates something totally different. > > > > So this patch is incorrect. > > Hi Pali, > > Yes I agree, I got tricked by some wrong cache from Yocto :/ > I have tried lldiv(), and that works on our x86 target. > > Do you have an opinion on that? > Or do you have another idea to avoid the > "undefined reference to `__udivmoddi4'" error? > > /Sean Hello! You really should not use C division operator for 64-bit integers as gcc still is not able to generate assembler code for such division on many 32-bit platforms. You should use some function or macro from linux/math64.h or div64.h header file. For every combination of types, pairs and required operation there is specific function/macro (e.g. u64/u32, u64%u32, u64/u64, etc...). I think that lldiv() is the correct call here. This function expects u64 as dividend, u32 as divisor and returns u64 result.