Skip to contentSkip to conversation

perf fixes

GIT PULL Ingo Molnar 1 participant 1 message Jul 6, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Linus,

Please pull the latest perf-urgent-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf-urgent-for-linus

# HEAD: ebf2d2689de551d90965090bb991fc640a0c0d41 perf/x86: Fix copy_from_user_nmi() return if range is not ok

This:

- Fixes the perf build, by fixing the rbtree.c sharing bug between kernel and tools/perf by creating a local copy of rbtree.c (more will be done for v4.3)

- Fixes an AUX buffer (Intel-PT support) refcounting bug

- Fixes copy_from_user_nmi() return value.

Thanks,

Ingo

------------------>
Arnaldo Carvalho de Melo (5):
tools: Adopt {READ,WRITE_ONCE} from the kernel perf tools: Copy rbtree.h from the kernel
tools: Copy lib/rbtree.c to tools/lib/
tools: Move rbtree.h from tools/perf/
tools: Copy rbtree_augmented.h from the kernel

Peter Zijlstra (1):
perf: Fix AUX buffer refcounting

Yann Droneaud (1):
perf/x86: Fix copy_from_user_nmi() return if range is not ok

 arch/x86/lib/usercopy.c                          |   2 +-
 kernel/events/core.c                             |   8 -
 kernel/events/internal.h                         |  10 +
 kernel/events/ring_buffer.c                      |  27 +-
 tools/include/linux/compiler.h                   |  58 +++
 tools/include/linux/export.h                     |  10 -
 tools/include/linux/rbtree.h                     | 104 +++++
 tools/include/linux/rbtree_augmented.h           | 245 ++++++++++
 tools/lib/rbtree.c                               | 548 +++++++++++++++++++++++
 tools/perf/MANIFEST                              |   6 +-
 tools/perf/util/Build                            |   2 +-
 tools/perf/util/include/linux/rbtree.h           |  16 -
 tools/perf/util/include/linux/rbtree_augmented.h |   2 -
 13 files changed, 995 insertions(+), 43 deletions(-)
 delete mode 100644 tools/include/linux/export.h
 create mode 100644 tools/include/linux/rbtree.h
 create mode 100644 tools/include/linux/rbtree_augmented.h
 create mode 100644 tools/lib/rbtree.c
 delete mode 100644 tools/perf/util/include/linux/rbtree.h
 delete mode 100644 tools/perf/util/include/linux/rbtree_augmented.h
arch/x86/lib/usercopy.c +1 -1
index ddf9ecb53cc3..e342586db6e4 100644
@@ -20,7 +20,7 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
 	unsigned long ret;
 
 	if (__range_not_ok(from, n, TASK_SIZE))
-		return 0;
+		return n;
 
 	/*
 	 * Even though this function is typically called from NMI/IRQ context
kernel/events/core.c +0 -8
index e965cfae4207..d3dae3419b99 100644
@@ -4358,14 +4358,6 @@ static void ring_buffer_wakeup(struct perf_event *event)
 	rcu_read_unlock();
 }
 
-static void rb_free_rcu(struct rcu_head *rcu_head)
-{
-	struct ring_buffer *rb;
-
-	rb = container_of(rcu_head, struct ring_buffer, rcu_head);
-	rb_free(rb);
-}
-
 struct ring_buffer *ring_buffer_get(struct perf_event *event)
 {
 	struct ring_buffer *rb;
kernel/events/internal.h +10 -0
index 2deb24c7a40d..2bbad9c1274c 100644
@@ -11,6 +11,7 @@
 struct ring_buffer {
 	atomic_t			refcount;
 	struct rcu_head			rcu_head;
+	struct irq_work			irq_work;
 #ifdef CONFIG_PERF_USE_VMALLOC
 	struct work_struct		work;
 	int				page_order;	/* allocation order  */
@@ -55,6 +56,15 @@ struct ring_buffer {
 };
 
 extern void rb_free(struct ring_buffer *rb);
+
+static inline void rb_free_rcu(struct rcu_head *rcu_head)
+{
+	struct ring_buffer *rb;
+
+	rb = container_of(rcu_head, struct ring_buffer, rcu_head);
+	rb_free(rb);
+}
+
 extern struct ring_buffer *
 rb_alloc(int nr_pages, long watermark, int cpu, int flags);
 extern void perf_event_wakeup(struct perf_event *event);
kernel/events/ring_buffer.c +25 -2
index 96472824a752..b2be01b1aa9d 100644
@@ -221,6 +221,8 @@ void perf_output_end(struct perf_output_handle *handle)
 	rcu_read_unlock();
 }
 
+static void rb_irq_work(struct irq_work *work);
+
 static void
 ring_buffer_init(struct ring_buffer *rb, long watermark, int flags)
 {
@@ -241,6 +243,16 @@ ring_buffer_init(struct ring_buffer *rb, long watermark, int flags)
 
 	INIT_LIST_HEAD(&rb->event_list);
 	spin_lock_init(&rb->event_lock);
+	init_irq_work(&rb->irq_work, rb_irq_work);
+}
+
+static void ring_buffer_put_async(struct ring_buffer *rb)
+{
+	if (!atomic_dec_and_test(&rb->refcount))
+		return;
+
+	rb->rcu_head.next = (void *)rb;
+	irq_work_queue(&rb->irq_work);
 }
 
 /*
@@ -319,7 +331,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
 	rb_free_aux(rb);
 
 err:
-	ring_buffer_put(rb);
+	ring_buffer_put_async(rb);
 	handle->event = NULL;
 
 	return NULL;
@@ -370,7 +382,7 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,
 
 	local_set(&rb->aux_nest, 0);
 	rb_free_aux(rb);
-	ring_buffer_put(rb);
+	ring_buffer_put_async(rb);
 }
 
 /*
@@ -557,7 +569,18 @@ static void __rb_free_aux(struct ring_buffer *rb)
 void rb_free_aux(struct ring_buffer *rb)
 {
 	if (atomic_dec_and_test(&rb->aux_refcount))
+		irq_work_queue(&rb->irq_work);
+}
+
+static void rb_irq_work(struct irq_work *work)
+{
+	struct ring_buffer *rb = container_of(work, struct ring_buffer, irq_work);
+
+	if (!atomic_read(&rb->aux_refcount))
 		__rb_free_aux(rb);
+
+	if (rb->rcu_head.next == (void *)rb)
+		call_rcu(&rb->rcu_head, rb_free_rcu);
 }
 
 #ifndef CONFIG_PERF_USE_VMALLOC
tools/include/linux/compiler.h +58 -0

62 lines not on this page · raw message

tools/include/linux/export.h deleted +0 -10
deleted file mode 100644
index d07e586b9ba0..000000000000
@@ -1,10 +0,0 @@
-#ifndef _TOOLS_LINUX_EXPORT_H_
-#define _TOOLS_LINUX_EXPORT_H_
-
-#define EXPORT_SYMBOL(sym)
-#define EXPORT_SYMBOL_GPL(sym)
-#define EXPORT_SYMBOL_GPL_FUTURE(sym)
-#define EXPORT_UNUSED_SYMBOL(sym)
-#define EXPORT_UNUSED_SYMBOL_GPL(sym)
-
-#endif
tools/include/linux/rbtree.h new file +104 -0

104 lines not on this page · raw message

tools/include/linux/rbtree_augmented.h new file +245 -0

245 lines not on this page · raw message

tools/lib/rbtree.c new file +548 -0

548 lines not on this page · raw message

tools/perf/MANIFEST +3 -3
index fe50a1b34aa0..09dc0aabb515 100644
@@ -18,6 +18,7 @@ tools/arch/x86/include/asm/atomic.h
 tools/arch/x86/include/asm/rmwcc.h
 tools/lib/traceevent
 tools/lib/api
+tools/lib/rbtree.c
 tools/lib/symbol/kallsyms.c
 tools/lib/symbol/kallsyms.h
 tools/lib/util/find_next_bit.c
@@ -44,6 +45,8 @@ tools/include/linux/kernel.h
 tools/include/linux/list.h
 tools/include/linux/log2.h
 tools/include/linux/poison.h
+tools/include/linux/rbtree.h
+tools/include/linux/rbtree_augmented.h
 tools/include/linux/types.h
 include/asm-generic/bitops/arch_hweight.h
 include/asm-generic/bitops/const_hweight.h
@@ -51,12 +54,10 @@ include/asm-generic/bitops/fls64.h
 include/asm-generic/bitops/__fls.h
 include/asm-generic/bitops/fls.h
 include/linux/perf_event.h
-include/linux/rbtree.h
 include/linux/list.h
 include/linux/hash.h
 include/linux/stringify.h
 lib/hweight.c
-lib/rbtree.c
 include/linux/swab.h
 arch/*/include/asm/unistd*.h
 arch/*/include/uapi/asm/unistd*.h
@@ -65,7 +66,6 @@ arch/*/lib/memcpy*.S
 arch/*/lib/memset*.S
 include/linux/poison.h
 include/linux/hw_breakpoint.h
-include/linux/rbtree_augmented.h
 include/uapi/linux/perf_event.h
 include/uapi/linux/const.h
 include/uapi/linux/swab.h
tools/perf/util/Build +1 -1
index 586a59d46022..601d11440596 100644
@@ -139,7 +139,7 @@ $(OUTPUT)util/find_next_bit.o: ../lib/util/find_next_bit.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
 
-$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c FORCE
+$(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
 
tools/perf/util/include/linux/rbtree.h deleted +0 -16
deleted file mode 100644
index f06d89f0b867..000000000000
@@ -1,16 +0,0 @@
-#ifndef __TOOLS_LINUX_PERF_RBTREE_H
-#define __TOOLS_LINUX_PERF_RBTREE_H
-#include <stdbool.h>
-#include "../../../../include/linux/rbtree.h"
-
-/*
- * Handy for checking that we are not deleting an entry that is
- * already in a list, found in block/{blk-throttle,cfq-iosched}.c,
- * probably should be moved to lib/rbtree.c...
- */
-static inline void rb_erase_init(struct rb_node *n, struct rb_root *root)
-{
-	rb_erase(n, root);
-	RB_CLEAR_NODE(n);
-}
-#endif /* __TOOLS_LINUX_PERF_RBTREE_H */
tools/perf/util/include/linux/rbtree_augmented.h deleted +0 -2
deleted file mode 100644
index 9d6fcdf1788b..000000000000
@@ -1,2 +0,0 @@
-#include <stdbool.h>
-#include "../../../../include/linux/rbtree_augmented.h"