From: "Jan Beulich" Subject: [PATCH] linux/blktap2: Fwd: Re: Crash on blktap shutdown Date: Mon, 01 Mar 2010 09:25:06 +0000 Message-ID: <4B8B96020200007800031C98@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartCDE700E2.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Daniel Stodden List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartCDE700E2.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: blktap2: Fix queue restart, racing block device removal. Makes tapdisk context test dev->gd before attempting a queue restart, with the device lock held. Fixes a race lost against device destruction, which may issued anywhere on the control path. Signed-off-by: Daniel Stodden Signed-off-by: Jan Beulich --- a/drivers/xen/blktap2/device.c +++ b/drivers/xen/blktap2/device.c @@ -946,8 +946,6 @@ struct blktap_device *dev; =20 dev =3D &tap->device; - if (!dev->gd || !dev->gd->queue) - return; =20 if (blktap_active(tap) && RING_FULL(&tap->ring.ring)) { blktap_defer(tap); @@ -963,11 +961,15 @@ spin_lock_irq(&dev->lock); =20 /* Re-enable calldowns. */ - if (blk_queue_stopped(dev->gd->queue)) - blk_start_queue(dev->gd->queue); + if (dev->gd) { + struct request_queue *rq =3D dev->gd->queue; =20 - /* Kick things off immediately. */ - blktap_device_do_request(dev->gd->queue); + if (blk_queue_stopped(rq)) + blk_start_queue(rq); + + /* Kick things off immediately. */ + blktap_device_do_request(rq); + } =20 spin_unlock_irq(&dev->lock); } @@ -1056,6 +1058,7 @@ blktap_device_destroy(struct blktap *tap) { struct blktap_device *dev =3D &tap->device; + struct gendisk *gd =3D dev->gd; =20 if (!test_bit(BLKTAP_DEVICE, &tap->dev_inuse)) return 0; @@ -1067,8 +1070,9 @@ =20 spin_lock_irq(&dev->lock); /* No more blktap_device_do_request(). */ - blk_stop_queue(dev->gd->queue); + blk_stop_queue(gd->queue); clear_bit(BLKTAP_DEVICE, &tap->dev_inuse); + dev->gd =3D NULL; spin_unlock_irq(&dev->lock); =20 #ifdef ENABLE_PASSTHROUGH @@ -1076,11 +1080,9 @@ blktap_device_close_bdev(tap); #endif =20 - del_gendisk(dev->gd); - blk_cleanup_queue(dev->gd->queue); - put_disk(dev->gd); - - dev->gd =3D NULL; + del_gendisk(gd); + blk_cleanup_queue(gd->queue); + put_disk(gd); =20 wake_up(&tap->wq); =20 --=__PartCDE700E2.1__= Content-Type: text/plain; name="blktap2-queue-restart-race.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="blktap2-queue-restart-race.patch" Subject: blktap2: Fix queue restart, racing block device removal.=0A=0AMake= s tapdisk context test dev->gd before attempting a queue restart,=0Awith = the device lock held. Fixes a race lost against device=0Adestruction, = which may issued anywhere on the control path.=0A=0ASigned-off-by: Daniel = Stodden =0ASigned-off-by: Jan Beulich =0A=0A--- a/drivers/xen/blktap2/device.c=0A+++ b/drivers/xen/blk= tap2/device.c=0A@@ -946,8 +946,6 @@=0A struct blktap_device *dev;=0A =0A = dev =3D &tap->device;=0A- if (!dev->gd || !dev->gd->queue)=0A- = return;=0A =0A if (blktap_active(tap) && RING_FULL(&tap->ring.ring)) {=0A = blktap_defer(tap);=0A@@ -963,11 +961,15 @@=0A spin_lock_i= rq(&dev->lock);=0A =0A /* Re-enable calldowns. */=0A- if (blk_queue_stopp= ed(dev->gd->queue))=0A- blk_start_queue(dev->gd->queue);=0A+ if = (dev->gd) {=0A+ struct request_queue *rq =3D dev->gd->queue;=0A = =0A- /* Kick things off immediately. */=0A- blktap_device_do_request(de= v->gd->queue);=0A+ if (blk_queue_stopped(rq))=0A+ = blk_start_queue(rq);=0A+=0A+ /* Kick things off immediately. = */=0A+ blktap_device_do_request(rq);=0A+ }=0A =0A = spin_unlock_irq(&dev->lock);=0A }=0A@@ -1056,6 +1058,7 @@=0A blktap_device_= destroy(struct blktap *tap)=0A {=0A struct blktap_device *dev =3D = &tap->device;=0A+ struct gendisk *gd =3D dev->gd;=0A =0A if = (!test_bit(BLKTAP_DEVICE, &tap->dev_inuse))=0A return 0;=0A@@ = -1067,8 +1070,9 @@=0A =0A spin_lock_irq(&dev->lock);=0A /* No more = blktap_device_do_request(). */=0A- blk_stop_queue(dev->gd->queue);=0A+= blk_stop_queue(gd->queue);=0A clear_bit(BLKTAP_DEVICE, &tap->dev_= inuse);=0A+ dev->gd =3D NULL;=0A spin_unlock_irq(&dev->lock);=0A = =0A #ifdef ENABLE_PASSTHROUGH=0A@@ -1076,11 +1080,9 @@=0A = blktap_device_close_bdev(tap);=0A #endif=0A =0A- del_gendisk(dev->gd= );=0A- blk_cleanup_queue(dev->gd->queue);=0A- put_disk(dev->gd);=0A-=0A- = dev->gd =3D NULL;=0A+ del_gendisk(gd);=0A+ blk_cleanup_queue(gd->queue= );=0A+ put_disk(gd);=0A =0A wake_up(&tap->wq);=0A =0A --=__PartCDE700E2.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartCDE700E2.1__=--