Skip to contentSkip to conversation

stop using ioctl_by_bdev in the s390 DASD driver

PATCH New Christoph Hellwig 4 participants 10 messages Apr 21, 2020

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

Hi Jens and DASD maintainers,

can you take a look at this series, which stops the DASD driver from issuing ioctls from kernel space, in preparation of removing ioctl_by_bdev. I don't really like the new s390-only method, but short of forcing the dasd driver to be built into the kernel I can't think of anything better. But maybe the s390 maintainers are fine with forcing the DASD driver to be built in, in which case we could go down that route?

#1 lore raw

PATCH 1/3 dasd: refactor dasd_ioctl_information

Prepare for in-kernel callers of this functionality.

---
 drivers/s390/block/dasd_ioctl.c | 38 +++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 16 deletions(-)
drivers/s390/block/dasd_ioctl.c +22 -16
index 9a5f3add325f..dabcb4ce92da 100644
@@ -457,10 +457,9 @@ static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
 /*
  * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
  */
-static int dasd_ioctl_information(struct dasd_block *block,
-				  unsigned int cmd, void __user *argp)
+static int __dasd_ioctl_information(struct dasd_block *block,
+		struct dasd_information2_t *dasd_info)
 {
-	struct dasd_information2_t *dasd_info;
 	struct subchannel_id sch_id;
 	struct ccw_dev_id dev_id;
 	struct dasd_device *base;
@@ -473,10 +472,6 @@ static int dasd_ioctl_information(struct dasd_block *block,
 	if (!base->discipline || !base->discipline->fill_info)
 		return -EINVAL;
 
-	dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
-	if (dasd_info == NULL)
-		return -ENOMEM;
-
 	rc = base->discipline->fill_info(base, dasd_info);
 	if (rc) {
 		kfree(dasd_info);
@@ -520,15 +515,24 @@ static int dasd_ioctl_information(struct dasd_block *block,
 	list_for_each(l, &base->ccw_queue)
 		dasd_info->chanq_len++;
 	spin_unlock_irqrestore(&block->queue_lock, flags);
+	return 0;
+}
 
-	rc = 0;
-	if (copy_to_user(argp, dasd_info,
-			 ((cmd == (unsigned int) BIODASDINFO2) ?
-			  sizeof(struct dasd_information2_t) :
-			  sizeof(struct dasd_information_t))))
-		rc = -EFAULT;
+static int dasd_ioctl_information(struct dasd_block *block, void __user *argp,
+		size_t copy_size)
+{
+	struct dasd_information2_t *dasd_info;
+	int error = 0;
+
+	dasd_info = kzalloc(sizeof(*dasd_info), GFP_KERNEL);
+	if (!dasd_info)
+		return -ENOMEM;
+
+	error = __dasd_ioctl_information(block, dasd_info);
+	if (!error && copy_to_user(argp, dasd_info, copy_size))
+		error = -EFAULT;
 	kfree(dasd_info);
-	return rc;
+	return error;
 }
 
 /*
@@ -622,10 +626,12 @@ int dasd_ioctl(struct block_device *bdev, fmode_t mode,
 		rc = dasd_ioctl_check_format(bdev, argp);
 		break;
 	case BIODASDINFO:
-		rc = dasd_ioctl_information(block, cmd, argp);
+		rc = dasd_ioctl_information(block, argp,
+				sizeof(struct dasd_information_t));
 		break;
 	case BIODASDINFO2:
-		rc = dasd_ioctl_information(block, cmd, argp);
+		rc = dasd_ioctl_information(block, argp,
+				sizeof(struct dasd_information2_t));
 		break;
 	case BIODASDPRRD:
 		rc = dasd_ioctl_read_profile(block, argp);
Signature · 1 line
2.26.1
#2 lore raw

PATCH 2/3 block: add a s390-only biodasdinfo method

In reply to Christoph Hellwig

The IBM partition parser needs to query the DASD driver for details that are very s390 specific. Instead of using ioctl_by_bdev with a fake user space pointer just add a s390-specific method to get the information directly.

---
 drivers/s390/block/dasd.c       |  1 +
 drivers/s390/block/dasd_int.h   |  1 +
 drivers/s390/block/dasd_ioctl.c | 13 +++++++++++++
 include/linux/blkdev.h          |  5 +++++
 4 files changed, 20 insertions(+)
drivers/s390/block/dasd.c +1 -0
index cf87eb27879f..26edd93167e7 100644
@@ -3394,6 +3394,7 @@ dasd_device_operations = {
 	.ioctl		= dasd_ioctl,
 	.compat_ioctl	= dasd_ioctl,
 	.getgeo		= dasd_getgeo,
+	.biodasdinfo	= dasd_biodasdinfo,
 };
 
 /*******************************************************************************
drivers/s390/block/dasd_int.h +1 -0
index fa552f9f1666..6eac7b11c75b 100644
@@ -845,6 +845,7 @@ void dasd_destroy_partitions(struct dasd_block *);
 
 /* externals in dasd_ioctl.c */
 int  dasd_ioctl(struct block_device *, fmode_t, unsigned int, unsigned long);
+int dasd_biodasdinfo(struct gendisk *disk, struct dasd_information2_t *info);
 
 /* externals in dasd_proc.c */
 int dasd_proc_init(void);
drivers/s390/block/dasd_ioctl.c +13 -0
index dabcb4ce92da..332836d46ba0 100644
@@ -666,3 +666,16 @@ int dasd_ioctl(struct block_device *bdev, fmode_t mode,
 	dasd_put_device(base);
 	return rc;
 }
+
+int dasd_biodasdinfo(struct gendisk *disk, struct dasd_information2_t *info)
+{
+	struct dasd_device *base;
+	int error;
+
+	base = dasd_device_from_gendisk(disk);
+	if (!base)
+		return -ENODEV;
+	error = __dasd_ioctl_information(base->block, info);
+	dasd_put_device(base);
+	return error;
+}
include/linux/blkdev.h +5 -0
index 32868fbedc9e..3b92cc970083 100644
@@ -43,6 +43,7 @@ struct pr_ops;
 struct rq_qos;
 struct blk_queue_stats;
 struct blk_stat_callback;
+struct dasd_information2_t;
 
 #define BLKDEV_MIN_RQ	4
 #define BLKDEV_MAX_RQ	128	/* Default maximum */
@@ -1700,6 +1701,10 @@ struct block_device_operations {
 	int (*report_zones)(struct gendisk *, sector_t sector,
 			unsigned int nr_zones, report_zones_cb cb, void *data);
 	char *(*devnode)(struct gendisk *disk, umode_t *mode);
+#ifdef CONFIG_S390
+	int (*biodasdinfo)(struct gendisk *disk,
+			struct dasd_information2_t *info);
+#endif
 	struct module *owner;
 	const struct pr_ops *pr_ops;
 };
Signature · 1 line
2.26.1
#3 lore raw

PATCH 3/3 partitions/ibm: stop using ioctl_by_bdev

In reply to Christoph Hellwig

Just call the getgeo and biodasdinfo methods directly.

---
 block/partitions/ibm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
block/partitions/ibm.c +5 -3
index 073faa6a69b8..21dc6da20ff2 100644
@@ -289,6 +289,7 @@ static int find_cms1_partitions(struct parsed_partitions *state,
 int ibm_partition(struct parsed_partitions *state)
 {
 	struct block_device *bdev = state->bdev;
+	struct gendisk *disk = bdev->bd_disk;
 	int blocksize, res;
 	loff_t i_size, offset, size;
 	dasd_information2_t *info;
@@ -308,15 +309,16 @@ int ibm_partition(struct parsed_partitions *state)
 	info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
 	if (info == NULL)
 		goto out_exit;
-	geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL);
+	geo = kzalloc(sizeof(struct hd_geometry), GFP_KERNEL);
 	if (geo == NULL)
 		goto out_nogeo;
 	label = kmalloc(sizeof(union label_t), GFP_KERNEL);
 	if (label == NULL)
 		goto out_nolab;
-	if (ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
+	geo->start = get_start_sect(bdev);
+	if (!disk->fops->getgeo || disk->fops->getgeo(bdev, geo))
 		goto out_freeall;
-	if (ioctl_by_bdev(bdev, BIODASDINFO2, (unsigned long)info) != 0) {
+	if (!disk->fops->biodasdinfo || disk->fops->biodasdinfo(disk, info)) {
 		kfree(info);
 		info = NULL;
 	}
Signature · 1 line
2.26.1
#4 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

Hi Jens and DASD maintainers,

can you take a look at this series, which stops the DASD driver from issuing ioctls from kernel space, in preparation of removing ioctl_by_bdev. I don't really like the new s390-only method, but short of forcing the dasd driver to be built into the kernel I can't think of anything better. But maybe the s390 maintainers are fine with forcing the DASD driver to be built in, in which case we could go down that route?

Hmm the defconfig results in dasd built-in anyway. But distros really like to keep it modular.

Hmm, we do have

obj-$(CONFIG_DASD) += dasd_mod.o
obj-$(CONFIG_DASD_DIAG) += dasd_diag_mod.o
obj-$(CONFIG_DASD_ECKD) += dasd_eckd_mod.o
obj-$(CONFIG_DASD_FBA) += dasd_fba_mod.o

Would it work to make CONFIG_DASD built-in only and keep the other 3 as modules? Not sure about the implications.

#5 lore raw
Quoted 16 lines · On Tue, 21 Apr 2020 11:58:31 +0200 Christian Borntraeger…
Quoted 9 lines · Christoph Hellwig

Hi Jens and DASD maintainers,

can you take a look at this series, which stops the DASD driver from issuing ioctls from kernel space, in preparation of removing ioctl_by_bdev. I don't really like the new s390-only method, but short of forcing the dasd driver to be built into the kernel I can't think of anything better. But maybe the s390 maintainers are fine with forcing the DASD driver to be built in, in which case we could go down that route?

Hmm the defconfig results in dasd built-in anyway. But distros really like to keep it modular.

Hmm, we do have

Quoted 8 lines

obj-$(CONFIG_DASD) += dasd_mod.o
obj-$(CONFIG_DASD_DIAG) += dasd_diag_mod.o
obj-$(CONFIG_DASD_ECKD) += dasd_eckd_mod.o
obj-$(CONFIG_DASD_FBA) += dasd_fba_mod.o

Would it work to make CONFIG_DASD built-in only and keep the other 3 as modules? Not sure about the implications.

I don't think non-eckd dasd drivers are really useful outside of z/VM guests, so keeping at least the disciplines modular would be good.

Also, what about special purpose environments like the zfcp dumper? Would be good to be able to keep these small.

How big is the dasd code in the end?

#6 lore raw
Quoted 28 lines · Cornelia Huck
Quoted 16 lines · On Tue, 21 Apr 2020 11:58:31 +0200 Christian Borntraeger…
Quoted 9 lines · Christoph Hellwig

Hi Jens and DASD maintainers,

can you take a look at this series, which stops the DASD driver from issuing ioctls from kernel space, in preparation of removing ioctl_by_bdev. I don't really like the new s390-only method, but short of forcing the dasd driver to be built into the kernel I can't think of anything better. But maybe the s390 maintainers are fine with forcing the DASD driver to be built in, in which case we could go down that route?

Hmm the defconfig results in dasd built-in anyway. But distros really like to keep it modular.

Hmm, we do have

Quoted 8 lines

obj-$(CONFIG_DASD) += dasd_mod.o
obj-$(CONFIG_DASD_DIAG) += dasd_diag_mod.o
obj-$(CONFIG_DASD_ECKD) += dasd_eckd_mod.o
obj-$(CONFIG_DASD_FBA) += dasd_fba_mod.o

Would it work to make CONFIG_DASD built-in only and keep the other 3 as modules? Not sure about the implications.

Quoted 7 lines

I don't think non-eckd dasd drivers are really useful outside of z/VM guests, so keeping at least the disciplines modular would be good.

Also, what about special purpose environments like the zfcp dumper? Would be good to be able to keep these small.

How big is the dasd code in the end?

File: drivers/s390/block/dasd_diag_mod.ko
Size: 519976 Blocks: 1016 IO Block: 4096 regular file
--
File: drivers/s390/block/dasd_eckd_mod.ko
Size: 2125976 Blocks: 4160 IO Block: 4096 regular file
--
File: drivers/s390/block/dasd_fba_mod.ko
Size: 524256 Blocks: 1024 IO Block: 4096 regular file
--
File: drivers/s390/block/dasd_mod.ko
Size: 3273464 Blocks: 6400 IO Block: 4096 regular file

So 3 MB seems quite a lot for special purpose Linuxes like the zfcp dumper.

#7 lore raw
Quoted 1 line · Christian Borntraeger

So 3 MB seems quite a lot for special purpose Linuxes like the zfcp dumper.

Does the zfcp dumper need DASD support at all? We don't have to always build in the DASD core to avoid the strange dasd-specific block_device operation, but only ensure it is built-in if it is selected at all.

maintainer
#8 lore raw
In reply to Christoph Hellwig

Hi Christoph,

thanks for addressing this. But I must say that I do not like this approach. I get your point why you want this ioctl to be removed and I agree with that.

Having those implicit partitions at all is really ugly but I fear that this is widely used int the field. So I can not simply remove this code although I would like to. Maybe we find a way to deprecate this.
But anyway...

Forcing the driver to be build in may have a lot of implications which we should at least have a look at and maybe discuss with the distributors. All major distributions have the driver build as modules and use module parameters in the initrd for example.

The second thing is that I do not really like this s390-specific blockdevice operation.

I can imagine some ways to get rid of this ioctl_by_bdev. Maybe having a udev
rule to add a partition from userspace or having the driver add the implicit partition at the end. Or maybe something else.

If it is OK I will have a look at this and discuss this issue with my colleagues and come up with a different approach.

Regards,
Stefan

Am 21.04.20 um 08:12 schrieb Christoph Hellwig:

Quoted 9 lines

Hi Jens and DASD maintainers,

can you take a look at this series, which stops the DASD driver from issuing ioctls from kernel space, in preparation of removing ioctl_by_bdev. I don't really like the new s390-only method, but short of forcing the dasd driver to be built into the kernel I can't think of anything better. But maybe the s390 maintainers are fine with forcing the DASD driver to be built in, in which case we could go down that route?

#9 lore raw
Quoted 7 lines · Stefan Haberland

I can imagine some ways to get rid of this ioctl_by_bdev. Maybe having a udev
rule to add a partition from userspace or having the driver add the implicit partition at the end. Or maybe something else.

If it is OK I will have a look at this and discuss this issue with my colleagues and come up with a different approach.

Sure, we can wait a few days. Note that I don't want to break existing userspace, which kinda speaks against a udev solution.