Skip to contentSkip to conversation

f2fs: fix 32-bit build

PATCH In review Arnd Bergmann 3 participants 5 messages Nov 22, 2016 – Nov 23, 2016 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: fix 32-bit build

The addition of multiple-device support broke CONFIG_BLK_DEV_ZONED on 32-bit machines because of a 64-bit division:

fs/f2fs/f2fs.o: In function `__issue_discard_async':
extent_cache.c:(.text.__issue_discard_async+0xd4): undefined reference to `__aeabi_uldivmod'

Unfortunately, the sector number is usually a 64-bit number, and we probably can't guarantee that bdev_zone_size() returns a power-of-two number, so we actually have to do the expensive 64-bit operation to get the remainder.

Fixes 792b84b74b54 ("f2fs: support multiple devices")
---
 fs/f2fs/segment.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +3 -1
index 634834e5a232..e4c5497aa172 100644
@@ -685,6 +685,7 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
 {
 	sector_t nr_sects = SECTOR_FROM_BLOCK(blklen);
 	sector_t sector;
+	u32 rem;
 	int devi = 0;
 
 	if (sbi->s_ndevs) {
@@ -693,7 +694,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
 	}
 	sector = SECTOR_FROM_BLOCK(blkstart);
 
-	if (sector % bdev_zone_size(bdev) || nr_sects != bdev_zone_size(bdev)) {
+	div_u64_rem(sector, bdev_zone_size(bdev), &rem);
+	if (rem || nr_sects != bdev_zone_size(bdev)) {
 		f2fs_msg(sbi->sb, KERN_INFO,
 			"(%d) %s: Unaligned discard attempted (block %x + %x)",
 			devi, sbi->s_ndevs ? FDEV(devi).path: "",
Signature · 4 lines
2.9.0


------------------------------------------------------------------------------
#1 lore raw

Arnd,

Quoted 4 lines

Unfortunately, the sector number is usually a 64-bit number, and we probably can't guarantee that bdev_zone_size() returns a power-of-two number, so we actually have to do the expensive 64-bit operation to get the remainder.

No, the zone size is guaranteed to be a power of 2. See sd_zbc.c in Jens linux-block tree, branch for-4.10/block. So it is ok to do a & (bdev_zone_size() - 1) for the remainder.

That was indeed my mistake in this patch. Modulo should not have been used in the first place. My bad.

Quoted 20 lines
Fixes 792b84b74b54 ("f2fs: support multiple devices")
---
 fs/f2fs/segment.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +1 -0
index 634834e5a232..e4c5497aa172 100644
@@ -685,6 +685,7 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
 {
 	sector_t nr_sects = SECTOR_FROM_BLOCK(blklen);
 	sector_t sector;
+	u32 rem;
 	int devi = 0;
 
 	if (sbi->s_ndevs) {

fs/f2fs/segment.c static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, · line 701

Quoted 9 lines
fs/f2fs/segment.c +2 -1
@@ -693,7 +694,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
 	}
 	sector = SECTOR_FROM_BLOCK(blkstart);
 
-	if (sector % bdev_zone_size(bdev) || nr_sects != bdev_zone_size(bdev)) {
+	div_u64_rem(sector, bdev_zone_size(bdev), &rem);
+	if (rem || nr_sects != bdev_zone_size(bdev)) {
 		f2fs_msg(sbi->sb, KERN_INFO,
 			"(%d) %s: Unaligned discard attempted (block %x + %x)",
 			devi, sbi->s_ndevs ? FDEV(devi).path: "",

Thanks !

Best regards.

Signature · 7 lines
Damien Le Moal, Ph.D.
Sr Manager, System Software Research Group,
Western Digital
[email protected]
Tel: (+81) 0466-98-3593 (Ext. 51-3593)
1 kirihara-cho, Fujisawa, Kanagawa, 252-0888 Japan
www.wdc.com, www.hgst.com
maintainer
#2 lore raw
In reply to Arnd Bergmann

Hi Arnd,

As Damien mentioned, is this fine to go, if you don't mind? I've confirmed that sd_zbc.c allows a power-of-two number only.

Thanks,

Quoted 1 line

From b709ff532daedc42526a46cb26860127f4959e01 Mon Sep 17 00:00:00 2001

From: Arnd Bergmann <[email protected]>
Date: Tue, 22 Nov 2016 15:20:16 +0100
Subject: [PATCH] f2fs: fix 32-bit build

The addition of multiple-device support broke CONFIG_BLK_DEV_ZONED on 32-bit machines because of a 64-bit division:

fs/f2fs/f2fs.o: In function `__issue_discard_async':
extent_cache.c:(.text.__issue_discard_async+0xd4): undefined reference to `__aeabi_uldivmod'

Unfortunately, the sector number is usually a 64-bit number, and we guarantee that bdev_zone_size() returns a power-of-two number.

Fixes 792b84b74b54 ("f2fs: support multiple devices")
---
 fs/f2fs/segment.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +2 -1
index eaa0b40..d5141a0 100644
@@ -693,7 +693,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
 	}
 	sector = SECTOR_FROM_BLOCK(blkstart);
 
-	if (sector % bdev_zone_size(bdev) || nr_sects != bdev_zone_size(bdev)) {
+	if (sector & (bdev_zone_size(bdev) - 1) ||
+				nr_sects != bdev_zone_size(bdev)) {
 		f2fs_msg(sbi->sb, KERN_INFO,
 			"(%d) %s: Unaligned discard attempted (block %x + %x)",
 			devi, sbi->s_ndevs ? FDEV(devi).path: "",
Signature · 1 line
2.8.3
#3 lore raw
Quoted 3 lines · CET Jaegeuk Kim

Unfortunately, the sector number is usually a 64-bit number, and we guarantee that bdev_zone_size() returns a power-of-two number.

The sentence no longer makes sense. Maybe

Fortunately, bdev_zone_size() is guaranteed to return a power-of-two number, so we can replace the % operator with a cheaper bit mask.

fs/f2fs/segment.c static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, · line 697

Quoted 7 lines
fs/f2fs/segment.c +1 -1
@@ -693,7 +693,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
        }
        sector = SECTOR_FROM_BLOCK(blkstart);
 
-       if (sector % bdev_zone_size(bdev) || nr_sects != bdev_zone_size(bdev)) {
+       if (sector & (bdev_zone_size(bdev) - 1) ||
 

looks good, thanks for following up!

Arnd

------------------------------------------------------------------------------

maintainer
#4 lore raw
Quoted 9 lines · Arnd Bergmann
Quoted 3 lines · CET Jaegeuk Kim

Unfortunately, the sector number is usually a 64-bit number, and we guarantee that bdev_zone_size() returns a power-of-two number.

The sentence no longer makes sense. Maybe

Fortunately, bdev_zone_size() is guaranteed to return a power-of-two number, so we can replace the % operator with a cheaper bit mask.

Got it.
Added it with modifed version.
Thanks,

Quoted 12 lines

fs/f2fs/segment.c static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, · line 697

Quoted 8 lines
fs/f2fs/segment.c +1 -1
@@ -693,7 +693,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
        }
        sector = SECTOR_FROM_BLOCK(blkstart);
 
-       if (sector % bdev_zone_size(bdev) || nr_sects != bdev_zone_size(bdev)) {
+       if (sector & (bdev_zone_size(bdev) - 1) ||
 

looks good, thanks for following up!

Arnd