Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/opencrypto separate crypto_drv_mtx from crypto_mtx.
details: https://anonhg.NetBSD.org/src/rev/0e1d32a21845
branches: trunk
changeset: 353216:0e1d32a21845
user: knakahara <knakahara%NetBSD.org@localhost>
date: Mon Apr 24 03:29:37 2017 +0000
description:
separate crypto_drv_mtx from crypto_mtx.
crypto_mtx is used only for cryptodev.c and ocryptodev.c now.
diffstat:
sys/opencrypto/crypto.c | 64 +++++++++++++++++++-----------------
sys/opencrypto/cryptodev.c | 10 ++++-
sys/opencrypto/cryptodev.h | 8 +----
sys/opencrypto/cryptodev_internal.h | 4 +-
4 files changed, 45 insertions(+), 41 deletions(-)
diffs (truncated from 350 to 300 lines):
diff -r 3c411960cd98 -r 0e1d32a21845 sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c Mon Apr 24 02:04:55 2017 +0000
+++ b/sys/opencrypto/crypto.c Mon Apr 24 03:29:37 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: crypto.c,v 1.56 2017/04/24 02:04:55 knakahara Exp $ */
+/* $NetBSD: crypto.c,v 1.57 2017/04/24 03:29:37 knakahara Exp $ */
/* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */
/* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */
@@ -53,7 +53,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.56 2017/04/24 02:04:55 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.57 2017/04/24 03:29:37 knakahara Exp $");
#include <sys/param.h>
#include <sys/reboot.h>
@@ -78,7 +78,6 @@
static kmutex_t crypto_q_mtx;
static kmutex_t crypto_ret_q_mtx;
static kcondvar_t cryptoret_cv;
-kmutex_t crypto_mtx;
/* below are kludges for residual code wrtitten to FreeBSD interfaces */
#define SWI_CRYPTO 17
@@ -99,6 +98,7 @@
* crypto_drivers table with crypto_get_driverid() and then registering
* each algorithm they support with crypto_register() and crypto_kregister().
*/
+static kmutex_t crypto_drv_mtx;
static struct cryptocap *crypto_drivers;
static int crypto_drivers_num;
static void *softintr_cookie;
@@ -221,7 +221,7 @@
{
int error;
- mutex_init(&crypto_mtx, MUTEX_DEFAULT, IPL_NONE);
+ mutex_init(&crypto_drv_mtx, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&crypto_q_mtx, MUTEX_DEFAULT, IPL_NET);
mutex_init(&crypto_ret_q_mtx, MUTEX_DEFAULT, IPL_NET);
cv_init(&cryptoret_cv, "crypto_w");
@@ -301,8 +301,10 @@
unregister_swi(SWI_CRYPTO, cryptointr);
+ mutex_enter(&crypto_drv_mtx);
if (crypto_drivers != NULL)
free(crypto_drivers, M_CRYPTO_DATA);
+ mutex_exit(&crypto_drv_mtx);
pool_destroy(&cryptop_pool);
pool_destroy(&cryptodesc_pool);
@@ -312,13 +314,13 @@
mutex_destroy(&crypto_ret_q_mtx);
mutex_destroy(&crypto_q_mtx);
- mutex_destroy(&crypto_mtx);
+ mutex_destroy(&crypto_drv_mtx);
return 0;
}
/*
- * Create a new session. Must be called with crypto_mtx held.
+ * Create a new session.
*/
int
crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int hard)
@@ -327,7 +329,7 @@
u_int32_t hid, lid;
int err = EINVAL;
- mutex_enter(&crypto_mtx);
+ mutex_enter(&crypto_drv_mtx);
if (crypto_drivers == NULL)
goto done;
@@ -393,13 +395,13 @@
}
}
done:
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
return err;
}
/*
* Delete an existing session (or a reserved session on an unregistered
- * driver). Must be called with crypto_mtx mutex held.
+ * driver).
*/
int
crypto_freesession(u_int64_t sid)
@@ -407,7 +409,7 @@
u_int32_t hid;
int err = 0;
- mutex_enter(&crypto_mtx);
+ mutex_enter(&crypto_drv_mtx);
if (crypto_drivers == NULL) {
err = EINVAL;
@@ -442,7 +444,7 @@
memset(&crypto_drivers[hid], 0, sizeof(struct cryptocap));
done:
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
return err;
}
@@ -458,7 +460,7 @@
(void)crypto_init(); /* XXX oh, this is foul! */
- mutex_enter(&crypto_mtx);
+ mutex_enter(&crypto_drv_mtx);
for (i = 0; i < crypto_drivers_num; i++)
if (crypto_drivers[i].cc_process == NULL &&
(crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP) == 0 &&
@@ -469,7 +471,7 @@
if (i == crypto_drivers_num) {
/* Be careful about wrap-around. */
if (2 * crypto_drivers_num <= crypto_drivers_num) {
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
printf("crypto: driver count wraparound!\n");
return -1;
}
@@ -477,7 +479,7 @@
newdrv = malloc(2 * crypto_drivers_num *
sizeof(struct cryptocap), M_CRYPTO_DATA, M_NOWAIT|M_ZERO);
if (newdrv == NULL) {
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
printf("crypto: no space to expand driver table!\n");
return -1;
}
@@ -498,7 +500,7 @@
if (bootverbose)
printf("crypto: assign driver %u, flags %u\n", i, flags);
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
return i;
}
@@ -523,7 +525,7 @@
struct cryptocap *cap;
int err;
- mutex_enter(&crypto_mtx);
+ mutex_enter(&crypto_drv_mtx);
cap = crypto_checkdriver(driverid);
if (cap != NULL &&
@@ -552,7 +554,7 @@
} else
err = EINVAL;
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
return err;
}
@@ -571,7 +573,7 @@
struct cryptocap *cap;
int err;
- mutex_enter(&crypto_mtx);
+ mutex_enter(&crypto_drv_mtx);
cap = crypto_checkdriver(driverid);
/* NB: algorithms are in the range [1..max] */
@@ -606,7 +608,7 @@
} else
err = EINVAL;
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
return err;
}
@@ -623,7 +625,7 @@
u_int32_t ses;
struct cryptocap *cap;
- mutex_enter(&crypto_mtx);
+ mutex_enter(&crypto_drv_mtx);
cap = crypto_checkdriver(driverid);
if (cap != NULL &&
@@ -652,7 +654,7 @@
} else
err = EINVAL;
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
return err;
}
@@ -674,7 +676,7 @@
u_int32_t ses;
struct cryptocap *cap;
- mutex_enter(&crypto_mtx);
+ mutex_enter(&crypto_drv_mtx);
cap = crypto_checkdriver(driverid);
if (cap != NULL) {
for (i = CRYPTO_ALGORITHM_MIN; i <= CRYPTO_ALGORITHM_MAX; i++) {
@@ -694,7 +696,7 @@
} else
err = EINVAL;
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
return err;
}
@@ -866,7 +868,7 @@
return EINVAL;
}
- mutex_enter(&crypto_mtx);
+ mutex_enter(&crypto_drv_mtx);
for (hid = 0; hid < crypto_drivers_num; hid++) {
if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
crypto_devallowsoft == 0)
@@ -884,11 +886,11 @@
process = crypto_drivers[hid].cc_kprocess;
arg = crypto_drivers[hid].cc_karg;
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
krp->krp_hid = hid;
error = (*process)(arg, krp, hint);
} else {
- mutex_exit(&crypto_mtx);
+ mutex_exit(&crypto_drv_mtx);
error = ENODEV;
}
@@ -1158,10 +1160,10 @@
{
int hid, kalg, feat = 0;
- mutex_enter(&crypto_mtx);
+ if (crypto_userasymcrypto == 0)
+ return 0;
- if (crypto_userasymcrypto == 0)
- goto out;
+ mutex_enter(&crypto_drv_mtx);
for (hid = 0; hid < crypto_drivers_num; hid++) {
if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
@@ -1175,8 +1177,8 @@
CRYPTO_ALG_FLAG_SUPPORTED) != 0)
feat |= 1 << kalg;
}
-out:
- mutex_exit(&crypto_mtx);
+
+ mutex_exit(&crypto_drv_mtx);
*featp = feat;
return (0);
}
diff -r 3c411960cd98 -r 0e1d32a21845 sys/opencrypto/cryptodev.c
--- a/sys/opencrypto/cryptodev.c Mon Apr 24 02:04:55 2017 +0000
+++ b/sys/opencrypto/cryptodev.c Mon Apr 24 03:29:37 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cryptodev.c,v 1.88 2017/04/07 12:17:57 knakahara Exp $ */
+/* $NetBSD: cryptodev.c,v 1.89 2017/04/24 03:29:37 knakahara Exp $ */
/* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */
/* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.88 2017/04/07 12:17:57 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.89 2017/04/24 03:29:37 knakahara Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -98,6 +98,8 @@
#include "ioconf.h"
+kmutex_t crypto_mtx;
+
struct csession {
TAILQ_ENTRY(csession) next;
u_int64_t sid;
@@ -2075,6 +2077,8 @@
{
crypto_init();
Home |
Main Index |
Thread Index |
Old Index