CVS commit: src/sys/opencrypto

2019-11-29 Thread Hikaru Abe
Module Name:src
Committed By:   hikaru
Date:   Fri Nov 29 08:30:31 UTC 2019

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

Log Message:
crypto(4): accept CRYPTO_SHA2_384_HMAC and CRYPTO_SHA2_512_HMAC.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/opencrypto/cryptodev.c

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/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.101 src/sys/opencrypto/cryptodev.c:1.102
--- src/sys/opencrypto/cryptodev.c:1.101	Thu Jun 13 02:02:45 2019
+++ src/sys/opencrypto/cryptodev.c	Fri Nov 29 08:30:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptodev.c,v 1.101 2019/06/13 02:02:45 christos Exp $ */
+/*	$NetBSD: cryptodev.c,v 1.102 2019/11/29 08:30:30 hikaru 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 
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.101 2019/06/13 02:02:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.102 2019/11/29 08:30:30 hikaru Exp $");
 
 #include 
 #include 
@@ -1644,6 +1644,12 @@ cryptodev_session(struct fcrypt *fcr, st
 			return EINVAL;
 		}
 		break;
+	case CRYPTO_SHA2_384_HMAC:
+		thash = _hash_hmac_sha2_384;
+		break;
+	case CRYPTO_SHA2_512_HMAC:
+		thash = _hash_hmac_sha2_512;
+		break;
 	case CRYPTO_RIPEMD160_HMAC:
 		thash = _hash_hmac_ripemd_160;
 		break;



CVS commit: src/sys/opencrypto

2019-11-29 Thread Hikaru Abe
Module Name:src
Committed By:   hikaru
Date:   Fri Nov 29 08:30:31 UTC 2019

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

Log Message:
crypto(4): accept CRYPTO_SHA2_384_HMAC and CRYPTO_SHA2_512_HMAC.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/opencrypto/cryptodev.c

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



CVS commit: src/sys/opencrypto

2019-11-28 Thread Hikaru Abe
Module Name:src
Committed By:   hikaru
Date:   Fri Nov 29 07:20:03 UTC 2019

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

Log Message:
HMAC-SHA-512 has 32 bytes MAC.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/opencrypto/cryptodev.h

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



CVS commit: src/sys/opencrypto

2019-11-28 Thread Hikaru Abe
Module Name:src
Committed By:   hikaru
Date:   Fri Nov 29 07:20:03 UTC 2019

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

Log Message:
HMAC-SHA-512 has 32 bytes MAC.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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/cryptodev.h
diff -u src/sys/opencrypto/cryptodev.h:1.39 src/sys/opencrypto/cryptodev.h:1.40
--- src/sys/opencrypto/cryptodev.h:1.39	Wed Jul 26 06:44:50 2017
+++ src/sys/opencrypto/cryptodev.h	Fri Nov 29 07:20:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptodev.h,v 1.39 2017/07/26 06:44:50 knakahara Exp $ */
+/*	$NetBSD: cryptodev.h,v 1.40 2019/11/29 07:20:03 hikaru 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 $	*/
 
@@ -262,7 +262,7 @@ struct crypt_sgop {
 	struct session_n_op * sessions;
 };
 
-#define CRYPTO_MAX_MAC_LEN	20
+#define CRYPTO_MAX_MAC_LEN	32 /* Keep this updated */
 
 /* bignum parameter, in packed bytes, ... */
 struct crparam {



CVS commit: src/sys/opencrypto

2019-10-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 12 00:49:30 UTC 2019

Modified Files:
src/sys/opencrypto: cryptosoft.c cryptosoft_xform.c

Log Message:
add (void *) intermediate casts to elide gcc function cast warnings. This
is the simplest solution; choices:
- add pragmas, complex and ugly (need to be gcc-specific)
- add -Wno to COPTS. Needs to be done in many makefiles because of rump
- add intermediate functions: slows down things


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/opencrypto/cryptosoft.c
cvs rdiff -u -r1.27 -r1.28 src/sys/opencrypto/cryptosoft_xform.c

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/cryptosoft.c
diff -u src/sys/opencrypto/cryptosoft.c:1.53 src/sys/opencrypto/cryptosoft.c:1.54
--- src/sys/opencrypto/cryptosoft.c:1.53	Thu Jul 11 19:27:24 2019
+++ src/sys/opencrypto/cryptosoft.c	Fri Oct 11 20:49:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptosoft.c,v 1.53 2019/07/11 23:27:24 christos Exp $ */
+/*	$NetBSD: cryptosoft.c,v 1.54 2019/10/12 00:49:30 christos Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $	*/
 /*	$OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $	*/
 
@@ -24,7 +24,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.53 2019/07/11 23:27:24 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.54 2019/10/12 00:49:30 christos Exp $");
 
 #include 
 #include 
@@ -500,7 +500,7 @@ swcr_authcompute(struct cryptop *crp, st
 		break;
 	case CRYPTO_BUF_MBUF:
 		err = m_apply((struct mbuf *) buf, crd->crd_skip, crd->crd_len,
-		(int (*)(void*, void *, unsigned int)) axf->Update,
+		(int (*)(void*, void *, unsigned int))(void *)axf->Update,
 		(void *) );
 		if (err)
 			return err;
@@ -508,7 +508,7 @@ swcr_authcompute(struct cryptop *crp, st
 	case CRYPTO_BUF_IOV:
 		err = cuio_apply((struct uio *) buf, crd->crd_skip,
 		crd->crd_len,
-		(int (*)(void *, void *, unsigned int)) axf->Update,
+		(int (*)(void *, void *, unsigned int))(void *)axf->Update,
 		(void *) );
 		if (err) {
 			return err;

Index: src/sys/opencrypto/cryptosoft_xform.c
diff -u src/sys/opencrypto/cryptosoft_xform.c:1.27 src/sys/opencrypto/cryptosoft_xform.c:1.28
--- src/sys/opencrypto/cryptosoft_xform.c:1.27	Thu Nov 27 15:30:21 2014
+++ src/sys/opencrypto/cryptosoft_xform.c	Fri Oct 11 20:49:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptosoft_xform.c,v 1.27 2014/11/27 20:30:21 christos Exp $ */
+/*	$NetBSD: cryptosoft_xform.c,v 1.28 2019/10/12 00:49:30 christos Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $	*/
 /*	$OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $	*/
 
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.27 2014/11/27 20:30:21 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.28 2019/10/12 00:49:30 christos Exp $");
 
 #include 
 #include 
@@ -313,26 +313,26 @@ static const struct swcr_auth_hash swcr_
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_256 = {
 	_hash_hmac_sha2_256, sizeof(SHA256_CTX),
-	(void (*)(void *)) SHA256_Init, NULL, NULL, SHA256Update_int,
-	(void (*)(u_int8_t *, void *)) SHA256_Final
+	(void (*)(void *))(void *)SHA256_Init, NULL, NULL, SHA256Update_int,
+	(void (*)(u_int8_t *, void *))(void *)SHA256_Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_384 = {
 	_hash_hmac_sha2_384, sizeof(SHA384_CTX),
-	(void (*)(void *)) SHA384_Init, NULL, NULL, SHA384Update_int,
-	(void (*)(u_int8_t *, void *)) SHA384_Final
+	(void (*)(void *))(void *)SHA384_Init, NULL, NULL, SHA384Update_int,
+	(void (*)(u_int8_t *, void *))(void *)SHA384_Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_512 = {
 	_hash_hmac_sha2_512, sizeof(SHA512_CTX),
-	(void (*)(void *)) SHA512_Init, NULL, NULL, SHA512Update_int,
-	(void (*)(u_int8_t *, void *)) SHA512_Final
+	(void (*)(void *))(void *)SHA512_Init, NULL, NULL, SHA512Update_int,
+	(void (*)(u_int8_t *, void *))(void *)SHA512_Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_aes_xcbc_mac = {
 	_hash_aes_xcbc_mac_96, sizeof(aesxcbc_ctx),
 	null_init,
-	(void (*)(void *, const u_int8_t *, u_int16_t))aes_xcbc_mac_init,
+	(void (*)(void *, const u_int8_t *, u_int16_t))(void *)aes_xcbc_mac_init,
 	NULL, aes_xcbc_mac_loop, aes_xcbc_mac_result
 };
 



CVS commit: src/sys/opencrypto

2019-10-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 12 00:49:30 UTC 2019

Modified Files:
src/sys/opencrypto: cryptosoft.c cryptosoft_xform.c

Log Message:
add (void *) intermediate casts to elide gcc function cast warnings. This
is the simplest solution; choices:
- add pragmas, complex and ugly (need to be gcc-specific)
- add -Wno to COPTS. Needs to be done in many makefiles because of rump
- add intermediate functions: slows down things


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/opencrypto/cryptosoft.c
cvs rdiff -u -r1.27 -r1.28 src/sys/opencrypto/cryptosoft_xform.c

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



CVS commit: src/sys/opencrypto

2019-07-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 11 23:28:17 UTC 2019

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

Log Message:
relinguish our lock while we are autoloading.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/opencrypto/crypto.c

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



CVS commit: src/sys/opencrypto

2019-07-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 11 23:28:17 UTC 2019

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

Log Message:
relinguish our lock while we are autoloading.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/opencrypto/crypto.c

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.107 src/sys/opencrypto/crypto.c:1.108
--- src/sys/opencrypto/crypto.c:1.107	Wed Jun 12 22:07:31 2019
+++ src/sys/opencrypto/crypto.c	Thu Jul 11 19:28:17 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.107 2019/06/13 02:07:31 christos Exp $ */
+/*	$NetBSD: crypto.c,v 1.108 2019/07/11 23:28:17 christos 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 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.107 2019/06/13 02:07:31 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.108 2019/07/11 23:28:17 christos Exp $");
 
 #include 
 #include 
@@ -812,7 +812,9 @@ again:
 	}
 
 	if (best == NULL && hard == 0 && error == 0) {
+		mutex_exit(_drv_mtx);
 		error = module_autoload("swcrypto", MODULE_CLASS_DRIVER);
+		mutex_enter(_drv_mtx);
 		if (error == 0) {
 			error = EINVAL;
 			goto again;



CVS commit: src/sys/opencrypto

2019-07-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 11 23:27:24 UTC 2019

Modified Files:
src/sys/opencrypto: cryptosoft.c

Log Message:
Disable unloading until we keep track of references


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/opencrypto/cryptosoft.c

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/cryptosoft.c
diff -u src/sys/opencrypto/cryptosoft.c:1.52 src/sys/opencrypto/cryptosoft.c:1.53
--- src/sys/opencrypto/cryptosoft.c:1.52	Fri Jun 23 07:41:58 2017
+++ src/sys/opencrypto/cryptosoft.c	Thu Jul 11 19:27:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptosoft.c,v 1.52 2017/06/23 11:41:58 knakahara Exp $ */
+/*	$NetBSD: cryptosoft.c,v 1.53 2019/07/11 23:27:24 christos Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $	*/
 /*	$OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $	*/
 
@@ -24,7 +24,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.52 2017/06/23 11:41:58 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.53 2019/07/11 23:27:24 christos Exp $");
 
 #include 
 #include 
@@ -1447,6 +1447,10 @@ swcrypto_modcmd(modcmd_t cmd, void *arg)
 #endif
 		return error;
 	case MODULE_CMD_FINI:
+#if 1
+		// XXX: Need to keep track if we are in use.
+		return ENOTTY;
+#else
 		error = config_cfdata_detach(swcrypto_cfdata);
 		if (error) {
 			return error;
@@ -1456,6 +1460,7 @@ swcrypto_modcmd(modcmd_t cmd, void *arg)
 		config_cfdriver_detach(_cd);
 
 		return 0;
+#endif
 	default:
 		return ENOTTY;
 	}



CVS commit: src/sys/opencrypto

2019-07-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 11 23:27:24 UTC 2019

Modified Files:
src/sys/opencrypto: cryptosoft.c

Log Message:
Disable unloading until we keep track of references


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/opencrypto/cryptosoft.c

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



CVS commit: src/sys/opencrypto

2019-06-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 13 02:07:31 UTC 2019

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

Log Message:
Try to load swcrypto if we we did not find any software drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/opencrypto/crypto.c

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.106 src/sys/opencrypto/crypto.c:1.107
--- src/sys/opencrypto/crypto.c:1.106	Tue Jun  5 21:49:09 2018
+++ src/sys/opencrypto/crypto.c	Wed Jun 12 22:07:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.106 2018/06/06 01:49:09 maya Exp $ */
+/*	$NetBSD: crypto.c,v 1.107 2019/06/13 02:07:31 christos 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 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.106 2018/06/06 01:49:09 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.107 2019/06/13 02:07:31 christos Exp $");
 
 #include 
 #include 
@@ -746,6 +746,7 @@ crypto_select_driver_lock(struct cryptoi
 	u_int32_t hid;
 	int accept;
 	struct cryptocap *cap, *best;
+	int error = 0;
 
 	best = NULL;
 	/*
@@ -810,6 +811,14 @@ again:
 		goto again;
 	}
 
+	if (best == NULL && hard == 0 && error == 0) {
+		error = module_autoload("swcrypto", MODULE_CLASS_DRIVER);
+		if (error == 0) {
+			error = EINVAL;
+			goto again;
+		}
+	}
+
 	return best;
 }
 



CVS commit: src/sys/opencrypto

2019-06-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 13 02:07:31 UTC 2019

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

Log Message:
Try to load swcrypto if we we did not find any software drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/opencrypto/crypto.c

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



CVS commit: src/sys/opencrypto

2019-06-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 13 02:02:45 UTC 2019

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

Log Message:
don't always panic when modunload crypto (int the pool destroy code, because
the pools are busy). XXX: this is still racy; we need to prevent creating
more sessions while destroying.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/opencrypto/cryptodev.c

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/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.100 src/sys/opencrypto/cryptodev.c:1.101
--- src/sys/opencrypto/cryptodev.c:1.100	Fri Mar  1 06:06:57 2019
+++ src/sys/opencrypto/cryptodev.c	Wed Jun 12 22:02:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptodev.c,v 1.100 2019/03/01 11:06:57 pgoyette Exp $ */
+/*	$NetBSD: cryptodev.c,v 1.101 2019/06/13 02:02:45 christos 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 
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.100 2019/03/01 11:06:57 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.101 2019/06/13 02:02:45 christos Exp $");
 
 #include 
 #include 
@@ -2246,6 +2246,8 @@ crypto_modcmd(modcmd_t cmd, void *arg)
 		return error;
 	case MODULE_CMD_FINI:
 #ifdef _MODULE
+		if (crypto_refcount != 0)
+			return EBUSY;
 		error = config_cfdata_detach(crypto_cfdata);
 		if (error) {
 			return error;



CVS commit: src/sys/opencrypto

2019-06-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 13 02:02:45 UTC 2019

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

Log Message:
don't always panic when modunload crypto (int the pool destroy code, because
the pools are busy). XXX: this is still racy; we need to prevent creating
more sessions while destroying.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/opencrypto/cryptodev.c

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



Re: CVS commit: src/sys/opencrypto

2017-04-18 Thread coypu
On Tue, Apr 18, 2017 at 05:05:06PM +, Maya Rashish wrote:
> XXX surrounding code seems fishy
> 
> @@ -759,7 +759,6 @@ swcr_compdec(struct cryptodesc *crd, con
>   if (result < crd->crd_len) {
>   adj = result - crd->crd_len;
>   if (outtype == CRYPTO_BUF_MBUF) {
> - adj = result - crd->crd_len;
>   m_adj((struct mbuf *)buf, adj);
>   }
>   /* Don't adjust the iov_len, it breaks the kmem_free */
> 


calling m_adj with negative adj sounds possibly unintended


Re: CVS commit: src/sys/opencrypto

2015-11-27 Thread Paul Goyette

On Fri, 27 Nov 2015, Christos Zoulas wrote:


Module Name:src
Committed By:   christos
Date:   Sat Nov 28 03:40:43 UTC 2015

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

Log Message:
fix the build


Thanks, and sorry for the breakage.



+--+--+-+
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| (Retired)| FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org  |
+--+--+-+


Re: CVS commit: src/sys/opencrypto

2014-01-27 Thread Paul Goyette

Taylor R Campbell wrote:


It seems to me that the crux of the problem is that devsw_detach
doesn't fail if the device is still in use, because we do keep no
books about which devsws are still in use, so there's nothing to stop
you from unloading a device's module before you've given a its close
routine a chance to clean up.

Would it suffice to add an open count to struct bdevsw and struct
cdevsw, to be maintained by {bdev,cdev}_{open,close}?


I think this would be sufficient.


A lesser problem is that the steps to finalize a device driver module
are complicated (attach/detach the devsw, the cfdriver, the cfattach,
the cfdata) and different drivers do them in a different order and may
or may not back out the same way (e.g., dtv(4) ignores devsw_detach
failure), so we ought to formalize what the right way to do this is
once we have a way that can work.


That would definitely be appreciated.

It would seem that config_{init,fini}_component() are intended to handle 
much/most of this, but these routines are not documented and not used 
universally. (see sys/kern/subr_autoconf.c)


-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


Re: CVS commit: src/sys/opencrypto

2014-01-26 Thread David Laight
On Sun, Jan 26, 2014 at 11:04:31AM +1100, matthew green wrote:
 
   phase one:  disable auto-unload.
  
   Phase 1 has been done.
  
   for the whole kernel?
  
  No.  Only for this specific module.
 
 right - my suggestion was that since this problem affects a
 large class of modules, until that is fixed, we should
 disable auto unload globally.

Does almost everything get loaded and auto-unloaded at boot time?
If so that that isn't really a good idea.

It also sounds like manual unloads of drivers can happen when the
device is open - and that is also bad.
A manual unload probably isn't going to race with open or close though.

Disallowing unload completely would be a pain when developing drivers.

David

-- 
David Laight: da...@l8s.co.uk


Re: CVS commit: src/sys/opencrypto

2014-01-26 Thread Taylor R Campbell
   Date: Sun, 26 Jan 2014 11:36:32 +
   From: David Laight da...@l8s.co.uk

   It also sounds like manual unloads of drivers can happen when the
   device is open - and that is also bad.
   A manual unload probably isn't going to race with open or close though.

   Disallowing unload completely would be a pain when developing drivers.

It seems to me that the crux of the problem is that devsw_detach
doesn't fail if the device is still in use, because we do keep no
books about which devsws are still in use, so there's nothing to stop
you from unloading a device's module before you've given a its close
routine a chance to clean up.

Would it suffice to add an open count to struct bdevsw and struct
cdevsw, to be maintained by {bdev,cdev}_{open,close}?

FreeBSD has a fancier reference-counting API for their devsw, but I'm
not sure why they need that.


A lesser problem is that the steps to finalize a device driver module
are complicated (attach/detach the devsw, the cfdriver, the cfattach,
the cfdata) and different drivers do them in a different order and may
or may not back out the same way (e.g., dtv(4) ignores devsw_detach
failure), so we ought to formalize what the right way to do this is
once we have a way that can work.


re: CVS commit: src/sys/opencrypto

2014-01-25 Thread matthew green

  Implement in-module ref-counting, and do not allow auto-unload if there
  are existing references.
  
  Note that manual unloading is not prevented.
  
  OK christos@
  
  XXX Also note that there is still a small window where the ref-count can
  XXX be decremented, and then the process/thread preempted.  If auto-unload
  XXX happens before that thread can return from the module's code, bad
  XXX things (tm) could happen.
 
 in this case, please simply disallow unload for this module always.
 if the race is fixed, it can be enabled again.
 
 I think that most module unloads suffer from this race, any ideas how to
 fix it?

phase one:  disable auto-unload.

phase two:  ???

the rest left as an exercise for the reader.  :-)


re: CVS commit: src/sys/opencrypto

2014-01-25 Thread Paul Goyette

Phase 1 has been done.

On Sat, 25 Jan 2014, matthew green wrote:




Implement in-module ref-counting, and do not allow auto-unload if there
are existing references.

Note that manual unloading is not prevented.

OK christos@

XXX Also note that there is still a small window where the ref-count can
XXX be decremented, and then the process/thread preempted.  If auto-unload
XXX happens before that thread can return from the module's code, bad
XXX things (tm) could happen.


in this case, please simply disallow unload for this module always.
if the race is fixed, it can be enabled again.


I think that most module unloads suffer from this race, any ideas how to
fix it?


phase one:  disable auto-unload.

phase two:  ???

the rest left as an exercise for the reader.  :-)

!DSPAM:52e37018210366601841969!




-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


re: CVS commit: src/sys/opencrypto

2014-01-25 Thread matthew green

  phase one:  disable auto-unload.

 Phase 1 has been done.

for the whole kernel?


re: CVS commit: src/sys/opencrypto

2014-01-25 Thread Paul Goyette

On Sun, 26 Jan 2014, matthew green wrote:




phase one:  disable auto-unload.



Phase 1 has been done.


for the whole kernel?


No.  Only for this specific module.


-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


re: CVS commit: src/sys/opencrypto

2014-01-25 Thread matthew green

  phase one:  disable auto-unload.
 
  Phase 1 has been done.
 
  for the whole kernel?
 
 No.  Only for this specific module.

right - my suggestion was that since this problem affects a
large class of modules, until that is fixed, we should
disable auto unload globally.


.mrg.


Re: CVS commit: src/sys/opencrypto

2014-01-24 Thread Christos Zoulas
In article 7458.1390534...@splode.eterna.com.au,
matthew green  m...@eterna.com.au wrote:

 Log Message:
 Implement in-module ref-counting, and do not allow auto-unload if there
 are existing references.
 
 Note that manual unloading is not prevented.
 
 OK christos@
 
 XXX Also note that there is still a small window where the ref-count can
 XXX be decremented, and then the process/thread preempted.  If auto-unload
 XXX happens before that thread can return from the module's code, bad
 XXX things (tm) could happen.

in this case, please simply disallow unload for this module always.
if the race is fixed, it can be enabled again.

I think that most module unloads suffer from this race, any ideas how to
fix it?

christos



Re: CVS commit: src/sys/opencrypto

2014-01-24 Thread Paul Goyette
Some modules get auto-loaded by the syscall mechanism.  We already have 
a mechanism to determine if any lwp's are currently executing these 
syscalls, and if yes we prevent auto-unload.


For device-driver modules, there is currently no equivalent mechanism. 
They get auto-loaded from code in specfs/vfsops as a result of trying to 
access the block/char device.  We would need to specify exactly what 
constitutes a reference and then keep track.  Is it only open that 
creates a reference?  Someone mentioned that it might be possible to 
read/write without opening the device...  Also need to consider what 
happens when the device is cloned ...


There is a refcount in the struct module, and a generic module_hold() / 
module_rele() mechanism to manipulate.  But it is currently used only 
for tracking inter-module references (ie, dependencies) as far as I can 
see.  It could be used here, but as currently implemented (linear search 
for module name) it's probably too expensive.


I'm not sure how we would handle miscellaneous modules...  :)




On Fri, 24 Jan 2014, Christos Zoulas wrote:


In article 7458.1390534...@splode.eterna.com.au,
matthew green  m...@eterna.com.au wrote:



Log Message:
Implement in-module ref-counting, and do not allow auto-unload if there
are existing references.

Note that manual unloading is not prevented.

OK christos@

XXX Also note that there is still a small window where the ref-count can
XXX be decremented, and then the process/thread preempted.  If auto-unload
XXX happens before that thread can return from the module's code, bad
XXX things (tm) could happen.


in this case, please simply disallow unload for this module always.
if the race is fixed, it can be enabled again.


I think that most module unloads suffer from this race, any ideas how to
fix it?

christos


!DSPAM:52e2a490250671524318036!




-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


Re: CVS commit: src/sys/opencrypto

2014-01-24 Thread Taylor R Campbell
   Date: Fri, 24 Jan 2014 17:35:41 + (UTC)
   From: chris...@astron.com (Christos Zoulas)

   In article 7458.1390534...@splode.eterna.com.au,
   matthew green  m...@eterna.com.au wrote:
   
Log Message:
XXX Also note that there is still a small window where the ref-count can
XXX be decremented, and then the process/thread preempted.  If auto-unload
XXX happens before that thread can return from the module's code, bad
XXX things (tm) could happen.
   
   in this case, please simply disallow unload for this module always.
   if the race is fixed, it can be enabled again.

   I think that most module unloads suffer from this race, any ideas how to
   fix it?

Shouldn't devsw_detach or config_fini_component handle this?  Why does
the crypto device need special reference counting that other devices
don't?


Re: CVS commit: src/sys/opencrypto

2014-01-24 Thread Paul Goyette

On Fri, 24 Jan 2014, Taylor R Campbell wrote:


Shouldn't devsw_detach or config_fini_component handle this?  Why does
the crypto device need special reference counting that other devices
don't?


The crypto device isn't special in this regard.  Pretty much all device 
driver modules need this sort of ref-counting.  Without it, the race 
exists and at some future time something will have reused/overwritten 
the memory previously occupied by the module, with non-deterministic 
results.


Crypto is special only in that it tried to do some clean-up during the 
detach.  The pool_destroy() code correctly noticed that there were still 
some outstanding allocations that had not been returned.  So we sort of 
got lucky here and found out about the problem immediately, rather 
than waiting for some non-deterministic future.



-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


re: CVS commit: src/sys/opencrypto

2014-01-23 Thread matthew green

 Log Message:
 Implement in-module ref-counting, and do not allow auto-unload if there
 are existing references.
 
 Note that manual unloading is not prevented.
 
 OK christos@
 
 XXX Also note that there is still a small window where the ref-count can
 XXX be decremented, and then the process/thread preempted.  If auto-unload
 XXX happens before that thread can return from the module's code, bad
 XXX things (tm) could happen.

in this case, please simply disallow unload for this module always.
if the race is fixed, it can be enabled again.


.mrg.


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Paul Goyette

On Sun, 19 Jan 2014, Christos Zoulas wrote:


Module Name:src
Committed By:   christos
Date:   Sun Jan 19 18:16:13 UTC 2014

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

Log Message:
bail out unloading for now


How about the following changes?

@@ -143,6 +143,8 @@ static int  cryptoread(dev_t dev, struct
 static int cryptowrite(dev_t dev, struct uio *uio, int ioflag);
 static int cryptoselect(dev_t dev, int rw, struct lwp *l);

+static int crypto_refcount = 0;/* Prevent detaching while in use */
+
 /* Declaration of cloned-device (per-ctxt) entrypoints */
 static int cryptof_read(struct file *, off_t *, struct uio *,
 kauth_cred_t, int);
@@ -262,6 +264,7 @@ cryptof_ioctl(struct file *fp, u_long cm
  */
criofcr-sesn = 1;
criofcr-requestid = 1;
+   crypto_refcount++;
mutex_exit(crypto_mtx);
(void)fd_clone(criofp, criofd, (FREAD|FWRITE),
  cryptofops, criofcr);
@@ -951,6 +954,7 @@ cryptof_close(struct file *fp)
}
seldestroy(fcr-sinfo);
fp-f_data = NULL;
+   crypto_refcount--;
mutex_exit(crypto_mtx);

pool_put(fcrpl, fcr);
@@ -1080,6 +1084,7 @@ cryptoopen(dev_t dev, int flag, int mode
 */
fcr-sesn = 1;
fcr-requestid = 1;
+   crypto_refcount++;
mutex_exit(crypto_mtx);
return fd_clone(fp, fd, flag, cryptofops, fcr);
 }
@@ -2109,6 +2114,10 @@ int  crypto_detach(device_t, int);
 int
 crypto_detach(device_t self, int num)
 {
+
+   if (crypto_refcount != 0 || self-dv_unit != 0)
+   return EBUSY;
+
pool_destroy(fcrpl);
pool_destroy(csepl);






To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/opencrypto/cryptodev.c

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


!DSPAM:52dc1675236281199521295!




-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Christos Zoulas
On Jan 19, 10:22am, p...@whooppee.com (Paul Goyette) wrote:
-- Subject: Re: CVS commit: src/sys/opencrypto

| How about the following changes?

You need to handle the regular open too, not justthe get (look for the
other fd_clone)

| @@ -143,6 +143,8 @@ static intcryptoread(dev_t dev, struct
|   static int  cryptowrite(dev_t dev, struct uio *uio, int ioflag);
|   static int  cryptoselect(dev_t dev, int rw, struct lwp *l);
| 
| +static int   crypto_refcount = 0;/* Prevent detaching while in use */
| +
|   /* Declaration of cloned-device (per-ctxt) entrypoints */
|   static int  cryptof_read(struct file *, off_t *, struct uio *,
|   kauth_cred_t, int);
| @@ -262,6 +264,7 @@ cryptof_ioctl(struct file *fp, u_long cm
|*/
|   criofcr-sesn = 1;
|   criofcr-requestid = 1;
| + crypto_refcount++;
|   mutex_exit(crypto_mtx);
|   (void)fd_clone(criofp, criofd, (FREAD|FWRITE),
| cryptofops, criofcr);
| @@ -951,6 +954,7 @@ cryptof_close(struct file *fp)
|   }
|   seldestroy(fcr-sinfo);
|   fp-f_data = NULL;
| + crypto_refcount--;
|   mutex_exit(crypto_mtx);
| 
|   pool_put(fcrpl, fcr);
| @@ -1080,6 +1084,7 @@ cryptoopen(dev_t dev, int flag, int mode
|*/
|   fcr-sesn = 1;
|   fcr-requestid = 1;
| + crypto_refcount++;
|   mutex_exit(crypto_mtx);
|   return fd_clone(fp, fd, flag, cryptofops, fcr);
|   }
| @@ -2109,6 +2114,10 @@ intcrypto_detach(device_t, int);

It is not just the detach we need to handle, it is the module unload too
(look for FINI).

|   int
|   crypto_detach(device_t self, int num)
|   {
| +
| + if (crypto_refcount != 0 || self-dv_unit != 0)
| + return EBUSY;
| +
|   pool_destroy(fcrpl);
|   pool_destroy(csepl);

christos


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Christos Zoulas
On Jan 19, 10:37am, p...@whooppee.com (Paul Goyette) wrote:
-- Subject: Re: CVS commit: src/sys/opencrypto

| That's covered in cryptoopen() at line 1060

I missed that patch

| Handled indirectly.  The MODULE_CMD_FINI calls config_cfdata_detach() 
| which attempts to detach each device instance.  If a detach fails, then 
| config_cfdata_detach fails, and the unload will fail.

Ok then! Did you test it? If it works, I guess commit it.

christos


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Paul Goyette

On Sun, 19 Jan 2014, Christos Zoulas wrote:


On Jan 19, 10:37am, p...@whooppee.com (Paul Goyette) wrote:
-- Subject: Re: CVS commit: src/sys/opencrypto

| That's covered in cryptoopen() at line 1060

I missed that patch


No worry.


| Handled indirectly.  The MODULE_CMD_FINI calls config_cfdata_detach()
| which attempts to detach each device instance.  If a detach fails, then
| config_cfdata_detach fails, and the unload will fail.

Ok then! Did you test it? If it works, I guess commit it.


It does address the simple case I described.  It has a minor/cosmetic 
issue of printing an error message


crypto0: unable to detach instance

from config_cfdata_detach().

But David Laight's post has me more concerned, that perhaps we really 
need to solve this sort of issue more generically.


So, not sure if this should be committed, or if we should leave your 
code in to prevent unload in all cases.




-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Christos Zoulas
On Jan 19, 11:21am, p...@whooppee.com (Paul Goyette) wrote:
-- Subject: Re: CVS commit: src/sys/opencrypto

|  | Handled indirectly.  The MODULE_CMD_FINI calls config_cfdata_detach()
|  | which attempts to detach each device instance.  If a detach fails, then
|  | config_cfdata_detach fails, and the unload will fail.
| 
|  Ok then! Did you test it? If it works, I guess commit it.
| 
| It does address the simple case I described.  It has a minor/cosmetic 
| issue of printing an error message
| 
|   crypto0: unable to detach instance
| 
| from config_cfdata_detach().

yes, it looks like it is not designed to be called if it is not going
to work. This is why most other things do the test in the MODULE_FINI
part, see bpf for example.

| But David Laight's post has me more concerned, that perhaps we really 
| need to solve this sort of issue more generically.

Yes, this is why I took the EOPNOTSUPP shortcut.

| So, not sure if this should be committed, or if we should leave your 
| code in to prevent unload in all cases.

Well, you can move your test from detach to MODULE_FINI and it should
work just fine. But yes, we should solve it more generically, but I still
think the reference counting code is needed.

christos


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Paul Goyette

On Sun, 19 Jan 2014, John Nemeth wrote:


} Handled indirectly.  The MODULE_CMD_FINI calls config_cfdata_detach()
} which attempts to detach each device instance.  If a detach fails, then
} config_cfdata_detach fails, and the unload will fail.

Does this mean that you'll end up with some device instances
detached and not others?


Nope.

All non-zero units are prevented from unload.  And unit zero is 
permitted only if there are no references, ie no clones.


So the master gets deleted only if there are no non-zero units.


-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Christos Zoulas
In article pine.neb.4.64.1401191416060.22...@screamer.whooppee.com,
Paul Goyette  p...@whooppee.com wrote:
On Sun, 19 Jan 2014, John Nemeth wrote:

 } Handled indirectly.  The MODULE_CMD_FINI calls config_cfdata_detach()
 } which attempts to detach each device instance.  If a detach fails, then
 } config_cfdata_detach fails, and the unload will fail.

 Does this mean that you'll end up with some device instances
 detached and not others?

Nope.

All non-zero units are prevented from unload.  And unit zero is 
permitted only if there are no references, ie no clones.

I don't see why non-zero units are special, can you explain? Open zero
open 1, close 0, close 1. Should the close 1 unload?

christos



Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread John Nemeth
On Jan 19, 10:37am, Paul Goyette wrote:
} On Sun, 19 Jan 2014, Christos Zoulas wrote:
}  On Jan 19, 10:22am, p...@whooppee.com (Paul Goyette) wrote:
} 
}  | How about the following changes?
} 
}  You need to handle the regular open too, not justthe get (look for the
}  other fd_clone)
} 
} That's covered in cryptoopen() at line 1060
} 
}  | @@ -143,6 +143,8 @@ static intcryptoread(dev_t dev, struct
}  |   static int  cryptowrite(dev_t dev, struct uio *uio, int ioflag);
}  |   static int  cryptoselect(dev_t dev, int rw, struct lwp *l);
}  |
}  | +static int   crypto_refcount = 0;/* Prevent detaching while in 
use */
}  | +
}  |   /* Declaration of cloned-device (per-ctxt) entrypoints */
}  |   static int  cryptof_read(struct file *, off_t *, struct uio *,
}  |   kauth_cred_t, int);
}  | @@ -262,6 +264,7 @@ cryptof_ioctl(struct file *fp, u_long cm
}  |*/
}  |   criofcr-sesn = 1;
}  |   criofcr-requestid = 1;
}  | + crypto_refcount++;
}  |   mutex_exit(crypto_mtx);
}  |   (void)fd_clone(criofp, criofd, (FREAD|FWRITE),
}  | cryptofops, criofcr);
}  | @@ -951,6 +954,7 @@ cryptof_close(struct file *fp)
}  |   }
}  |   seldestroy(fcr-sinfo);
}  |   fp-f_data = NULL;
}  | + crypto_refcount--;
}  |   mutex_exit(crypto_mtx);
}  |
}  |   pool_put(fcrpl, fcr);
}  | @@ -1080,6 +1084,7 @@ cryptoopen(dev_t dev, int flag, int mode
}  |*/
}  |   fcr-sesn = 1;
}  |   fcr-requestid = 1;
}  | + crypto_refcount++;
}  |   mutex_exit(crypto_mtx);
}  |   return fd_clone(fp, fd, flag, cryptofops, fcr);
}  |   }
}  | @@ -2109,6 +2114,10 @@ intcrypto_detach(device_t, int);
} 
}  It is not just the detach we need to handle, it is the module unload too
}  (look for FINI).
} 
} Handled indirectly.  The MODULE_CMD_FINI calls config_cfdata_detach() 
} which attempts to detach each device instance.  If a detach fails, then 
} config_cfdata_detach fails, and the unload will fail.

 Does this mean that you'll end up with some device instances
detached and not others?

}-- End of excerpt from Paul Goyette


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Paul Goyette
The mere existence of a non-zero unit is a reference that needs to 
prevent unloading.


The two checks (unit# and ref-count) are equivalent and redundant, and 
only one of them needs to be there.



On Sun, 19 Jan 2014, Christos Zoulas wrote:


In article pine.neb.4.64.1401191416060.22...@screamer.whooppee.com,
Paul Goyette  p...@whooppee.com wrote:

On Sun, 19 Jan 2014, John Nemeth wrote:


} Handled indirectly.  The MODULE_CMD_FINI calls config_cfdata_detach()
} which attempts to detach each device instance.  If a detach fails, then
} config_cfdata_detach fails, and the unload will fail.

Does this mean that you'll end up with some device instances
detached and not others?


Nope.

All non-zero units are prevented from unload.  And unit zero is
permitted only if there are no references, ie no clones.


I don't see why non-zero units are special, can you explain? Open zero
open 1, close 0, close 1. Should the close 1 unload?

christos


!DSPAM:52dc4fde23811308416388!




-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Christos Zoulas
On Jan 19,  3:04pm, p...@whooppee.com (Paul Goyette) wrote:
-- Subject: Re: CVS commit: src/sys/opencrypto

| The mere existence of a non-zero unit is a reference that needs to 
| prevent unloading.

What if it is the last reference? Then the ref count will go to zero after
close without unloading, and you'll never unload.

| The two checks (unit# and ref-count) are equivalent and redundant, and 
| only one of them needs to be there.

Well, just keep the refcount one then.

christos


Re: CVS commit: src/sys/opencrypto

2014-01-19 Thread Paul Goyette

On Sun, 19 Jan 2014, Christos Zoulas wrote:


On Jan 19,  3:04pm, p...@whooppee.com (Paul Goyette) wrote:
-- Subject: Re: CVS commit: src/sys/opencrypto

| The mere existence of a non-zero unit is a reference that needs to
| prevent unloading.

What if it is the last reference? Then the ref count will go to zero after
close without unloading, and you'll never unload.

| The two checks (unit# and ref-count) are equivalent and redundant, and
| only one of them needs to be there.

Well, just keep the refcount one then.


Yup - that's what I committed.

The device_t wasn't available anyway, in crypto_modcmd()   :)


-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-