Skip to contentSkip to conversation

xentrace: fix off-by-one in calculate_tbuf_size

PATCH In review Olaf Hering 3 participants 4 messages Mar 1, 2013 – Mar 4, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xentrace: fix off-by-one in calculate_tbuf_size

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1362151425 -3600
# Node ID 13c43170cd5f653d9590916df82f60597d1d5326 # Parent 3eb62c576a1a315b9f8655a186ead470abe69b31
xentrace: fix off-by-one in calculate_tbuf_size

Commit "xentrace: reduce trace buffer size to something mfn_offset can reach" contains an off-by-one bug. max_mfn_offset needs to be reduced by exactly the value of t_info_first_offset.

If the system has two cpus and the number of requested trace pages is very large, the final number of trace pages + the offset will not fit into a short. As a result the variable offset in alloc_trace_bufs() will wrap while allocating buffers for the second cpu. Later share_xen_page_with_privileged_guests() will be called with a wrong page and the ASSERT in this function triggers. If the ASSERT is ignored by running a non-dbg hypervisor the asserts in xentrace itself trigger because "cons" is not aligned because the very last trace page for the second cpu is a random mfn.

Thanks to Jan for the quick analysis.

xen/common/trace.c +1 -1
diff -r 3eb62c576a1a -r 13c43170cd5f xen/common/trace.c
@@ -133,7 +133,7 @@ static int calculate_tbuf_size(unsigned 
      * The array of mfns for the highest cpu can start at the maximum value
      * mfn_offset can hold. So reduce the number of cpus and also the mfn_offset.
      */
-    max_mfn_offset -= t_info_first_offset - 1;
+    max_mfn_offset -= t_info_first_offset;
     max_cpus--;
     if ( max_cpus )
         max_mfn_offset /= max_cpus;
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Olaf Hering

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1362151425 -3600
# Node ID 13c43170cd5f653d9590916df82f60597d1d5326 # Parent 3eb62c576a1a315b9f8655a186ead470abe69b31
xentrace: fix off-by-one in calculate_tbuf_size

Commit "xentrace: reduce trace buffer size to something mfn_offset can reach" contains an off-by-one bug. max_mfn_offset needs to be reduced by exactly the value of t_info_first_offset.

If the system has two cpus and the number of requested trace pages is very large, the final number of trace pages + the offset will not fit into a short. As a result the variable offset in alloc_trace_bufs() will wrap while allocating buffers for the second cpu. Later share_xen_page_with_privileged_guests() will be called with a wrong page and the ASSERT in this function triggers. If the ASSERT is ignored by running a non-dbg hypervisor the asserts in xentrace itself trigger because "cons" is not aligned because the very last trace page for the second cpu is a random mfn.

Quoted 1 line

Thanks to Jan for the quick analysis.

And with that obviously ...

Quoted 1 line
Quoted 17 lines
xen/common/trace.c +0 -0
@@ -133,7 +133,7 @@ static int calculate_tbuf_size(unsigned 
      * The array of mfns for the highest cpu can start at the maximum value
      * mfn_offset can hold. So reduce the number of cpus and also the 

mfn_offset.

      */
xen/common/trace.c +1 -1
-    max_mfn_offset -= t_info_first_offset - 1;
+    max_mfn_offset -= t_info_first_offset;
     max_cpus--;
     if ( max_cpus )
         max_mfn_offset /= max_cpus;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Olaf Hering
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Olaf Hering

xentrace: fix off-by-one in calculate_tbuf_size

Commit "xentrace: reduce trace buffer size to something mfn_offset can reach" contains an off-by-one bug. max_mfn_offset needs to be reduced by exactly the value of t_info_first_offset.

If the system has two cpus and the number of requested trace pages is very large, the final number of trace pages + the offset will not fit into a short. As a result the variable offset in alloc_trace_bufs() will wrap while allocating buffers for the second cpu. Later share_xen_page_with_privileged_guests() will be called with a wrong page and the ASSERT in this function triggers. If the ASSERT is ignored by running a non-dbg hypervisor the asserts in xentrace itself trigger because "cons" is not aligned because the very last trace page for the second cpu is a random mfn.

Quoted 4 lines

Thanks to Jan for the quick analysis.

George?

Thanks, Jan

Quoted 18 lines

diff -r 3eb62c576a1a -r 13c43170cd5f xen/common/trace.c

xen/common/trace.c +0 -0
@@ -133,7 +133,7 @@ static int calculate_tbuf_size(unsigned 
      * The array of mfns for the highest cpu can start at the maximum value
      * mfn_offset can hold. So reduce the number of cpus and also the 

mfn_offset.

      */
xen/common/trace.c +1 -1
-    max_mfn_offset -= t_info_first_offset - 1;
+    max_mfn_offset -= t_info_first_offset;
     max_cpus--;
     if ( max_cpus )
         max_mfn_offset /= max_cpus;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v1 1/1
#3 lore raw
In reply to Olaf Hering
Quoted 30 lines · Olaf Hering

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1362151425 -3600
# Node ID 13c43170cd5f653d9590916df82f60597d1d5326 # Parent 3eb62c576a1a315b9f8655a186ead470abe69b31
xentrace: fix off-by-one in calculate_tbuf_size

Commit "xentrace: reduce trace buffer size to something mfn_offset can reach" contains an off-by-one bug. max_mfn_offset needs to be reduced by exactly the value of t_info_first_offset.

If the system has two cpus and the number of requested trace pages is very large, the final number of trace pages + the offset will not fit into a short. As a result the variable offset in alloc_trace_bufs() will wrap while allocating buffers for the second cpu. Later share_xen_page_with_privileged_guests() will be called with a wrong page and the ASSERT in this function triggers. If the ASSERT is ignored by running a non-dbg hypervisor the asserts in xentrace itself trigger because "cons" is not aligned because the very last trace page for the second cpu is a random mfn.

Thanks to Jan for the quick analysis.

diff -r 3eb62c576a1a -r 13c43170cd5f xen/common/trace.c

xen/common/trace.c static int calculate_tbuf_size(unsigned · line 136

Quoted 5 lines
xen/common/trace.c +1 -1
@@ -133,7 +133,7 @@ static int calculate_tbuf_size(unsigned
      * The array of mfns for the highest cpu can start at the maximum value
      * mfn_offset can hold. So reduce the number of cpus and also the mfn_offset.
      */
-    max_mfn_offset -= t_info_first_offset - 1;
+    max_mfn_offset -= t_info_first_offset;

Hmm -- I think my intention was actually to be more conservative; i.e., max_mfn_offset = max_mfn_offset - t_info_first_offset - 1. But it seems I did the opposite. :-)

In any case, this looks good: