Skip to contentSkip to conversation

: Fix some bugs in usbfront

PATCH In review Ky Srinivasan 2 participants 5 messages Mar 12, 2010 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : Fix some bugs in usbfront

The attached patch fixes some bugs in usbfront.

Bug#584218: Fix a scheduling race in usbfront. Create the thread only after we are connected. The current code schedules the thread at a point where the communication rings are not initialized yet.

drivers/xen/usbfront/xenbus.c +14 -10
Index: linux/drivers/xen/usbfront/xenbus.c
===================================================================
@@ -192,11 +192,23 @@ static int connect(struct xenbus_device
 	usbif_conn_request_t *req;
 	int i, idx, err;
 	int notify;
+	char name[TASK_COMM_LEN];
+	struct usb_hcd *hcd;
+
+	hcd = info_to_hcd(info);
+	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
 
 	err = talk_to_backend(dev, info);
 	if (err)
 		return err;
 
+	info->kthread = kthread_run(xenhcd_schedule, info, name);
+	if (IS_ERR(info->kthread)) {
+		err = PTR_ERR(info->kthread);
+		info->kthread = NULL;
+		xenbus_dev_fatal(dev, err, "Error creating thread");
+		return err;
+	}
 	/* prepare ring for hotplug notification */
 	for (idx = 0, i = 0; i < USB_CONN_RING_SIZE; i++) {
 		req = RING_GET_REQUEST(&info->conn_ring, idx);
@@ -274,7 +286,6 @@ static int usbfront_probe(struct xenbus_
 	int err;
 	struct usb_hcd *hcd;
 	struct usbfront_info *info;
-	char name[TASK_COMM_LEN];
 
 	if (usb_disabled())
 		return -ENODEV;
@@ -298,13 +309,6 @@ static int usbfront_probe(struct xenbus_
 	}
 
 	init_waitqueue_head(&info->wq);
-	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
-	info->kthread = kthread_run(xenhcd_schedule, info, name);
-	if (IS_ERR(info->kthread)) {
-		err = PTR_ERR(info->kthread);
-		info->kthread = NULL;
-		goto fail;
-	}
 
 	return 0;
 
@@ -343,8 +347,8 @@ static void backend_changed(struct xenbu
 	case XenbusStateInitWait:
 		if (dev->state != XenbusStateInitialising)
 			break;
-		connect(dev);
-		xenbus_switch_state(dev, XenbusStateConnected);
+		if (!connect(dev))
+			xenbus_switch_state(dev, XenbusStateConnected);
 		break;
 
 	case XenbusStateClosing:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 2 lines · Ky Srinivasan

The attached patch fixes some bugs in usbfront.

What kernel version is this patch against? linux-2.6.18-xen?

-- Pasi

Quoted 78 lines

Bug#584218: Fix a scheduling race in usbfront. Create the thread only after we are connected. The current code schedules the thread at a point where the communication rings are not initialized yet.

Index: linux/drivers/xen/usbfront/xenbus.c
===================================================================

drivers/xen/usbfront/xenbus.c +14 -10
@@ -192,11 +192,23 @@ static int connect(struct xenbus_device
 	usbif_conn_request_t *req;
 	int i, idx, err;
 	int notify;
+	char name[TASK_COMM_LEN];
+	struct usb_hcd *hcd;
+
+	hcd = info_to_hcd(info);
+	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
 
 	err = talk_to_backend(dev, info);
 	if (err)
 		return err;
 
+	info->kthread = kthread_run(xenhcd_schedule, info, name);
+	if (IS_ERR(info->kthread)) {
+		err = PTR_ERR(info->kthread);
+		info->kthread = NULL;
+		xenbus_dev_fatal(dev, err, "Error creating thread");
+		return err;
+	}
 	/* prepare ring for hotplug notification */
 	for (idx = 0, i = 0; i < USB_CONN_RING_SIZE; i++) {
 		req = RING_GET_REQUEST(&info->conn_ring, idx);
@@ -274,7 +286,6 @@ static int usbfront_probe(struct xenbus_
 	int err;
 	struct usb_hcd *hcd;
 	struct usbfront_info *info;
-	char name[TASK_COMM_LEN];
 
 	if (usb_disabled())
 		return -ENODEV;
@@ -298,13 +309,6 @@ static int usbfront_probe(struct xenbus_
 	}
 
 	init_waitqueue_head(&info->wq);
-	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
-	info->kthread = kthread_run(xenhcd_schedule, info, name);
-	if (IS_ERR(info->kthread)) {
-		err = PTR_ERR(info->kthread);
-		info->kthread = NULL;
-		goto fail;
-	}
 
 	return 0;
 
@@ -343,8 +347,8 @@ static void backend_changed(struct xenbu
 	case XenbusStateInitWait:
 		if (dev->state != XenbusStateInitialising)
 			break;
-		connect(dev);
-		xenbus_switch_state(dev, XenbusStateConnected);
+		if (!connect(dev))
+			xenbus_switch_state(dev, XenbusStateConnected);
 		break;
 
 	case XenbusStateClosing:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 3/12/2010 at 5:30 PM, in message <[email protected]>, Pasi

Quoted 5 lines · Kärkkäinen
Quoted 2 lines · Ky Srinivasan

The attached patch fixes some bugs in usbfront.

What kernel version is this patch against? linux-2.6.18-xen?

Once again this patch is against 2.6.32 kernel (sles11 sp1). Sorry for not making this clear in the patch.

Regards,
K. Y

Quoted 81 lines

-- Pasi

Quoted 7 lines

Bug#584218: Fix a scheduling race in usbfront. Create the thread only after

we

Quoted 71 lines

are connected. The current code schedules the thread at a point where the communication rings are not initialized yet.

Index: linux/drivers/xen/usbfront/xenbus.c
===================================================================

drivers/xen/usbfront/xenbus.c +14 -10
@@ -192,11 +192,23 @@ static int connect(struct xenbus_device
 	usbif_conn_request_t *req;
 	int i, idx, err;
 	int notify;
+	char name[TASK_COMM_LEN];
+	struct usb_hcd *hcd;
+
+	hcd = info_to_hcd(info);
+	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
 
 	err = talk_to_backend(dev, info);
 	if (err)
 		return err;
 
+	info->kthread = kthread_run(xenhcd_schedule, info, name);
+	if (IS_ERR(info->kthread)) {
+		err = PTR_ERR(info->kthread);
+		info->kthread = NULL;
+		xenbus_dev_fatal(dev, err, "Error creating thread");
+		return err;
+	}
 	/* prepare ring for hotplug notification */
 	for (idx = 0, i = 0; i < USB_CONN_RING_SIZE; i++) {
 		req = RING_GET_REQUEST(&info->conn_ring, idx);
@@ -274,7 +286,6 @@ static int usbfront_probe(struct xenbus_
 	int err;
 	struct usb_hcd *hcd;
 	struct usbfront_info *info;
-	char name[TASK_COMM_LEN];
 
 	if (usb_disabled())
 		return -ENODEV;
@@ -298,13 +309,6 @@ static int usbfront_probe(struct xenbus_
 	}
 
 	init_waitqueue_head(&info->wq);
-	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
-	info->kthread = kthread_run(xenhcd_schedule, info, name);
-	if (IS_ERR(info->kthread)) {
-		err = PTR_ERR(info->kthread);
-		info->kthread = NULL;
-		goto fail;
-	}
 
 	return 0;
 
@@ -343,8 +347,8 @@ static void backend_changed(struct xenbu
 	case XenbusStateInitWait:
 		if (dev->state != XenbusStateInitialising)
 			break;
-		connect(dev);
-		xenbus_switch_state(dev, XenbusStateConnected);
+		if (!connect(dev))
+			xenbus_switch_state(dev, XenbusStateConnected);
 		break;
 
 	case XenbusStateClosing:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 4 lines · Ky Srinivasan
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 3/12/2010 at 5:30 PM, in message <[email protected]>, Pasi

Kärkkäinen<[email protected]> wrote:

Quoted 8 lines
Quoted 5 lines · Ky Srinivasan
Quoted 2 lines

The attached patch fixes some bugs in usbfront.

What kernel version is this patch against? linux-2.6.18-xen?

Once again this patch is against 2.6.32 kernel (sles11 sp1). Sorry for not making this clear in the patch.

Ok.

Does the SLES11 2.6.27 kernel-xen have usbback/usbfront? How about the opensuse kernel-xen versions?

I can add the info to:
http://wiki.xensource.com/xenwiki/XenUSBPassthrough

-- Pasi

Quoted 85 lines

Regards,
K. Y

Quoted 81 lines

-- Pasi

Quoted 7 lines

Bug#584218: Fix a scheduling race in usbfront. Create the thread only after

we

Quoted 71 lines

are connected. The current code schedules the thread at a point where the communication rings are not initialized yet.

Index: linux/drivers/xen/usbfront/xenbus.c
===================================================================

drivers/xen/usbfront/xenbus.c +14 -10
@@ -192,11 +192,23 @@ static int connect(struct xenbus_device
 	usbif_conn_request_t *req;
 	int i, idx, err;
 	int notify;
+	char name[TASK_COMM_LEN];
+	struct usb_hcd *hcd;
+
+	hcd = info_to_hcd(info);
+	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
 
 	err = talk_to_backend(dev, info);
 	if (err)
 		return err;
 
+	info->kthread = kthread_run(xenhcd_schedule, info, name);
+	if (IS_ERR(info->kthread)) {
+		err = PTR_ERR(info->kthread);
+		info->kthread = NULL;
+		xenbus_dev_fatal(dev, err, "Error creating thread");
+		return err;
+	}
 	/* prepare ring for hotplug notification */
 	for (idx = 0, i = 0; i < USB_CONN_RING_SIZE; i++) {
 		req = RING_GET_REQUEST(&info->conn_ring, idx);
@@ -274,7 +286,6 @@ static int usbfront_probe(struct xenbus_
 	int err;
 	struct usb_hcd *hcd;
 	struct usbfront_info *info;
-	char name[TASK_COMM_LEN];
 
 	if (usb_disabled())
 		return -ENODEV;
@@ -298,13 +309,6 @@ static int usbfront_probe(struct xenbus_
 	}
 
 	init_waitqueue_head(&info->wq);
-	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
-	info->kthread = kthread_run(xenhcd_schedule, info, name);
-	if (IS_ERR(info->kthread)) {
-		err = PTR_ERR(info->kthread);
-		info->kthread = NULL;
-		goto fail;
-	}
 
 	return 0;
 
@@ -343,8 +347,8 @@ static void backend_changed(struct xenbu
 	case XenbusStateInitWait:
 		if (dev->state != XenbusStateInitialising)
 			break;
-		connect(dev);
-		xenbus_switch_state(dev, XenbusStateConnected);
+		if (!connect(dev))
+			xenbus_switch_state(dev, XenbusStateConnected);
 		break;
 
 	case XenbusStateClosing:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 3/12/2010 at 5:42 PM, in message <[email protected]>, Pasi

Quoted 12 lines · Kärkkäinen
Quoted 3 lines · Ky Srinivasan
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 3/12/2010 at 5:30 PM, in message <[email protected]>,

Pasi

Quoted 7 lines
Quoted 5 lines · Kärkkäinen
Quoted 2 lines · Ky Srinivasan

The attached patch fixes some bugs in usbfront.

What kernel version is this patch against? linux-2.6.18-xen?

Quoted 7 lines
Quoted 2 lines

Once again this patch is against 2.6.32 kernel (sles11 sp1). Sorry for not making this clear in the patch.

Ok.

Does the SLES11 2.6.27 kernel-xen have usbback/usbfront? How about the opensuse kernel-xen versions?

Well, PV USB will be supported in sles11 sp1. I am not sure what the plans are for other versions.

Quoted 3 lines

I can add the info to:
http://wiki.xensource.com/xenwiki/XenUSBPassthrough

That will be good.

Thanks,

K. Y

Quoted 89 lines

-- Pasi

Quoted 12 lines

Regards,
K. Y

Quoted 9 lines

-- Pasi

Quoted 7 lines

Bug#584218: Fix a scheduling race in usbfront. Create the thread only

after

Quoted 73 lines
Quoted 72 lines

we

Quoted 71 lines

are connected. The current code schedules the thread at a point where the communication rings are not initialized yet.

Index: linux/drivers/xen/usbfront/xenbus.c
===================================================================

drivers/xen/usbfront/xenbus.c +14 -10
@@ -192,11 +192,23 @@ static int connect(struct xenbus_device
 	usbif_conn_request_t *req;
 	int i, idx, err;
 	int notify;
+	char name[TASK_COMM_LEN];
+	struct usb_hcd *hcd;
+
+	hcd = info_to_hcd(info);
+	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
 
 	err = talk_to_backend(dev, info);
 	if (err)
 		return err;
 
+	info->kthread = kthread_run(xenhcd_schedule, info, name);
+	if (IS_ERR(info->kthread)) {
+		err = PTR_ERR(info->kthread);
+		info->kthread = NULL;
+		xenbus_dev_fatal(dev, err, "Error creating thread");
+		return err;
+	}
 	/* prepare ring for hotplug notification */
 	for (idx = 0, i = 0; i < USB_CONN_RING_SIZE; i++) {
 		req = RING_GET_REQUEST(&info->conn_ring, idx);
@@ -274,7 +286,6 @@ static int usbfront_probe(struct xenbus_
 	int err;
 	struct usb_hcd *hcd;
 	struct usbfront_info *info;
-	char name[TASK_COMM_LEN];
 
 	if (usb_disabled())
 		return -ENODEV;
@@ -298,13 +309,6 @@ static int usbfront_probe(struct xenbus_
 	}
 
 	init_waitqueue_head(&info->wq);
-	snprintf(name, TASK_COMM_LEN, "xenhcd.%d", hcd->self.busnum);
-	info->kthread = kthread_run(xenhcd_schedule, info, name);
-	if (IS_ERR(info->kthread)) {
-		err = PTR_ERR(info->kthread);
-		info->kthread = NULL;
-		goto fail;
-	}
 
 	return 0;
 
@@ -343,8 +347,8 @@ static void backend_changed(struct xenbu
 	case XenbusStateInitWait:
 		if (dev->state != XenbusStateInitialising)
 			break;
-		connect(dev);
-		xenbus_switch_state(dev, XenbusStateConnected);
+		if (!connect(dev))
+			xenbus_switch_state(dev, XenbusStateConnected);
 		break;
 
 	case XenbusStateClosing:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel