Re: [RFC] [PATCH 2/5] aead: Add generic aead wrapper interface

2009-06-29 Thread Steffen Klassert
On Thu, Jun 25, 2009 at 02:51:12PM +0800, Herbert Xu wrote:
 
 OK, the patch I just posted to the list should fix the problem.
 
 I was able to test it suing
 
 modprobe tcrypt alg='pcrypt(authenc(hmac(sha1-generic),cbc(aes-generic)))' 
 type=3
 

I applied your patch on top of the last pcrypt patchset, but
unfortunately it does not change anything here.

If I do
modprobe tcrypt alg='pcrypt(authenc(hmac(sha1-generic),cbc(aes-generic)))' 
type=3

it instantiates

authenc(hmac(sha1-generic),cbc(aes-generic))

but not 

pcrypt(authenc(hmac(sha1-generic),cbc(aes-generic)))

regardless your patch applied or not.
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC] [PATCH 3/5] eseqiv: Add support for aead algorithms

2009-06-29 Thread Steffen Klassert
On Thu, Jun 25, 2009 at 06:46:02PM +0800, Herbert Xu wrote:
 On Mon, Jun 08, 2009 at 09:10:46AM +0200, Steffen Klassert wrote:
  This adds eseqiv support for aead algorithms, this is usefull
  for aead algorithms that need eseqiv as it's default IV generator.
  
  Signed-off-by: Steffen Klassert steffen.klass...@secunet.com
 
 I'm going to change the default sync geniv to eseqiv for SMP.
 That should render this patch unnecessary, right?
 

Right, this would reduce the patchset to the padata and the pcrypt
patch. I'll strip the patchset to these two patches as soon as I see
your patch applied to cryptodev-2.6.
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Bug when modprobing tcrypt

2009-06-29 Thread Eric Sesterhenn
Hi,

i can repeatedly trigger the following bug when modprobing tcrypt
to test the crypto algorithms with todays -git

[  122.967099] BUG: sleeping function called from invalid context at
kernel/rwsem.c:21
[  122.967398] in_atomic(): 1, irqs_disabled(): 0, pid: 4926, name:
modprobe
[  122.967643] INFO: lockdep is turned off.
[  122.967858] Pid: 4926, comm: modprobe Tainted: G   M
2.6.31-rc1-22297-g5298976 #24
[  122.968176] Call Trace:
[  122.968411]  [c011dd93] __might_sleep+0xf9/0x101
[  122.968677]  [c0777aa0] down_read+0x16/0x68
[  122.968928]  [c048bf04] crypto_alg_lookup+0x16/0x34
[  122.969479]  [c048bf52] crypto_larval_lookup+0x30/0xf9
[  122.969722]  [c048c038] crypto_alg_mod_lookup+0x1d/0x62
[  122.969977]  [c048c13e] crypto_alloc_base+0x1e/0x64
[  122.970271]  [c04bf991] reset_prng_context+0xab/0x13f
[  122.970523]  [c04e5cfc] ? __spin_lock_init+0x27/0x51
[  122.970777]  [c04bfce1] cprng_init+0x2a/0x42
[  122.971012]  [c048bb4c] __crypto_alloc_tfm+0xfa/0x128
[  122.971304]  [c048c153] crypto_alloc_base+0x33/0x64
[  122.971556]  [c04933c9] alg_test_cprng+0x30/0x1f4
[  122.971809]  [c0493329] alg_test+0x12f/0x19f
[  122.972103]  [c0177f1f] ? __alloc_pages_nodemask+0x14d/0x481
[  122.972356]  [d09219e2] do_test+0xf9d/0x163f [tcrypt]
[  122.972613]  [d0920de6] do_test+0x3a1/0x163f [tcrypt]
[  122.972855]  [d0926035] tcrypt_mod_init+0x35/0x7c [tcrypt]
[  122.973488]  [c010113c] _stext+0x54/0x12c
[  122.974575]  [d0926000] ? tcrypt_mod_init+0x0/0x7c [tcrypt]
[  122.974836]  [c01398a3] ? up_read+0x16/0x2b
[  122.975126]  [c0139fc4] ? __blocking_notifier_call_chain+0x40/0x4c
[  122.975376]  [c014ee8d] sys_init_module+0xa9/0x1bf
[  122.975635]  [c010292b] sysenter_do_call+0x12/0x32

(gdb) l *(crypto_alg_lookup+0x16)
0xc048bf04 is in crypto_alg_lookup (crypto/api.c:201).
196 struct crypto_alg *crypto_alg_lookup(const char *name, u32 type, u32
mask)
197 {
198 struct crypto_alg *alg;
199 
200 down_read(crypto_alg_sem);
201 alg = __crypto_alg_lookup(name, type, mask);
202 up_read(crypto_alg_sem);
203 
204 return alg;
205 }

Please let me know if you need further information or have patches to
test.

Regards, Eric

--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] padata: generic interface for parallel processing

2009-06-29 Thread Steffen Klassert
This patch introduces an interface to process data objects
in parallel. On request it is possible to serialize again.
The parallelized objects return after serialization in the
same order as they were before the parallelization.

Signed-off-by: Steffen Klassert steffen.klass...@secunet.com
---
 include/linux/interrupt.h |3 +-
 include/linux/padata.h|  116 +++
 kernel/Makefile   |2 +-
 kernel/padata.c   |  490 +
 kernel/softirq.c  |2 +-
 5 files changed, 610 insertions(+), 3 deletions(-)
 create mode 100644 include/linux/padata.h
 create mode 100644 kernel/padata.c

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 2721f07..4aad58f 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -344,7 +344,8 @@ enum
TASKLET_SOFTIRQ,
SCHED_SOFTIRQ,
HRTIMER_SOFTIRQ,
-   RCU_SOFTIRQ,/* Preferable RCU should always be the last softirq */
+   PADATA_SOFTIRQ,
+   RCU_SOFTIRQ,/* Preferable RCU should always be the last softirq */
 
NR_SOFTIRQS
 };
diff --git a/include/linux/padata.h b/include/linux/padata.h
new file mode 100644
index 000..469359f
--- /dev/null
+++ b/include/linux/padata.h
@@ -0,0 +1,116 @@
+/*
+ * padata.h - header for the padata parallelization interface
+ *
+ * Copyright (C) 2008, 2009 secunet Security Networks AG
+ * Copyright (C) 2008, 2009 Steffen Klassert steffen.klass...@secunet.com
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef PADATA_H
+#define PADATA_H
+
+#include linux/interrupt.h
+#include linux/smp.h
+#include linux/list.h
+
+enum
+{
+   NO_PADATA=0,
+   AEAD_ENC_PADATA,
+   AEAD_DEC_PADATA,
+   NR_PADATA
+};
+
+struct padata_priv {
+   struct list_headlist;
+   struct call_single_data csd;
+   int cb_cpu;
+   int seq_nr;
+   unsigned intnr;
+   int info;
+   void(*parallel)(struct padata_priv *padata);
+   void(*serial)(struct padata_priv *padata);
+};
+
+struct padata_queue {
+   struct list_headlist;
+   atomic_tnum_obj;
+   int cpu_index;
+   spinlock_t  lock;
+};
+
+struct parallel_data {
+   struct work_struct  work;
+   struct padata_queue *queue;
+   atomic_tseq_nr;
+   atomic_tqueued_objects;
+   cpumask_t   cpu_map;
+   cpumask_t   new_cpu_map;
+   u8  flags;
+#definePADATA_INIT 1
+#definePADATA_FLUSH_HARD   2
+#definePADATA_RESET_IN_PROGRESS4
+   spinlock_t  lock;
+};
+
+#ifdef CONFIG_USE_GENERIC_SMP_HELPERS
+extern void __init padata_init(unsigned int nr, cpumask_t cpu_map);
+extern void padata_dont_wait(unsigned int nr, struct padata_priv *padata);
+extern int padata_do_parallel(unsigned int softirq_nr, unsigned int nr,
+ struct padata_priv *padata, int cb_cpu);
+extern int padata_do_serial(unsigned int nr, struct padata_priv *padata);
+extern cpumask_t padata_get_cpumap(unsigned int nr);
+extern void padata_set_cpumap(unsigned int nr, cpumask_t cpu_map);
+extern void padata_add_cpu(unsigned int nr, int cpu);
+extern void padata_remove_cpu(unsigned int nr, int cpu);
+extern void padata_start(unsigned int nr);
+extern void padata_stop(unsigned int nr);
+#else
+static inline void padata_init(unsigned int nr,cpumask_t cpu_map)
+{
+}
+static inline void padata_dont_wait(unsigned int nr, struct padata_priv 
*padata)
+{
+}
+static inline int padata_do_parallel(unsigned int softirq_nr, unsigned int nr,
+struct padata_priv *padata, int cb_cpu)
+{
+   return 0;
+}
+static inline int padata_do_serial(unsigned int nr, struct padata_priv *padata)
+{
+   return 0;
+}
+static inline cpumask_t padata_get_cpumap(unsigned int nr)
+{
+   return cpu_online_map;
+}
+static inline void padata_set_cpumap(unsigned int nr, cpumask_t cpu_map)
+{
+}
+static inline padata_add_cpu(unsigned int nr, int cpu)
+{
+}
+static inline padata_remove_cpu(unsigned int nr, int cpu)
+{
+}
+static 

[PATCH 2/2] pcrypt: Add pcrypt crypto parallelization wrapper

2009-06-29 Thread Steffen Klassert
This patch adds a parallel crypto template that takes a crypto
algorithm and converts it to process the crypto transforms in
parallel. For the moment only aead is supported.

Signed-off-by: Steffen Klassert steffen.klass...@secunet.com
---
 crypto/Kconfig|   13 ++
 crypto/Makefile   |2 +
 crypto/pcrypt.c   |  411 +
 crypto/pcrypt_core.c  |  106 
 include/crypto/pcrypt.h   |   51 ++
 include/linux/interrupt.h |2 +
 6 files changed, 585 insertions(+), 0 deletions(-)
 create mode 100644 crypto/pcrypt.c
 create mode 100644 crypto/pcrypt_core.c
 create mode 100644 include/crypto/pcrypt.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index f2002d8..1a3b277 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -113,6 +113,19 @@ config CRYPTO_NULL
help
  These are 'Null' algorithms, used by IPsec, which do nothing.
 
+config CRYPTO_PCRYPT_CORE
+   bool
+
+config CRYPTO_PCRYPT
+   tristate Parallel crypto engine (EXPERIMENTAL)
+   depends on USE_GENERIC_SMP_HELPERS  EXPERIMENTAL
+   select CRYPTO_MANAGER
+   select CRYPTO_PCRYPT_CORE
+   select CRYPTO_AEAD
+   help
+ This converts an arbitrary crypto algorithm into a parallel
+ algorithm that is executed in a softirq.
+
 config CRYPTO_WORKQUEUE
tristate
 
diff --git a/crypto/Makefile b/crypto/Makefile
index 673d9f7..84b9d17 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -56,6 +56,8 @@ obj-$(CONFIG_CRYPTO_XTS) += xts.o
 obj-$(CONFIG_CRYPTO_CTR) += ctr.o
 obj-$(CONFIG_CRYPTO_GCM) += gcm.o
 obj-$(CONFIG_CRYPTO_CCM) += ccm.o
+obj-$(CONFIG_CRYPTO_PCRYPT_CORE) += pcrypt_core.o
+obj-$(CONFIG_CRYPTO_PCRYPT) += pcrypt.o
 obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o
 obj-$(CONFIG_CRYPTO_DES) += des_generic.o
 obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
new file mode 100644
index 000..2debf8b
--- /dev/null
+++ b/crypto/pcrypt.c
@@ -0,0 +1,411 @@
+/*
+ * pcrypt - Parallel crypto wrapper.
+ *
+ * Copyright (C) 2009 secunet Security Networks AG
+ * Copyright (C) 2009 Steffen Klassert steffen.klass...@secunet.com
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include crypto/algapi.h
+#include crypto/internal/aead.h
+#include linux/err.h
+#include linux/init.h
+#include linux/module.h
+#include linux/slab.h
+#include crypto/pcrypt.h
+
+struct pcrypt_instance_ctx {
+   struct crypto_spawn spawn;
+   unsigned int tfm_count;
+};
+
+struct pcrypt_aead_ctx {
+   struct crypto_aead *child;
+   unsigned int tfm_nr;
+};
+
+static int pcrypt_do_parallel(struct padata_priv *padata, unsigned int tfm_nr,
+ unsigned int softirq, unsigned int padata_nr)
+{
+   unsigned int cpu, cpu_index, num_cpus, cb_cpu;
+   cpumask_t cpu_map;
+
+   cpu_map = padata_get_cpumap(padata_nr);
+   num_cpus = cpus_weight(cpu_map);
+
+   cpu_index = tfm_nr % num_cpus;
+
+   cb_cpu = first_cpu(cpu_map);
+   for (cpu = 0; cpu  cpu_index; cpu++)
+   cb_cpu = next_cpu(cb_cpu, cpu_map);
+
+   return padata_do_parallel(softirq, padata_nr, padata, cb_cpu);
+}
+
+static int pcrypt_aead_setkey(struct crypto_aead *parent,
+ const u8 *key, unsigned int keylen)
+{
+   struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(parent);
+
+   return crypto_aead_setkey(ctx-child, key, keylen);
+}
+
+static int pcrypt_aead_setauthsize(struct crypto_aead *parent,
+  unsigned int authsize)
+{
+   struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(parent);
+
+   return crypto_aead_setauthsize(ctx-child, authsize);
+}
+
+static void pcrypt_aead_serial(struct padata_priv *padata)
+{
+   struct pcrypt_request *preq = pcrypt_padata_request(padata);
+   struct aead_request *req = pcrypt_request_ctx(preq);
+
+   aead_request_complete(req-base.data, padata-info);
+}
+
+static void pcrypt_aead_giv_serial(struct padata_priv *padata)
+{
+   struct pcrypt_request *preq = pcrypt_padata_request(padata);
+   struct aead_givcrypt_request *req = pcrypt_request_ctx(preq);
+
+   aead_request_complete(req-areq.base.data, padata-info);
+}
+
+static void pcrypt_aead_done(struct crypto_async_request *areq, int err)
+{
+   struct aead_request *req 

[PATCH 2/2] crypto/ansi prng: alloc cipher just in in init()

2009-06-29 Thread Sebastian Andrzej Siewior
From: Sebastian Andrzej Siewior sebast...@breakpoint.cc

As reported by Eric Sesterhenn the re-allocation of the cipher in reset leads
to:
|BUG: sleeping function called from invalid context at kernel/rwsem.c:21
|in_atomic(): 1, irqs_disabled(): 0, pid: 4926, name: modprobe
|INFO: lockdep is turned off.
|Pid: 4926, comm: modprobe Tainted: G   M 2.6.31-rc1-22297-g5298976 #24
|Call Trace:
| [c011dd93] __might_sleep+0xf9/0x101
| [c0777aa0] down_read+0x16/0x68
| [c048bf04] crypto_alg_lookup+0x16/0x34
| [c048bf52] crypto_larval_lookup+0x30/0xf9
| [c048c038] crypto_alg_mod_lookup+0x1d/0x62
| [c048c13e] crypto_alloc_base+0x1e/0x64
| [c04bf991] reset_prng_context+0xab/0x13f
| [c04e5cfc] ? __spin_lock_init+0x27/0x51
| [c04bfce1] cprng_init+0x2a/0x42
| [c048bb4c] __crypto_alloc_tfm+0xfa/0x128
| [c048c153] crypto_alloc_base+0x33/0x64
| [c04933c9] alg_test_cprng+0x30/0x1f4
| [c0493329] alg_test+0x12f/0x19f
| [c0177f1f] ? __alloc_pages_nodemask+0x14d/0x481
| [d09219e2] do_test+0xf9d/0x163f [tcrypt]
| [d0920de6] do_test+0x3a1/0x163f [tcrypt]
| [d0926035] tcrypt_mod_init+0x35/0x7c [tcrypt]
| [c010113c] _stext+0x54/0x12c
| [d0926000] ? tcrypt_mod_init+0x0/0x7c [tcrypt]
| [c01398a3] ? up_read+0x16/0x2b
| [c0139fc4] ? __blocking_notifier_call_chain+0x40/0x4c
| [c014ee8d] sys_init_module+0xa9/0x1bf
| [c010292b] sysenter_do_call+0x12/0x32

because a spin lock is held and crypto_alloc_base() may sleep.
There is no reason to re-allocate the cipher, the state is resetted in
-setkey(). This move it to init.

Signed-off-by: Sebastian Andrzej Siewior sebast...@breakpoint.cc
---
 crypto/ansi_cprng.c |   18 +++---
 1 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index ff00b58..259d2de 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -307,17 +307,6 @@ static int reset_prng_context(struct prng_context *ctx,
memset(ctx-rand_data, 0, DEFAULT_BLK_SZ);
memset(ctx-last_rand_data, 0, DEFAULT_BLK_SZ);
 
-   if (ctx-tfm)
-   crypto_free_cipher(ctx-tfm);
-
-   ctx-tfm = crypto_alloc_cipher(aes, 0, 0);
-   if (IS_ERR(ctx-tfm)) {
-   dbgprint(KERN_CRIT Failed to alloc tfm for context %p\n,
-   ctx);
-   ctx-tfm = NULL;
-   goto out;
-   }
-
ctx-rand_data_valid = DEFAULT_BLK_SZ;
 
ret = crypto_cipher_setkey(ctx-tfm, prng_key, klen);
@@ -342,6 +331,13 @@ static int cprng_init(struct crypto_tfm *tfm)
struct prng_context *ctx = crypto_tfm_ctx(tfm);
 
spin_lock_init(ctx-prng_lock);
+   ctx-tfm = crypto_alloc_cipher(aes, 0, 0);
+   if (IS_ERR(ctx-tfm)) {
+   dbgprint(KERN_CRIT Failed to alloc tfm for context %p\n,
+   ctx);
+   ctx-tfm = NULL;
+   return PTR_ERR(ctx-tfm);
+   }
 
if (reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL)  0)
return -EINVAL;
-- 
1.6.3.3

--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html