* [PATCH 01/12] staging: lustre: libcfs: limit scope of libcfs_crypto.h
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 02/12] staging: lustre: libcfs: add documentation for cfs_crypto_hash_*() James Simmons
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Remove <libcfs/libcfs_crypto.h> from <libcfs/libcfs.h> and only
include it into the places where it is actually needed. This
works out to be the same places as <obd_cksum.h>, so put it there.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../staging/lustre/include/linux/libcfs/libcfs.h | 1 -
.../lustre/lnet/libcfs/linux/linux-crypto.c | 1 +
drivers/staging/lustre/lustre/include/obd_cksum.h | 1 +
3 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 6a8e0d0..d2e4361 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -96,7 +96,6 @@ void cfs_get_random_bytes(void *buf, int size);
#include "libcfs_workitem.h"
#include "libcfs_hash.h"
#include "libcfs_fail.h"
-#include "libcfs_crypto.h"
struct libcfs_ioctl_handler {
struct list_head item;
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 8c9377e..d4cb260 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -30,6 +30,7 @@
#include <crypto/hash.h>
#include <linux/scatterlist.h>
#include "../../../include/linux/libcfs/libcfs.h"
+#include "../../../include/linux/libcfs/libcfs_crypto.h"
#include "linux-crypto.h"
/**
* Array of hash algorithm speed in MByte per second
diff --git a/drivers/staging/lustre/lustre/include/obd_cksum.h b/drivers/staging/lustre/lustre/include/obd_cksum.h
index 637fa22..f6c18df 100644
--- a/drivers/staging/lustre/lustre/include/obd_cksum.h
+++ b/drivers/staging/lustre/lustre/include/obd_cksum.h
@@ -35,6 +35,7 @@
#ifndef __OBD_CKSUM
#define __OBD_CKSUM
#include "../../include/linux/libcfs/libcfs.h"
+#include "../../include/linux/libcfs/libcfs_crypto.h"
#include "lustre/lustre_idl.h"
static inline unsigned char cksum_obd2cfs(enum cksum_type cksum_type)
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 02/12] staging: lustre: libcfs: add documentation for cfs_crypto_hash_*()
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
2016-03-26 19:40 ` [PATCH 01/12] staging: lustre: libcfs: limit scope of libcfs_crypto.h James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 03/12] staging: lustre: libcfs: rename some variables for crypto handling James Simmons
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Add comment blocks for cfs_crypto_hash_*() in linux-crypto.c and
libcfs_crypto.h. Delete obsolete comment about shash handling in
cfs_crypto_hash_alloc().
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/include/linux/libcfs/libcfs_crypto.h | 101 ++++---------
.../lustre/lnet/libcfs/linux/linux-crypto.c | 153 ++++++++++++++++++--
2 files changed, 174 insertions(+), 80 deletions(-)
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
index e866369..5182416 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
@@ -61,7 +61,14 @@ static struct cfs_crypto_hash_type hash_types[] = {
[CFS_HASH_ALG_SHA512] = { "sha512", 0, 64 },
};
-/** Return pointer to type of hash for valid hash algorithm identifier */
+/**
+ * Return hash algorithm information for the specified algorithm identifier
+ *
+ * Hash information includes algorithm name, initial seed, hash size.
+ *
+ * \retval cfs_crypto_hash_type for valid ID (CFS_HASH_ALG_*)
+ * \retval NULL for unknown algorithm identifier
+ */
static inline const struct cfs_crypto_hash_type *
cfs_crypto_hash_type(unsigned char hash_alg)
{
@@ -75,7 +82,14 @@ static inline const struct cfs_crypto_hash_type *
return NULL;
}
-/** Return hash name for valid hash algorithm identifier or "unknown" */
+/**
+ * Return hash name for hash algorithm identifier
+ *
+ * \param[in] hash_alg hash alrgorithm id (CFS_HASH_ALG_*)
+ *
+ * \retval string name of known hash algorithm
+ * \retval "unknown" if hash algorithm is unknown
+ */
static inline const char *cfs_crypto_hash_name(unsigned char hash_alg)
{
const struct cfs_crypto_hash_type *ht;
@@ -86,7 +100,14 @@ static inline const char *cfs_crypto_hash_name(unsigned char hash_alg)
return "unknown";
}
-/** Return digest size for valid algorithm identifier or 0 */
+/**
+ * Return digest size for hash algorithm type
+ *
+ * \param[in] hash_alg hash alrgorithm id (CFS_HASH_ALG_*)
+ *
+ * \retval hash algorithm digest size in bytes
+ * \retval 0 if hash algorithm type is unknown
+ */
static inline int cfs_crypto_hash_digestsize(unsigned char hash_alg)
{
const struct cfs_crypto_hash_type *ht;
@@ -97,7 +118,12 @@ static inline int cfs_crypto_hash_digestsize(unsigned char hash_alg)
return 0;
}
-/** Return hash identifier for valid hash algorithm name or 0xFF */
+/**
+ * Find hash algorithm ID for the specified algorithm name
+ *
+ * \retval hash algorithm ID for valid ID (CFS_HASH_ALG_*)
+ * \retval CFS_HASH_ALG_UNKNOWN for unknown algorithm name
+ */
static inline unsigned char cfs_crypto_hash_alg(const char *algname)
{
unsigned char i;
@@ -108,24 +134,6 @@ static inline unsigned char cfs_crypto_hash_alg(const char *algname)
return (i == CFS_HASH_ALG_MAX ? 0xFF : i);
}
-/** Calculate hash digest for buffer.
- * @param alg id of hash algorithm
- * @param buf buffer of data
- * @param buf_len buffer len
- * @param key initial value for algorithm, if it is NULL,
- * default initial value should be used.
- * @param key_len len of initial value
- * @param hash [out] pointer to hash, if it is NULL, hash_len is
- * set to valid digest size in bytes, retval -ENOSPC.
- * @param hash_len [in,out] size of hash buffer
- * @returns status of operation
- * @retval -EINVAL if buf, buf_len, hash_len or alg_id is invalid
- * @retval -ENODEV if this algorithm is unsupported
- * @retval -ENOSPC if pointer to hash is NULL, or hash_len less than
- * digest size
- * @retval 0 for success
- * @retval < 0 other errors from lower layers.
- */
int cfs_crypto_hash_digest(unsigned char alg,
const void *buf, unsigned int buf_len,
unsigned char *key, unsigned int key_len,
@@ -134,66 +142,17 @@ int cfs_crypto_hash_digest(unsigned char alg,
/* cfs crypto hash descriptor */
struct cfs_crypto_hash_desc;
-/** Allocate and initialize descriptor for hash algorithm.
- * @param alg algorithm id
- * @param key initial value for algorithm, if it is NULL,
- * default initial value should be used.
- * @param key_len len of initial value
- * @returns pointer to descriptor of hash instance
- * @retval ERR_PTR(error) when errors occurred.
- */
struct cfs_crypto_hash_desc*
cfs_crypto_hash_init(unsigned char alg,
unsigned char *key, unsigned int key_len);
-
-/** Update digest by part of data.
- * @param desc hash descriptor
- * @param page data page
- * @param offset data offset
- * @param len data len
- * @returns status of operation
- * @retval 0 for success.
- */
int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *desc,
struct page *page, unsigned int offset,
unsigned int len);
-
-/** Update digest by part of data.
- * @param desc hash descriptor
- * @param buf pointer to data buffer
- * @param buf_len size of data at buffer
- * @returns status of operation
- * @retval 0 for success.
- */
int cfs_crypto_hash_update(struct cfs_crypto_hash_desc *desc, const void *buf,
unsigned int buf_len);
-
-/** Finalize hash calculation, copy hash digest to buffer, destroy hash
- * descriptor.
- * @param desc hash descriptor
- * @param hash buffer pointer to store hash digest
- * @param hash_len pointer to hash buffer size, if NULL
- * destroy hash descriptor
- * @returns status of operation
- * @retval -ENOSPC if hash is NULL, or *hash_len less than
- * digest size
- * @retval 0 for success
- * @retval < 0 other errors from lower layers.
- */
int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *desc,
unsigned char *hash, unsigned int *hash_len);
-/**
- * Register crypto hash algorithms
- */
int cfs_crypto_register(void);
-
-/**
- * Unregister
- */
void cfs_crypto_unregister(void);
-
-/** Return hash speed in Mbytes per second for valid hash algorithm
- * identifier. If test was unsuccessful -1 would be returned.
- */
int cfs_crypto_hash_speed(unsigned char hash_alg);
#endif
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index d4cb260..8960c3a 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -32,11 +32,31 @@
#include "../../../include/linux/libcfs/libcfs.h"
#include "../../../include/linux/libcfs/libcfs_crypto.h"
#include "linux-crypto.h"
+
/**
- * Array of hash algorithm speed in MByte per second
+ * Array of hash algorithm speed in MByte per second
*/
static int cfs_crypto_hash_speeds[CFS_HASH_ALG_MAX];
+/**
+ * Initialize the state descriptor for the specified hash algorithm.
+ *
+ * An internal routine to allocate the hash-specific state in \a hdesc for
+ * use with cfs_crypto_hash_digest() to compute the hash of a single message,
+ * though possibly in multiple chunks. The descriptor internal state should
+ * be freed with cfs_crypto_hash_final().
+ *
+ * \param[in] hash_alg hash algorithm id (CFS_HASH_ALG_*)
+ * \param[out] type pointer to the hash description in hash_types[]
+ * array
+ * \param[in,out] hdesc hash state descriptor to be initialized
+ * \param[in] key initial hash value/state, NULL to use default
+ * value
+ * \param[in] key_len length of \a key
+ *
+ * \retval 0 on success
+ * \retval negative errno on failure
+ */
static int cfs_crypto_hash_alloc(unsigned char alg_id,
const struct cfs_crypto_hash_type **type,
struct ahash_request **req,
@@ -71,12 +91,6 @@ static int cfs_crypto_hash_alloc(unsigned char alg_id,
ahash_request_set_callback(*req, 0, NULL, NULL);
- /** Shash have different logic for initialization then digest
- * shash: crypto_hash_setkey, crypto_hash_init
- * digest: crypto_digest_init, crypto_digest_setkey
- * Skip this function for digest, because we use shash logic at
- * cfs_crypto_hash_alloc.
- */
if (key)
err = crypto_ahash_setkey(tfm, key, key_len);
else if ((*type)->cht_key != 0)
@@ -101,6 +115,32 @@ static int cfs_crypto_hash_alloc(unsigned char alg_id,
return err;
}
+/**
+ * Calculate hash digest for the passed buffer.
+ *
+ * This should be used when computing the hash on a single contiguous buffer.
+ * It combines the hash initialization, computation, and cleanup.
+ *
+ * \param[in] hash_alg id of hash algorithm (CFS_HASH_ALG_*)
+ * \param[in] buf data buffer on which to compute hash
+ * \param[in] buf_len length of \a buf in bytes
+ * \param[in] key initial value/state for algorithm,
+ * if \a key = NULL use default initial value
+ * \param[in] key_len length of \a key in bytes
+ * \param[out] hash pointer to computed hash value,
+ * if \a hash = NULL then \a hash_len is to digest
+ * size in bytes, retval -ENOSPC
+ * \param[in,out] hash_len size of \a hash buffer
+ *
+ * \retval -EINVAL \a buf, \a buf_len, \a hash_len,
+ * \a alg_id invalid
+ * \retval -ENOENT \a hash_alg is unsupported
+ * \retval -ENOSPC \a hash is NULL, or \a hash_len less than
+ * digest size
+ * \retval 0 for success
+ * \retval negative errno for other errors from lower
+ * layers.
+ */
int cfs_crypto_hash_digest(unsigned char alg_id,
const void *buf, unsigned int buf_len,
unsigned char *key, unsigned int key_len,
@@ -135,6 +175,23 @@ int cfs_crypto_hash_digest(unsigned char alg_id,
}
EXPORT_SYMBOL(cfs_crypto_hash_digest);
+/**
+ * Allocate and initialize desriptor for hash algorithm.
+ *
+ * This should be used to initialize a hash descriptor for multiple calls
+ * to a single hash function when computing the hash across multiple
+ * separate buffers or pages using cfs_crypto_hash_update{,_page}().
+ *
+ * The hash descriptor should be freed with cfs_crypto_hash_final().
+ *
+ * \param[in] hash_alg algorithm id (CFS_HASH_ALG_*)
+ * \param[in] key initial value/state for algorithm, if \a key = NULL
+ * use default initial value
+ * \param[in] key_len length of \a key in bytes
+ *
+ * \retval pointer to descriptor of hash instance
+ * \retval ERR_PTR(errno) in case of error
+ */
struct cfs_crypto_hash_desc *
cfs_crypto_hash_init(unsigned char alg_id,
unsigned char *key, unsigned int key_len)
@@ -151,6 +208,17 @@ struct cfs_crypto_hash_desc *
}
EXPORT_SYMBOL(cfs_crypto_hash_init);
+/**
+ * Update hash digest computed on data within the given \a page
+ *
+ * \param[in] hdesc hash state descriptor
+ * \param[in] page data page on which to compute the hash
+ * \param[in] offset offset within \a page at which to start hash
+ * \param[in] len length of data on which to compute hash
+ *
+ * \retval 0 for success
+ * \retval negative errno on failure
+ */
int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *hdesc,
struct page *page, unsigned int offset,
unsigned int len)
@@ -166,6 +234,16 @@ int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *hdesc,
}
EXPORT_SYMBOL(cfs_crypto_hash_update_page);
+/**
+ * Update hash digest computed on the specified data
+ *
+ * \param[in] hdesc hash state descriptor
+ * \param[in] buf data buffer on which to compute the hash
+ * \param[in] buf_len length of \buf on which to compute hash
+ *
+ * \retval 0 for success
+ * \retval negative errno on failure
+ */
int cfs_crypto_hash_update(struct cfs_crypto_hash_desc *hdesc,
const void *buf, unsigned int buf_len)
{
@@ -179,7 +257,18 @@ int cfs_crypto_hash_update(struct cfs_crypto_hash_desc *hdesc,
}
EXPORT_SYMBOL(cfs_crypto_hash_update);
-/* If hash_len pointer is NULL - destroy descriptor. */
+/**
+ * Finish hash calculation, copy hash digest to buffer, clean up hash descriptor
+ *
+ * \param[in] hdesc hash descriptor
+ * \param[out] hash pointer to hash buffer to store hash digest
+ * \param[in,out] hash_len pointer to hash buffer size, if \a hdesc = NULL
+ * only free \a hdesc instead of computing the hash
+ *
+ * \retval -ENOSPC if \a hash = NULL, or \a hash_len < digest size
+ * \retval 0 for success
+ * \retval negative errno for other errors from lower layers
+ */
int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *hdesc,
unsigned char *hash, unsigned int *hash_len)
{
@@ -209,6 +298,17 @@ int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *hdesc,
}
EXPORT_SYMBOL(cfs_crypto_hash_final);
+/**
+ * Compute the speed of specified hash function
+ *
+ * Run a speed test on the given hash algorithm on buffer of the given size.
+ * The speed is stored internally in the cfs_crypto_hash_speeds[] array, and
+ * is available through the cfs_crypto_hash_speed() function.
+ *
+ * \param[in] hash_alg hash algorithm id (CFS_HASH_ALG_*)
+ * \param[in] buf data buffer on which to compute the hash
+ * \param[in] buf_len length of \buf on which to compute hash
+ */
static void cfs_crypto_performance_test(unsigned char alg_id,
const unsigned char *buf,
unsigned int buf_len)
@@ -243,6 +343,18 @@ static void cfs_crypto_performance_test(unsigned char alg_id,
cfs_crypto_hash_name(alg_id), cfs_crypto_hash_speeds[alg_id]);
}
+/**
+ * hash speed in Mbytes per second for valid hash algorithm
+ *
+ * Return the performance of the specified \a hash_alg that was previously
+ * computed using cfs_crypto_performance_test().
+ *
+ * \param[in] hash_alg hash algorithm id (CFS_HASH_ALG_*)
+ *
+ * \retval positive speed of the hash function in MB/s
+ * \retval -ENOENT if \a hash_alg is unsupported
+ * \retval negative errno if \a hash_alg speed is unavailable
+ */
int cfs_crypto_hash_speed(unsigned char hash_alg)
{
if (hash_alg < CFS_HASH_ALG_MAX)
@@ -252,7 +364,22 @@ int cfs_crypto_hash_speed(unsigned char hash_alg)
EXPORT_SYMBOL(cfs_crypto_hash_speed);
/**
- * Do performance test for all hash algorithms.
+ * Run the performance test for all hash algorithms.
+ *
+ * Run the cfs_crypto_performance_test() benchmark for all of the available
+ * hash functions using a 1MB buffer size. This is a reasonable buffer size
+ * for Lustre RPCs, even if the actual RPC size is larger or smaller.
+ *
+ * Since the setup cost and computation speed of various hash algorithms is
+ * a function of the buffer size (and possibly internal contention of offload
+ * engines), this speed only represents an estimate of the actual speed under
+ * actual usage, but is reasonable for comparing available algorithms.
+ *
+ * The actual speeds are available via cfs_crypto_hash_speed() for later
+ * comparison.
+ *
+ * \retval 0 on success
+ * \retval -ENOMEM if no memory is available for test buffer
*/
static int cfs_crypto_test_hashes(void)
{
@@ -280,6 +407,11 @@ static int cfs_crypto_test_hashes(void)
static int adler32;
+/**
+ * Register available hash functions
+ *
+ * \retval 0
+ */
int cfs_crypto_register(void)
{
request_module("crc32c");
@@ -291,6 +423,9 @@ int cfs_crypto_register(void)
return 0;
}
+/**
+ * Unregister previously registered hash functions
+ */
void cfs_crypto_unregister(void)
{
if (adler32 == 0)
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 03/12] staging: lustre: libcfs: rename some variables for crypto handling
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
2016-03-26 19:40 ` [PATCH 01/12] staging: lustre: libcfs: limit scope of libcfs_crypto.h James Simmons
2016-03-26 19:40 ` [PATCH 02/12] staging: lustre: libcfs: add documentation for cfs_crypto_hash_*() James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 04/12] staging: lustre: libcfs: add new definitions for cfs_crypto api James Simmons
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
For the crypto algorthim type use the same name hash_alg everywhere.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/include/linux/libcfs/libcfs_crypto.h | 4 +-
.../lustre/lnet/libcfs/linux/linux-crypto.c | 30 ++++++++++----------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
index 5182416..0782bfb 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
@@ -134,7 +134,7 @@ static inline unsigned char cfs_crypto_hash_alg(const char *algname)
return (i == CFS_HASH_ALG_MAX ? 0xFF : i);
}
-int cfs_crypto_hash_digest(unsigned char alg,
+int cfs_crypto_hash_digest(unsigned char hash_alg,
const void *buf, unsigned int buf_len,
unsigned char *key, unsigned int key_len,
unsigned char *hash, unsigned int *hash_len);
@@ -143,7 +143,7 @@ int cfs_crypto_hash_digest(unsigned char alg,
struct cfs_crypto_hash_desc;
struct cfs_crypto_hash_desc*
- cfs_crypto_hash_init(unsigned char alg,
+ cfs_crypto_hash_init(unsigned char hash_alg,
unsigned char *key, unsigned int key_len);
int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *desc,
struct page *page, unsigned int offset,
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 8960c3a..1a9eb77 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -57,7 +57,7 @@ static int cfs_crypto_hash_speeds[CFS_HASH_ALG_MAX];
* \retval 0 on success
* \retval negative errno on failure
*/
-static int cfs_crypto_hash_alloc(unsigned char alg_id,
+static int cfs_crypto_hash_alloc(unsigned char hash_alg,
const struct cfs_crypto_hash_type **type,
struct ahash_request **req,
unsigned char *key,
@@ -66,11 +66,11 @@ static int cfs_crypto_hash_alloc(unsigned char alg_id,
struct crypto_ahash *tfm;
int err = 0;
- *type = cfs_crypto_hash_type(alg_id);
+ *type = cfs_crypto_hash_type(hash_alg);
if (!*type) {
CWARN("Unsupported hash algorithm id = %d, max id is %d\n",
- alg_id, CFS_HASH_ALG_MAX);
+ hash_alg, CFS_HASH_ALG_MAX);
return -EINVAL;
}
tfm = crypto_alloc_ahash((*type)->cht_name, 0, CRYPTO_ALG_ASYNC);
@@ -105,7 +105,7 @@ static int cfs_crypto_hash_alloc(unsigned char alg_id,
CDEBUG(D_INFO, "Using crypto hash: %s (%s) speed %d MB/s\n",
crypto_ahash_alg_name(tfm), crypto_ahash_driver_name(tfm),
- cfs_crypto_hash_speeds[alg_id]);
+ cfs_crypto_hash_speeds[hash_alg]);
err = crypto_ahash_init(*req);
if (err) {
@@ -133,7 +133,7 @@ static int cfs_crypto_hash_alloc(unsigned char alg_id,
* \param[in,out] hash_len size of \a hash buffer
*
* \retval -EINVAL \a buf, \a buf_len, \a hash_len,
- * \a alg_id invalid
+ * \a hash_alg invalid
* \retval -ENOENT \a hash_alg is unsupported
* \retval -ENOSPC \a hash is NULL, or \a hash_len less than
* digest size
@@ -141,7 +141,7 @@ static int cfs_crypto_hash_alloc(unsigned char alg_id,
* \retval negative errno for other errors from lower
* layers.
*/
-int cfs_crypto_hash_digest(unsigned char alg_id,
+int cfs_crypto_hash_digest(unsigned char hash_alg,
const void *buf, unsigned int buf_len,
unsigned char *key, unsigned int key_len,
unsigned char *hash, unsigned int *hash_len)
@@ -154,7 +154,7 @@ int cfs_crypto_hash_digest(unsigned char alg_id,
if (!buf || buf_len == 0 || !hash_len)
return -EINVAL;
- err = cfs_crypto_hash_alloc(alg_id, &type, &req, key, key_len);
+ err = cfs_crypto_hash_alloc(hash_alg, &type, &req, key, key_len);
if (err != 0)
return err;
@@ -193,14 +193,14 @@ EXPORT_SYMBOL(cfs_crypto_hash_digest);
* \retval ERR_PTR(errno) in case of error
*/
struct cfs_crypto_hash_desc *
- cfs_crypto_hash_init(unsigned char alg_id,
+ cfs_crypto_hash_init(unsigned char hash_alg,
unsigned char *key, unsigned int key_len)
{
struct ahash_request *req;
int err;
const struct cfs_crypto_hash_type *type;
- err = cfs_crypto_hash_alloc(alg_id, &type, &req, key, key_len);
+ err = cfs_crypto_hash_alloc(hash_alg, &type, &req, key, key_len);
if (err)
return ERR_PTR(err);
@@ -309,7 +309,7 @@ EXPORT_SYMBOL(cfs_crypto_hash_final);
* \param[in] buf data buffer on which to compute the hash
* \param[in] buf_len length of \buf on which to compute hash
*/
-static void cfs_crypto_performance_test(unsigned char alg_id,
+static void cfs_crypto_performance_test(unsigned char hash_alg,
const unsigned char *buf,
unsigned int buf_len)
{
@@ -321,7 +321,7 @@ static void cfs_crypto_performance_test(unsigned char alg_id,
for (start = jiffies, end = start + sec * HZ, bcount = 0;
time_before(jiffies, end); bcount++) {
- err = cfs_crypto_hash_digest(alg_id, buf, buf_len, NULL, 0,
+ err = cfs_crypto_hash_digest(hash_alg, buf, buf_len, NULL, 0,
hash, &hash_len);
if (err)
break;
@@ -329,18 +329,18 @@ static void cfs_crypto_performance_test(unsigned char alg_id,
end = jiffies;
if (err) {
- cfs_crypto_hash_speeds[alg_id] = -1;
+ cfs_crypto_hash_speeds[hash_alg] = -1;
CDEBUG(D_INFO, "Crypto hash algorithm %s, err = %d\n",
- cfs_crypto_hash_name(alg_id), err);
+ cfs_crypto_hash_name(hash_alg), err);
} else {
unsigned long tmp;
tmp = ((bcount * buf_len / jiffies_to_msecs(end - start)) *
1000) / (1024 * 1024);
- cfs_crypto_hash_speeds[alg_id] = (int)tmp;
+ cfs_crypto_hash_speeds[hash_alg] = (int)tmp;
}
CDEBUG(D_INFO, "Crypto hash algorithm %s speed = %d MB/s\n",
- cfs_crypto_hash_name(alg_id), cfs_crypto_hash_speeds[alg_id]);
+ cfs_crypto_hash_name(hash_alg), cfs_crypto_hash_speeds[hash_alg]);
}
/**
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 04/12] staging: lustre: libcfs: add new definitions for cfs_crypto api
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (2 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 03/12] staging: lustre: libcfs: rename some variables for crypto handling James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 05/12] staging: lustre: libcfs: small alignment change for cfs_crypto_hash_*() James Simmons
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Add CFS_HASH_ALG_UNKOWN for unknown hash names instead of
using "0xFF" directly. Define the max digestsize the cfs
crypto api can handle.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/include/linux/libcfs/libcfs_crypto.h | 9 +++++++--
.../lustre/lnet/libcfs/linux/linux-crypto.c | 4 ++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
index 0782bfb..921aa7c 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
@@ -46,7 +46,8 @@ enum cfs_crypto_hash_alg {
CFS_HASH_ALG_SHA384,
CFS_HASH_ALG_SHA512,
CFS_HASH_ALG_CRC32C,
- CFS_HASH_ALG_MAX
+ CFS_HASH_ALG_MAX,
+ CFS_HASH_ALG_UNKNOWN = 0xff
};
static struct cfs_crypto_hash_type hash_types[] = {
@@ -59,8 +60,12 @@ static struct cfs_crypto_hash_type hash_types[] = {
[CFS_HASH_ALG_SHA256] = { "sha256", 0, 32 },
[CFS_HASH_ALG_SHA384] = { "sha384", 0, 48 },
[CFS_HASH_ALG_SHA512] = { "sha512", 0, 64 },
+ [CFS_HASH_ALG_MAX] = { NULL, 0, 64 },
};
+/* Maximum size of hash_types[].cht_size */
+#define CFS_CRYPTO_HASH_DIGESTSIZE_MAX 64
+
/**
* Return hash algorithm information for the specified algorithm identifier
*
@@ -131,7 +136,7 @@ static inline unsigned char cfs_crypto_hash_alg(const char *algname)
for (i = 0; i < CFS_HASH_ALG_MAX; i++)
if (!strcmp(hash_types[i].cht_name, algname))
break;
- return (i == CFS_HASH_ALG_MAX ? 0xFF : i);
+ return (i == CFS_HASH_ALG_MAX ? CFS_HASH_ALG_UNKNOWN : i);
}
int cfs_crypto_hash_digest(unsigned char hash_alg,
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 1a9eb77..b4e203d 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -316,8 +316,8 @@ static void cfs_crypto_performance_test(unsigned char hash_alg,
unsigned long start, end;
int bcount, err = 0;
int sec = 1; /* do test only 1 sec */
- unsigned char hash[64];
- unsigned int hash_len = 64;
+ unsigned char hash[CFS_CRYPTO_HASH_DIGESTSIZE_MAX];
+ unsigned int hash_len = sizeof(hash);
for (start = jiffies, end = start + sec * HZ, bcount = 0;
time_before(jiffies, end); bcount++) {
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 05/12] staging: lustre: libcfs: small alignment change for cfs_crypto_hash_*()
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (3 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 04/12] staging: lustre: libcfs: add new definitions for cfs_crypto api James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 06/12] staging: lustre: libcfs: start using enum cfs_crypto_hash_alg James Simmons
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Change the aligment of some of the functions.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/include/linux/libcfs/libcfs_crypto.h | 11 ++++++-----
.../lustre/lnet/libcfs/linux/linux-crypto.c | 4 ++--
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
index 921aa7c..ade8894 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
@@ -75,7 +75,7 @@ static struct cfs_crypto_hash_type hash_types[] = {
* \retval NULL for unknown algorithm identifier
*/
static inline const struct cfs_crypto_hash_type *
- cfs_crypto_hash_type(unsigned char hash_alg)
+cfs_crypto_hash_type(unsigned char hash_alg)
{
struct cfs_crypto_hash_type *ht;
@@ -95,7 +95,8 @@ static inline const struct cfs_crypto_hash_type *
* \retval string name of known hash algorithm
* \retval "unknown" if hash algorithm is unknown
*/
-static inline const char *cfs_crypto_hash_name(unsigned char hash_alg)
+static inline const char *
+cfs_crypto_hash_name(unsigned char hash_alg)
{
const struct cfs_crypto_hash_type *ht;
@@ -147,9 +148,9 @@ int cfs_crypto_hash_digest(unsigned char hash_alg,
/* cfs crypto hash descriptor */
struct cfs_crypto_hash_desc;
-struct cfs_crypto_hash_desc*
- cfs_crypto_hash_init(unsigned char hash_alg,
- unsigned char *key, unsigned int key_len);
+struct cfs_crypto_hash_desc *
+cfs_crypto_hash_init(unsigned char hash_alg,
+ unsigned char *key, unsigned int key_len);
int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *desc,
struct page *page, unsigned int offset,
unsigned int len);
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index b4e203d..0241729 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -193,8 +193,8 @@ EXPORT_SYMBOL(cfs_crypto_hash_digest);
* \retval ERR_PTR(errno) in case of error
*/
struct cfs_crypto_hash_desc *
- cfs_crypto_hash_init(unsigned char hash_alg,
- unsigned char *key, unsigned int key_len)
+cfs_crypto_hash_init(unsigned char hash_alg,
+ unsigned char *key, unsigned int key_len)
{
struct ahash_request *req;
int err;
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 06/12] staging: lustre: libcfs: start using enum cfs_crypto_hash_alg
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (4 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 05/12] staging: lustre: libcfs: small alignment change for cfs_crypto_hash_*() James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 07/12] staging: lustre: libcfs: bug fixes for cfs_crypto_hash_final() James Simmons
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Fix the cfs_crypto_hash_* functions to take enum cfs_crypto_hash_alg
as the algorithm type, instead of an unsigned char.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/include/linux/libcfs/libcfs_crypto.h | 23 ++++++++++---------
.../lustre/lnet/libcfs/linux/linux-crypto.c | 10 ++++----
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
index ade8894..02be7d7 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
@@ -75,7 +75,7 @@ static struct cfs_crypto_hash_type hash_types[] = {
* \retval NULL for unknown algorithm identifier
*/
static inline const struct cfs_crypto_hash_type *
-cfs_crypto_hash_type(unsigned char hash_alg)
+cfs_crypto_hash_type(enum cfs_crypto_hash_alg hash_alg)
{
struct cfs_crypto_hash_type *ht;
@@ -96,7 +96,7 @@ cfs_crypto_hash_type(unsigned char hash_alg)
* \retval "unknown" if hash algorithm is unknown
*/
static inline const char *
-cfs_crypto_hash_name(unsigned char hash_alg)
+cfs_crypto_hash_name(enum cfs_crypto_hash_alg hash_alg)
{
const struct cfs_crypto_hash_type *ht;
@@ -114,7 +114,7 @@ cfs_crypto_hash_name(unsigned char hash_alg)
* \retval hash algorithm digest size in bytes
* \retval 0 if hash algorithm type is unknown
*/
-static inline int cfs_crypto_hash_digestsize(unsigned char hash_alg)
+static inline int cfs_crypto_hash_digestsize(enum cfs_crypto_hash_alg hash_alg)
{
const struct cfs_crypto_hash_type *ht;
@@ -132,15 +132,16 @@ static inline int cfs_crypto_hash_digestsize(unsigned char hash_alg)
*/
static inline unsigned char cfs_crypto_hash_alg(const char *algname)
{
- unsigned char i;
+ enum cfs_crypto_hash_alg hash_alg;
- for (i = 0; i < CFS_HASH_ALG_MAX; i++)
- if (!strcmp(hash_types[i].cht_name, algname))
- break;
- return (i == CFS_HASH_ALG_MAX ? CFS_HASH_ALG_UNKNOWN : i);
+ for (hash_alg = 0; hash_alg < CFS_HASH_ALG_MAX; hash_alg++)
+ if (strcmp(hash_types[hash_alg].cht_name, algname) == 0)
+ return hash_alg;
+
+ return CFS_HASH_ALG_UNKNOWN;
}
-int cfs_crypto_hash_digest(unsigned char hash_alg,
+int cfs_crypto_hash_digest(enum cfs_crypto_hash_alg hash_alg,
const void *buf, unsigned int buf_len,
unsigned char *key, unsigned int key_len,
unsigned char *hash, unsigned int *hash_len);
@@ -149,7 +150,7 @@ int cfs_crypto_hash_digest(unsigned char hash_alg,
struct cfs_crypto_hash_desc;
struct cfs_crypto_hash_desc *
-cfs_crypto_hash_init(unsigned char hash_alg,
+cfs_crypto_hash_init(enum cfs_crypto_hash_alg hash_alg,
unsigned char *key, unsigned int key_len);
int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *desc,
struct page *page, unsigned int offset,
@@ -160,5 +161,5 @@ int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *desc,
unsigned char *hash, unsigned int *hash_len);
int cfs_crypto_register(void);
void cfs_crypto_unregister(void);
-int cfs_crypto_hash_speed(unsigned char hash_alg);
+int cfs_crypto_hash_speed(enum cfs_crypto_hash_alg hash_alg);
#endif
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 0241729..6fe1fdd 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -57,7 +57,7 @@ static int cfs_crypto_hash_speeds[CFS_HASH_ALG_MAX];
* \retval 0 on success
* \retval negative errno on failure
*/
-static int cfs_crypto_hash_alloc(unsigned char hash_alg,
+static int cfs_crypto_hash_alloc(enum cfs_crypto_hash_alg hash_alg,
const struct cfs_crypto_hash_type **type,
struct ahash_request **req,
unsigned char *key,
@@ -141,7 +141,7 @@ static int cfs_crypto_hash_alloc(unsigned char hash_alg,
* \retval negative errno for other errors from lower
* layers.
*/
-int cfs_crypto_hash_digest(unsigned char hash_alg,
+int cfs_crypto_hash_digest(enum cfs_crypto_hash_alg hash_alg,
const void *buf, unsigned int buf_len,
unsigned char *key, unsigned int key_len,
unsigned char *hash, unsigned int *hash_len)
@@ -193,7 +193,7 @@ EXPORT_SYMBOL(cfs_crypto_hash_digest);
* \retval ERR_PTR(errno) in case of error
*/
struct cfs_crypto_hash_desc *
-cfs_crypto_hash_init(unsigned char hash_alg,
+cfs_crypto_hash_init(enum cfs_crypto_hash_alg hash_alg,
unsigned char *key, unsigned int key_len)
{
struct ahash_request *req;
@@ -309,7 +309,7 @@ EXPORT_SYMBOL(cfs_crypto_hash_final);
* \param[in] buf data buffer on which to compute the hash
* \param[in] buf_len length of \buf on which to compute hash
*/
-static void cfs_crypto_performance_test(unsigned char hash_alg,
+static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg,
const unsigned char *buf,
unsigned int buf_len)
{
@@ -355,7 +355,7 @@ static void cfs_crypto_performance_test(unsigned char hash_alg,
* \retval -ENOENT if \a hash_alg is unsupported
* \retval negative errno if \a hash_alg speed is unavailable
*/
-int cfs_crypto_hash_speed(unsigned char hash_alg)
+int cfs_crypto_hash_speed(enum cfs_crypto_hash_alg hash_alg)
{
if (hash_alg < CFS_HASH_ALG_MAX)
return cfs_crypto_hash_speeds[hash_alg];
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 07/12] staging: lustre: libcfs: bug fixes for cfs_crypto_hash_final()
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (5 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 06/12] staging: lustre: libcfs: start using enum cfs_crypto_hash_alg James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 08/12] staging: lustre: libcfs: return proper error code for cfs_crypto_hash_speed() James Simmons
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Change cfs_crypto_hash_final() to always clean up the hash descrptor
instead of not doing this in error cases. All of the callers were
just calling cfs_crypto_hash_final() immediately to clean up the
descriptor anyway, and the old behaviour is unlike other init/fini
functions, and prone to memory leaks and other incorrect usage. The
callers can call cfs_crypto_digest_size() to determine the hash size
in advance if needed, and avoid complexity in cfs_crypto_hash_final().
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/lnet/libcfs/linux/linux-crypto.c | 24 +++++++++----------
drivers/staging/lustre/lustre/osc/osc_request.c | 5 +---
drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | 12 +++++-----
3 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 6fe1fdd..d5bb10f 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -265,8 +265,8 @@ EXPORT_SYMBOL(cfs_crypto_hash_update);
* \param[in,out] hash_len pointer to hash buffer size, if \a hdesc = NULL
* only free \a hdesc instead of computing the hash
*
- * \retval -ENOSPC if \a hash = NULL, or \a hash_len < digest size
* \retval 0 for success
+ * \retval -EOVERFLOW if hash_len is too small for the hash digest
* \retval negative errno for other errors from lower layers
*/
int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *hdesc,
@@ -276,22 +276,20 @@ int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *hdesc,
struct ahash_request *req = (void *)hdesc;
int size = crypto_ahash_digestsize(crypto_ahash_reqtfm(req));
- if (!hash_len) {
- crypto_free_ahash(crypto_ahash_reqtfm(req));
- ahash_request_free(req);
- return 0;
+ if (!hash || !hash_len) {
+ err = 0;
+ goto free_ahash;
}
- if (!hash || *hash_len < size) {
- *hash_len = size;
- return -ENOSPC;
+ if (*hash_len < size) {
+ err = -EOVERFLOW;
+ goto free_ahash;
}
+
ahash_request_set_crypt(req, NULL, hash, 0);
err = crypto_ahash_final(req);
-
- if (err < 0) {
- /* May be caller can fix error */
- return err;
- }
+ if (!err)
+ *hash_len = size;
+free_ahash:
crypto_free_ahash(crypto_ahash_reqtfm(req));
ahash_request_free(req);
return err;
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 74805f1..ec0287f 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -1208,12 +1208,9 @@ static u32 osc_checksum_bulk(int nob, u32 pg_count,
i++;
}
- bufsize = 4;
+ bufsize = sizeof(cksum);
err = cfs_crypto_hash_final(hdesc, (unsigned char *)&cksum, &bufsize);
- if (err)
- cfs_crypto_hash_final(hdesc, NULL, NULL);
-
/* For sending we only compute the wrong checksum instead
* of corrupting the data so it is still correct on a redo
*/
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
index 72d5b9b..54a0c1f 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
@@ -41,7 +41,6 @@
#define DEBUG_SUBSYSTEM S_SEC
#include "../../include/linux/libcfs/libcfs.h"
-#include <linux/crypto.h>
#include "../include/obd.h"
#include "../include/obd_cksum.h"
@@ -511,7 +510,6 @@ int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg,
{
struct cfs_crypto_hash_desc *hdesc;
int hashsize;
- char hashbuf[64];
unsigned int bufsize;
int i, err;
@@ -532,18 +530,20 @@ int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg,
desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK,
desc->bd_iov[i].kiov_len);
}
+
if (hashsize > buflen) {
+ unsigned char hashbuf[CFS_CRYPTO_HASH_DIGESTSIZE_MAX];
+
bufsize = sizeof(hashbuf);
- err = cfs_crypto_hash_final(hdesc, (unsigned char *)hashbuf,
- &bufsize);
+ LASSERTF(bufsize >= hashsize, "bufsize = %u < hashsize %u\n",
+ bufsize, hashsize);
+ err = cfs_crypto_hash_final(hdesc, hashbuf, &bufsize);
memcpy(buf, hashbuf, buflen);
} else {
bufsize = buflen;
err = cfs_crypto_hash_final(hdesc, buf, &bufsize);
}
- if (err)
- cfs_crypto_hash_final(hdesc, NULL, NULL);
return err;
}
EXPORT_SYMBOL(sptlrpc_get_bulk_checksum);
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 08/12] staging: lustre: libcfs: return proper error code for cfs_crypto_hash_speed()
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (6 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 07/12] staging: lustre: libcfs: bug fixes for cfs_crypto_hash_final() James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 09/12] staging: lustre: libcfs: allocate memory in cfs_crypto_performance_test() James Simmons
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Return a real error code, -ENOENT, instead of a -1.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/lnet/libcfs/linux/linux-crypto.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index d5bb10f..90d6e08 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -357,7 +357,7 @@ int cfs_crypto_hash_speed(enum cfs_crypto_hash_alg hash_alg)
{
if (hash_alg < CFS_HASH_ALG_MAX)
return cfs_crypto_hash_speeds[hash_alg];
- return -1;
+ return -ENOENT;
}
EXPORT_SYMBOL(cfs_crypto_hash_speed);
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 09/12] staging: lustre: libcfs: allocate memory in cfs_crypto_performance_test()
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (7 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 08/12] staging: lustre: libcfs: return proper error code for cfs_crypto_hash_speed() James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 10/12] staging: lustre: libcfs: print crypto performance result only on success James Simmons
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Move memory allocation from cfs_crypto_test_hashes() into the
function cfs_crypto_performance_test().
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/lnet/libcfs/linux/linux-crypto.c | 40 +++++++++----------
1 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 90d6e08..4857a11 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -307,16 +307,27 @@ EXPORT_SYMBOL(cfs_crypto_hash_final);
* \param[in] buf data buffer on which to compute the hash
* \param[in] buf_len length of \buf on which to compute hash
*/
-static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg,
- const unsigned char *buf,
- unsigned int buf_len)
+static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg)
{
+ int buf_len = max(PAGE_SIZE, 1048576UL);
+ void *buf;
unsigned long start, end;
int bcount, err = 0;
int sec = 1; /* do test only 1 sec */
+ struct page *page;
unsigned char hash[CFS_CRYPTO_HASH_DIGESTSIZE_MAX];
unsigned int hash_len = sizeof(hash);
+ page = alloc_page(GFP_KERNEL);
+ if (!page) {
+ err = -ENOMEM;
+ goto out_err;
+ }
+
+ buf = kmap(page);
+ memset(buf, 0xAD, PAGE_SIZE);
+ kunmap(page);
+
for (start = jiffies, end = start + sec * HZ, bcount = 0;
time_before(jiffies, end); bcount++) {
err = cfs_crypto_hash_digest(hash_alg, buf, buf_len, NULL, 0,
@@ -325,7 +336,8 @@ static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg,
break;
}
end = jiffies;
-
+ __free_page(page);
+out_err:
if (err) {
cfs_crypto_hash_speeds[hash_alg] = -1;
CDEBUG(D_INFO, "Crypto hash algorithm %s, err = %d\n",
@@ -381,25 +393,11 @@ EXPORT_SYMBOL(cfs_crypto_hash_speed);
*/
static int cfs_crypto_test_hashes(void)
{
- unsigned char i;
- unsigned char *data;
- unsigned int j;
- /* Data block size for testing hash. Maximum
- * kmalloc size for 2.6.18 kernel is 128K
- */
- unsigned int data_len = 1 * 128 * 1024;
-
- data = kmalloc(data_len, 0);
- if (!data)
- return -ENOMEM;
-
- for (j = 0; j < data_len; j++)
- data[j] = j & 0xff;
+ enum cfs_crypto_hash_alg hash_alg;
- for (i = 0; i < CFS_HASH_ALG_MAX; i++)
- cfs_crypto_performance_test(i, data, data_len);
+ for (hash_alg = 0; hash_alg < CFS_HASH_ALG_MAX; hash_alg++)
+ cfs_crypto_performance_test(hash_alg);
- kfree(data);
return 0;
}
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 10/12] staging: lustre: libcfs: print crypto performance result only on success
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (8 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 09/12] staging: lustre: libcfs: allocate memory in cfs_crypto_performance_test() James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 11/12] staging: lustre: libcfs: improve reporting error for crypto performance James Simmons
2016-03-26 19:40 ` [PATCH 12/12] staging: lustre: libcfs: calculate crypto performance using pages James Simmons
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Only print info about the crypto performance when no error
is encounter.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/lnet/libcfs/linux/linux-crypto.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 4857a11..3d74fd1 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -348,9 +348,10 @@ out_err:
tmp = ((bcount * buf_len / jiffies_to_msecs(end - start)) *
1000) / (1024 * 1024);
cfs_crypto_hash_speeds[hash_alg] = (int)tmp;
+ CDEBUG(D_CONFIG, "Crypto hash algorithm %s speed = %d MB/s\n",
+ cfs_crypto_hash_name(hash_alg),
+ cfs_crypto_hash_speeds[hash_alg]);
}
- CDEBUG(D_INFO, "Crypto hash algorithm %s speed = %d MB/s\n",
- cfs_crypto_hash_name(hash_alg), cfs_crypto_hash_speeds[hash_alg]);
}
/**
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 11/12] staging: lustre: libcfs: improve reporting error for crypto performance
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (9 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 10/12] staging: lustre: libcfs: print crypto performance result only on success James Simmons
@ 2016-03-26 19:40 ` James Simmons
2016-03-26 19:40 ` [PATCH 12/12] staging: lustre: libcfs: calculate crypto performance using pages James Simmons
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Set cfs_crypto_hash_speeds[X] result to the actual error instead
of -1. Make the error message more clear and informative.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/lnet/libcfs/linux/linux-crypto.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 3d74fd1..aec7916 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -339,8 +339,8 @@ static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg)
__free_page(page);
out_err:
if (err) {
- cfs_crypto_hash_speeds[hash_alg] = -1;
- CDEBUG(D_INFO, "Crypto hash algorithm %s, err = %d\n",
+ cfs_crypto_hash_speeds[hash_alg] = err;
+ CDEBUG(D_INFO, "Crypto hash algorithm %s test error: rc = %d\n",
cfs_crypto_hash_name(hash_alg), err);
} else {
unsigned long tmp;
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 12/12] staging: lustre: libcfs: calculate crypto performance using pages
2016-03-26 19:40 [PATCH 00/12] Bring the libcfs crypto code up to date James Simmons
` (10 preceding siblings ...)
2016-03-26 19:40 ` [PATCH 11/12] staging: lustre: libcfs: improve reporting error for crypto performance James Simmons
@ 2016-03-26 19:40 ` James Simmons
11 siblings, 0 replies; 13+ messages in thread
From: James Simmons @ 2016-03-26 19:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel, Andreas Dilger, Oleg Drokin
Cc: Linux Kernel Mailing List, Lustre Development List, Andreas Dilger
From: Andreas Dilger <andreas.dilger@intel.com>
Use alloc_page() and use cfs_crypto_hash_update_page()
to compute the hash instead of cfs_crypto_hash_digest(), since
tgt_checksum_bulk() computes the hash by page anyway.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5279
Reviewed-on: http://review.whamcloud.com/10982
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Alexander Boyko <alexander_boyko@xyratex.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
.../lustre/lnet/libcfs/linux/linux-crypto.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index aec7916..f8383dc 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -330,8 +330,23 @@ static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg)
for (start = jiffies, end = start + sec * HZ, bcount = 0;
time_before(jiffies, end); bcount++) {
- err = cfs_crypto_hash_digest(hash_alg, buf, buf_len, NULL, 0,
- hash, &hash_len);
+ struct cfs_crypto_hash_desc *hdesc;
+ int i;
+
+ hdesc = cfs_crypto_hash_init(hash_alg, NULL, 0);
+ if (IS_ERR(hdesc)) {
+ err = PTR_ERR(hdesc);
+ break;
+ }
+
+ for (i = 0; i < buf_len / PAGE_SIZE; i++) {
+ err = cfs_crypto_hash_update_page(hdesc, page, 0,
+ PAGE_SIZE);
+ if (err)
+ break;
+ }
+
+ err = cfs_crypto_hash_final(hdesc, hash, &hash_len);
if (err)
break;
}
--
1.7.1
^ permalink raw reply [flat|nested] 13+ messages in thread