Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/opencrypto -if an opencrypto(9) session is allocated, th...



details:   https://anonhg.NetBSD.org/src/rev/b6b0f3747b68
branches:  trunk
changeset: 765896:b6b0f3747b68
user:      drochner <drochner%NetBSD.org@localhost>
date:      Thu Jun 09 14:41:24 2011 +0000

description:
-if an opencrypto(9) session is allocated, the driver is refcounted
 and can not disappear -- no need to hold crypto_mtx to check the
 driver list
 (the whole check is questionable)
-crp->crp_cv (the condition variable) is used by userland cryptodev
 exclusively -- move its initialization there, no need to waste
 cycles of in-kernel callers
-add a comment which members of "struct cryptop" are used
 by opencrypto(9) and which by crypto(4)
 (this should be split, no need to waste memory for in-kernel callers)

diffstat:

 sys/opencrypto/crypto.c    |  14 ++++----------
 sys/opencrypto/cryptodev.c |  11 +++++++++--
 sys/opencrypto/cryptodev.h |  11 +++++++----
 3 files changed, 20 insertions(+), 16 deletions(-)

diffs (166 lines):

diff -r 11c1869ce573 -r b6b0f3747b68 sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c   Thu Jun 09 13:43:44 2011 +0000
+++ b/sys/opencrypto/crypto.c   Thu Jun 09 14:41:24 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crypto.c,v 1.40 2011/05/16 10:27:49 drochner Exp $ */
+/*     $NetBSD: crypto.c,v 1.41 2011/06/09 14:41:24 drochner 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.40 2011/05/16 10:27:49 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.41 2011/06/09 14:41:24 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -720,8 +720,8 @@
        int result;
 
        mutex_spin_enter(&crypto_q_mtx);
-       DPRINTF(("crypto_dispatch: crp %p, reqid 0x%x, alg %d\n",
-               crp, crp->crp_reqid, crp->crp_desc->crd_alg));
+       DPRINTF(("crypto_dispatch: crp %p, alg %d\n",
+               crp, crp->crp_desc->crd_alg));
 
        cryptostats.cs_ops++;
 
@@ -928,7 +928,6 @@
 
        hid = CRYPTO_SESID2HID(crp->crp_sid);
 
-       mutex_enter(&crypto_mtx);
        if (hid < crypto_drivers_num) {
                int (*process)(void *, struct cryptop *, int);
                void *arg;
@@ -940,7 +939,6 @@
                }
                process = crypto_drivers[hid].cc_process;
                arg = crypto_drivers[hid].cc_arg;
-               mutex_exit(&crypto_mtx);
 
                /*
                 * Invoke the driver to process the request.
@@ -958,8 +956,6 @@
                for (crd = crp->crp_desc; crd->crd_next; crd = crd->crd_next)
                        crd->CRD_INI.cri_next = &(crd->crd_next->CRD_INI);
 
-               mutex_exit(&crypto_mtx);
-
                if (crypto_newsession(&nid, &(crp->crp_desc->CRD_INI), 0) == 0)
                        crp->crp_sid = nid;
 
@@ -992,7 +988,6 @@
                crp->crp_desc = crd->crd_next;
                pool_put(&cryptodesc_pool, crd);
        }
-       cv_destroy(&crp->crp_cv);
        pool_put(&cryptop_pool, crp);
 }
 
@@ -1010,7 +1005,6 @@
                return NULL;
        }
        memset(crp, 0, sizeof(struct cryptop));
-       cv_init(&crp->crp_cv, "crydev");
 
        while (num--) {
                crd = pool_get(&cryptodesc_pool, 0);
diff -r 11c1869ce573 -r b6b0f3747b68 sys/opencrypto/cryptodev.c
--- a/sys/opencrypto/cryptodev.c        Thu Jun 09 13:43:44 2011 +0000
+++ b/sys/opencrypto/cryptodev.c        Thu Jun 09 14:41:24 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cryptodev.c,v 1.66 2011/05/27 17:09:09 drochner Exp $ */
+/*     $NetBSD: cryptodev.c,v 1.67 2011/06/09 14:41:24 drochner 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.66 2011/05/27 17:09:09 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.67 2011/06/09 14:41:24 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -615,6 +615,8 @@
                crp->crp_mac=cse->tmp_mac;
        }
 
+       cv_init(&crp->crp_cv, "crydev");
+
        /*
         * XXX there was a comment here which said that we went to
         * XXX splcrypto() but needed to only if CRYPTO_F_CBIMM,
@@ -651,6 +653,7 @@
        default:
                DPRINTF(("cryptodev_op: not waiting, error.\n"));
                mutex_exit(&crypto_mtx);
+               cv_destroy(&crp->crp_cv);
                goto bail;
        }
 
@@ -667,6 +670,7 @@
                (void)crypto_ret_q_remove(crp);
        }
        mutex_exit(&crypto_mtx);
+       cv_destroy(&crp->crp_cv);
 
        if (crp->crp_etype != 0) {
                DPRINTF(("cryptodev_op: crp_etype %d\n", crp->crp_etype));
@@ -1317,6 +1321,7 @@
                cnop[req].reqid = atomic_inc_32_nv(&(fcr->requestid));
                crp->crp_reqid = cnop[req].reqid;
                crp->crp_usropaque = cnop[req].opaque;
+               cv_init(&crp->crp_cv, "crydev");
 #ifdef notyet
 eagain:
 #endif
@@ -1335,10 +1340,12 @@
                default:
                        DPRINTF(("cryptodev_op: not waiting, error.\n"));
                        mutex_exit(&crypto_mtx);
+                       cv_destroy(&crp->crp_cv);
                        goto bail;
                }
 
                mutex_exit(&crypto_mtx);
+               cv_destroy(&crp->crp_cv);
 bail:
                if (cnop[req].status) {
                        if (crp) {
diff -r 11c1869ce573 -r b6b0f3747b68 sys/opencrypto/cryptodev.h
--- a/sys/opencrypto/cryptodev.h        Thu Jun 09 13:43:44 2011 +0000
+++ b/sys/opencrypto/cryptodev.h        Thu Jun 09 14:41:24 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cryptodev.h,v 1.24 2011/05/26 21:50:03 drochner Exp $ */
+/*     $NetBSD: cryptodev.h,v 1.25 2011/06/09 14:41:24 drochner 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 $      */
 
@@ -442,9 +442,6 @@
 struct cryptop {
        TAILQ_ENTRY(cryptop) crp_next;
        u_int64_t       crp_sid;        /* Session ID */
-       
-       u_int32_t       crp_reqid;      /* request id */
-       void *          crp_usropaque;  /* Opaque pointer from user, passed along */
 
        int             crp_ilen;       /* Input data total length */
        int             crp_olen;       /* Result total length */
@@ -479,6 +476,12 @@
        int (*crp_callback)(struct cryptop *); /* Callback function */
 
        void *          crp_mac;
+
+       /*
+        * everything below is private to crypto(4)
+        */
+       u_int32_t       crp_reqid;      /* request id */
+       void *          crp_usropaque;  /* Opaque pointer from user, passed along */
        struct timespec crp_tstamp;     /* performance time stamp */
        kcondvar_t      crp_cv;
        struct fcrypt   *fcrp;



Home | Main Index | Thread Index | Old Index