Commit 6d7d9798ad5c97ee4e911dd070dc12dc5ae55bd0
Committed by
Greg Kroah-Hartman
1 parent
6bd4a5d96c
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
staging: zcache: fix cleancache race condition with shrinker
This patch fixes a race condition that results in memory corruption when using cleancache. The race exists between the zcache shrinker handler, shrink_zcache_memory() and cleancache_get_page(). In most cases, the shrinker will both evict a zbpg from its buddy list and flush it from tmem before a cleancache_get_page() occurs on that page. A subsequent cleancache_get_page() will fail in the tmem layer. In the rare case that two occur together and the cleancache_get_page() path gets through the tmem layer before the shrinker path can flush tmem, zbud_decompress() does a check to see if the zbpg is a "zombie", i.e. not on a buddy list, which means the shrinker is in the process of reclaiming it. If the zbpg is a zombie, zbud_decompress() returns -EINVAL. However, this return code is being ignored by the caller, zcache_pampd_get_data_and_free(), which results in the caller of cleancache_get_page() thinking that the page has been properly retrieved when it has not. This patch modifies zcache_pampd_get_data_and_free() to convey the failure up the stack so that the caller of cleancache_get_page() knows the page retrieval failed. This needs to be applied to stable trees as well. zcache-main.c was named zcache.c before v3.1, so I'm not sure how you want to handle trees earlier than that. Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com> Cc: stable <stable@vger.kernel.org> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Reviewed-by: Minchan Kim <minchan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 1 changed file with 3 additions and 4 deletions Side-by-side Diff
drivers/staging/zcache/zcache-main.c
... | ... | @@ -1251,13 +1251,12 @@ |
1251 | 1251 | void *pampd, struct tmem_pool *pool, |
1252 | 1252 | struct tmem_oid *oid, uint32_t index) |
1253 | 1253 | { |
1254 | - int ret = 0; | |
1255 | - | |
1256 | 1254 | BUG_ON(!is_ephemeral(pool)); |
1257 | - zbud_decompress((struct page *)(data), pampd); | |
1255 | + if (zbud_decompress((struct page *)(data), pampd) < 0) | |
1256 | + return -EINVAL; | |
1258 | 1257 | zbud_free_and_delist((struct zbud_hdr *)pampd); |
1259 | 1258 | atomic_dec(&zcache_curr_eph_pampd_count); |
1260 | - return ret; | |
1259 | + return 0; | |
1261 | 1260 | } |
1262 | 1261 | |
1263 | 1262 | /* |