From patchwork Wed Jan 6 16:32:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 563984 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 74EDA14029E for ; Thu, 7 Jan 2016 03:33:08 +1100 (AEDT) Received: from localhost ([::1]:55061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGr1G-0002zX-FH for incoming@patchwork.ozlabs.org; Wed, 06 Jan 2016 11:33:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGr11-0002gQ-0Y for qemu-devel@nongnu.org; Wed, 06 Jan 2016 11:32:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGr0x-0002LQ-0p for qemu-devel@nongnu.org; Wed, 06 Jan 2016 11:32:50 -0500 Received: from smtp02.citrix.com ([66.165.176.63]:11736) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGr0w-0002LH-T8 for qemu-devel@nongnu.org; Wed, 06 Jan 2016 11:32:46 -0500 X-IronPort-AV: E=Sophos;i="5.20,529,1444694400"; d="scan'208";a="329376995" Date: Wed, 6 Jan 2016 16:32:22 +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: MIA2 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 v2] 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 Reported-by: Ling Liu diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 4e2a27a..594baff 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -789,8 +789,9 @@ 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 >= XENFB_OUT_RING_LEL) { + return; + } xen_rmb(); /* ensure we see ring contents up to prod */ for (cons = out_cons; cons != prod; cons++) { union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons);