From patchwork Wed Jan 6 12:08:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 563920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B4C221402EC for ; Wed, 6 Jan 2016 23:09:11 +1100 (AEDT) Received: from localhost ([::1]:53858 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGmtp-0001p4-Jj for incoming@patchwork.ozlabs.org; Wed, 06 Jan 2016 07:09:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGmtc-0001XY-0K for qemu-devel@nongnu.org; Wed, 06 Jan 2016 07:08:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGmtY-00018J-QS for qemu-devel@nongnu.org; Wed, 06 Jan 2016 07:08:55 -0500 Received: from smtp02.citrix.com ([66.165.176.63]:39336) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGmtY-00018E-Lj for qemu-devel@nongnu.org; Wed, 06 Jan 2016 07:08:52 -0500 X-IronPort-AV: E=Sophos;i="5.20,528,1444694400"; d="scan'208";a="329313970" Date: Wed, 6 Jan 2016 12:08:28 +0000 From: Stefano Stabellini X-X-Sender: sstabellini@kaball.uk.xensource.com To: Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-DLP: MIA1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: liuling-it@360.cn, xen-devel@lists.xensource.com, Stefano Stabellini Subject: [Qemu-devel] [PATCH] xenfb.c: avoid expensive loops when prod <= out_cons X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If the frontend sets out_cons to a value higher than out_prod, it will cause xenfb_handle_events to loop about 2^32 times. Avoid that by using better checks at the beginning of the function. Signed-off-by: Stefano Stabellini diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 4e2a27a..f963cf2 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -789,10 +789,11 @@ static void xenfb_handle_events(struct XenFB *xenfb) prod = page->out_prod; out_cons = page->out_cons; - if (prod == out_cons) - return; + if (prod <= out_cons) { + return; + } xen_rmb(); /* ensure we see ring contents up to prod */ - for (cons = out_cons; cons != prod; cons++) { + for (cons = out_cons; cons < prod; cons++) { union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons); uint8_t type = event->type; int x, y, w, h;