Re: [Ocf-linux-users] crypto_newsession / crypto_freesession
                
                Brought to you by:
                
                    david-m
                    
                
            
            
        
        
        
    | 
      
      
      From: Pirasenna T. <pir...@gm...> - 2009-01-30 08:01:06
      
     | 
| diff -ruw /export/tmp/linux-2.6.17.10/crypto/ocf/crypto.c ./crypto.c
--- /export/tmp/linux-2.6.17.10/crypto/ocf/crypto.c	2009-01-29 10:10:36.000000000 -0800
+++ ./crypto.c	2009-01-29 18:54:59.000000000 -0800
@@ -389,17 +389,14 @@
 		/* Call the driver initialization routine. */
 		hid = cap - crypto_drivers;
 		lid = hid;		/* Pass the driver ID. */
-		cap->cc_sessions++;
 		CRYPTO_DRIVER_UNLOCK();
-		err = CRYPTODEV_NEWSESSION(cap->cc_dev, &lid, cri);
+		err = CRYPTODEV_NEWSESSION(cap->cc_dev, &sid[0], cri);
 		CRYPTO_DRIVER_LOCK();
 		if (err == 0) {
-			(*sid) = (cap->cc_flags & 0xff000000)
-			       | (hid & 0x00ffffff);
-			(*sid) <<= 32;
-			(*sid) |= (lid & 0xffffffff);
-		} else
-			cap->cc_sessions--;
+			cap->cc_sessions++;
+			(sid[1]) = ((cap->cc_flags & 0xff000000)
+			       | (hid & 0x00ffffff)) & 0xffffffff;
+		}
 	} else
 		err = EINVAL;
 	CRYPTO_DRIVER_UNLOCK();
@@ -419,7 +416,7 @@
  * driver).
  */
 int
-crypto_freesession(u_int64_t sid)
+crypto_freesession(u_int64_t *sid)
 {
 	struct cryptocap *cap;
 	u_int32_t hid;
@@ -447,7 +444,7 @@
 	if (cap->cc_dev) {
 		CRYPTO_DRIVER_UNLOCK();
 		/* Call the driver cleanup routine, if available, unlocked. */
-		err = CRYPTODEV_FREESESSION(cap->cc_dev, sid);
+		err = CRYPTODEV_FREESESSION(cap->cc_dev, CRYPTO_SESID2LID(sid));
 		CRYPTO_DRIVER_LOCK();
 	}
 
@@ -1014,7 +1011,7 @@
 #endif
 	if (cap->cc_flags & CRYPTOCAP_F_CLEANUP) {
 		struct cryptodesc *crd;
-		u_int64_t nid;
+		u_int64_t nid[2];
 
 		/*
 		 * Driver has unregistered; migrate the session and return
@@ -1030,8 +1027,10 @@
 
 		/* XXX propagate flags from initial session? */
 		if (crypto_newsession(&nid, &(crp->crp_desc->CRD_INI),
-		    CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE) == 0)
-			crp->crp_sid = nid;
+				      CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE) == 0) {
+			crp->crp_sid[0] = nid[0];
+			crp->crp_sid[1] = nid[1];
+		}
 
 		crp->crp_etype = EAGAIN;
 		crypto_done(crp);
diff -ruw /export/tmp/linux-2.6.17.10/crypto/ocf/cryptodev.c ./cryptodev.c
--- /export/tmp/linux-2.6.17.10/crypto/ocf/cryptodev.c	2009-01-29 10:10:36.000000000 -0800
+++ ./cryptodev.c	2009-01-29 23:39:00.000000000 -0800
@@ -82,7 +82,7 @@
 
 struct csession {
 	struct list_head	list;
-	u_int64_t	sid;
+	u_int64_t	sid[2];
 	u_int32_t	ses;
 
 	wait_queue_head_t waitq;
@@ -113,7 +113,7 @@
 static struct csession *csefind(struct fcrypt *, u_int);
 static int csedelete(struct fcrypt *, struct csession *);
 static struct csession *cseadd(struct fcrypt *, struct csession *);
-static struct csession *csecreate(struct fcrypt *, u_int64_t,
+static struct csession *csecreate(struct fcrypt *, u_int64_t *,
 		struct cryptoini *crie, struct cryptoini *cria, struct csession_info *);
 static int csefree(struct csession *);
 
@@ -256,7 +256,8 @@
 		       | (cop->flags & COP_F_BATCH);
 	crp->crp_buf = (caddr_t)&cse->uio;
 	crp->crp_callback = (int (*) (struct cryptop *)) cryptodev_cb;
-	crp->crp_sid = cse->sid;
+	crp->crp_sid[0] = cse->sid[0];
+	crp->crp_sid[1] = cse->sid[1];
 	crp->crp_opaque = (void *)cse;
 
 	if (cop->iv) {
@@ -325,7 +326,7 @@
 
 	if (crp->crp_etype != 0) {
 		error = crp->crp_etype;
-		dprintk("%s error in crp processing\n", __FUNCTION__);
+		dprintk("%s error in crp processing: error=%d\n", __FUNCTION__, error);
 		goto bail;
 	}
 
@@ -568,7 +569,7 @@
 }
 
 static struct csession *
-csecreate(struct fcrypt *fcr, u_int64_t sid, struct cryptoini *crie,
+csecreate(struct fcrypt *fcr, u_int64_t *sid, struct cryptoini *crie,
 	struct cryptoini *cria, struct csession_info *info)
 {
 	struct csession *cse;
@@ -586,7 +587,8 @@
 	cse->keylen = crie->cri_klen/8;
 	cse->mackey = cria->cri_key;
 	cse->mackeylen = cria->cri_klen/8;
-	cse->sid = sid;
+	cse->sid[0] = sid[0];
+	cse->sid[1] = sid[1];
 	cse->cipher = crie->cri_alg;
 	cse->mac = cria->cri_alg;
 	cse->info = *info;
@@ -600,7 +602,7 @@
 	int error;
 
 	dprintk("%s()\n", __FUNCTION__);
-	error = crypto_freesession(cse->sid);
+	error = crypto_freesession(&cse->sid[0]);
 	if (cse->key)
 		kfree(cse->key);
 	if (cse->mackey)
@@ -624,7 +626,7 @@
 	struct crypt_op cop;
 	struct crypt_kop kop;
 	struct crypt_find_op fop;
-	u_int64_t sid;
+	u_int64_t sid[2];
 	u_int32_t ses;
 	int feat, fd, error = 0, crid;
 	mm_segment_t fs;
@@ -822,15 +824,15 @@
 			/* allow either HW or SW to be used */
 			crid = CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE;
 		}
-		error = crypto_newsession(&sid, (info.blocksize ? &crie : &cria), crid);
+		error = crypto_newsession(&sid[0], (info.blocksize ? &crie : &cria), crid);
 		if (error) {
 			dprintk("%s(%s) - newsession %d\n",__FUNCTION__,CIOCGSESSSTR,error);
 			goto bail;
 		}
 
-		cse = csecreate(fcr, sid, &crie, &cria, &info);
+		cse = csecreate(fcr, &sid[0], &crie, &cria, &info);
 		if (cse == NULL) {
-			crypto_freesession(sid);
+			crypto_freesession(&sid[0]);
 			error = EINVAL;
 			dprintk("%s(%s) - csecreate failed\n", __FUNCTION__, CIOCGSESSSTR);
 			goto bail;
diff -ruw /export/tmp/linux-2.6.17.10/crypto/ocf/cryptodev.h ./cryptodev.h
--- /export/tmp/linux-2.6.17.10/crypto/ocf/cryptodev.h	2009-01-29 10:10:36.000000000 -0800
+++ ./cryptodev.h	2009-01-29 23:42:33.000000000 -0800
@@ -345,7 +345,7 @@
 	struct list_head crp_next;
 	wait_queue_head_t crp_waitq;
 
-	u_int64_t	crp_sid;	/* Session ID */
+	u_int64_t	crp_sid[2];	/* Session ID */
 	int		crp_ilen;	/* Input data total length */
 	int		crp_olen;	/* Result total length */
 
@@ -415,12 +415,12 @@
  * a copy of the driver's capabilities that can be used by client code to
  * optimize operation.
  */
-#define CRYPTO_SESID2HID(_sid)	(((_sid) >> 32) & 0x00ffffff)
-#define CRYPTO_SESID2CAPS(_sid)	(((_sid) >> 32) & 0xff000000)
-#define CRYPTO_SESID2LID(_sid)	(((u_int32_t) (_sid)) & 0xffffffff)
+#define CRYPTO_SESID2HID(_sid)	((_sid[1]) & 0x00ffffffULL)
+#define CRYPTO_SESID2CAPS(_sid)	(((_sid[1]) >> 32) & 0xff000000ULL)
+#define CRYPTO_SESID2LID(_sid)	(_sid[0])
 
 extern	int crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int hard);
-extern	int crypto_freesession(u_int64_t sid);
+extern	int crypto_freesession(u_int64_t *sid);
 #define CRYPTOCAP_F_HARDWARE	CRYPTO_FLAG_HARDWARE
 #define CRYPTOCAP_F_SOFTWARE	CRYPTO_FLAG_SOFTWARE
 #define CRYPTOCAP_F_SYNC	0x04000000	/* operates synchronously */
diff -ruw /export/tmp/linux-2.6.17.10/crypto/ocf/cryptosoft.c ./cryptosoft.c
--- /export/tmp/linux-2.6.17.10/crypto/ocf/cryptosoft.c	2009-01-29 10:10:36.000000000 -0800
+++ ./cryptosoft.c	2009-01-29 23:25:47.000000000 -0800
@@ -201,7 +201,7 @@
 static u_int32_t swcr_sesnum = 0;
 
 static	int swcr_process(device_t, struct cryptop *, int);
-static	int swcr_newsession(device_t, u_int32_t *, struct cryptoini *);
+static	int swcr_newsession(device_t, u_int64_t *, struct cryptoini *);
 static	int swcr_freesession(device_t, u_int64_t);
 
 static device_method_t swcr_methods = {
@@ -220,7 +220,7 @@
  * Generate a new software session.
  */
 static int
-swcr_newsession(device_t dev, u_int32_t *sid, struct cryptoini *cri)
+swcr_newsession(device_t dev, u_int64_t *sid, struct cryptoini *cri)
 {
 	struct swcr_data **swd;
 	u_int32_t i;
@@ -407,7 +407,7 @@
 swcr_freesession(device_t dev, u_int64_t tid)
 {
 	struct swcr_data *swd;
-	u_int32_t sid = CRYPTO_SESID2LID(tid);
+	u_int32_t sid = tid;
 
 	dprintk("%s()\n", __FUNCTION__);
 	if (sid > swcr_sesnum || swcr_sessions == NULL ||
@@ -466,7 +466,7 @@
 		goto done;
 	}
 
-	lid = crp->crp_sid & 0xffffffff;
+	lid = CRYPTO_SESID2LID(crp->crp_sid);
 	if (lid >= swcr_sesnum || lid == 0 || swcr_sessions == NULL ||
 			swcr_sessions[lid] == NULL) {
 		crp->crp_etype = ENOENT;
diff -ruw /export/tmp/linux-2.6.17.10/crypto/ocf/ocf-bench.c ./ocf-bench.c
--- /export/tmp/linux-2.6.17.10/crypto/ocf/ocf-bench.c	2009-01-29 10:10:36.000000000 -0800
+++ ./ocf-bench.c	2009-01-29 19:01:12.000000000 -0800
@@ -104,7 +104,7 @@
  * OCF benchmark routines
  */
 
-static uint64_t ocf_cryptoid;
+static uint64_t ocf_cryptoid[2];
 static int ocf_init(void);
 static int ocf_cb(struct cryptop *crp);
 static void ocf_request(void *arg);
@@ -134,7 +134,7 @@
 
 	crie.cri_next = &cria;
 
-	error = crypto_newsession(&ocf_cryptoid, &crie, 0);
+	error = crypto_newsession(&ocf_cryptoid[0], &crie, 0);
 	if (error) {
 		printk("crypto_newsession failed %d\n", error);
 		return -1;
@@ -203,7 +203,8 @@
 	crp->crp_flags = CRYPTO_F_CBIMM;
 	crp->crp_buf = (caddr_t) r->buffer;
 	crp->crp_callback = ocf_cb;
-	crp->crp_sid = ocf_cryptoid;
+	crp->crp_sid[0] = ocf_cryptoid[0];
+	crp->crp_sid[1] = ocf_cryptoid[1];
 	crp->crp_opaque = (caddr_t) r;
 	crypto_dispatch(crp);
 }
diff -ruw /export/tmp/linux-2.6.17.10/crypto/ocf/ocf-compat.h ./ocf-compat.h
--- /export/tmp/linux-2.6.17.10/crypto/ocf/ocf-compat.h	2009-01-29 10:10:36.000000000 -0800
+++ ./ocf-compat.h	2009-01-29 23:44:33.000000000 -0800
@@ -41,7 +41,7 @@
 typedef struct ocf_device *device_t;
 
 typedef struct {
-	int (*cryptodev_newsession)(device_t dev, u_int32_t *sidp, struct cryptoini *cri);
+	int (*cryptodev_newsession)(device_t dev, u_int64_t *sidp, struct cryptoini *cri);
 	int (*cryptodev_freesession)(device_t dev, u_int64_t tid);
 	int (*cryptodev_process)(device_t dev, struct cryptop *crp, int hint);
 	int (*cryptodev_kprocess)(device_t dev, struct cryptkop *krp, int hint);
diff -ruw /export/tmp/linux-2.6.17.10/crypto/ocf/ocfnull/ocfnull.c ./ocfnull/ocfnull.c
--- /export/tmp/linux-2.6.17.10/crypto/ocf/ocfnull/ocfnull.c	2009-01-29 10:10:36.000000000 -0800
+++ ./ocfnull/ocfnull.c	2009-01-29 19:17:59.000000000 -0800
@@ -52,7 +52,7 @@
 static u_int32_t		 null_sesnum = 0;
 
 static int null_process(device_t, struct cryptop *, int);
-static int null_newsession(device_t, u_int32_t *, struct cryptoini *);
+static int null_newsession(device_t, u_int64_t *, struct cryptoini *);
 static int null_freesession(device_t, u_int64_t);
 
 #define debug ocfnull_debug
@@ -79,7 +79,7 @@
  * Generate a new software session.
  */
 static int
-null_newsession(device_t arg, u_int32_t *sid, struct cryptoini *cri)
+null_newsession(device_t arg, u_int64_t *sid, struct cryptoini *cri)
 {
 	dprintk("%s()\n", __FUNCTION__);
 	if (sid == NULL || cri == NULL) {
@@ -100,7 +100,7 @@
 static int
 null_freesession(device_t arg, u_int64_t tid)
 {
-	u_int32_t sid = CRYPTO_SESID2LID(tid);
+	u_int32_t sid = tid;
 
 	dprintk("%s()\n", __FUNCTION__);
 	if (sid > null_sesnum) {
@@ -143,7 +143,7 @@
 	 * find the session we are using
 	 */
 
-	lid = crp->crp_sid & 0xffffffff;
+	lid = CRYPTO_SESID2LID(crp->crp_sid);
 	if (lid >= null_sesnum || lid == 0) {
 		crp->crp_etype = ENOENT;
 		dprintk("%s,%d: ENOENT\n", __FILE__, __LINE__);
 |