U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3()
@ 2026-11-25 12:42 Josef Schlehofer
  2026-11-25 12:42 ` [PATCH 1/6] fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread() Josef Schlehofer
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Josef Schlehofer @ 2026-11-25 12:42 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	Marek Behún, Qu Wenruo, Joao Marcos Costa, Richard Genoud,
	Thomas Petazzoni, Miquel Raynal, Peng Fan, Jaehoon Chung,
	Tanmay Kathpalia, linux-btrfs

U-Boot's private libgcc does not provide __udivdi3() and __umoddi3().
v3 of the mpc85xx LTO series links mpc85xx LTO builds with it and added
both routines [1]. Christophe Leroy asked why the callers do not avoid
'/' and '%' on 64-bit operands instead, and Tom Rini asked to update
the common code [2].

Patches 1-4 avoid the divisions that make the mpc85xx LTO builds call
__udivdi3() or __umoddi3(), in btrfs, squashfs, mmc_berase() and
get_win_cnt() of the mpc8xxx PAMU code. They do not depend on each
other. Patch 5 removes fs/btrfs/dev.c, which nothing uses and which
holds another 64-bit modulo. Patch 6 converts the remaining divisions
in btrfs. U-Boot never runs them, but builds without LTO still link the
ones in the RAID5/6 code. My reply in that thread announced these
conversions for v4 of the LTO series. They are sent on their own
instead.

Patch 2 and my big-endian fix for squashfs [3] conflict in
sqfs_read_nest(). I will rebase whichever of them goes in second.

Build tested with a buildman world build on a fork's CI, and sandbox
test.py gives the same results as before. Run tested on qemu-ppce500
(btrfs) and qemu_arm (btrfs, squashfs, mmc erase), and on a Turris 1.1
with the mpc85xx LTO patches on top, which boots from an SD card and
loads files from btrfs. The PAMU change is build tested only.

[1] https://lore.kernel.org/u-boot/20261119133310.22732-5-pepe.schlehofer@gmail.com/
[2] https://lore.kernel.org/u-boot/20261119200924.GB3176972@bill-the-cat/
[3] https://lore.kernel.org/u-boot/20261125095537.37979-1-pepe.schlehofer@gmail.com/

Josef Schlehofer (6):
  fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread()
  fs/squashfs: Avoid 64-bit divisions
  mmc: Use div_u64() in mmc_berase()
  powerpc: mpc8xxx: Avoid a 64-bit division in get_win_cnt()
  fs: btrfs: Remove the unused dev.c
  fs: btrfs: Avoid the remaining 64-bit divisions

 arch/powerpc/cpu/mpc8xxx/fsl_pamu.c |  2 +-
 drivers/mmc/mmc_write.c             |  2 +-
 fs/btrfs/Makefile                   |  2 +-
 fs/btrfs/compat.h                   |  8 ++------
 fs/btrfs/dev.c                      | 25 -------------------------
 fs/btrfs/volumes.c                  | 19 +++++++++++--------
 fs/btrfs/volumes.h                  |  9 +++++----
 fs/squashfs/sqfs.c                  | 21 +++++++++++----------
 fs/squashfs/sqfs_inode.c            |  5 +++--
 9 files changed, 35 insertions(+), 58 deletions(-)
 delete mode 100644 fs/btrfs/dev.c


base-commit: 79497816056122c49b3b135e14cbac59374e636c
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/6] fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread()
  2026-11-25 12:42 [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Josef Schlehofer
@ 2026-11-25 12:42 ` Josef Schlehofer
  2026-11-25 20:11   ` Qu Wenruo
  2026-11-25 12:42 ` [PATCH 2/6] fs/squashfs: Avoid 64-bit divisions Josef Schlehofer
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Josef Schlehofer @ 2026-11-25 12:42 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	linux-btrfs, Marek Behún, Qu Wenruo

On 32-bit PowerPC, GCC turns the u64 '%' in __btrfs_devread() into a
call to __umoddi3(), which U-Boot's private libgcc does not provide.

The shift by log2blksz on the line above already requires a power-of-two
block size, so take the offset within the block with a mask.

Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Cc: Marek Behún <kabel@kernel.org>
Cc: Qu Wenruo <wqu@suse.com>
Cc: Tom Rini <trini@konsulko.com>
---
 fs/btrfs/compat.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h
index 4596b9d1dd3..e6784884835 100644
--- a/fs/btrfs/compat.h
+++ b/fs/btrfs/compat.h
@@ -60,7 +60,7 @@ static inline int __btrfs_devread(struct blk_desc *desc,
 	int ret;
 
 	sector = offset >> desc->log2blksz;
-	byte_offset = offset % desc->blksz;
+	byte_offset = offset & (desc->blksz - 1);
 
 	/* fs_devread() return 0 for error, >0 for success */
 	ret = fs_devread(desc, part, sector, byte_offset, size, buf);
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/6] fs/squashfs: Avoid 64-bit divisions
  2026-11-25 12:42 [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Josef Schlehofer
  2026-11-25 12:42 ` [PATCH 1/6] fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread() Josef Schlehofer
@ 2026-11-25 12:42 ` Josef Schlehofer
  2026-11-25 12:42 ` [PATCH 3/6] mmc: Use div_u64() in mmc_berase() Josef Schlehofer
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Josef Schlehofer @ 2026-11-25 12:42 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	Joao Marcos Costa, Richard Genoud, Thomas Petazzoni,
	Miquel Raynal

On 32-bit PowerPC, GCC turns '/' on u64 values into calls to
__udivdi3(), which U-Boot's private libgcc does not provide.

Use lldiv() and DIV_ROUND_UP_ULL(), as commit 92080c6ef6c7 ("fs/squashfs:
use lldiv function for math") and commit aeea67f9a033 ("fs/squashfs: use
lldiv function for math") already did for other divisions here. The
divisors are block sizes and fit into 32 bits.

Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Cc: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
Cc: Richard Genoud <richard.genoud@bootlin.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Tom Rini <trini@konsulko.com>
---
 fs/squashfs/sqfs.c       | 21 +++++++++++----------
 fs/squashfs/sqfs_inode.c |  5 +++--
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index 0ea6dcaba1a..7b4f1310c00 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -95,7 +95,7 @@ static int sqfs_calc_n_blks(__le64 start, __le64 end, u64 *offset)
 	start_ = lldiv(le64_to_cpu(start), ctxt.cur_dev->blksz);
 	*offset = le64_to_cpu(start) - (start_ * ctxt.cur_dev->blksz);
 
-	return DIV_ROUND_UP(table_size + *offset, ctxt.cur_dev->blksz);
+	return DIV_ROUND_UP_ULL(table_size + *offset, ctxt.cur_dev->blksz);
 }
 
 /*
@@ -131,7 +131,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
 	n_blks = sqfs_calc_n_blks(sblk->fragment_table_start,
 				  cpu_to_le64(end), &table_offset);
 
-	start /= ctxt.cur_dev->blksz;
+	start = lldiv(start, ctxt.cur_dev->blksz);
 
 	/* Allocate a proper sized buffer to store the fragment index table */
 	if (__builtin_mul_overflow(n_blks, ctxt.cur_dev->blksz, &table_size)) {
@@ -170,7 +170,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
 	start_block = get_unaligned_le64(table + table_offset + block *
 					 sizeof(u64));
 
-	start = start_block / ctxt.cur_dev->blksz;
+	start = lldiv(start_block, ctxt.cur_dev->blksz);
 	n_blks = sqfs_calc_n_blks(cpu_to_le64(start_block),
 				  sblk->fragment_table_start, &table_offset);
 
@@ -792,8 +792,8 @@ static int sqfs_read_inode_table(unsigned char **inode_table, size_t *out_size)
 
 	table_size = get_unaligned_le64(&sblk->directory_table_start) -
 		get_unaligned_le64(&sblk->inode_table_start);
-	start = get_unaligned_le64(&sblk->inode_table_start) /
-		ctxt.cur_dev->blksz;
+	start = lldiv(get_unaligned_le64(&sblk->inode_table_start),
+		      ctxt.cur_dev->blksz);
 	n_blks = sqfs_calc_n_blks(sblk->inode_table_start,
 				  sblk->directory_table_start, &table_offset);
 
@@ -888,8 +888,8 @@ static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list)
 	/* DIRECTORY TABLE */
 	table_size = get_unaligned_le64(&sblk->fragment_table_start) -
 		get_unaligned_le64(&sblk->directory_table_start);
-	start = get_unaligned_le64(&sblk->directory_table_start) /
-		ctxt.cur_dev->blksz;
+	start = lldiv(get_unaligned_le64(&sblk->directory_table_start),
+		      ctxt.cur_dev->blksz);
 	n_blks = sqfs_calc_n_blks(sblk->directory_table_start,
 				  sblk->fragment_table_start, &table_offset);
 
@@ -1603,8 +1603,8 @@ static int sqfs_read_nest(const char *filename, void *buf, loff_t offset,
 		start = lldiv(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,
-				      ctxt.cur_dev->blksz);
+		n_blks = DIV_ROUND_UP_ULL(table_size + table_offset,
+					  ctxt.cur_dev->blksz);
 
 		/* Don't load any data for sparse blocks */
 		if (finfo.blk_sizes[j] == 0) {
@@ -1677,7 +1677,8 @@ static int sqfs_read_nest(const char *filename, void *buf, loff_t offset,
 	start = lldiv(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);
+	n_blks = DIV_ROUND_UP_ULL(table_size + table_offset,
+				  ctxt.cur_dev->blksz);
 
 	if (__builtin_mul_overflow(n_blks, ctxt.cur_dev->blksz, &buf_size)) {
 		ret = -EINVAL;
diff --git a/fs/squashfs/sqfs_inode.c b/fs/squashfs/sqfs_inode.c
index 20085f8912b..d43277f06e7 100644
--- a/fs/squashfs/sqfs_inode.c
+++ b/fs/squashfs/sqfs_inode.c
@@ -7,6 +7,7 @@
 
 #include <asm/unaligned.h>
 #include <compiler.h>
+#include <div64.h>
 #include <errno.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -122,9 +123,9 @@ int sqfs_inode_size(struct squashfs_base_inode *inode, u32 blk_size, size_t max)
 			return -EINVAL;
 
 		if (fragment == 0xFFFFFFFF)
-			blk_list_size = DIV_ROUND_UP(file_size, blk_size);
+			blk_list_size = DIV_ROUND_UP_ULL(file_size, blk_size);
 		else
-			blk_list_size = file_size / blk_size;
+			blk_list_size = lldiv(file_size, blk_size);
 
 		if (__builtin_mul_overflow(blk_list_size, (unsigned int)sizeof(u32),
 					   &blk_list_size) ||
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/6] mmc: Use div_u64() in mmc_berase()
  2026-11-25 12:42 [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Josef Schlehofer
  2026-11-25 12:42 ` [PATCH 1/6] fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread() Josef Schlehofer
  2026-11-25 12:42 ` [PATCH 2/6] fs/squashfs: Avoid 64-bit divisions Josef Schlehofer
@ 2026-11-25 12:42 ` Josef Schlehofer
  2026-11-26  2:10   ` Peng Fan (OSS)
  2026-11-25 12:42 ` [PATCH 4/6] powerpc: mpc8xxx: Avoid a 64-bit division in get_win_cnt() Josef Schlehofer
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Josef Schlehofer @ 2026-11-25 12:42 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan, Peng Fan,
	Jaehoon Chung, Tanmay Kathpalia

With CONFIG_SYS_64BIT_LBA, GCC turns the lbaint_t division in
mmc_berase() into a call to __udivdi3() on 32-bit PowerPC, which
U-Boot's private libgcc does not provide.

Use div_u64(), as the remainders above already use div_u64_rem().

Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Tanmay Kathpalia <tanmay.kathpalia@altera.com>
Cc: Tom Rini <trini@konsulko.com>
---
 drivers/mmc/mmc_write.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
index e739720b77c..ce0592aa659 100644
--- a/drivers/mmc/mmc_write.c
+++ b/drivers/mmc/mmc_write.c
@@ -126,7 +126,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt)
 			blk_r = ((blkcnt - blk) > mmc->erase_grp_size) ?
 				mmc->erase_grp_size : (blkcnt - blk);
 
-			grpcnt = (blkcnt - blk) / mmc->erase_grp_size;
+			grpcnt = div_u64(blkcnt - blk, mmc->erase_grp_size);
 			/* Max 2GB per spec */
 			if ((blkcnt - blk) > 0x400000)
 				blk_r = 0x400000;
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/6] powerpc: mpc8xxx: Avoid a 64-bit division in get_win_cnt()
  2026-11-25 12:42 [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Josef Schlehofer
                   ` (2 preceding siblings ...)
  2026-11-25 12:42 ` [PATCH 3/6] mmc: Use div_u64() in mmc_berase() Josef Schlehofer
@ 2026-11-25 12:42 ` Josef Schlehofer
  2026-11-25 15:53   ` Bradley Morgan
  2026-11-25 12:42 ` [PATCH 5/6] fs: btrfs: Remove the unused dev.c Josef Schlehofer
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Josef Schlehofer @ 2026-11-25 12:42 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan

GCC turns the u64 division in get_win_cnt() into a call to __udivdi3(),
which U-Boot's private libgcc does not provide.

Compare size with the product of win_cnt and PAMU_PAGE_SIZE instead.
For a non-zero win_cnt, size / win_cnt < PAMU_PAGE_SIZE holds exactly
when size < win_cnt * PAMU_PAGE_SIZE, and the product is at most
128 * 4096.

Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Cc: Bradley Morgan <bradley.morgan@linux.dev>
Cc: Tom Rini <trini@konsulko.com>
---
 arch/powerpc/cpu/mpc8xxx/fsl_pamu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c b/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
index 638c3a6fee5..b6f8552d7d8 100644
--- a/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
+++ b/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
@@ -364,7 +364,7 @@ static uint32_t get_win_cnt(uint64_t size)
 {
 	uint32_t win_cnt = DEFAULT_NUM_SUBWINDOWS;
 
-	while (win_cnt && (size/win_cnt) < PAMU_PAGE_SIZE)
+	while (win_cnt && size < (uint64_t)win_cnt * PAMU_PAGE_SIZE)
 		win_cnt >>= 1;
 
 	return win_cnt;
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 5/6] fs: btrfs: Remove the unused dev.c
  2026-11-25 12:42 [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Josef Schlehofer
                   ` (3 preceding siblings ...)
  2026-11-25 12:42 ` [PATCH 4/6] powerpc: mpc8xxx: Avoid a 64-bit division in get_win_cnt() Josef Schlehofer
@ 2026-11-25 12:42 ` Josef Schlehofer
  2026-11-25 20:14   ` Qu Wenruo
  2026-11-25 12:42 ` [PATCH 6/6] fs: btrfs: Avoid the remaining 64-bit divisions Josef Schlehofer
  2026-11-25 15:45 ` [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Bradley Morgan
  6 siblings, 1 reply; 16+ messages in thread
From: Josef Schlehofer @ 2026-11-25 12:42 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	linux-btrfs, Marek Behún, Qu Wenruo

Nothing uses btrfs_devread(), btrfs_blk_desc or btrfs_part_info, which
are all that fs/btrfs/dev.c defines. On 32-bit PowerPC, GCC turns the
u64 '%' in btrfs_devread() into a call to __umoddi3(), which U-Boot's
private libgcc does not provide.

Remove the file.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Cc: Marek Behún <kabel@kernel.org>
Cc: Qu Wenruo <wqu@suse.com>
Cc: Tom Rini <trini@konsulko.com>
---
 fs/btrfs/Makefile |  2 +-
 fs/btrfs/dev.c    | 25 -------------------------
 2 files changed, 1 insertion(+), 26 deletions(-)
 delete mode 100644 fs/btrfs/dev.c

diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index 31b426d572a..79d96c6e0ca 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -2,6 +2,6 @@
 #
 # 2017 Marek Behún, CZ.NIC, kabel@kernel.org
 
-obj-y := btrfs.o compression.o ctree.o dev.o dir-item.o \
+obj-y := btrfs.o compression.o ctree.o dir-item.o \
 	extent-io.o inode.o subvolume.o crypto/hash.o disk-io.o \
 	common/rbtree-utils.o extent-cache.o volumes.o root-tree.o
diff --git a/fs/btrfs/dev.c b/fs/btrfs/dev.c
deleted file mode 100644
index e27a032c9f6..00000000000
--- a/fs/btrfs/dev.c
+++ /dev/null
@@ -1,25 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * BTRFS filesystem implementation for U-Boot
- *
- * 2017 Marek Behún, CZ.NIC, kabel@kernel.org
- */
-
-#include <blk.h>
-#include <compiler.h>
-#include <fs_internal.h>
-
-struct blk_desc *btrfs_blk_desc;
-struct disk_partition *btrfs_part_info;
-
-int btrfs_devread(u64 address, int byte_len, void *buf)
-{
-	lbaint_t sector;
-	int byte_offset;
-
-	sector = address >> btrfs_blk_desc->log2blksz;
-	byte_offset = address % btrfs_blk_desc->blksz;
-
-	return fs_devread(btrfs_blk_desc, btrfs_part_info, sector, byte_offset,
-			  byte_len, buf);
-}
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 6/6] fs: btrfs: Avoid the remaining 64-bit divisions
  2026-11-25 12:42 [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Josef Schlehofer
                   ` (4 preceding siblings ...)
  2026-11-25 12:42 ` [PATCH 5/6] fs: btrfs: Remove the unused dev.c Josef Schlehofer
@ 2026-11-25 12:42 ` Josef Schlehofer
  2026-11-25 20:15   ` Qu Wenruo
  2026-11-25 15:45 ` [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Bradley Morgan
  6 siblings, 1 reply; 16+ messages in thread
From: Josef Schlehofer @ 2026-11-25 12:42 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	linux-btrfs, Marek Behún, Qu Wenruo

On 32-bit PowerPC, GCC turns the u64 divisions in btrfs_stripe_length()
and in the RAID5/6 code of __btrfs_map_block() into calls to
__udivdi3(), which U-Boot's private libgcc does not provide.
calc_stripe_length() has the same divisions.

U-Boot never runs these divisions. btrfs_stripe_length() and
calc_stripe_length() have no caller, and the RAID5/6 divisions sit in
the branch that fills a raid map, which needs a raid_map_ret. Both
callers of btrfs_map_block() set it to NULL. Builds of turris_1x_nor
and turris_1x_sdcard still link that branch, and with it __udivdi3().

Use div_u64(). Its divisors fit into 32 bits: num_stripes is a u32 or
an int and stripe_len is an int. full_stripe_len is the product of two
ints, so declare it as a u32.

linux/math64.h pulls in linux/log2.h, whose is_power_of_2() conflicts
with the copy in compat.h, which returns int instead of bool. Include
linux/log2.h in compat.h and drop the copy.

Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Cc: Marek Behún <kabel@kernel.org>
Cc: Qu Wenruo <wqu@suse.com>
Cc: Tom Rini <trini@konsulko.com>
---
 fs/btrfs/compat.h  |  6 +-----
 fs/btrfs/volumes.c | 19 +++++++++++--------
 fs/btrfs/volumes.h |  9 +++++----
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h
index e6784884835..f973f3f1185 100644
--- a/fs/btrfs/compat.h
+++ b/fs/btrfs/compat.h
@@ -4,6 +4,7 @@
 #define __BTRFS_COMPAT_H__
 
 #include <linux/errno.h>
+#include <linux/log2.h>
 #include <fs_internal.h>
 #include <u-boot/uuid.h>
 
@@ -74,9 +75,4 @@ static inline void uuid_unparse(const u8 *uuid, char *out)
 	return uuid_bin_to_str((unsigned char *)uuid, out, 0);
 }
 
-static inline int is_power_of_2(unsigned long n)
-{
-	return (n != 0 && ((n & (n - 1)) == 0));
-}
-
 #endif
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 71b0b55b9c6..fcb20a761f5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <fs_internal.h>
+#include <linux/math64.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "volumes.h"
@@ -825,17 +826,17 @@ u64 btrfs_stripe_length(struct btrfs_fs_info *fs_info,
 		stripe_len = chunk_len;
 		break;
 	case BTRFS_BLOCK_GROUP_RAID0:
-		stripe_len = chunk_len / num_stripes;
+		stripe_len = div_u64(chunk_len, num_stripes);
 		break;
 	case BTRFS_BLOCK_GROUP_RAID5:
-		stripe_len = chunk_len / (num_stripes - 1);
+		stripe_len = div_u64(chunk_len, num_stripes - 1);
 		break;
 	case BTRFS_BLOCK_GROUP_RAID6:
-		stripe_len = chunk_len / (num_stripes - 2);
+		stripe_len = div_u64(chunk_len, num_stripes - 2);
 		break;
 	case BTRFS_BLOCK_GROUP_RAID10:
-		stripe_len = chunk_len / (num_stripes /
-				btrfs_chunk_sub_stripes(leaf, chunk));
+		stripe_len = div_u64(chunk_len, num_stripes /
+				     btrfs_chunk_sub_stripes(leaf, chunk));
 		break;
 	default:
 		/* Invalid chunk profile found */
@@ -1085,17 +1086,19 @@ again:
 			int rot;
 			u64 tmp;
 			u64 raid56_full_stripe_start;
-			u64 full_stripe_len = nr_data_stripes(map) * map->stripe_len;
+			u32 full_stripe_len = nr_data_stripes(map) * map->stripe_len;
 
 			/*
 			 * align the start of our data stripe in the logical
 			 * address space
 			 */
-			raid56_full_stripe_start = offset / full_stripe_len;
+			raid56_full_stripe_start = div_u64(offset,
+							   full_stripe_len);
 			raid56_full_stripe_start *= full_stripe_len;
 
 			/* get the data stripe number */
-			stripe_nr = raid56_full_stripe_start / map->stripe_len;
+			stripe_nr = div_u64(raid56_full_stripe_start,
+					    map->stripe_len);
 			stripe_nr = stripe_nr / nr_data_stripes(map);
 
 			/* Work out the disk rotation on this stripe-set */
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 9d1a07ae789..d66547c6c10 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -4,6 +4,7 @@
 #define __BTRFS_VOLUMES_H__
 
 #include <fs_internal.h>
+#include <linux/math64.h>
 #include "ctree.h"
 
 #define BTRFS_STRIPE_LEN	SZ_64K
@@ -138,16 +139,16 @@ static inline u64 calc_stripe_length(u64 type, u64 length, int num_stripes)
 
 	if (type & BTRFS_BLOCK_GROUP_RAID0) {
 		stripe_size = length;
-		stripe_size /= num_stripes;
+		stripe_size = div_u64(stripe_size, num_stripes);
 	} else if (type & BTRFS_BLOCK_GROUP_RAID10) {
 		stripe_size = length * 2;
-		stripe_size /= num_stripes;
+		stripe_size = div_u64(stripe_size, num_stripes);
 	} else if (type & BTRFS_BLOCK_GROUP_RAID5) {
 		stripe_size = length;
-		stripe_size /= (num_stripes - 1);
+		stripe_size = div_u64(stripe_size, num_stripes - 1);
 	} else if (type & BTRFS_BLOCK_GROUP_RAID6) {
 		stripe_size = length;
-		stripe_size /= (num_stripes - 2);
+		stripe_size = div_u64(stripe_size, num_stripes - 2);
 	} else {
 		stripe_size = length;
 	}
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3()
  2026-11-25 12:42 [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Josef Schlehofer
                   ` (5 preceding siblings ...)
  2026-11-25 12:42 ` [PATCH 6/6] fs: btrfs: Avoid the remaining 64-bit divisions Josef Schlehofer
@ 2026-11-25 15:45 ` Bradley Morgan
  2026-11-25 15:51   ` Tom Rini
  6 siblings, 1 reply; 16+ messages in thread
From: Bradley Morgan @ 2026-11-25 15:45 UTC (permalink / raw)
  To: Josef Schlehofer, u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Marek Behún,
	Qu Wenruo, Joao Marcos Costa, Richard Genoud, Thomas Petazzoni,
	Miquel Raynal, Peng Fan, Jaehoon Chung, Tanmay Kathpalia,
	linux-btrfs

On 25 November 2026 12:42:53 GMT, Josef Schlehofer
<pepe.schlehofer@gmail.com> wrote:
>U-Boot's private libgcc does not provide __udivdi3() and __umoddi3().
>v3 of the mpc85xx LTO series links mpc85xx LTO builds with it and added
>both routines [1]. Christophe Leroy asked why the callers do not avoid
>'/' and '%' on 64-bit operands instead, and Tom Rini asked to update
>the common code [2].
>
>Patches 1-4 avoid the divisions that make the mpc85xx LTO builds call
>__udivdi3() or __umoddi3(), in btrfs, squashfs, mmc_berase() and
>get_win_cnt() of the mpc8xxx PAMU code. They do not depend on each
>other. Patch 5 removes fs/btrfs/dev.c, which nothing uses and which
>holds another 64-bit modulo. Patch 6 converts the remaining divisions
>in btrfs. U-Boot never runs them, but builds without LTO still link the
>ones in the RAID5/6 code. My reply in that thread announced these
>conversions for v4 of the LTO series. They are sent on their own
>instead.
>
>Patch 2 and my big-endian fix for squashfs [3] conflict in
>sqfs_read_nest(). I will rebase whichever of them goes in second.
>
>Build tested with a buildman world build on a fork's CI, and sandbox
>test.py gives the same results as before. Run tested on qemu-ppce500
>(btrfs) and qemu_arm (btrfs, squashfs, mmc erase), and on a Turris 1.1
>with the mpc85xx LTO patches on top, which boots from an SD card and
>loads files from btrfs. The PAMU change is build tested only.
>
>[1]
>https://lore.kernel.org/u-boot/20261119133310.22732-5-pepe.schlehofer@gmail.com/
>[2] https://lore.kernel.org/u-boot/20261119200924.GB3176972@bill-the-cat/
>[3]
>https://lore.kernel.org/u-boot/20261125095537.37979-1-pepe.schlehofer@gmail.com/


Thanks,  after review, who will merge? Me? Or anyone else up to?

>
>Josef Schlehofer (6):
>  fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread()
>  fs/squashfs: Avoid 64-bit divisions
>  mmc: Use div_u64() in mmc_berase()
>  powerpc: mpc8xxx: Avoid a 64-bit division in get_win_cnt()
>  fs: btrfs: Remove the unused dev.c
>  fs: btrfs: Avoid the remaining 64-bit divisions
>
> arch/powerpc/cpu/mpc8xxx/fsl_pamu.c |  2 +-
> drivers/mmc/mmc_write.c             |  2 +-
> fs/btrfs/Makefile                   |  2 +-
> fs/btrfs/compat.h                   |  8 ++------
> fs/btrfs/dev.c                      | 25 -------------------------
> fs/btrfs/volumes.c                  | 19 +++++++++++--------
> fs/btrfs/volumes.h                  |  9 +++++----
> fs/squashfs/sqfs.c                  | 21 +++++++++++----------
> fs/squashfs/sqfs_inode.c            |  5 +++--
> 9 files changed, 35 insertions(+), 58 deletions(-)
> delete mode 100644 fs/btrfs/dev.c
>
>
>base-commit: 79497816056122c49b3b135e14cbac59374e636c
>

--- Thanks!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3()
  2026-11-25 15:45 ` [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Bradley Morgan
@ 2026-11-25 15:51   ` Tom Rini
  0 siblings, 0 replies; 16+ messages in thread
From: Tom Rini @ 2026-11-25 15:51 UTC (permalink / raw)
  To: Bradley Morgan
  Cc: Josef Schlehofer, u-boot, Christophe Leroy (CS GROUP),
	Marek Behún, Qu Wenruo, Joao Marcos Costa, Richard Genoud,
	Thomas Petazzoni, Miquel Raynal, Peng Fan, Jaehoon Chung,
	Tanmay Kathpalia, linux-btrfs

[-- Attachment #1: Type: text/plain, Size: 2000 bytes --]

On Wed, Nov 25, 2026 at 03:45:12PM +0000, Bradley Morgan wrote:
> On 25 November 2026 12:42:53 GMT, Josef Schlehofer
> <pepe.schlehofer@gmail.com> wrote:
> >U-Boot's private libgcc does not provide __udivdi3() and __umoddi3().
> >v3 of the mpc85xx LTO series links mpc85xx LTO builds with it and added
> >both routines [1]. Christophe Leroy asked why the callers do not avoid
> >'/' and '%' on 64-bit operands instead, and Tom Rini asked to update
> >the common code [2].
> >
> >Patches 1-4 avoid the divisions that make the mpc85xx LTO builds call
> >__udivdi3() or __umoddi3(), in btrfs, squashfs, mmc_berase() and
> >get_win_cnt() of the mpc8xxx PAMU code. They do not depend on each
> >other. Patch 5 removes fs/btrfs/dev.c, which nothing uses and which
> >holds another 64-bit modulo. Patch 6 converts the remaining divisions
> >in btrfs. U-Boot never runs them, but builds without LTO still link the
> >ones in the RAID5/6 code. My reply in that thread announced these
> >conversions for v4 of the LTO series. They are sent on their own
> >instead.
> >
> >Patch 2 and my big-endian fix for squashfs [3] conflict in
> >sqfs_read_nest(). I will rebase whichever of them goes in second.
> >
> >Build tested with a buildman world build on a fork's CI, and sandbox
> >test.py gives the same results as before. Run tested on qemu-ppce500
> >(btrfs) and qemu_arm (btrfs, squashfs, mmc erase), and on a Turris 1.1
> >with the mpc85xx LTO patches on top, which boots from an SD card and
> >loads files from btrfs. The PAMU change is build tested only.
> >
> >[1]
> >https://lore.kernel.org/u-boot/20261119133310.22732-5-pepe.schlehofer@gmail.com/
> >[2] https://lore.kernel.org/u-boot/20261119200924.GB3176972@bill-the-cat/
> >[3]
> >https://lore.kernel.org/u-boot/20261125095537.37979-1-pepe.schlehofer@gmail.com/
> 
> 
> Thanks,  after review, who will merge? Me? Or anyone else up to?

I'll pick up the series, once there's been enough review on it.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/6] powerpc: mpc8xxx: Avoid a 64-bit division in get_win_cnt()
  2026-11-25 12:42 ` [PATCH 4/6] powerpc: mpc8xxx: Avoid a 64-bit division in get_win_cnt() Josef Schlehofer
@ 2026-11-25 15:53   ` Bradley Morgan
  0 siblings, 0 replies; 16+ messages in thread
From: Bradley Morgan @ 2026-11-25 15:53 UTC (permalink / raw)
  To: Josef Schlehofer, u-boot; +Cc: Tom Rini, Christophe Leroy (CS GROUP)

On 25 November 2026 12:42:57 GMT, Josef Schlehofer
<pepe.schlehofer@gmail.com> wrote:
>GCC turns the u64 division in get_win_cnt() into a call to __udivdi3(),
>which U-Boot's private libgcc does not provide.
>
>Compare size with the product of win_cnt and PAMU_PAGE_SIZE instead.
>For a non-zero win_cnt, size / win_cnt < PAMU_PAGE_SIZE holds exactly
>when size < win_cnt * PAMU_PAGE_SIZE, and the product is at most
>128 * 4096.
>
>Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
>Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
>Cc: Bradley Morgan <bradley.morgan@linux.dev>

Acked-by: Bradley Morgan <bradley.morgan@linux.dev> # PowerPC


>Cc: Tom Rini <trini@konsulko.com>
>---
> arch/powerpc/cpu/mpc8xxx/fsl_pamu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c b/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
>index 638c3a6fee5..b6f8552d7d8 100644
>--- a/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
>+++ b/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
>@@ -364,7 +364,7 @@ static uint32_t get_win_cnt(uint64_t size)
> {
> 	uint32_t win_cnt = DEFAULT_NUM_SUBWINDOWS;
> 
>-	while (win_cnt && (size/win_cnt) < PAMU_PAGE_SIZE)
>+	while (win_cnt && size < (uint64_t)win_cnt * PAMU_PAGE_SIZE)
> 		win_cnt >>= 1;
> 
> 	return win_cnt;
>

--- Thanks!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/6] fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread()
  2026-11-25 12:42 ` [PATCH 1/6] fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread() Josef Schlehofer
@ 2026-11-25 20:11   ` Qu Wenruo
  0 siblings, 0 replies; 16+ messages in thread
From: Qu Wenruo @ 2026-11-25 20:11 UTC (permalink / raw)
  To: Josef Schlehofer, u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	linux-btrfs, Marek Behún



在 2026/11/25 23:12, Josef Schlehofer 写道:
> On 32-bit PowerPC, GCC turns the u64 '%' in __btrfs_devread() into a
> call to __umoddi3(), which U-Boot's private libgcc does not provide.
> 
> The shift by log2blksz on the line above already requires a power-of-two
> block size, so take the offset within the block with a mask.
> 
> Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
> Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
> Cc: Marek Behún <kabel@kernel.org>
> Cc: Qu Wenruo <wqu@suse.com>
> Cc: Tom Rini <trini@konsulko.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   fs/btrfs/compat.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h
> index 4596b9d1dd3..e6784884835 100644
> --- a/fs/btrfs/compat.h
> +++ b/fs/btrfs/compat.h
> @@ -60,7 +60,7 @@ static inline int __btrfs_devread(struct blk_desc *desc,
>   	int ret;
>   
>   	sector = offset >> desc->log2blksz;
> -	byte_offset = offset % desc->blksz;
> +	byte_offset = offset & (desc->blksz - 1);
>   
>   	/* fs_devread() return 0 for error, >0 for success */
>   	ret = fs_devread(desc, part, sector, byte_offset, size, buf);


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] fs: btrfs: Remove the unused dev.c
  2026-11-25 12:42 ` [PATCH 5/6] fs: btrfs: Remove the unused dev.c Josef Schlehofer
@ 2026-11-25 20:14   ` Qu Wenruo
  2026-11-26  9:15     ` Josef Schlehofer
  0 siblings, 1 reply; 16+ messages in thread
From: Qu Wenruo @ 2026-11-25 20:14 UTC (permalink / raw)
  To: Josef Schlehofer, u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	linux-btrfs, Marek Behún



在 2026/11/25 23:12, Josef Schlehofer 写道:
> Nothing uses btrfs_devread(), btrfs_blk_desc or btrfs_part_info, which
> are all that fs/btrfs/dev.c defines. On 32-bit PowerPC, GCC turns the
> u64 '%' in btrfs_devread() into a call to __umoddi3(), which U-Boot's
> private libgcc does not provide.
> 
> Remove the file.
> 
> Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
> Cc: Marek Behún <kabel@kernel.org>
> Cc: Qu Wenruo <wqu@suse.com>
> Cc: Tom Rini <trini@konsulko.com>

The removal looks fine to me, however since there are only 
__btrfs_devread() callers, it would make more sense to rename 
__btrfs_devread() to btrfs_devread().

Thanks,
Qu
> ---
>   fs/btrfs/Makefile |  2 +-
>   fs/btrfs/dev.c    | 25 -------------------------
>   2 files changed, 1 insertion(+), 26 deletions(-)
>   delete mode 100644 fs/btrfs/dev.c
> 
> diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
> index 31b426d572a..79d96c6e0ca 100644
> --- a/fs/btrfs/Makefile
> +++ b/fs/btrfs/Makefile
> @@ -2,6 +2,6 @@
>   #
>   # 2017 Marek Behún, CZ.NIC, kabel@kernel.org
>   
> -obj-y := btrfs.o compression.o ctree.o dev.o dir-item.o \
> +obj-y := btrfs.o compression.o ctree.o dir-item.o \
>   	extent-io.o inode.o subvolume.o crypto/hash.o disk-io.o \
>   	common/rbtree-utils.o extent-cache.o volumes.o root-tree.o
> diff --git a/fs/btrfs/dev.c b/fs/btrfs/dev.c
> deleted file mode 100644
> index e27a032c9f6..00000000000
> --- a/fs/btrfs/dev.c
> +++ /dev/null
> @@ -1,25 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0+
> -/*
> - * BTRFS filesystem implementation for U-Boot
> - *
> - * 2017 Marek Behún, CZ.NIC, kabel@kernel.org
> - */
> -
> -#include <blk.h>
> -#include <compiler.h>
> -#include <fs_internal.h>
> -
> -struct blk_desc *btrfs_blk_desc;
> -struct disk_partition *btrfs_part_info;
> -
> -int btrfs_devread(u64 address, int byte_len, void *buf)
> -{
> -	lbaint_t sector;
> -	int byte_offset;
> -
> -	sector = address >> btrfs_blk_desc->log2blksz;
> -	byte_offset = address % btrfs_blk_desc->blksz;
> -
> -	return fs_devread(btrfs_blk_desc, btrfs_part_info, sector, byte_offset,
> -			  byte_len, buf);
> -}


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 6/6] fs: btrfs: Avoid the remaining 64-bit divisions
  2026-11-25 12:42 ` [PATCH 6/6] fs: btrfs: Avoid the remaining 64-bit divisions Josef Schlehofer
@ 2026-11-25 20:15   ` Qu Wenruo
  0 siblings, 0 replies; 16+ messages in thread
From: Qu Wenruo @ 2026-11-25 20:15 UTC (permalink / raw)
  To: Josef Schlehofer, u-boot
  Cc: Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	linux-btrfs, Marek Behún



在 2026/11/25 23:12, Josef Schlehofer 写道:
> On 32-bit PowerPC, GCC turns the u64 divisions in btrfs_stripe_length()
> and in the RAID5/6 code of __btrfs_map_block() into calls to
> __udivdi3(), which U-Boot's private libgcc does not provide.
> calc_stripe_length() has the same divisions.
> 
> U-Boot never runs these divisions. btrfs_stripe_length() and
> calc_stripe_length() have no caller, and the RAID5/6 divisions sit in
> the branch that fills a raid map, which needs a raid_map_ret. Both
> callers of btrfs_map_block() set it to NULL. Builds of turris_1x_nor
> and turris_1x_sdcard still link that branch, and with it __udivdi3().
> 
> Use div_u64(). Its divisors fit into 32 bits: num_stripes is a u32 or
> an int and stripe_len is an int. full_stripe_len is the product of two
> ints, so declare it as a u32.
> 
> linux/math64.h pulls in linux/log2.h, whose is_power_of_2() conflicts
> with the copy in compat.h, which returns int instead of bool. Include
> linux/log2.h in compat.h and drop the copy.
> 
> Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
> Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
> Cc: Marek Behún <kabel@kernel.org>
> Cc: Qu Wenruo <wqu@suse.com>
> Cc: Tom Rini <trini@konsulko.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   fs/btrfs/compat.h  |  6 +-----
>   fs/btrfs/volumes.c | 19 +++++++++++--------
>   fs/btrfs/volumes.h |  9 +++++----
>   3 files changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h
> index e6784884835..f973f3f1185 100644
> --- a/fs/btrfs/compat.h
> +++ b/fs/btrfs/compat.h
> @@ -4,6 +4,7 @@
>   #define __BTRFS_COMPAT_H__
>   
>   #include <linux/errno.h>
> +#include <linux/log2.h>
>   #include <fs_internal.h>
>   #include <u-boot/uuid.h>
>   
> @@ -74,9 +75,4 @@ static inline void uuid_unparse(const u8 *uuid, char *out)
>   	return uuid_bin_to_str((unsigned char *)uuid, out, 0);
>   }
>   
> -static inline int is_power_of_2(unsigned long n)
> -{
> -	return (n != 0 && ((n & (n - 1)) == 0));
> -}
> -
>   #endif
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 71b0b55b9c6..fcb20a761f5 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2,6 +2,7 @@
>   #include <stdlib.h>
>   #include <errno.h>
>   #include <fs_internal.h>
> +#include <linux/math64.h>
>   #include "ctree.h"
>   #include "disk-io.h"
>   #include "volumes.h"
> @@ -825,17 +826,17 @@ u64 btrfs_stripe_length(struct btrfs_fs_info *fs_info,
>   		stripe_len = chunk_len;
>   		break;
>   	case BTRFS_BLOCK_GROUP_RAID0:
> -		stripe_len = chunk_len / num_stripes;
> +		stripe_len = div_u64(chunk_len, num_stripes);
>   		break;
>   	case BTRFS_BLOCK_GROUP_RAID5:
> -		stripe_len = chunk_len / (num_stripes - 1);
> +		stripe_len = div_u64(chunk_len, num_stripes - 1);
>   		break;
>   	case BTRFS_BLOCK_GROUP_RAID6:
> -		stripe_len = chunk_len / (num_stripes - 2);
> +		stripe_len = div_u64(chunk_len, num_stripes - 2);
>   		break;
>   	case BTRFS_BLOCK_GROUP_RAID10:
> -		stripe_len = chunk_len / (num_stripes /
> -				btrfs_chunk_sub_stripes(leaf, chunk));
> +		stripe_len = div_u64(chunk_len, num_stripes /
> +				     btrfs_chunk_sub_stripes(leaf, chunk));
>   		break;
>   	default:
>   		/* Invalid chunk profile found */
> @@ -1085,17 +1086,19 @@ again:
>   			int rot;
>   			u64 tmp;
>   			u64 raid56_full_stripe_start;
> -			u64 full_stripe_len = nr_data_stripes(map) * map->stripe_len;
> +			u32 full_stripe_len = nr_data_stripes(map) * map->stripe_len;
>   
>   			/*
>   			 * align the start of our data stripe in the logical
>   			 * address space
>   			 */
> -			raid56_full_stripe_start = offset / full_stripe_len;
> +			raid56_full_stripe_start = div_u64(offset,
> +							   full_stripe_len);
>   			raid56_full_stripe_start *= full_stripe_len;
>   
>   			/* get the data stripe number */
> -			stripe_nr = raid56_full_stripe_start / map->stripe_len;
> +			stripe_nr = div_u64(raid56_full_stripe_start,
> +					    map->stripe_len);
>   			stripe_nr = stripe_nr / nr_data_stripes(map);
>   
>   			/* Work out the disk rotation on this stripe-set */
> diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
> index 9d1a07ae789..d66547c6c10 100644
> --- a/fs/btrfs/volumes.h
> +++ b/fs/btrfs/volumes.h
> @@ -4,6 +4,7 @@
>   #define __BTRFS_VOLUMES_H__
>   
>   #include <fs_internal.h>
> +#include <linux/math64.h>
>   #include "ctree.h"
>   
>   #define BTRFS_STRIPE_LEN	SZ_64K
> @@ -138,16 +139,16 @@ static inline u64 calc_stripe_length(u64 type, u64 length, int num_stripes)
>   
>   	if (type & BTRFS_BLOCK_GROUP_RAID0) {
>   		stripe_size = length;
> -		stripe_size /= num_stripes;
> +		stripe_size = div_u64(stripe_size, num_stripes);
>   	} else if (type & BTRFS_BLOCK_GROUP_RAID10) {
>   		stripe_size = length * 2;
> -		stripe_size /= num_stripes;
> +		stripe_size = div_u64(stripe_size, num_stripes);
>   	} else if (type & BTRFS_BLOCK_GROUP_RAID5) {
>   		stripe_size = length;
> -		stripe_size /= (num_stripes - 1);
> +		stripe_size = div_u64(stripe_size, num_stripes - 1);
>   	} else if (type & BTRFS_BLOCK_GROUP_RAID6) {
>   		stripe_size = length;
> -		stripe_size /= (num_stripes - 2);
> +		stripe_size = div_u64(stripe_size, num_stripes - 2);
>   	} else {
>   		stripe_size = length;
>   	}


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/6] mmc: Use div_u64() in mmc_berase()
  2026-11-25 12:42 ` [PATCH 3/6] mmc: Use div_u64() in mmc_berase() Josef Schlehofer
@ 2026-11-26  2:10   ` Peng Fan (OSS)
  0 siblings, 0 replies; 16+ messages in thread
From: Peng Fan (OSS) @ 2026-11-26  2:10 UTC (permalink / raw)
  To: Josef Schlehofer
  Cc: Peng Fan, u-boot, Tom Rini, Christophe Leroy (CS GROUP),
	Bradley Morgan, Peng Fan, Jaehoon Chung, Tanmay Kathpalia

On Wed, 25 Nov 2026 13:42:56 +0100 Josef Schlehofer <pepe.schlehofer@gmail.com> wrote:

> With CONFIG_SYS_64BIT_LBA, GCC turns the lbaint_t division in
> mmc_berase() into a call to __udivdi3() on 32-bit PowerPC, which
> U-Boot's private libgcc does not provide.
> 
> Use div_u64(), as the remainders above already use div_u64_rem().
> 
> Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
> Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>

Reviewed-by: Peng Fan <peng.fan@nxp.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] fs: btrfs: Remove the unused dev.c
  2026-11-25 20:14   ` Qu Wenruo
@ 2026-11-26  9:15     ` Josef Schlehofer
  2026-11-26  9:20       ` Qu Wenruo
  0 siblings, 1 reply; 16+ messages in thread
From: Josef Schlehofer @ 2026-11-26  9:15 UTC (permalink / raw)
  To: Qu Wenruo
  Cc: u-boot, Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	linux-btrfs, Marek Behún

Hi Qu,

On 25. 11. 26 21:14, Qu Wenruo wrote:
> The removal looks fine to me, however since there are only
> __btrfs_devread() callers, it would make more sense to rename
> __btrfs_devread() to btrfs_devread().

Whoa, good catch, I'm not sure at the moment. Happy to leave it as is
for now and do a follow-up once it's merged, or I can send a v2.
Whichever you and Tom prefer.

Josef

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] fs: btrfs: Remove the unused dev.c
  2026-11-26  9:15     ` Josef Schlehofer
@ 2026-11-26  9:20       ` Qu Wenruo
  0 siblings, 0 replies; 16+ messages in thread
From: Qu Wenruo @ 2026-11-26  9:20 UTC (permalink / raw)
  To: Josef Schlehofer, Qu Wenruo
  Cc: u-boot, Tom Rini, Christophe Leroy (CS GROUP), Bradley Morgan,
	linux-btrfs, Marek Behún



在 2026/11/26 19:45, Josef Schlehofer 写道:
> Hi Qu,
> 
> On 25. 11. 26 21:14, Qu Wenruo wrote:
>> The removal looks fine to me, however since there are only
>> __btrfs_devread() callers, it would make more sense to rename
>> __btrfs_devread() to btrfs_devread().
> 
> Whoa, good catch, I'm not sure at the moment. Happy to leave it as is
> for now and do a follow-up once it's merged, or I can send a v2.
> Whichever you and Tom prefer.

Either looks good to me. If there is no other review, I think you can 
wait for merge and got for a follow up.

Otherwise you can go a v2 do the rename in the same patch.

Anyway, the removal itself is fine. So:

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> 
> Josef


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-11-26  9:20 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 12:42 [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Josef Schlehofer
2026-11-25 12:42 ` [PATCH 1/6] fs: btrfs: Avoid a 64-bit modulo in __btrfs_devread() Josef Schlehofer
2026-11-25 20:11   ` Qu Wenruo
2026-11-25 12:42 ` [PATCH 2/6] fs/squashfs: Avoid 64-bit divisions Josef Schlehofer
2026-11-25 12:42 ` [PATCH 3/6] mmc: Use div_u64() in mmc_berase() Josef Schlehofer
2026-11-26  2:10   ` Peng Fan (OSS)
2026-11-25 12:42 ` [PATCH 4/6] powerpc: mpc8xxx: Avoid a 64-bit division in get_win_cnt() Josef Schlehofer
2026-11-25 15:53   ` Bradley Morgan
2026-11-25 12:42 ` [PATCH 5/6] fs: btrfs: Remove the unused dev.c Josef Schlehofer
2026-11-25 20:14   ` Qu Wenruo
2026-11-26  9:15     ` Josef Schlehofer
2026-11-26  9:20       ` Qu Wenruo
2026-11-25 12:42 ` [PATCH 6/6] fs: btrfs: Avoid the remaining 64-bit divisions Josef Schlehofer
2026-11-25 20:15   ` Qu Wenruo
2026-11-25 15:45 ` [PATCH 0/6] Avoid 64-bit divisions that need __udivdi3() or __umoddi3() Bradley Morgan
2026-11-25 15:51   ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox