Skip to contentSkip to conversation

staging: erofs: fix race when the managed cache is enabled

PATCH New Gao Xiang 2 participants 2 messages Mar 18, 2019

Subsystems (2)
lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH v3 1/1 staging: erofs: fix race when the managed cache is enabled

commit 51232df5e4b268936beccde5248f312a316800be upstream.

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.

A typical race as follows:

Thread 1 (In the reclaim path) Thread 2
workgroup_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.

Reviewed-by Chao Yu <yuchao0 at huawei.com>
Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>

---

change log v3:
- avoid using xa_tag apis since Matthew refuses the first XArray patch in the previous version again;

RESEND in order to ping due to lack of response from Matthew and Greg for half a month, patch 2/2 is needed to be backported to linux-4.19.

change log v2:
- fix tagged pointer apis to make it work properly pointed out by Matthew;

Thanks,
Gao Xiang

 drivers/staging/erofs/internal.h |   1 +
 drivers/staging/erofs/utils.c    | 139 ++++++++++++++++++++++++++++-----------
 2 files changed, 101 insertions(+), 39 deletions(-)
drivers/staging/erofs/internal.h +1 -0
index c70f0c5237ea..58d8cbc3f921 100644
@@ -260,6 +260,7 @@ static inline bool erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt)
 }
 
 #define __erofs_workgroup_get(grp)	atomic_inc(&(grp)->refcount)
+#define __erofs_workgroup_put(grp)	atomic_dec(&(grp)->refcount)
 
 extern int erofs_workgroup_put(struct erofs_workgroup *grp);
 
drivers/staging/erofs/utils.c +100 -39

175 lines not on this page · raw message

Signature · 1 line
2.14.5
maintainer Applied
#1 lore raw

PATCH v3 1/1 staging: erofs: fix race when the managed cache is enabled

Quoted 23 lines · Gao Xiang

commit 51232df5e4b268936beccde5248f312a316800be upstream.

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.

A typical race as follows:

Thread 1 (In the reclaim path) Thread 2
workgroup_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.

Reviewed-by Chao Yu <yuchao0 at huawei.com>
Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Quoted 8 lines

---

change log v3:
- avoid using xa_tag apis since Matthew refuses the first XArray patch in the previous version again;

RESEND in order to ping due to lack of response from Matthew and Greg for half a month, patch 2/2 is needed to be backported to linux-4.19.

I've queued this up now, thanks.

greg k-h