Skip to content

Commit

Permalink
zswap: don't param_set_charp while holding spinlock
Browse files Browse the repository at this point in the history
Change the zpool/compressor param callback function to release the
zswap_pools_lock spinlock before calling param_set_charp, since that
function may sleep when it calls kmalloc with GFP_KERNEL.

While this problem has existed for a while, I wasn't able to trigger it
using a tight loop changing either/both the zpool and compressor params; I
think it's very unlikely to be an issue on the stable kernels, especially
since most zswap users will change the compressor and/or zpool from sysfs
only one time each boot - or zero times, if they add the params to the
kernel boot.

Fixes: c99b42c ("zswap: use charp for zswap param strings")
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Dan Streetman <[email protected]>
Reported-by: Sergey Senozhatsky <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Minchan Kim <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ddstreet authored and torvalds committed Feb 28, 2017
1 parent bae21db commit fd5bb66
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mm/zswap.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,18 +704,22 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp,
pool = zswap_pool_find_get(type, compressor);
if (pool) {
zswap_pool_debug("using existing", pool);
WARN_ON(pool == zswap_pool_current());
list_del_rcu(&pool->list);
} else {
spin_unlock(&zswap_pools_lock);
pool = zswap_pool_create(type, compressor);
spin_lock(&zswap_pools_lock);
}

spin_unlock(&zswap_pools_lock);

if (!pool)
pool = zswap_pool_create(type, compressor);

if (pool)
ret = param_set_charp(s, kp);
else
ret = -EINVAL;

spin_lock(&zswap_pools_lock);

if (!ret) {
put_pool = zswap_pool_current();
list_add_rcu(&pool->list, &zswap_pools);
Expand All @@ -727,7 +731,11 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp,
*/
list_add_tail_rcu(&pool->list, &zswap_pools);
put_pool = pool;
} else if (!zswap_has_pool) {
}

spin_unlock(&zswap_pools_lock);

if (!zswap_has_pool && !pool) {
/* if initial pool creation failed, and this pool creation also
* failed, maybe both compressor and zpool params were bad.
* Allow changing this param, so pool creation will succeed
Expand All @@ -738,8 +746,6 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp,
ret = param_set_charp(s, kp);
}

spin_unlock(&zswap_pools_lock);

/* drop the ref from either the old current pool,
* or the new pool we failed to add
*/
Expand Down

0 comments on commit fd5bb66

Please sign in to comment.