• K Prateek Nayak's avatar
    drivers: base: cacheinfo: Update cpu_map_populated during CPU Hotplug · c26fabe7
    K Prateek Nayak authored
    Until commit 5c271238 ("cacheinfo: Fix LLC is not exported through
    sysfs"), cacheinfo called populate_cache_leaves() for CPU coming online
    which let the arch specific functions handle (at least on x86)
    populating the shared_cpu_map. However, with the changes in the
    aforementioned commit, populate_cache_leaves() is not called when a CPU
    comes online as a result of hotplug since last_level_cache_is_valid()
    returns true as the cacheinfo data is not discarded. The CPU coming
    online is not present in shared_cpu_map, however, it will not be added
    since the cpu_cacheinfo->cpu_map_populated flag is set (it is set in
    populate_cache_leaves() when cacheinfo is first populated for x86)
    
    This can lead to inconsistencies in the shared_cpu_map when an offlined
    CPU comes online again. Example below depicts the inconsistency in the
    shared_cpu_list in cacheinfo when CPU8 is offlined and onlined again on
    a 3rd Generation EPYC processor:
    
      # for i in /sys/devices/system/cpu/cpu8/cache/index*/shared_cpu_list; do echo -n "$i: "; cat $i; done
        /sys/devices/system/cpu/cpu8/cache/index0/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index1/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index2/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index3/shared_cpu_list: 8-15,136-143
    
      # echo 0 > /sys/devices/system/cpu/cpu8/online
      # echo 1 > /sys/devices/system/cpu/cpu8/online
    
      # for i in /sys/devices/system/cpu/cpu8/cache/index*/shared_cpu_list; do echo -n "$i: "; cat $i; done
        /sys/devices/system/cpu/cpu8/cache/index0/shared_cpu_list: 8
        /sys/devices/system/cpu/cpu8/cache/index1/shared_cpu_list: 8
        /sys/devices/system/cpu/cpu8/cache/index2/shared_cpu_list: 8
        /sys/devices/system/cpu/cpu8/cache/index3/shared_cpu_list: 8
    
      # cat /sys/devices/system/cpu/cpu136/cache/index0/shared_cpu_list
        136
    
      # cat /sys/devices/system/cpu/cpu136/cache/index3/shared_cpu_list
        9-15,136-143
    
    Clear the flag when the CPU is removed from shared_cpu_map when
    cache_shared_cpu_map_remove() is called during CPU hotplug. This will
    allow cache_shared_cpu_map_setup() to add the CPU coming back online in
    the shared_cpu_map. Set the flag again when the shared_cpu_map is setup.
    Following are results of performing the same test as described above with
    the changes:
    
      # for i in /sys/devices/system/cpu/cpu8/cache/index*/shared_cpu_list; do echo -n "$i: "; cat $i; done
        /sys/devices/system/cpu/cpu8/cache/index0/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index1/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index2/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index3/shared_cpu_list: 8-15,136-143
    
      # echo 0 > /sys/devices/system/cpu/cpu8/online
      # echo 1 > /sys/devices/system/cpu/cpu8/online
    
      # for i in /sys/devices/system/cpu/cpu8/cache/index*/shared_cpu_list; do echo -n "$i: "; cat $i; done
        /sys/devices/system/cpu/cpu8/cache/index0/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index1/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index2/shared_cpu_list: 8,136
        /sys/devices/system/cpu/cpu8/cache/index3/shared_cpu_list: 8-15,136-143
    
      # cat /sys/devices/system/cpu/cpu136/cache/index0/shared_cpu_list
        8,136
    
      # cat /sys/devices/system/cpu/cpu136/cache/index3/shared_cpu_list
        8-15,136-143
    
    Fixes: 5c271238 ("cacheinfo: Fix LLC is not exported through sysfs")
    Signed-off-by: default avatarK Prateek Nayak <kprateek.nayak@amd.com>
    Reviewed-by: default avatarYicong Yang <yangyicong@hisilicon.com>
    Reviewed-by: default avatarSudeep Holla <sudeep.holla@arm.com>
    Link: https://lore.kernel.org/r/20230508084115.1157-3-kprateek.nayak@amd.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    c26fabe7
cacheinfo.c 23.1 KB