Skip to contentSkip to conversation

ioctl cleanups: enable sg_io and serial stuff to be shared

DISCUSSION Arnd Bergmann 12 participants 38 messages May 7, 2003 – May 8, 2003 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 2 lines · Pavel Machek

Only change *needed* in each architecture is moving A() macros into compat.h, so that generic code can use it. Please apply,

Please don't use A() in new code, we now have compat_ptr() and compat_uptr_t for this.

        Arnd <><
#2 lore raw

Hi!

Quoted 5 lines
Quoted 2 lines

Only change *needed* in each architecture is moving A() macros into compat.h, so that generic code can use it. Please apply,

Please don't use A() in new code, we now have compat_ptr() and compat_uptr_t for this.

Fixed now.
Pavel

arch/x86_64/ia32/ia32_ioctl.c +0 -232
@@ -1333,235 +1333,6 @@
 	return err;
 }
 
-
-typedef struct sg_io_hdr32 {
-	s32 interface_id;	/* [i] 'S' for SCSI generic (required) */
-	s32 dxfer_direction;	/* [i] data transfer direction  */
-	u8  cmd_len;		/* [i] SCSI command length ( <= 16 bytes) */
-	u8  mx_sb_len;		/* [i] max length to write to sbp */
-	u16 iovec_count;	/* [i] 0 implies no scatter gather */
-	u32 dxfer_len;		/* [i] byte count of data transfer */
-	u32 dxferp;		/* [i], [*io] points to data transfer memory
-					      or scatter gather list */
-	u32 cmdp;		/* [i], [*i] points to command to perform */
-	u32 sbp;		/* [i], [*o] points to sense_buffer memory */
-	u32 timeout;		/* [i] MAX_UINT->no timeout (unit: millisec) */
-	u32 flags;		/* [i] 0 -> default, see SG_FLAG... */
-	s32 pack_id;		/* [i->o] unused internally (normally) */
-	u32 usr_ptr;		/* [i->o] unused internally */
-	u8  status;		/* [o] scsi status */
-	u8  masked_status;	/* [o] shifted, masked scsi status */
-	u8  msg_status;		/* [o] messaging level data (optional) */
-	u8  sb_len_wr;		/* [o] byte count actually written to sbp */
-	u16 host_status;	/* [o] errors from host adapter */
-	u16 driver_status;	/* [o] errors from software driver */
-	s32 resid;		/* [o] dxfer_len - actual_transferred */
-	u32 duration;		/* [o] time taken by cmd (unit: millisec) */
-	u32 info;		/* [o] auxiliary information */
-} sg_io_hdr32_t;  /* 64 bytes long (on sparc32) */
-
-typedef struct sg_iovec32 {
-	u32 iov_base;
-	u32 iov_len;
-} sg_iovec32_t;
-
-static int alloc_sg_iovec(sg_io_hdr_t *sgp, u32 uptr32)
-{
-	sg_iovec32_t *uiov = (sg_iovec32_t *) A(uptr32);
-	sg_iovec_t *kiov;
-	int i;
-
-	sgp->dxferp = kmalloc(sgp->iovec_count *
-			      sizeof(sg_iovec_t), GFP_KERNEL);
-	if (!sgp->dxferp)
-		return -ENOMEM;
-	memset(sgp->dxferp, 0,
-	       sgp->iovec_count * sizeof(sg_iovec_t));
-
-	kiov = (sg_iovec_t *) sgp->dxferp;
-	for (i = 0; i < sgp->iovec_count; i++) {
-		u32 iov_base32;
-		if (__get_user(iov_base32, &uiov->iov_base) ||
-		    __get_user(kiov->iov_len, &uiov->iov_len))
-			return -EFAULT;
-
-		kiov->iov_base = kmalloc(kiov->iov_len, GFP_KERNEL);
-		if (!kiov->iov_base)
-			return -ENOMEM;
-		if (copy_from_user(kiov->iov_base,
-				   (void *) A(iov_base32),
-				   kiov->iov_len))
-			return -EFAULT;
-
-		uiov++;
-		kiov++;
-	}
-
-	return 0;
-}
-
-static int copy_back_sg_iovec(sg_io_hdr_t *sgp, u32 uptr32)
-{
-	sg_iovec32_t *uiov = (sg_iovec32_t *) A(uptr32);
-	sg_iovec_t *kiov = (sg_iovec_t *) sgp->dxferp;
-	int i;
-
-	for (i = 0; i < sgp->iovec_count; i++) {
-		u32 iov_base32;
-
-		if (__get_user(iov_base32, &uiov->iov_base))
-			return -EFAULT;
-
-		if (copy_to_user((void *) A(iov_base32),
-				 kiov->iov_base,
-				 kiov->iov_len))
-			return -EFAULT;
-
-		uiov++;
-		kiov++;
-	}
-
-	return 0;
-}
-
-static void free_sg_iovec(sg_io_hdr_t *sgp)
-{
-	sg_iovec_t *kiov = (sg_iovec_t *) sgp->dxferp;
-	int i;
-
-	for (i = 0; i < sgp->iovec_count; i++) {
-		if (kiov->iov_base) {
-			kfree(kiov->iov_base);
-			kiov->iov_base = NULL;
-		}
-		kiov++;
-	}
-	kfree(sgp->dxferp);
-	sgp->dxferp = NULL;
-}
-
-static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	sg_io_hdr32_t *sg_io32;
-	sg_io_hdr_t sg_io64;
-	u32 dxferp32, cmdp32, sbp32;
-	mm_segment_t old_fs;
-	int err = 0;
-
-	sg_io32 = (sg_io_hdr32_t *)arg;
-	err = __get_user(sg_io64.interface_id, &sg_io32->interface_id);
-	err |= __get_user(sg_io64.dxfer_direction, &sg_io32->dxfer_direction);
-	err |= __get_user(sg_io64.cmd_len, &sg_io32->cmd_len);
-	err |= __get_user(sg_io64.mx_sb_len, &sg_io32->mx_sb_len);
-	err |= __get_user(sg_io64.iovec_count, &sg_io32->iovec_count);
-	err |= __get_user(sg_io64.dxfer_len, &sg_io32->dxfer_len);
-	err |= __get_user(sg_io64.timeout, &sg_io32->timeout);
-	err |= __get_user(sg_io64.flags, &sg_io32->flags);
-	err |= __get_user(sg_io64.pack_id, &sg_io32->pack_id);
-
-	sg_io64.dxferp = NULL;
-	sg_io64.cmdp = NULL;
-	sg_io64.sbp = NULL;
-
-	err |= __get_user(cmdp32, &sg_io32->cmdp);
-	sg_io64.cmdp = kmalloc(sg_io64.cmd_len, GFP_KERNEL);
-	if (!sg_io64.cmdp) {
-		err = -ENOMEM;
-		goto out;
-	}
-	if (copy_from_user(sg_io64.cmdp,
-			   (void *) A(cmdp32),
-			   sg_io64.cmd_len)) {
-		err = -EFAULT;
-		goto out;
-	}
-
-	err |= __get_user(sbp32, &sg_io32->sbp);
-	sg_io64.sbp = kmalloc(sg_io64.mx_sb_len, GFP_KERNEL);
-	if (!sg_io64.sbp) {
-		err = -ENOMEM;
-		goto out;
-	}
-	if (copy_from_user(sg_io64.sbp,
-			   (void *) A(sbp32),
-			   sg_io64.mx_sb_len)) {
-		err = -EFAULT;
-		goto out;
-	}
-
-	err |= __get_user(dxferp32, &sg_io32->dxferp);
-	if (sg_io64.iovec_count) {
-		int ret;
-
-		if ((ret = alloc_sg_iovec(&sg_io64, dxferp32))) {
-			err = ret;
-			goto out;
-		}
-	} else {
-		sg_io64.dxferp = kmalloc(sg_io64.dxfer_len, GFP_KERNEL);
-		if (!sg_io64.dxferp) {
-			err = -ENOMEM;
-			goto out;
-		}
-		if (copy_from_user(sg_io64.dxferp,
-				   (void *) A(dxferp32),
-				   sg_io64.dxfer_len)) {
-			err = -EFAULT;
-			goto out;
-		}
-	}
-
-	/* Unused internally, do not even bother to copy it over. */
-	sg_io64.usr_ptr = NULL;
-
-	if (err)
-		return -EFAULT;
-
-	old_fs = get_fs();
-	set_fs (KERNEL_DS);
-	err = sys_ioctl (fd, cmd, (unsigned long) &sg_io64);
-	set_fs (old_fs);
-
-	if (err < 0)
-		goto out;
-
-	err = __put_user(sg_io64.pack_id, &sg_io32->pack_id);
-	err |= __put_user(sg_io64.status, &sg_io32->status);
-	err |= __put_user(sg_io64.masked_status, &sg_io32->masked_status);
-	err |= __put_user(sg_io64.msg_status, &sg_io32->msg_status);
-	err |= __put_user(sg_io64.sb_len_wr, &sg_io32->sb_len_wr);
-	err |= __put_user(sg_io64.host_status, &sg_io32->host_status);
-	err |= __put_user(sg_io64.driver_status, &sg_io32->driver_status);
-	err |= __put_user(sg_io64.resid, &sg_io32->resid);
-	err |= __put_user(sg_io64.duration, &sg_io32->duration);
-	err |= __put_user(sg_io64.info, &sg_io32->info);
-	err |= copy_to_user((void *)A(sbp32), sg_io64.sbp, sg_io64.mx_sb_len);
-	if (sg_io64.dxferp) {
-		if (sg_io64.iovec_count)
-			err |= copy_back_sg_iovec(&sg_io64, dxferp32);
-		else
-			err |= copy_to_user((void *)A(dxferp32),
-					    sg_io64.dxferp,
-					    sg_io64.dxfer_len);
-	}
-	if (err)
-		err = -EFAULT;
-
-out:
-	if (sg_io64.cmdp)
-		kfree(sg_io64.cmdp);
-	if (sg_io64.sbp)
-		kfree(sg_io64.sbp);
-	if (sg_io64.dxferp) {
-		if (sg_io64.iovec_count) {
-			free_sg_iovec(&sg_io64);
-		} else {
-			kfree(sg_io64.dxferp);
-		}
-	}
-	return err;
-}
-
 struct sock_fprog32 {
 	__u16	len;
 	__u32	filter;
@@ -3190,8 +2961,6 @@
 
 /* And these ioctls need translation */
 HANDLE_IOCTL(TIOCGDEV, tiocgdev)
-HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
-HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
 HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
 HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
 #ifdef CONFIG_NET
@@ -3274,7 +3043,6 @@
 HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
 HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
 HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
-HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
drivers/block/Makefile +1 -1
@@ -25,7 +25,7 @@
 obj-$(CONFIG_BLK_DEV_PS2)	+= ps2esdi.o
 obj-$(CONFIG_BLK_DEV_XD)	+= xd.o
 obj-$(CONFIG_BLK_CPQ_DA)	+= cpqarray.o
-obj-$(CONFIG_BLK_CPQ_CISS_DA)  += cciss.o
+obj-$(CONFIG_BLK_CPQ_CISS_DA)	+= cciss.o
 obj-$(CONFIG_BLK_DEV_DAC960)	+= DAC960.o
 
 obj-$(CONFIG_BLK_DEV_UMEM)	+= umem.o
drivers/block/scsi_ioctl.c +213 -1

237 lines not on this page · raw message

drivers/serial/core.c +62 -0

74 lines not on this page · raw message

include/linux/ioctl32.h +6 -3
@@ -2,9 +2,9 @@
 #define IOCTL32_H 1
 
 struct file;
-
 extern long sys_ioctl(unsigned int, unsigned int, unsigned long);
 
+
 /* 
  * Register an 32bit ioctl translation handler for ioctl cmd.
  *
@@ -14,12 +14,15 @@
  *                        arg: ioctl argument
  *                        struct file *file: file descriptor pointer.
  */ 
+typedef int (*ioctl_trans_handler_t)(unsigned int, unsigned int, unsigned long, struct file *);
 
 extern int register_ioctl32_conversion(unsigned int cmd, int (*handler)(unsigned int, unsigned int, unsigned long, struct file *));
-
 extern int unregister_ioctl32_conversion(unsigned int cmd);
 
-typedef int (*ioctl_trans_handler_t)(unsigned int, unsigned int, unsigned long, struct file *);
+/* FIXME: several conversions make sense for one cmd depending on
+ * device being used (don't complain, its ioctl, its supposed to be
+ * ugly). Therefore unregisters needs *handler, too.
+ */
 
 struct ioctl_trans {
 	unsigned long cmd;
Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#3 lore raw
Quoted 9 lines · Pavel Machek

Hi!

Quoted 5 lines
Quoted 2 lines

Only change *needed* in each architecture is moving A() macros into compat.h, so that generic code can use it. Please apply,

Please don't use A() in new code, we now have compat_ptr() and compat_uptr_t for this.

Fixed now.

Btw, if you really want to move all the 32bit ioctl compat code to the drivers a ->ioctl32 file operation might be the better choice..

#4 lore raw
Quoted 2 lines · Christoph Hellwig

Btw, if you really want to move all the 32bit ioctl compat code to the drivers a ->ioctl32 file operation might be the better choice..

I can't believe I never thought of that. :-)

Signature · 1 line
David S. Miller <[email protected]>
#5 lore raw
Quoted 5 lines · David S. Miller
Quoted 2 lines · Christoph Hellwig

Btw, if you really want to move all the 32bit ioctl compat code to the drivers a ->ioctl32 file operation might be the better choice..

I can't believe I never thought of that. :-)

Likewise. That's a good idea...

Jeff

#6 lore raw

From: Jeff Garzik <[email protected]>
Date: Wed, 7 May 2003 11:12:03 -0400

Quoted 5 lines · David S. Miller
Quoted 2 lines · Christoph Hellwig

Btw, if you really want to move all the 32bit ioctl compat code to the drivers a ->ioctl32 file operation might be the better choice..

I can't believe I never thought of that. :-)

Likewise. That's a good idea...

But, of course, name it compat_ioctl() not ioctl32. The compat layer is not only about 32-bit compatibility even though that is all that it is used for currently.

#7 lore raw
In reply to David S. Miller
Quoted 5 lines · David S. Miller
Quoted 2 lines · Christoph Hellwig

Btw, if you really want to move all the 32bit ioctl compat code to the drivers a ->ioctl32 file operation might be the better choice..

I can't believe I never thought of that. :-)

Why ->ioctl32()? Wouldn't ->ioctl() work equally well? That assumes that ioctls which need translation have different numbers through. Not sure whenever this is a problem, but most ioctls which need translation need this due to different field sizes. Thus the total ioctl struct size and the ioctl number (which has the size encoded) should end up being different too. Anyone aware of corner cases where this isn't going to work?

I ran into this compat issue while porting my scsi media changer driver to 2.5 and I decided to register the one ioctl which needs translation as "compatible" and handle the issue within the ->ioctl handler of the driver. Patch below, untested, grep for "CONFIG_COMPAT" to find the intresting places. Comments welcome.

Oh, and maybe move the ioctl compat lists stuff into modutils? So you just have some magic macros (like EXPORT_SYMBOL + friends) where you list your drivers ioctls and they will be registered/unregistered automagically at boot/insmod/rmmod time?

Gerd

Documentation/scsi-changer.txt +184 -0
diff -u linux-2.5.69/Documentation/scsi-changer.txt linux/Documentation/scsi-changer.txt
@@ -0,0 +1,184 @@
+
+README for the SCSI media changer driver
+========================================
+
+This is a driver for SCSI Medium Changer devices, which are listed
+with "Type: Medium Changer" in /proc/scsi/scsi.
+
+This is for *real* Jukeboxes.  It is *not* supported to work with
+common small CD-ROM changers, neither one-lun-per-slot SCSI changers
+nor IDE drives.
+
+Userland tools available from: http://bytesex.org/changer.html
+
+
+General Information
+-------------------
+
+First some words about how changers work: A changer has 2 (possibly
+more) SCSI ID's. One for the changer device which controls the robot,
+and one for the device which actually reads and writes the data. The
+later may be anything, a MOD, a CD-ROM, a tape or whatever. For the
+changer device this is a "don't care", he *only* shuffles around the
+media, nothing else.
+
+
+The SCSI changer model is complex, compared to - for example - IDE-CD
+changers. But it allows to handle nearly all possible cases. It knows
+4 different types of changer elements:
+
+  media transport - this one shuffles around the media, i.e. the
+                    transport arm.  Also known as "picker".
+  storage         - a slot which can hold a media.
+  import/export   - the same as above, but is accessable from outside,
+                    i.e. there the operator (you !) can use this to
+                    fill in and remove media from the changer.
+		    Sometimes named "mailslot".
+  data transfer   - this is the device which reads/writes, i.e. the
+		    CD-ROM / Tape / whatever drive.
+
+None of these is limited to one: A huge Jukebox could have slots for
+123 CD-ROM's, 5 CD-ROM readers (and therefore 6 SCSI ID's: the changer
+and each CD-ROM) and 2 transport arms. No problem to handle.
+
+
+How it is implemented
+---------------------
+
+I implemented the driver as character device driver with a NetBSD-like
+ioctl interface. Just grabbed NetBSD's header file and one of the
+other linux SCSI device drivers as starting point. The interface
+should be source code compatible with NetBSD. So if there is any
+software (anybody knows ???) which supports a BSDish changer driver,
+it should work with this driver too.
+
+Over time a few more ioctls where added, volume tag support for example
+wasn't covered by the NetBSD ioctl API.
+
+
+Current State
+-------------
+
+Support for more than one transport arm is not implemented yet (and
+nobody asked for it so far...).
+
+I test and use the driver myself with a 35 slot cdrom jukebox from
+Grundig.  I got some reports telling it works ok with tape autoloaders
+(Exabyte, HP and DEC).  Some People use this driver with amanda.  It
+works fine with small (11 slots) and a huge (4 MOs, 88 slots)
+magneto-optical Jukebox.  Probably with lots of other changers too, most
+(but not all :-) people mail me only if it does *not* work...
+
+I don't have any device lists, neither black-list nor white-list.  Thus
+it is quite useless to ask me whenever a specific device is supported or
+not.  In theory every changer device which supports the SCSI-2 media
+changer command set should work out-of-the-box with this driver.  If it
+doesn't, it is a bug.  Either within the driver or within the firmware
+of the changer device.
+
+
+Using it
+--------
+
+This is a character device with major number is 86, so use
+"mknod /dev/sch0 c 86 0" to create the special file for the driver.
+
+If the module finds the changer, it prints some messages about the
+device [ try "dmesg" if you don't see anything ] and should show up in
+/proc/devices. If not....  some changers use ID ? / LUN 0 for the
+device and ID ? / LUN 1 for the robot mechanism. But Linux does *not*
+look for LUN's other than 0 as default, becauce there are to many
+broken devices. So you can try:
+
+  1) echo "scsi add-single-device 0 0 ID 1" > /proc/scsi/scsi
+     (replace ID with the SCSI-ID of the device)
+  2) boot the kernel with "max_scsi_luns=1" on the command line
+     (append="max_scsi_luns=1" in lilo.conf should do the trick)
+
+
+Trouble?
+--------
+
+If you insmod the driver with "insmod debug=1", it will be verbose and
+prints a lot of stuff to the syslog.  Compiling the kernel with
+CONFIG_SCSI_CONSTANTS=y improves the quality of the error messages alot
+because the kernel will translate the error codes into human-readable
+strings then.
+
+You can display these messages with the dmesg command (or check the
+logfiles).  If you email me some question becauce of a problem with the
+driver, please include these messages.
+
+
+Insmod options
+--------------
+
+debug=0/1
+	Enable debug messages (see above, default: 0).
+
+verbose=0/1
+	Be verbose (default: 1).
+
+init=0/1
+	Send INITIALIZE ELEMENT STATUS command to the changer
+	at insmod time (default: 1).
+
+check_busy=0/1
+	When moving media from/to data transfer elements, check
+	whenever the device is busy and refuse to move if so
+	(default: 1).
+
+timeout_init=<seconds>
+	timeout for the INITIALIZE ELEMENT STATUS command
+	(default: 3600).
+
+timeout_move=<seconds>
+	timeout for all other commands (default: 120).
+
+dt_id=<id1>,<id2>,...
+dt_lun=<lun1>,<lun2>,...
+	These two allow to specify the SCSI ID and LUN for the data
+	transfer elements.  You likely don't need this as the jukebox
+	should provide this information.  But some devices don't ...
+
+vendor_firsts=
+vendor_counts=
+vendor_labels=
+	These insmod options can be used to tell the driver that there
+	are some vendor-specific element types.  Grundig for example
+	does this.  Some jukeboxes have a printer to label fresh burned
+	CDs, which is addressed as element 0xc000 (type 5).  To tell the
+	driver about this vendor-specific element, use this:
+		$ insmod ch			\
+			vendor_firsts=0xc000	\
+			vendor_counts=1		\
+			vendor_labels=printer
+	All three insmod options accept up to four comma-separated
+	values, this way you can configure the element types 5-8.
+	You likely need the SCSI specs for the device in question to
+	find the correct values as they are not covered by the SCSI-2
+	standard.
+
+
+Credits
+-------
+
+I wrote this driver using the famous mailing-patches-around-the-world
+method.  With (more or less) help from:
+
+	Daniel Moehwald <[email protected]>
+	Dane Jasper <[email protected]>
+	R. Scott Bailey <[email protected]>
+	Jonathan Corbet <[email protected]>
+
+Special thanks go to
+	Martin Kuehne <[email protected]>
+for a old, second-hand (but full functional) cdrom jukebox which I use
+to develop/test driver and tools now.
+
+Have fun,
+
+   Gerd
+
+-- 
+Gerd Knorr <[email protected]>
drivers/scsi/Kconfig +18 -0
diff -u linux-2.5.69/drivers/scsi/Kconfig linux/drivers/scsi/Kconfig
@@ -111,6 +111,24 @@
 	  <file:Documentation/scsi/scsi.txt>. The module will be called sg.
 	  If unsure, say N.
 
+config CHR_DEV_SCH
+	tristate "SCSI media changer support"
+	depends on SCSI
+	---help---
+	  This is a driver for SCSI media changers.  Most common devices are
+	  tape libraries and MOD/CDROM jukeboxes.  *Real* jukeboxes, you
+	  don't need this for those tiny 6-slot cdrom changers.  Media
+	  changers are listed as "Type: Medium Changer" in /proc/scsi/scsi.
+	  If you have such hardware and want to use it with linux, say Y
+	  here.  Check <file:Documentation/scsi-changer.txt> for details.
+	
+	  If you want to compile this as a module ( = code which can be
+	  inserted in and removed from the running kernel whenever you want),
+	  say M here and read <file:Documentation/modules.txt> and
+	  <file:Documentation/scsi.txt>. The module will be called ch.o.
+	  If unsure, say N.
+	
+
 comment "Some SCSI devices (e.g. CD jukebox) support multiple LUNs"
 	depends on SCSI
 
drivers/scsi/Makefile +1 -0
diff -u linux-2.5.69/drivers/scsi/Makefile linux/drivers/scsi/Makefile
@@ -121,6 +121,7 @@
 obj-$(CONFIG_BLK_DEV_SD)	+= sd_mod.o
 obj-$(CONFIG_BLK_DEV_SR)	+= sr_mod.o
 obj-$(CONFIG_CHR_DEV_SG)	+= sg.o
+obj-$(CONFIG_CHR_DEV_SCH)	+= ch.o
 
 scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o constants.o \
 				   scsicam.o scsi_error.o scsi_lib.o \
drivers/scsi/ch.c +1097 -0

1,097 lines not on this page · raw message

include/linux/chio.h +168 -0

168 lines not on this page · raw message

include/linux/major.h +1 -0
diff -u linux-2.5.69/include/linux/major.h linux/include/linux/major.h
@@ -100,6 +100,7 @@
 #define I2O_MAJOR		80	/* 80->87 */
 
 #define SHMIQ_MAJOR		85   /* Linux/mips, SGI /dev/shmiq */
+#define SCSI_CHANGER_MAJOR      86
 
 #define IDE6_MAJOR		88
 #define IDE7_MAJOR		89
include/scsi/scsi.h +3 -0
diff -u linux-2.5.69/include/scsi/scsi.h linux/include/scsi/scsi.h
@@ -31,6 +31,7 @@
 #define FORMAT_UNIT           0x04
 #define READ_BLOCK_LIMITS     0x05
 #define REASSIGN_BLOCKS       0x07
+#define INITIALIZE_ELEMENT_STATUS 0x07
 #define READ_6                0x08
 #define WRITE_6               0x0a
 #define SEEK_6                0x0b
@@ -55,6 +56,7 @@
 #define READ_10               0x28
 #define WRITE_10              0x2a
 #define SEEK_10               0x2b
+#define POSITION_TO_ELEMENT   0x2b
 #define WRITE_VERIFY          0x2e
 #define VERIFY                0x2f
 #define SEARCH_HIGH           0x30
@@ -87,6 +89,7 @@
 #define PERSISTENT_RESERVE_OUT 0x5f
 #define REPORT_LUNS           0xa0
 #define MOVE_MEDIUM           0xa5
+#define EXCHANGE_MEDIUM       0xa6
 #define READ_12               0xa8
 #define WRITE_12              0xaa
 #define WRITE_VERIFY_12       0xae
#8 lore raw
In reply to David S. Miller
Quoted 3 lines · Gerd Knorr

ioctl struct size and the ioctl number (which has the size encoded) should end up being different too. Anyone aware of corner cases where this isn't going to work?

About half of the ioctls that need special care have fixed numbers instead of using _IOR() etc, see e.g. include/linux/sockios.h, or they get the definition wrong in some way.

The way you do it in your patch could work for many cases, but it won't be enough to eliminate HANDLE_IOCTL(), if that is desired.

Adding fops->compat_ioctl() makes it possible to eventually replace all HANDLE_IOCTL() and keep only COMPATIBLE_IOCTL(), which in turn would become simpler to deal with.
If we don't add fops->compat_ioctl(), the ioctl handlers could however look at (current_thread_info()->flags & _TIF_32BIT) to find out if which user data structure they should expect. Is that reliable? Do we already have a macro to do it?

	Arnd <><
#9 lore raw
In reply to David S. Miller
Quoted 5 lines · David S. Miller
Quoted 2 lines · Christoph Hellwig

Btw, if you really want to move all the 32bit ioctl compat code to the drivers a ->ioctl32 file operation might be the better choice..

I can't believe I never thought of that. :-)

How would the driver differentiate between .compat_ioctl == NULL being a case where it should fail because there is no translation, or a case where it should use the compatible .ioctl? Maybe there should be an extra flag like use_compat_ioctl. So:

	.use_compat_ioctl	= 1;
	.ioctl			= my_ioctl;
	.compat_ioctl		= my_compat_ioctl;

Means use my_compat_ioctl() for translation. And just:

	.use_compat_ioctl	= 1;
	.ioctl			= my_ioctl;

Means that our standard my_ioctl is 32/64 compatible.

This would also solve the current problem where a module that is compiled with compat ioctl's using register_ioctl32_conversion() is not usable on a kernel compiled without CONFIG_COMPAT, even though it very well should be.

Signature · 4 lines
Debian     - http://www.debian.org/
Linux 1394 - http://www.linux1394.org/
Subversion - http://subversion.tigris.org/
Deqo       - http://www.deqo.com/
#10 lore raw
Quoted 4 lines · Ben Collins

How would the driver differentiate between .compat_ioctl == NULL being a case where it should fail because there is no translation, or a case where it should use the compatible .ioctl? Maybe there should be an extra flag like use_compat_ioctl. So:

.compat_ioctl == NULL: fail
.compat_ioctl == .ioctl: everythings fine, I read the docs

Quoted 4 lines

This would also solve the current problem where a module that is compiled with compat ioctl's using register_ioctl32_conversion() is not usable on a kernel compiled without CONFIG_COMPAT, even though it very well should be.

You mean you want to load the same binary module in differently compiled kernels? That's a flawed idea to start with..

#11 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Ben Collins

How would the driver differentiate between .compat_ioctl == NULL being a case where it should fail because there is no translation, or a case where it should use the compatible .ioctl? Maybe there should be an extra flag like use_compat_ioctl. So:

.compat_ioctl == NULL: fail
.compat_ioctl == .ioctl: everythings fine, I read the docs

That makes sense aswell.

Quoted 7 lines
Quoted 4 lines

This would also solve the current problem where a module that is compiled with compat ioctl's using register_ioctl32_conversion() is not usable on a kernel compiled without CONFIG_COMPAT, even though it very well should be.

You mean you want to load the same binary module in differently compiled kernels? That's a flawed idea to start with..

I don't, but I don't see the point in it not working in this case.

Signature · 4 lines
Debian     - http://www.debian.org/
Linux 1394 - http://www.linux1394.org/
Subversion - http://subversion.tigris.org/
Deqo       - http://www.deqo.com/
#12 lore raw
In reply to Ben Collins

Hi!

Quoted 4 lines

This would also solve the current problem where a module that is compiled with compat ioctl's using register_ioctl32_conversion() is not usable on a kernel compiled without CONFIG_COMPAT, even though it very well should be.

CONFIG_COMPAT is pretty much constant depending only on architecture. I see no point in complicating this.

Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#13 lore raw
Quoted 9 lines · Pavel Machek

Hi!

Quoted 4 lines

This would also solve the current problem where a module that is compiled with compat ioctl's using register_ioctl32_conversion() is not usable on a kernel compiled without CONFIG_COMPAT, even though it very well should be.

CONFIG_COMPAT is pretty much constant depending only on architecture. I see no point in complicating this.

I don't think so. Sparc64 and ia64 I know allow you to disable 32bit compatibility. I'd be surprised if the other 32/64 architectures didn't.

Signature · 4 lines
Debian     - http://www.debian.org/
Linux 1394 - http://www.linux1394.org/
Subversion - http://subversion.tigris.org/
Deqo       - http://www.deqo.com/
#14 lore raw
Quoted 8 lines · Pavel Machek
Quoted 7 lines

Hi!

Quoted 4 lines

This would also solve the current problem where a module that is compiled with compat ioctl's using register_ioctl32_conversion() is not usable on a kernel compiled without CONFIG_COMPAT, even though it very well should be.

Quoted 5 lines
Quoted 2 lines

CONFIG_COMPAT is pretty much constant depending only on architecture. I see no point in complicating this.

I don't think so. Sparc64 and ia64 I know allow you to disable 32bit compatibility. I'd be surprised if the other 32/64 architectures

didn't.

Really? I thought sparc64 has no real 64-bit userland?

Okay, it might make sense on x86-64, but I do not think savings are worth the trouble.
Pavel

Quoted 1 line
Signature · 2 lines
Horseback riding is like software...
...vgf orggre jura vgf serr.
#15 lore raw

From: Pavel Machek <[email protected]>
Date: Thu, 8 May 2003 22:06:30 +0200

Really? I thought sparc64 has no real 64-bit userland?

Wrong. We use 32-bit binaries by default because they're more efficient.

#16 lore raw
In reply to Pavel Machek
Quoted 13 lines · Pavel Machek
Quoted 8 lines · Pavel Machek
Quoted 7 lines

Hi!

Quoted 4 lines

This would also solve the current problem where a module that is compiled with compat ioctl's using register_ioctl32_conversion() is not usable on a kernel compiled without CONFIG_COMPAT, even though it very well should be.

Quoted 5 lines
Quoted 2 lines

CONFIG_COMPAT is pretty much constant depending only on architecture. I see no point in complicating this.

I don't think so. Sparc64 and ia64 I know allow you to disable 32bit compatibility. I'd be surprised if the other 32/64 architectures

Quoted 7 lines

didn't.

Really? I thought sparc64 has no real 64-bit userland?

Okay, it might make sense on x86-64, but I do not think savings are worth the trouble.

I never said it was worth just that effort. What I said was is that the smarter change of using a compat_ioctl in the fops has the cool side affect of allowing that to happen. Not that I ever thought it was worth making huge changes to the infrastructure.

Signature · 4 lines
Debian     - http://www.debian.org/
Linux 1394 - http://www.linux1394.org/
Subversion - http://subversion.tigris.org/
Deqo       - http://www.deqo.com/
#17 lore raw
In reply to Ben Collins
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Ben Collins
Quoted 10 lines · Pavel Machek
Quoted 10 lines

Hi!

Quoted 1 line

This would also solve the current problem where a module that

is > compiled with compat ioctl's using register_ioctl32_conversion() is not > usable on a kernel compiled without CONFIG_COMPAT, even though it very > well should be.

CONFIG_COMPAT is pretty much constant depending only on architecture. I see no point in complicating this.

Ben> I don't think so. Sparc64 and ia64 I know allow you to disable Ben> 32bit compatibility. I'd be surprised if the other 32/64 Ben> architectures didn't.

Definitely. I turn it off on a regular basis and expect to use it even less in the future.

	--david
#18 lore raw
Quoted 3 lines

Definitely. I turn it off on a regular basis and expect to use it even less in the future.

working on a qemu port to ia64 ?

#19 lore raw
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Arjan van de Ven

Definitely. I turn it off on a regular basis and expect to use it even less in the future.

Arjan> working on a qemu port to ia64 ?

Who, me? I know better than that.

Last time I worked on x86 emulation was on Alpha for BIOS emulation. It wasn't fun then.

	--david
#20 lore raw
In reply to Christoph Hellwig

Hi!

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Only change *needed* in each architecture is moving A() macros into compat.h, so that generic code can use it. Please apply,

Please don't use A() in new code, we now have compat_ptr() and compat_uptr_t for this.

Fixed now.

Btw, if you really want to move all the 32bit ioctl compat code to the drivers a ->ioctl32 file operation might be the better choice..

Not sure if we are not too close to stable release to do that? And I see no incremental way how to get there. Moving compatibility stuff closer to drivers can be done close to stable release...

OTOH it forces pain where it belongs, and when someone invents stupid ioctl, it puts pain on him... I like that.

Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#21 lore raw
Quoted 3 lines · Pavel Machek

Not sure if we are not too close to stable release to do that? And I see no incremental way how to get there. Moving compatibility stuff closer to drivers can be done close to stable release...

You can define it as follows:

1) If entry exists in COMPAT or TRANSLATE table, invoke fops->ioctl(), else

2) If ->compat_ioctl() exists, invoke that, else

3) Fail.

The COMPAT tables are sort of valuable, in that it eliminates the need to duplicate code when all of a drivers ioctls need no translation.

BTW, need to extend this to netdev->do_ioctl as well for the handling of SIOCDEVPRIVATE based stuff. Oh goody, we can finally fix up that crap :))))

Signature · 1 line
David S. Miller <[email protected]>
#22 lore raw
Quoted 8 lines · David S. Miller

You can define it as follows:

1) If entry exists in COMPAT or TRANSLATE table, invoke fops->ioctl(), else

2) If ->compat_ioctl() exists, invoke that, else

3) Fail.

Another solution could be to use the tables only if ->compat_ioctl() is undefined or returned -ENOTTY. That would save the hash table lookup in many cases and makes it possible for a driver to override a generic handler with its more specialized version (e.g. CIODEVPRIVATE).

Quoted 3 lines

The COMPAT tables are sort of valuable, in that it eliminates the need to duplicate code when all of a drivers ioctls need no translation.

Right. Of course you can just as well do

.ioctl = &foo_ioctl,
.compat_ioctl = &foo_ioctl,

in that case.

Btw: is there any bit in the ioctl number definition that can be (ab)used for compat_ioctl? Maybe we don't even need another callback if the compatibility mode can be encoded in the number itself (simplified):

long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
unsigned long arg)

{
	long err = sys_ioctl(fd, cmd | _IOC_COMPAT, arg);
	if (err == -ENOTTY) /* use ioctl_trans table */
		err = compat_do_ioctl(fd, cmd, arg);
	return err;
}
...
long foo_ioctl(struct inode * inode, struct file * filp,
		unsigned int cmd, unsigned long arg)
{
	switch(cmd) {
	case SOMEIOCTL:
		return do_something(inode, arg);
	case SOMEIOCTL | _IOC_COMPAT:
		return compat_do_something(inode, arg);
	case ANOTHERIOCTL:
	case ANOTHERIOCTL | _IOC_COMPAT:	
		return do_something_else(inode, arg);
	}
	return -ENOTTY;
}
	Arnd <><	
#23 lore raw

From: Arnd Bergmann <[email protected]>
Date: Wed, 7 May 2003 21:13:07 +0200

Btw: is there any bit in the ioctl number definition that can be (ab)used for compat_ioctl?

Unfortunately no. All the bits are used in order to allow the size field of the encoding to be as large as possible.

#24 lore raw
Quoted 8 lines · David S. Miller

From: Arnd Bergmann <[email protected]>
Date: Wed, 7 May 2003 21:13:07 +0200

Btw: is there any bit in the ioctl number definition that can be (ab)used for compat_ioctl?

Unfortunately no. All the bits are used in order to allow the size field of the encoding to be as large as possible.

I checked the numbers that are in arch/sparc64/kernel/ioctl32.o and found none that uses more than 9 bits for the size field, while every architecture has at least 13 bits space. There may of course be other ioctls that can not live with 12 bit size fields and it's probably a bad idea to require special-casing these in the compat code.

	Arnd <><
#25 lore raw

From: Arnd Bergmann <[email protected]>
Date: Thu, 8 May 2003 01:50:10 +0200

I checked the numbers that are in arch/sparc64/kernel/ioctl32.o and found none that uses more than 9 bits for the size field,

I know that we had to change our sparc ioctl macro definitions a few months ago to accomodate some ioctl that wanted more bits.

It isn't a theoretical problem.

#26 lore raw
In reply to Arnd Bergmann
Quoted 2 lines · Arnd Bergmann

Another solution could be to use the tables only if ->compat_ioctl() is undefined or returned -ENOTTY. That

We have magic -ENOIOCTLCMD type returns never meant for user space to handle that ambiguity

#27 lore raw
In reply to David S. Miller

Hi!

Quoted 13 lines
Quoted 3 lines

Not sure if we are not too close to stable release to do that? And I see no incremental way how to get there. Moving compatibility stuff closer to drivers can be done close to stable release...

You can define it as follows:

1) If entry exists in COMPAT or TRANSLATE table, invoke fops->ioctl(), else

2) If ->compat_ioctl() exists, invoke that, else

3) Fail.

Quoted 7 lines

The COMPAT tables are sort of valuable, in that it eliminates the need to duplicate code when all of a drivers ioctls need no translation.

BTW, need to extend this to netdev->do_ioctl as well for the handling of SIOCDEVPRIVATE based stuff. Oh goody, we can finally fix up that crap :))))

There's a *lot* of structs that contain *ioctl:

pavel@amd:/usr/src/linux-test/include/linux$ grep "*ioctl" *
pavel@amd:/usr/src/linux-test/include/linux$ grep "*ioctl" *
atmdev.h:       int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
atmdev.h:       int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
fs.h:   int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
fs.h:   int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
hdlc.h: int (*ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
hdlcdrv.h:      int (*ioctl)(struct net_device *, struct ifreq *,
ide.h:  int             (*ioctl)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
if_bridge.h:extern void brioctl_set(int (*ioctl_hook)(unsigned long));
if_pppox.h:     int             (*ioctl)(struct socket *sock, unsigned int cmd,
ioctl32.h:typedef int (*ioctl_trans_handler_t)(unsigned int, unsigned int, unsigned long, struct file *);
loop.h: int             (*ioctl)(struct loop_device *, int cmd,
loop.h: int (*ioctl)(struct loop_device *, int cmd, unsigned long arg);
net.h:  int             (*ioctl)     (struct socket *sock, unsigned int cmd,
ppp_channel.h:  int     (*ioctl)(struct ppp_channel *, unsigned int, unsigned long);
serial_core.h:  int             (*ioctl)(struct uart_port *, unsigned int, unsigned long);
tty_driver.h: * int  (*ioctl)(struct tty_struct *tty, struct file * file,
tty_driver.h:   int  (*ioctl)(struct tty_struct *tty, struct file * file,
tty_ldisc.h: * int      (*ioctl)(struct tty_struct * tty, struct file * file,
tty_ldisc.h:    int     (*ioctl)(struct tty_struct * tty, struct file * file,
usb.h:  int (*ioctl) (struct usb_interface *intf, unsigned int code, void *buf);
wanrouter.h:    int (*ioctl) (struct wan_device *wandev, unsigned cmd,
pavel@amd:/usr/src/linux-test/include/linux$

What about this one: redefine it to (*ioctl)( ...., unsigned *long*, unsinged long). That means we can add

#define IOCTL_COMPAT 0x1 0000 0000

and avoid adding new field to each such structure. Also I will not have to duplicate lots of middle-level code (I will have to modify unsigned int -> unsigned long, but no second copies of everything). It means that architecture with CONFIG_COMPAT needs to have unsigned long

Quoted 1 line

32 bits, but I guess we can live with that.

What do you think?
Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#28 lore raw

From: Pavel Machek <[email protected]>
Date: Thu, 8 May 2003 22:33:14 +0200

What about this one: redefine it to (*ioctl)( ...., unsigned *long*, unsinged long). That means we can add

   #define IOCTL_COMPAT 0x1 0000 0000

Bzzt! Doesn't work on 32-bit. COMPAT does not mean 64-bit-->32-bit translations, stop thinking about the compat layer in this way.

It is a generic environment translation system.

Eventually we can use it for things like IBCS2 and stuff like that.

Suggest something sane like defining a macro such as "compat_task(tsk)" that can be tested by various bits of code.

#29 lore raw

Hi!

Quoted 6 lines

From: Pavel Machek <[email protected]>
Date: Thu, 8 May 2003 22:33:14 +0200

What about this one: redefine it to (*ioctl)( ...., unsigned *long*, unsinged long). That means we can add

Quoted 8 lines
   #define IOCTL_COMPAT 0x1 0000 0000

Bzzt! Doesn't work on 32-bit. COMPAT does not mean 64-bit-->32-bit translations, stop thinking about the compat layer in this way.

It is a generic environment translation system.

Eventually we can use it for things like IBCS2 and stuff like that.

I... do not think so.

You'd then need

.compat_linux32_ioctl
.compat_IBCS2_ioctl
...

I do not think that is doable.

Quoted 3 lines

Suggest something sane like defining a macro such as "compat_task(tsk)" that can be tested by various bits of code.

That makes more sense. Unfortunately, that means that case "okay, it is compatible" can not be told from "we did not bother to check compat_task()". :-(. Nor do I see a transition phase.
Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#30 lore raw
Quoted 7 lines · Pavel Machek
Quoted 3 lines

Suggest something sane like defining a macro such as "compat_task(tsk)" that can be tested by various bits of code.

That makes more sense. Unfortunately, that means that case "okay, it is compatible" can not be told from "we did not bother to check compat_task()". :-(. Nor do I see a transition phase.

You still need to list them as COMPATIBLE_IOCTL() or call register_ioctl32_conversion(IOCTLNO, 0) when the ioctl has been made compatible. Unless we are sure that every single ioctl has been made compatible (probably never), the default must be to call sys_ioctl from compat_sys_ioctl only if the number is explicitly listed. This should solve both problems you mentioned.

One minor remaining problem is that if multiple files contain handlers for the same ioctl number, they have to be converted at the same time because the number can not both be compatible and incompatible at the same time.

	Arnd <><
#31 lore raw
In reply to Pavel Machek
Quoted 4 lines · Pavel Machek
Quoted 3 lines

BTW, need to extend this to netdev->do_ioctl as well for the handling of SIOCDEVPRIVATE based stuff. Oh goody, we can finally fix up that crap :))))

Quoted 8 lines

There's a *lot* of structs that contain *ioctl:

atmdev.h:       int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
atmdev.h:       int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
fs.h:   int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
fs.h:   int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); 
hdlc.h: int (*ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); 

...

There are even some more that your grep did not catch. However, only few of them actually need to be changed if we add ->compat_ioctl().

For those subsystems that have a clearly defined set of ioctls that are implemented by the specific drivers, the compatibility code can be put in a higher level ioctl handler, e.g. atm_ioctl() instead of each of the atm drivers.
Finding out exactly which interfaces need to be extended can be done in the process.

Quoted 4 lines

What about this one: redefine it to (*ioctl)( ...., unsigned *long*, unsinged long). That means we can add

#define IOCTL_COMPAT 0x1 0000 0000

I had the same idea before but in addition to the problem that davem mentioned, this would require changing every single ioctl handler in the kernel and in third party drivers to use 'long' numbers. Not really something we want to do during the current freeze.

The three options that currently make sense to me are:

a) keep using register_ioctl32_conversion() for everything
b) add a compat_task() function that handlers may use to decide if they should use the compat data structures, list those ioctls as COMPATIBLE_IOCTL()
c) add ->compat_ioctl() to some interfaces, with HANDLE_IOCTL() as fallback

	Arnd <><
#32 lore raw

Hi!

Quoted 13 lines
Quoted 4 lines
Quoted 3 lines

BTW, need to extend this to netdev->do_ioctl as well for the handling of SIOCDEVPRIVATE based stuff. Oh goody, we can finally fix up that crap :))))

Quoted 8 lines

There's a *lot* of structs that contain *ioctl:

atmdev.h:       int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
atmdev.h:       int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
fs.h:   int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
fs.h:   int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); 
hdlc.h: int (*ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); 

...

Quoted 2 lines

There are even some more that your grep did not catch. However, only few of them actually need to be changed if we add ->compat_ioctl().

Having few structs with ->ioctl() and few with both ->ioctl() and ->compat_ioctl() seems pretty ugly to me...

Quoted 4 lines

For those subsystems that have a clearly defined set of ioctls that are implemented by the specific drivers, the compatibility code can be put in a higher level ioctl handler, e.g. atm_ioctl() instead of each of the atm drivers.

If it is clearly defined, it should not be an ioctl() in the first place. Yep, you are right ioctl is probably abused for that at few points... And finding out where it ->compat_ioctl() is going to be "interesting".

Quoted 11 lines

Finding out exactly which interfaces need to be extended can be done in the process.

Quoted 4 lines

What about this one: redefine it to (*ioctl)( ...., unsigned *long*, unsinged long). That means we can add

#define IOCTL_COMPAT 0x1 0000 0000

I had the same idea before but in addition to the problem that davem mentioned, this would require changing every single ioctl handler in the kernel and in third party drivers to use 'long' numbers.

Oops; yep, that's a showstopper.

Quoted 5 lines

Not really something we want to do during the current freeze.

The three options that currently make sense to me are:

a) keep using register_ioctl32_conversion() for everything

I believe this makes sense: its too close to 2.6 to do anything else.

Quoted 3 lines

b) add a compat_task() function that handlers may use to decide if they should use the compat data structures, list those ioctls as COMPATIBLE_IOCTL()

Unfortunately missing compat handler silently does the wrong thing in this case.

Quoted 2 lines

c) add ->compat_ioctl() to some interfaces, with HANDLE_IOCTL() as fallback

Seems like too much rewriting to me...
Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#33 lore raw
In reply to Pavel Machek
Quoted 9 lines · Pavel Machek

Hi!

Quoted 5 lines
Quoted 2 lines

Only change *needed* in each architecture is moving A() macros into compat.h, so that generic code can use it. Please apply,

Please don't use A() in new code, we now have compat_ptr() and compat_uptr_t for this.

Fixed now.

Ok. I now noticed there are some more problems that I did not see at first:

drivers/block/Makefile line 29

Quoted 9 lines
drivers/block/Makefile +1 -1
@@ -25,7 +25,7 @@
 obj-$(CONFIG_BLK_DEV_PS2)	+= ps2esdi.o
 obj-$(CONFIG_BLK_DEV_XD)	+= xd.o
 obj-$(CONFIG_BLK_CPQ_DA)	+= cpqarray.o
-obj-$(CONFIG_BLK_CPQ_CISS_DA)  += cciss.o
+obj-$(CONFIG_BLK_CPQ_CISS_DA)	+= cciss.o
 obj-$(CONFIG_BLK_DEV_DAC960)	+= DAC960.o

huh?

Quoted 20 lines
drivers/block/Makefile +20 -0
+typedef struct sg_io_hdr32 {
+	s32 interface_id;	/* [i] 'S' for SCSI generic (required) */
+	s32 dxfer_direction;	/* [i] data transfer direction  */
+	u8  cmd_len;		/* [i] SCSI command length ( <= 16 bytes) */
+	u8  mx_sb_len;		/* [i] max length to write to sbp */
+	u16 iovec_count;	/* [i] 0 implies no scatter gather */
+	u32 dxfer_len;		/* [i] byte count of data transfer */
+	u32 dxferp;		/* [i], [*io] points to data transfer memory
+					      or scatter gather list */
+	u32 cmdp;		/* [i], [*i] points to command to perform */
+	u32 sbp;		/* [i], [*o] points to sense_buffer memory */
+	u32 timeout;		/* [i] MAX_UINT->no timeout (unit: millisec) */
+	u32 flags;		/* [i] 0 -> default, see SG_FLAG... */
+	s32 pack_id;		/* [i->o] unused internally (normally) */
+	u32 usr_ptr;		/* [i->o] unused internally */
+	u8  status;		/* [o] scsi status */
+	u8  masked_status;	/* [o] shifted, masked scsi status */
+	u8  msg_status;		/* [o] messaging level data (optional) */
+	u8  sb_len_wr;		/* [o] byte count actually written to sbp */
+	u16 host_status;	/* [o] errors from host adapter */

drivers/block/Makefile

Quoted 10 lines
drivers/block/Makefile +10 -0
+	u16 driver_status;	/* [o] errors from software driver */
+	s32 resid;		/* [o] dxfer_len - actual_transferred */
+	u32 duration;		/* [o] time taken by cmd (unit: millisec) */
+	u32 info;		/* [o] auxiliary information */
+} sg_io_hdr32_t;  /* 64 bytes long (on sparc32) */
+
+typedef struct sg_iovec32 {
+	u32 iov_base;
+	u32 iov_len;
+} sg_iovec32_t;

These should better be expressed with compat_uptr_t, compat_ulong_t etc.

drivers/block/Makefile

Quoted 5 lines
drivers/block/Makefile +2 -0
+	sg_iovec32_t *uiov = (sg_iovec32_t *) compat_ptr(uptr32);
 
+		if (verify_area(VERIFY_WRITE, (void *)compat_ptr(iov_base32),

kiov->iov_len)) + return -EFAULT;

drivers/block/Makefile +1 -0
+		kiov->iov_base = (void *)compat_ptr(iov_base32);

You don't need to cast to a pointer when using compat_ptr.

drivers/block/Makefile

Quoted 12 lines
drivers/block/Makefile +9 -0
+static int __init init_compat(void)
+{
+	register_ioctl32_conversion(SG_IO, sg_ioctl_trans);
+	return 0;
+}
+
+__initcall(init_compat);
+#endif
+
 #define FORMAT_UNIT_TIMEOUT		(2 * 60 * 60 * HZ)
 #define START_STOP_TIMEOUT		(60 * HZ)
 #define MOVE_MEDIUM_TIMEOUT		(5 * 60 * HZ)

Has anyone solved the register_ioctl32_conversion() from module problem yet? The patch will break if you build scsi as a module because you never unregister the conversion helper on unload.
Even if you do the unregister from a module_exit() function, there will still be a small race against running ioctl handlers. I suppose we have to add an 'owner' field to struct ioctl_trans in order to get it right.

Quoted 11 lines
drivers/block/Makefile +11 -0
+#ifdef CONFIG_COMPAT
+struct serial_struct32 {
+	int	type;
+	int	line;
+	unsigned int	port;
+	int	irq;
+	int	flags;
+	int	xmit_fifo_size;
+	int	custom_divisor;
+	int	baud_base;
+	unsigned short	close_delay;

drivers/block/Makefile

Quoted 10 lines
drivers/block/Makefile +10 -0
+	char	io_type;
+	char	reserved_char[1];
+	int	hub6;
+	unsigned short	closing_wait; /* time to wait before closing */
+	unsigned short	closing_wait2; /* no longer used... */
+	__u32 iomem_base;
+	unsigned short	iomem_reg_shift;
+	unsigned int	port_high;
+	int	reserved[1];
+};

see above.

drivers/block/Makefile

Quoted 1 line
drivers/block/Makefile +1 -0
+		ss.iomem_base = (void *)((unsigned long)ss.iomem_base & 0xffffffff);

you need compat_ptr() for iomem_base as well

drivers/block/Makefile

Quoted 9 lines
drivers/block/Makefile +9 -0
+
+static int __init init_compat(void)
+{
+	register_ioctl32_conversion(TIOCGSERIAL, serial_struct_ioctl);
+	register_ioctl32_conversion(TIOCSSERIAL, serial_struct_ioctl);
+	return 0;
+}
+
+__initcall(init_compat);

see above.

	Arnd <><
#34 lore raw
Quoted 6 lines · Arnd Bergmann

On Wednesday 07 May 2003 14:41, Pavel Machek wrote:

Ok. I now noticed there are some more problems that I did not see at first:

Quoted 12 lines
Quoted 9 lines
drivers/block/Makefile +0 -0
@@ -25,7 +25,7 @@

obj-$(CONFIG_BLK_DEV_PS2) += ps2esdi.o
obj-$(CONFIG_BLK_DEV_XD) += xd.o
obj-$(CONFIG_BLK_CPQ_DA) += cpqarray.o

drivers/block/Makefile +1 -1
-obj-$(CONFIG_BLK_CPQ_CISS_DA)  += cciss.o
+obj-$(CONFIG_BLK_CPQ_CISS_DA)	+= cciss.o

obj-$(CONFIG_BLK_DEV_DAC960) += DAC960.o

huh?

Tab vs. spaces

Carl-Daniel

#35 lore raw
In reply to Arnd Bergmann

Hi!

Quoted 34 lines
Quoted 20 lines
drivers/block/scsi_ioctl.c +20 -0
+typedef struct sg_io_hdr32 {
+	s32 interface_id;	/* [i] 'S' for SCSI generic (required) */
+	s32 dxfer_direction;	/* [i] data transfer direction  */
+	u8  cmd_len;		/* [i] SCSI command length ( <= 16 bytes) */
+	u8  mx_sb_len;		/* [i] max length to write to sbp */
+	u16 iovec_count;	/* [i] 0 implies no scatter gather */
+	u32 dxfer_len;		/* [i] byte count of data transfer */
+	u32 dxferp;		/* [i], [*io] points to data transfer memory
+					      or scatter gather list */
+	u32 cmdp;		/* [i], [*i] points to command to perform */
+	u32 sbp;		/* [i], [*o] points to sense_buffer memory */
+	u32 timeout;		/* [i] MAX_UINT->no timeout (unit: millisec) */
+	u32 flags;		/* [i] 0 -> default, see SG_FLAG... */
+	s32 pack_id;		/* [i->o] unused internally (normally) */
+	u32 usr_ptr;		/* [i->o] unused internally */
+	u8  status;		/* [o] scsi status */
+	u8  masked_status;	/* [o] shifted, masked scsi status */
+	u8  msg_status;		/* [o] messaging level data (optional) */
+	u8  sb_len_wr;		/* [o] byte count actually written to sbp */
+	u16 host_status;	/* [o] errors from host adapter */

drivers/block/scsi_ioctl.c line 332

Quoted 10 lines
drivers/block/scsi_ioctl.c +10 -0
+	u16 driver_status;	/* [o] errors from software driver */
+	s32 resid;		/* [o] dxfer_len - actual_transferred */
+	u32 duration;		/* [o] time taken by cmd (unit: millisec) */
+	u32 info;		/* [o] auxiliary information */
+} sg_io_hdr32_t;  /* 64 bytes long (on sparc32) */
+
+typedef struct sg_iovec32 {
+	u32 iov_base;
+	u32 iov_len;
+} sg_iovec32_t;

These should better be expressed with compat_uptr_t, compat_ulong_t etc.

Quoted 7 lines

drivers/block/scsi_ioctl.c line 359

Quoted 5 lines
(quoted diff) +2 -0
+	sg_iovec32_t *uiov = (sg_iovec32_t *) compat_ptr(uptr32);
 
+		if (verify_area(VERIFY_WRITE, (void *)compat_ptr(iov_base32),

kiov->iov_len)) + return -EFAULT;

drivers/block/scsi_ioctl.c +1 -0
+		kiov->iov_base = (void *)compat_ptr(iov_base32);

You don't need to cast to a pointer when using compat_ptr.

I thought so. I originally wanted as clean move as possible. I'll fix it.

Quoted 13 lines

drivers/block/scsi_ioctl.c line 511

Quoted 12 lines
drivers/block/scsi_ioctl.c +9 -0
+static int __init init_compat(void)
+{
+	register_ioctl32_conversion(SG_IO, sg_ioctl_trans);
+	return 0;
+}
+
+__initcall(init_compat);
+#endif
+
 #define FORMAT_UNIT_TIMEOUT		(2 * 60 * 60 * HZ)
 #define START_STOP_TIMEOUT		(60 * HZ)
 #define MOVE_MEDIUM_TIMEOUT		(5 * 60 * HZ)
Quoted 7 lines

Has anyone solved the register_ioctl32_conversion() from module problem yet? The patch will break if you build scsi as a module because you never unregister the conversion helper on unload.
Even if you do the unregister from a module_exit() function, there will still be a small race against running ioctl handlers. I suppose we have to add an 'owner' field to struct ioctl_trans in order to get it right.

Its in drivers/block/scsi_ioctl.c. AFAICS, its always compiled in, so I'm not hitting that problem *yet*.

Quoted 23 lines
Quoted 11 lines
drivers/serial/core.c +11 -0
+#ifdef CONFIG_COMPAT
+struct serial_struct32 {
+	int	type;
+	int	line;
+	unsigned int	port;
+	int	irq;
+	int	flags;
+	int	xmit_fifo_size;
+	int	custom_divisor;
+	int	baud_base;
+	unsigned short	close_delay;

drivers/serial/core.c line 1171

Quoted 10 lines
drivers/serial/core.c +10 -0
+	char	io_type;
+	char	reserved_char[1];
+	int	hub6;
+	unsigned short	closing_wait; /* time to wait before closing */
+	unsigned short	closing_wait2; /* no longer used... */
+	__u32 iomem_base;
+	unsigned short	iomem_reg_shift;
+	unsigned int	port_high;
+	int	reserved[1];
+};

see above.

Quoted 2 lines

drivers/serial/core.c line 1185

Quoted 1 line
drivers/serial/core.c +1 -0
+		ss.iomem_base = (void *)((unsigned long)ss.iomem_base & 0xffffffff);

you need compat_ptr() for iomem_base as well

Its not pointer, AFAICS (at least it can not be dereferenced by userspace).
Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#36 lore raw
Quoted 10 lines · Pavel Machek
Quoted 7 lines

Has anyone solved the register_ioctl32_conversion() from module problem yet? The patch will break if you build scsi as a module because you never unregister the conversion helper on unload.
Even if you do the unregister from a module_exit() function, there will still be a small race against running ioctl handlers. I suppose we have to add an 'owner' field to struct ioctl_trans in order to get it right.

Its in drivers/block/scsi_ioctl.c. AFAICS, its always compiled in, so I'm not hitting that problem *yet*.

No, it has indeed been possible to build scsi as a module for a long time and in that case, scsi_ioctl becomes part of that module. The same problem also exists for any user of register_ioctl32_conversion(), e.g. ieee1394.

Quoted 6 lines
Quoted 3 lines

drivers/serial/core.c line 1185

Quoted 1 line
drivers/serial/core.c +1 -0
+		ss.iomem_base = (void *)((unsigned long)ss.iomem_base & 0xffffffff);

you need compat_ptr() for iomem_base as well

Its not pointer, AFAICS (at least it can not be dereferenced by userspace).

Right, it appears to be a physical address, which therefore would require a new mapping macro to be really correct. If this were used on s390, that macro would be the same as compat_ptr(), the other architectures probably need a simple cast (again, like compat_ptr()). Either of 1. new macro, 2. compat_ptr() or 3. the existing code works correctly here, so just do whichever you prefer. Maybe somebody else has a strong opinion on it.

	Arnd <><
#37 lore raw
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · Pavel Machek
Quoted 7 lines

Has anyone solved the register_ioctl32_conversion() from module problem yet? The patch will break if you build scsi as a module because you never unregister the conversion helper on unload.
Even if you do the unregister from a module_exit() function, there will still be a small race against running ioctl handlers. I suppose we have to add an 'owner' field to struct ioctl_trans in order to get it right.

Quoted 7 lines
Quoted 2 lines

Its in drivers/block/scsi_ioctl.c. AFAICS, its always compiled in, so I'm not hitting that problem *yet*.

No, it has indeed been possible to build scsi as a module for a long time and in that case, scsi_ioctl becomes part of that module. The same problem also exists for any user of register_ioctl32_conversion(), e.g. ieee1394.

drivers/block/scsi_ioctl.c is not part of the scsi layer, it provides generic SG_IO functionality for scsi-like block drivers.

Signature · 1 line
Jens Axboe
#38 lore raw
Quoted 8 lines · Jens Axboe
Quoted 4 lines · Arnd Bergmann

No, it has indeed been possible to build scsi as a module for a long time and in that case, scsi_ioctl becomes part of that module. The same problem also exists for any user of register_ioctl32_conversion(), e.g. ieee1394.

drivers/block/scsi_ioctl.c is not part of the scsi layer, it provides generic SG_IO functionality for scsi-like block drivers.

Ok, sorry about the confusion. I was thinking of drivers/scsi/scsi_ioctl.c all the time. However, the problem I meant is still present in the patch for drivers/serial/core.c, which does get built as a module, and potentially in any other module. Note that the whole purpose of register_ioctl32_conversion() is to be able to put the wrappers in modules:
If you put your wrapper function in a file that is never a module, you can simply put HANDLE_IOCTL(FOO, compat_foo) in include/linux/compat_ioctl.h.

	Arnd <><