From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/scsiback/usbback: move cond_resched() invocations to proper place Date: Tue, 05 Feb 2013 14:10:25 +0000 Message-ID: <511120E102000078000BC1AC@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartFBCBB6C1.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 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. --=__PartFBCBB6C1.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The call to cond_resched() must be inside the loop, in order to not expose the host to guest induced soft lockups (due to a close to unbounded loop). Also rate limit printk()-s in those loops as well as in blktap's. Signed-off-by: Jan Beulich --- a/drivers/xen/blktap/common.h +++ b/drivers/xen/blktap/common.h @@ -41,7 +41,9 @@ #define DPRINTK(_f, _a...) pr_debug("(file=3D%s, line=3D%d) " _f, \ __FILE__ , __LINE__ , ## _a ) =20 -#define WPRINTK(fmt, args...) printk(KERN_WARNING "blk_tap: " fmt, = ##args) +#define WPRINTK(fmt, args...) \ + ((void)(printk_ratelimit() && \ + printk(KERN_WARNING "blktap: " fmt, ##args))) =20 struct backend_info; =20 --- a/drivers/xen/scsiback/scsiback.c +++ b/drivers/xen/scsiback/scsiback.c @@ -603,40 +603,36 @@ static int _scsiback_do_cmd_fn(struct vs =20 err =3D prepare_pending_reqs(info, ring_req, pending_req); - if (err =3D=3D -EINVAL) { - scsiback_do_resp_with_sense(NULL, (DRIVER_ERROR << = 24), - 0, pending_req); - continue; - } else if (err =3D=3D -ENODEV) { - scsiback_do_resp_with_sense(NULL, (DID_NO_CONNECT = << 16), - 0, pending_req); - continue; - } - - if (pending_req->act =3D=3D VSCSIIF_ACT_SCSI_CDB) { - + switch (err ?: pending_req->act) { + case VSCSIIF_ACT_SCSI_CDB: /* The Host mode is through as for Emulation. */ if (info->feature =3D=3D VSCSI_TYPE_HOST) scsiback_cmd_exec(pending_req); else scsiback_req_emulation_or_cmdexec(pending_r= eq); - - } else if (pending_req->act =3D=3D VSCSIIF_ACT_SCSI_RESET) = { + break; + case VSCSIIF_ACT_SCSI_RESET: scsiback_device_reset_exec(pending_req); - } else { - printk(KERN_ERR "scsiback: invalid parameter for = request\n"); - scsiback_do_resp_with_sense(NULL, (DRIVER_ERROR << = 24), - 0, pending_req); - continue; + break; + default: + if(!err && printk_ratelimit()) + printk(KERN_ERR "scsiback: invalid = request\n"); + scsiback_do_resp_with_sense(NULL, DRIVER_ERROR << = 24, + 0, pending_req); + break; + case -ENODEV: + scsiback_do_resp_with_sense(NULL, DID_NO_CONNECT = << 16, + 0, pending_req); + break; } + + /* Yield point for this unbounded loop. */ + cond_resched(); } =20 if (RING_HAS_UNCONSUMED_REQUESTS(ring)) more_to_do =3D 1; =20 - /* Yield point for this unbounded loop. */ - cond_resched(); - return more_to_do; } =20 --- a/drivers/xen/usbback/usbback.c +++ b/drivers/xen/usbback/usbback.c @@ -981,7 +981,9 @@ static int usbbk_start_submit_urb(usbif_ =20 while (rc !=3D rp) { if (RING_REQUEST_CONS_OVERFLOW(urb_ring, rc)) { - printk(KERN_WARNING "RING_REQUEST_CONS_OVERFLOW\n")= ; + if(printk_ratelimit()) + printk(KERN_WARNING "usbback: " + "RING_REQUEST_CONS_OVERFLOW\n"); break; } =20 @@ -996,12 +998,12 @@ static int usbbk_start_submit_urb(usbif_ =20 dispatch_request_to_pending_reqs(usbif, req, pending_req); + + cond_resched(); } =20 RING_FINAL_CHECK_FOR_REQUESTS(&usbif->urb_ring, more_to_do); =20 - cond_resched(); - return more_to_do; } =20 --=__PartFBCBB6C1.0__= Content-Type: text/plain; name="xen-backends-cond-resched.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-backends-cond-resched.patch" scsiback/usbback: move cond_resched() invocations to proper place=0A=0AThe = call to cond_resched() must be inside the loop, in order to not=0Aexpose = the host to guest induced soft lockups (due to a close to=0Aunbounded = loop).=0A=0AAlso rate limit printk()-s in those loops as well as in = blktap's.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/drivers/xen/blktap/common.h=0A+++ b/drivers/xen/blktap/common.h=0A@@ = -41,7 +41,9 @@=0A #define DPRINTK(_f, _a...) pr_debug("(file=3D%s, = line=3D%d) " _f, \=0A __FILE__ , = __LINE__ , ## _a )=0A =0A-#define WPRINTK(fmt, args...) printk(KERN_WARNING= "blk_tap: " fmt, ##args)=0A+#define WPRINTK(fmt, args...) \=0A+ = ((void)(printk_ratelimit() && \=0A+ printk(KERN_WARNING = "blktap: " fmt, ##args)))=0A =0A struct backend_info;=0A =0A--- a/drivers/x= en/scsiback/scsiback.c=0A+++ b/drivers/xen/scsiback/scsiback.c=0A@@ = -603,40 +603,36 @@ static int _scsiback_do_cmd_fn(struct vs=0A =0A = err =3D prepare_pending_reqs(info, ring_req,=0A = pending_req);=0A- if (err =3D=3D -EINVAL) = {=0A- scsiback_do_resp_with_sense(NULL, (DRIVER_ERROR << = 24),=0A- 0, pending_req);=0A- = continue;=0A- } else if (err =3D=3D -ENODEV) {=0A- = scsiback_do_resp_with_sense(NULL, (DID_NO_CONNECT << 16),=0A- = 0, pending_req);=0A- continue;=0A- = }=0A-=0A- if (pending_req->act =3D=3D VSCSIIF_ACT_SCSI_CDB) = {=0A-=0A+ switch (err ?: pending_req->act) {=0A+ = case VSCSIIF_ACT_SCSI_CDB:=0A /* The Host mode is = through as for Emulation. */=0A if (info->feature = =3D=3D VSCSI_TYPE_HOST)=0A scsiback_cmd_exec(p= ending_req);=0A else=0A = scsiback_req_emulation_or_cmdexec(pending_req);=0A-=0A- } else if = (pending_req->act =3D=3D VSCSIIF_ACT_SCSI_RESET) {=0A+ = break;=0A+ case VSCSIIF_ACT_SCSI_RESET:=0A = scsiback_device_reset_exec(pending_req);=0A- } else {=0A- = printk(KERN_ERR "scsiback: invalid parameter for request\n");=0A- = scsiback_do_resp_with_sense(NULL, (DRIVER_ERROR << = 24),=0A- 0, pending_req);=0A- = continue;=0A+ break;=0A+ default:=0A+ = if(!err && printk_ratelimit())=0A+ = printk(KERN_ERR "scsiback: invalid request\n");=0A+ = scsiback_do_resp_with_sense(NULL, DRIVER_ERROR << 24,=0A+ = 0, pending_req);=0A+ = break;=0A+ case -ENODEV:=0A+ scsiback_do= _resp_with_sense(NULL, DID_NO_CONNECT << 16,=0A+ = 0, pending_req);=0A+ break;=0A = }=0A+=0A+ /* Yield point for this unbounded loop. = */=0A+ cond_resched();=0A }=0A =0A if (RING_HAS_UNCONS= UMED_REQUESTS(ring))=0A more_to_do =3D 1;=0A =0A- /* = Yield point for this unbounded loop. */=0A- cond_resched();=0A-=0A = return more_to_do;=0A }=0A =0A--- a/drivers/xen/usbback/usbback.c=0A+++ = b/drivers/xen/usbback/usbback.c=0A@@ -981,7 +981,9 @@ static int usbbk_star= t_submit_urb(usbif_=0A =0A while (rc !=3D rp) {=0A if = (RING_REQUEST_CONS_OVERFLOW(urb_ring, rc)) {=0A- = printk(KERN_WARNING "RING_REQUEST_CONS_OVERFLOW\n");=0A+ = if(printk_ratelimit())=0A+ printk(KERN_WARNING= "usbback: "=0A+ "RING_REQUEST_CONS_O= VERFLOW\n");=0A break;=0A }=0A =0A@@ = -996,12 +998,12 @@ static int usbbk_start_submit_urb(usbif_=0A =0A = dispatch_request_to_pending_reqs(usbif, req,=0A = pending_req);=0A+=0A+ cond_resched();=0A = }=0A =0A RING_FINAL_CHECK_FOR_REQUESTS(&usbif->urb_ring, = more_to_do);=0A =0A- cond_resched();=0A-=0A return more_to_do;=0A }=0A = =0A --=__PartFBCBB6C1.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 --=__PartFBCBB6C1.0__=--