1 --- a/crypto/ocf/random.c
2 +++ b/crypto/ocf/random.c
4 #include <linux/unistd.h>
5 #include <linux/poll.h>
6 #include <linux/random.h>
7 +#include <linux/kthread.h>
10 #ifdef CONFIG_OCF_FIPS
11 @@ -81,7 +82,7 @@ struct random_op {
13 static int random_proc(void *arg);
15 -static pid_t randomproc = (pid_t) -1;
16 +static struct task_struct *random_task;
17 static spinlock_t random_lock;
20 @@ -141,13 +142,18 @@ crypto_rregister(
21 spin_lock_irqsave(&random_lock, flags);
22 list_add_tail(&rops->random_list, &random_ops);
24 - randomproc = kernel_thread(random_proc, NULL, CLONE_FS|CLONE_FILES);
25 - if (randomproc < 0) {
27 + struct task_struct *t;
29 + t = kthread_create(random_proc, NULL, "ocf-random");
31 printk("crypto: crypto_rregister cannot start random thread; "
41 spin_unlock_irqrestore(&random_lock, flags);
43 @@ -172,7 +178,7 @@ crypto_runregister_all(u_int32_t driveri
45 spin_lock_irqsave(&random_lock, flags);
46 if (list_empty(&random_ops) && started)
47 - kill_proc(randomproc, SIGKILL, 1);
48 + send_sig(SIGKILL, random_task, 1);
49 spin_unlock_irqrestore(&random_lock, flags);
52 @@ -308,7 +314,7 @@ random_proc(void *arg)
55 spin_lock_irq(&random_lock);
56 - randomproc = (pid_t) -1;
59 spin_unlock_irq(&random_lock);
61 --- a/crypto/ocf/crypto.c
62 +++ b/crypto/ocf/crypto.c
63 @@ -74,6 +74,7 @@ __FBSDID("$FreeBSD: src/sys/opencrypto/c
64 #include <linux/sched.h>
65 #include <linux/spinlock.h>
66 #include <linux/version.h>
67 +#include <linux/kthread.h>
68 #include <cryptodev.h>
71 @@ -255,10 +256,10 @@ module_param(crypto_devallowsoft, int, 0
72 MODULE_PARM_DESC(crypto_devallowsoft,
73 "Enable/disable use of software crypto support");
75 -static pid_t cryptoproc = (pid_t) -1;
76 +static struct task_struct *crypto_task;
77 static struct completion cryptoproc_exited;
78 static DECLARE_WAIT_QUEUE_HEAD(cryptoproc_wait);
79 -static pid_t cryptoretproc = (pid_t) -1;
80 +static struct task_struct *cryptoret_task;
81 static struct completion cryptoretproc_exited;
82 static DECLARE_WAIT_QUEUE_HEAD(cryptoretproc_wait);
84 @@ -1401,7 +1402,7 @@ crypto_proc(void *arg)
85 wait_event_interruptible(cryptoproc_wait,
86 !(list_empty(&crp_q) || crypto_all_qblocked) ||
87 !(list_empty(&crp_kq) || crypto_all_kqblocked) ||
88 - cryptoproc == (pid_t) -1);
89 + crypto_task == NULL);
91 if (signal_pending (current)) {
92 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
93 @@ -1414,7 +1415,7 @@ crypto_proc(void *arg)
96 dprintk("%s - awake\n", __FUNCTION__);
97 - if (cryptoproc == (pid_t) -1)
98 + if (crypto_task == NULL)
100 cryptostats.cs_intrs++;
102 @@ -1470,7 +1471,7 @@ crypto_ret_proc(void *arg)
103 dprintk("%s - sleeping\n", __FUNCTION__);
104 CRYPTO_RETQ_UNLOCK();
105 wait_event_interruptible(cryptoretproc_wait,
106 - cryptoretproc == (pid_t) -1 ||
107 + cryptoret_task == NULL ||
108 !list_empty(&crp_ret_q) ||
109 !list_empty(&crp_ret_kq));
110 if (signal_pending (current)) {
111 @@ -1484,7 +1485,7 @@ crypto_ret_proc(void *arg)
114 dprintk("%s - awake\n", __FUNCTION__);
115 - if (cryptoretproc == (pid_t) -1) {
116 + if (cryptoret_task == NULL) {
117 dprintk("%s - EXITING!\n", __FUNCTION__);
120 @@ -1597,6 +1598,7 @@ DB_SHOW_COMMAND(kcrypto, db_show_kcrypto
124 + struct task_struct *t;
127 dprintk("%s(0x%x)\n", __FUNCTION__, (int) crypto_init);
128 @@ -1643,23 +1645,27 @@ crypto_init(void)
129 init_completion(&cryptoproc_exited);
130 init_completion(&cryptoretproc_exited);
132 - cryptoproc = 0; /* to avoid race condition where proc runs first */
133 - cryptoproc = kernel_thread(crypto_proc, NULL, CLONE_FS|CLONE_FILES);
134 - if (cryptoproc < 0) {
135 - error = cryptoproc;
136 + crypto_task = NULL; /* to avoid race condition where proc runs first */
137 + t = kthread_create(crypto_proc, NULL, "ocf-crypto");
139 + error = PTR_ERR(t);
140 printk("crypto: crypto_init cannot start crypto thread; error %d",
144 + wake_up_process(t);
147 - cryptoretproc = 0; /* to avoid race condition where proc runs first */
148 - cryptoretproc = kernel_thread(crypto_ret_proc, NULL, CLONE_FS|CLONE_FILES);
149 - if (cryptoretproc < 0) {
150 - error = cryptoretproc;
151 + cryptoret_task = NULL; /* to avoid race condition where proc runs first */
152 + t = kthread_create(crypto_ret_proc, NULL, "ocf-cryptoret");
154 + error = PTR_ERR(t);
155 printk("crypto: crypto_init cannot start cryptoret thread; error %d",
159 + wake_up_process(t);
160 + cryptoret_task = t;
164 @@ -1671,7 +1677,7 @@ bad:
169 + struct task_struct *t;
170 unsigned long d_flags;
172 dprintk("%s()\n", __FUNCTION__);
173 @@ -1681,18 +1687,18 @@ crypto_exit(void)
176 CRYPTO_DRIVER_LOCK();
178 - cryptoproc = (pid_t) -1;
179 - kill_proc(p, SIGTERM, 1);
181 + crypto_task = NULL;
182 + send_sig(SIGTERM, t, 1);
183 wake_up_interruptible(&cryptoproc_wait);
184 CRYPTO_DRIVER_UNLOCK();
186 wait_for_completion(&cryptoproc_exited);
188 CRYPTO_DRIVER_LOCK();
190 - cryptoretproc = (pid_t) -1;
191 - kill_proc(p, SIGTERM, 1);
192 + t = cryptoret_task;
193 + cryptoret_task = NULL;
194 + send_sig(SIGTERM, t, 1);
195 wake_up_interruptible(&cryptoretproc_wait);
196 CRYPTO_DRIVER_UNLOCK();