Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp477698ybi; Fri, 21 Jun 2019 02:56:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUiVrXQGRHSflRjgIfibwId6mgdRyFq9X87HoEEwcaxj+R2OR+MqGAFL/nv4fTRcTK3Qg5 X-Received: by 2002:a63:d354:: with SMTP id u20mr16936658pgi.129.1561111012949; Fri, 21 Jun 2019 02:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561111012; cv=none; d=google.com; s=arc-20160816; b=MFFfiIZWOr5gz5Qvmzz/SocQRvSAnlp8Zj+RXDKBOwJxRJv8DKtOwOmIg9xAaTerGP cCYXQB1834LoT2S1mnInf5C5awgvbteepGmhWhSFqSfE4OlpdBqHrsuiVawJFjmQ6zk6 uG+N4DgeRRzlbpasScQdpaLzZht1NZEiaE+n3wvEuB4q5O3/GsD56ZPaJ1JpIQRy+MiI rw0T27SLEyw7i2PX0tMSXsh9oW++gF3AFYZvRS7v+UsdpSJau61kcnFXixV5jk3DN7Vl dz3o3rkwqxp9IRQ3B294qJCZ0UXJJpdUPyPAB2xR/77GdjQQLHUZFWEdNhvxMTepaskD AzaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=xDev0r7o29mgtF+85WipHnZ7mNl/oLfOiQLKM/gad6o=; b=yV1SECoURaJQDXApjYG39PInpvJCfLmD7HL55iC+8d3ENwmyRfrLFH/gABSTiu6gTR ZaDr0wCUqBSuBtisoxlvvlvfWGGrceTFeUTpUtj6LKwBCxs8wixf8uZfhbgGc1CKKg4s iAvrP21z5/LyF8dEvDzQTrOK6BjMnijAD7b6lnBKQJixz45NP9z1XO+cs/oKcMMseGH4 0hnzMZqznnm8JTA3+JZA/YK1yKVKVeRIrzv1j0822hrB0qn5xKvH6pCzFx305gibZdj4 qUMokfGpIeoAZWtt/vVgqlCtDiBJcydV++s95iYvxGv/tTngABm91q8AW/Pgj472DQdl EMjQ== 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 r4si2005860pgp.249.2019.06.21.02.56.38; Fri, 21 Jun 2019 02:56:52 -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 S1726860AbfFUJyx (ORCPT + 99 others); Fri, 21 Jun 2019 05:54:53 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:19054 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727253AbfFUJyt (ORCPT ); Fri, 21 Jun 2019 05:54:49 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id CE75F25CFA34DA6EF421; Fri, 21 Jun 2019 17:54:46 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.212) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 21 Jun 2019 17:54:39 +0800 Subject: Re: [PATCH -next] f2fs: Use div_u64*() for 64-bit divisions To: Geert Uytterhoeven , Qiuyang Sun , Jaegeuk Kim CC: , , References: <20190620143800.20640-1-geert@linux-m68k.org> From: Chao Yu Message-ID: Date: Fri, 21 Jun 2019 17:54:24 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190620143800.20640-1-geert@linux-m68k.org> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 + >