Skip to contentSkip to conversation

oprofile, arm: proper release resources on failure

PATCH In review Robert Richter 2 participants 8 messages Sep 29, 2010 – Oct 16, 2010 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oprofile, arm: proper release resources on failure

Will,

the patch below fixes a resource leak I found during code review. Can you please review and test it (I don't have an ARM environment for this available). If you are fine with the change, please ack. I want to send it upstream via tip/perf/urgent.

Though you reworked the code already, parts of the fix are still valid for latest oprofile code in oprofile/core.

Ingo,

if Will agrees with it, please apply it directly to tip/perf/urgent.

Thanks,

-Robert

--

#1 lore raw
Quoted 2 lines · Robert Richter

Will,

Hi Robert,

Quoted 5 lines

the patch below fixes a resource leak I found during code review. Can you please review and test it (I don't have an ARM environment for this available). If you are fine with the change, please ack. I want to send it upstream via tip/perf/urgent.

I have a few minor clarifications:

Quoted 7 lines
arch/arm/oprofile/common.c +0 -0
index 0691176..72e09eb 100644

arch/arm/oprofile/common.c static int op_create_counter(int cpu, int event) · line 108

Quoted 7 lines
arch/arm/oprofile/common.c +1 -0
@@ -102,6 +102,7 @@ static int op_create_counter(int cpu, int event)
        if (IS_ERR(pevent)) {
                ret = PTR_ERR(pevent);
        } else if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
+               perf_event_release_kernel(pevent);
                pr_warning("oprofile: failed to enable event %d "
                                "on CPU %d\n", event, cpu);
                ret = -EBUSY;

Yup, this is needed. Thanks! It would be nice to do away with the else statement altogether but I think adding a pinned event and then failing to activate it still succeeds in perf_event_create_kernel_counter.

Quoted 29 lines
arch/arm/oprofile/common.c +4 -3
@@ -365,6 +366,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
        ret = init_driverfs();
        if (ret) {
                kfree(counter_config);
+               counter_config = NULL;
                return ret;
        }
 
@@ -402,7 +404,6 @@ void oprofile_arch_exit(void)
        struct perf_event *event;
 
        if (*perf_events) {
-               exit_driverfs();
                for_each_possible_cpu(cpu) {
                        for (id = 0; id < perf_num_counters; ++id) {
                                event = perf_events[cpu][id];
@@ -413,8 +414,10 @@ void oprofile_arch_exit(void)
                }
        }
 
-       if (counter_config)
+       if (counter_config) {
                kfree(counter_config);
+               exit_driverfs();
+       }
 }
 #else
 int __init oprofile_arch_init(struct oprofile_operations *ops)
--
Quoted 2 lines

1.7.2.2

Hmm, these three hunks conflict with the patches I posted last month to fix the resource allocation and freeing. Can't we merge those patches instead? I have versions against -rc6 here:

git://linux-arm.org/linux-2.6-wd.git oprofile-mm

Cheers,

Will

#2 lore raw
Quoted 13 lines · Will Deacon

I have a few minor clarifications:

Quoted 12 lines
arch/arm/oprofile/common.c +1 -0
index 0691176..72e09eb 100644
@@ -102,6 +102,7 @@ static int op_create_counter(int cpu, int event)
        if (IS_ERR(pevent)) {
                ret = PTR_ERR(pevent);
        } else if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
+               perf_event_release_kernel(pevent);
                pr_warning("oprofile: failed to enable event %d "
Quoted 8 lines

arch/arm/oprofile/common.c static int op_create_counter(int cpu, int event) · line 108

Quoted 2 lines
arch/arm/oprofile/common.c +0 -0
                                "on CPU %d\n", event, cpu);
                ret = -EBUSY;

Yup, this is needed. Thanks! It would be nice to do away with the else statement altogether but I think adding a pinned event and then failing to activate it still succeeds in perf_event_create_kernel_counter.

Yes, I have cleanup code already for this. But as this is an -rc and stable fix, I didn't want to change too much here. But I will send a follow-on patch with the cleanup I made.

Quoted 22 lines
Quoted 22 lines
arch/arm/oprofile/common.c +1 -1
@@ -365,6 +366,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
        ret = init_driverfs();
        if (ret) {
                kfree(counter_config);
+               counter_config = NULL;
                return ret;
        }
 
@@ -402,7 +404,6 @@ void oprofile_arch_exit(void)
        struct perf_event *event;
 
        if (*perf_events) {
-               exit_driverfs();
                for_each_possible_cpu(cpu) {
                        for (id = 0; id < perf_num_counters; ++id) {
                                event = perf_events[cpu][id];
@@ -413,8 +414,10 @@ void oprofile_arch_exit(void)
                }
        }
 
Quoted 15 lines
Quoted 11 lines
arch/arm/oprofile/common.c +3 -2
-       if (counter_config)
+       if (counter_config) {
                kfree(counter_config);
+               exit_driverfs();
+       }
 }
 #else
 int __init oprofile_arch_init(struct oprofile_operations *ops)
--

1.7.2.2

Hmm, these three hunks conflict with the patches I posted last month to fix the resource allocation and freeing. Can't we merge those patches instead? I have versions against -rc6 here:

Yes, these patches are also in my oprofile/core branch and its changes conflict, but are scheduled for the next merge window. This fix is for urgent and for 2.6.36. We will then merge back rc7 or 2.6.36 to oprofile/core and solve the conflicts. But if you don't have something else for -rc7/.36 that conflicts, this should be ok.

-Robert

Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center
#3 lore raw
Quoted 9 lines · Robert Richter
Quoted 3 lines

Hmm, these three hunks conflict with the patches I posted last month to fix the resource allocation and freeing. Can't we merge those patches instead? I have versions against -rc6 here:

Yes, these patches are also in my oprofile/core branch and its changes conflict, but are scheduled for the next merge window. This fix is for urgent and for 2.6.36. We will then merge back rc7 or 2.6.36 to oprofile/core and solve the conflicts. But if you don't have something else for -rc7/.36 that conflicts, this should be ok.

So, it would be ok then to test only this fix on -rc6 without your other patches.

Thanks,

-Robert

Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center
Acked-by
#4 lore raw

Robert,

Quoted 6 lines · Robert Richter
Quoted 4 lines · Robert Richter
Quoted 3 lines

Hmm, these three hunks conflict with the patches I posted last month to fix the resource allocation and freeing. Can't we merge those patches instead? I have versions against -rc6 here:

Quoted 9 lines
Quoted 5 lines

Yes, these patches are also in my oprofile/core branch and its changes conflict, but are scheduled for the next merge window. This fix is for urgent and for 2.6.36. We will then merge back rc7 or 2.6.36 to oprofile/core and solve the conflicts. But if you don't have something else for -rc7/.36 that conflicts, this should be ok.

So, it would be ok then to test only this fix on -rc6 without your other patches.

Gotcha - this is a minimal fixup for -stable which we'll tackle properly in the merge window with the stuff in oprofile/core. In that case I'm happy for this to go upstream now:

I also built an -rc6 kernel with this change on top and OProfile worked happily across module loads/unloads.

As for oprofile/core; will you handle the conflicts there or do I need to resend my previous patches?

Cheers,

Will

#5 lore raw
Quoted 23 lines · Will Deacon

Robert,

Quoted 6 lines · Robert Richter
Quoted 4 lines · Robert Richter
Quoted 3 lines

Hmm, these three hunks conflict with the patches I posted last month to fix the resource allocation and freeing. Can't we merge those patches instead? I have versions against -rc6 here:

Quoted 9 lines
Quoted 5 lines

Yes, these patches are also in my oprofile/core branch and its changes conflict, but are scheduled for the next merge window. This fix is for urgent and for 2.6.36. We will then merge back rc7 or 2.6.36 to oprofile/core and solve the conflicts. But if you don't have something else for -rc7/.36 that conflicts, this should be ok.

So, it would be ok then to test only this fix on -rc6 without your other patches.

Gotcha - this is a minimal fixup for -stable which we'll tackle properly in the merge window with the stuff in oprofile/core. In that case I'm happy for this to go upstream now:

Quoted 8 lines

I also built an -rc6 kernel with this change on top and OProfile worked happily across module loads/unloads.

As for oprofile/core; will you handle the conflicts there or do I need to resend my previous patches?

Yes, I will merge it after it went upstream and let you know.

-Robert

Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center
#6 lore raw

[tip:perf/urgent] oprofile, ARM: Release resources on failure

In reply to Robert Richter
Commit-ID:  98d943b02f6f1b57787ff1aa6f34d019a407e3ee
Gitweb:     http://git.kernel.org/tip/98d943b02f6f1b57787ff1aa6f34d019a407e3ee
Author:     Robert Richter <[email protected]>
AuthorDate: Wed, 29 Sep 2010 16:52:25 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 30 Sep 2010 09:14:25 +0200

oprofile, ARM: Release resources on failure

This patch fixes a resource leak on failure, where the oprofilefs and some counters may not released properly.

LKML-Reference: <[email protected]>

---
 arch/arm/oprofile/common.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
arch/arm/oprofile/common.c +5 -2
index 0691176..72e09eb 100644
@@ -102,6 +102,7 @@ static int op_create_counter(int cpu, int event)
 	if (IS_ERR(pevent)) {
 		ret = PTR_ERR(pevent);
 	} else if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
+		perf_event_release_kernel(pevent);
 		pr_warning("oprofile: failed to enable event %d "
 				"on CPU %d\n", event, cpu);
 		ret = -EBUSY;
@@ -365,6 +366,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
 	ret = init_driverfs();
 	if (ret) {
 		kfree(counter_config);
+		counter_config = NULL;
 		return ret;
 	}
 
@@ -402,7 +404,6 @@ void oprofile_arch_exit(void)
 	struct perf_event *event;
 
 	if (*perf_events) {
-		exit_driverfs();
 		for_each_possible_cpu(cpu) {
 			for (id = 0; id < perf_num_counters; ++id) {
 				event = perf_events[cpu][id];
@@ -413,8 +414,10 @@ void oprofile_arch_exit(void)
 		}
 	}
 
-	if (counter_config)
+	if (counter_config) {
 		kfree(counter_config);
+		exit_driverfs();
+	}
 }
 #else
 int __init oprofile_arch_init(struct oprofile_operations *ops)
#7 lore raw

[tip:perf/core] oprofile, ARM: Release resources on failure

In reply to Robert Richter
Commit-ID:  81771974ae49bf79aab60c42eac7a6d730a9ef2b
Gitweb:     http://git.kernel.org/tip/81771974ae49bf79aab60c42eac7a6d730a9ef2b
Author:     Robert Richter <[email protected]>
AuthorDate: Wed, 29 Sep 2010 16:52:25 +0200
Committer:  Robert Richter <[email protected]>
CommitDate: Mon, 11 Oct 2010 19:27:10 +0200

oprofile, ARM: Release resources on failure

This patch fixes a resource leak on failure, where the oprofilefs and some counters may not released properly.

LKML-Reference: <[email protected]>

---
 drivers/oprofile/oprofile_perf.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/oprofile/oprofile_perf.c +1 -0
index ebb40cb..f3d3df2 100644
@@ -84,6 +84,7 @@ static int op_create_counter(int cpu, int event)
 	if (IS_ERR(pevent)) {
 		ret = PTR_ERR(pevent);
 	} else if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
+		perf_event_release_kernel(pevent);
 		pr_warning("oprofile: failed to enable event %d "
 				"on CPU %d\n", event, cpu);
 		ret = -EBUSY;