summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2017-02-07 17:25:47 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2017-02-07 17:25:47 +0000
commit1222539b6394ce40c12127425e341be7447471ee (patch)
tree721477aee6fbd097fd777cf68fa80f12b72bca78 /sys/arch
parentb5f0b38252e2338e048adce12dde40f7a6cae620 (diff)
Reduce the per-packet allocation costs for crypto operations (cryptop)
by pre-allocating two cryptodesc objects and storing them in an array instead of a linked list. If more than two cryptodesc objects are required use mallocarray to fetch them. Adapt the drivers to the new API. This change results in one pool-get per ESP packet instead of three. It also simplifies softraid crypto where more cryptodesc objects are allocated than used. From, with and ok markus@, ok bluhm@ "looks sane" mpi@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/amd64/amd64/aesni.c8
-rw-r--r--sys/arch/amd64/amd64/via.c8
-rw-r--r--sys/arch/i386/i386/via.c8
-rw-r--r--sys/arch/i386/pci/glxsb.c10
4 files changed, 23 insertions, 11 deletions
diff --git a/sys/arch/amd64/amd64/aesni.c b/sys/arch/amd64/amd64/aesni.c
index b712cdceaef..dd8dbfd3ed9 100644
--- a/sys/arch/amd64/amd64/aesni.c
+++ b/sys/arch/amd64/amd64/aesni.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aesni.c,v 1.39 2016/09/15 02:00:16 dlg Exp $ */
+/* $OpenBSD: aesni.c,v 1.40 2017/02/07 17:25:45 patrick Exp $ */
/*-
* Copyright (c) 2003 Jason Wright
* Copyright (c) 2003, 2004 Theo de Raadt
@@ -616,9 +616,12 @@ aesni_process(struct cryptop *crp)
struct aesni_session *ses;
struct cryptodesc *crd, *crda, *crde;
int err = 0;
+ int i;
if (crp == NULL || crp->crp_callback == NULL)
return (EINVAL);
+ if (crp->crp_ndesc < 1)
+ return (EINVAL);
mtx_enter(&aesni_sc->sc_mtx);
LIST_FOREACH(ses, &aesni_sc->sc_sessions, ses_entries) {
@@ -633,7 +636,8 @@ aesni_process(struct cryptop *crp)
}
crda = crde = NULL;
- for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
+ for (i = 0; i < crp->crp_ndesc; i++) {
+ crd = &crp->crp_desc[i];
switch (crd->crd_alg) {
case CRYPTO_AES_CBC:
case CRYPTO_AES_CTR:
diff --git a/sys/arch/amd64/amd64/via.c b/sys/arch/amd64/amd64/via.c
index f631f5aa303..53cfe1813f5 100644
--- a/sys/arch/amd64/amd64/via.c
+++ b/sys/arch/amd64/amd64/via.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: via.c,v 1.21 2015/08/28 00:03:53 deraadt Exp $ */
+/* $OpenBSD: via.c,v 1.22 2017/02/07 17:25:45 patrick Exp $ */
/* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */
/*-
@@ -441,9 +441,12 @@ viac3_crypto_process(struct cryptop *crp)
struct viac3_session *ses;
struct cryptodesc *crd;
int sesn, err = 0;
+ int i;
if (crp == NULL || crp->crp_callback == NULL)
return (EINVAL);
+ if (crp->crp_ndesc < 1)
+ return (EINVAL);
sesn = VIAC3_SESSION(crp->crp_sid);
if (sesn >= sc->sc_nsessions) {
@@ -456,7 +459,8 @@ viac3_crypto_process(struct cryptop *crp)
goto out;
}
- for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
+ for (i = 0; i < crp->crp_ndesc; i++) {
+ crd = &crp->crp_desc[i];
switch (crd->crd_alg) {
case CRYPTO_AES_CBC:
if ((err = viac3_crypto_encdec(crp, crd, ses, sc,
diff --git a/sys/arch/i386/i386/via.c b/sys/arch/i386/i386/via.c
index 3e007c4ba80..2765dc596ec 100644
--- a/sys/arch/i386/i386/via.c
+++ b/sys/arch/i386/i386/via.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: via.c,v 1.35 2015/09/08 07:12:56 deraadt Exp $ */
+/* $OpenBSD: via.c,v 1.36 2017/02/07 17:25:45 patrick Exp $ */
/* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */
/*-
@@ -444,9 +444,12 @@ viac3_crypto_process(struct cryptop *crp)
struct viac3_session *ses;
struct cryptodesc *crd;
int sesn, err = 0;
+ int i;
if (crp == NULL || crp->crp_callback == NULL)
return (EINVAL);
+ if (crp->crp_ndesc < 1)
+ return (EINVAL);
sesn = VIAC3_SESSION(crp->crp_sid);
if (sesn >= sc->sc_nsessions) {
@@ -459,7 +462,8 @@ viac3_crypto_process(struct cryptop *crp)
goto out;
}
- for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
+ for (i = 0; i < crp->crp_ndesc; i++) {
+ crd = &crp->crp_desc[i];
switch (crd->crd_alg) {
case CRYPTO_AES_CBC:
if ((err = viac3_crypto_encdec(crp, crd, ses, sc,
diff --git a/sys/arch/i386/pci/glxsb.c b/sys/arch/i386/pci/glxsb.c
index c93a86452b4..21786ab4ece 100644
--- a/sys/arch/i386/pci/glxsb.c
+++ b/sys/arch/i386/pci/glxsb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: glxsb.c,v 1.30 2015/09/08 08:33:26 deraadt Exp $ */
+/* $OpenBSD: glxsb.c,v 1.31 2017/02/07 17:25:45 patrick Exp $ */
/*
* Copyright (c) 2006 Tom Cosgrove <tom@openbsd.org>
@@ -778,7 +778,7 @@ glxsb_crypto_process(struct cryptop *crp)
struct glxsb_session *ses;
struct cryptodesc *crd;
int sesn,err = 0;
- int s;
+ int s, i;
s = splnet();
@@ -786,8 +786,7 @@ glxsb_crypto_process(struct cryptop *crp)
err = EINVAL;
goto out;
}
- crd = crp->crp_desc;
- if (crd == NULL) {
+ if (crp->crp_ndesc < 1) {
err = EINVAL;
goto out;
}
@@ -803,7 +802,8 @@ glxsb_crypto_process(struct cryptop *crp)
goto out;
}
- for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
+ for (i = 0; i < crp->crp_ndesc; i++) {
+ crd = &crp->crp_desc[i];
switch (crd->crd_alg) {
case CRYPTO_AES_CBC:
if (ses->ses_swd_enc) {