Source-Changes-HG archive

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

[src/trunk]: src/sys/opencrypto fix panic when using ecryption devices attach...



details:   https://anonhg.NetBSD.org/src/rev/5c03379cd7d2
branches:  trunk
changeset: 355236:5c03379cd7d2
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Thu Jul 20 09:31:36 2017 +0000

description:
fix panic when using ecryption devices attached earlier than ipi_sysinit().

pointed out and tested by martin@n.o, thanks.

diffstat:

 sys/opencrypto/crypto.c |  29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

diffs (71 lines):

diff -r 4015c3a79c5e -r 5c03379cd7d2 sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c   Thu Jul 20 08:07:14 2017 +0000
+++ b/sys/opencrypto/crypto.c   Thu Jul 20 09:31:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crypto.c,v 1.92 2017/07/18 06:01:36 knakahara Exp $ */
+/*     $NetBSD: crypto.c,v 1.93 2017/07/20 09:31:36 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.92 2017/07/18 06:01:36 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.93 2017/07/20 09:31:36 knakahara Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -68,6 +68,7 @@
 #include <sys/errno.h>
 #include <sys/module.h>
 #include <sys/xcall.h>
+#include <sys/device.h>
 
 #if defined(_KERNEL_OPT)
 #include "opt_ocf.h"
@@ -382,6 +383,8 @@
 static void crypto_driver_unlock(struct cryptocap *);
 static void crypto_driver_clear(struct cryptocap *);
 
+static int crypto_init_finalize(device_t);
+
 static struct cryptostats cryptostats;
 #ifdef CRYPTO_TIMING
 static int crypto_timing = 0;
@@ -417,10 +420,13 @@
                return crypto_destroy(false);
        }
 
-       crypto_ret_si = softint_establish(SOFTINT_NET|SOFTINT_MPSAFE|SOFTINT_RCPU,
-           &cryptoret_softint, NULL);
-       if (crypto_ret_si == NULL) {
-               printf("crypto_init: cannot establish ret queue handler\n");
+       /*
+        * Some encryption devices(such as mvcesa) is attached before
+        * ipi_sysinit(). That causes assertion in ipi_register() as
+        * crypto_ret_si softint uses SOFTINT_RCPU.
+        */
+       if (config_finalize_register(NULL, crypto_init_finalize) != 0) {
+               printf("crypto_init: cannot register crypto_init_finalize\n");
                return crypto_destroy(false);
        }
 
@@ -429,6 +435,17 @@
        return 0;
 }
 
+static int
+crypto_init_finalize(device_t self __unused)
+{
+
+       crypto_ret_si = softint_establish(SOFTINT_NET|SOFTINT_MPSAFE|SOFTINT_RCPU,
+           &cryptoret_softint, NULL);
+       KASSERT(crypto_ret_si != NULL);
+
+       return 0;
+}
+
 int
 crypto_init(void)
 {



Home | Main Index | Thread Index | Old Index