Skip to content
Snippets Groups Projects
Commit 0cdda9f8 authored by Mamatha Inamdar's avatar Mamatha Inamdar
Browse files

arch/powerpc/perf: Check the instruction type before creating sample with perf_mem_data_src

JIRA: https://issues.redhat.com/browse/RHEL-80602



commit 2ffb26afa64261139e608bf087a0c1fe24d76d4d
Author: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Date:   Tue Jan 21 18:46:20 2025 +0530

    arch/powerpc/perf: Check the instruction type before creating sample with perf_mem_data_src

    perf mem report aborts as below sometimes (during some corner
    case) in powerpc:

       # ./perf mem report 1>out
       *** stack smashing detected ***: terminated
       Aborted (core dumped)

    The backtrace is as below:
       __pthread_kill_implementation ()
       raise ()
       abort ()
       __libc_message
       __fortify_fail
       __stack_chk_fail
       hist_entry.lvl_snprintf
       __sort__hpp_entry
       __hist_entry__snprintf
       hists.fprintf
       cmd_report
       cmd_mem

    Snippet of code which triggers the issue
    from tools/perf/util/sort.c

       static int hist_entry__lvl_snprintf(struct hist_entry *he, char *bf,
                                        size_t size, unsigned int width)
       {
            char out[64];

            perf_mem__lvl_scnprintf(out, sizeof(out), he->mem_info);
            return repsep_snprintf(bf, size, "%-*s", width, out);
       }

    The value of "out" is filled from perf_mem_data_src value.
    Debugging this further showed that for some corner cases, the
    value of "data_src" was pointing to wrong value. This resulted
    in bigger size of string and causing stack check fail.

    The perf mem data source values are captured in the sample via
    isa207_get_mem_data_src function. The initial check is to fetch
    the type of sampled instruction. If the type of instruction is
    not valid (not a load/store instruction), the function returns.

    Since 'commit e16fd7f2cb1a ("perf: Use sample_flags for data_src")',
    data_src field is not initialized by the perf_sample_data_init()
    function. If the PMU driver doesn't set the data_src value to zero if
    type is not valid, this will result in uninitailised value for data_src.
    The uninitailised value of data_src resulted in stack check fail
    followed by abort for "perf mem report".

    When requesting for data source information in the sample, the
    instruction type is expected to be load or store instruction.
    In ISA v3.0, due to hardware limitation, there are corner cases
    where the instruction type other than load or store is observed.
    In ISA v3.0 and before values "0" and "7" are considered reserved.
    In ISA v3.1, value "7" has been used to indicate "larx/stcx".
    Drop the sample if instruction type has reserved values for this
    field with a ISA version check. Initialize data_src to zero in
    isa207_get_mem_data_src if the instruction type is not load/store.

Reported-by: default avatarDisha Goel <disgoel@linux.vnet.ibm.com>
Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: default avatarMadhavan Srinivasan <maddy@linux.ibm.com>
    Link: https://patch.msgid.link/20250121131621.39054-1-atrajeev@linux.vnet.ibm.com



Signed-off-by: default avatarMamatha Inamdar <minamdar@redhat.com>
parent 15b5887e
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment