linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] f2fs: Use div_u64*() for 64-bit divisions
@ 2019-06-20 14:38 Geert Uytterhoeven
  2019-06-21  9:54 ` Chao Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2019-06-20 14:38 UTC (permalink / raw)
  To: Qiuyang Sun, Jaegeuk Kim, Chao Yu
  Cc: linux-f2fs-devel, linux-next, linux-kernel, Geert Uytterhoeven

On 32-bit (e.g. m68k):

    fs/f2fs/gc.o: In function `f2fs_resize_fs':
    gc.c:(.text+0x3056): undefined reference to `__umoddi3'
    gc.c:(.text+0x30c4): undefined reference to `__udivdi3'

Fix this by using div_u64_rem() and div_u64() for 64-by-32 modulo resp.
division operations.

Reported-by: noreply@ellerman.id.au
Fixes: d2ae7494d043bfaf ("f2fs: ioctl for removing a range from F2FS")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
This assumes BLKS_PER_SEC(sbi) is 32-bit.

    #define BLKS_PER_SEC(sbi)                                       \
	    ((sbi)->segs_per_sec * (sbi)->blocks_per_seg)

Notes:
  1. f2fs_sb_info.segs_per_sec and f2fs_sb_info.blocks_per_seg are both
     unsigned int,
  2. The multiplication is done in 32-bit arithmetic, hence the result
     is of type unsigned int.
  3. Is it guaranteed that the result will always fit in 32-bit, or can
     this overflow?
  4. fs/f2fs/debug.c:update_sit_info() assigns BLKS_PER_SEC(sbi) to
     unsigned long long blks_per_sec, anticipating a 64-bit value.
---
 fs/f2fs/gc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 5b1076505ade9f84..c65f87f11de029f4 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1438,13 +1438,15 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
 	unsigned int secs;
 	int gc_mode, gc_type;
 	int err = 0;
+	__u32 rem;
 
 	old_block_count = le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count);
 	if (block_count > old_block_count)
 		return -EINVAL;
 
 	/* new fs size should align to section size */
-	if (block_count % BLKS_PER_SEC(sbi))
+	div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
+	if (rem)
 		return -EINVAL;
 
 	if (block_count == old_block_count)
@@ -1463,7 +1465,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
 	freeze_bdev(sbi->sb->s_bdev);
 
 	shrunk_blocks = old_block_count - block_count;
-	secs = shrunk_blocks / BLKS_PER_SEC(sbi);
+	secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi));
 	spin_lock(&sbi->stat_lock);
 	if (shrunk_blocks + valid_user_blocks(sbi) +
 		sbi->current_reserved_blocks + sbi->unusable_block_count +
-- 
2.17.1


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

* Re: [PATCH -next] f2fs: Use div_u64*() for 64-bit divisions
  2019-06-20 14:38 [PATCH -next] f2fs: Use div_u64*() for 64-bit divisions Geert Uytterhoeven
@ 2019-06-21  9:54 ` Chao Yu
  2019-06-21  9:55   ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2019-06-21  9:54 UTC (permalink / raw)
  To: Geert Uytterhoeven, Qiuyang Sun, Jaegeuk Kim
  Cc: linux-f2fs-devel, linux-next, linux-kernel

Hi Geert,

Since the original patch hasn't been merged to upstream, I think we can merge
this into original patch, how do you think?

On 2019/6/20 22:38, Geert Uytterhoeven wrote:
> On 32-bit (e.g. m68k):
> 
>     fs/f2fs/gc.o: In function `f2fs_resize_fs':
>     gc.c:(.text+0x3056): undefined reference to `__umoddi3'
>     gc.c:(.text+0x30c4): undefined reference to `__udivdi3'
> 
> Fix this by using div_u64_rem() and div_u64() for 64-by-32 modulo resp.
> division operations.
> 
> Reported-by: noreply@ellerman.id.au
> Fixes: d2ae7494d043bfaf ("f2fs: ioctl for removing a range from F2FS")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> This assumes BLKS_PER_SEC(sbi) is 32-bit.
> 
>     #define BLKS_PER_SEC(sbi)                                       \
> 	    ((sbi)->segs_per_sec * (sbi)->blocks_per_seg)
> 
> Notes:
>   1. f2fs_sb_info.segs_per_sec and f2fs_sb_info.blocks_per_seg are both
>      unsigned int,
>   2. The multiplication is done in 32-bit arithmetic, hence the result
>      is of type unsigned int.
>   3. Is it guaranteed that the result will always fit in 32-bit, or can
>      this overflow?
>   4. fs/f2fs/debug.c:update_sit_info() assigns BLKS_PER_SEC(sbi) to
>      unsigned long long blks_per_sec, anticipating a 64-bit value.
> ---
>  fs/f2fs/gc.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index 5b1076505ade9f84..c65f87f11de029f4 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -1438,13 +1438,15 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
>  	unsigned int secs;
>  	int gc_mode, gc_type;
>  	int err = 0;
> +	__u32 rem;
>  
>  	old_block_count = le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count);
>  	if (block_count > old_block_count)
>  		return -EINVAL;
>  
>  	/* new fs size should align to section size */
> -	if (block_count % BLKS_PER_SEC(sbi))
> +	div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
> +	if (rem)
>  		return -EINVAL;
>  
>  	if (block_count == old_block_count)
> @@ -1463,7 +1465,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
>  	freeze_bdev(sbi->sb->s_bdev);
>  
>  	shrunk_blocks = old_block_count - block_count;
> -	secs = shrunk_blocks / BLKS_PER_SEC(sbi);
> +	secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi));
>  	spin_lock(&sbi->stat_lock);
>  	if (shrunk_blocks + valid_user_blocks(sbi) +
>  		sbi->current_reserved_blocks + sbi->unusable_block_count +
> 

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

* Re: [PATCH -next] f2fs: Use div_u64*() for 64-bit divisions
  2019-06-21  9:54 ` Chao Yu
@ 2019-06-21  9:55   ` Geert Uytterhoeven
  2019-06-21 18:02     ` Jaegeuk Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2019-06-21  9:55 UTC (permalink / raw)
  To: Chao Yu
  Cc: Qiuyang Sun, Jaegeuk Kim, linux-f2fs-devel, Linux-Next,
	Linux Kernel Mailing List

Hi Chao,

On Fri, Jun 21, 2019 at 11:54 AM Chao Yu <yuchao0@huawei.com> wrote:
> Since the original patch hasn't been merged to upstream, I think we can merge
> this into original patch, how do you think?

Thanks, that's fine for me.

> On 2019/6/20 22:38, Geert Uytterhoeven wrote:
> > On 32-bit (e.g. m68k):
> >
> >     fs/f2fs/gc.o: In function `f2fs_resize_fs':
> >     gc.c:(.text+0x3056): undefined reference to `__umoddi3'
> >     gc.c:(.text+0x30c4): undefined reference to `__udivdi3'
> >
> > Fix this by using div_u64_rem() and div_u64() for 64-by-32 modulo resp.
> > division operations.
> >
> > Reported-by: noreply@ellerman.id.au
> > Fixes: d2ae7494d043bfaf ("f2fs: ioctl for removing a range from F2FS")
> > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > ---
> > This assumes BLKS_PER_SEC(sbi) is 32-bit.
> >
> >     #define BLKS_PER_SEC(sbi)                                       \
> >           ((sbi)->segs_per_sec * (sbi)->blocks_per_seg)
> >
> > Notes:
> >   1. f2fs_sb_info.segs_per_sec and f2fs_sb_info.blocks_per_seg are both
> >      unsigned int,
> >   2. The multiplication is done in 32-bit arithmetic, hence the result
> >      is of type unsigned int.
> >   3. Is it guaranteed that the result will always fit in 32-bit, or can
> >      this overflow?
> >   4. fs/f2fs/debug.c:update_sit_info() assigns BLKS_PER_SEC(sbi) to
> >      unsigned long long blks_per_sec, anticipating a 64-bit value.
> > ---
> >  fs/f2fs/gc.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> > index 5b1076505ade9f84..c65f87f11de029f4 100644
> > --- a/fs/f2fs/gc.c
> > +++ b/fs/f2fs/gc.c
> > @@ -1438,13 +1438,15 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
> >       unsigned int secs;
> >       int gc_mode, gc_type;
> >       int err = 0;
> > +     __u32 rem;
> >
> >       old_block_count = le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count);
> >       if (block_count > old_block_count)
> >               return -EINVAL;
> >
> >       /* new fs size should align to section size */
> > -     if (block_count % BLKS_PER_SEC(sbi))
> > +     div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
> > +     if (rem)
> >               return -EINVAL;
> >
> >       if (block_count == old_block_count)
> > @@ -1463,7 +1465,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
> >       freeze_bdev(sbi->sb->s_bdev);
> >
> >       shrunk_blocks = old_block_count - block_count;
> > -     secs = shrunk_blocks / BLKS_PER_SEC(sbi);
> > +     secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi));
> >       spin_lock(&sbi->stat_lock);
> >       if (shrunk_blocks + valid_user_blocks(sbi) +
> >               sbi->current_reserved_blocks + sbi->unusable_block_count +

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH -next] f2fs: Use div_u64*() for 64-bit divisions
  2019-06-21  9:55   ` Geert Uytterhoeven
@ 2019-06-21 18:02     ` Jaegeuk Kim
  0 siblings, 0 replies; 4+ messages in thread
From: Jaegeuk Kim @ 2019-06-21 18:02 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Chao Yu, Qiuyang Sun, linux-f2fs-devel, Linux-Next,
	Linux Kernel Mailing List

On 06/21, Geert Uytterhoeven wrote:
> Hi Chao,
> 
> On Fri, Jun 21, 2019 at 11:54 AM Chao Yu <yuchao0@huawei.com> wrote:
> > Since the original patch hasn't been merged to upstream, I think we can merge
> > this into original patch, how do you think?
> 
> Thanks, that's fine for me.

Merged the fix.
Thank you so much.

> 
> > On 2019/6/20 22:38, Geert Uytterhoeven wrote:
> > > On 32-bit (e.g. m68k):
> > >
> > >     fs/f2fs/gc.o: In function `f2fs_resize_fs':
> > >     gc.c:(.text+0x3056): undefined reference to `__umoddi3'
> > >     gc.c:(.text+0x30c4): undefined reference to `__udivdi3'
> > >
> > > Fix this by using div_u64_rem() and div_u64() for 64-by-32 modulo resp.
> > > division operations.
> > >
> > > Reported-by: noreply@ellerman.id.au
> > > Fixes: d2ae7494d043bfaf ("f2fs: ioctl for removing a range from F2FS")
> > > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > > ---
> > > This assumes BLKS_PER_SEC(sbi) is 32-bit.
> > >
> > >     #define BLKS_PER_SEC(sbi)                                       \
> > >           ((sbi)->segs_per_sec * (sbi)->blocks_per_seg)
> > >
> > > Notes:
> > >   1. f2fs_sb_info.segs_per_sec and f2fs_sb_info.blocks_per_seg are both
> > >      unsigned int,
> > >   2. The multiplication is done in 32-bit arithmetic, hence the result
> > >      is of type unsigned int.
> > >   3. Is it guaranteed that the result will always fit in 32-bit, or can
> > >      this overflow?
> > >   4. fs/f2fs/debug.c:update_sit_info() assigns BLKS_PER_SEC(sbi) to
> > >      unsigned long long blks_per_sec, anticipating a 64-bit value.
> > > ---
> > >  fs/f2fs/gc.c | 6 ++++--
> > >  1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> > > index 5b1076505ade9f84..c65f87f11de029f4 100644
> > > --- a/fs/f2fs/gc.c
> > > +++ b/fs/f2fs/gc.c
> > > @@ -1438,13 +1438,15 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
> > >       unsigned int secs;
> > >       int gc_mode, gc_type;
> > >       int err = 0;
> > > +     __u32 rem;
> > >
> > >       old_block_count = le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count);
> > >       if (block_count > old_block_count)
> > >               return -EINVAL;
> > >
> > >       /* new fs size should align to section size */
> > > -     if (block_count % BLKS_PER_SEC(sbi))
> > > +     div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
> > > +     if (rem)
> > >               return -EINVAL;
> > >
> > >       if (block_count == old_block_count)
> > > @@ -1463,7 +1465,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
> > >       freeze_bdev(sbi->sb->s_bdev);
> > >
> > >       shrunk_blocks = old_block_count - block_count;
> > > -     secs = shrunk_blocks / BLKS_PER_SEC(sbi);
> > > +     secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi));
> > >       spin_lock(&sbi->stat_lock);
> > >       if (shrunk_blocks + valid_user_blocks(sbi) +
> > >               sbi->current_reserved_blocks + sbi->unusable_block_count +
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> -- 
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds

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

end of thread, other threads:[~2019-06-21 18:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-20 14:38 [PATCH -next] f2fs: Use div_u64*() for 64-bit divisions Geert Uytterhoeven
2019-06-21  9:54 ` Chao Yu
2019-06-21  9:55   ` Geert Uytterhoeven
2019-06-21 18:02     ` Jaegeuk Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).