Skip to contentSkip to conversation

NVMe: compat SG_IO ioctl

PATCH Superseded Keith Busch 2 participants 2 messages Sep 27, 2013 – Oct 8, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NVMe: compat SG_IO ioctl

I hear some people have (and use!) 32-bit versions of sg3-utils on 64-bit OSes. This is pretty much a straight copy from fs/compat_ioctl.c.

Signed-off-by Keith Busch <keith.busch at intel.com>
---
 drivers/block/nvme-core.c |   14 +++++-
 drivers/block/nvme-scsi.c |  111 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/nvme.h      |    1 +
 3 files changed, 125 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 +111 -0

129 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 1/1 NVMe: compat SG_IO ioctl

Quoted 10 lines · Keith Busch

I hear some people have (and use!) 32-bit versions of sg3-utils on 64-bit OSes. This is pretty much a straight copy from fs/compat_ioctl.c.

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

---
drivers/block/nvme-core.c | 14 +++++-
drivers/block/nvme-scsi.c | 111
+++++++++++++++++++++++++++++++++++++++++++++
include/linux/nvme.h | 1 +

3 files changed, 125 insertions(+), 1 deletion(-)

<snip>

Quoted 47 lines
drivers/block/nvme-scsi.c +46 -0
+
+int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg)
+{
+	sg_io_hdr32_t __user *sgio32 = (sg_io_hdr32_t __user *)arg;
+	sg_io_hdr_t __user *sgio;
+	u16 iovec_count;
+	u32 data;
+	void __user *dxferp;
+	unsigned char __user *cmdp;
+	unsigned char __user *sbp;
+	unsigned char __user *new;
+	unsigned char __user *top;
+	
+	if (get_user(iovec_count, &sgio32->iovec_count))
+		return -EFAULT;
+
+	top = compat_alloc_user_space(0);
+	new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
+			       (iovec_count * sizeof(sg_iovec_t)));
+	if (new > top)
+		return -EINVAL;
+
+	sgio = (sg_io_hdr_t __user *)new;
+	if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
+							 (2 * sizeof(int)) +
+							 (2 * sizeof(unsigned char)) +
+							 (1 * sizeof(unsigned short)) +
+							 (1 * sizeof(unsigned int))))
+		return -EFAULT;
+	if (get_user(data, &sgio32->dxferp))
+		return -EFAULT;
+
+	dxferp = compat_ptr(data);
+	if (iovec_count && sg_build_iovec(sgio, dxferp, iovec_count))
+			return -EFAULT;
+	else if (put_user(dxferp, &sgio->dxferp))
+			return -EFAULT;
+
+	if (get_user(data, &sgio32->cmdp))
+		return -EFAULT;
+
+	cmdp = compat_ptr(data);
+	if (get_user(data, &sgio32->sbp))
+		return -EFAULT;
+
+	sbp = compat_ptr(data);

drivers/block/nvme-scsi.c int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr) · line 3149

Quoted 10 lines
drivers/block/nvme-scsi.c +10 -0
+	if (put_user(cmdp, &sgio->cmdp) || put_user(sbp, &sgio->sbp))
+		return -EFAULT;
+	if (copy_in_user(&sgio->timeout, &sgio32->timeout, 3 * sizeof(int)))
+		return -EFAULT;
+	if (get_user(data, &sgio32->usr_ptr))
+		return -EFAULT;
+	if (put_user(compat_ptr(data), &sgio->usr_ptr))
+		return -EFAULT;
+
+	return nvme_sg_io(ns, sgio);

This should copy status and sbp/sb_len_wr from sgio back into sgio32 before returning.

Quoted 17 lines
(quoted diff) +2 -0
+}
+

int nvme_sg_get_version_num(int __user *ip)

{
	return put_user(sg_version_num, ip);
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);
 
Quoted 4 lines

#endif /* _LINUX_NVME_H */

Signature · 1 line
1.7.10.4

Thanks,
-Vishal

Quoted 6 lines

_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
http://merlin.infradead.org/mailman/listinfo/linux-nvme