Skip to contentSkip to conversation

NVMe: compat SG_IO ioctl

PATCH New Keith Busch 3 participants 3 messages Oct 23, 2013 – Dec 16, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 NVMe: compat SG_IO ioctl

For 32-bit versions of sg3-utils running on a 64-bit system. This is mostly a copy from the relevent portions of fs/compat_ioctl.c, with slight modifications for going through block_device_operations.

Signed-off-by Keith Busch <keith.busch at intel.com>

---
v1->v2:

Added the copying the status back into the 32-bit user structure at the end. I missed this when copying from the original implmenetation.

 drivers/block/nvme-core.c |   14 ++++-
 drivers/block/nvme-scsi.c |  146 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/nvme.h      |    1 +
 3 files changed, 160 insertions(+), 1 deletion(-)
drivers/block/nvme-core.c +13 -1
index da52092..2cb41df 100644
@@ -1569,10 +1569,22 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 	}
 }
 
+static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode,
+					unsigned int cmd, unsigned long arg)
+{
+	struct nvme_ns *ns = bdev->bd_disk->private_data;
+
+	switch (cmd) {
+	case SG_IO:
+		return nvme_sg_io32(ns, arg);
+	}
+	return nvme_ioctl(bdev, mode, cmd, arg);
+}
+
 static const struct block_device_operations nvme_fops = {
 	.owner		= THIS_MODULE,
 	.ioctl		= nvme_ioctl,
-	.compat_ioctl	= nvme_ioctl,
+	.compat_ioctl	= nvme_compat_ioctl,
 };
 
 static void nvme_resubmit_bios(struct nvme_queue *nvmeq)
drivers/block/nvme-scsi.c +146 -0

164 lines not on this page · raw message

include/linux/nvme.h +1 -0
index 26ebcf4..6867de6 100644
@@ -165,6 +165,7 @@ int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
 struct sg_io_hdr;
 
 int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr);
+int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg);
 int nvme_sg_get_version_num(int __user *ip);
 
 #endif /* _LINUX_NVME_H */
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 1/1 NVMe: compat SG_IO ioctl

Quoted 8 lines · Keith Busch

For 32-bit versions of sg3-utils running on a 64-bit system. This is mostly a copy from the relevent portions of fs/compat_ioctl.c, with slight modifications for going through block_device_operations.

Signed-off-by Keith Busch <keith.busch at intel.com>

---
v1->v2:

Quoted 8 lines

Added the copying the status back into the 32-bit user structure at the end. I missed this when copying from the original implmenetation.

 drivers/block/nvme-core.c |   14 ++++-
 drivers/block/nvme-scsi.c |  146 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/nvme.h      |    1 +
 3 files changed, 160 insertions(+), 1 deletion(-)
Reviewed-by Vishal Verma <vishal.l.verma at linux.intel.com>
#2 lore raw

PATCH v2 1/1 NVMe: compat SG_IO ioctl

In reply to Keith Busch
Quoted 10 lines · Keith Busch

For 32-bit versions of sg3-utils running on a 64-bit system. This is mostly a copy from the relevent portions of fs/compat_ioctl.c, with slight modifications for going through block_device_operations.

Signed-off-by Keith Busch <keith.busch at intel.com>

---
v1->v2:

Added the copying the status back into the 32-bit user structure at the end. I missed this when copying from the original implmenetation.

Thanks to Fengguang's automated tester, I ended up fixing the !CONFIG_COMPAT case like this:

drivers/block/nvme-core.c +4 -0
index 3f5d67a..b59a93a 100644
@@ -1696,6 +1696,7 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 	}
 }
 
+#ifdef CONFIG_COMPAT
 static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode,
 					unsigned int cmd, unsigned long arg)
 {
@@ -1707,6 +1708,9 @@ static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode,
 	}
 	return nvme_ioctl(bdev, mode, cmd, arg);
 }
+#else
+#define nvme_compat_ioctl	NULL
+#endif
 
 static const struct block_device_operations nvme_fops = {
 	.owner		= THIS_MODULE,
drivers/block/nvme-scsi.c +2 -1
index be04c50..4a0ceb6 100644
@@ -47,7 +47,6 @@
 #include <linux/types.h>
 #include <scsi/sg.h>
 #include <scsi/scsi.h>
-#include <asm/compat.h>
 
 
 static int sg_version_num = 30534;	/* 2 digits for each component */
@@ -3040,6 +3039,7 @@ int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr)
 	return retcode;
 }
 
+#ifdef CONFIG_COMPAT
 typedef struct sg_io_hdr32 {
 	compat_int_t interface_id;	/* [i] 'S' for SCSI generic (required) */
 	compat_int_t dxfer_direction;	/* [i] data transfer direction  */
@@ -3183,6 +3183,7 @@ int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg)
 
 	return err;
 }
+#endif
 
 int nvme_sg_get_version_num(int __user *ip)
 {