Source-Changes-HG archive

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

[src/pgoyette-compat]: src/sys When the compat code needs to callback to the ...



details:   https://anonhg.NetBSD.org/src/rev/fd225b047597
branches:  pgoyette-compat
changeset: 830743:fd225b047597
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Sep 22 10:33:50 2018 +0000

description:
When the compat code needs to callback to the original code, we cannot
call directly via the routines' global symbols, since the original code
might not be built-in.  So, the original code that calls compat code
needs to pass in the addresses of the callbacks.  This allows for the
compat code to be built whether or not the original (calling) code is
included.

XXX Done for cryptodev, will need to do the same thing for ccd(4) and
XXX vnd(4)

diffstat:

 sys/opencrypto/cryptodev.c  |  23 ++++++++++++++----
 sys/opencrypto/ocryptodev.c |  56 ++++++++++++++++++++++++++++----------------
 sys/opencrypto/ocryptodev.h |  10 ++++---
 sys/sys/compat_stub.h       |  14 +++++++++-
 4 files changed, 72 insertions(+), 31 deletions(-)

diffs (265 lines):

diff -r 564f242b7dff -r fd225b047597 sys/opencrypto/cryptodev.c
--- a/sys/opencrypto/cryptodev.c        Sat Sep 22 10:30:53 2018 +0000
+++ b/sys/opencrypto/cryptodev.c        Sat Sep 22 10:33:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cryptodev.c,v 1.98.2.4 2018/09/18 23:03:55 pgoyette Exp $ */
+/*     $NetBSD: cryptodev.c,v 1.98.2.5 2018/09/22 10:33:50 pgoyette 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.98.2.4 2018/09/18 23:03:55 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.98.2.5 2018/09/22 10:33:50 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -219,11 +219,24 @@
        return EIO;
 }
 
-/* Hook the ocryptodev 50 compat code */
+/*
+ * Hook the ocryptodev 50 compat code
+ *
+ * This is a bit messy because we need to pass local stuff to the
+ * compat routines.  The compat routines may be built-in to a
+ * kernel which doesn't contain the local stuff, so the compat
+ * code cannot directly reference them as globals.
+ */
 MODULE_CALL_HOOK_DECL(ocryptof_50_hook, f,
-    (struct file *fp, u_long cmd, void *data), (fp, cmd, data), enosys());
+    (struct file *fp, u_long cmd, void *data),
+    (fp, cmd, data, cryptodev_mtx, cryptodev_session, cryptodev_op,
+       cryptodev_mop, cryptodev_csefind),
+    enosys());
 MODULE_CALL_HOOK(ocryptof_50_hook, f,
-    (struct file *fp, u_long cmd, void *data), (fp, cmd, data), enosys());
+    (struct file *fp, u_long cmd, void *data),
+    (fp, cmd, data, &cryptodev_mtx, cryptodev_session, cryptodev_op,
+       cryptodev_mop, cryptodev_csefind),
+    enosys());
 
 /* ARGSUSED */
 int
diff -r 564f242b7dff -r fd225b047597 sys/opencrypto/ocryptodev.c
--- a/sys/opencrypto/ocryptodev.c       Sat Sep 22 10:30:53 2018 +0000
+++ b/sys/opencrypto/ocryptodev.c       Sat Sep 22 10:33:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ocryptodev.c,v 1.11.2.3 2018/09/18 23:03:55 pgoyette Exp $ */
+/*     $NetBSD: ocryptodev.c,v 1.11.2.4 2018/09/22 10:33:50 pgoyette 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 $   */
 
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ocryptodev.c,v 1.11.2.3 2018/09/18 23:03:55 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ocryptodev.c,v 1.11.2.4 2018/09/22 10:33:50 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -101,14 +101,23 @@
 #include <opencrypto/xform.h>
 
 static int     ocryptodev_op(struct csession *, struct ocrypt_op *,
-                   struct lwp *);
+                   struct lwp *, int (*)(struct csession *, 
+                                       struct crypt_op *, struct lwp *));
 static int     ocryptodev_mop(struct fcrypt *, struct ocrypt_n_op *, int,
-                   struct lwp *);
-static int     ocryptodev_session(struct fcrypt *, struct osession_op *);
-static int     ocryptodev_msession(struct fcrypt *, struct osession_n_op *, int);
+                   struct lwp *,
+                   int (*real_mop)(struct fcrypt *, struct crypt_n_op *,
+                        int, struct lwp *));
+static int     ocryptodev_session(struct fcrypt *, struct osession_op *,
+                       int(*)(struct fcrypt *, struct session_op *));
+static int     ocryptodev_msession(struct fcrypt *, struct osession_n_op *,
+                       int, int (*)(struct fcrypt *, struct session_op *));
 
 int
-ocryptof_ioctl(struct file *fp, u_long cmd, void *data)
+ocryptof_ioctl(struct file *fp, u_long cmd, void *data, kmutex_t *mtx,
+    int (*real_session)(struct fcrypt *, struct session_op *),
+    int (*real_op)(struct csession *, struct crypt_op *, struct lwp *),
+    int (*real_mop)(struct fcrypt *, struct crypt_n_op *, int, struct lwp *),
+    struct csession * (*real_csefind)(struct fcrypt *, u_int32_t))
 {
        struct fcrypt *fcr = fp->f_fcrypt;
        struct csession *cse;
@@ -124,7 +133,7 @@
        switch (cmd) {
        case OCIOCGSESSION:
                osop = (struct osession_op *)data;
-               error = ocryptodev_session(fcr, osop);
+               error = ocryptodev_session(fcr, osop, real_session);
                break;
        case CIOCNGSESSION:
                osgop = (struct ocrypt_sgop *)data;
@@ -141,7 +150,8 @@
                        goto mbail;
                }
 
-               error = ocryptodev_msession(fcr, osnop, osgop->count);
+               error = ocryptodev_msession(fcr, osnop, osgop->count,
+                   real_session);
                if (error) {
                        goto mbail;
                }
@@ -154,13 +164,13 @@
        case OCIOCCRYPT:
                mutex_enter(&cryptodev_mtx);
                ocop = (struct ocrypt_op *)data;
-               cse = cryptodev_csefind(fcr, ocop->ses);
+               cse = (*real_csefind)(fcr, ocop->ses);
                mutex_exit(&cryptodev_mtx);
                if (cse == NULL) {
                        DPRINTF("csefind failed\n");
                        return EINVAL;
                }
-               error = ocryptodev_op(cse, ocop, curlwp);
+               error = ocryptodev_op(cse, ocop, curlwp, real_op);
                DPRINTF("ocryptodev_op error = %d\n", error);
                break;
        case OCIOCNCRYPTM:
@@ -175,7 +185,8 @@
                error = copyin(omop->reqs, ocnop,
                    (omop->count * sizeof(struct ocrypt_n_op)));
                if(!error) {
-                       error = ocryptodev_mop(fcr, ocnop, omop->count, curlwp);
+                       error = ocryptodev_mop(fcr, ocnop, omop->count,
+                           curlwp, real_mop);
                        if (!error) {
                                error = copyout(ocnop, omop->reqs, 
                                    (omop->count * sizeof(struct ocrypt_n_op)));
@@ -192,7 +203,8 @@
 
 
 static int
-ocryptodev_op(struct csession *cse, struct ocrypt_op *ocop, struct lwp *l)
+ocryptodev_op(struct csession *cse, struct ocrypt_op *ocop, struct lwp *l,
+    int (*real_op)(struct csession *, struct crypt_op *, struct lwp *))
 {
        struct crypt_op cop;
 
@@ -206,13 +218,15 @@
        cop.iv = ocop->iv;
        cop.dst_len = 0;
 
-       return cryptodev_op(cse, &cop, l);
+       return real_op(cse, &cop, l);
 };
 
 static int 
 ocryptodev_mop(struct fcrypt *fcr, 
               struct ocrypt_n_op *ocnop,
-              int count, struct lwp *l)
+              int count, struct lwp *l,
+             int (*real_mop)(struct fcrypt *, struct crypt_n_op *, int,
+                               struct lwp *))
 {
        int res;
 
@@ -234,7 +248,7 @@
        cnop.mac = ocnop->mac;
        cnop.iv = ocnop->iv;
        cnop.dst_len = 0;
-       res = cryptodev_mop(fcr, &cnop, count, l);
+       res = (*real_mop)(fcr, &cnop, count, l);
        ocnop->reqid = cnop.reqid;
        ocnop->status = cnop.status;
 
@@ -243,7 +257,8 @@
 
 
 static int
-ocryptodev_session(struct fcrypt *fcr, struct osession_op *osop) 
+ocryptodev_session(struct fcrypt *fcr, struct osession_op *osop,
+    int (*real_session)(struct fcrypt *, struct session_op *))
 {
        struct session_op sop;
        int res;
@@ -255,7 +270,7 @@
        sop.key = osop->key;
        sop.mackeylen = osop->mackeylen;
        sop.mackey = osop->mackey;
-       res = cryptodev_session(fcr, &sop);
+       res = (*real_session)(fcr, &sop);
        if (res)
                return res;
        osop->ses = sop.ses;
@@ -265,7 +280,8 @@
 
 static int
 ocryptodev_msession(struct fcrypt *fcr, struct osession_n_op *osn_ops,
-                  int count)
+                  int count,
+                  int (*real_session)(struct fcrypt *, struct session_op *))
 {
        int i;
 
@@ -278,7 +294,7 @@
                os_op.mackeylen =       osn_ops->mackeylen;
                os_op.mackey =          osn_ops->mackey;
 
-               osn_ops->status = ocryptodev_session(fcr, &os_op);
+               osn_ops->status = ocryptodev_session(fcr, &os_op, real_session);
                osn_ops->ses =          os_op.ses;
        }
 
diff -r 564f242b7dff -r fd225b047597 sys/opencrypto/ocryptodev.h
--- a/sys/opencrypto/ocryptodev.h       Sat Sep 22 10:30:53 2018 +0000
+++ b/sys/opencrypto/ocryptodev.h       Sat Sep 22 10:33:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ocryptodev.h,v 1.3.16.1 2018/03/23 09:41:10 pgoyette Exp $ */
+/*     $NetBSD: ocryptodev.h,v 1.3.16.2 2018/09/22 10:33:50 pgoyette 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 $      */
 
@@ -170,9 +170,11 @@
 #define OCIOCCRYPT     _IOWR('c', 103, struct ocrypt_op)
 #define OCIOCNCRYPTM   _IOWR('c', 107, struct ocrypt_mop)
 
-int ocryptof_ioctl(struct file *, u_long, void *);
-
-extern int (*ocryptof50_ioctl)(struct file *, u_long, void *);
+int ocryptof_ioctl(struct file *, u_long, void *, kmutex_t *,
+    int (*)(struct fcrypt *, struct session_op *),
+    int (*)(struct csession *, struct crypt_op *, struct lwp *),
+    int (*)(struct fcrypt *, struct crypt_n_op *, int, struct lwp *),
+    struct csession * (*)(struct fcrypt *, u_int32_t));
 
 void cryptodev_50_init(void);
 void cryptodev_50_fini(void);
diff -r 564f242b7dff -r fd225b047597 sys/sys/compat_stub.h
--- a/sys/sys/compat_stub.h     Sat Sep 22 10:30:53 2018 +0000
+++ b/sys/sys/compat_stub.h     Sat Sep 22 10:33:50 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.h,v 1.1.2.33 2018/09/21 03:42:20 pgoyette Exp $        */
+/* $NetBSD: compat_stub.h,v 1.1.2.34 2018/09/22 10:33:51 pgoyette Exp $        */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -86,7 +86,17 @@
  * cryptodev compatability ioctl
  */
 
-MODULE_HOOK(ocryptof_50_hook, (struct file *, u_long, void *));
+struct fcrypt;
+struct session_op;
+struct csession;
+struct crypt_op;
+struct crypt_n_op;
+struct kmutex_t;
+MODULE_HOOK(ocryptof_50_hook, (struct file *, u_long, void *, kmutex_t *,
+    int (*)(struct fcrypt *, struct session_op *),
+    int (*)(struct csession *, struct crypt_op *, struct lwp *),
+    int (*)(struct fcrypt *, struct crypt_n_op *, int, struct lwp *),
+    struct csession * (*)(struct fcrypt *, u_int32_t)));
 
 /*
  * raidframe compatability



Home | Main Index | Thread Index | Old Index