perf test code-reading: Fix duplicate kernel maps and machine leak
Ian Rogers
reviewerPATCH 1/1 perf test code-reading: Fix duplicate kernel maps and machine leak
In do_test_code_reading(), machine__new_host(&host_env) already calls machine__create_kernel_maps(machine). Calling machine__create_kernel_maps(machine) a second time immediately afterwards duplicates all kernel module maps in machine->kmaps, causing dso__load_kcore()'s module validation (do_validate_kcore_modules()) to fail and fall back to /proc/kallsyms.
Furthermore, when try_kcore is true and !have_kcore, returning TEST_CODE_READING_NO_KCORE directly bypasses out_err, leaking the entire struct machine, its kernel/module maps and DSOs, all kallsyms symbols, and host_env.
Remove the redundant machine__create_kernel_maps() call, check for !machine after machine__new_host(), and jump to out_err when returning TEST_CODE_READING_NO_KCORE.
--- tools/perf/tests/code-reading.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/tests/code-reading.c +6 -6
@@ -716,10 +716,8 @@ static int do_test_code_reading(bool try_kcore)perf_env__init (&host_env); machine =machine__new_host (&host_env); - - ret =machine__create_kernel_maps (machine); -if (ret <0 ) { -pr_debug ("machine__create_kernel_maps failed\n" ); +if (!machine) { +pr_debug ("machine__new_host failed\n" ); goto out_err; }
@@ -739,8 +737,10 @@ static int do_test_code_reading(bool try_kcore) have_kcore =dso__is_kcore (dso);/* 2nd time through we just try kcore */ -if (try_kcore && !have_kcore) -return TEST_CODE_READING_NO_KCORE ; +if (try_kcore && !have_kcore) { + err =TEST_CODE_READING_NO_KCORE ; + goto out_err; + }/* No point getting kernel events if there is no kernel object */ if (!have_vmlinux && !have_kcore)
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 12 lines
In
do_test_code_reading(),machine__new_host(&host_env)already callsmachine__create_kernel_maps(machine). Callingmachine__create_kernel_maps(machine)a second time immediately afterwards duplicates all kernel module maps inmachine->kmaps, causing dso__load_kcore()'s module validation (do_validate_kcore_modules()) to fail and fall back to/proc/kallsyms.Furthermore, when
try_kcoreis true and !have_kcore, returningTEST_CODE_READING_NO_KCOREdirectly bypassesout_err, leaking the entire struct machine, its kernel/module maps and DSOs, all kallsyms symbols, andhost_env.
Quoted 7 lines
Remove the redundant
machine__create_kernel_maps()call, check for !machine aftermachine__new_host(), and jump toout_errwhen returningTEST_CODE_READING_NO_KCORE.Fixes 0fd4008ed755 ("perf test: Use machine__new_host in mmap thread code reading test")Assisted-by Antigravity:gemini-3.1-proSigned-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 11 lines · Ian Rogers
Furthermore, when
try_kcoreis true and !have_kcore, returningTEST_CODE_READING_NO_KCOREdirectly bypassesout_err, leaking the entire struct machine, its kernel/module maps and DSOs, all kallsyms symbols, andhost_env.Remove the redundant
machine__create_kernel_maps()call, check for !machine aftermachine__new_host(), and jump toout_errwhen returningTEST_CODE_READING_NO_KCORE.Fixes 0fd4008ed755 ("perf test: Use machine__new_host in mmap thread code reading test")Assisted-by Antigravity:gemini-3.1-pro
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo