diff options
author | Dan Streetman <ddstreet@ieee.org> | 2017-02-27 17:26:53 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-02-27 21:43:45 -0500 |
commit | fd5bb66cd934987e49557455b6497fc006521940 (patch) | |
tree | d238fc3900b464c335b8719703ee1bfd9743c719 /mm | |
parent | bae21db88b7075662f28a0aa57e97016a2fdabfd (diff) |
zswap: don't param_set_charp while holding spinlock
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: c99b42c3529e ("zswap: use charp for zswap param strings")
Link: http://lkml.kernel.org/r/20170126155821.4545-1-ddstreet@ieee.org
Signed-off-by: Dan Streetman <dan.streetman@canonical.com>
Reported-by: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/zswap.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/mm/zswap.c b/mm/zswap.c index 9e8565d9c66b..eedc27894b10 100644 --- a/mm/zswap.c +++ b/mm/zswap.c | |||
@@ -704,18 +704,22 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, | |||
704 | pool = zswap_pool_find_get(type, compressor); | 704 | pool = zswap_pool_find_get(type, compressor); |
705 | if (pool) { | 705 | if (pool) { |
706 | zswap_pool_debug("using existing", pool); | 706 | zswap_pool_debug("using existing", pool); |
707 | WARN_ON(pool == zswap_pool_current()); | ||
707 | list_del_rcu(&pool->list); | 708 | list_del_rcu(&pool->list); |
708 | } else { | ||
709 | spin_unlock(&zswap_pools_lock); | ||
710 | pool = zswap_pool_create(type, compressor); | ||
711 | spin_lock(&zswap_pools_lock); | ||
712 | } | 709 | } |
713 | 710 | ||
711 | spin_unlock(&zswap_pools_lock); | ||
712 | |||
713 | if (!pool) | ||
714 | pool = zswap_pool_create(type, compressor); | ||
715 | |||
714 | if (pool) | 716 | if (pool) |
715 | ret = param_set_charp(s, kp); | 717 | ret = param_set_charp(s, kp); |
716 | else | 718 | else |
717 | ret = -EINVAL; | 719 | ret = -EINVAL; |
718 | 720 | ||
721 | spin_lock(&zswap_pools_lock); | ||
722 | |||
719 | if (!ret) { | 723 | if (!ret) { |
720 | put_pool = zswap_pool_current(); | 724 | put_pool = zswap_pool_current(); |
721 | list_add_rcu(&pool->list, &zswap_pools); | 725 | list_add_rcu(&pool->list, &zswap_pools); |
@@ -727,7 +731,11 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, | |||
727 | */ | 731 | */ |
728 | list_add_tail_rcu(&pool->list, &zswap_pools); | 732 | list_add_tail_rcu(&pool->list, &zswap_pools); |
729 | put_pool = pool; | 733 | put_pool = pool; |
730 | } else if (!zswap_has_pool) { | 734 | } |
735 | |||
736 | spin_unlock(&zswap_pools_lock); | ||
737 | |||
738 | if (!zswap_has_pool && !pool) { | ||
731 | /* if initial pool creation failed, and this pool creation also | 739 | /* if initial pool creation failed, and this pool creation also |
732 | * failed, maybe both compressor and zpool params were bad. | 740 | * failed, maybe both compressor and zpool params were bad. |
733 | * Allow changing this param, so pool creation will succeed | 741 | * Allow changing this param, so pool creation will succeed |
@@ -738,8 +746,6 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, | |||
738 | ret = param_set_charp(s, kp); | 746 | ret = param_set_charp(s, kp); |
739 | } | 747 | } |
740 | 748 | ||
741 | spin_unlock(&zswap_pools_lock); | ||
742 | |||
743 | /* drop the ref from either the old current pool, | 749 | /* drop the ref from either the old current pool, |
744 | * or the new pool we failed to add | 750 | * or the new pool we failed to add |
745 | */ | 751 | */ |