Skip to contentSkip to conversation

sparc64: prevent sunvdc panic when mpgroup disk added to guest domain

PATCH In review Jim Quigley 3 participants 6 messages Jul 20, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc64: prevent sunvdc panic when mpgroup disk added to guest domain

Using mpgroup to define multiple paths for a virtual disk causes multiple virtual-device-port ports to be created for that virtual device. Each virtual-device-port port then gets a vdisk created for it by the Linux sunvdc driver. As mpgroup is not supported by the Linux sunvdc driver it cannot handle multiple ports for a single vdisk, leading to a kernel panic at startup.

This fix prevents more than one vdisk per virtual-device-port being created until full virtual disk multipathing (mpgroup) support is implemented.

---
 drivers/block/sunvdc.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
drivers/block/sunvdc.c +66 -0
index 6b16ead..9638403 100644
@@ -875,6 +875,58 @@ static void print_version(void)
 		printk(KERN_INFO "%s", version);
 }
 
+struct vdc_check_port_data {
+	int	dev_no;
+	char	*type;
+};
+
+static int vdc_device_probed(struct device *dev, void *arg)
+{
+	struct vio_dev *vdev = to_vio_dev(dev);
+	struct vdc_check_port_data *port_data;
+
+	port_data = (struct vdc_check_port_data *)arg;
+
+	if ((vdev->dev_no = port_data->dev_no) &&
+	    (!(strcmp((char *)&vdev->type, port_data->type))) &&
+		dev_get_drvdata(dev)) {
+		/*
+		 * This device has already been configured
+		 * by vdc_port_probe()
+		 */
+		return 1;
+	} else {
+		return 0;
+	}
+}
+
+/*
+ * Determine whether the VIO device is part of an mpgroup
+ * by locating all the virtual-device-port nodes associated
+ * with the parent virtual-device node for the VIO device
+ * and checking whether any of these nodes are vdc-ports
+ * which have already been configured.
+ *
+ * Returns true if this device is part of an mpgroup and has
+ * already been probed.
+ */
+static bool vdc_port_mpgroup_check(struct vio_dev *vdev)
+{
+	struct vdc_check_port_data port_data;
+	struct device *dev;
+
+	port_data.dev_no = vdev->dev_no;
+	port_data.type = (char *)&vdev->type;
+
+	dev = device_find_child(vdev->dev.parent, (void *)&port_data,
+				vdc_device_probed);
+
+	if (dev)
+		return true;
+
+	return false;
+}
+
 static int vdc_port_probe(struct vio_dev *vdev, const struct vio_device_id *id)
 {
 	struct mdesc_handle *hp;
@@ -893,6 +945,16 @@ static int vdc_port_probe(struct vio_dev *vdev, const struct vio_device_id *id)
 		goto err_out_release_mdesc;
 	}
 
+	/*
+	 * Check if this device is part of an mpgroup
+	 */
+	if (vdc_port_mpgroup_check(vdev)) {
+		printk(KERN_WARNING
+			"VIO: Ignoring extra vdisk port %s",
+			dev_name(&vdev->dev));
+		goto err_out_release_mdesc;
+	}
+
 	port = kzalloc(sizeof(*port), GFP_KERNEL);
 	err = -ENOMEM;
 	if (!port) {
@@ -943,6 +1005,10 @@ static int vdc_port_probe(struct vio_dev *vdev, const struct vio_device_id *id)
 	if (err)
 		goto err_out_free_tx_ring;
 
+	/*
+	 * Note that the device driver_data is used to determine
+	 * whether the port has been probed.
+	 */
 	dev_set_drvdata(&vdev->dev, port);
 
 	mdesc_release(hp);
Signature · 1 line
1.7.1
#1 lore raw

From: Jim Quigley <[email protected]>
Date: Thu, 20 Jul 2017 06:29:50 -0400

Quoted 7 lines

Using mpgroup to define multiple paths for a virtual disk causes multiple virtual-device-port ports to be created for that virtual device. Each virtual-device-port port then gets a vdisk created for it by the Linux sunvdc driver. As mpgroup is not supported by the Linux sunvdc driver it cannot handle multiple ports for a single vdisk, leading to a kernel panic at startup.

Quoted 7 lines

This fix prevents more than one vdisk per virtual-device-port being created until full virtual disk multipathing (mpgroup) support is implemented.

Please use "sunvdc: " as your subsystem prefix in your subject line.

drivers/block/sunvdc.c static void print_version(void) · line 891

Quoted 2 lines
drivers/block/sunvdc.c +2 -0
+	if ((vdev->dev_no = port_data->dev_no) &&
+	    (!(strcmp((char *)&vdev->type, port_data->type))) &&

vdev->type is a char pointer already, there is no need for this cast and it's looks awful as well :-)

drivers/block/sunvdc.c static void print_version(void) · line 899

Quoted 3 lines
drivers/block/sunvdc.c +3 -0
+		return 1;
+	} else {
+		return 0;

Please use "bool" as the return type and true/false here.

drivers/block/sunvdc.c static void print_version(void) · line 919

Quoted 1 line
drivers/block/sunvdc.c +1 -0
+	port_data.type = (char *)&vdev->type;

Again, no need for this cast.

drivers/block/sunvdc.c static void print_version(void) · line 921

Quoted 1 line
drivers/block/sunvdc.c +1 -0
+	dev = device_find_child(vdev->dev.parent, (void *)&port_data,

You also never need to explicitly cast to "void *", it will implicitly be done if that is the argument type.

#2 lore raw
In reply to Jim Quigley

Hi Jim.

A few nitpicks.

Quoted 15 lines · Jim Quigley

Using mpgroup to define multiple paths for a virtual disk causes multiple virtual-device-port ports to be created for that virtual device. Each virtual-device-port port then gets a vdisk created for it by the Linux sunvdc driver. As mpgroup is not supported by the Linux sunvdc driver it cannot handle multiple ports for a single vdisk, leading to a kernel panic at startup.

This fix prevents more than one vdisk per virtual-device-port being created until full virtual disk multipathing (mpgroup) support is implemented.

drivers/block/sunvdc.c +1 -0
+

drivers/block/sunvdc.c static void print_version(void) · line 912

Quoted 10 lines
drivers/block/sunvdc.c +10 -0
+/*
+ * Determine whether the VIO device is part of an mpgroup
+ * by locating all the virtual-device-port nodes associated
+ * with the parent virtual-device node for the VIO device
+ * and checking whether any of these nodes are vdc-ports
+ * which have already been configured.
+ *
+ * Returns true if this device is part of an mpgroup and has
+ * already been probed.
+ */

This filel uses "netdev" style for comments.
Change coments to look like this:

/* Bla bla.
* More bla blah.
*/

drivers/block/sunvdc.c static void print_version(void) · line 919

Quoted 7 lines
drivers/block/sunvdc.c +7 -0
+static bool vdc_port_mpgroup_check(struct vio_dev *vdev)
+{
+	struct vdc_check_port_data port_data;
+	struct device *dev;
+
+	port_data.dev_no = vdev->dev_no;
+	port_data.type = (char *)&vdev->type;

Cast not needed?

Sam

#3 lore raw
In reply to Jim Quigley
Quoted 10 lines · David Miller

From: Jim Quigley <[email protected]>
Date: Thu, 20 Jul 2017 06:29:50 -0400

Quoted 7 lines

Using mpgroup to define multiple paths for a virtual disk causes multiple virtual-device-port ports to be created for that virtual device. Each virtual-device-port port then gets a vdisk created for it by the Linux sunvdc driver. As mpgroup is not supported by the Linux sunvdc driver it cannot handle multiple ports for a single vdisk, leading to a kernel panic at startup.

Quoted 8 lines
Quoted 7 lines

This fix prevents more than one vdisk per virtual-device-port being created until full virtual disk multipathing (mpgroup) support is implemented.

Please use "sunvdc: " as your subsystem prefix in your subject line.

Will do.

Quoted 5 lines

drivers/block/sunvdc.c static void print_version(void) · line 891

Quoted 3 lines
drivers/block/sunvdc.c +2 -0
+	if ((vdev->dev_no = port_data->dev_no) &&
+	    (!(strcmp((char *)&vdev->type, port_data->type))) &&

vdev->type is a char pointer already, there is no need for this cast and it's looks awful as well :-)

     vdev->type is defined as

                 char                    type[VIO_MAX_TYPE_LEN];

     and removing the cast results in :-

drivers/block/sunvdc.c: In function 'vdc_device_probed':
drivers/block/sunvdc.c:891: warning: passing argument 1 of 'strcmp' from incompatible pointer type
./include/linux/string.h:42: note: expected 'const char *' but argument is of type 'char (*)[32]'

Quoted 5 lines

drivers/block/sunvdc.c static void print_version(void) · line 899

Quoted 4 lines
drivers/block/sunvdc.c +3 -0
+		return 1;
+	} else {
+		return 0;

Please use "bool" as the return type and true/false here.

It needs to be an int for device_find_child().

drivers/block/sunvdc.c:921: warning: passing argument 3 of 'device_find_child' from incompatible pointer type ./include/linux/device.h:1125: note: expected 'int (*)(struct device *, void *)' but argument is of type 'bool (*)(struct device *, void *)'

Quoted 3 lines

drivers/block/sunvdc.c static void print_version(void) · line 919

Quoted 2 lines
drivers/block/sunvdc.c +1 -0
+	port_data.type = (char *)&vdev->type;

Again, no need for this cast.

The same as above :-

drivers/block/sunvdc.c:918: warning: assignment from incompatible pointer type

Quoted 4 lines

drivers/block/sunvdc.c static void print_version(void) · line 921

Quoted 2 lines
drivers/block/sunvdc.c +1 -0
+	dev = device_find_child(vdev->dev.parent, (void *)&port_data,

You also never need to explicitly cast to "void *", it will implicitly be done if that is the argument type.

Yes.

thanks

regards

Jim Q.

#4 lore raw
In reply to Jim Quigley
Quoted 33 lines · Sam Ravnborg

Hi Jim.

A few nitpicks.

Quoted 15 lines · Jim Quigley

Using mpgroup to define multiple paths for a virtual disk causes multiple virtual-device-port ports to be created for that virtual device. Each virtual-device-port port then gets a vdisk created for it by the Linux sunvdc driver. As mpgroup is not supported by the Linux sunvdc driver it cannot handle multiple ports for a single vdisk, leading to a kernel panic at startup.

This fix prevents more than one vdisk per virtual-device-port being created until full virtual disk multipathing (mpgroup) support is implemented.

drivers/block/sunvdc.c +1 -0
+

drivers/block/sunvdc.c static void print_version(void) · line 912

Quoted 10 lines
drivers/block/sunvdc.c +10 -0
+/*
+ * Determine whether the VIO device is part of an mpgroup
+ * by locating all the virtual-device-port nodes associated
+ * with the parent virtual-device node for the VIO device
+ * and checking whether any of these nodes are vdc-ports
+ * which have already been configured.
+ *
+ * Returns true if this device is part of an mpgroup and has
+ * already been probed.
+ */

This filel uses "netdev" style for comments.
Change coments to look like this:

Quoted 3 lines

/* Bla bla.
* More bla blah.
*/

Will do.

Quoted 10 lines

drivers/block/sunvdc.c static void print_version(void) · line 919

Quoted 9 lines
drivers/block/sunvdc.c +7 -0
+static bool vdc_port_mpgroup_check(struct vio_dev *vdev)
+{
+	struct vdc_check_port_data port_data;
+	struct device *dev;
+
+	port_data.dev_no = vdev->dev_no;
+	port_data.type = (char *)&vdev->type;

Cast not needed?

It appears to be needed,

drivers/block/sunvdc.c:918: warning: assignment from incompatible pointer type

thanks

regards

Jim Q.

Quoted 2 lines

Sam

#5 lore raw
In reply to Jim Quigley

From: Jim Quigley <[email protected]>
Date: Thu, 20 Jul 2017 21:19:52 +0100

Quoted 12 lines · David Miller
Quoted 4 lines

drivers/block/sunvdc.c static void print_version(void) · line 891

Quoted 2 lines
drivers/block/sunvdc.c +2 -0
+	if ((vdev->dev_no = port_data->dev_no) &&
+	    (!(strcmp((char *)&vdev->type, port_data->type))) &&

vdev->type is a char pointer already, there is no need for this cast and it's looks awful as well :-)

    vdev->type is defined as

                char                    type[VIO_MAX_TYPE_LEN];

    and removing the cast results in :-
Quoted 5 lines

drivers/block/sunvdc.c: In function 'vdc_device_probed':
drivers/block/sunvdc.c:891: warning: passing argument 1 of 'strcmp' from incompatible pointer type ./include/linux/string.h:42: note: expected 'const char *' but argument is of type 'char (*)[32]'

That's unfortunate, ok.

Quoted 7 lines
Quoted 5 lines

drivers/block/sunvdc.c static void print_version(void) · line 899

Quoted 4 lines
drivers/block/sunvdc.c +3 -0
+		return 1;
+	} else {
+		return 0;

Please use "bool" as the return type and true/false here.

It needs to be an int for device_find_child().

Ok.