]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ring-buffer: Make sure event has enough room for extend and padding
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>
Fri, 29 May 2015 14:29:10 +0000 (10:29 -0400)
committerSteven Rostedt <rostedt@goodmis.org>
Tue, 21 Jul 2015 02:30:49 +0000 (22:30 -0400)
Now that events only add time extends after it is committed, in case
an event comes in before it can discard the allocated event, the time
extend needs to be stored within the event. If the event is bigger
than then size needed for the time extend, padding must be added.
The minimum padding size is 8 bytes. Thus if the event is 12 bytes
(size of time extend + 4), there will not be enough room to add both
the time extend and padding. Make sure all events are either 8 bytes
or 16 or more bytes.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/ring_buffer.c

index b5ed553e0a45f9a4faf3b74dacfc4fa18842bdd6..781ce359976c97a9d5bae2d188e7a760cc8172c7 100644 (file)
@@ -2208,6 +2208,21 @@ static unsigned rb_calculate_event_length(unsigned length)
        length += RB_EVNT_HDR_SIZE;
        length = ALIGN(length, RB_ARCH_ALIGNMENT);
 
+       /*
+        * In case the time delta is larger than the 27 bits for it
+        * in the header, we need to add a timestamp. If another
+        * event comes in when trying to discard this one to increase
+        * the length, then the timestamp will be added in the allocated
+        * space of this event. If length is bigger than the size needed
+        * for the TIME_EXTEND, then padding has to be used. The events
+        * length must be either RB_LEN_TIME_EXTEND, or greater than or equal
+        * to RB_LEN_TIME_EXTEND + 8, as 8 is the minimum size for padding.
+        * As length is a multiple of 4, we only need to worry if it
+        * is 12 (RB_LEN_TIME_EXTEND + 4).
+        */
+       if (length == RB_LEN_TIME_EXTEND + RB_ALIGNMENT)
+               length += RB_ALIGNMENT;
+
        return length;
 }