From: David Vrabel Subject: Re: [Xen-devel] [PATCH] xenfb.c: avoid expensive loops when prod <= out_cons Date: Wed, 6 Jan 2016 12:22:50 +0000 Message-ID: <568D071A.7050009@citrix.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org Sender: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org To: Stefano Stabellini , qemu-devel@nongnu.org Cc: xen-devel@lists.xensource.com, liuling-it@360.cn List-Id: xen-devel@lists.xenproject.org On 06/01/16 12:08, Stefano Stabellini wrote: > 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. You can't use less than to compare prod and cons because they wrap. You need to compare (prod - cons) against ring size (or similar) to check for overflow. See RING_REQUEST_PROD_OVERFLOW() etc. David