Source-Changes-HG archive

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

[src/trunk]: src/sys/opencrypto refactor crypto_dispatch (3/3): do "blocked" ...



details:   https://anonhg.NetBSD.org/src/rev/ac16164cb95b
branches:  trunk
changeset: 353674:ac16164cb95b
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Wed May 17 06:53:02 2017 +0000

description:
refactor crypto_dispatch (3/3): do "blocked" operation previously

diffstat:

 sys/opencrypto/crypto.c |  66 +++++++++++++++++++++++++-----------------------
 1 files changed, 35 insertions(+), 31 deletions(-)

diffs (96 lines):

diff -r 936490336c19 -r ac16164cb95b sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c   Wed May 17 06:52:08 2017 +0000
+++ b/sys/opencrypto/crypto.c   Wed May 17 06:53:02 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crypto.c,v 1.66 2017/05/17 06:52:08 knakahara Exp $ */
+/*     $NetBSD: crypto.c,v 1.67 2017/05/17 06:53:02 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.66 2017/05/17 06:52:08 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.67 2017/05/17 06:53:02 knakahara Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -792,44 +792,48 @@
        }
 
        /*
-        * Caller marked the request to be processed
-        * immediately; dispatch it directly to the
-        * driver unless the driver is currently blocked.
+        * TODO:
+        * cap->cc_qblocked should be protected by a spin lock other than
+        * crypto_q_mtx.
         */
-       if (!cap->cc_qblocked) {
-               mutex_spin_exit(&crypto_q_mtx);
-               result = crypto_invoke(crp, 0);
-               if (result == ERESTART) {
-                       /*
-                        * The driver ran out of resources, mark the
-                        * driver ``blocked'' for cryptop's and put
-                        * the op on the queue.
-                        */
-                       mutex_spin_enter(&crypto_q_mtx);
-                       crypto_drivers[hid].cc_qblocked = 1;
-                       TAILQ_INSERT_HEAD(&crp_q, crp, crp_next);
-                       cryptostats.cs_blocks++;
-                       mutex_spin_exit(&crypto_q_mtx);
-
-                       /*
-                        * The crp is enqueued to crp_q, that is,
-                        * no error occurs. So, this function should
-                        * not return error.
-                        */
-                       result = 0;
-               }
-               goto out_released;
-       } else {
+       if (cap->cc_qblocked != 0) {
                /*
                 * The driver is blocked, just queue the op until
                 * it unblocks and the swi thread gets kicked.
                 */
                TAILQ_INSERT_TAIL(&crp_q, crp, crp_next);
+               mutex_spin_exit(&crypto_q_mtx);
+
+               return 0;
+       }
+
+       /*
+        * Caller marked the request to be processed
+        * immediately; dispatch it directly to the
+        * driver unless the driver is currently blocked.
+        */
+       mutex_spin_exit(&crypto_q_mtx);
+       result = crypto_invoke(crp, 0);
+       if (result == ERESTART) {
+               /*
+                * The driver ran out of resources, mark the
+                * driver ``blocked'' for cryptop's and put
+                * the op on the queue.
+                */
+               mutex_spin_enter(&crypto_q_mtx);
+               crypto_drivers[hid].cc_qblocked = 1;
+               TAILQ_INSERT_HEAD(&crp_q, crp, crp_next);
+               cryptostats.cs_blocks++;
+               mutex_spin_exit(&crypto_q_mtx);
+
+               /*
+                * The crp is enqueued to crp_q, that is,
+                * no error occurs. So, this function should
+                * not return error.
+                */
                result = 0;
        }
 
-       mutex_spin_exit(&crypto_q_mtx);
-out_released:
        return result;
 }
 



Home | Main Index | Thread Index | Old Index