Module Name:    src
Committed By:   drochner
Date:           Thu Jun  9 14:41:24 UTC 2011

Modified Files:
        src/sys/opencrypto: crypto.c cryptodev.c cryptodev.h

Log Message:
-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)


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/opencrypto/crypto.c
cvs rdiff -u -r1.66 -r1.67 src/sys/opencrypto/cryptodev.c
cvs rdiff -u -r1.24 -r1.25 src/sys/opencrypto/cryptodev.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.40 src/sys/opencrypto/crypto.c:1.41
--- src/sys/opencrypto/crypto.c:1.40	Mon May 16 10:27:49 2011
+++ src/sys/opencrypto/crypto.c	Thu Jun  9 14:41:24 2011
@@ -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);

Index: src/sys/opencrypto/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.66 src/sys/opencrypto/cryptodev.c:1.67
--- src/sys/opencrypto/cryptodev.c:1.66	Fri May 27 17:09:09 2011
+++ src/sys/opencrypto/cryptodev.c	Thu Jun  9 14:41:24 2011
@@ -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) {

Index: src/sys/opencrypto/cryptodev.h
diff -u src/sys/opencrypto/cryptodev.h:1.24 src/sys/opencrypto/cryptodev.h:1.25
--- src/sys/opencrypto/cryptodev.h:1.24	Thu May 26 21:50:03 2011
+++ src/sys/opencrypto/cryptodev.h	Thu Jun  9 14:41:24 2011
@@ -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;

Reply via email to