add patch add-the-sb_start_intwrite_trylock-helper
[ext4-patch-queue.git] / use-raw_iversion-value-for-ea_inode
blobc1bcd4b6caf10800d31f77316e882cb5c4d48fc4
1 ext4: use raw i_version value for ea_inode
3 From: Eryu Guan <guaneryu@gmail.com>
5 Currently, creating large xattr (e.g. 2k) in ea_inode would cause
6 ea_inode refcount corruption, e.g.
8   Pass 4: Checking reference counts
9   Extended attribute inode 13 ref count is 0, should be 1. Fix? no
11 This is because that we save the lower 32bit of refcount in
12 inode->i_version and store it in raw_inode->i_disk_version on disk.
13 But since commit ee73f9a52a34 ("ext4: convert to new i_version
14 API"), we load/store modified i_disk_version from/to disk instead of
15 raw value, which causes on-disk ea_inode refcount corruption.
17 Fix it by loading/storing raw i_version/i_disk_version, because it's
18 a self-managed value in this case.
20 Fixes: ee73f9a52a34 ("ext4: convert to new i_version API")
21 Cc: Tahsin Erdogan <tahsin@google.com>
22 Signed-off-by: Eryu Guan <guaneryu@gmail.com>
23 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
24 ---
25  fs/ext4/inode.c | 24 ++++++++++++++++++++++--
26  1 file changed, 22 insertions(+), 2 deletions(-)
28 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
29 index 1e50c5efae67..0eb64e8f9602 100644
30 --- a/fs/ext4/inode.c
31 +++ b/fs/ext4/inode.c
32 @@ -4724,6 +4724,26 @@ int ext4_get_projid(struct inode *inode, kprojid_t *projid)
33         return 0;
34  }
36 +/*
37 + * ext4 has self-managed i_version for ea inodes, it stores the lower 32bit of
38 + * refcount in i_version, so use raw values if inode has EXT4_EA_INODE_FL flag
39 + * set.
40 + */
41 +static inline void ext4_inode_set_iversion_queried(struct inode *inode, u64 val)
43 +       if (unlikely(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL))
44 +               inode_set_iversion_raw(inode, val);
45 +       else
46 +               inode_set_iversion_queried(inode, val);
48 +static inline u64 ext4_inode_peek_iversion(const struct inode *inode)
50 +       if (unlikely(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL))
51 +               return inode_peek_iversion_raw(inode);
52 +       else
53 +               return inode_peek_iversion(inode);
56  struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
57  {
58         struct ext4_iloc iloc;
59 @@ -4910,7 +4930,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
60                                 ivers |=
61                     (__u64)(le32_to_cpu(raw_inode->i_version_hi)) << 32;
62                 }
63 -               inode_set_iversion_queried(inode, ivers);
64 +               ext4_inode_set_iversion_queried(inode, ivers);
65         }
67         ret = 0;
68 @@ -5196,7 +5216,7 @@ static int ext4_do_update_inode(handle_t *handle,
69         }
71         if (likely(!test_opt2(inode->i_sb, HURD_COMPAT))) {
72 -               u64 ivers = inode_peek_iversion(inode);
73 +               u64 ivers = ext4_inode_peek_iversion(inode);
75                 raw_inode->i_disk_version = cpu_to_le32(ivers);
76                 if (ei->i_extra_isize) {
77 -- 
78 2.14.3