perf_counter: sanity check on the output API
authorPeter Zijlstra <a.p.zijlstra@chello.nl>
Wed, 25 Mar 2009 11:30:24 +0000 (12:30 +0100)
committerIngo Molnar <mingo@elte.hu>
Mon, 6 Apr 2009 07:30:33 +0000 (09:30 +0200)
Ensure we never write more than we said we would.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Orig-LKML-Reference: <20090325113316.921433024@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
kernel/perf_counter.c

index d76e3112d386bd1b89df8b4c6f3a65195583ae2f..7669afe82cc7c6b62aeebde009d0d782ed479f75 100644 (file)
@@ -1422,6 +1422,7 @@ struct perf_output_handle {
        struct perf_counter     *counter;
        struct perf_mmap_data   *data;
        unsigned int            offset;
+       unsigned int            head;
        int                     wakeup;
 };
 
@@ -1447,6 +1448,7 @@ static int perf_output_begin(struct perf_output_handle *handle,
        handle->counter = counter;
        handle->data    = data;
        handle->offset  = offset;
+       handle->head    = head;
        handle->wakeup  = (offset >> PAGE_SHIFT) != (head >> PAGE_SHIFT);
 
        return 0;
@@ -1485,6 +1487,8 @@ static void perf_output_copy(struct perf_output_handle *handle,
        } while (len);
 
        handle->offset = offset;
+
+       WARN_ON_ONCE(handle->offset > handle->head);
 }
 
 #define perf_output_put(handle, x) \