• Arnaldo Carvalho de Melo's avatar
    perf map: Set kmap->kmaps backpointer for main kernel map chunks · a75af86b
    Arnaldo Carvalho de Melo authored
    When a map is create to represent the main kernel area (vmlinux) with
    map__new2() we allocate an extra area to store a pointer to the 'struct
    maps' for the kernel maps, so that we can access that struct when
    loading ELF files or kallsyms, as we will need to split it in multiple
    maps, one per kernel module or ELF section (such as ".init.text").
    
    So when map->dso->kernel is non-zero, it is expected that
    map__kmap(map)->kmaps to be set to the tree of kernel maps (modules,
    chunks of the main kernel, bpf progs put in place via
    PERF_RECORD_KSYMBOL, the main kernel).
    
    This was not the case when we were splitting the main kernel into chunks
    for its ELF sections, which ended up making 'perf report --children'
    processing a perf.data file with callchains to trip on
    __map__is_kernel(), when we press ENTER to see the popup menu for main
    histogram entries that starts at a symbol in the ".init.text" ELF
    section, e.g.:
    
    -    8.83%     0.00%  swapper     [kernel.vmlinux].init.text  [k] start_kernel
         start_kernel
         cpu_startup_entry
         do_idle
         cpuidle_enter
         cpuidle_enter_state
         intel_idle
    
    Fix it.
    Reviewed-by: default avatarJiri Olsa <jolsa@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/lkml/20191218190120.GB13282@kernel.org/Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    a75af86b
symbol-elf.c 51.6 KB