* [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 5/6] fs: btrfs: Remove the unused dev.c Josef Schlehofer
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ 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] 11+ 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; 11+ 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] 11+ 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
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 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
3 siblings, 1 reply; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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
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 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
3 siblings, 1 reply; 11+ 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] 11+ 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; 11+ 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] 11+ 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
` (2 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
3 siblings, 1 reply; 11+ 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] 11+ 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; 11+ 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] 11+ messages in thread