[PATCH v2 1/2] perf/x86: fix active_entry initialization

2014-01-08 Thread Stephane Eranian
This patch fixes a problem with the initialization of the
struct perf_event active_entry field. It is defined inside
an anonymous union and was initialized in perf_event_alloc()
using INIT_LIST_HEAD(). However at that time, we do not know
whether the event is going to use active_entry or hlist_entry (SW).
Or at last, we don't want to make that determination there.
The problem is that hlist and list_head are not initialized
the same way. One is okay with NULL (from kzmalloc), the other
needs to pointers to point to self.

This patch resolves this problem by dropping the union.
This will avoid problems later on, if someone starts using
active_entry or hlist_entry without verifying that they
actually overlap. This also solves the initialization
problem.

Signed-off-by: Stephane Eranian 
---
 include/linux/perf_event.h |6 ++
 kernel/events/core.c   |2 ++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 8f4a70f..e56b07f 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -319,10 +319,8 @@ struct perf_event {
 */
struct list_headmigrate_entry;
 
-   union {
-   struct hlist_node   hlist_entry;
-   struct list_headactive_entry;
-   };
+   struct hlist_node   hlist_entry;
+   struct list_headactive_entry;
int nr_siblings;
int group_flags;
struct perf_event   *group_leader;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4b743b2..74fdef5 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6685,6 +6685,8 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
INIT_LIST_HEAD(>sibling_list);
INIT_LIST_HEAD(>rb_entry);
INIT_LIST_HEAD(>active_entry);
+   INIT_HLIST_NODE(>hlist_entry);
+
 
init_waitqueue_head(>waitq);
init_irq_work(>pending, perf_pending_event);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/2] perf/x86: fix active_entry initialization

2014-01-08 Thread Stephane Eranian
This patch fixes a problem with the initialization of the
struct perf_event active_entry field. It is defined inside
an anonymous union and was initialized in perf_event_alloc()
using INIT_LIST_HEAD(). However at that time, we do not know
whether the event is going to use active_entry or hlist_entry (SW).
Or at last, we don't want to make that determination there.
The problem is that hlist and list_head are not initialized
the same way. One is okay with NULL (from kzmalloc), the other
needs to pointers to point to self.

This patch resolves this problem by dropping the union.
This will avoid problems later on, if someone starts using
active_entry or hlist_entry without verifying that they
actually overlap. This also solves the initialization
problem.

Signed-off-by: Stephane Eranian eran...@google.com
---
 include/linux/perf_event.h |6 ++
 kernel/events/core.c   |2 ++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 8f4a70f..e56b07f 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -319,10 +319,8 @@ struct perf_event {
 */
struct list_headmigrate_entry;
 
-   union {
-   struct hlist_node   hlist_entry;
-   struct list_headactive_entry;
-   };
+   struct hlist_node   hlist_entry;
+   struct list_headactive_entry;
int nr_siblings;
int group_flags;
struct perf_event   *group_leader;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4b743b2..74fdef5 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6685,6 +6685,8 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
INIT_LIST_HEAD(event-sibling_list);
INIT_LIST_HEAD(event-rb_entry);
INIT_LIST_HEAD(event-active_entry);
+   INIT_HLIST_NODE(event-hlist_entry);
+
 
init_waitqueue_head(event-waitq);
init_irq_work(event-pending, perf_pending_event);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/