• Dave Martin's avatar
    x86/resctrl: Don't try to free nonexistent RMIDs · 739c9765
    Dave Martin authored
    Commit
    
      6791e0ea ("x86/resctrl: Access per-rmid structures by index")
    
    adds logic to map individual monitoring groups into a global index space used
    for tracking allocated RMIDs.
    
    Attempts to free the default RMID are ignored in free_rmid(), and this works
    fine on x86.
    
    With arm64 MPAM, there is a latent bug here however: on platforms with no
    monitors exposed through resctrl, each control group still gets a different
    monitoring group ID as seen by the hardware, since the CLOSID always forms part
    of the monitoring group ID.
    
    This means that when removing a control group, the code may try to free this
    group's default monitoring group RMID for real.  If there are no monitors
    however, the RMID tracking table rmid_ptrs[] would be a waste of memory and is
    never allocated, leading to a splat when free_rmid() tries to dereference the
    table.
    
    One option would be to treat RMID 0 as special for every CLOSID, but this would
    be ugly since bookkeeping still needs to be done for these monitoring group IDs
    when there are monitors present in the hardware.
    
    Instead, add a gating check of resctrl_arch_mon_capable() in free_rmid(), and
    just do nothing if the hardware doesn't have monitors.
    
    This fix mirrors the gating checks already present in
    mkdir_rdt_prepare_rmid_alloc() and elsewhere.
    
    No functional change on x86.
    
      [ bp: Massage commit message. ]
    
    Fixes: 6791e0ea ("x86/resctrl: Access per-rmid structures by index")
    Signed-off-by: default avatarDave Martin <Dave.Martin@arm.com>
    Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
    Tested-by: default avatarReinette Chatre <reinette.chatre@intel.com>
    Link: https://lore.kernel.org/r/20240618140152.83154-1-Dave.Martin@arm.com
    739c9765
monitor.c 29.9 KB