perf cgroup: Fix leak of file reference count
PATCH 1/4 perf cgroup: Fix leak of file reference count
In perf_cgroup_connect(), fput_light() is missing in a failure path.
--- kernel/perf_event.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
kernel/perf_event.c +5 -2
@@ -404,8 +404,10 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,return -EBADF ; css =cgroup_css_from_dir (file, perf_subsys_id); -if (IS_ERR (css)) -return PTR_ERR (css); +if (IS_ERR (css)) { + ret =PTR_ERR (css); + goto out; + } cgrp = container_of(css, struct perf_cgroup, css); event->cgrp = cgrp;
@@ -422,6 +424,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,/* must be done before we fput() the file */ perf_get_cgroup (event); } +out:fput_light (file, fput_needed);return ret; }
Signature · 1 line
1.6.3
PATCH 2/4 perf cgroup: Fix unmatched call to perf_detach_cgroup()
In the failure path, we call perf_detach_cgroup(), but we didn't call perf_get_cgroup() prio to it.
--- kernel/perf_event.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/perf_event.c +3 -3
@@ -412,6 +412,9 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, cgrp = container_of(css, struct perf_cgroup, css); event->cgrp = cgrp; +/* must be done before we fput() the file */ +perf_get_cgroup (event); +/* * all events in a group must monitor * the same cgroup because a task belongs
@@ -420,9 +423,6 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,if (group_leader && group_leader->cgrp != cgrp) {perf_detach_cgroup (event); ret = -EINVAL ; - }else { -/* must be done before we fput() the file */ -perf_get_cgroup (event); } out:fput_light (file, fput_needed);
Signature · 1 line
1.6.3
Re: [PATCH 2/4] perf cgroup: Fix unmatched call to perf_detach_cgroup()
Quoted 3 lines · Li Zefan
In the failure path, we call
perf_detach_cgroup(), but we didn't callperf_get_cgroup()prio to it.
the funny thing is that I had this change at some point. But apparently it got lost in the many revisions of the patch. Thanks for fixing it.
Quoted 32 lines
Signed-off-by Li Zefan <[email protected]>---
kernel/perf_event.c | 6 +++---1 files changed, 3 insertions(+), 3 deletions(-)kernel/perf_event.c +3
-3@@ -412,6 +412,9 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, cgrp = container_of(css, struct perf_cgroup, css); event->cgrp = cgrp; + /* must be done before we fput() the file */ + perf_get_cgroup(event); + /** all events in a group must monitor * the same cgroup because a task belongs @@ -420,9 +423,6 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, if (group_leader && group_leader->cgrp != cgrp) { perf_detach_cgroup(event); ret = -EINVAL; - } else { - /* must be done before we fput() the file */ - perf_get_cgroup(event); }out:
fput_light(file,fput_needed);
--
1.6.3
[tip:perf/core] perf cgroup: Fix unmatched call to perf_detach_cgroup()
In reply to Li ZefanCommit-ID: f75e18cb9627b1d3d752b83a0b5563da0042c50a Gitweb: http://git.kernel.org/tip/f75e18cb9627b1d3d752b83a0b5563da0042c50a Author: Li Zefan <[email protected]> AuthorDate: Thu, 3 Mar 2011 14:25:50 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 4 Mar 2011 11:32:51 +0100
perf cgroup: Fix unmatched call to perf_detach_cgroup()
In the failure path, we call perf_detach_cgroup(), but we didn't call perf_get_cgroup() prio to it.
LKML-Reference: <[email protected]>
--- kernel/perf_event.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/perf_event.c +3 -3
@@ -412,6 +412,9 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, cgrp = container_of(css, struct perf_cgroup, css); event->cgrp = cgrp; +/* must be done before we fput() the file */ +perf_get_cgroup (event); +/* * all events in a group must monitor * the same cgroup because a task belongs
@@ -420,9 +423,6 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,if (group_leader && group_leader->cgrp != cgrp) {perf_detach_cgroup (event); ret = -EINVAL ; - }else { -/* must be done before we fput() the file */ -perf_get_cgroup (event); } out:fput_light (file, fput_needed);
PATCH 3/4 perf cgroup: Clean up perf_cgroup_create()
In reply to Li Zefan- Use kzalloc() to replace kmalloc() + memset().
- Remove redundant initialization, since alloc_percpu() returns zero-filled percpu memory.
--- kernel/perf_event.c | 11 +---------- 1 files changed, 1 insertions(+), 10 deletions(-)
kernel/perf_event.c +1 -10
@@ -7341,26 +7341,17 @@ static struct cgroup_subsys_state *perf_cgroup_create( struct cgroup_subsys *ss, struct cgroup *cont) { struct perf_cgroup *jc; -struct perf_cgroup_info *t; -int c; - jc =kmalloc (sizeof (*jc),GFP_KERNEL ); + jc =kzalloc (sizeof (*jc),GFP_KERNEL );if (!jc)return ERR_PTR (-ENOMEM ); -memset (jc,0 ,sizeof (*jc)); - jc->info = alloc_percpu(struct perf_cgroup_info);if (!jc->info) {kfree (jc);return ERR_PTR (-ENOMEM ); } -for_each_possible_cpu (c) { - t =per_cpu_ptr (jc->info, c); - t->time =0 ; - t->timestamp =0 ; - }return &jc->css; }
Signature · 1 line
1.6.3
Re: [PATCH 3/4] perf cgroup: Clean up perf_cgroup_create()
Quoted 4 lines · Li Zefan
- Use
kzalloc()to replacekmalloc()+memset().
- Remove redundant initialization, sincealloc_percpu()returns zero-filled percpu memory.
Quoted 40 lines
Signed-off-by Li Zefan <[email protected]>---
kernel/perf_event.c | 11 +----------1 files changed, 1 insertions(+), 10 deletions(-)kernel/perf_event.c +1
-11@@ -7341,26 +7341,17 @@ static struct cgroup_subsys_state *perf_cgroup_create( struct cgroup_subsys *ss, struct cgroup *cont) { struct perf_cgroup *jc; - struct perf_cgroup_info *t; - int c; - jc = kmalloc(sizeof(*jc), GFP_KERNEL); + jc = kzalloc(sizeof(*jc), GFP_KERNEL); if (!jc) return ERR_PTR(-ENOMEM); - memset(jc, 0, sizeof(*jc)); - jc->info = alloc_percpu(struct perf_cgroup_info); if (!jc->info) { kfree(jc); return ERR_PTR(-ENOMEM); } - for_each_possible_cpu(c) { - t = per_cpu_ptr(jc->info, c); - t->time = 0; - t->timestamp = 0; - } return &jc->css; } --1.6.3
Re: [PATCH 3/4] perf cgroup: Clean up perf_cgroup_create()
In reply to Li ZefanLi,
I have to NACK this patch or at least request more information.
The for_each_possible_cpu() is initializing what's allocated via alloc_percpu(), jc->info and NOT jc.
I don't think this gets zeroed by this allocator. But I could be wrong.
Quoted 44 lines · Li Zefan
- Use
kzalloc()to replacekmalloc()+memset().
- Remove redundant initialization, sincealloc_percpu()returns zero-filled percpu memory.Signed-off-by Li Zefan <[email protected]>---
kernel/perf_event.c | 11 +----------1 files changed, 1 insertions(+), 10 deletions(-)kernel/perf_event.c +1
-11@@ -7341,26 +7341,17 @@ static struct cgroup_subsys_state *perf_cgroup_create( struct cgroup_subsys *ss, struct cgroup *cont) { struct perf_cgroup *jc; - struct perf_cgroup_info *t; - int c; - jc = kmalloc(sizeof(*jc), GFP_KERNEL); + jc = kzalloc(sizeof(*jc), GFP_KERNEL); if (!jc) return ERR_PTR(-ENOMEM); - memset(jc, 0, sizeof(*jc)); - jc->info = alloc_percpu(struct perf_cgroup_info); if (!jc->info) { kfree(jc); return ERR_PTR(-ENOMEM); } - for_each_possible_cpu(c) { - t = per_cpu_ptr(jc->info, c); - t->time = 0; - t->timestamp = 0; - } return &jc->css; } --1.6.3
Re: [PATCH 3/4] perf cgroup: Clean up perf_cgroup_create()
Ok,
I checked and yes, alloc_percpu() does return zeroed out memory. So the patch looks good to me.
Thanks.
Quoted 57 lines · Stephane Eranian
Li,
I have to NACK this patch or at least request more information.
The
for_each_possible_cpu()is initializing what's allocated viaalloc_percpu(),jc->infoand NOT jc.I don't think this gets zeroed by this allocator. But I could be wrong.
Quoted 44 lines · Li Zefan
- Use
kzalloc()to replacekmalloc()+memset().
- Remove redundant initialization, sincealloc_percpu()returns zero-filled percpu memory.Signed-off-by Li Zefan <[email protected]>---
kernel/perf_event.c | 11 +----------1 files changed, 1 insertions(+), 10 deletions(-)kernel/perf_event.c +1
-11@@ -7341,26 +7341,17 @@ static struct cgroup_subsys_state *perf_cgroup_create( struct cgroup_subsys *ss, struct cgroup *cont) { struct perf_cgroup *jc; - struct perf_cgroup_info *t; - int c; - jc = kmalloc(sizeof(*jc), GFP_KERNEL); + jc = kzalloc(sizeof(*jc), GFP_KERNEL); if (!jc) return ERR_PTR(-ENOMEM); - memset(jc, 0, sizeof(*jc)); - jc->info = alloc_percpu(struct perf_cgroup_info); if (!jc->info) { kfree(jc); return ERR_PTR(-ENOMEM); } - for_each_possible_cpu(c) { - t = per_cpu_ptr(jc->info, c); - t->time = 0; - t->timestamp = 0; - } return &jc->css; } --1.6.3
[tip:perf/core] perf cgroup: Clean up perf_cgroup_create()
In reply to Li ZefanCommit-ID: 1b15d0558e82df9b3659804ceb44187b98eda354 Gitweb: http://git.kernel.org/tip/1b15d0558e82df9b3659804ceb44187b98eda354 Author: Li Zefan <[email protected]> AuthorDate: Thu, 3 Mar 2011 14:26:06 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 4 Mar 2011 11:32:51 +0100
perf cgroup: Clean up perf_cgroup_create()
- Use kzalloc() to replace kmalloc() + memset().
- Remove redundant initialization, since alloc_percpu() returns zero-filled percpu memory.
LKML-Reference: <[email protected]>
--- kernel/perf_event.c | 11 +---------- 1 files changed, 1 insertions(+), 10 deletions(-)
kernel/perf_event.c +1 -10
@@ -7346,26 +7346,17 @@ static struct cgroup_subsys_state *perf_cgroup_create( struct cgroup_subsys *ss, struct cgroup *cont) { struct perf_cgroup *jc; -struct perf_cgroup_info *t; -int c; - jc =kmalloc (sizeof (*jc),GFP_KERNEL ); + jc =kzalloc (sizeof (*jc),GFP_KERNEL );if (!jc)return ERR_PTR (-ENOMEM ); -memset (jc,0 ,sizeof (*jc)); - jc->info = alloc_percpu(struct perf_cgroup_info);if (!jc->info) {kfree (jc);return ERR_PTR (-ENOMEM ); } -for_each_possible_cpu (c) { - t =per_cpu_ptr (jc->info, c); - t->time =0 ; - t->timestamp =0 ; - }return &jc->css; }
PATCH 4/4 perf cgroup: Fix a typo in kernel config
In reply to Li Zefans/specificied/specified
--- init/Kconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
init/Kconfig +1 -1
@@ -688,7 +688,7 @@ config CGROUP_PERF depends on PERF_EVENTS && CGROUPS help This option extends the per-cpu mode to restrict monitoring to - threads which belong to the cgroup specificied and run on the + threads which belong to the cgroup specified and run on the designated cpu. Say N if unsure.
Signature · 1 line
1.6.3
[tip:perf/core] perf cgroup: Fix a typo in kernel config
Commit-ID: 2d0f25201ee210a0666ec9c41538ba05a07f8bc6 Gitweb: http://git.kernel.org/tip/2d0f25201ee210a0666ec9c41538ba05a07f8bc6 Author: Li Zefan <[email protected]> AuthorDate: Thu, 3 Mar 2011 14:26:20 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 4 Mar 2011 11:32:51 +0100
perf cgroup: Fix a typo in kernel config
s/specificied/specified
LKML-Reference: <[email protected]>
--- init/Kconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
init/Kconfig +1 -1
@@ -688,7 +688,7 @@ config CGROUP_PERF depends on PERF_EVENTS && CGROUPS help This option extends the per-cpu mode to restrict monitoring to - threads which belong to the cgroup specificied and run on the + threads which belong to the cgroup specified and run on the designated cpu. Say N if unsure.
Quoted 3 lines · Li Zefan
In
perf_cgroup_connect(),fput_light()is missing in a failure path.
Yes, you're right.
Quoted 33 lines
Signed-off-by Li Zefan <[email protected]>---
kernel/perf_event.c | 7 +++++--1 files changed, 5 insertions(+), 2 deletions(-)kernel/perf_event.c +5
-3@@ -404,8 +404,10 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, return -EBADF; css = cgroup_css_from_dir(file, perf_subsys_id); - if (IS_ERR(css)) - return PTR_ERR(css); + if (IS_ERR(css)) { + ret = PTR_ERR(css); + goto out; + } cgrp = container_of(css, struct perf_cgroup, css); event->cgrp = cgrp;@@ -422,6 +424,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, /* must be done before we fput() the file */ perf_get_cgroup(event); } +out: fput_light(file, fput_needed); return ret; } --1.6.3
Applied all 4,
Thanks Li!
Commit-ID: 3db272c0494900fcb905a201180a78cae3addd6e Gitweb: http://git.kernel.org/tip/3db272c0494900fcb905a201180a78cae3addd6e Author: Li Zefan <[email protected]> AuthorDate: Thu, 3 Mar 2011 14:25:37 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 4 Mar 2011 11:32:50 +0100
perf cgroup: Fix leak of file reference count
In perf_cgroup_connect(), fput_light() is missing in a failure path.
LKML-Reference: <[email protected]>
--- kernel/perf_event.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
kernel/perf_event.c +5 -2
@@ -404,8 +404,10 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,return -EBADF ; css =cgroup_css_from_dir (file, perf_subsys_id); -if (IS_ERR (css)) -return PTR_ERR (css); +if (IS_ERR (css)) { + ret =PTR_ERR (css); + goto out; + } cgrp = container_of(css, struct perf_cgroup, css); event->cgrp = cgrp;
@@ -422,6 +424,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,/* must be done before we fput() the file */ perf_get_cgroup (event); } +out:fput_light (file, fput_needed);return ret; }