Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/opencrypto add cryptkop alloc/free KPI instead of manipu...
details: https://anonhg.NetBSD.org/src/rev/0eef02a0992f
branches: trunk
changeset: 353833:0eef02a0992f
user: knakahara <knakahara%NetBSD.org@localhost>
date: Thu May 25 05:24:57 2017 +0000
description:
add cryptkop alloc/free KPI instead of manipulating cryptkop_pool directly.
diffstat:
sys/opencrypto/crypto.c | 54 +++++++++++++++++++++++++++++++++++++++++++--
sys/opencrypto/cryptodev.c | 24 +++++++++++++------
sys/opencrypto/cryptodev.h | 11 +++-----
3 files changed, 71 insertions(+), 18 deletions(-)
diffs (192 lines):
diff -r 0098c8c0e25b -r 0eef02a0992f sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c Thu May 25 05:22:55 2017 +0000
+++ b/sys/opencrypto/crypto.c Thu May 25 05:24:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: crypto.c,v 1.75 2017/05/24 10:05:09 knakahara Exp $ */
+/* $NetBSD: crypto.c,v 1.76 2017/05/25 05:24:57 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.75 2017/05/24 10:05:09 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.76 2017/05/25 05:24:57 knakahara Exp $");
#include <sys/param.h>
#include <sys/reboot.h>
@@ -1076,7 +1076,7 @@
/* Sanity checks. */
if (krp->krp_callback == NULL) {
cv_destroy(&krp->krp_cv);
- pool_put(&cryptkop_pool, krp);
+ crypto_kfreereq(krp);
return EINVAL;
}
@@ -1262,6 +1262,54 @@
}
/*
+ * Release a set of asymmetric crypto descriptors.
+ * Currently, support one descriptor only.
+ */
+void
+crypto_kfreereq(struct cryptkop *krp)
+{
+
+ if (krp == NULL)
+ return;
+
+ DPRINTF("krp %p\n", krp);
+
+ /* sanity check */
+ if (krp->krp_flags & CRYPTO_F_ONRETQ) {
+ panic("crypto_kfreereq() freeing krp on RETQ\n");
+ }
+
+ pool_put(&cryptkop_pool, krp);
+}
+
+/*
+ * Acquire a set of asymmetric crypto descriptors.
+ * Currently, support one descriptor only.
+ */
+struct cryptkop *
+crypto_kgetreq(int num __unused, int prflags)
+{
+ struct cryptkop *krp;
+
+ /*
+ * When crp_ret_kq is full, we restrict here to avoid crp_ret_kq
+ * overflow by error callback.
+ */
+ if (CRYPTO_Q_IS_FULL(crp_ret_kq)) {
+ CRYPTO_Q_INC_DROPS(crp_ret_kq);
+ return NULL;
+ }
+
+ krp = pool_get(&cryptkop_pool, prflags);
+ if (krp == NULL) {
+ return NULL;
+ }
+ memset(krp, 0, sizeof(struct cryptkop));
+
+ return krp;
+}
+
+/*
* Invoke the callback on behalf of the driver.
*/
void
diff -r 0098c8c0e25b -r 0eef02a0992f sys/opencrypto/cryptodev.c
--- a/sys/opencrypto/cryptodev.c Thu May 25 05:22:55 2017 +0000
+++ b/sys/opencrypto/cryptodev.c Thu May 25 05:24:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cryptodev.c,v 1.90 2017/05/17 06:33:04 knakahara Exp $ */
+/* $NetBSD: cryptodev.c,v 1.91 2017/05/25 05:24:57 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.90 2017/05/17 06:33:04 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.91 2017/05/25 05:24:57 knakahara Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -855,7 +855,11 @@
return EINVAL;
}
- krp = pool_get(&cryptkop_pool, PR_WAITOK);
+ krp = crypto_kgetreq(1, PR_WAITOK);
+ if (krp == NULL) {
+ /* limited by opencrypto.crypto_ret_kq.maxlen */
+ return ENOMEM;
+ }
(void)memset(krp, 0, sizeof *krp);
cv_init(&krp->krp_cv, "crykdev");
krp->krp_op = kop->crk_op;
@@ -923,7 +927,7 @@
}
}
cv_destroy(&krp->krp_cv);
- pool_put(&cryptkop_pool, krp);
+ crypto_kfreereq(krp);
DPRINTF("error=0x%08x\n", error);
return error;
}
@@ -1435,7 +1439,11 @@
continue;
}
- krp = pool_get(&cryptkop_pool, PR_WAITOK);
+ krp = crypto_kgetreq(1, PR_WAITOK);
+ if (krp == NULL) {
+ /* limited by opencrypto.crypto_ret_kq.maxlen */
+ continue;
+ }
(void)memset(krp, 0, sizeof *krp);
cv_init(&krp->krp_cv, "crykdev");
krp->krp_op = kop[req].crk_op;
@@ -1493,7 +1501,7 @@
}
}
cv_destroy(&krp->krp_cv);
- pool_put(&cryptkop_pool, krp);
+ crypto_kfreereq(krp);
}
}
error = 0;
@@ -1912,7 +1920,7 @@
}
}
cv_destroy(&krp->krp_cv);
- pool_put(&cryptkop_pool, krp);
+ crypto_kfreereq(krp);
req++;
}
}
@@ -2012,7 +2020,7 @@
}
}
cv_destroy(&krp->krp_cv);
- pool_put(&cryptkop_pool, krp);
+ crypto_kfreereq(krp);
return 0;
}
}
diff -r 0098c8c0e25b -r 0eef02a0992f sys/opencrypto/cryptodev.h
--- a/sys/opencrypto/cryptodev.h Thu May 25 05:22:55 2017 +0000
+++ b/sys/opencrypto/cryptodev.h Thu May 25 05:24:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cryptodev.h,v 1.33 2017/05/25 05:22:55 knakahara Exp $ */
+/* $NetBSD: cryptodev.h,v 1.34 2017/05/25 05:24:57 knakahara Exp $ */
/* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */
/* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */
@@ -606,17 +606,14 @@
extern void crypto_freereq(struct cryptop *crp);
extern struct cryptop *crypto_getreq(int num);
+extern void crypto_kfreereq(struct cryptkop *);
+extern struct cryptkop *crypto_kgetreq(int, int);
+
extern int crypto_usercrypto; /* userland may do crypto requests */
extern int crypto_userasymcrypto; /* userland may do asym crypto reqs */
extern int crypto_devallowsoft; /* only use hardware crypto */
/*
- * Asymmetric operations are allocated in cryptodev.c but can be
- * freed in crypto.c.
- */
-extern struct pool cryptkop_pool;
-
-/*
* initialize the crypto framework subsystem (not the pseudo-device).
* This must be called very early in boot, so the framework is ready
* to handle registration requests when crpto hardware is autoconfigured.
Home |
Main Index |
Thread Index |
Old Index