From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/backends: Check for insane amounts of requests on the ring Date: Fri, 07 Jun 2013 09:04:47 +0100 Message-ID: <51B1B03F02000078000DC23A@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part1323FE0F.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Konrad Rzeszutek Wilk 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. --=__Part1323FE0F.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Check that the ring does not have an insane amount of requests (more than there could fit on the ring). If we detect this case we will stop processing the requests and wait until the XenBus disconnects the ring. The existing check RING_REQUEST_CONS_OVERFLOW which checks for how many responses we have created in the past (rsp_prod_pvt) vs requests consumed (req_cons) and whether said difference is greater or equal to the size of the ring, does not catch this case. Wha the condition does check if there is a need to process more as we still have a backlog of responses to finish. Note that both of those values (rsp_prod_pvt and req_cons) are not exposed on the shared ring. To understand this problem a mini crash course in ring protocol response/request updates is in place. There are four entries: req_prod and rsp_prod; req_event and rsp_event to track the ring entries. We are only concerned about the first two - which set the tone of this bug. The req_prod is a value incremented by frontend for each request put on the ring. Conversely the rsp_prod is a value incremented by the backend for each response put on the ring (rsp_prod gets set by rsp_prod_pvt when pushing the responses on the ring). Both values can wrap and are modulo the size of the ring (in block case that is 32). Please see RING_GET_REQUEST and RING_GET_RESPONSE for the more details. The culprit here is that if the difference between the req_prod and req_cons is greater than the ring size we have a problem. Fortunately for us, the '__do_block_io_op' loop: rc =3D blk_rings->common.req_cons; rp =3D blk_rings->common.sring->req_prod; while (rc !=3D rp) { .. blk_rings->common.req_cons =3D ++rc; /* before make_respons= e() */ } will loop up to the point when rc =3D=3D rp. The macros inside of the loop (RING_GET_REQUEST) is smart and is indexing based on the modulo of the ring size. If the frontend has provided a bogus req_prod value we will loop until the 'rc =3D=3D rp' - which means we could be processing already processed requests (or responses) often. The reason the RING_REQUEST_CONS_OVERFLOW is not helping here is b/c it only tracks how many responses we have internally produced and whether we would should process more. The astute reader will notice that the macro RING_REQUEST_CONS_OVERFLOW provides two arguments - more on this later. For example, if we were to enter this function with these values: blk_rings->common.sring->req_prod =3D X+31415 (X is the value = from the last time __do_block_io_op was called). blk_rings->common.req_cons =3D X blk_rings->common.rsp_prod_pvt =3D X The RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, blk_rings->common.req_co= ns) is doing: req_cons - sring->rsp_prod_pvt >=3D 32 Which is, X - X >=3D 32 or 0 >=3D 32 And that is false, so we continue on looping (this bug). If we re-use said macro RING_REQUEST_CONS_OVERFLOW and pass in the rp instead (sring->req_prod) of rc, the this macro can do the check: req_prod - sring->rsp_prov_pvt >=3D 32 Which is, X + 31415 - X >=3D 32 , or 31415 >=3D 32 which is true, so we can error out and break out of the function. Signed-off-by: Konrad Rzeszutek Wilk Extend the blkback-only upstream patch to other affected backends. Signed-off-by: Jan Beulich --- a/drivers/xen/blkback/blkback.c +++ b/drivers/xen/blkback/blkback.c @@ -229,8 +229,18 @@ int blkif_schedule(void *arg) blkif->waiting_reqs =3D 0; smp_mb(); /* clear flag *before* checking for work */ =20 - if (do_block_io_op(blkif)) + switch (do_block_io_op(blkif)) { + case 1: blkif->waiting_reqs =3D 1; + case 0: + break; + case -EACCES: + wait_event_interruptible(blkif->shutdown_wq, + kthread_should_stop()); + break; + default: + BUG(); + } unplug_queue(blkif); =20 if (log_stats && time_after(jiffies, blkif->st_print)) @@ -320,6 +330,15 @@ static int do_block_io_op(blkif_t *blkif rp =3D blk_rings->common.sring->req_prod; rmb(); /* Ensure we see queued requests up to 'rp'. */ =20 + /* N.B. 'rp', not 'rc'. */ + if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rp)) { + printk(KERN_WARNING "blkback:" + " Dom%d provided bogus ring requests (%#x - %#x =3D = %u)." + " Halting ring processing on dev=3D%04x\n", + blkif->domid, rp, rc, rp - rc, blkif->vbd.pdevice); + return -EACCES; + } + while (rc !=3D rp) { if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rc)) break; --- a/drivers/xen/blkback/common.h +++ b/drivers/xen/blkback/common.h @@ -89,6 +89,7 @@ typedef struct blkif_st { int st_wr_sect; =20 wait_queue_head_t waiting_to_free; + wait_queue_head_t shutdown_wq; } blkif_t; =20 struct backend_info --- a/drivers/xen/blkback/interface.c +++ b/drivers/xen/blkback/interface.c @@ -51,6 +51,7 @@ blkif_t *blkif_alloc(domid_t domid) init_waitqueue_head(&blkif->wq); blkif->st_print =3D jiffies; init_waitqueue_head(&blkif->waiting_to_free); + init_waitqueue_head(&blkif->shutdown_wq); =20 return blkif; } @@ -106,6 +107,7 @@ void blkif_disconnect(blkif_t *blkif) if (blkif->xenblkd) { kthread_stop(blkif->xenblkd); blkif->xenblkd =3D NULL; + wake_up(&blkif->shutdown_wq); } =20 atomic_dec(&blkif->refcnt); --- a/drivers/xen/blktap/blktap.c +++ b/drivers/xen/blktap/blktap.c @@ -659,6 +659,7 @@ static int blktap_release(struct inode * if (info->blkif->xenblkd !=3D NULL) { kthread_stop(info->blkif->xenblkd); info->blkif->xenblkd =3D NULL; + wake_up(&info->blkif->shutdown_wq); } info->status =3D CLEANSHUTDOWN; } @@ -1160,8 +1161,18 @@ int tap_blkif_schedule(void *arg) blkif->waiting_reqs =3D 0; smp_mb(); /* clear flag *before* checking for work */ =20 - if (do_block_io_op(blkif)) + switch (do_block_io_op(blkif)) { + case 1: blkif->waiting_reqs =3D 1; + case 0: + break; + case -EACCES: + wait_event_interruptible(blkif->shutdown_wq, + kthread_should_stop()); + break; + default: + BUG(); + } =20 if (log_stats && time_after(jiffies, blkif->st_print)) print_stats(blkif); @@ -1319,6 +1330,15 @@ static int do_block_io_op(blkif_t *blkif return 0; } =20 + /* N.B. 'rp', not 'rc'. */ + if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rp)) { + printk(KERN_WARNING "blktap:" + " Dom%d provided bogus ring requests (%#x - %#x =3D = %u)." + " Halting ring processing on tap%d\n", + blkif->domid, rp, rc, rp - rc, info->minor); + return -EACCES; + } + while (rc !=3D rp) { =09 if (RING_FULL(&info->ufe_ring)) { --- a/drivers/xen/blktap/common.h +++ b/drivers/xen/blktap/common.h @@ -77,6 +77,7 @@ typedef struct blkif_st { int st_wr_sect; =20 wait_queue_head_t waiting_to_free; + wait_queue_head_t shutdown_wq; =20 int dev_num; uint64_t sectors; --- a/drivers/xen/blktap/interface.c +++ b/drivers/xen/blktap/interface.c @@ -51,6 +51,7 @@ blkif_t *tap_alloc_blkif(domid_t domid) init_waitqueue_head(&blkif->wq); blkif->st_print =3D jiffies; init_waitqueue_head(&blkif->waiting_to_free); + init_waitqueue_head(&blkif->shutdown_wq); =20 return blkif; } --- a/drivers/xen/blktap/xenbus.c +++ b/drivers/xen/blktap/xenbus.c @@ -187,8 +187,11 @@ static int blktap_remove(struct xenbus_d be->backend_watch.node =3D NULL; } if (be->blkif) { - if (be->blkif->xenblkd) + if (be->blkif->xenblkd) { kthread_stop(be->blkif->xenblkd); + be->blkif->xenblkd =3D NULL; + wake_up(&be->blkif->shutdown_wq); + } signal_tapdisk(be->blkif->dev_num); tap_blkif_free(be->blkif, dev); tap_blkif_kmem_cache_free(be->blkif); @@ -340,6 +343,7 @@ static void blkif_disconnect(blkif_t *bl if (blkif->xenblkd) { kthread_stop(blkif->xenblkd); blkif->xenblkd =3D NULL; + wake_up(&blkif->shutdown_wq); } =20 /* idempotent */ --- a/drivers/xen/scsiback/common.h +++ b/drivers/xen/scsiback/common.h @@ -92,6 +92,7 @@ struct vscsibk_info { struct task_struct *kthread; wait_queue_head_t waiting_to_free; wait_queue_head_t wq; + wait_queue_head_t shutdown_wq; unsigned int waiting_reqs; struct page **mmap_pages; =20 --- a/drivers/xen/scsiback/interface.c +++ b/drivers/xen/scsiback/interface.c @@ -55,6 +55,7 @@ struct vscsibk_info *vscsibk_info_alloc( spin_lock_init(&info->ring_lock); atomic_set(&info->nr_unreplied_reqs, 0); init_waitqueue_head(&info->wq); + init_waitqueue_head(&info->shutdown_wq); init_waitqueue_head(&info->waiting_to_free); =20 return info; @@ -102,6 +103,7 @@ void scsiback_disconnect(struct vscsibk_ if (info->kthread) { kthread_stop(info->kthread); info->kthread =3D NULL; + wake_up(&info->shutdown_wq); } =20 wait_event(info->waiting_to_free,=20 --- a/drivers/xen/scsiback/scsiback.c +++ b/drivers/xen/scsiback/scsiback.c @@ -589,6 +589,15 @@ static int scsiback_do_cmd_fn(struct vsc rp =3D ring->sring->req_prod; rmb(); =20 + /* N.B. 'rp', not 'rc'. */ + if (RING_REQUEST_CONS_OVERFLOW(ring, rp)) { + printk(KERN_WARNING "scsiback:" + " Dom%d provided bogus ring requests (%#x - %#x =3D = %u)." + " Halting ring processing\n", + info->domid, rp, rc, rp - rc); + return -EACCES; + } + while ((rc !=3D rp)) { if (RING_REQUEST_CONS_OVERFLOW(ring, rc)) break; @@ -669,8 +678,18 @@ int scsiback_schedule(void *data) info->waiting_reqs =3D 0; smp_mb(); =20 - if (scsiback_do_cmd_fn(info)) + switch (scsiback_do_cmd_fn(info)) { + case 1: info->waiting_reqs =3D 1; + case 0: + break; + case -EACCES: + wait_event_interruptible(info->shutdown_wq, + kthread_should_stop()); + break; + default: + BUG(); + } } =20 return 0; --- a/drivers/xen/usbback/interface.c +++ b/drivers/xen/usbback/interface.c @@ -89,6 +89,7 @@ usbif_t *usbif_alloc(domid_t domid, unsi atomic_set(&usbif->refcnt, 0); init_waitqueue_head(&usbif->wq); init_waitqueue_head(&usbif->waiting_to_free); + init_waitqueue_head(&usbif->shutdown_wq); spin_lock_init(&usbif->stub_lock); INIT_LIST_HEAD(&usbif->stub_list); spin_lock_init(&usbif->addr_lock); @@ -155,6 +156,7 @@ void usbif_disconnect(usbif_t *usbif) if (usbif->xenusbd) { kthread_stop(usbif->xenusbd); usbif->xenusbd =3D NULL; + wake_up(&usbif->shutdown_wq); } =20 spin_lock_irqsave(&usbif->stub_lock, flags); --- a/drivers/xen/usbback/usbback.c +++ b/drivers/xen/usbback/usbback.c @@ -979,6 +979,15 @@ static int usbbk_start_submit_urb(usbif_ rp =3D urb_ring->sring->req_prod; rmb(); =20 + /* N.B. 'rp', not 'rc'. */ + if (RING_REQUEST_CONS_OVERFLOW(urb_ring, rp)) { + printk(KERN_WARNING "usbback:" + " Dom%d provided bogus ring requests (%#x - %#x =3D = %u)." + " Halting ring processing on dev=3D%#x\n", + usbif->domid, rp, rc, rp - rc, usbif->handle); + return -EACCES; + } + while (rc !=3D rp) { if (RING_REQUEST_CONS_OVERFLOW(urb_ring, rc)) { if(printk_ratelimit()) @@ -1052,8 +1061,18 @@ int usbbk_schedule(void *arg) usbif->waiting_reqs =3D 0; smp_mb(); =20 - if (usbbk_start_submit_urb(usbif)) + switch (usbbk_start_submit_urb(usbif)) { + case 1: usbif->waiting_reqs =3D 1; + case 0: + break; + case -EACCES: + wait_event_interruptible(usbif->shutdown_wq, + kthread_should_stop()); + break; + default: + BUG(); + } } =20 usbif->xenusbd =3D NULL; --- a/drivers/xen/usbback/usbback.h +++ b/drivers/xen/usbback/usbback.h @@ -99,6 +99,7 @@ typedef struct usbif_st { unsigned int waiting_reqs; wait_queue_head_t waiting_to_free; wait_queue_head_t wq; + wait_queue_head_t shutdown_wq; } usbif_t; =20 struct vusb_port_id { --=__Part1323FE0F.0__= Content-Type: text/plain; name="xen-backends-reject-ring-overruns.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-backends-reject-ring-overruns.patch" backends: Check for insane amounts of requests on the ring=0A=0ACheck that = the ring does not have an insane amount of requests=0A(more than there = could fit on the ring).=0A=0AIf we detect this case we will stop processing= the requests=0Aand wait until the XenBus disconnects the ring.=0A=0AThe = existing check RING_REQUEST_CONS_OVERFLOW which checks for how=0Amany = responses we have created in the past (rsp_prod_pvt) vs=0Arequests = consumed (req_cons) and whether said difference is greater or=0Aequal to = the size of the ring, does not catch this case.=0A=0AWha the condition = does check if there is a need to process more=0Aas we still have a backlog = of responses to finish. Note that both=0Aof those values (rsp_prod_pvt and = req_cons) are not exposed on the=0Ashared ring.=0A=0ATo understand this = problem a mini crash course in ring protocol=0Aresponse/request updates is = in place.=0A=0AThere are four entries: req_prod and rsp_prod; req_event = and rsp_event=0Ato track the ring entries. We are only concerned about the = first two -=0Awhich set the tone of this bug.=0A=0AThe req_prod is a value = incremented by frontend for each request put=0Aon the ring. Conversely the = rsp_prod is a value incremented by the backend=0Afor each response put on = the ring (rsp_prod gets set by rsp_prod_pvt when=0Apushing the responses = on the ring). Both values can=0Awrap and are modulo the size of the ring = (in block case that is 32).=0APlease see RING_GET_REQUEST and RING_GET_RESP= ONSE for the more details.=0A=0AThe culprit here is that if the difference = between the=0Areq_prod and req_cons is greater than the ring size we have = a problem.=0AFortunately for us, the '__do_block_io_op' loop:=0A=0A rc = =3D blk_rings->common.req_cons;=0A rp =3D blk_rings->common.sring->req= _prod;=0A=0A while (rc !=3D rp) {=0A=0A ..=0A = blk_rings->common.req_cons =3D ++rc; /* before make_response() */=0A=0A = }=0A=0Awill loop up to the point when rc =3D=3D rp. The macros inside of = the=0Aloop (RING_GET_REQUEST) is smart and is indexing based on the = modulo=0Aof the ring size. If the frontend has provided a bogus req_prod = value=0Awe will loop until the 'rc =3D=3D rp' - which means we could be = processing=0Aalready processed requests (or responses) often.=0A=0AThe = reason the RING_REQUEST_CONS_OVERFLOW is not helping here is=0Ab/c it only = tracks how many responses we have internally produced=0Aand whether we = would should process more. The astute reader will=0Anotice that the macro = RING_REQUEST_CONS_OVERFLOW provides two=0Aarguments - more on this = later.=0A=0AFor example, if we were to enter this function with these = values:=0A=0A blk_rings->common.sring->req_prod =3D X+31415 (X = is the value from=0A the last time __do_block_io_op was = called).=0A blk_rings->common.req_cons =3D X=0A blk_rings->co= mmon.rsp_prod_pvt =3D X=0A=0AThe RING_REQUEST_CONS_OVERFLOW(&blk_rings->com= mon, blk_rings->common.req_cons)=0Ais doing:=0A=0A req_cons - = sring->rsp_prod_pvt >=3D 32=0A=0AWhich is,=0A X - X >=3D 32 or 0 >=3D = 32=0A=0AAnd that is false, so we continue on looping (this bug).=0A=0AIf = we re-use said macro RING_REQUEST_CONS_OVERFLOW and pass in the rp=0Ainstea= d (sring->req_prod) of rc, the this macro can do the check:=0A=0A = req_prod - sring->rsp_prov_pvt >=3D 32=0A=0AWhich is,=0A X + 31415 - = X >=3D 32 , or 31415 >=3D 32=0A=0Awhich is true, so we can error out and = break out of the function.=0A=0ASigned-off-by: Konrad Rzeszutek Wilk = =0A=0AExtend the blkback-only upstream patch to = other affected backends.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/drivers/xen/blkback/blkback.c=0A+++ b/drivers/xen/blkback/blkb= ack.c=0A@@ -229,8 +229,18 @@ int blkif_schedule(void *arg)=0A = blkif->waiting_reqs =3D 0;=0A smp_mb(); /* clear flag *before* = checking for work */=0A =0A- if (do_block_io_op(blkif))=0A+ = switch (do_block_io_op(blkif)) {=0A+ case 1:=0A = blkif->waiting_reqs =3D 1;=0A+ case 0:=0A+ = break;=0A+ case -EACCES:=0A+ wait_event_= interruptible(blkif->shutdown_wq,=0A+ = kthread_should_stop());=0A+ break;=0A+ = default:=0A+ BUG();=0A+ }=0A = unplug_queue(blkif);=0A =0A if (log_stats && time_after(jiffies= , blkif->st_print))=0A@@ -320,6 +330,15 @@ static int do_block_io_op(blkif_= t *blkif=0A rp =3D blk_rings->common.sring->req_prod;=0A rmb(); /* = Ensure we see queued requests up to 'rp'. */=0A =0A+ /* N.B. 'rp', not = 'rc'. */=0A+ if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rp)) = {=0A+ printk(KERN_WARNING "blkback:"=0A+ " = Dom%d provided bogus ring requests (%#x - %#x =3D %u)."=0A+ = " Halting ring processing on dev=3D%04x\n",=0A+ = blkif->domid, rp, rc, rp - rc, blkif->vbd.pdevice);=0A+ return = -EACCES;=0A+ }=0A+=0A while (rc !=3D rp) {=0A if = (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rc))=0A = break;=0A--- a/drivers/xen/blkback/common.h=0A+++ b/drivers/xen/blkback/com= mon.h=0A@@ -89,6 +89,7 @@ typedef struct blkif_st {=0A int = st_wr_sect;=0A =0A wait_queue_head_t waiting_to_free;=0A+ wait_queue_= head_t shutdown_wq;=0A } blkif_t;=0A =0A struct backend_info=0A--- = a/drivers/xen/blkback/interface.c=0A+++ b/drivers/xen/blkback/interface.c= =0A@@ -51,6 +51,7 @@ blkif_t *blkif_alloc(domid_t domid)=0A init_waitqu= eue_head(&blkif->wq);=0A blkif->st_print =3D jiffies;=0A = init_waitqueue_head(&blkif->waiting_to_free);=0A+ init_waitqueue_head= (&blkif->shutdown_wq);=0A =0A return blkif;=0A }=0A@@ -106,6 +107,7 @@ = void blkif_disconnect(blkif_t *blkif)=0A if (blkif->xenblkd) {=0A = kthread_stop(blkif->xenblkd);=0A blkif->xenblkd =3D = NULL;=0A+ wake_up(&blkif->shutdown_wq);=0A }=0A =0A = atomic_dec(&blkif->refcnt);=0A--- a/drivers/xen/blktap/blktap.c=0A+++ = b/drivers/xen/blktap/blktap.c=0A@@ -659,6 +659,7 @@ static int blktap_relea= se(struct inode *=0A if (info->blkif->xenblkd !=3D NULL) {=0A = kthread_stop(info->blkif->xenblkd);=0A = info->blkif->xenblkd =3D NULL;=0A+ wake_up(&info->blki= f->shutdown_wq);=0A }=0A info->status =3D CLEANSHUTD= OWN;=0A }=0A@@ -1160,8 +1161,18 @@ int tap_blkif_schedule(void = *arg)=0A blkif->waiting_reqs =3D 0;=0A smp_mb(); = /* clear flag *before* checking for work */=0A =0A- if = (do_block_io_op(blkif))=0A+ switch (do_block_io_op(blkif)) = {=0A+ case 1:=0A blkif->waiting_reqs =3D = 1;=0A+ case 0:=0A+ break;=0A+ = case -EACCES:=0A+ wait_event_interruptible(blkif->shu= tdown_wq,=0A+ kthread_should_sto= p());=0A+ break;=0A+ default:=0A+ = BUG();=0A+ }=0A =0A if (log_stats && = time_after(jiffies, blkif->st_print))=0A print_stats= (blkif);=0A@@ -1319,6 +1330,15 @@ static int do_block_io_op(blkif_t = *blkif=0A return 0;=0A }=0A =0A+ /* N.B. 'rp', not = 'rc'. */=0A+ if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rp)) = {=0A+ printk(KERN_WARNING "blktap:"=0A+ " = Dom%d provided bogus ring requests (%#x - %#x =3D %u)."=0A+ = " Halting ring processing on tap%d\n",=0A+ blkif->domid= , rp, rc, rp - rc, info->minor);=0A+ return -EACCES;=0A+ = }=0A+=0A while (rc !=3D rp) {=0A =0A if = (RING_FULL(&info->ufe_ring)) {=0A--- a/drivers/xen/blktap/common.h=0A+++ = b/drivers/xen/blktap/common.h=0A@@ -77,6 +77,7 @@ typedef struct blkif_st = {=0A int st_wr_sect;=0A =0A wait_queue_head_t = waiting_to_free;=0A+ wait_queue_head_t shutdown_wq;=0A =0A int = dev_num;=0A uint64_t sectors;=0A--- a/drivers/xen/blktap/interfa= ce.c=0A+++ b/drivers/xen/blktap/interface.c=0A@@ -51,6 +51,7 @@ blkif_t = *tap_alloc_blkif(domid_t domid)=0A init_waitqueue_head(&blkif->wq);=0A= blkif->st_print =3D jiffies;=0A init_waitqueue_head(&blkif-= >waiting_to_free);=0A+ init_waitqueue_head(&blkif->shutdown_wq);=0A =0A = return blkif;=0A }=0A--- a/drivers/xen/blktap/xenbus.c=0A+++ b/drivers/xen/= blktap/xenbus.c=0A@@ -187,8 +187,11 @@ static int blktap_remove(struct = xenbus_d=0A be->backend_watch.node =3D NULL;=0A }=0A if = (be->blkif) {=0A- if (be->blkif->xenblkd)=0A+ if = (be->blkif->xenblkd) {=0A kthread_stop(be->blkif->xen= blkd);=0A+ be->blkif->xenblkd =3D NULL;=0A+ = wake_up(&be->blkif->shutdown_wq);=0A+ }=0A = signal_tapdisk(be->blkif->dev_num);=0A tap_blkif_free(be->blkif, = dev);=0A tap_blkif_kmem_cache_free(be->blkif);=0A@@ -340,6 = +343,7 @@ static void blkif_disconnect(blkif_t *bl=0A if (blkif->xenblkd)= {=0A kthread_stop(blkif->xenblkd);=0A blkif->xenb= lkd =3D NULL;=0A+ wake_up(&blkif->shutdown_wq);=0A = }=0A =0A /* idempotent */=0A--- a/drivers/xen/scsiback/common.h=0A++= + b/drivers/xen/scsiback/common.h=0A@@ -92,6 +92,7 @@ struct vscsibk_info = {=0A struct task_struct *kthread;=0A wait_queue_head_t = waiting_to_free;=0A wait_queue_head_t wq;=0A+ wait_queue_head_t = shutdown_wq;=0A unsigned int waiting_reqs;=0A struct page = **mmap_pages;=0A =0A--- a/drivers/xen/scsiback/interface.c=0A+++ b/drivers/= xen/scsiback/interface.c=0A@@ -55,6 +55,7 @@ struct vscsibk_info *vscsibk_i= nfo_alloc(=0A spin_lock_init(&info->ring_lock);=0A atomic_set(&info->n= r_unreplied_reqs, 0);=0A init_waitqueue_head(&info->wq);=0A+ = init_waitqueue_head(&info->shutdown_wq);=0A init_waitqueue_head(&info->= waiting_to_free);=0A =0A return info;=0A@@ -102,6 +103,7 @@ void = scsiback_disconnect(struct vscsibk_=0A if (info->kthread) {=0A = kthread_stop(info->kthread);=0A info->kthread =3D = NULL;=0A+ wake_up(&info->shutdown_wq);=0A }=0A =0A = wait_event(info->waiting_to_free, =0A--- a/drivers/xen/scsiback/scsiback.c= =0A+++ b/drivers/xen/scsiback/scsiback.c=0A@@ -589,6 +589,15 @@ static int = scsiback_do_cmd_fn(struct vsc=0A rp =3D ring->sring->req_prod;=0A = rmb();=0A =0A+ /* N.B. 'rp', not 'rc'. */=0A+ if (RING_REQUEST_CONS_OVERF= LOW(ring, rp)) {=0A+ printk(KERN_WARNING "scsiback:"=0A+ = " Dom%d provided bogus ring requests (%#x - %#x =3D %u)."=0A+ = " Halting ring processing\n",=0A+ info->domid,= rp, rc, rp - rc);=0A+ return -EACCES;=0A+ }=0A+=0A = while ((rc !=3D rp)) {=0A if (RING_REQUEST_CONS_OVERFLOW(ring= , rc))=0A break;=0A@@ -669,8 +678,18 @@ int = scsiback_schedule(void *data)=0A info->waiting_reqs =3D = 0;=0A smp_mb();=0A =0A- if (scsiback_do_cmd_fn(info= ))=0A+ switch (scsiback_do_cmd_fn(info)) {=0A+ case 1:=0A = info->waiting_reqs =3D 1;=0A+ case = 0:=0A+ break;=0A+ case -EACCES:=0A+ = wait_event_interruptible(info->shutdown_wq,=0A+ = kthread_should_stop());=0A+ break;=0A+ = default:=0A+ BUG();=0A+ }=0A = }=0A =0A return 0;=0A--- a/drivers/xen/usbback/interface.c=0A+++ = b/drivers/xen/usbback/interface.c=0A@@ -89,6 +89,7 @@ usbif_t *usbif_alloc(= domid_t domid, unsi=0A atomic_set(&usbif->refcnt, 0);=0A init_waitqu= eue_head(&usbif->wq);=0A init_waitqueue_head(&usbif->waiting_to_free= );=0A+ init_waitqueue_head(&usbif->shutdown_wq);=0A spin_lock_init(&usb= if->stub_lock);=0A INIT_LIST_HEAD(&usbif->stub_list);=0A spin_lock_i= nit(&usbif->addr_lock);=0A@@ -155,6 +156,7 @@ void usbif_disconnect(usbif_t= *usbif)=0A if (usbif->xenusbd) {=0A kthread_stop(usbif-= >xenusbd);=0A usbif->xenusbd =3D NULL;=0A+ wake_up(&us= bif->shutdown_wq);=0A }=0A =0A spin_lock_irqsave(&usbif->stub_lock= , flags);=0A--- a/drivers/xen/usbback/usbback.c=0A+++ b/drivers/xen/usbback= /usbback.c=0A@@ -979,6 +979,15 @@ static int usbbk_start_submit_urb(usbif_= =0A rp =3D urb_ring->sring->req_prod;=0A rmb();=0A =0A+ /* N.B. = 'rp', not 'rc'. */=0A+ if (RING_REQUEST_CONS_OVERFLOW(urb_ring, rp)) = {=0A+ printk(KERN_WARNING "usbback:"=0A+ " = Dom%d provided bogus ring requests (%#x - %#x =3D %u)."=0A+ = " Halting ring processing on dev=3D%#x\n",=0A+ = usbif->domid, rp, rc, rp - rc, usbif->handle);=0A+ return = -EACCES;=0A+ }=0A+=0A while (rc !=3D rp) {=0A if = (RING_REQUEST_CONS_OVERFLOW(urb_ring, rc)) {=0A = if(printk_ratelimit())=0A@@ -1052,8 +1061,18 @@ int usbbk_schedule(void = *arg)=0A usbif->waiting_reqs =3D 0;=0A = smp_mb();=0A =0A- if (usbbk_start_submit_urb(usbif))=0A+ = switch (usbbk_start_submit_urb(usbif)) {=0A+ case 1:=0A = usbif->waiting_reqs =3D 1;=0A+ case 0:=0A+ = break;=0A+ case -EACCES:=0A+ wait_event_= interruptible(usbif->shutdown_wq,=0A+ = kthread_should_stop());=0A+ break;=0A+ = default:=0A+ BUG();=0A+ }=0A }=0A =0A = usbif->xenusbd =3D NULL;=0A--- a/drivers/xen/usbback/usbback.h=0A+++ = b/drivers/xen/usbback/usbback.h=0A@@ -99,6 +99,7 @@ typedef struct = usbif_st {=0A unsigned int waiting_reqs;=0A wait_queue_head_t = waiting_to_free;=0A wait_queue_head_t wq;=0A+ wait_queue_head_t = shutdown_wq;=0A } usbif_t;=0A =0A struct vusb_port_id {=0A --=__Part1323FE0F.0__= 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.xen.org http://lists.xen.org/xen-devel --=__Part1323FE0F.0__=--