hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
kernel/mm/zswap.c
....@@ -27,6 +27,7 @@
2727 #include <linux/highmem.h>
2828 #include <linux/slab.h>
2929 #include <linux/spinlock.h>
30
+#include <linux/locallock.h>
3031 #include <linux/types.h>
3132 #include <linux/atomic.h>
3233 #include <linux/frontswap.h>
....@@ -990,6 +991,8 @@
990991 memset_l(page, value, PAGE_SIZE / sizeof(unsigned long));
991992 }
992993
994
+/* protect zswap_dstmem from concurrency */
995
+static DEFINE_LOCAL_IRQ_LOCK(zswap_dstmem_lock);
993996 /*********************************
994997 * frontswap hooks
995998 **********************************/
....@@ -1066,12 +1069,11 @@
10661069 }
10671070
10681071 /* compress */
1069
- dst = get_cpu_var(zswap_dstmem);
1070
- tfm = *get_cpu_ptr(entry->pool->tfm);
1072
+ dst = get_locked_var(zswap_dstmem_lock, zswap_dstmem);
1073
+ tfm = *this_cpu_ptr(entry->pool->tfm);
10711074 src = kmap_atomic(page);
10721075 ret = crypto_comp_compress(tfm, src, PAGE_SIZE, dst, &dlen);
10731076 kunmap_atomic(src);
1074
- put_cpu_ptr(entry->pool->tfm);
10751077 if (ret) {
10761078 ret = -EINVAL;
10771079 goto put_dstmem;
....@@ -1094,7 +1096,7 @@
10941096 memcpy(buf, &zhdr, hlen);
10951097 memcpy(buf + hlen, dst, dlen);
10961098 zpool_unmap_handle(entry->pool->zpool, handle);
1097
- put_cpu_var(zswap_dstmem);
1099
+ put_locked_var(zswap_dstmem_lock, zswap_dstmem);
10981100
10991101 /* populate entry */
11001102 entry->offset = offset;
....@@ -1122,7 +1124,7 @@
11221124 return 0;
11231125
11241126 put_dstmem:
1125
- put_cpu_var(zswap_dstmem);
1127
+ put_locked_var(zswap_dstmem_lock, zswap_dstmem);
11261128 zswap_pool_put(entry->pool);
11271129 freepage:
11281130 zswap_entry_cache_free(entry);