aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/zram/zram_drv.c
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2016-07-26 18:22:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-07-26 19:19:19 -0400
commit415403be37e204632b17bdb6857890fe5a220cea (patch)
tree994757df320bc700b01ea86fa458a071f925ae58 /drivers/block/zram/zram_drv.c
parentebaf9ab56d9d5f350969bd1ea8f47234623c9684 (diff)
zram: use crypto api to check alg availability
There is no way to get a string with all the crypto comp algorithms supported by the crypto comp engine, so we need to maintain our own backends list. At the same time we additionally need to use crypto_has_comp() to make sure that the user has requested a compression algorithm that is recognized by the crypto comp engine. Relying on /proc/crypto is not an options here, because it does not show not-yet-inserted compression modules. Example: modprobe zram cat /proc/crypto | grep -i lz4 modprobe lz4 cat /proc/crypto | grep -i lz4 name : lz4 driver : lz4-generic module : lz4 So the user can't tell exactly if the lz4 is really supported from /proc/crypto output, unless someone or something has loaded it. This patch also adds crypto_has_comp() to zcomp_available_show(). We store all the compression algorithms names in zcomp's `backends' array, regardless the CONFIG_CRYPTO_FOO configuration, but show only those that are also supported by crypto engine. This helps user to know the exact list of compression algorithms that can be used. Example: module lz4 is not loaded yet, but is supported by the crypto engine. /proc/crypto has no information on this module, while zram's `comp_algorithm' lists it: cat /proc/crypto | grep -i lz4 cat /sys/block/zram0/comp_algorithm [lzo] lz4 deflate lz4hc 842 We still use the `backends' array to determine if the requested compression backend is known to crypto api. This array, however, may not contain some entries, therefore as the last step we call crypto_has_comp() function which attempts to insmod the requested compression algorithm to determine if crypto api supports it. The advantage of this method is that now we permit the usage of out-of-tree crypto compression modules (implementing S/W or H/W compression). [sergey.senozhatsky@gmail.com: zram-use-crypto-api-to-check-alg-availability-v3] Link: http://lkml.kernel.org/r/20160604024902.11778-4-sergey.senozhatsky@gmail.com Link: http://lkml.kernel.org/r/20160531122017.2878-5-sergey.senozhatsky@gmail.com Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/zram/zram_drv.c')
-rw-r--r--drivers/block/zram/zram_drv.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 65d140336289..c2a1d7dbaec9 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -342,9 +342,16 @@ static ssize_t comp_algorithm_store(struct device *dev,
342 struct device_attribute *attr, const char *buf, size_t len) 342 struct device_attribute *attr, const char *buf, size_t len)
343{ 343{
344 struct zram *zram = dev_to_zram(dev); 344 struct zram *zram = dev_to_zram(dev);
345 char compressor[CRYPTO_MAX_ALG_NAME];
345 size_t sz; 346 size_t sz;
346 347
347 if (!zcomp_available_algorithm(buf)) 348 strlcpy(compressor, buf, sizeof(compressor));
349 /* ignore trailing newline */
350 sz = strlen(compressor);
351 if (sz > 0 && compressor[sz - 1] == '\n')
352 compressor[sz - 1] = 0x00;
353
354 if (!zcomp_available_algorithm(compressor))
348 return -EINVAL; 355 return -EINVAL;
349 356
350 down_write(&zram->init_lock); 357 down_write(&zram->init_lock);
@@ -353,13 +360,8 @@ static ssize_t comp_algorithm_store(struct device *dev,
353 pr_info("Can't change algorithm for initialized device\n"); 360 pr_info("Can't change algorithm for initialized device\n");
354 return -EBUSY; 361 return -EBUSY;
355 } 362 }
356 strlcpy(zram->compressor, buf, sizeof(zram->compressor));
357
358 /* ignore trailing newline */
359 sz = strlen(zram->compressor);
360 if (sz > 0 && zram->compressor[sz - 1] == '\n')
361 zram->compressor[sz - 1] = 0x00;
362 363
364 strlcpy(zram->compressor, compressor, sizeof(compressor));
363 up_write(&zram->init_lock); 365 up_write(&zram->init_lock);
364 return len; 366 return len;
365} 367}