Re: [PATCH] perf/x86/intel: Fix minor memleak on Skylake perf initialization
On Wed, 27 Dec 2017, Andi Kleen wrote: > From: Andi KleenFixed that yesterday already slightly different.
Re: [PATCH] perf/x86/intel: Fix minor memleak on Skylake perf initialization
On Wed, 27 Dec 2017, Andi Kleen wrote: > From: Andi Kleen Fixed that yesterday already slightly different.
[PATCH] perf/x86/intel: Fix minor memleak on Skylake perf initialization
From: Andi KleenTommi reports: I'm seeing this kmemleak report in v4.15-rc4: unreferenced object 0x8801f3d5d720 (size 64): comm "swapper/0", pid 1, jiffies 4294667312 (age 2687.423s) hex dump (first 32 bytes): 60 d1 41 ad ff ff ff ff 20 d1 41 ad ff ff ff ff `.A. .A. 80 d0 41 ad ff ff ff ff 40 d0 41 ad ff ff ff ff ..A.@.A. backtrace: [ ] intel_pmu_init+0x1844/0x1d38 [ ] init_hw_perf_events+0x8c/0x66f [ ] do_one_initcall+0x7b/0x1d0 [<8ee1f02a>] kernel_init_freeable+0x163/0x2f9 [ ] kernel_init+0xf/0x120 [<38a99264>] ret_from_fork+0x24/0x30 [ ] 0x $ ./scripts/faddr2line vmlinux intel_pmu_init+0x1844/0x1d38 intel_pmu_init+0x1844/0x1d38: intel_pmu_init at arch/x86/events/intel/core.c:4296 Which matches line: extra_attr = merge_attr(extra_attr, skl_format_attr); So looks like "extra_attr" is leaked here. Free the attribute in this case. Reported-by: Tommi Rantala Cc: Tommi Rantala Fixes: a5df70c354c26 ( perf/x86: Only show format attributes) Signed-off-by: Andi Kleen --- arch/x86/events/intel/core.c | 4 1 file changed, 4 insertions(+) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 09c26a4f139c..71321f48e1e6 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3855,6 +3855,7 @@ __init int intel_pmu_init(void) struct extra_reg *er; int version, i; struct attribute **extra_attr = NULL; + bool extra_attr_allocated = false; char *name; if (!cpu_has(_cpu_data, X86_FEATURE_ARCH_PERFMON)) { @@ -4294,6 +4295,7 @@ __init int intel_pmu_init(void) extra_attr = boot_cpu_has(X86_FEATURE_RTM) ? hsw_format_attr : nhm_format_attr; extra_attr = merge_attr(extra_attr, skl_format_attr); + extra_attr_allocated = true; x86_pmu.cpu_events = get_hsw_events_attrs(); intel_pmu_pebs_data_source_skl( boot_cpu_data.x86_model == INTEL_FAM6_SKYLAKE_X); @@ -4324,6 +4326,8 @@ __init int intel_pmu_init(void) if (version >= 2 && extra_attr) { x86_pmu.format_attrs = merge_attr(intel_arch3_formats_attr, extra_attr); + if (extra_attr_allocated) + kfree(extra_attr); WARN_ON(!x86_pmu.format_attrs); } -- 2.14.3
[PATCH] perf/x86/intel: Fix minor memleak on Skylake perf initialization
From: Andi Kleen Tommi reports: I'm seeing this kmemleak report in v4.15-rc4: unreferenced object 0x8801f3d5d720 (size 64): comm "swapper/0", pid 1, jiffies 4294667312 (age 2687.423s) hex dump (first 32 bytes): 60 d1 41 ad ff ff ff ff 20 d1 41 ad ff ff ff ff `.A. .A. 80 d0 41 ad ff ff ff ff 40 d0 41 ad ff ff ff ff ..A.@.A. backtrace: [] intel_pmu_init+0x1844/0x1d38 [ ] init_hw_perf_events+0x8c/0x66f [ ] do_one_initcall+0x7b/0x1d0 [<8ee1f02a>] kernel_init_freeable+0x163/0x2f9 [ ] kernel_init+0xf/0x120 [<38a99264>] ret_from_fork+0x24/0x30 [ ] 0x $ ./scripts/faddr2line vmlinux intel_pmu_init+0x1844/0x1d38 intel_pmu_init+0x1844/0x1d38: intel_pmu_init at arch/x86/events/intel/core.c:4296 Which matches line: extra_attr = merge_attr(extra_attr, skl_format_attr); So looks like "extra_attr" is leaked here. Free the attribute in this case. Reported-by: Tommi Rantala Cc: Tommi Rantala Fixes: a5df70c354c26 ( perf/x86: Only show format attributes) Signed-off-by: Andi Kleen --- arch/x86/events/intel/core.c | 4 1 file changed, 4 insertions(+) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 09c26a4f139c..71321f48e1e6 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3855,6 +3855,7 @@ __init int intel_pmu_init(void) struct extra_reg *er; int version, i; struct attribute **extra_attr = NULL; + bool extra_attr_allocated = false; char *name; if (!cpu_has(_cpu_data, X86_FEATURE_ARCH_PERFMON)) { @@ -4294,6 +4295,7 @@ __init int intel_pmu_init(void) extra_attr = boot_cpu_has(X86_FEATURE_RTM) ? hsw_format_attr : nhm_format_attr; extra_attr = merge_attr(extra_attr, skl_format_attr); + extra_attr_allocated = true; x86_pmu.cpu_events = get_hsw_events_attrs(); intel_pmu_pebs_data_source_skl( boot_cpu_data.x86_model == INTEL_FAM6_SKYLAKE_X); @@ -4324,6 +4326,8 @@ __init int intel_pmu_init(void) if (version >= 2 && extra_attr) { x86_pmu.format_attrs = merge_attr(intel_arch3_formats_attr, extra_attr); + if (extra_attr_allocated) + kfree(extra_attr); WARN_ON(!x86_pmu.format_attrs); } -- 2.14.3