]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
staging: erofs: fix race when the managed cache is enabled
authorGao Xiang <gaoxiang25@huawei.com>
Thu, 22 Nov 2018 17:16:00 +0000 (01:16 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Feb 2019 19:02:09 +0000 (20:02 +0100)
commite6cef0ba3b97744883d83867ac9d18c8b3f1b404
tree4be1fb414f3ee7a6111e2c8673aec5f71db834b6
parent289d181cfaa5ffb6898735d191f1a660ca6229bf
staging: erofs: fix race when the managed cache is enabled

[ Upstream commit 51232df5e4b268936beccde5248f312a316800be ]

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@huawei.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/staging/erofs/internal.h
drivers/staging/erofs/utils.c