Skip to contentSkip to conversation

vfs: follow-on fixes for i_ino widening

PATCH Superseded Jeff Layton 4 participants 8 messages Mar 13 – Mar 16

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover vfs: follow-on fixes for i_ino widening

Just some patches to fix follow-on issues reported after the inode->i_ino widening series. Christian, could you toss these onto the vfs-7.1.kino branch?

---
Changes in v2:
- rename variable in nilfs2 patch from "rem" to "index"
- reword comment and commit log for better accuracy in EVM patch

---
Jeff Layton (2):
nilfs2: fix 64-bit division operations in nilfs_bmap_find_target_in_group()
EVM: add comment describing why ino field is still unsigned long

 fs/nilfs2/bmap.c                    | 9 ++++++---
 security/integrity/evm/evm_crypto.c | 6 ++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

---
base-commit: 9840bb66e7e5dffd72b03201318f154a10b06b4a
change-id: 20260310-iino-u64-424fa570d850

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
#1 lore raw

PATCH v2 1/2 nilfs2: fix 64-bit division operations in nilfs_bmap_find_target_in_group()

With the change to make inode->i_ino a u64, the build started failing on 32-bit ARM with:

ERROR: modpost: "__aeabi_uldivmod" [fs/nilfs2/nilfs2.ko] undefined!

Fix this by using the 64-bit division interfaces in nilfs_bmap_find_target_in_group().

---
 fs/nilfs2/bmap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/nilfs2/bmap.c +6 -3
index 824f2bd91c167965ec3a660202b6e6c5f1fe007e..abcf5252578ad24f694bfccf525893674bfcb4bc 100644
@@ -455,11 +455,14 @@ __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)
 {
 	struct inode *dat = nilfs_bmap_get_dat(bmap);
 	unsigned long entries_per_group = nilfs_palloc_entries_per_group(dat);
-	unsigned long group = bmap->b_inode->i_ino / entries_per_group;
+	unsigned long group;
+	u32 index;
+
+	group = div_u64(bmap->b_inode->i_ino, entries_per_group);
+	div_u64_rem(bmap->b_inode->i_ino, NILFS_BMAP_GROUP_DIV, &index);
 
 	return group * entries_per_group +
-		(bmap->b_inode->i_ino % NILFS_BMAP_GROUP_DIV) *
-		(entries_per_group / NILFS_BMAP_GROUP_DIV);
+	       index * (entries_per_group / NILFS_BMAP_GROUP_DIV);
 }
 
 static struct lock_class_key nilfs_bmap_dat_lock_key;
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2 1/2] nilfs2: fix 64-bit division operations in nilfs_bmap_find_target_in_group()

Quoted 23 lines · On Fri, 13 Mar 2026 14:45:20 -0400 Jeff Layton <[email protected]> wrote:

With the change to make inode->i_ino a u64, the build started failing on 32-bit ARM with:

ERROR: modpost: "__aeabi_uldivmod" [fs/nilfs2/nilfs2.ko] undefined!

Fix this by using the 64-bit division interfaces in nilfs_bmap_find_target_in_group().

---
 fs/nilfs2/bmap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/nilfs2/bmap.c +0 -0
index 824f2bd91c167965ec3a660202b6e6c5f1fe007e..abcf5252578ad24f694bfccf525893674bfcb4bc 100644

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 458

Quoted 4 lines
fs/nilfs2/bmap.c +0 -1
@@ -455,11 +455,14 @@ __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)
 {
 	struct inode *dat = nilfs_bmap_get_dat(bmap);
 	unsigned long entries_per_group = nilfs_palloc_entries_per_group(dat);
-	unsigned long group = bmap->b_inode->i_ino / entries_per_group;

Are you sure entries_per_group can be more than 32 bits? It looks like something that will be the same size on 32 and 64bit.

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 461

Quoted 4 lines
fs/nilfs2/bmap.c +4 -0
+	unsigned long group;
+	u32 index;
+
+	group = div_u64(bmap->b_inode->i_ino, entries_per_group);

You don't need the full 64 by 64 divide.
IIRC there are both div_u64_u32() and div_u64_ulong().

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 462

Quoted 1 line
fs/nilfs2/bmap.c +1 -0
+	div_u64_rem(bmap->b_inode->i_ino, NILFS_BMAP_GROUP_DIV, &index);

NILFD_BMAP_GROUP_DIV is 8 (and probably has to be a power of 2). So:

	index = bmap->b_inode->i_ino & (NILFS_BMAP_GROUP_DIV - 1);

is the same and likely much faster to calculate. (The compiler will have done that optimisation before.)

David

Quoted 9 lines
fs/nilfs2/bmap.c +1 -2
 	return group * entries_per_group +
-		(bmap->b_inode->i_ino % NILFS_BMAP_GROUP_DIV) *
-		(entries_per_group / NILFS_BMAP_GROUP_DIV);
+	       index * (entries_per_group / NILFS_BMAP_GROUP_DIV);
 }
 
 static struct lock_class_key nilfs_bmap_dat_lock_key;
 
#3 lore raw

Re: [PATCH v2 1/2] nilfs2: fix 64-bit division operations in nilfs_bmap_find_target_in_group()

Quoted 21 lines · David Laight
Quoted 18 lines · On Fri, 13 Mar 2026 14:45:20 -0400 Jeff Layton <[email protected]> wrote:

With the change to make inode->i_ino a u64, the build started failing on 32-bit ARM with:

ERROR: modpost: "__aeabi_uldivmod" [fs/nilfs2/nilfs2.ko] undefined!

Fix this by using the 64-bit division interfaces in nilfs_bmap_find_target_in_group().

---
 fs/nilfs2/bmap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 13 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 458

Quoted 9 lines
fs/nilfs2/bmap.c +0 -1
index 824f2bd91c167965ec3a660202b6e6c5f1fe007e..abcf5252578ad24f694bfccf525893674bfcb4bc 100644
@@ -455,11 +455,14 @@ __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)
 {
 	struct inode *dat = nilfs_bmap_get_dat(bmap);
 	unsigned long entries_per_group = nilfs_palloc_entries_per_group(dat);
-	unsigned long group = bmap->b_inode->i_ino / entries_per_group;

Are you sure entries_per_group can be more than 32 bits? It looks like something that will be the same size on 32 and 64bit.

I'm not sure of anything here. I'm just want to get this to compile on all arches. FWIW, I'm not looking to optimize anything in this patch.

Quoted 8 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 461

Quoted 4 lines
fs/nilfs2/bmap.c +4 -0
+	unsigned long group;
+	u32 index;
+
+	group = div_u64(bmap->b_inode->i_ino, entries_per_group);

You don't need the full 64 by 64 divide.
IIRC there are both div_u64_u32() and div_u64_ulong().

Quoted 9 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 462

Quoted 1 line
fs/nilfs2/bmap.c +1 -0
+	div_u64_rem(bmap->b_inode->i_ino, NILFS_BMAP_GROUP_DIV, &index);

NILFD_BMAP_GROUP_DIV is 8 (and probably has to be a power of 2). So:

	index = bmap->b_inode->i_ino & (NILFS_BMAP_GROUP_DIV - 1);

is the same and likely much faster to calculate. (The compiler will have done that optimisation before.)

That all sounds reasonable to me. At this point though, it would be better if the NILFS2 folks stepped in with how they'd prefer this be done.

Quoted 10 lines
Quoted 10 lines
fs/nilfs2/bmap.c +1 -2
 	return group * entries_per_group +
-		(bmap->b_inode->i_ino % NILFS_BMAP_GROUP_DIV) *
-		(entries_per_group / NILFS_BMAP_GROUP_DIV);
+	       index * (entries_per_group / NILFS_BMAP_GROUP_DIV);
 }
 
 static struct lock_class_key nilfs_bmap_dat_lock_key;
 
Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#4 lore raw

Re: [PATCH v2 1/2] nilfs2: fix 64-bit division operations in nilfs_bmap_find_target_in_group()

Quoted 37 lines · Jeff Layton
Quoted 21 lines · David Laight
Quoted 18 lines · On Fri, 13 Mar 2026 14:45:20 -0400 Jeff Layton <[email protected]> wrote:

With the change to make inode->i_ino a u64, the build started failing on 32-bit ARM with:

ERROR: modpost: "__aeabi_uldivmod" [fs/nilfs2/nilfs2.ko] undefined!

Fix this by using the 64-bit division interfaces in nilfs_bmap_find_target_in_group().

---
 fs/nilfs2/bmap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 13 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 458

Quoted 9 lines
fs/nilfs2/bmap.c +0 -1
index 824f2bd91c167965ec3a660202b6e6c5f1fe007e..abcf5252578ad24f694bfccf525893674bfcb4bc 100644
@@ -455,11 +455,14 @@ __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)
 {
    struct inode *dat = nilfs_bmap_get_dat(bmap);
    unsigned long entries_per_group = nilfs_palloc_entries_per_group(dat);
-   unsigned long group = bmap->b_inode->i_ino / entries_per_group;

Are you sure entries_per_group can be more than 32 bits? It looks like something that will be the same size on 32 and 64bit.

Quoted 10 lines

I'm not sure of anything here. I'm just want to get this to compile on all arches. FWIW, I'm not looking to optimize anything in this patch.

Quoted 7 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 461

Quoted 4 lines
fs/nilfs2/bmap.c +4 -0
+   unsigned long group;
+   u32 index;
+
+   group = div_u64(bmap->b_inode->i_ino, entries_per_group);

You don't need the full 64 by 64 divide.
IIRC there are both div_u64_u32() and div_u64_ulong().

Isn't the type of divisor in div_u64() u32?
Since entries_per_group cannot exceed 32 bits according to the current specification, I think using div_u64() is fine.

Quoted 11 lines
Quoted 10 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 462

Quoted 2 lines
fs/nilfs2/bmap.c +1 -0
+   div_u64_rem(bmap->b_inode->i_ino, NILFS_BMAP_GROUP_DIV, &index);

NILFD_BMAP_GROUP_DIV is 8 (and probably has to be a power of 2). So:

      index = bmap->b_inode->i_ino & (NILFS_BMAP_GROUP_DIV - 1);

is the same and likely much faster to calculate. (The compiler will have done that optimisation before.)

Quoted 3 lines

That all sounds reasonable to me. At this point though, it would be better if the NILFS2 folks stepped in with how they'd prefer this be done.

Yes, indeed. It seems that the application of optimizations will change, so this proposed correction is better.

Since NILFS_BMAP_GROUP_DIV is a fixed constant and cannot be anything other than a power of 2, could you please adopt this proposed correction with the following comment?

#define NILFS_BMAP_GROUP_DIV 8 /* must be a power of 2 */

Thanks,
Ryusuke Konishi

Quoted 14 lines
Quoted 11 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)

Quoted 11 lines
fs/nilfs2/bmap.c +1 -2
    return group * entries_per_group +
-           (bmap->b_inode->i_ino % NILFS_BMAP_GROUP_DIV) *
-           (entries_per_group / NILFS_BMAP_GROUP_DIV);
+          index * (entries_per_group / NILFS_BMAP_GROUP_DIV);
 }
 
 static struct lock_class_key nilfs_bmap_dat_lock_key;
 

--
Jeff Layton <[email protected]>

#5 lore raw

Re: [PATCH v2 1/2] nilfs2: fix 64-bit division operations in nilfs_bmap_find_target_in_group()

Quoted 46 lines · Ryusuke Konishi
Quoted 45 lines · Jeff Layton
Quoted 21 lines · David Laight
Quoted 18 lines · On Fri, 13 Mar 2026 14:45:20 -0400 Jeff Layton <[email protected]> wrote:

With the change to make inode->i_ino a u64, the build started failing on 32-bit ARM with:

ERROR: modpost: "__aeabi_uldivmod" [fs/nilfs2/nilfs2.ko] undefined!

Fix this by using the 64-bit division interfaces in nilfs_bmap_find_target_in_group().

---
 fs/nilfs2/bmap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 13 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 458

Quoted 9 lines
fs/nilfs2/bmap.c +0 -1
index 824f2bd91c167965ec3a660202b6e6c5f1fe007e..abcf5252578ad24f694bfccf525893674bfcb4bc 100644
@@ -455,11 +455,14 @@ __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)
 {
    struct inode *dat = nilfs_bmap_get_dat(bmap);
    unsigned long entries_per_group = nilfs_palloc_entries_per_group(dat);
-   unsigned long group = bmap->b_inode->i_ino / entries_per_group;

Are you sure entries_per_group can be more than 32 bits? It looks like something that will be the same size on 32 and 64bit.

I'm not sure of anything here. I'm just want to get this to compile on all arches. FWIW, I'm not looking to optimize anything in this patch.

Quoted 5 lines
Quoted 4 lines
fs/nilfs2/bmap.c +4 -0
+   unsigned long group;
+   u32 index;
+
+   group = div_u64(bmap->b_inode->i_ino, entries_per_group);
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

You don't need the full 64 by 64 divide.
IIRC there are both div_u64_u32() and div_u64_ulong().

Isn't the type of divisor in div_u64() u32?
Since entries_per_group cannot exceed 32 bits according to the current specification, I think using div_u64() is fine.

Yep, it is:

static inline u64 div_u64(u64 dividend, u32 divisor)

Quoted 15 lines
Quoted 11 lines
Quoted 10 lines

fs/nilfs2/bmap.c __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap) · line 462

Quoted 2 lines
fs/nilfs2/bmap.c +1 -0
+   div_u64_rem(bmap->b_inode->i_ino, NILFS_BMAP_GROUP_DIV, &index);

NILFD_BMAP_GROUP_DIV is 8 (and probably has to be a power of 2). So:

      index = bmap->b_inode->i_ino & (NILFS_BMAP_GROUP_DIV - 1);

is the same and likely much faster to calculate. (The compiler will have done that optimisation before.)

Quoted 3 lines

That all sounds reasonable to me. At this point though, it would be better if the NILFS2 folks stepped in with how they'd prefer this be done.

Quoted 9 lines

Yes, indeed. It seems that the application of optimizations will change, so this proposed correction is better.

Since NILFS_BMAP_GROUP_DIV is a fixed constant and cannot be anything other than a power of 2, could you please adopt this proposed correction with the following comment?

#define NILFS_BMAP_GROUP_DIV 8 /* must be a power of 2 */

Even better, lets use a compile-time assertion:

    BUILD_BUG_ON_NOT_POWER_OF_TWO(NILFS_BMAP_GROUP_DIV);

I'll send a respin.

Thanks!

Signature · 1 line
Jeff Layton <[email protected]>
#6 lore raw

PATCH v2 2/2 EVM: add comment describing why ino field is still unsigned long

In reply to Jeff Layton

Mimi pointed out that we didn't widen the inode number field in struct h_misc alongside the inode->i_ino widening. While we could make an equivalent change there, that would require EVM resigning on all 32-bit hosts.

Instead, leave the field as an unsigned long. This should have no effect on 64-bit hosts, and allow things to continue working on 32-bit hosts in the cases where the i_ino fits in 32-bits.

Add a comment explaining why it's being left as unsigned long.

---
 security/integrity/evm/evm_crypto.c | 6 ++++++
 1 file changed, 6 insertions(+)
security/integrity/evm/evm_crypto.c +6 -0
index c0ca4eedb0fe5d5c30f45f515a4bc90248ec64ea..1c41af2f91a60a714878ff93b554c90e45546503 100644
@@ -144,6 +144,12 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
 			  char type, char *digest)
 {
 	struct h_misc {
+		/*
+		 * Although inode->i_ino is now u64, this field remains
+		 * unsigned long to allow existing HMAC and signatures from
+		 * 32-bit hosts to continue working when i_ino hasn't changed
+		 * and fits in a u32.
+		 */
 		unsigned long ino;
 		__u32 generation;
 		uid_t uid;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 2/2
#7 lore raw

Re: [PATCH v2 2/2] EVM: add comment describing why ino field is still unsigned long

Quoted 5 lines · Jeff Layton

Mimi pointed out that we didn't widen the inode number field in struct h_misc alongside the inode->i_ino widening. While we could make an equivalent change there, that would require EVM resigning on all 32-bit hosts.

Quoted 8 lines

Instead, leave the field as an unsigned long. This should have no effect on 64-bit hosts, and allow things to continue working on 32-bit hosts in the cases where the i_ino fits in 32-bits.

Add a comment explaining why it's being left as unsigned long.

Thanks, Jeff.

Quoted 21 lines
---
 security/integrity/evm/evm_crypto.c | 6 ++++++
 1 file changed, 6 insertions(+)
security/integrity/evm/evm_crypto.c +6 -0
index c0ca4eedb0fe5d5c30f45f515a4bc90248ec64ea..1c41af2f91a60a714878ff93b554c90e45546503 100644
@@ -144,6 +144,12 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
 			  char type, char *digest)
 {
 	struct h_misc {
+		/*
+		 * Although inode->i_ino is now u64, this field remains
+		 * unsigned long to allow existing HMAC and signatures from
+		 * 32-bit hosts to continue working when i_ino hasn't changed
+		 * and fits in a u32.
+		 */
 		unsigned long ino;
 		__u32 generation;
 		uid_t uid;