staging: erofs: harden inode lookup for 32-bit platforms
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
This patch introduces inode hash function, test and set callbacks, and iget5_locked to find the right inode for 32-bit platforms.
--- drivers/staging/erofs/inode.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/staging/erofs/internal.h | 10 ++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-)
drivers/staging/erofs/inode.c +36 -1
@@ -232,10 +232,45 @@ static int fill_inode(struct inode *inode, int isdir)return err; } +/* +* erofs nid is 64bits, but i_ino is 'unsigned long', therefore +* we should do more for 32-bit platform to find the right inode. +*/ +#if BITS_PER_LONG <64 +static int erofs_ilookup_test_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + +return EROFS_V (inode)->nid == nid; +} + +static int erofs_iget_set_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + + inode->i_ino =erofs_inode_hash (nid); +return 0 ; +} +#endif + +static inline struct inode *erofs_iget_locked (struct super_block *sb, +erofs_nid_t nid) +{ +const unsigned long hashval =erofs_inode_hash (nid); + +#if BITS_PER_LONG >=64 +/* it is safe to use iget_locked for >= 64-bit platform */ +return iget_locked (sb, hashval); +#else +return iget5_locked (sb, hashval, erofs_ilookup_test_actor, + erofs_iget_set_actor, &nid); +#endif +} +struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool isdir) { -struct inode *inode =iget_locked (sb, nid); +struct inode *inode =erofs_iget_locked (sb, nid);if (unlikely (inode ==NULL ))return ERR_PTR (-ENOMEM );
drivers/staging/erofs/internal.h +10 -0
@@ -511,6 +511,16 @@ struct erofs_map_blocks_iter { }/* inode.c */ +static inline unsigned long erofs_inode_hash (erofs_nid_t nid) +{ +u64 h = nid; + +#if BITS_PER_LONG ==32 + h = (h >>32 ) ^ (h &0xffffffff ); +#endif +return (unsigned long )h; +} +extern struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool dir);
Signature · 1 line
1.9.1
PATCH 2/3 staging: erofs: fix race when the managed cache is enabled
When the managed cache is enabled, the last reference count of a workgroup must be used for its workstation.
Otherwise, it could lead to incorrect (un)freezes in the reclaim path, and it would be harmful.
--- drivers/staging/erofs/utils.c | 131 ++++++++++++++++++++++++++++++------------ 1 file changed, 95 insertions(+), 36 deletions(-)
drivers/staging/erofs/utils.c +95 -36
@@ -87,12 +87,28 @@ int erofs_register_workgroup(struct super_block *sb, grp = (void *)((unsigned long )grp |1UL <<RADIX_TREE_EXCEPTIONAL_SHIFT ); +/* +* If managed cache is enabled, the reclaim path assumes +* that the last reference count is used for its workstation. +* Therefore we should bump up reference count before +* making this workgroup visible to other users. +*/ +#ifdef EROFS_FS_HAS_MANAGED_CACHE +/* refcount should be at least 2 to get on well with reclaim path */ +__erofs_workgroup_get (grp); +#endif + err =radix_tree_insert (&sbi->workstn_tree, grp->index, grp); -if (!err) { +#ifdef EROFS_FS_HAS_MANAGED_CACHE +if (unlikely (err)) +/* it is safe to decrease for refcount >= 2 */ +atomic_dec (&grp->refcount); +#else +if (!err)__erofs_workgroup_get (grp); - } +#endif erofs_workstn_unlock (sbi);radix_tree_preload_end ();
@@ -101,19 +117,90 @@ int erofs_register_workgroup(struct super_block *sb,extern void erofs_workgroup_free_rcu (struct erofs_workgroup *grp); +static void __erofs_workgroup_free (struct erofs_workgroup *grp) +{ +atomic_long_dec (&erofs_global_shrink_cnt); +erofs_workgroup_free_rcu (grp); +} +int erofs_workgroup_put (struct erofs_workgroup *grp) {int count =atomic_dec_return (&grp->refcount);if (count ==1 )atomic_long_inc (&erofs_global_shrink_cnt); -else if (!count) { -atomic_long_dec (&erofs_global_shrink_cnt); -erofs_workgroup_free_rcu (grp); - } +else if (!count) +__erofs_workgroup_free (grp);return count; } +#ifdef EROFS_FS_HAS_MANAGED_CACHE + +static void erofs_workgroup_unfreeze_final (struct erofs_workgroup *grp) +{ +erofs_workgroup_unfreeze (grp,0 ); +__erofs_workgroup_free (grp); +} + +bool erofs_try_to_release_workgroup (struct erofs_sb_info *sbi, +struct erofs_workgroup *grp, +bool cleanup) +{ +/* +* for managed cache enabled, the refcount of workgroups +* themselves could be < 0 (freezed). So there is no guarantee +* that all refcount > 0 if managed cache is enabled. +*/ +if (!erofs_workgroup_try_to_freeze (grp,1 )) +return false; + +/* +* note that all cached pages should be unlinked +* before delete it from the radix tree. +* Otherwise some cached pages of an orphan old workgroup +* could be still linked after the new one is available. +*/ +if (erofs_try_to_free_all_cached_pages (sbi, grp)) { +erofs_workgroup_unfreeze (grp,1 ); +return false; + } + +/* it is impossible to fail after we freeze the workgroup */ +if (radix_tree_delete (&sbi->workstn_tree, grp->index) != grp) +BUG ();/* should never happen */ + +/* +* if managed cache is enable, the last refcount +* should indicate the related workstation. +*/ +erofs_workgroup_unfreeze_final (grp); +return true; +} + +#else + +bool erofs_try_to_release_workgroup (struct erofs_sb_info *sbi, +struct erofs_workgroup *grp, +bool cleanup) +{ +int cnt =atomic_read (&grp->refcount); + +DBG_BUGON (cnt <=0 ); +DBG_BUGON (cleanup && cnt !=1 ); + +if (cnt >1 ) +return false; + +if (radix_tree_delete (&sbi->workstn_tree, grp->index) != grp) +return false; + +/* (rarely) could be grabbed again when freeing */ +erofs_workgroup_put (grp); +return true; +} + +#endif +unsigned long erofs_shrink_workstation (struct erofs_sb_info *sbi,unsigned long nr_shrink,bool cleanup)
@@ -130,43 +217,15 @@ unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi, batch, first_index, PAGEVEC_SIZE);for (i =0 ; i < found; ++i) { -int cnt;struct erofs_workgroup *grp = (void *) ((unsigned long )batch[i] & ~RADIX_TREE_EXCEPTIONAL_ENTRY ); first_index = grp->index +1 ; - cnt =atomic_read (&grp->refcount); -BUG_ON (cnt <=0 ); - -if (cleanup) -BUG_ON (cnt !=1 ); - -#ifndef EROFS_FS_HAS_MANAGED_CACHE - else if (cnt > 1) -#else - if (!erofs_workgroup_try_to_freeze(grp, 1)) -#endif -continue ; - -if (radix_tree_delete (&sbi->workstn_tree, - grp->index) != grp) { -#ifdef EROFS_FS_HAS_MANAGED_CACHE -skip: -erofs_workgroup_unfreeze (grp,1 ); -#endif +/* try to shrink each workgroup */ +if (!erofs_try_to_release_workgroup (sbi, grp, cleanup))continue ; - } - -#ifdef EROFS_FS_HAS_MANAGED_CACHE -if (erofs_try_to_free_all_cached_pages (sbi, grp)) - goto skip; - -erofs_workgroup_unfreeze (grp,1 ); -#endif -/* (rarely) grabbed again when freeing */ -erofs_workgroup_put (grp); ++freed;if (unlikely (!--nr_shrink))
Signature · 1 line
1.9.1
PATCH 2/3 staging: erofs: fix race when the managed cache is enabled
Quoted 5 lines · Gao Xiang
When the managed cache is enabled, the last reference count of a workgroup must be used for its workstation.
Otherwise, it could lead to incorrect (un)freezes in the reclaim path, and it would be harmful.
Could you add related race condition stack to demonstrate this problem more clearly?
Thanks,
Quoted 183 lines
Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>--- drivers/staging/erofs/utils.c | 131 ++++++++++++++++++++++++++++++------------ 1 file changed, 95 insertions(+), 36 deletions(-)drivers/staging/erofs/utils.c +95
-36@@ -87,12 +87,28 @@ int erofs_register_workgroup(struct super_block *sb, grp = (void *)((unsigned long )grp |1UL <<RADIX_TREE_EXCEPTIONAL_SHIFT ); +/* +* If managed cache is enabled, the reclaim path assumes +* that the last reference count is used for its workstation. +* Therefore we should bump up reference count before +* making this workgroup visible to other users. +*/ +#ifdef EROFS_FS_HAS_MANAGED_CACHE +/* refcount should be at least 2 to get on well with reclaim path */ +__erofs_workgroup_get (grp); +#endif + err =radix_tree_insert (&sbi->workstn_tree, grp->index, grp); -if (!err) { +#ifdef EROFS_FS_HAS_MANAGED_CACHE +if (unlikely (err)) +/* it is safe to decrease for refcount >= 2 */ +atomic_dec (&grp->refcount); +#else +if (!err)__erofs_workgroup_get (grp); - } +#endif erofs_workstn_unlock (sbi);radix_tree_preload_end ();@@ -101,19 +117,90 @@ int erofs_register_workgroup(struct super_block *sb,extern void erofs_workgroup_free_rcu (struct erofs_workgroup *grp); +static void __erofs_workgroup_free (struct erofs_workgroup *grp) +{ +atomic_long_dec (&erofs_global_shrink_cnt); +erofs_workgroup_free_rcu (grp); +} +int erofs_workgroup_put (struct erofs_workgroup *grp) {int count =atomic_dec_return (&grp->refcount);if (count ==1 )atomic_long_inc (&erofs_global_shrink_cnt); -else if (!count) { -atomic_long_dec (&erofs_global_shrink_cnt); -erofs_workgroup_free_rcu (grp); - } +else if (!count) +__erofs_workgroup_free (grp);return count; } +#ifdef EROFS_FS_HAS_MANAGED_CACHE + +static void erofs_workgroup_unfreeze_final (struct erofs_workgroup *grp) +{ +erofs_workgroup_unfreeze (grp,0 ); +__erofs_workgroup_free (grp); +} + +bool erofs_try_to_release_workgroup (struct erofs_sb_info *sbi, +struct erofs_workgroup *grp, +bool cleanup) +{ +/* +* for managed cache enabled, the refcount of workgroups +* themselves could be < 0 (freezed). So there is no guarantee +* that all refcount > 0 if managed cache is enabled. +*/ +if (!erofs_workgroup_try_to_freeze (grp,1 )) +return false; + +/* +* note that all cached pages should be unlinked +* before delete it from the radix tree. +* Otherwise some cached pages of an orphan old workgroup +* could be still linked after the new one is available. +*/ +if (erofs_try_to_free_all_cached_pages (sbi, grp)) { +erofs_workgroup_unfreeze (grp,1 ); +return false; + } + +/* it is impossible to fail after we freeze the workgroup */ +if (radix_tree_delete (&sbi->workstn_tree, grp->index) != grp) +BUG ();/* should never happen */ + +/* +* if managed cache is enable, the last refcount +* should indicate the related workstation. +*/ +erofs_workgroup_unfreeze_final (grp); +return true; +} + +#else + +bool erofs_try_to_release_workgroup (struct erofs_sb_info *sbi, +struct erofs_workgroup *grp, +bool cleanup) +{ +int cnt =atomic_read (&grp->refcount); + +DBG_BUGON (cnt <=0 ); +DBG_BUGON (cleanup && cnt !=1 ); + +if (cnt >1 ) +return false; + +if (radix_tree_delete (&sbi->workstn_tree, grp->index) != grp) +return false; + +/* (rarely) could be grabbed again when freeing */ +erofs_workgroup_put (grp); +return true; +} + +#endif +unsigned long erofs_shrink_workstation (struct erofs_sb_info *sbi,unsigned long nr_shrink,bool cleanup)@@ -130,43 +217,15 @@ unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi, batch, first_index, PAGEVEC_SIZE);for (i =0 ; i < found; ++i) { -int cnt;struct erofs_workgroup *grp = (void *) ((unsigned long )batch[i] & ~RADIX_TREE_EXCEPTIONAL_ENTRY ); first_index = grp->index +1 ; - cnt =atomic_read (&grp->refcount); -BUG_ON (cnt <=0 ); - -if (cleanup) -BUG_ON (cnt !=1 ); - -#ifndef EROFS_FS_HAS_MANAGED_CACHE - else if (cnt > 1) -#else - if (!erofs_workgroup_try_to_freeze(grp, 1)) -#endif -continue ; - -if (radix_tree_delete (&sbi->workstn_tree, - grp->index) != grp) { -#ifdef EROFS_FS_HAS_MANAGED_CACHE -skip: -erofs_workgroup_unfreeze (grp,1 ); -#endif +/* try to shrink each workgroup */ +if (!erofs_try_to_release_workgroup (sbi, grp, cleanup))continue ; - } - -#ifdef EROFS_FS_HAS_MANAGED_CACHE -if (erofs_try_to_free_all_cached_pages (sbi, grp)) - goto skip; - -erofs_workgroup_unfreeze (grp,1 ); -#endif -/* (rarely) grabbed again when freeing */ -erofs_workgroup_put (grp); ++freed;if (unlikely (!--nr_shrink))
PATCH 2/3 staging: erofs: fix race when the managed cache is enabled
Hi Chao,
Quoted 8 lines · Chao Yu
Quoted 5 lines · Gao Xiang
When the managed cache is enabled, the last reference count of a workgroup must be used for its workstation.
Otherwise, it could lead to incorrect (un)freezes in the reclaim path, and it would be harmful.
Could you add related race condition stack to demonstrate this problem more clearly?
I remembered that the original related stack isn't directly related to code fixing in this patch. I reviewed the reclaim path then and found a issue, so the patch it is.
The incorrect reclaim will do harm to other code, but I think I can try to give a rough race condition (some stack) in the next patch.
That is because when the managed cache is enabled, the reclaim path will work for every decompression workgroup with refcount == 1.
Just like the page cache (and pages are not truncated) refcount idea, the last refcount should be reserved for its tree rather than other uses for all cases by design.
Thanks,
Gao Xiang
Quoted 2 lines
Thanks,
PATCH v2 2/3 staging: erofs: fix race when the managed cache is enabled
In reply to Chao YuWhen the managed cache is enabled, the last reference count of a workgroup must be used for its workstation.
Otherwise, it could lead to incorrect (un)freezes in the reclaim path, and it would be harmful.
A typical race as follows:
Thread 1 (In the reclaim path) Thread 2workgroup_freeze(grp, 1) refcnt = 1
...
workgroup_unfreeze(grp, 1) refcnt = 1
workgroup_get(grp) refcnt = 2 (x)
workgroup_put(grp) refcnt = 1 (x)...unexpected behaviors
* grp is detached but still used, which violates cache-managed freeze constraint.
---
Change log v2:
- add the detail of race condition as pointed out by Chao
drivers/staging/erofs/utils.c | 130 +++++++++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 39 deletions(-)
drivers/staging/erofs/utils.c +91 -39
@@ -87,12 +87,21 @@ int erofs_register_workgroup(struct super_block *sb, grp = (void *)((unsigned long )grp |1UL <<RADIX_TREE_EXCEPTIONAL_SHIFT ); - err =radix_tree_insert (&sbi->workstn_tree, - grp->index, grp); +/* +* Bump up reference count before making this workgroup +* visible to other users in order to avoid potential UAF +* without serialized by erofs_workstn_lock. +*/ +__erofs_workgroup_get (grp); -if (!err) { -__erofs_workgroup_get (grp); - } + err =radix_tree_insert (&sbi->workstn_tree, + grp->index, grp); +if (unlikely (err)) +/* +* it's safe to decrease since the workgroup isn't visible +* and refcount >= 2 (cannot be freezed). +*/ +atomic_dec (&grp->refcount);erofs_workstn_unlock (sbi);radix_tree_preload_end ();
@@ -101,19 +110,90 @@ int erofs_register_workgroup(struct super_block *sb,extern void erofs_workgroup_free_rcu (struct erofs_workgroup *grp); +static void __erofs_workgroup_free (struct erofs_workgroup *grp) +{ +atomic_long_dec (&erofs_global_shrink_cnt); +erofs_workgroup_free_rcu (grp); +} +int erofs_workgroup_put (struct erofs_workgroup *grp) {int count =atomic_dec_return (&grp->refcount);if (count ==1 )atomic_long_inc (&erofs_global_shrink_cnt); -else if (!count) { -atomic_long_dec (&erofs_global_shrink_cnt); -erofs_workgroup_free_rcu (grp); - } +else if (!count) +__erofs_workgroup_free (grp);return count; } +#ifdef EROFS_FS_HAS_MANAGED_CACHE +/* for cache-managed case, customized reclaim paths exist */ +static void erofs_workgroup_unfreeze_final (struct erofs_workgroup *grp) +{ +erofs_workgroup_unfreeze (grp,0 ); +__erofs_workgroup_free (grp); +} + +bool erofs_try_to_release_workgroup (struct erofs_sb_info *sbi, +struct erofs_workgroup *grp, +bool cleanup) +{ +/* +* for managed cache enabled, the refcount of workgroups +* themselves could be < 0 (freezed). So there is no guarantee +* that all refcount > 0 if managed cache is enabled. +*/ +if (!erofs_workgroup_try_to_freeze (grp,1 )) +return false; + +/* +* note that all cached pages should be unlinked +* before delete it from the radix tree. +* Otherwise some cached pages of an orphan old workgroup +* could be still linked after the new one is available. +*/ +if (erofs_try_to_free_all_cached_pages (sbi, grp)) { +erofs_workgroup_unfreeze (grp,1 ); +return false; + } + +/* it is impossible to fail after we freeze the workgroup */ +if (radix_tree_delete (&sbi->workstn_tree, grp->index) != grp) +BUG ();/* should never happen */ + +/* +* if managed cache is enable, the last refcount +* should indicate the related workstation. +*/ +erofs_workgroup_unfreeze_final (grp); +return true; +} + +#else +/* for nocache case, no customized reclaim path at all */ +bool erofs_try_to_release_workgroup (struct erofs_sb_info *sbi, +struct erofs_workgroup *grp, +bool cleanup) +{ +int cnt =atomic_read (&grp->refcount); + +DBG_BUGON (cnt <=0 ); +DBG_BUGON (cleanup && cnt !=1 ); + +if (cnt >1 ) +return false; + +if (radix_tree_delete (&sbi->workstn_tree, grp->index) != grp) +return false; + +/* (rarely) could be grabbed again when freeing */ +erofs_workgroup_put (grp); +return true; +} + +#endif +unsigned long erofs_shrink_workstation (struct erofs_sb_info *sbi,unsigned long nr_shrink,bool cleanup)
@@ -130,43 +210,15 @@ unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi, batch, first_index, PAGEVEC_SIZE);for (i =0 ; i < found; ++i) { -int cnt;struct erofs_workgroup *grp = (void *) ((unsigned long )batch[i] & ~RADIX_TREE_EXCEPTIONAL_ENTRY ); first_index = grp->index +1 ; - cnt =atomic_read (&grp->refcount); -BUG_ON (cnt <=0 ); - -if (cleanup) -BUG_ON (cnt !=1 ); - -#ifndef EROFS_FS_HAS_MANAGED_CACHE - else if (cnt > 1) -#else - if (!erofs_workgroup_try_to_freeze(grp, 1)) -#endif -continue ; - -if (radix_tree_delete (&sbi->workstn_tree, - grp->index) != grp) { -#ifdef EROFS_FS_HAS_MANAGED_CACHE -skip: -erofs_workgroup_unfreeze (grp,1 ); -#endif +/* try to shrink each valid workgroup */ +if (!erofs_try_to_release_workgroup (sbi, grp, cleanup))continue ; - } - -#ifdef EROFS_FS_HAS_MANAGED_CACHE -if (erofs_try_to_free_all_cached_pages (sbi, grp)) - goto skip; - -erofs_workgroup_unfreeze (grp,1 ); -#endif -/* (rarely) grabbed again when freeing */ -erofs_workgroup_put (grp); ++freed;if (unlikely (!--nr_shrink))
Signature · 1 line
2.14.4
PATCH 1/1 staging: erofs: add a full barrier in erofs_workgroup_unfreeze
In reply to Chao YuJust like other generic locks, insert a full barrier in case of memory reorder.
--- drivers/staging/erofs/internal.h | 2 ++ 1 file changed, 2 insertions(+)
drivers/staging/erofs/internal.h +2 -0
@@ -218,6 +218,8 @@ erofs_workgroup_unfreeze(struct erofs_workgroup *grp, int orig_val) {#if defined(CONFIG_SMP ) +smp_mb (); +atomic_set (&grp->refcount, orig_val);#endif preempt_enable ();
Signature · 1 line
2.14.4
PATCH 3/3 staging: erofs: managed pages could be locked at the time of decompression
In reply to Gao XiangManaged compressed pages should be unlocked when IO ends by design. Therefore, these pages will be up-to-date and unlocked at the time of decompression in general.
However managed pages could be re-locked in some other paths, such as the reclaim path. Let's remove the related assertion in decompression.
--- drivers/staging/erofs/unzip_vle.c | 1 - 1 file changed, 1 deletion(-)
drivers/staging/erofs/unzip_vle.c +0 -1
@@ -872,7 +872,6 @@ static int z_erofs_vle_unzip(struct super_block *sb,continue ;#ifdef EROFS_FS_HAS_MANAGED_CACHE else if (page->mapping == mngda) { -BUG_ON (PageLocked (page));BUG_ON (!PageUptodate (page));continue ; }
Signature · 1 line
1.9.1
PATCH 3/3 staging: erofs: managed pages could be locked at the time of decompression
Quoted 8 lines · Gao Xiang
Managed compressed pages should be unlocked when IO ends by design. Therefore, these pages will be up-to-date and unlocked at the time of decompression in general.
However managed pages could be re-locked in some other paths, such as the reclaim path. Let's remove the related assertion in decompression.
Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
In reply to Gao XiangHi Chao,
Could you help merge these patches into erofs-dev (rebased on the latest erofs-master)? I need to fix several issues reported these days formally.
If you have time, could you also take some time review these patches?
Thanks,
Gao Xiang
Quoted 4 lines · Gao Xiang
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
Hi Xiang,
Sorry for late response to those patches.
Quoted 4 lines · Gao Xiang
Hi Chao,
Could you help merge these patches into erofs-dev (rebased on the latest erofs-master)? I need to fix several issues reported these days formally.
No problem.
Quoted 2 lines
If you have time, could you also take some time review these patches?
Okay, will review them soon. :)
Thanks,
Quoted 9 lines
Thanks,
Gao XiangQuoted 4 lines · Gao Xiang
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
Hi Chao,
Quoted 3 lines · Chao Yu
Hi Xiang,
Sorry for late response to those patches.
That doesn't matter I know you are now busy with f2fs stuffs. ;)
I have to deal with internal reported issues which could impact our products and do more cleanup apart from stability fixes.
It seems that Linux-4.20 will be out weeks later, and we also need to prepare more for it.
And I tend to make progress in moving into fs tree before the next LTS version, we need to do more...
Source code of previewed mkfs will be released this month and it also seems much work to clean up it.
Quoted 7 lines · Gao Xiang
Quoted 4 lines
Hi Chao,
Could you help merge these patches into erofs-dev (rebased on the latest erofs-master)? I need to fix several issues reported these days formally.
Quoted 6 lines
No problem.
Quoted 2 lines
If you have time, could you also take some time review these patches?
Okay, will review them soon. :)
Thanks Chao :)
Thanks,
Gao Xiang
Quoted 12 lines
Thanks,
Quoted 9 lines
Thanks,
Gao XiangQuoted 4 lines · Gao Xiang
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
Hi Xiang,
Quoted 8 lines · Gao Xiang
Hi Chao,
Quoted 3 lines · Chao Yu
Hi Xiang,
Sorry for late response to those patches.
That doesn't matter I know you are now busy with f2fs stuffs. ;)
Yeah, still struggling in fixing quota bugs, and try to write several test case for xfstest suit.. :P
Quoted 10 lines
I have to deal with internal reported issues which could impact our products and do more cleanup apart from stability fixes.
It seems that Linux-4.20 will be out weeks later, and we also need to prepare more for it.
And I tend to make progress in moving into fs tree before the next LTS version, we need to do more...
Sounds a lot of pending work there. :)
Quoted 2 lines
Source code of previewed mkfs will be released this month and it also seems much work to clean up it.
I hope Guifu can help to handle those work.
Thanks,
Quoted 32 lines
Quoted 8 lines · Gao Xiang
Quoted 4 lines
Hi Chao,
Could you help merge these patches into erofs-dev (rebased on the latest erofs-master)? I need to fix several issues reported these days formally.
Quoted 6 lines
No problem.
Quoted 2 lines
If you have time, could you also take some time review these patches?
Okay, will review them soon. :)
Thanks Chao :)
Thanks,
Gao XiangQuoted 12 lines
Thanks,
Quoted 9 lines
Thanks,
Gao XiangQuoted 4 lines · Gao Xiang
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
Hi Chao,
Quoted 20 lines · Chao Yu
Hi Xiang,
Quoted 7 lines · Gao Xiang
Hi Chao,
Quoted 3 lines · Chao Yu
Hi Xiang,
Sorry for late response to those patches.
That doesn't matter I know you are now busy with f2fs stuffs. ;)
Yeah, still struggling in fixing quota bugs, and try to write several test case for xfstest suit.. :P
Quoted 7 lines
I have to deal with internal reported issues which could impact our products and do more cleanup apart from stability fixes.
It seems that Linux-4.20 will be out weeks later, and we also need to prepare more for it.
Quoted 6 lines
Quoted 2 lines
And I tend to make progress in moving into fs tree before the next LTS version, we need to do more...
Sounds a lot of pending work there. :)
Quoted 1 line
Source code of previewed mkfs will be released this month and it also seems much work to clean up it.
I hope Guifu can help to handle those work.
Yes, I confirmed that Guifu would like to maintain erofs mkfs related stuffs as the original mkfs author. Another guy will also take part in it.
If that is working fine, no worry about it ;)
Thanks,
Gao Xiang
Quoted 27 lines
Thanks,
Quoted 24 lines
Quoted 9 lines · Gao Xiang
Quoted 4 lines
Hi Chao,
Could you help merge these patches into erofs-dev (rebased on the latest erofs-master)? I need to fix several issues reported these days formally.
No problem.
Quoted 1 line
If you have time, could you also take some time review these patches?
Okay, will review them soon. :)
Thanks Chao :)
Thanks,
Gao XiangQuoted 10 lines
Thanks,
Quoted 8 lines
Thanks,
Gao XiangQuoted 4 lines · Gao Xiang
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
In reply to Gao XiangQuoted 14 lines · Gao Xiang
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>--- drivers/staging/erofs/inode.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/staging/erofs/internal.h | 10 ++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-)drivers/staging/erofs/inode.c +0
-0
drivers/staging/erofs/inode.c static int fill_inode(struct inode *inode, int isdir) · line 239
Quoted 8 lines
drivers/staging/erofs/inode.c +5
-0@@ -232,10 +232,45 @@ static int fill_inode(struct inode *inode, int isdir)return err; } +/* +* erofs nid is 64bits, but i_ino is 'unsigned long', therefore +* we should do more for 32-bit platform to find the right inode. +*/ +#if BITS_PER_LONG <64
#if BITS_PER_LOG == 32
Quoted 17 lines
drivers/staging/erofs/inode.c +17
-0+static int erofs_ilookup_test_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + +return EROFS_V (inode)->nid == nid; +} + +static int erofs_iget_set_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + + inode->i_ino =erofs_inode_hash (nid); +return 0 ; +} +#endif + +static inline struct inode *erofs_iget_locked(struct super_block *sb,
drivers/staging/erofs/inode.c static int fill_inode(struct inode *inode, int isdir) · line 266
Quoted 10 lines
drivers/staging/erofs/inode.c +10
-0+ erofs_nid_t nid) +{ +const unsigned long hashval =erofs_inode_hash (nid); + +#if BITS_PER_LONG >=64 +/* it is safe to use iget_locked for >= 64-bit platform */ +return iget_locked (sb, hashval); +#else +return iget5_locked (sb, hashval, erofs_ilookup_test_actor, + erofs_iget_set_actor, &nid);
How about just using iget5_locked? and then we can only handle 32/64-bit platforms difference in erofs_inode_hash()?
Quoted 16 lines
drivers/staging/erofs/inode.c +4
-1+#endif +} +struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool isdir) { -struct inode *inode =iget_locked (sb, nid); +struct inode *inode =erofs_iget_locked (sb, nid);if (unlikely (inode ==NULL ))return ERR_PTR (-ENOMEM );drivers/staging/erofs/internal.h +0
-0
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 516
Quoted 6 lines
drivers/staging/erofs/internal.h +3
-0@@ -511,6 +511,16 @@ struct erofs_map_blocks_iter { }/* inode.c */ +static inline unsigned long erofs_inode_hash (erofs_nid_t nid) +{ +u64 h = nid;
unsigned long h;
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 519
Quoted 3 lines
drivers/staging/erofs/internal.h +3
-0+ +#if BITS_PER_LONG ==32 + h = (h >>32 ) ^ (h &0xffffffff );
h = (nid >> 32) ^ (nid & 0xffffffff);
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 521
Quoted 2 lines
drivers/staging/erofs/internal.h +2
-0+#endif +return (unsigned long )h;
return h;
Thanks,
Quoted 6 lines
drivers/staging/erofs/internal.h +2
-0+} +extern struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool dir);
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
Hi Chao,
Quoted 18 lines · Chao Yu
Quoted 17 lines · Gao Xiang
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>--- drivers/staging/erofs/inode.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/staging/erofs/internal.h | 10 ++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-)drivers/staging/erofs/inode.c +0
-0@@ -232,10 +232,45 @@ static int fill_inode(struct inode *inode, int isdir)return err; }
Quoted 7 lines
drivers/staging/erofs/inode.c static int fill_inode(struct inode *inode, int isdir) · line 239
Quoted 5 lines
drivers/staging/erofs/inode.c +5
-0+/* +* erofs nid is 64bits, but i_ino is 'unsigned long', therefore +* we should do more for 32-bit platform to find the right inode. +*/ +#if BITS_PER_LONG <64 #if
BITS_PER_LOG== 32
OK.
Quoted 23 lines
Quoted 23 lines
drivers/staging/erofs/inode.c +22
-0+static int erofs_ilookup_test_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + +return EROFS_V (inode)->nid == nid; +} + +static int erofs_iget_set_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + + inode->i_ino =erofs_inode_hash (nid); +return 0 ; +} +#endif + +static inline struct inode *erofs_iget_locked (struct super_block *sb, +erofs_nid_t nid) +{ +const unsigned long hashval =erofs_inode_hash (nid); + +#if BITS_PER_LONG >=64
Quoted 8 lines
drivers/staging/erofs/inode.c static int fill_inode(struct inode *inode, int isdir) · line 266
Quoted 5 lines
drivers/staging/erofs/inode.c +5
-0+/* it is safe to use iget_locked for >= 64-bit platform */ +return iget_locked (sb, hashval); +#else +return iget5_locked (sb, hashval, erofs_ilookup_test_actor, + erofs_iget_set_actor, &nid);How about just using
iget5_locked? and then we can only handle 32/64-bit platforms difference inerofs_inode_hash()?
It seems iget_locked is faster than iget5_locked because it has more fast paths and no indirect callbacks for each inode...
Quoted 32 lines
Quoted 17 lines
drivers/staging/erofs/inode.c +4
-1+#endif +} +struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool isdir) { -struct inode *inode =iget_locked (sb, nid); +struct inode *inode =erofs_iget_locked (sb, nid);if (unlikely (inode ==NULL ))return ERR_PTR (-ENOMEM );drivers/staging/erofs/internal.h +0
-0drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 516
Quoted 6 lines
drivers/staging/erofs/internal.h +3
-0@@ -511,6 +511,16 @@ struct erofs_map_blocks_iter { }/* inode.c */ +static inline unsigned long erofs_inode_hash (erofs_nid_t nid) +{ +u64 h = nid;unsigned long h;
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 519
Quoted 3 lines
drivers/staging/erofs/internal.h +3
-0+ +#if BITS_PER_LONG ==32 + h = (h >>32 ) ^ (h &0xffffffff );h = (nid >> 32) ^ (nid &
0xffffffff);
Quoted 4 lines
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 521
Quoted 2 lines
drivers/staging/erofs/internal.h +2
-0+#endif +return (unsigned long )h;return h;
OK, will fix soon.
Thanks,
Gao Xiang
Quoted 9 lines
Thanks,
Quoted 6 lines
drivers/staging/erofs/internal.h +2
-0+} +extern struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool dir);
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
Quoted 63 lines · Gao Xiang
Hi Chao,
Quoted 18 lines · Chao Yu
Quoted 17 lines · Gao Xiang
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>--- drivers/staging/erofs/inode.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/staging/erofs/internal.h | 10 ++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-)drivers/staging/erofs/inode.c +0
-0@@ -232,10 +232,45 @@ static int fill_inode(struct inode *inode, int isdir)return err; }Quoted 7 lines
drivers/staging/erofs/inode.c static int fill_inode(struct inode *inode, int isdir) · line 239
Quoted 5 lines
drivers/staging/erofs/inode.c +5
-0+/* +* erofs nid is 64bits, but i_ino is 'unsigned long', therefore +* we should do more for 32-bit platform to find the right inode. +*/ +#if BITS_PER_LONG <64 #if
BITS_PER_LOG== 32OK.
Quoted 23 lines
Quoted 23 lines
drivers/staging/erofs/inode.c +22
-0+static int erofs_ilookup_test_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + +return EROFS_V (inode)->nid == nid; +} + +static int erofs_iget_set_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + + inode->i_ino =erofs_inode_hash (nid); +return 0 ; +} +#endif + +static inline struct inode *erofs_iget_locked (struct super_block *sb, +erofs_nid_t nid) +{ +const unsigned long hashval =erofs_inode_hash (nid); + +#if BITS_PER_LONG >=64 Quoted 8 lines
drivers/staging/erofs/inode.c static int fill_inode(struct inode *inode, int isdir) · line 266
Quoted 5 lines
drivers/staging/erofs/inode.c +5
-0+/* it is safe to use iget_locked for >= 64-bit platform */ +return iget_locked (sb, hashval); +#else +return iget5_locked (sb, hashval, erofs_ilookup_test_actor, + erofs_iget_set_actor, &nid);How about just using
iget5_locked? and then we can only handle 32/64-bit platforms difference inerofs_inode_hash()?
Quoted 2 lines
It seems
iget_lockedis faster thaniget5_lockedbecause it has more fast paths and no indirect callbacks for each inode...
That's trivial cleanup. Well, if you are worried about the performance of erofs_iget(), let's keep it as it is. :)
Thanks,
Quoted 52 lines
Quoted 33 lines
Quoted 18 lines
drivers/staging/erofs/inode.c +4
-1+#endif +} +struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool isdir) { -struct inode *inode =iget_locked (sb, nid); +struct inode *inode =erofs_iget_locked (sb, nid);if (unlikely (inode ==NULL ))return ERR_PTR (-ENOMEM );drivers/staging/erofs/internal.h +0
-0drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 516
Quoted 6 lines
drivers/staging/erofs/internal.h +3
-0@@ -511,6 +511,16 @@ struct erofs_map_blocks_iter { }/* inode.c */ +static inline unsigned long erofs_inode_hash (erofs_nid_t nid) +{ +u64 h = nid;unsigned long h;
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 519
Quoted 3 lines
drivers/staging/erofs/internal.h +3
-0+ +#if BITS_PER_LONG ==32 + h = (h >>32 ) ^ (h &0xffffffff );h = (nid >> 32) ^ (nid &
0xffffffff);Quoted 4 lines
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 521
Quoted 2 lines
drivers/staging/erofs/internal.h +2
-0+#endif +return (unsigned long )h;return h;
OK, will fix soon.
Thanks,
Gao XiangQuoted 9 lines
Thanks,
Quoted 6 lines
drivers/staging/erofs/internal.h +2
-0+} +extern struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool dir);
PATCH 1/3 staging: erofs: harden inode lookup for 32-bit platforms
Hi Chao
Quoted 6 lines · Chao Yu
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 516
Quoted 4 lines
/*
inode.c*/drivers/staging/erofs/internal.h +3
-0+static inline unsigned long erofs_inode_hash (erofs_nid_t nid) +{ +u64 h = nid;unsigned long h;
Quoted 7 lines
drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 519
Quoted 3 lines
drivers/staging/erofs/internal.h +3
-0+ +#if BITS_PER_LONG ==32 + h = (h >>32 ) ^ (h &0xffffffff );h = (nid >> 32) ^ (nid &
0xffffffff);drivers/staging/erofs/internal.h struct erofs_map_blocks_iter { · line 521
Quoted 2 lines
drivers/staging/erofs/internal.h +2
-0+#endif +return (unsigned long )h;
inode hash could be wrong in 64-bit since h is not initialized. I will fix it in another way.
Thanks,
Gao Xiang.
PATCH v2 1/1 staging: erofs: harden inode lookup for 32-bit platforms
From: Gao Xiang <[email protected]>
This patch introduces inode hash function, test and set callbacks, and iget5_locked to find the right inode for 32-bit platforms.
--- drivers/staging/erofs/inode.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/staging/erofs/internal.h | 9 +++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)
drivers/staging/erofs/inode.c +36 -1
@@ -232,10 +232,45 @@ static int fill_inode(struct inode *inode, int isdir)return err; } +/* +* erofs nid is 64bits, but i_ino is 'unsigned long', therefore +* we should do more for 32-bit platform to find the right inode. +*/ +#if BITS_PER_LONG ==32 +static int erofs_ilookup_test_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + +return EROFS_V (inode)->nid == nid; +} + +static int erofs_iget_set_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + + inode->i_ino =erofs_inode_hash (nid); +return 0 ; +} +#endif + +static inline struct inode *erofs_iget_locked (struct super_block *sb, +erofs_nid_t nid) +{ +const unsigned long hashval =erofs_inode_hash (nid); + +#if BITS_PER_LONG >=64 +/* it is safe to use iget_locked for >= 64-bit platform */ +return iget_locked (sb, hashval); +#else +return iget5_locked (sb, hashval, erofs_ilookup_test_actor, + erofs_iget_set_actor, &nid); +#endif +} +struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool isdir) { -struct inode *inode =iget_locked (sb, nid); +struct inode *inode =erofs_iget_locked (sb, nid);if (unlikely (inode ==NULL ))return ERR_PTR (-ENOMEM );
drivers/staging/erofs/internal.h +9 -0
@@ -511,6 +511,15 @@ erofs_get_inline_page(struct inode *inode, }/* inode.c */ +static inline unsigned long erofs_inode_hash (erofs_nid_t nid) +{ +#if BITS_PER_LONG ==32 +return (nid >>32 ) ^ (nid &0xffffffff ); +#else +return nid; +#endif +} +extern struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool dir);
Signature · 1 line
2.7.4
PATCH v2 1/1 staging: erofs: harden inode lookup for 32-bit platforms
Quoted 67 lines · Gao Xiang
From: Gao Xiang <gaoxiang25 at huawei.com>
This patch introduces inode hash function, test and set callbacks, and
iget5_lockedto find the right inode for 32-bit platforms.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>--- drivers/staging/erofs/inode.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/staging/erofs/internal.h | 9 +++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)drivers/staging/erofs/inode.c +36
-1@@ -232,10 +232,45 @@ static int fill_inode(struct inode *inode, int isdir)return err; } +/* +* erofs nid is 64bits, but i_ino is 'unsigned long', therefore +* we should do more for 32-bit platform to find the right inode. +*/ +#if BITS_PER_LONG ==32 +static int erofs_ilookup_test_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + +return EROFS_V (inode)->nid == nid; +} + +static int erofs_iget_set_actor (struct inode *inode,void *opaque) +{ +const erofs_nid_t nid = *(erofs_nid_t *)opaque; + + inode->i_ino =erofs_inode_hash (nid); +return 0 ; +} +#endif + +static inline struct inode *erofs_iget_locked (struct super_block *sb, +erofs_nid_t nid) +{ +const unsigned long hashval =erofs_inode_hash (nid); + +#if BITS_PER_LONG >=64 +/* it is safe to use iget_locked for >= 64-bit platform */ +return iget_locked (sb, hashval); +#else +return iget5_locked (sb, hashval, erofs_ilookup_test_actor, + erofs_iget_set_actor, &nid); +#endif +} +struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool isdir) { -struct inode *inode =iget_locked (sb, nid); +struct inode *inode =erofs_iget_locked (sb, nid);if (unlikely (inode ==NULL ))return ERR_PTR (-ENOMEM );drivers/staging/erofs/internal.h +0
-0
drivers/staging/erofs/internal.h erofs_get_inline_page(struct inode *inode, · line 520
Quoted 10 lines
drivers/staging/erofs/internal.h +7
-0@@ -511,6 +511,15 @@ erofs_get_inline_page(struct inode *inode, }/* inode.c */ +static inline unsigned long erofs_inode_hash (erofs_nid_t nid) +{ +#if BITS_PER_LONG ==32 +return (nid >>32 ) ^ (nid &0xffffffff ); +#else +return nid; +#endif
That's the right way. :)
Thanks,
Quoted 6 lines
drivers/staging/erofs/internal.h +2
-0+} +extern struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool dir);