From: George Dunlap Subject: [PATCH 2 of 4] trace: improve check_tbuf_size() Date: Thu, 1 Jul 2010 10:12:30 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: george.dunlap@eu.citrix.com List-Id: xen-devel@lists.xenproject.org It didn't consider the case of the incoming size not allowing for the 2*data_size range for t_buf->{prod,cons} Signed-off-by: Jan Beulich Signed-off-by: George Dunlap diff -r cdffdb3b34b1 -r aef5229e5b96 xen/common/trace.c --- a/xen/common/trace.c Thu Jul 01 11:00:58 2010 +0100 +++ b/xen/common/trace.c Thu Jul 01 11:09:40 2010 +0100 @@ -92,11 +92,19 @@ /** * check_tbuf_size - check to make sure that the proposed size will fit - * in the currently sized struct t_info. + * in the currently sized struct t_info and allows prod and cons to + * reach double the value without overflow. */ -static inline int check_tbuf_size(int size) +static int check_tbuf_size(u32 pages) { - return (num_online_cpus() * size + t_info_first_offset) > (T_INFO_SIZE / sizeof(uint32_t)); + struct t_buf dummy; + typeof(dummy.prod) size; + + size = ((typeof(dummy.prod))pages) * PAGE_SIZE; + + return (size / PAGE_SIZE != pages) + || (size + size < size) + || (num_online_cpus() * pages + t_info_first_offset > T_INFO_SIZE / sizeof(uint32_t)); } /**