public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RFC: block/loop.c & crypto
@ 2001-07-22 10:21 Herbert Valerio Riedel
  2001-07-22 15:03 ` Andrea Arcangeli
  0 siblings, 1 reply; 8+ messages in thread
From: Herbert Valerio Riedel @ 2001-07-22 10:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: axboe, andrea

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1492 bytes --]

hello!

...some time has passed since I've contacted you last time about
crypto/loop issues... but now it's time again to annoy you :-)

 btw; while I'm at it, a question which came to mind while writing this
 mail; is it safe to call...

 if (current->need_resched) schedule();

 ...from within the transfer function? are there possible race conditions
 where another transfer request may come in for the same blocks, while
 another one is still in progress?

some months ago, when I proposed to switch IV calculation completely to
fixed a fixed 512 byte blocksize, I was reminded, that the international
crypto patch was not the only one to make use of the IV calculatiion, and
doing so would break other crypto packages around...

...so I suggested that I'd try a more backward compatible approach, which
would allow old packages to retain compatibility, and new packages aware
of the new flag to set IV calculation to 512 byte blocks...
well the result of this experiment can be seen in the attachment...

so... any comments?

ps: this are the only changes to kernel sources optionally (!) 'required',
in order to use the international crypto api
(see http://cryptoapi.sourceforge.net/ and the package README file
accessible through CVS for more information)

regards,
-- 
Herbert Valerio Riedel       /    Phone: (EUROPE) +43-1-58801-18840
Email: hvr@gnu.org          /    Finger hvr@gnu.org for GnuPG Public Key
GnuPG Key Fingerprint: 7BB9 2D6C D485 CE64 4748  5F65 4981 E064 883F 4142

[-- Attachment #2: Type: TEXT/PLAIN, Size: 4856 bytes --]

diff -urN linux-2.4.6/drivers/block/loop.c linux-int-2.4.6/drivers/block/loop.c
--- linux-2.4.6/drivers/block/loop.c	Sat Jun 30 01:16:56 2001
+++ linux-int-2.4.6/drivers/block/loop.c	Sat Jul  7 10:52:41 2001
@@ -36,6 +36,9 @@
  * Al Viro too.
  * Jens Axboe <axboe@suse.de>, Nov 2000
  *
+ * Fixed and made IV calculation customizable by lo_iv_mode
+ * Herbert Valerio Riedel <hvr@gnu.org>, Apr 2001
+ *
  * Still To Fix:
  * - Advisory locking is ignored here. 
  * - Should use an own CAP_* category instead of CAP_SYS_ADMIN 
@@ -164,6 +167,43 @@
 					lo->lo_device);
 }
 
+static inline int loop_get_bs(struct loop_device *lo)
+{
+	int bs = 0;
+
+	if (blksize_size[MAJOR(lo->lo_device)])
+		bs = blksize_size[MAJOR(lo->lo_device)][MINOR(lo->lo_device)];
+	if (!bs)
+		bs = BLOCK_SIZE;	
+
+	return bs;
+}
+
+static inline unsigned long loop_get_iv(struct loop_device *lo,
+					unsigned long sector)
+{
+	unsigned long offset, IV;
+	int bs;
+
+	switch (lo->lo_iv_mode) {
+		case LO_IV_MODE_SECTOR:
+			IV = sector + (lo->lo_offset >> LO_IV_SECTOR_BITS);
+			break;
+
+		default:
+			printk (KERN_WARNING "loop: unexpected lo_iv_mode\n");
+		case LO_IV_MODE_DEFAULT:
+			bs = loop_get_bs(lo);
+			IV = sector / (bs >> 9) + lo->lo_offset / bs;
+			offset = ((sector % (bs >> 9)) << 9) + lo->lo_offset % bs;
+			if (offset >= bs)
+				IV++;
+			break;
+	}
+
+	return IV;
+}
+
 static int lo_send(struct loop_device *lo, struct buffer_head *bh, int bsize,
 		   loff_t pos)
 {
@@ -181,7 +221,8 @@
 	len = bh->b_size;
 	data = bh->b_data;
 	while (len > 0) {
-		int IV = index * (PAGE_CACHE_SIZE/bsize) + offset/bsize;
+		unsigned long IV = loop_get_iv(lo, (pos - lo->lo_offset) >> LO_IV_SECTOR_BITS);
+
 		size = PAGE_CACHE_SIZE - offset;
 		if (size > len)
 			size = len;
@@ -232,7 +273,10 @@
 	unsigned long count = desc->count;
 	struct lo_read_data *p = (struct lo_read_data*)desc->buf;
 	struct loop_device *lo = p->lo;
-	int IV = page->index * (PAGE_CACHE_SIZE/p->bsize) + offset/p->bsize;
+	unsigned long IV = loop_get_iv(lo,
+		((page->index <<  (PAGE_CACHE_SHIFT - LO_IV_SECTOR_BITS))
+		+ (offset >> LO_IV_SECTOR_BITS)
+		- (lo->lo_offset >> LO_IV_SECTOR_BITS)));
 
 	if (size > count)
 		size = count;
@@ -272,32 +316,6 @@
 	return desc.error;
 }
 
-static inline int loop_get_bs(struct loop_device *lo)
-{
-	int bs = 0;
-
-	if (blksize_size[MAJOR(lo->lo_device)])
-		bs = blksize_size[MAJOR(lo->lo_device)][MINOR(lo->lo_device)];
-	if (!bs)
-		bs = BLOCK_SIZE;	
-
-	return bs;
-}
-
-static inline unsigned long loop_get_iv(struct loop_device *lo,
-					unsigned long sector)
-{
-	int bs = loop_get_bs(lo);
-	unsigned long offset, IV;
-
-	IV = sector / (bs >> 9) + lo->lo_offset / bs;
-	offset = ((sector % (bs >> 9)) << 9) + lo->lo_offset % bs;
-	if (offset >= bs)
-		IV++;
-
-	return IV;
-}
-
 static int do_bh_filebacked(struct loop_device *lo, struct buffer_head *bh, int rw)
 {
 	loff_t pos;
@@ -474,9 +492,11 @@
 	/*
 	 * piggy old buffer on original, and submit for I/O
 	 */
+	IV = loop_get_iv(lo, rbh->b_rsector);
+
 	bh = loop_get_buffer(lo, rbh);
 	bh->b_private = rbh;
-	IV = loop_get_iv(lo, bh->b_rsector);
+
 	if (rw == WRITE) {
 		set_bit(BH_Dirty, &bh->b_state);
 		if (lo_do_transfer(lo, WRITE, bh->b_data, rbh->b_data,
@@ -646,6 +666,7 @@
 	lo->lo_backing_file = file;
 	lo->transfer = NULL;
 	lo->ioctl = NULL;
+	lo->lo_iv_mode = LO_IV_MODE_DEFAULT;
 	figure_loop_size(lo);
 	lo->old_gfp_mask = inode->i_mapping->gfp_mask;
 	inode->i_mapping->gfp_mask = GFP_NOIO;
@@ -655,7 +676,7 @@
 		bs = blksize_size[MAJOR(lo_device)][MINOR(lo_device)];
 	if (!bs)
 		bs = BLOCK_SIZE;
-
+	  
 	set_blocksize(dev, bs);
 
 	lo->lo_bh = lo->lo_bhtail = NULL;
diff -urN linux-2.4.6/include/linux/loop.h linux-int-2.4.6/include/linux/loop.h
--- linux-2.4.6/include/linux/loop.h	Wed Mar  7 04:35:36 2001
+++ linux-int-2.4.6/include/linux/loop.h	Sat Jul  7 10:42:18 2001
@@ -24,6 +24,13 @@
 	Lo_rundown,
 };
 
+/* IV calculation related constants */
+#define LO_IV_MODE_DEFAULT 0 /* old logical block size based mode */
+#define LO_IV_MODE_SECTOR  1 /* calculate IV based on relative 
+				512 byte sectors */
+#define LO_IV_SECTOR_BITS 9
+#define LO_IV_SECTOR_SIZE (1 << LO_IV_SECTOR_BITS)
+
 struct loop_device {
 	int		lo_number;
 	int		lo_refcnt;
@@ -56,6 +63,8 @@
 	struct semaphore	lo_ctl_mutex;
 	struct semaphore	lo_bh_mutex;
 	atomic_t		lo_pending;
+
+	int			lo_iv_mode;
 };
 
 typedef	int (* transfer_proc_t)(struct loop_device *, int cmd,
@@ -121,6 +130,7 @@
 #define LO_CRYPT_IDEA     6
 #define LO_CRYPT_DUMMY    9
 #define LO_CRYPT_SKIPJACK 10
+#define LO_CRYPT_CRYPTOAPI 18  /* international crypto patch */
 #define MAX_LO_CRYPT	20
 
 #ifdef __KERNEL__

^ permalink raw reply	[flat|nested] 8+ messages in thread
[parent not found: <20010723170038.G822@athlon.random>]

end of thread, other threads:[~2001-07-25 20:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-07-22 10:21 RFC: block/loop.c & crypto Herbert Valerio Riedel
2001-07-22 15:03 ` Andrea Arcangeli
2001-07-22 18:53   ` Herbert Valerio Riedel
2001-07-22 22:21     ` Andrea Arcangeli
2001-07-23  1:47       ` Albert D. Cahalan
2001-07-23  2:08         ` Andrea Arcangeli
     [not found] <20010723170038.G822@athlon.random>
2001-07-24  9:56 ` Herbert Valerio Riedel
2001-07-25 20:28   ` Andrea Arcangeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox