Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp477411ybi; Fri, 21 Jun 2019 02:56:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIGH+VsFxH77QUuXTLaKR+zNqyCB5ioBy0eCxgSTHFOrT8boU4V8i5BD1jXiMIdbQRB+V9 X-Received: by 2002:a17:902:934a:: with SMTP id g10mr120836818plp.18.1561110989374; Fri, 21 Jun 2019 02:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561110989; cv=none; d=google.com; s=arc-20160816; b=OM9HsaYwn38xSkmxqr7RUDXQPDqHGWliDdQRDtCXbfxvN0ayQxShWILQSsV8l7UZzJ UE8V7h9pf5tvyzAcKykp9pDCr4U2P9vymlFOz7WmA46o99ON1YKkzl1WA0+rEo6apM/4 Vh1qtfKisQCf2oYlUHs8xvPdyAe1oC53vqyr9M1Nhv/Jk6y40Z1mL3GrhxD9Ch1m6l9h 5PP0fyYnUBjttkj1AUI9UbHCgY5BMY6krKHjAtPCFr/IZq/z/1yEaPJd+LLAqPVXLlH+ zcP3/cgz+zVF8NAAcw5UmBWrsYqB9Gu9yN0LYIPYoH4v/WlH61Y9Y6d8cPxAVtwDBssi Lcng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=zoSCQQgDyqdNTKrY/BA7yRe6rgMh4ABI0Zse4HOFW8I=; b=sAaTXzOZYvEiHPcvRh+FlkqeQIGjmA8B444Aw2rnPQ8clv+1SevyX1wrEPBgHSAwlk md9E3TmuhlVl5mY4E2oZVK23ffEztG5Pp9eg/Biefv7egPa9OVp/Xa134Dhq7kvY+U4x UwSoNjZ/u/HNLEIIlymLQLp6zCkOnV/cu3z1tCdyEp8yIj7it0ZP/MZtPYw1Y5W5fVg2 yhjjTn0qTurHMSHDSZsG3oaJt88JdFq19mJ4MvVhYW5466jtJqgiU8fM9ekcn3m7wCx/ h+hpkJN6GsRC772Fn0/8/nn7fYk8kSgQOTymx6clGNUuEJluLv0nu4wTUSXaUOfAS9s5 GcBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si1985316pgp.532.2019.06.21.02.56.14; Fri, 21 Jun 2019 02:56:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726462AbfFUJ4J (ORCPT + 99 others); Fri, 21 Jun 2019 05:56:09 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:33512 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726210AbfFUJ4J (ORCPT ); Fri, 21 Jun 2019 05:56:09 -0400 Received: by mail-qt1-f193.google.com with SMTP id x2so6330468qtr.0; Fri, 21 Jun 2019 02:56:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zoSCQQgDyqdNTKrY/BA7yRe6rgMh4ABI0Zse4HOFW8I=; b=iGbUzHSUsXKE4Mhdgla4u6B7/wCG8Wbmf5kDEQ4BN4k1tQ8eg8CQayXAinNe5wTRGl RgZb3XHyc3YUpW/i6jHAP2Slc280FCqKj4v1pyc3XxorwWYgJ9iHTb3QF2zwUZuUT/fB RVFxSEKbmMSV8JQPOW68FxPyBLivkZCncf9tp4NEz/ZV8fRl8ykLK+pjeyJSfF38jqXP fZ/ntGqcFdrzhmJSLFKtHne4UkS5Eca6PdGXe4CgH4tx2t6iI6BUU5qzbt4HSsqu9fdx 8QeL7UYNipQ2zOZjrEfWxkurPIbyI4/KAK3wyWO30U6rxA8itr/IkMri5NUHlFDujyDV SESw== X-Gm-Message-State: APjAAAVriE4RiYeS1vHfGyvxgGyYEdIomySOqmqhCFsE87bF3ZM05ExW xUv5sqP0emizTYgZgFatYR7PYimq627vK1UvQCs= X-Received: by 2002:ac8:2379:: with SMTP id b54mr56769954qtb.168.1561110967884; Fri, 21 Jun 2019 02:56:07 -0700 (PDT) MIME-Version: 1.0 References: <20190620143800.20640-1-geert@linux-m68k.org> In-Reply-To: From: Geert Uytterhoeven Date: Fri, 21 Jun 2019 11:55:56 +0200 Message-ID: Subject: Re: [PATCH -next] f2fs: Use div_u64*() for 64-bit divisions To: Chao Yu Cc: Qiuyang Sun , Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net, Linux-Next , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chao, On Fri, Jun 21, 2019 at 11:54 AM Chao Yu 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 > > --- > > 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