[f2fs-dev] [PATCH 08/10] f2fs crypto: migrate into vfs's crypto engine

2016-03-02 Thread Jaegeuk Kim
This patch removes the most parts of internal crypto codes.
And then, it modifies some f2fs-specific crypt codes to use the generic
facility.

Signed-off-by: Jaegeuk Kim 
---
 fs/f2fs/Kconfig |  10 +-
 fs/f2fs/Makefile|   2 -
 fs/f2fs/crypto.c| 473 
 fs/f2fs/crypto_fname.c  | 446 -
 fs/f2fs/crypto_key.c| 267 ---
 fs/f2fs/crypto_policy.c | 210 -
 fs/f2fs/data.c  |  31 ++--
 fs/f2fs/dir.c   |  44 ++---
 fs/f2fs/f2fs.h  | 172 --
 fs/f2fs/f2fs_crypto.h   | 151 
 fs/f2fs/file.c  |  36 ++--
 fs/f2fs/inline.c|   4 +-
 fs/f2fs/inode.c |   5 +-
 fs/f2fs/namei.c |  56 +++---
 fs/f2fs/super.c |  55 --
 15 files changed, 149 insertions(+), 1813 deletions(-)
 delete mode 100644 fs/f2fs/crypto.c
 delete mode 100644 fs/f2fs/crypto_fname.c
 delete mode 100644 fs/f2fs/crypto_key.c
 delete mode 100644 fs/f2fs/crypto_policy.c
 delete mode 100644 fs/f2fs/f2fs_crypto.h

diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig
index b0a9dc9..402792b 100644
--- a/fs/f2fs/Kconfig
+++ b/fs/f2fs/Kconfig
@@ -76,15 +76,7 @@ config F2FS_FS_ENCRYPTION
bool "F2FS Encryption"
depends on F2FS_FS
depends on F2FS_FS_XATTR
-   select CRYPTO_AES
-   select CRYPTO_CBC
-   select CRYPTO_ECB
-   select CRYPTO_XTS
-   select CRYPTO_CTS
-   select CRYPTO_CTR
-   select CRYPTO_SHA256
-   select KEYS
-   select ENCRYPTED_KEYS
+   select FS_ENCRYPTION
help
  Enable encryption of f2fs files and directories.  This
  feature is similar to ecryptfs, but it is more memory
diff --git a/fs/f2fs/Makefile b/fs/f2fs/Makefile
index 08e101e..ca949ea 100644
--- a/fs/f2fs/Makefile
+++ b/fs/f2fs/Makefile
@@ -7,5 +7,3 @@ f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o
 f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o
 f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
 f2fs-$(CONFIG_F2FS_IO_TRACE) += trace.o
-f2fs-$(CONFIG_F2FS_FS_ENCRYPTION) += crypto_policy.o crypto.o \
-   crypto_key.o crypto_fname.o
diff --git a/fs/f2fs/crypto.c b/fs/f2fs/crypto.c
deleted file mode 100644
index 3ef3786..000
--- a/fs/f2fs/crypto.c
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- * linux/fs/f2fs/crypto.c
- *
- * Copied from linux/fs/ext4/crypto.c
- *
- * Copyright (C) 2015, Google, Inc.
- * Copyright (C) 2015, Motorola Mobility
- *
- * This contains encryption functions for f2fs
- *
- * Written by Michael Halcrow, 2014.
- *
- * Filename encryption additions
- * Uday Savagaonkar, 2014
- * Encryption policy handling additions
- * Ildar Muslukhov, 2014
- * Remove ext4_encrypted_zeroout(),
- *   add f2fs_restore_and_release_control_page()
- * Jaegeuk Kim, 2015.
- *
- * This has not yet undergone a rigorous security audit.
- *
- * The usage of AES-XTS should conform to recommendations in NIST
- * Special Publication 800-38E and IEEE P1619/D16.
- */
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "f2fs.h"
-#include "xattr.h"
-
-/* Encryption added and removed here! (L: */
-
-static unsigned int num_prealloc_crypto_pages = 32;
-static unsigned int num_prealloc_crypto_ctxs = 128;
-
-module_param(num_prealloc_crypto_pages, uint, 0444);
-MODULE_PARM_DESC(num_prealloc_crypto_pages,
-   "Number of crypto pages to preallocate");
-module_param(num_prealloc_crypto_ctxs, uint, 0444);
-MODULE_PARM_DESC(num_prealloc_crypto_ctxs,
-   "Number of crypto contexts to preallocate");
-
-static mempool_t *f2fs_bounce_page_pool;
-
-static LIST_HEAD(f2fs_free_crypto_ctxs);
-static DEFINE_SPINLOCK(f2fs_crypto_ctx_lock);
-
-static struct workqueue_struct *f2fs_read_workqueue;
-static DEFINE_MUTEX(crypto_init);
-
-static struct kmem_cache *f2fs_crypto_ctx_cachep;
-struct kmem_cache *f2fs_crypt_info_cachep;
-
-/**
- * f2fs_release_crypto_ctx() - Releases an encryption context
- * @ctx: The encryption context to release.
- *
- * If the encryption context was allocated from the pre-allocated pool, returns
- * it to that pool. Else, frees it.
- *
- * If there's a bounce page in the context, this frees that.
- */
-void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *ctx)
-{
-   unsigned long flags;
-
-   if (ctx->flags & F2FS_WRITE_PATH_FL && ctx->w.bounce_page) {
-   mempool_free(ctx->w.bounce_page, f2fs_bounce_page_pool);
-   ctx->w.bounce_page = NULL;
-   }
-   ctx->w.control_page = NULL;
-   if (ctx->flags & F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL) {
-   kmem_cache_free(f2fs_crypto_ctx_cachep, ctx);
-   } else {
-   spin_lock_irqsave(_crypto_ctx_lock, flags);
-   list_add(>free_list, 

[f2fs-dev] [PATCH 08/10] f2fs crypto: migrate into vfs's crypto engine

2016-02-25 Thread Jaegeuk Kim
This patch removes the most parts of internal crypto codes.
And then, it modifies some f2fs-specific crypt codes to use the generic
facility.

Signed-off-by: Jaegeuk Kim 
---
 fs/f2fs/Kconfig |  10 +-
 fs/f2fs/Makefile|   2 -
 fs/f2fs/crypto.c| 473 
 fs/f2fs/crypto_fname.c  | 446 -
 fs/f2fs/crypto_key.c| 267 ---
 fs/f2fs/crypto_policy.c | 210 -
 fs/f2fs/data.c  |  31 ++--
 fs/f2fs/dir.c   |  46 ++---
 fs/f2fs/f2fs.h  | 151 +---
 fs/f2fs/f2fs_crypto.h   | 151 
 fs/f2fs/file.c  |  36 ++--
 fs/f2fs/inline.c|   4 +-
 fs/f2fs/inode.c |   5 +-
 fs/f2fs/namei.c |  56 +++---
 fs/f2fs/super.c |  55 --
 15 files changed, 127 insertions(+), 1816 deletions(-)
 delete mode 100644 fs/f2fs/crypto.c
 delete mode 100644 fs/f2fs/crypto_fname.c
 delete mode 100644 fs/f2fs/crypto_key.c
 delete mode 100644 fs/f2fs/crypto_policy.c
 delete mode 100644 fs/f2fs/f2fs_crypto.h

diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig
index b0a9dc9..e7fbde6 100644
--- a/fs/f2fs/Kconfig
+++ b/fs/f2fs/Kconfig
@@ -76,15 +76,7 @@ config F2FS_FS_ENCRYPTION
bool "F2FS Encryption"
depends on F2FS_FS
depends on F2FS_FS_XATTR
-   select CRYPTO_AES
-   select CRYPTO_CBC
-   select CRYPTO_ECB
-   select CRYPTO_XTS
-   select CRYPTO_CTS
-   select CRYPTO_CTR
-   select CRYPTO_SHA256
-   select KEYS
-   select ENCRYPTED_KEYS
+   depends on FS_ENCRYPTION
help
  Enable encryption of f2fs files and directories.  This
  feature is similar to ecryptfs, but it is more memory
diff --git a/fs/f2fs/Makefile b/fs/f2fs/Makefile
index 08e101e..ca949ea 100644
--- a/fs/f2fs/Makefile
+++ b/fs/f2fs/Makefile
@@ -7,5 +7,3 @@ f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o
 f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o
 f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
 f2fs-$(CONFIG_F2FS_IO_TRACE) += trace.o
-f2fs-$(CONFIG_F2FS_FS_ENCRYPTION) += crypto_policy.o crypto.o \
-   crypto_key.o crypto_fname.o
diff --git a/fs/f2fs/crypto.c b/fs/f2fs/crypto.c
deleted file mode 100644
index 3ef3786..000
--- a/fs/f2fs/crypto.c
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- * linux/fs/f2fs/crypto.c
- *
- * Copied from linux/fs/ext4/crypto.c
- *
- * Copyright (C) 2015, Google, Inc.
- * Copyright (C) 2015, Motorola Mobility
- *
- * This contains encryption functions for f2fs
- *
- * Written by Michael Halcrow, 2014.
- *
- * Filename encryption additions
- * Uday Savagaonkar, 2014
- * Encryption policy handling additions
- * Ildar Muslukhov, 2014
- * Remove ext4_encrypted_zeroout(),
- *   add f2fs_restore_and_release_control_page()
- * Jaegeuk Kim, 2015.
- *
- * This has not yet undergone a rigorous security audit.
- *
- * The usage of AES-XTS should conform to recommendations in NIST
- * Special Publication 800-38E and IEEE P1619/D16.
- */
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "f2fs.h"
-#include "xattr.h"
-
-/* Encryption added and removed here! (L: */
-
-static unsigned int num_prealloc_crypto_pages = 32;
-static unsigned int num_prealloc_crypto_ctxs = 128;
-
-module_param(num_prealloc_crypto_pages, uint, 0444);
-MODULE_PARM_DESC(num_prealloc_crypto_pages,
-   "Number of crypto pages to preallocate");
-module_param(num_prealloc_crypto_ctxs, uint, 0444);
-MODULE_PARM_DESC(num_prealloc_crypto_ctxs,
-   "Number of crypto contexts to preallocate");
-
-static mempool_t *f2fs_bounce_page_pool;
-
-static LIST_HEAD(f2fs_free_crypto_ctxs);
-static DEFINE_SPINLOCK(f2fs_crypto_ctx_lock);
-
-static struct workqueue_struct *f2fs_read_workqueue;
-static DEFINE_MUTEX(crypto_init);
-
-static struct kmem_cache *f2fs_crypto_ctx_cachep;
-struct kmem_cache *f2fs_crypt_info_cachep;
-
-/**
- * f2fs_release_crypto_ctx() - Releases an encryption context
- * @ctx: The encryption context to release.
- *
- * If the encryption context was allocated from the pre-allocated pool, returns
- * it to that pool. Else, frees it.
- *
- * If there's a bounce page in the context, this frees that.
- */
-void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *ctx)
-{
-   unsigned long flags;
-
-   if (ctx->flags & F2FS_WRITE_PATH_FL && ctx->w.bounce_page) {
-   mempool_free(ctx->w.bounce_page, f2fs_bounce_page_pool);
-   ctx->w.bounce_page = NULL;
-   }
-   ctx->w.control_page = NULL;
-   if (ctx->flags & F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL) {
-   kmem_cache_free(f2fs_crypto_ctx_cachep, ctx);
-   } else {
-   spin_lock_irqsave(_crypto_ctx_lock, flags);
-   list_add(>free_list,