Asynchronous crypto layer. Reincarnation #1.
Subsystems (2)
Changed locking schema, coding style, symbol exporting. HIFN driver is ready and is waiting the latest test.
It works several hours on a 4-way system without any problem (test crypto_provider and crypto consumer are also in patch).
BTW, little note:
System crypts with 128 bits aes in ecb mode, since only one CPU in a time performs
crypto operations(crypto_provider is a wrapper over synchronous crypto layer)
numbers are not so exciting: about 250-350 sessions per second, each one works
with 32 bytes block. Test crypto consumer injects new session each 3 milliseconds.
An interesting note about linux work_queues: when I inject new crypto_session each 2
msecs - work_queue's threads for 2 of 4 CPUs are loaded about the same 3-10% of
the CPU time, but when I inject sessions each 3 or 1 msec - only one queue's thread
gets all sessions callbacks and takes about 100% of the CPU time. With 2msec delay I get about 500 sessions per second, with 1msec - little more than 1000.
pcix$ cat /sys/class/acrypto/crypto_provider/scompleted && sleep 1 &&cat /sys/class/acrypto/crypto_provider/scompleted 7044717
7045728
Please test, review and comment.
Signature · 3 lines
Evgeniy Polyakov Crash is better than data corruption -- Arthur Grabowski
drivers/acrypto/acrypto.h renamed from tmp/empty/acrypto.h +226 -0
@@ -0,0 +1,226 @@ +/* +* acrypto.h +* +* Copyright (c) 2004 Evgeniy Polyakov <[email protected]> +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __ACRYPTO_H +#define __ACRYPTO_H + +#define SCACHE_NAMELEN 32 + +struct crypto_session_initializer ; +struct crypto_data ; +typedef void (*crypto_callback_t ) (struct crypto_session_initializer *, +struct crypto_data *); + +extern void crypto_wake_lb (void ); + +#define SESSION_COMPLETED (1<<15) +#define SESSION_FINISHED (1<<14) +#define SESSION_STARTED (1<<13) +#define SESSION_PROCESSED (1<<12) +#define SESSION_BINDED (1<<11) +#define SESSION_BROKEN (1<<10) + +#define session_completed (s) (s->ci.flags & SESSION_COMPLETED) +#define complete_session (s) do {s->ci.flags |= SESSION_COMPLETED;} while(0) +#define uncomplete_session (s) do {s->ci.flags &= ~SESSION_COMPLETED;} while (0) + +#define session_finished (s) (s->ci.flags & SESSION_FINISHED) +#define finish_session (s) do {s->ci.flags |= SESSION_FINISHED;} while(0) +#define unfinish_session (s) do {s->ci.flags &= ~SESSION_FINISHED;} while (0) + +#define session_started (s) (s->ci.flags & SESSION_STARTED) +#define start_session (s) do {s->ci.flags |= SESSION_STARTED;} while(0) +#define unstart_session (s) do {s->ci.flags &= ~SESSION_STARTED;} while (0) + +#define session_is_processed (s) (s->ci.flags & SESSION_PROCESSED) +#define start_process_session (s) do {s->ci.flags |= SESSION_PROCESSED; s->ci.ptime = jiffies;} while(0) +#define stop_process_session (s) do {s->ci.flags &= ~SESSION_PROCESSED; s->ci.ptime = jiffies - s->ci.ptime; crypto_wake_lb();} while (0) + +#define session_binded (s) (s->ci.flags & SESSION_BINDED) +#define bind_session (s) do {s->ci.flags |= SESSION_BINDED;} while(0) +#define unbind_session (s) do {s->ci.flags &= ~SESSION_BINDED;} while (0) +#define sci_binded (ci) (ci->flags & SESSION_BINDED) + +#define session_broken (s) (s->ci.flags & SESSION_BROKEN) +#define broke_session (s) do {s->ci.flags |= SESSION_BROKEN;} while(0) +#define unbroke_session (s) do {s->ci.flags &= ~SESSION_BROKEN;} while (0) + +struct crypto_device_stat { +__u64 scompleted; +__u64 sfinished; +__u64 sstarted; +__u64 kmem_failed; +}; + +#ifdef __KERNEL__ + +#include <linux/types.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/device.h> +#include <linux/workqueue.h> + +#include <asm/scatterlist.h> + +#define DEBUG +#ifdef DEBUG +#define dprintk(f, a...) printk("%d " f, smp_processor_id(), ##a) +#else +#define dprintk(f, a...) +#endif + +#define CRYPTO_MAX_PRIV_SIZE 1024 + +#define DEVICE_BROKEN (1<<0) + +#define device_broken (dev) (dev->flags & DEVICE_BROKEN) +#define broke_device (dev) do {dev->flags |= DEVICE_BROKEN;} while(0) +#define repair_device (dev) do {dev->flags &= ~DEVICE_BROKEN;} while(0) + +struct crypto_capability { +u16 operation; +u16 type; +u16 mode; +u16 qlen; +u64 ptime; +u64 scomp; +}; + +struct crypto_session_initializer { +u16 operation; +u16 type; +u16 mode; +u16 priority; + +u64 id; +u64 dev_id; + +u32 flags; + +u32 bdev; + +u64 ptime; + +crypto_callback_t callback; +}; + +struct crypto_data { +int sg_src_num; +struct scatterlist sg_src; +struct scatterlist sg_dst; +struct scatterlist sg_key; +struct scatterlist sg_iv; + +void *priv; +unsigned int priv_size; +}; + +struct crypto_device { +char name[SCACHE_NAMELEN ]; + +spinlock_t session_lock; +struct list_head session_list; + +u64 sid; +spinlock_t lock; + +atomic_t refcnt; + +u32 flags; + +u32 id; + +struct list_head cdev_entry; + +void (*data_ready)(struct crypto_device *); + +struct device_driver *driver; +struct device device; +struct class_device class_device; +struct completion dev_released; + +spinlock_t stat_lock; +struct crypto_device_stat stat; + +struct crypto_capability *cap; +int cap_number; + +void *priv; +}; + +struct crypto_route_head { +struct crypto_route *next; +struct crypto_route *prev; + +__u32 qlen; +spinlock_t lock; +}; + +struct crypto_route { +struct crypto_route *next; +struct crypto_route *prev; + +struct crypto_route_head *list; +struct crypto_device *dev; + +struct crypto_session_initializer ci; +}; + +struct crypto_session { +struct list_head dev_queue_entry; +struct list_head main_queue_entry; + +struct crypto_session_initializer ci; + +struct crypto_data data; + +spinlock_t lock; + +struct work_struct work; + +struct crypto_route_head route_list; +}; + +struct crypto_session *crypto_session_alloc (struct crypto_session_initializer *,struct crypto_data *); +struct crypto_session *crypto_session_create (struct crypto_session_initializer *,struct crypto_data *); +void crypto_session_add (struct crypto_session *); +void crypto_session_dequeue_main (struct crypto_session *); +void __crypto_session_dequeue_main (struct crypto_session *); +void __crypto_session_dequeue_route (struct crypto_session *); +void crypto_session_dequeue_route (struct crypto_session *); + +void crypto_device_get (struct crypto_device *); +void crypto_device_put (struct crypto_device *); +struct crypto_device *crypto_device_get_name (char *); + +int __crypto_device_add (struct crypto_device *); +int crypto_device_add (struct crypto_device *); +void __crypto_device_remove (struct crypto_device *); +void crypto_device_remove (struct crypto_device *); +int match_initializer (struct crypto_device *,struct crypto_session_initializer *); +int __match_initializer (struct crypto_capability *,struct crypto_session_initializer *); + +void crypto_session_insert_main (struct crypto_device *dev,struct crypto_session *s); +void crypto_session_insert (struct crypto_device *dev,struct crypto_session *s); + +#endif /* __KERNEL__ */ +#endif /* __ACRYPTO_H */
drivers/acrypto/.arch-ids/acrypto.h.id renamed from tmp/empty/.arch-ids/acrypto.h.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Sun Oct 3 20:33:25 2004 2957.0
drivers/acrypto/.arch-ids/consumer.c.id renamed from tmp/empty/.arch-ids/consumer.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Wed Oct 6 02:34:04 2004 4902.0
drivers/acrypto/.arch-ids/crypto_conn.c.id renamed from tmp/empty/.arch-ids/crypto_conn.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Wed Oct 6 03:19:44 2004 5558.0
drivers/acrypto/.arch-ids/crypto_conn.h.id renamed from tmp/empty/.arch-ids/crypto_conn.h.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Wed Oct 6 03:19:44 2004 5558.1
drivers/acrypto/.arch-ids/crypto_def.h.id renamed from tmp/empty/.arch-ids/crypto_def.h.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Tue Oct 26 20:26:53 2004 2903.0
drivers/acrypto/.arch-ids/crypto_dev.c.id renamed from tmp/empty/.arch-ids/crypto_dev.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Sun Oct 3 22:27:13 2004 4211.0
drivers/acrypto/.arch-ids/crypto_lb.c.id renamed from tmp/empty/.arch-ids/crypto_lb.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Sun Oct 3 22:27:09 2004 4210.0
drivers/acrypto/.arch-ids/crypto_lb.h.id renamed from tmp/empty/.arch-ids/crypto_lb.h.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Sun Oct 3 22:27:09 2004 4210.1
drivers/acrypto/.arch-ids/crypto_main.c.id renamed from tmp/empty/.arch-ids/crypto_main.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Sun Oct 3 20:28:05 2004 2950.1
drivers/acrypto/.arch-ids/crypto_route.h.id renamed from tmp/empty/.arch-ids/crypto_route.h.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Tue Oct 12 19:25:27 2004 2518.0
drivers/acrypto/.arch-ids/crypto_stat.c.id renamed from tmp/empty/.arch-ids/crypto_stat.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Thu Oct 7 23:08:48 2004 4384.0
drivers/acrypto/.arch-ids/crypto_stat.h.id renamed from tmp/empty/.arch-ids/crypto_stat.h.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Thu Oct 7 23:08:48 2004 4384.1
drivers/acrypto/.arch-ids/Makefile.id renamed from tmp/empty/.arch-ids/Makefile.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Sun Oct 3 20:28:05 2004 2950.0
drivers/acrypto/.arch-ids/provider.c.id renamed from tmp/empty/.arch-ids/provider.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Wed Oct 6 02:34:04 2004 4902.1
drivers/acrypto/.arch-ids/sha1_provider.c.id renamed from tmp/empty/.arch-ids/sha1_provider.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Wed Oct 20 20:26:53 2004 25654.0
drivers/acrypto/.arch-ids/simple_lb.c.id renamed from tmp/empty/.arch-ids/simple_lb.c.id +1 -0
@@ -0,0 +1 @@ +Evgeniy Polyakov <[email protected]> Mon Oct 4 00:58:07 2004 4691.0
drivers/acrypto/consumer.c renamed from tmp/empty/consumer.c +288 -0
288 lines not on this page · raw message
Binary files /tmp/empty/.consumer.c.swp and linux-2.6/drivers/acrypto/.consumer.c.swp differ
drivers/acrypto/crypto_conn.c renamed from tmp/empty/crypto_conn.c +191 -0
191 lines not on this page · raw message
drivers/acrypto/crypto_conn.h renamed from tmp/empty/crypto_conn.h +44 -0
44 lines not on this page · raw message
drivers/acrypto/crypto_def.h renamed from tmp/empty/crypto_def.h +38 -0
@@ -0,0 +1,38 @@ +/* +* crypto_def.h +* +* Copyright (c) 2004 Evgeniy Polyakov <[email protected]> +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __CRYPTO_DEF_H +#define __CRYPTO_DEF_H + +#define CRYPTO_OP_DECRYPT 0 +#define CRYPTO_OP_ENCRYPT 1 +#define CRYPTO_OP_HMAC 2 + +#define CRYPTO_MODE_ECB 0 +#define CRYPTO_MODE_CBC 1 +#define CRYPTO_MODE_CFB 2 +#define CRYPTO_MODE_OFB 3 + +#define CRYPTO_TYPE_AES_128 0 +#define CRYPTO_TYPE_AES_192 1 +#define CRYPTO_TYPE_AES_256 2 + +#endif /* __CRYPTO_DEF_H */
drivers/acrypto/crypto_dev.c renamed from tmp/empty/crypto_dev.c +371 -0
371 lines not on this page · raw message
drivers/acrypto/crypto_lb.c renamed from tmp/empty/crypto_lb.c +631 -0
631 lines not on this page · raw message
Binary files /tmp/empty/.crypto_lb.c.swn and linux-2.6/drivers/acrypto/.crypto_lb.c.swn differ Binary files /tmp/empty/.crypto_lb.c.swo and linux-2.6/drivers/acrypto/.crypto_lb.c.swo differ Binary files /tmp/empty/.crypto_lb.c.swp and linux-2.6/drivers/acrypto/.crypto_lb.c.swp differ
drivers/acrypto/crypto_lb.h renamed from tmp/empty/crypto_lb.h +62 -0
62 lines not on this page · raw message
drivers/acrypto/crypto_main.c renamed from tmp/empty/crypto_main.c +340 -0
340 lines not on this page · raw message
drivers/acrypto/crypto_provider.c renamed from tmp/empty/crypto_provider.c +183 -0
183 lines not on this page · raw message
Binary files /tmp/empty/.crypto_provider.c.swp and linux-2.6/drivers/acrypto/.crypto_provider.c.swp differ
drivers/acrypto/crypto_route.h renamed from tmp/empty/crypto_route.h +242 -0
242 lines not on this page · raw message
drivers/acrypto/crypto_stat.c renamed from tmp/empty/crypto_stat.c +100 -0
100 lines not on this page · raw message
drivers/acrypto/crypto_stat.h renamed from tmp/empty/crypto_stat.h +32 -0
@@ -0,0 +1,32 @@ +/* +* crypto_stat.h +* +* Copyright (c) 2004 Evgeniy Polyakov <[email protected]> +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __CRYPTO_STAT_H +#define __CRYPTO_STAT_H + +#include "acrypto.h" + +void crypto_stat_start_inc (struct crypto_session *s); +void crypto_stat_finish_inc (struct crypto_session *s); +void crypto_stat_complete_inc (struct crypto_session *s); +void crypto_stat_ptime_inc (struct crypto_session *s); + +#endif /* __CRYPTO_STAT_H */
drivers/acrypto/Kconfig renamed from tmp/empty/Kconfig +40 -0
@@ -0,0 +1,40 @@ +menu "Asynchronous crypto layer" + +config ACRYPTO + tristate "Asyncronous crypto layer" + depends on CONNECTOR + help + Say Y here if you want to use new Linux asynchronous crypto layer. + This support is also available as a module. If so, the module + will be called acrypto.ko. + +config SIMPLE_LB + tristate "Simple asyncronous crypto load balancer" + depends on ACRYPTO + help + Say Y here if you want to compile simple load balancer which takes into + account only crypto device's queue length. + This support is also available as a module. If so, the module + will be called simpl_lb.ko. + +config TEST_CRYPTO_PROVIDER + tristate "Simple crypto provider" + depends on CRYPTO && ACRYPTO + help + Say Y here if you want to compile test bridge between + synchronous crypto layer and asyncronous one. + It supports only AES-128-ECB. + This support is also available as a module. If so, the module + will be called crypto_provider.ko. + +config TEST_CRYPTO_CONSUMER + tristate "Simple crypto consumer" + depends on ACRYPTO + help + Say Y here if you want to compile test crypto consumer + which injects crypto session one time per jiffie. + It supports only AES-128-ECB. + This support is also available as a module. If so, the module + will be called consumer.ko. + +endmenu
drivers/acrypto/Makefile renamed from tmp/empty/Makefile +6 -0
@@ -0,0 +1,6 @@ +obj-$(CONFIG_ACRYPTO) += acrypto.o +obj-$(CONFIG_SIMPLE_LB) += simple_lb.o +obj-$(CONFIG_TEST_CRYPTO_PROVIDER) += crypto_provider.o +obj-$(CONFIG_TEST_CRYPTO_CONSUMER) += consumer.o + +acrypto-objs := crypto_main.o crypto_lb.o crypto_dev.o crypto_conn.o crypto_stat.o
drivers/acrypto/simple_lb.c renamed from tmp/empty/simple_lb.c +91 -0
91 lines not on this page · raw message
drivers/connector/Kconfig renamed from tmp/empty/Kconfig +13 -0
@@ -0,0 +1,13 @@ +menu "Connector - unified userspace <-> kernelspace linker" + +config CONNECTOR + tristate "Connector - unified userspace <-> kernelspace linker" + depends on NET + ---help--- + This is unified userspace <-> kernelspace connector working on top + of the netlink socket protocol. + + Connector support can also be built as a module. If so, the module + will be called connector.ko. + +endmenu
drivers/connector/Makefile renamed from tmp/empty/Makefile +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_CONNECTOR) += cn.o +cn-objs := cn_queue.o connector.o
drivers/connector/cn_queue.c renamed from tmp/empty/cn_queue.c +219 -0
84 lines not on this page · raw message
drivers/connector/cn_queue.h renamed from tmp/empty/cn_queue.h +90 -0
90 lines not on this page · raw message
drivers/connector/connector.c renamed from tmp/empty/connector.c +498 -0
498 lines not on this page · raw message
drivers/connector/connector.h renamed from tmp/empty/connector.h +81 -0
81 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
drivers/Kconfig renamed from drivers/Kconfig.orig +2 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/Kconfig renamed from drivers/Kconfig.nocrypto +2 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/Makefile renamed from drivers/Makefile.orig +1 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/Makefile renamed from drivers/Makefile.nocrypto +1 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.