hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/s390/crypto/zcrypt_api.c
....@@ -1,8 +1,6 @@
11 // SPDX-License-Identifier: GPL-2.0+
22 /*
3
- * zcrypt 2.1.0
4
- *
5
- * Copyright IBM Corp. 2001, 2012
3
+ * Copyright IBM Corp. 2001, 2018
64 * Author(s): Robert Burroughs
75 * Eric Rossman (edrossma@us.ibm.com)
86 * Cornelia Huck <cornelia.huck@de.ibm.com>
....@@ -11,6 +9,7 @@
119 * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
1210 * Ralph Wuerthner <rwuerthn@de.ibm.com>
1311 * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
12
+ * Multiple device nodes: Harald Freudenberger <freude@linux.ibm.com>
1413 */
1514
1615 #include <linux/module.h>
....@@ -24,6 +23,9 @@
2423 #include <linux/uaccess.h>
2524 #include <linux/hw_random.h>
2625 #include <linux/debugfs.h>
26
+#include <linux/cdev.h>
27
+#include <linux/ctype.h>
28
+#include <linux/capability.h>
2729 #include <asm/debug.h>
2830
2931 #define CREATE_TRACE_POINTS
....@@ -34,6 +36,8 @@
3436
3537 #include "zcrypt_msgtype6.h"
3638 #include "zcrypt_msgtype50.h"
39
+#include "zcrypt_ccamisc.h"
40
+#include "zcrypt_ep11misc.h"
3741
3842 /*
3943 * Module description.
....@@ -108,6 +112,358 @@
108112 }
109113 EXPORT_SYMBOL(zcrypt_msgtype);
110114
115
+/*
116
+ * Multi device nodes extension functions.
117
+ */
118
+
119
+#ifdef CONFIG_ZCRYPT_MULTIDEVNODES
120
+
121
+struct zcdn_device;
122
+
123
+static struct class *zcrypt_class;
124
+static dev_t zcrypt_devt;
125
+static struct cdev zcrypt_cdev;
126
+
127
+struct zcdn_device {
128
+ struct device device;
129
+ struct ap_perms perms;
130
+};
131
+
132
+#define to_zcdn_dev(x) container_of((x), struct zcdn_device, device)
133
+
134
+#define ZCDN_MAX_NAME 32
135
+
136
+static int zcdn_create(const char *name);
137
+static int zcdn_destroy(const char *name);
138
+
139
+/*
140
+ * Find zcdn device by name.
141
+ * Returns reference to the zcdn device which needs to be released
142
+ * with put_device() after use.
143
+ */
144
+static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
145
+{
146
+ struct device *dev = class_find_device_by_name(zcrypt_class, name);
147
+
148
+ return dev ? to_zcdn_dev(dev) : NULL;
149
+}
150
+
151
+/*
152
+ * Find zcdn device by devt value.
153
+ * Returns reference to the zcdn device which needs to be released
154
+ * with put_device() after use.
155
+ */
156
+static inline struct zcdn_device *find_zcdndev_by_devt(dev_t devt)
157
+{
158
+ struct device *dev = class_find_device_by_devt(zcrypt_class, devt);
159
+
160
+ return dev ? to_zcdn_dev(dev) : NULL;
161
+}
162
+
163
+static ssize_t ioctlmask_show(struct device *dev,
164
+ struct device_attribute *attr,
165
+ char *buf)
166
+{
167
+ int i, rc;
168
+ struct zcdn_device *zcdndev = to_zcdn_dev(dev);
169
+
170
+ if (mutex_lock_interruptible(&ap_perms_mutex))
171
+ return -ERESTARTSYS;
172
+
173
+ buf[0] = '0';
174
+ buf[1] = 'x';
175
+ for (i = 0; i < sizeof(zcdndev->perms.ioctlm) / sizeof(long); i++)
176
+ snprintf(buf + 2 + 2 * i * sizeof(long),
177
+ PAGE_SIZE - 2 - 2 * i * sizeof(long),
178
+ "%016lx", zcdndev->perms.ioctlm[i]);
179
+ buf[2 + 2 * i * sizeof(long)] = '\n';
180
+ buf[2 + 2 * i * sizeof(long) + 1] = '\0';
181
+ rc = 2 + 2 * i * sizeof(long) + 1;
182
+
183
+ mutex_unlock(&ap_perms_mutex);
184
+
185
+ return rc;
186
+}
187
+
188
+static ssize_t ioctlmask_store(struct device *dev,
189
+ struct device_attribute *attr,
190
+ const char *buf, size_t count)
191
+{
192
+ int rc;
193
+ struct zcdn_device *zcdndev = to_zcdn_dev(dev);
194
+
195
+ rc = ap_parse_mask_str(buf, zcdndev->perms.ioctlm,
196
+ AP_IOCTLS, &ap_perms_mutex);
197
+ if (rc)
198
+ return rc;
199
+
200
+ return count;
201
+}
202
+
203
+static DEVICE_ATTR_RW(ioctlmask);
204
+
205
+static ssize_t apmask_show(struct device *dev,
206
+ struct device_attribute *attr,
207
+ char *buf)
208
+{
209
+ int i, rc;
210
+ struct zcdn_device *zcdndev = to_zcdn_dev(dev);
211
+
212
+ if (mutex_lock_interruptible(&ap_perms_mutex))
213
+ return -ERESTARTSYS;
214
+
215
+ buf[0] = '0';
216
+ buf[1] = 'x';
217
+ for (i = 0; i < sizeof(zcdndev->perms.apm) / sizeof(long); i++)
218
+ snprintf(buf + 2 + 2 * i * sizeof(long),
219
+ PAGE_SIZE - 2 - 2 * i * sizeof(long),
220
+ "%016lx", zcdndev->perms.apm[i]);
221
+ buf[2 + 2 * i * sizeof(long)] = '\n';
222
+ buf[2 + 2 * i * sizeof(long) + 1] = '\0';
223
+ rc = 2 + 2 * i * sizeof(long) + 1;
224
+
225
+ mutex_unlock(&ap_perms_mutex);
226
+
227
+ return rc;
228
+}
229
+
230
+static ssize_t apmask_store(struct device *dev,
231
+ struct device_attribute *attr,
232
+ const char *buf, size_t count)
233
+{
234
+ int rc;
235
+ struct zcdn_device *zcdndev = to_zcdn_dev(dev);
236
+
237
+ rc = ap_parse_mask_str(buf, zcdndev->perms.apm,
238
+ AP_DEVICES, &ap_perms_mutex);
239
+ if (rc)
240
+ return rc;
241
+
242
+ return count;
243
+}
244
+
245
+static DEVICE_ATTR_RW(apmask);
246
+
247
+static ssize_t aqmask_show(struct device *dev,
248
+ struct device_attribute *attr,
249
+ char *buf)
250
+{
251
+ int i, rc;
252
+ struct zcdn_device *zcdndev = to_zcdn_dev(dev);
253
+
254
+ if (mutex_lock_interruptible(&ap_perms_mutex))
255
+ return -ERESTARTSYS;
256
+
257
+ buf[0] = '0';
258
+ buf[1] = 'x';
259
+ for (i = 0; i < sizeof(zcdndev->perms.aqm) / sizeof(long); i++)
260
+ snprintf(buf + 2 + 2 * i * sizeof(long),
261
+ PAGE_SIZE - 2 - 2 * i * sizeof(long),
262
+ "%016lx", zcdndev->perms.aqm[i]);
263
+ buf[2 + 2 * i * sizeof(long)] = '\n';
264
+ buf[2 + 2 * i * sizeof(long) + 1] = '\0';
265
+ rc = 2 + 2 * i * sizeof(long) + 1;
266
+
267
+ mutex_unlock(&ap_perms_mutex);
268
+
269
+ return rc;
270
+}
271
+
272
+static ssize_t aqmask_store(struct device *dev,
273
+ struct device_attribute *attr,
274
+ const char *buf, size_t count)
275
+{
276
+ int rc;
277
+ struct zcdn_device *zcdndev = to_zcdn_dev(dev);
278
+
279
+ rc = ap_parse_mask_str(buf, zcdndev->perms.aqm,
280
+ AP_DOMAINS, &ap_perms_mutex);
281
+ if (rc)
282
+ return rc;
283
+
284
+ return count;
285
+}
286
+
287
+static DEVICE_ATTR_RW(aqmask);
288
+
289
+static struct attribute *zcdn_dev_attrs[] = {
290
+ &dev_attr_ioctlmask.attr,
291
+ &dev_attr_apmask.attr,
292
+ &dev_attr_aqmask.attr,
293
+ NULL
294
+};
295
+
296
+static struct attribute_group zcdn_dev_attr_group = {
297
+ .attrs = zcdn_dev_attrs
298
+};
299
+
300
+static const struct attribute_group *zcdn_dev_attr_groups[] = {
301
+ &zcdn_dev_attr_group,
302
+ NULL
303
+};
304
+
305
+static ssize_t zcdn_create_store(struct class *class,
306
+ struct class_attribute *attr,
307
+ const char *buf, size_t count)
308
+{
309
+ int rc;
310
+ char name[ZCDN_MAX_NAME];
311
+
312
+ strncpy(name, skip_spaces(buf), sizeof(name));
313
+ name[sizeof(name) - 1] = '\0';
314
+
315
+ rc = zcdn_create(strim(name));
316
+
317
+ return rc ? rc : count;
318
+}
319
+
320
+static const struct class_attribute class_attr_zcdn_create =
321
+ __ATTR(create, 0600, NULL, zcdn_create_store);
322
+
323
+static ssize_t zcdn_destroy_store(struct class *class,
324
+ struct class_attribute *attr,
325
+ const char *buf, size_t count)
326
+{
327
+ int rc;
328
+ char name[ZCDN_MAX_NAME];
329
+
330
+ strncpy(name, skip_spaces(buf), sizeof(name));
331
+ name[sizeof(name) - 1] = '\0';
332
+
333
+ rc = zcdn_destroy(strim(name));
334
+
335
+ return rc ? rc : count;
336
+}
337
+
338
+static const struct class_attribute class_attr_zcdn_destroy =
339
+ __ATTR(destroy, 0600, NULL, zcdn_destroy_store);
340
+
341
+static void zcdn_device_release(struct device *dev)
342
+{
343
+ struct zcdn_device *zcdndev = to_zcdn_dev(dev);
344
+
345
+ ZCRYPT_DBF(DBF_INFO, "releasing zcdn device %d:%d\n",
346
+ MAJOR(dev->devt), MINOR(dev->devt));
347
+
348
+ kfree(zcdndev);
349
+}
350
+
351
+static int zcdn_create(const char *name)
352
+{
353
+ dev_t devt;
354
+ int i, rc = 0;
355
+ char nodename[ZCDN_MAX_NAME];
356
+ struct zcdn_device *zcdndev;
357
+
358
+ if (mutex_lock_interruptible(&ap_perms_mutex))
359
+ return -ERESTARTSYS;
360
+
361
+ /* check if device node with this name already exists */
362
+ if (name[0]) {
363
+ zcdndev = find_zcdndev_by_name(name);
364
+ if (zcdndev) {
365
+ put_device(&zcdndev->device);
366
+ rc = -EEXIST;
367
+ goto unlockout;
368
+ }
369
+ }
370
+
371
+ /* find an unused minor number */
372
+ for (i = 0; i < ZCRYPT_MAX_MINOR_NODES; i++) {
373
+ devt = MKDEV(MAJOR(zcrypt_devt), MINOR(zcrypt_devt) + i);
374
+ zcdndev = find_zcdndev_by_devt(devt);
375
+ if (zcdndev)
376
+ put_device(&zcdndev->device);
377
+ else
378
+ break;
379
+ }
380
+ if (i == ZCRYPT_MAX_MINOR_NODES) {
381
+ rc = -ENOSPC;
382
+ goto unlockout;
383
+ }
384
+
385
+ /* alloc and prepare a new zcdn device */
386
+ zcdndev = kzalloc(sizeof(*zcdndev), GFP_KERNEL);
387
+ if (!zcdndev) {
388
+ rc = -ENOMEM;
389
+ goto unlockout;
390
+ }
391
+ zcdndev->device.release = zcdn_device_release;
392
+ zcdndev->device.class = zcrypt_class;
393
+ zcdndev->device.devt = devt;
394
+ zcdndev->device.groups = zcdn_dev_attr_groups;
395
+ if (name[0])
396
+ strncpy(nodename, name, sizeof(nodename));
397
+ else
398
+ snprintf(nodename, sizeof(nodename),
399
+ ZCRYPT_NAME "_%d", (int) MINOR(devt));
400
+ nodename[sizeof(nodename)-1] = '\0';
401
+ if (dev_set_name(&zcdndev->device, nodename)) {
402
+ kfree(zcdndev);
403
+ rc = -EINVAL;
404
+ goto unlockout;
405
+ }
406
+ rc = device_register(&zcdndev->device);
407
+ if (rc) {
408
+ put_device(&zcdndev->device);
409
+ goto unlockout;
410
+ }
411
+
412
+ ZCRYPT_DBF(DBF_INFO, "created zcdn device %d:%d\n",
413
+ MAJOR(devt), MINOR(devt));
414
+
415
+unlockout:
416
+ mutex_unlock(&ap_perms_mutex);
417
+ return rc;
418
+}
419
+
420
+static int zcdn_destroy(const char *name)
421
+{
422
+ int rc = 0;
423
+ struct zcdn_device *zcdndev;
424
+
425
+ if (mutex_lock_interruptible(&ap_perms_mutex))
426
+ return -ERESTARTSYS;
427
+
428
+ /* try to find this zcdn device */
429
+ zcdndev = find_zcdndev_by_name(name);
430
+ if (!zcdndev) {
431
+ rc = -ENOENT;
432
+ goto unlockout;
433
+ }
434
+
435
+ /*
436
+ * The zcdn device is not hard destroyed. It is subject to
437
+ * reference counting and thus just needs to be unregistered.
438
+ */
439
+ put_device(&zcdndev->device);
440
+ device_unregister(&zcdndev->device);
441
+
442
+unlockout:
443
+ mutex_unlock(&ap_perms_mutex);
444
+ return rc;
445
+}
446
+
447
+static void zcdn_destroy_all(void)
448
+{
449
+ int i;
450
+ dev_t devt;
451
+ struct zcdn_device *zcdndev;
452
+
453
+ mutex_lock(&ap_perms_mutex);
454
+ for (i = 0; i < ZCRYPT_MAX_MINOR_NODES; i++) {
455
+ devt = MKDEV(MAJOR(zcrypt_devt), MINOR(zcrypt_devt) + i);
456
+ zcdndev = find_zcdndev_by_devt(devt);
457
+ if (zcdndev) {
458
+ put_device(&zcdndev->device);
459
+ device_unregister(&zcdndev->device);
460
+ }
461
+ }
462
+ mutex_unlock(&ap_perms_mutex);
463
+}
464
+
465
+#endif
466
+
111467 /**
112468 * zcrypt_read (): Not supported beyond zcrypt 1.3.1.
113469 *
....@@ -137,8 +493,25 @@
137493 */
138494 static int zcrypt_open(struct inode *inode, struct file *filp)
139495 {
496
+ struct ap_perms *perms = &ap_perms;
497
+
498
+#ifdef CONFIG_ZCRYPT_MULTIDEVNODES
499
+ if (filp->f_inode->i_cdev == &zcrypt_cdev) {
500
+ struct zcdn_device *zcdndev;
501
+
502
+ if (mutex_lock_interruptible(&ap_perms_mutex))
503
+ return -ERESTARTSYS;
504
+ zcdndev = find_zcdndev_by_devt(filp->f_inode->i_rdev);
505
+ /* find returns a reference, no get_device() needed */
506
+ mutex_unlock(&ap_perms_mutex);
507
+ if (zcdndev)
508
+ perms = &zcdndev->perms;
509
+ }
510
+#endif
511
+ filp->private_data = (void *) perms;
512
+
140513 atomic_inc(&zcrypt_open_count);
141
- return nonseekable_open(inode, filp);
514
+ return stream_open(inode, filp);
142515 }
143516
144517 /**
....@@ -148,12 +521,57 @@
148521 */
149522 static int zcrypt_release(struct inode *inode, struct file *filp)
150523 {
524
+#ifdef CONFIG_ZCRYPT_MULTIDEVNODES
525
+ if (filp->f_inode->i_cdev == &zcrypt_cdev) {
526
+ struct zcdn_device *zcdndev;
527
+
528
+ mutex_lock(&ap_perms_mutex);
529
+ zcdndev = find_zcdndev_by_devt(filp->f_inode->i_rdev);
530
+ mutex_unlock(&ap_perms_mutex);
531
+ if (zcdndev) {
532
+ /* 2 puts here: one for find, one for open */
533
+ put_device(&zcdndev->device);
534
+ put_device(&zcdndev->device);
535
+ }
536
+ }
537
+#endif
538
+
151539 atomic_dec(&zcrypt_open_count);
152540 return 0;
153541 }
154542
543
+static inline int zcrypt_check_ioctl(struct ap_perms *perms,
544
+ unsigned int cmd)
545
+{
546
+ int rc = -EPERM;
547
+ int ioctlnr = (cmd & _IOC_NRMASK) >> _IOC_NRSHIFT;
548
+
549
+ if (ioctlnr > 0 && ioctlnr < AP_IOCTLS) {
550
+ if (test_bit_inv(ioctlnr, perms->ioctlm))
551
+ rc = 0;
552
+ }
553
+
554
+ if (rc)
555
+ ZCRYPT_DBF(DBF_WARN,
556
+ "ioctl check failed: ioctlnr=0x%04x rc=%d\n",
557
+ ioctlnr, rc);
558
+
559
+ return rc;
560
+}
561
+
562
+static inline bool zcrypt_check_card(struct ap_perms *perms, int card)
563
+{
564
+ return test_bit_inv(card, perms->apm) ? true : false;
565
+}
566
+
567
+static inline bool zcrypt_check_queue(struct ap_perms *perms, int queue)
568
+{
569
+ return test_bit_inv(queue, perms->aqm) ? true : false;
570
+}
571
+
155572 static inline struct zcrypt_queue *zcrypt_pick_queue(struct zcrypt_card *zc,
156573 struct zcrypt_queue *zq,
574
+ struct module **pmod,
157575 unsigned int weight)
158576 {
159577 if (!zq || !try_module_get(zq->queue->ap_dev.drv->driver.owner))
....@@ -163,15 +581,15 @@
163581 atomic_add(weight, &zc->load);
164582 atomic_add(weight, &zq->load);
165583 zq->request_count++;
584
+ *pmod = zq->queue->ap_dev.drv->driver.owner;
166585 return zq;
167586 }
168587
169588 static inline void zcrypt_drop_queue(struct zcrypt_card *zc,
170589 struct zcrypt_queue *zq,
590
+ struct module *mod,
171591 unsigned int weight)
172592 {
173
- struct module *mod = zq->queue->ap_dev.drv->driver.owner;
174
-
175593 zq->request_count--;
176594 atomic_sub(weight, &zc->load);
177595 atomic_sub(weight, &zq->load);
....@@ -186,13 +604,13 @@
186604 unsigned int pref_weight)
187605 {
188606 if (!pref_zc)
189
- return false;
607
+ return true;
190608 weight += atomic_read(&zc->load);
191609 pref_weight += atomic_read(&pref_zc->load);
192610 if (weight == pref_weight)
193
- return atomic64_read(&zc->card->total_request_count) >
611
+ return atomic64_read(&zc->card->total_request_count) <
194612 atomic64_read(&pref_zc->card->total_request_count);
195
- return weight > pref_weight;
613
+ return weight < pref_weight;
196614 }
197615
198616 static inline bool zcrypt_queue_compare(struct zcrypt_queue *zq,
....@@ -201,27 +619,38 @@
201619 unsigned int pref_weight)
202620 {
203621 if (!pref_zq)
204
- return false;
622
+ return true;
205623 weight += atomic_read(&zq->load);
206624 pref_weight += atomic_read(&pref_zq->load);
207625 if (weight == pref_weight)
208
- return zq->queue->total_request_count >
626
+ return zq->queue->total_request_count <
209627 pref_zq->queue->total_request_count;
210
- return weight > pref_weight;
628
+ return weight < pref_weight;
211629 }
212630
213631 /*
214632 * zcrypt ioctls.
215633 */
216
-static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
634
+static long zcrypt_rsa_modexpo(struct ap_perms *perms,
635
+ struct zcrypt_track *tr,
636
+ struct ica_rsa_modexpo *mex)
217637 {
218638 struct zcrypt_card *zc, *pref_zc;
219639 struct zcrypt_queue *zq, *pref_zq;
220
- unsigned int weight, pref_weight;
640
+ struct ap_message ap_msg;
641
+ unsigned int wgt = 0, pref_wgt = 0;
221642 unsigned int func_code;
222
- int qid = 0, rc = -ENODEV;
643
+ int cpen, qpen, qid = 0, rc = -ENODEV;
644
+ struct module *mod;
223645
224646 trace_s390_zcrypt_req(mex, TP_ICARSAMODEXPO);
647
+
648
+ ap_init_message(&ap_msg);
649
+
650
+#ifdef CONFIG_ZCRYPT_DEBUG
651
+ if (tr && tr->fi.cmd)
652
+ ap_msg.fi.cmd = tr->fi.cmd;
653
+#endif
225654
226655 if (mex->outputdatalength < mex->inputdatalength) {
227656 func_code = 0;
....@@ -244,30 +673,47 @@
244673 pref_zq = NULL;
245674 spin_lock(&zcrypt_list_lock);
246675 for_each_zcrypt_card(zc) {
247
- /* Check for online accelarator and CCA cards */
248
- if (!zc->online || !(zc->card->functions & 0x18000000))
676
+ /* Check for useable accelarator or CCA card */
677
+ if (!zc->online || !zc->card->config ||
678
+ !(zc->card->functions & 0x18000000))
249679 continue;
250680 /* Check for size limits */
251681 if (zc->min_mod_size > mex->inputdatalength ||
252682 zc->max_mod_size < mex->inputdatalength)
253683 continue;
684
+ /* check if device node has admission for this card */
685
+ if (!zcrypt_check_card(perms, zc->card->id))
686
+ continue;
254687 /* get weight index of the card device */
255
- weight = zc->speed_rating[func_code];
256
- if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
688
+ wgt = zc->speed_rating[func_code];
689
+ /* penalty if this msg was previously sent via this card */
690
+ cpen = (tr && tr->again_counter && tr->last_qid &&
691
+ AP_QID_CARD(tr->last_qid) == zc->card->id) ?
692
+ TRACK_AGAIN_CARD_WEIGHT_PENALTY : 0;
693
+ if (!zcrypt_card_compare(zc, pref_zc, wgt + cpen, pref_wgt))
257694 continue;
258695 for_each_zcrypt_queue(zq, zc) {
259
- /* check if device is online and eligible */
260
- if (!zq->online || !zq->ops->rsa_modexpo)
696
+ /* check if device is useable and eligible */
697
+ if (!zq->online || !zq->ops->rsa_modexpo ||
698
+ !zq->queue->config)
261699 continue;
262
- if (zcrypt_queue_compare(zq, pref_zq,
263
- weight, pref_weight))
700
+ /* check if device node has admission for this queue */
701
+ if (!zcrypt_check_queue(perms,
702
+ AP_QID_QUEUE(zq->queue->qid)))
703
+ continue;
704
+ /* penalty if the msg was previously sent at this qid */
705
+ qpen = (tr && tr->again_counter && tr->last_qid &&
706
+ tr->last_qid == zq->queue->qid) ?
707
+ TRACK_AGAIN_QUEUE_WEIGHT_PENALTY : 0;
708
+ if (!zcrypt_queue_compare(zq, pref_zq,
709
+ wgt + cpen + qpen, pref_wgt))
264710 continue;
265711 pref_zc = zc;
266712 pref_zq = zq;
267
- pref_weight = weight;
713
+ pref_wgt = wgt + cpen + qpen;
268714 }
269715 }
270
- pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight);
716
+ pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt);
271717 spin_unlock(&zcrypt_list_lock);
272718
273719 if (!pref_zq) {
....@@ -276,27 +722,43 @@
276722 }
277723
278724 qid = pref_zq->queue->qid;
279
- rc = pref_zq->ops->rsa_modexpo(pref_zq, mex);
725
+ rc = pref_zq->ops->rsa_modexpo(pref_zq, mex, &ap_msg);
280726
281727 spin_lock(&zcrypt_list_lock);
282
- zcrypt_drop_queue(pref_zc, pref_zq, weight);
728
+ zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
283729 spin_unlock(&zcrypt_list_lock);
284730
285731 out:
732
+ ap_release_message(&ap_msg);
733
+ if (tr) {
734
+ tr->last_rc = rc;
735
+ tr->last_qid = qid;
736
+ }
286737 trace_s390_zcrypt_rep(mex, func_code, rc,
287738 AP_QID_CARD(qid), AP_QID_QUEUE(qid));
288739 return rc;
289740 }
290741
291
-static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
742
+static long zcrypt_rsa_crt(struct ap_perms *perms,
743
+ struct zcrypt_track *tr,
744
+ struct ica_rsa_modexpo_crt *crt)
292745 {
293746 struct zcrypt_card *zc, *pref_zc;
294747 struct zcrypt_queue *zq, *pref_zq;
295
- unsigned int weight, pref_weight;
748
+ struct ap_message ap_msg;
749
+ unsigned int wgt = 0, pref_wgt = 0;
296750 unsigned int func_code;
297
- int qid = 0, rc = -ENODEV;
751
+ int cpen, qpen, qid = 0, rc = -ENODEV;
752
+ struct module *mod;
298753
299754 trace_s390_zcrypt_req(crt, TP_ICARSACRT);
755
+
756
+ ap_init_message(&ap_msg);
757
+
758
+#ifdef CONFIG_ZCRYPT_DEBUG
759
+ if (tr && tr->fi.cmd)
760
+ ap_msg.fi.cmd = tr->fi.cmd;
761
+#endif
300762
301763 if (crt->outputdatalength < crt->inputdatalength) {
302764 func_code = 0;
....@@ -319,30 +781,47 @@
319781 pref_zq = NULL;
320782 spin_lock(&zcrypt_list_lock);
321783 for_each_zcrypt_card(zc) {
322
- /* Check for online accelarator and CCA cards */
323
- if (!zc->online || !(zc->card->functions & 0x18000000))
784
+ /* Check for useable accelarator or CCA card */
785
+ if (!zc->online || !zc->card->config ||
786
+ !(zc->card->functions & 0x18000000))
324787 continue;
325788 /* Check for size limits */
326789 if (zc->min_mod_size > crt->inputdatalength ||
327790 zc->max_mod_size < crt->inputdatalength)
328791 continue;
792
+ /* check if device node has admission for this card */
793
+ if (!zcrypt_check_card(perms, zc->card->id))
794
+ continue;
329795 /* get weight index of the card device */
330
- weight = zc->speed_rating[func_code];
331
- if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
796
+ wgt = zc->speed_rating[func_code];
797
+ /* penalty if this msg was previously sent via this card */
798
+ cpen = (tr && tr->again_counter && tr->last_qid &&
799
+ AP_QID_CARD(tr->last_qid) == zc->card->id) ?
800
+ TRACK_AGAIN_CARD_WEIGHT_PENALTY : 0;
801
+ if (!zcrypt_card_compare(zc, pref_zc, wgt + cpen, pref_wgt))
332802 continue;
333803 for_each_zcrypt_queue(zq, zc) {
334
- /* check if device is online and eligible */
335
- if (!zq->online || !zq->ops->rsa_modexpo_crt)
804
+ /* check if device is useable and eligible */
805
+ if (!zq->online || !zq->ops->rsa_modexpo_crt ||
806
+ !zq->queue->config)
336807 continue;
337
- if (zcrypt_queue_compare(zq, pref_zq,
338
- weight, pref_weight))
808
+ /* check if device node has admission for this queue */
809
+ if (!zcrypt_check_queue(perms,
810
+ AP_QID_QUEUE(zq->queue->qid)))
811
+ continue;
812
+ /* penalty if the msg was previously sent at this qid */
813
+ qpen = (tr && tr->again_counter && tr->last_qid &&
814
+ tr->last_qid == zq->queue->qid) ?
815
+ TRACK_AGAIN_QUEUE_WEIGHT_PENALTY : 0;
816
+ if (!zcrypt_queue_compare(zq, pref_zq,
817
+ wgt + cpen + qpen, pref_wgt))
339818 continue;
340819 pref_zc = zc;
341820 pref_zq = zq;
342
- pref_weight = weight;
821
+ pref_wgt = wgt + cpen + qpen;
343822 }
344823 }
345
- pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight);
824
+ pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt);
346825 spin_unlock(&zcrypt_list_lock);
347826
348827 if (!pref_zq) {
....@@ -351,66 +830,114 @@
351830 }
352831
353832 qid = pref_zq->queue->qid;
354
- rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt);
833
+ rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt, &ap_msg);
355834
356835 spin_lock(&zcrypt_list_lock);
357
- zcrypt_drop_queue(pref_zc, pref_zq, weight);
836
+ zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
358837 spin_unlock(&zcrypt_list_lock);
359838
360839 out:
840
+ ap_release_message(&ap_msg);
841
+ if (tr) {
842
+ tr->last_rc = rc;
843
+ tr->last_qid = qid;
844
+ }
361845 trace_s390_zcrypt_rep(crt, func_code, rc,
362846 AP_QID_CARD(qid), AP_QID_QUEUE(qid));
363847 return rc;
364848 }
365849
366
-long zcrypt_send_cprb(struct ica_xcRB *xcRB)
850
+static long _zcrypt_send_cprb(bool userspace, struct ap_perms *perms,
851
+ struct zcrypt_track *tr,
852
+ struct ica_xcRB *xcRB)
367853 {
368854 struct zcrypt_card *zc, *pref_zc;
369855 struct zcrypt_queue *zq, *pref_zq;
370856 struct ap_message ap_msg;
371
- unsigned int weight, pref_weight;
857
+ unsigned int wgt = 0, pref_wgt = 0;
372858 unsigned int func_code;
373
- unsigned short *domain;
374
- int qid = 0, rc = -ENODEV;
859
+ unsigned short *domain, tdom;
860
+ int cpen, qpen, qid = 0, rc = -ENODEV;
861
+ struct module *mod;
375862
376863 trace_s390_zcrypt_req(xcRB, TB_ZSECSENDCPRB);
377864
865
+ xcRB->status = 0;
378866 ap_init_message(&ap_msg);
379
- rc = get_cprb_fc(xcRB, &ap_msg, &func_code, &domain);
867
+
868
+#ifdef CONFIG_ZCRYPT_DEBUG
869
+ if (tr && tr->fi.cmd)
870
+ ap_msg.fi.cmd = tr->fi.cmd;
871
+ if (tr && tr->fi.action == AP_FI_ACTION_CCA_AGENT_FF) {
872
+ ZCRYPT_DBF_WARN("%s fi cmd 0x%04x: forcing invalid agent_ID 'FF'\n",
873
+ __func__, tr->fi.cmd);
874
+ xcRB->agent_ID = 0x4646;
875
+ }
876
+#endif
877
+
878
+ rc = get_cprb_fc(userspace, xcRB, &ap_msg, &func_code, &domain);
380879 if (rc)
381880 goto out;
881
+
882
+ /*
883
+ * If a valid target domain is set and this domain is NOT a usage
884
+ * domain but a control only domain, use the default domain as target.
885
+ */
886
+ tdom = *domain;
887
+ if (tdom < AP_DOMAINS &&
888
+ !ap_test_config_usage_domain(tdom) &&
889
+ ap_test_config_ctrl_domain(tdom) &&
890
+ ap_domain_index >= 0)
891
+ tdom = ap_domain_index;
382892
383893 pref_zc = NULL;
384894 pref_zq = NULL;
385895 spin_lock(&zcrypt_list_lock);
386896 for_each_zcrypt_card(zc) {
387
- /* Check for online CCA cards */
388
- if (!zc->online || !(zc->card->functions & 0x10000000))
897
+ /* Check for useable CCA card */
898
+ if (!zc->online || !zc->card->config ||
899
+ !(zc->card->functions & 0x10000000))
389900 continue;
390901 /* Check for user selected CCA card */
391902 if (xcRB->user_defined != AUTOSELECT &&
392903 xcRB->user_defined != zc->card->id)
393904 continue;
905
+ /* check if device node has admission for this card */
906
+ if (!zcrypt_check_card(perms, zc->card->id))
907
+ continue;
394908 /* get weight index of the card device */
395
- weight = speed_idx_cca(func_code) * zc->speed_rating[SECKEY];
396
- if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
909
+ wgt = speed_idx_cca(func_code) * zc->speed_rating[SECKEY];
910
+ /* penalty if this msg was previously sent via this card */
911
+ cpen = (tr && tr->again_counter && tr->last_qid &&
912
+ AP_QID_CARD(tr->last_qid) == zc->card->id) ?
913
+ TRACK_AGAIN_CARD_WEIGHT_PENALTY : 0;
914
+ if (!zcrypt_card_compare(zc, pref_zc, wgt + cpen, pref_wgt))
397915 continue;
398916 for_each_zcrypt_queue(zq, zc) {
399
- /* check if device is online and eligible */
917
+ /* check for device useable and eligible */
400918 if (!zq->online ||
401919 !zq->ops->send_cprb ||
402
- ((*domain != (unsigned short) AUTOSELECT) &&
403
- (*domain != AP_QID_QUEUE(zq->queue->qid))))
920
+ !zq->queue->config ||
921
+ (tdom != AUTOSEL_DOM &&
922
+ tdom != AP_QID_QUEUE(zq->queue->qid)))
404923 continue;
405
- if (zcrypt_queue_compare(zq, pref_zq,
406
- weight, pref_weight))
924
+ /* check if device node has admission for this queue */
925
+ if (!zcrypt_check_queue(perms,
926
+ AP_QID_QUEUE(zq->queue->qid)))
927
+ continue;
928
+ /* penalty if the msg was previously sent at this qid */
929
+ qpen = (tr && tr->again_counter && tr->last_qid &&
930
+ tr->last_qid == zq->queue->qid) ?
931
+ TRACK_AGAIN_QUEUE_WEIGHT_PENALTY : 0;
932
+ if (!zcrypt_queue_compare(zq, pref_zq,
933
+ wgt + cpen + qpen, pref_wgt))
407934 continue;
408935 pref_zc = zc;
409936 pref_zq = zq;
410
- pref_weight = weight;
937
+ pref_wgt = wgt + cpen + qpen;
411938 }
412939 }
413
- pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight);
940
+ pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt);
414941 spin_unlock(&zcrypt_list_lock);
415942
416943 if (!pref_zq) {
....@@ -420,20 +947,37 @@
420947
421948 /* in case of auto select, provide the correct domain */
422949 qid = pref_zq->queue->qid;
423
- if (*domain == (unsigned short) AUTOSELECT)
950
+ if (*domain == AUTOSEL_DOM)
424951 *domain = AP_QID_QUEUE(qid);
425952
426
- rc = pref_zq->ops->send_cprb(pref_zq, xcRB, &ap_msg);
953
+#ifdef CONFIG_ZCRYPT_DEBUG
954
+ if (tr && tr->fi.action == AP_FI_ACTION_CCA_DOM_INVAL) {
955
+ ZCRYPT_DBF_WARN("%s fi cmd 0x%04x: forcing invalid domain\n",
956
+ __func__, tr->fi.cmd);
957
+ *domain = 99;
958
+ }
959
+#endif
960
+
961
+ rc = pref_zq->ops->send_cprb(userspace, pref_zq, xcRB, &ap_msg);
427962
428963 spin_lock(&zcrypt_list_lock);
429
- zcrypt_drop_queue(pref_zc, pref_zq, weight);
964
+ zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
430965 spin_unlock(&zcrypt_list_lock);
431966
432967 out:
433968 ap_release_message(&ap_msg);
969
+ if (tr) {
970
+ tr->last_rc = rc;
971
+ tr->last_qid = qid;
972
+ }
434973 trace_s390_zcrypt_rep(xcRB, func_code, rc,
435974 AP_QID_CARD(qid), AP_QID_QUEUE(qid));
436975 return rc;
976
+}
977
+
978
+long zcrypt_send_cprb(struct ica_xcRB *xcRB)
979
+{
980
+ return _zcrypt_send_cprb(false, &ap_perms, NULL, xcRB);
437981 }
438982 EXPORT_SYMBOL(zcrypt_send_cprb);
439983
....@@ -442,7 +986,7 @@
442986 struct ep11_target_dev *targets)
443987 {
444988 while (target_num-- > 0) {
445
- if (dev_id == targets->ap_id)
989
+ if (targets->ap_id == dev_id || targets->ap_id == AUTOSEL_AP)
446990 return true;
447991 targets++;
448992 }
....@@ -453,28 +997,39 @@
453997 unsigned short target_num,
454998 struct ep11_target_dev *targets)
455999 {
1000
+ int card = AP_QID_CARD(dev_qid), dom = AP_QID_QUEUE(dev_qid);
1001
+
4561002 while (target_num-- > 0) {
457
- if (AP_MKQID(targets->ap_id, targets->dom_id) == dev_qid)
1003
+ if ((targets->ap_id == card || targets->ap_id == AUTOSEL_AP) &&
1004
+ (targets->dom_id == dom || targets->dom_id == AUTOSEL_DOM))
4581005 return true;
4591006 targets++;
4601007 }
4611008 return false;
4621009 }
4631010
464
-static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
1011
+static long _zcrypt_send_ep11_cprb(bool userspace, struct ap_perms *perms,
1012
+ struct zcrypt_track *tr,
1013
+ struct ep11_urb *xcrb)
4651014 {
4661015 struct zcrypt_card *zc, *pref_zc;
4671016 struct zcrypt_queue *zq, *pref_zq;
4681017 struct ep11_target_dev *targets;
4691018 unsigned short target_num;
470
- unsigned int weight, pref_weight;
1019
+ unsigned int wgt = 0, pref_wgt = 0;
4711020 unsigned int func_code;
4721021 struct ap_message ap_msg;
473
- int qid = 0, rc = -ENODEV;
1022
+ int cpen, qpen, qid = 0, rc = -ENODEV;
1023
+ struct module *mod;
4741024
4751025 trace_s390_zcrypt_req(xcrb, TP_ZSENDEP11CPRB);
4761026
4771027 ap_init_message(&ap_msg);
1028
+
1029
+#ifdef CONFIG_ZCRYPT_DEBUG
1030
+ if (tr && tr->fi.cmd)
1031
+ ap_msg.fi.cmd = tr->fi.cmd;
1032
+#endif
4781033
4791034 target_num = (unsigned short) xcrb->targets_num;
4801035
....@@ -491,7 +1046,7 @@
4911046 }
4921047
4931048 uptr = (struct ep11_target_dev __force __user *) xcrb->targets;
494
- if (copy_from_user(targets, uptr,
1049
+ if (z_copy_from_user(userspace, targets, uptr,
4951050 target_num * sizeof(*targets))) {
4961051 func_code = 0;
4971052 rc = -EFAULT;
....@@ -499,7 +1054,7 @@
4991054 }
5001055 }
5011056
502
- rc = get_ep11cprb_fc(xcrb, &ap_msg, &func_code);
1057
+ rc = get_ep11cprb_fc(userspace, xcrb, &ap_msg, &func_code);
5031058 if (rc)
5041059 goto out_free;
5051060
....@@ -507,34 +1062,51 @@
5071062 pref_zq = NULL;
5081063 spin_lock(&zcrypt_list_lock);
5091064 for_each_zcrypt_card(zc) {
510
- /* Check for online EP11 cards */
511
- if (!zc->online || !(zc->card->functions & 0x04000000))
1065
+ /* Check for useable EP11 card */
1066
+ if (!zc->online || !zc->card->config ||
1067
+ !(zc->card->functions & 0x04000000))
5121068 continue;
5131069 /* Check for user selected EP11 card */
5141070 if (targets &&
5151071 !is_desired_ep11_card(zc->card->id, target_num, targets))
5161072 continue;
1073
+ /* check if device node has admission for this card */
1074
+ if (!zcrypt_check_card(perms, zc->card->id))
1075
+ continue;
5171076 /* get weight index of the card device */
518
- weight = speed_idx_ep11(func_code) * zc->speed_rating[SECKEY];
519
- if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
1077
+ wgt = speed_idx_ep11(func_code) * zc->speed_rating[SECKEY];
1078
+ /* penalty if this msg was previously sent via this card */
1079
+ cpen = (tr && tr->again_counter && tr->last_qid &&
1080
+ AP_QID_CARD(tr->last_qid) == zc->card->id) ?
1081
+ TRACK_AGAIN_CARD_WEIGHT_PENALTY : 0;
1082
+ if (!zcrypt_card_compare(zc, pref_zc, wgt + cpen, pref_wgt))
5201083 continue;
5211084 for_each_zcrypt_queue(zq, zc) {
522
- /* check if device is online and eligible */
1085
+ /* check if device is useable and eligible */
5231086 if (!zq->online ||
5241087 !zq->ops->send_ep11_cprb ||
1088
+ !zq->queue->config ||
5251089 (targets &&
5261090 !is_desired_ep11_queue(zq->queue->qid,
5271091 target_num, targets)))
5281092 continue;
529
- if (zcrypt_queue_compare(zq, pref_zq,
530
- weight, pref_weight))
1093
+ /* check if device node has admission for this queue */
1094
+ if (!zcrypt_check_queue(perms,
1095
+ AP_QID_QUEUE(zq->queue->qid)))
1096
+ continue;
1097
+ /* penalty if the msg was previously sent at this qid */
1098
+ qpen = (tr && tr->again_counter && tr->last_qid &&
1099
+ tr->last_qid == zq->queue->qid) ?
1100
+ TRACK_AGAIN_QUEUE_WEIGHT_PENALTY : 0;
1101
+ if (!zcrypt_queue_compare(zq, pref_zq,
1102
+ wgt + cpen + qpen, pref_wgt))
5311103 continue;
5321104 pref_zc = zc;
5331105 pref_zq = zq;
534
- pref_weight = weight;
1106
+ pref_wgt = wgt + cpen + qpen;
5351107 }
5361108 }
537
- pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight);
1109
+ pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt);
5381110 spin_unlock(&zcrypt_list_lock);
5391111
5401112 if (!pref_zq) {
....@@ -543,30 +1115,41 @@
5431115 }
5441116
5451117 qid = pref_zq->queue->qid;
546
- rc = pref_zq->ops->send_ep11_cprb(pref_zq, xcrb, &ap_msg);
1118
+ rc = pref_zq->ops->send_ep11_cprb(userspace, pref_zq, xcrb, &ap_msg);
5471119
5481120 spin_lock(&zcrypt_list_lock);
549
- zcrypt_drop_queue(pref_zc, pref_zq, weight);
1121
+ zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
5501122 spin_unlock(&zcrypt_list_lock);
5511123
5521124 out_free:
5531125 kfree(targets);
5541126 out:
5551127 ap_release_message(&ap_msg);
1128
+ if (tr) {
1129
+ tr->last_rc = rc;
1130
+ tr->last_qid = qid;
1131
+ }
5561132 trace_s390_zcrypt_rep(xcrb, func_code, rc,
5571133 AP_QID_CARD(qid), AP_QID_QUEUE(qid));
5581134 return rc;
5591135 }
5601136
1137
+long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
1138
+{
1139
+ return _zcrypt_send_ep11_cprb(false, &ap_perms, NULL, xcrb);
1140
+}
1141
+EXPORT_SYMBOL(zcrypt_send_ep11_cprb);
1142
+
5611143 static long zcrypt_rng(char *buffer)
5621144 {
5631145 struct zcrypt_card *zc, *pref_zc;
5641146 struct zcrypt_queue *zq, *pref_zq;
565
- unsigned int weight, pref_weight;
1147
+ unsigned int wgt = 0, pref_wgt = 0;
5661148 unsigned int func_code;
5671149 struct ap_message ap_msg;
5681150 unsigned int domain;
5691151 int qid = 0, rc = -ENODEV;
1152
+ struct module *mod;
5701153
5711154 trace_s390_zcrypt_req(buffer, TP_HWRNGCPRB);
5721155
....@@ -579,26 +1162,27 @@
5791162 pref_zq = NULL;
5801163 spin_lock(&zcrypt_list_lock);
5811164 for_each_zcrypt_card(zc) {
582
- /* Check for online CCA cards */
583
- if (!zc->online || !(zc->card->functions & 0x10000000))
1165
+ /* Check for useable CCA card */
1166
+ if (!zc->online || !zc->card->config ||
1167
+ !(zc->card->functions & 0x10000000))
5841168 continue;
5851169 /* get weight index of the card device */
586
- weight = zc->speed_rating[func_code];
587
- if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
1170
+ wgt = zc->speed_rating[func_code];
1171
+ if (!zcrypt_card_compare(zc, pref_zc, wgt, pref_wgt))
5881172 continue;
5891173 for_each_zcrypt_queue(zq, zc) {
590
- /* check if device is online and eligible */
591
- if (!zq->online || !zq->ops->rng)
1174
+ /* check if device is useable and eligible */
1175
+ if (!zq->online || !zq->ops->rng ||
1176
+ !zq->queue->config)
5921177 continue;
593
- if (zcrypt_queue_compare(zq, pref_zq,
594
- weight, pref_weight))
1178
+ if (!zcrypt_queue_compare(zq, pref_zq, wgt, pref_wgt))
5951179 continue;
5961180 pref_zc = zc;
5971181 pref_zq = zq;
598
- pref_weight = weight;
1182
+ pref_wgt = wgt;
5991183 }
6001184 }
601
- pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight);
1185
+ pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt);
6021186 spin_unlock(&zcrypt_list_lock);
6031187
6041188 if (!pref_zq) {
....@@ -610,7 +1194,7 @@
6101194 rc = pref_zq->ops->rng(pref_zq, buffer, &ap_msg);
6111195
6121196 spin_lock(&zcrypt_list_lock);
613
- zcrypt_drop_queue(pref_zc, pref_zq, weight);
1197
+ zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
6141198 spin_unlock(&zcrypt_list_lock);
6151199
6161200 out:
....@@ -672,6 +1256,34 @@
6721256 spin_unlock(&zcrypt_list_lock);
6731257 }
6741258 EXPORT_SYMBOL(zcrypt_device_status_mask_ext);
1259
+
1260
+int zcrypt_device_status_ext(int card, int queue,
1261
+ struct zcrypt_device_status_ext *devstat)
1262
+{
1263
+ struct zcrypt_card *zc;
1264
+ struct zcrypt_queue *zq;
1265
+
1266
+ memset(devstat, 0, sizeof(*devstat));
1267
+
1268
+ spin_lock(&zcrypt_list_lock);
1269
+ for_each_zcrypt_card(zc) {
1270
+ for_each_zcrypt_queue(zq, zc) {
1271
+ if (card == AP_QID_CARD(zq->queue->qid) &&
1272
+ queue == AP_QID_QUEUE(zq->queue->qid)) {
1273
+ devstat->hwtype = zc->card->ap_dev.device_type;
1274
+ devstat->functions = zc->card->functions >> 26;
1275
+ devstat->qid = zq->queue->qid;
1276
+ devstat->online = zq->online ? 0x01 : 0x00;
1277
+ spin_unlock(&zcrypt_list_lock);
1278
+ return 0;
1279
+ }
1280
+ }
1281
+ }
1282
+ spin_unlock(&zcrypt_list_lock);
1283
+
1284
+ return -ENODEV;
1285
+}
1286
+EXPORT_SYMBOL(zcrypt_device_status_ext);
6751287
6761288 static void zcrypt_status_mask(char status[], size_t max_adapters)
6771289 {
....@@ -791,92 +1403,207 @@
7911403 return requestq_count;
7921404 }
7931405
1406
+static int icarsamodexpo_ioctl(struct ap_perms *perms, unsigned long arg)
1407
+{
1408
+ int rc;
1409
+ struct zcrypt_track tr;
1410
+ struct ica_rsa_modexpo mex;
1411
+ struct ica_rsa_modexpo __user *umex = (void __user *) arg;
1412
+
1413
+ memset(&tr, 0, sizeof(tr));
1414
+ if (copy_from_user(&mex, umex, sizeof(mex)))
1415
+ return -EFAULT;
1416
+
1417
+#ifdef CONFIG_ZCRYPT_DEBUG
1418
+ if (mex.inputdatalength & (1U << 31)) {
1419
+ if (!capable(CAP_SYS_ADMIN))
1420
+ return -EPERM;
1421
+ tr.fi.cmd = (u16)(mex.inputdatalength >> 16);
1422
+ }
1423
+ mex.inputdatalength &= 0x0000FFFF;
1424
+#endif
1425
+
1426
+ do {
1427
+ rc = zcrypt_rsa_modexpo(perms, &tr, &mex);
1428
+ if (rc == -EAGAIN)
1429
+ tr.again_counter++;
1430
+#ifdef CONFIG_ZCRYPT_DEBUG
1431
+ if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY))
1432
+ break;
1433
+#endif
1434
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1435
+ /* on failure: retry once again after a requested rescan */
1436
+ if ((rc == -ENODEV) && (zcrypt_process_rescan()))
1437
+ do {
1438
+ rc = zcrypt_rsa_modexpo(perms, &tr, &mex);
1439
+ if (rc == -EAGAIN)
1440
+ tr.again_counter++;
1441
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1442
+ if (rc == -EAGAIN && tr.again_counter >= TRACK_AGAIN_MAX)
1443
+ rc = -EIO;
1444
+ if (rc) {
1445
+ ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSAMODEXPO rc=%d\n", rc);
1446
+ return rc;
1447
+ }
1448
+ return put_user(mex.outputdatalength, &umex->outputdatalength);
1449
+}
1450
+
1451
+static int icarsacrt_ioctl(struct ap_perms *perms, unsigned long arg)
1452
+{
1453
+ int rc;
1454
+ struct zcrypt_track tr;
1455
+ struct ica_rsa_modexpo_crt crt;
1456
+ struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg;
1457
+
1458
+ memset(&tr, 0, sizeof(tr));
1459
+ if (copy_from_user(&crt, ucrt, sizeof(crt)))
1460
+ return -EFAULT;
1461
+
1462
+#ifdef CONFIG_ZCRYPT_DEBUG
1463
+ if (crt.inputdatalength & (1U << 31)) {
1464
+ if (!capable(CAP_SYS_ADMIN))
1465
+ return -EPERM;
1466
+ tr.fi.cmd = (u16)(crt.inputdatalength >> 16);
1467
+ }
1468
+ crt.inputdatalength &= 0x0000FFFF;
1469
+#endif
1470
+
1471
+ do {
1472
+ rc = zcrypt_rsa_crt(perms, &tr, &crt);
1473
+ if (rc == -EAGAIN)
1474
+ tr.again_counter++;
1475
+#ifdef CONFIG_ZCRYPT_DEBUG
1476
+ if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY))
1477
+ break;
1478
+#endif
1479
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1480
+ /* on failure: retry once again after a requested rescan */
1481
+ if ((rc == -ENODEV) && (zcrypt_process_rescan()))
1482
+ do {
1483
+ rc = zcrypt_rsa_crt(perms, &tr, &crt);
1484
+ if (rc == -EAGAIN)
1485
+ tr.again_counter++;
1486
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1487
+ if (rc == -EAGAIN && tr.again_counter >= TRACK_AGAIN_MAX)
1488
+ rc = -EIO;
1489
+ if (rc) {
1490
+ ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSACRT rc=%d\n", rc);
1491
+ return rc;
1492
+ }
1493
+ return put_user(crt.outputdatalength, &ucrt->outputdatalength);
1494
+}
1495
+
1496
+static int zsecsendcprb_ioctl(struct ap_perms *perms, unsigned long arg)
1497
+{
1498
+ int rc;
1499
+ struct ica_xcRB xcRB;
1500
+ struct zcrypt_track tr;
1501
+ struct ica_xcRB __user *uxcRB = (void __user *) arg;
1502
+
1503
+ memset(&tr, 0, sizeof(tr));
1504
+ if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB)))
1505
+ return -EFAULT;
1506
+
1507
+#ifdef CONFIG_ZCRYPT_DEBUG
1508
+ if (xcRB.status & (1U << 31)) {
1509
+ if (!capable(CAP_SYS_ADMIN))
1510
+ return -EPERM;
1511
+ tr.fi.cmd = (u16)(xcRB.status >> 16);
1512
+ }
1513
+ xcRB.status &= 0x0000FFFF;
1514
+#endif
1515
+
1516
+ do {
1517
+ rc = _zcrypt_send_cprb(true, perms, &tr, &xcRB);
1518
+ if (rc == -EAGAIN)
1519
+ tr.again_counter++;
1520
+#ifdef CONFIG_ZCRYPT_DEBUG
1521
+ if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY))
1522
+ break;
1523
+#endif
1524
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1525
+ /* on failure: retry once again after a requested rescan */
1526
+ if ((rc == -ENODEV) && (zcrypt_process_rescan()))
1527
+ do {
1528
+ rc = _zcrypt_send_cprb(true, perms, &tr, &xcRB);
1529
+ if (rc == -EAGAIN)
1530
+ tr.again_counter++;
1531
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1532
+ if (rc == -EAGAIN && tr.again_counter >= TRACK_AGAIN_MAX)
1533
+ rc = -EIO;
1534
+ if (rc)
1535
+ ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDCPRB rc=%d status=0x%x\n",
1536
+ rc, xcRB.status);
1537
+ if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB)))
1538
+ return -EFAULT;
1539
+ return rc;
1540
+}
1541
+
1542
+static int zsendep11cprb_ioctl(struct ap_perms *perms, unsigned long arg)
1543
+{
1544
+ int rc;
1545
+ struct ep11_urb xcrb;
1546
+ struct zcrypt_track tr;
1547
+ struct ep11_urb __user *uxcrb = (void __user *)arg;
1548
+
1549
+ memset(&tr, 0, sizeof(tr));
1550
+ if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb)))
1551
+ return -EFAULT;
1552
+
1553
+#ifdef CONFIG_ZCRYPT_DEBUG
1554
+ if (xcrb.req_len & (1ULL << 63)) {
1555
+ if (!capable(CAP_SYS_ADMIN))
1556
+ return -EPERM;
1557
+ tr.fi.cmd = (u16)(xcrb.req_len >> 48);
1558
+ }
1559
+ xcrb.req_len &= 0x0000FFFFFFFFFFFFULL;
1560
+#endif
1561
+
1562
+ do {
1563
+ rc = _zcrypt_send_ep11_cprb(true, perms, &tr, &xcrb);
1564
+ if (rc == -EAGAIN)
1565
+ tr.again_counter++;
1566
+#ifdef CONFIG_ZCRYPT_DEBUG
1567
+ if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY))
1568
+ break;
1569
+#endif
1570
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1571
+ /* on failure: retry once again after a requested rescan */
1572
+ if ((rc == -ENODEV) && (zcrypt_process_rescan()))
1573
+ do {
1574
+ rc = _zcrypt_send_ep11_cprb(true, perms, &tr, &xcrb);
1575
+ if (rc == -EAGAIN)
1576
+ tr.again_counter++;
1577
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1578
+ if (rc == -EAGAIN && tr.again_counter >= TRACK_AGAIN_MAX)
1579
+ rc = -EIO;
1580
+ if (rc)
1581
+ ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDEP11CPRB rc=%d\n", rc);
1582
+ if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb)))
1583
+ return -EFAULT;
1584
+ return rc;
1585
+}
1586
+
7941587 static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
7951588 unsigned long arg)
7961589 {
797
- int rc = 0;
1590
+ int rc;
1591
+ struct ap_perms *perms =
1592
+ (struct ap_perms *) filp->private_data;
1593
+
1594
+ rc = zcrypt_check_ioctl(perms, cmd);
1595
+ if (rc)
1596
+ return rc;
7981597
7991598 switch (cmd) {
800
- case ICARSAMODEXPO: {
801
- struct ica_rsa_modexpo __user *umex = (void __user *) arg;
802
- struct ica_rsa_modexpo mex;
803
-
804
- if (copy_from_user(&mex, umex, sizeof(mex)))
805
- return -EFAULT;
806
- do {
807
- rc = zcrypt_rsa_modexpo(&mex);
808
- } while (rc == -EAGAIN);
809
- /* on failure: retry once again after a requested rescan */
810
- if ((rc == -ENODEV) && (zcrypt_process_rescan()))
811
- do {
812
- rc = zcrypt_rsa_modexpo(&mex);
813
- } while (rc == -EAGAIN);
814
- if (rc) {
815
- ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSAMODEXPO rc=%d\n", rc);
816
- return rc;
817
- }
818
- return put_user(mex.outputdatalength, &umex->outputdatalength);
819
- }
820
- case ICARSACRT: {
821
- struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg;
822
- struct ica_rsa_modexpo_crt crt;
823
-
824
- if (copy_from_user(&crt, ucrt, sizeof(crt)))
825
- return -EFAULT;
826
- do {
827
- rc = zcrypt_rsa_crt(&crt);
828
- } while (rc == -EAGAIN);
829
- /* on failure: retry once again after a requested rescan */
830
- if ((rc == -ENODEV) && (zcrypt_process_rescan()))
831
- do {
832
- rc = zcrypt_rsa_crt(&crt);
833
- } while (rc == -EAGAIN);
834
- if (rc) {
835
- ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSACRT rc=%d\n", rc);
836
- return rc;
837
- }
838
- return put_user(crt.outputdatalength, &ucrt->outputdatalength);
839
- }
840
- case ZSECSENDCPRB: {
841
- struct ica_xcRB __user *uxcRB = (void __user *) arg;
842
- struct ica_xcRB xcRB;
843
-
844
- if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB)))
845
- return -EFAULT;
846
- do {
847
- rc = zcrypt_send_cprb(&xcRB);
848
- } while (rc == -EAGAIN);
849
- /* on failure: retry once again after a requested rescan */
850
- if ((rc == -ENODEV) && (zcrypt_process_rescan()))
851
- do {
852
- rc = zcrypt_send_cprb(&xcRB);
853
- } while (rc == -EAGAIN);
854
- if (rc)
855
- ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDCPRB rc=%d\n", rc);
856
- if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB)))
857
- return -EFAULT;
858
- return rc;
859
- }
860
- case ZSENDEP11CPRB: {
861
- struct ep11_urb __user *uxcrb = (void __user *)arg;
862
- struct ep11_urb xcrb;
863
-
864
- if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb)))
865
- return -EFAULT;
866
- do {
867
- rc = zcrypt_send_ep11_cprb(&xcrb);
868
- } while (rc == -EAGAIN);
869
- /* on failure: retry once again after a requested rescan */
870
- if ((rc == -ENODEV) && (zcrypt_process_rescan()))
871
- do {
872
- rc = zcrypt_send_ep11_cprb(&xcrb);
873
- } while (rc == -EAGAIN);
874
- if (rc)
875
- ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDEP11CPRB rc=%d\n", rc);
876
- if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb)))
877
- return -EFAULT;
878
- return rc;
879
- }
1599
+ case ICARSAMODEXPO:
1600
+ return icarsamodexpo_ioctl(perms, arg);
1601
+ case ICARSACRT:
1602
+ return icarsacrt_ioctl(perms, arg);
1603
+ case ZSECSENDCPRB:
1604
+ return zsecsendcprb_ioctl(perms, arg);
1605
+ case ZSENDEP11CPRB:
1606
+ return zsendep11cprb_ioctl(perms, arg);
8801607 case ZCRYPT_DEVICE_STATUS: {
8811608 struct zcrypt_device_status_ext *device_status;
8821609 size_t total_size = MAX_ZDEV_ENTRIES_EXT
....@@ -996,14 +1723,16 @@
9961723 compat_uptr_t n_modulus;
9971724 };
9981725
999
-static long trans_modexpo32(struct file *filp, unsigned int cmd,
1000
- unsigned long arg)
1726
+static long trans_modexpo32(struct ap_perms *perms, struct file *filp,
1727
+ unsigned int cmd, unsigned long arg)
10011728 {
10021729 struct compat_ica_rsa_modexpo __user *umex32 = compat_ptr(arg);
10031730 struct compat_ica_rsa_modexpo mex32;
10041731 struct ica_rsa_modexpo mex64;
1732
+ struct zcrypt_track tr;
10051733 long rc;
10061734
1735
+ memset(&tr, 0, sizeof(tr));
10071736 if (copy_from_user(&mex32, umex32, sizeof(mex32)))
10081737 return -EFAULT;
10091738 mex64.inputdata = compat_ptr(mex32.inputdata);
....@@ -1013,13 +1742,19 @@
10131742 mex64.b_key = compat_ptr(mex32.b_key);
10141743 mex64.n_modulus = compat_ptr(mex32.n_modulus);
10151744 do {
1016
- rc = zcrypt_rsa_modexpo(&mex64);
1017
- } while (rc == -EAGAIN);
1745
+ rc = zcrypt_rsa_modexpo(perms, &tr, &mex64);
1746
+ if (rc == -EAGAIN)
1747
+ tr.again_counter++;
1748
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
10181749 /* on failure: retry once again after a requested rescan */
10191750 if ((rc == -ENODEV) && (zcrypt_process_rescan()))
10201751 do {
1021
- rc = zcrypt_rsa_modexpo(&mex64);
1022
- } while (rc == -EAGAIN);
1752
+ rc = zcrypt_rsa_modexpo(perms, &tr, &mex64);
1753
+ if (rc == -EAGAIN)
1754
+ tr.again_counter++;
1755
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1756
+ if (rc == -EAGAIN && tr.again_counter >= TRACK_AGAIN_MAX)
1757
+ rc = -EIO;
10231758 if (rc)
10241759 return rc;
10251760 return put_user(mex64.outputdatalength,
....@@ -1038,14 +1773,16 @@
10381773 compat_uptr_t u_mult_inv;
10391774 };
10401775
1041
-static long trans_modexpo_crt32(struct file *filp, unsigned int cmd,
1042
- unsigned long arg)
1776
+static long trans_modexpo_crt32(struct ap_perms *perms, struct file *filp,
1777
+ unsigned int cmd, unsigned long arg)
10431778 {
10441779 struct compat_ica_rsa_modexpo_crt __user *ucrt32 = compat_ptr(arg);
10451780 struct compat_ica_rsa_modexpo_crt crt32;
10461781 struct ica_rsa_modexpo_crt crt64;
1782
+ struct zcrypt_track tr;
10471783 long rc;
10481784
1785
+ memset(&tr, 0, sizeof(tr));
10491786 if (copy_from_user(&crt32, ucrt32, sizeof(crt32)))
10501787 return -EFAULT;
10511788 crt64.inputdata = compat_ptr(crt32.inputdata);
....@@ -1058,13 +1795,19 @@
10581795 crt64.nq_prime = compat_ptr(crt32.nq_prime);
10591796 crt64.u_mult_inv = compat_ptr(crt32.u_mult_inv);
10601797 do {
1061
- rc = zcrypt_rsa_crt(&crt64);
1062
- } while (rc == -EAGAIN);
1798
+ rc = zcrypt_rsa_crt(perms, &tr, &crt64);
1799
+ if (rc == -EAGAIN)
1800
+ tr.again_counter++;
1801
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
10631802 /* on failure: retry once again after a requested rescan */
10641803 if ((rc == -ENODEV) && (zcrypt_process_rescan()))
10651804 do {
1066
- rc = zcrypt_rsa_crt(&crt64);
1067
- } while (rc == -EAGAIN);
1805
+ rc = zcrypt_rsa_crt(perms, &tr, &crt64);
1806
+ if (rc == -EAGAIN)
1807
+ tr.again_counter++;
1808
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1809
+ if (rc == -EAGAIN && tr.again_counter >= TRACK_AGAIN_MAX)
1810
+ rc = -EIO;
10681811 if (rc)
10691812 return rc;
10701813 return put_user(crt64.outputdatalength,
....@@ -1091,14 +1834,16 @@
10911834 unsigned int status;
10921835 } __packed;
10931836
1094
-static long trans_xcRB32(struct file *filp, unsigned int cmd,
1095
- unsigned long arg)
1837
+static long trans_xcRB32(struct ap_perms *perms, struct file *filp,
1838
+ unsigned int cmd, unsigned long arg)
10961839 {
10971840 struct compat_ica_xcRB __user *uxcRB32 = compat_ptr(arg);
10981841 struct compat_ica_xcRB xcRB32;
1842
+ struct zcrypt_track tr;
10991843 struct ica_xcRB xcRB64;
11001844 long rc;
11011845
1846
+ memset(&tr, 0, sizeof(tr));
11021847 if (copy_from_user(&xcRB32, uxcRB32, sizeof(xcRB32)))
11031848 return -EFAULT;
11041849 xcRB64.agent_ID = xcRB32.agent_ID;
....@@ -1122,13 +1867,19 @@
11221867 xcRB64.priority_window = xcRB32.priority_window;
11231868 xcRB64.status = xcRB32.status;
11241869 do {
1125
- rc = zcrypt_send_cprb(&xcRB64);
1126
- } while (rc == -EAGAIN);
1870
+ rc = _zcrypt_send_cprb(true, perms, &tr, &xcRB64);
1871
+ if (rc == -EAGAIN)
1872
+ tr.again_counter++;
1873
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
11271874 /* on failure: retry once again after a requested rescan */
11281875 if ((rc == -ENODEV) && (zcrypt_process_rescan()))
11291876 do {
1130
- rc = zcrypt_send_cprb(&xcRB64);
1131
- } while (rc == -EAGAIN);
1877
+ rc = _zcrypt_send_cprb(true, perms, &tr, &xcRB64);
1878
+ if (rc == -EAGAIN)
1879
+ tr.again_counter++;
1880
+ } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
1881
+ if (rc == -EAGAIN && tr.again_counter >= TRACK_AGAIN_MAX)
1882
+ rc = -EIO;
11321883 xcRB32.reply_control_blk_length = xcRB64.reply_control_blk_length;
11331884 xcRB32.reply_data_length = xcRB64.reply_data_length;
11341885 xcRB32.status = xcRB64.status;
....@@ -1140,12 +1891,20 @@
11401891 static long zcrypt_compat_ioctl(struct file *filp, unsigned int cmd,
11411892 unsigned long arg)
11421893 {
1894
+ int rc;
1895
+ struct ap_perms *perms =
1896
+ (struct ap_perms *) filp->private_data;
1897
+
1898
+ rc = zcrypt_check_ioctl(perms, cmd);
1899
+ if (rc)
1900
+ return rc;
1901
+
11431902 if (cmd == ICARSAMODEXPO)
1144
- return trans_modexpo32(filp, cmd, arg);
1903
+ return trans_modexpo32(perms, filp, cmd, arg);
11451904 if (cmd == ICARSACRT)
1146
- return trans_modexpo_crt32(filp, cmd, arg);
1905
+ return trans_modexpo_crt32(perms, filp, cmd, arg);
11471906 if (cmd == ZSECSENDCPRB)
1148
- return trans_xcRB32(filp, cmd, arg);
1907
+ return trans_xcRB32(perms, filp, cmd, arg);
11491908 return zcrypt_unlocked_ioctl(filp, cmd, arg);
11501909 }
11511910 #endif
....@@ -1263,6 +2022,67 @@
12632022 debug_unregister(zcrypt_dbf_info);
12642023 }
12652024
2025
+#ifdef CONFIG_ZCRYPT_MULTIDEVNODES
2026
+
2027
+static int __init zcdn_init(void)
2028
+{
2029
+ int rc;
2030
+
2031
+ /* create a new class 'zcrypt' */
2032
+ zcrypt_class = class_create(THIS_MODULE, ZCRYPT_NAME);
2033
+ if (IS_ERR(zcrypt_class)) {
2034
+ rc = PTR_ERR(zcrypt_class);
2035
+ goto out_class_create_failed;
2036
+ }
2037
+ zcrypt_class->dev_release = zcdn_device_release;
2038
+
2039
+ /* alloc device minor range */
2040
+ rc = alloc_chrdev_region(&zcrypt_devt,
2041
+ 0, ZCRYPT_MAX_MINOR_NODES,
2042
+ ZCRYPT_NAME);
2043
+ if (rc)
2044
+ goto out_alloc_chrdev_failed;
2045
+
2046
+ cdev_init(&zcrypt_cdev, &zcrypt_fops);
2047
+ zcrypt_cdev.owner = THIS_MODULE;
2048
+ rc = cdev_add(&zcrypt_cdev, zcrypt_devt, ZCRYPT_MAX_MINOR_NODES);
2049
+ if (rc)
2050
+ goto out_cdev_add_failed;
2051
+
2052
+ /* need some class specific sysfs attributes */
2053
+ rc = class_create_file(zcrypt_class, &class_attr_zcdn_create);
2054
+ if (rc)
2055
+ goto out_class_create_file_1_failed;
2056
+ rc = class_create_file(zcrypt_class, &class_attr_zcdn_destroy);
2057
+ if (rc)
2058
+ goto out_class_create_file_2_failed;
2059
+
2060
+ return 0;
2061
+
2062
+out_class_create_file_2_failed:
2063
+ class_remove_file(zcrypt_class, &class_attr_zcdn_create);
2064
+out_class_create_file_1_failed:
2065
+ cdev_del(&zcrypt_cdev);
2066
+out_cdev_add_failed:
2067
+ unregister_chrdev_region(zcrypt_devt, ZCRYPT_MAX_MINOR_NODES);
2068
+out_alloc_chrdev_failed:
2069
+ class_destroy(zcrypt_class);
2070
+out_class_create_failed:
2071
+ return rc;
2072
+}
2073
+
2074
+static void zcdn_exit(void)
2075
+{
2076
+ class_remove_file(zcrypt_class, &class_attr_zcdn_create);
2077
+ class_remove_file(zcrypt_class, &class_attr_zcdn_destroy);
2078
+ zcdn_destroy_all();
2079
+ cdev_del(&zcrypt_cdev);
2080
+ unregister_chrdev_region(zcrypt_devt, ZCRYPT_MAX_MINOR_NODES);
2081
+ class_destroy(zcrypt_class);
2082
+}
2083
+
2084
+#endif
2085
+
12662086 /**
12672087 * zcrypt_api_init(): Module initialization.
12682088 *
....@@ -1276,15 +2096,27 @@
12762096 if (rc)
12772097 goto out;
12782098
2099
+#ifdef CONFIG_ZCRYPT_MULTIDEVNODES
2100
+ rc = zcdn_init();
2101
+ if (rc)
2102
+ goto out;
2103
+#endif
2104
+
12792105 /* Register the request sprayer. */
12802106 rc = misc_register(&zcrypt_misc_device);
12812107 if (rc < 0)
1282
- goto out;
2108
+ goto out_misc_register_failed;
12832109
12842110 zcrypt_msgtype6_init();
12852111 zcrypt_msgtype50_init();
2112
+
12862113 return 0;
12872114
2115
+out_misc_register_failed:
2116
+#ifdef CONFIG_ZCRYPT_MULTIDEVNODES
2117
+ zcdn_exit();
2118
+#endif
2119
+ zcrypt_debug_exit();
12882120 out:
12892121 return rc;
12902122 }
....@@ -1296,9 +2128,14 @@
12962128 */
12972129 void __exit zcrypt_api_exit(void)
12982130 {
2131
+#ifdef CONFIG_ZCRYPT_MULTIDEVNODES
2132
+ zcdn_exit();
2133
+#endif
12992134 misc_deregister(&zcrypt_misc_device);
13002135 zcrypt_msgtype6_exit();
13012136 zcrypt_msgtype50_exit();
2137
+ zcrypt_ccamisc_exit();
2138
+ zcrypt_ep11misc_exit();
13022139 zcrypt_debug_exit();
13032140 }
13042141