trace: improve check_tbuf_size()
PATCH 3/6 trace: improve check_tbuf_size()
It didn't consider the case of the incoming size not allowing for the 2*data_size range for t_buf->{prod,cons}
xen/common/trace.c +8 -3
@@ -77,11 +77,16 @@ static u32 tb_event_mask = TRC_ALL;/** * 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 )); +u32 size = 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 )); }/**
It didn't consider the case of the incoming size not allowing for the 2*data_size range for t_buf->{prod,cons}
xen/common/trace.c +8 -3
@@ -77,11 +77,16 @@ static u32 tb_event_mask = TRC_ALL;/** * 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 )); +u32 size = 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 )); }/**
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
As long as we're being anal, we should be sure to use the actual types from prod and cons to do the check. Patch attached.
-George
Quoted 21 lines · Jan Beulich
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 <[email protected]>xen/common/trace.c 2010-06-28 11:58:37.000000000 +0200 renamed from xen/common/trace.c 2010-06-28 11:58:37.000000000 +0200 +3
-2@@ -77,11 +77,16 @@ static u32 tb_event_mask = TRC_ALL; /** * 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)
xen/common/trace.c 2010-06-28 11:58:37.000000000 +0200 static u32 tb_event_mask = TRC_ALL; · line 92
Quoted 10 lines
xen/common/trace.c 2010-06-28 11:58:37.000000000 +0200 renamed from xen/common/trace.c 2010-06-28 11:58:37.000000000 +0200 +5
-1{ - return (num_online_cpus() * size + T_INFO_FIRST_OFFSET) > (T_INFO_SIZE / sizeof(uint32_t)); + u32 size = 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)); } /**
trace: improve check_tbuf_size()
It didn't consider the case of the incoming size not allowing for the 2*data_size range for t_buf->{prod,cons}
xen/common/trace.c +11 -3
@@ -80,11 +80,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 )); }/**
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · George Dunlap
As long as we're being anal, we should be sure to use the actual types from prod and cons to do the check. Patch attached.
Okay - I didn't want to go that far, but it's fine by me.
Jan