• Thomas Richter's avatar
    s390/cpum_sf: Check for SDBT and SDB consistency · a06124a3
    Thomas Richter authored
    BugLink: https://bugs.launchpad.net/bugs/1858462
    
    [ Upstream commit 247f265f ]
    
    Each SBDT is located at a 4KB page and contains 512 entries.
    Each entry of a SDBT points to a SDB, a 4KB page containing
    sampled data. The last entry is a link to another SDBT page.
    
    When an event is created the function sequence executed is:
    
      __hw_perf_event_init()
      +--> allocate_buffers()
           +--> realloc_sampling_buffers()
    	    +---> alloc_sample_data_block()
    
    Both functions realloc_sampling_buffers() and
    alloc_sample_data_block() allocate pages and the allocation
    can fail. This is handled correctly and all allocated
    pages are freed and error -ENOMEM is returned to the
    top calling function. Finally the event is not created.
    
    Once the event has been created, the amount of initially
    allocated SDBT and SDB can be too low. This is detected
    during measurement interrupt handling, where the amount
    of lost samples is calculated. If the number of lost samples
    is too high considering sampling frequency and already allocated
    SBDs, the number of SDBs is enlarged during the next execution
    of cpumsf_pmu_enable().
    
    If more SBDs need to be allocated, functions
    
           realloc_sampling_buffers()
           +---> alloc-sample_data_block()
    
    are called to allocate more pages. Page allocation may fail
    and the returned error is ignored. A SDBT and SDB setup
    already exists.
    
    However the modified SDBTs and SDBs might end up in a situation
    where the first entry of an SDBT does not point to an SDB,
    but another SDBT, basicly an SBDT without payload.
    This can not be handled by the interrupt handler, where an SDBT
    must have at least one entry pointing to an SBD.
    
    Add a check to avoid SDBTs with out payload (SDBs) when enlarging
    the buffer setup.
    Signed-off-by: default avatarThomas Richter <tmricht@linux.ibm.com>
    Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
    Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
    a06124a3
perf_cpum_sf.c 46.2 KB