• Rhys Rustad-Elliott's avatar
    bpf: Fix elem_size not being set for inner maps · cba41bb7
    Rhys Rustad-Elliott authored
    Commit d937bc34 ("bpf: make uniform use of array->elem_size
    everywhere in arraymap.c") changed array_map_gen_lookup to use
    array->elem_size instead of round_up(map->value_size, 8) as the element
    size when generating code to access a value in an array map.
    
    array->elem_size, however, is not set by bpf_map_meta_alloc when
    initializing an BPF_MAP_TYPE_ARRAY_OF_MAPS or BPF_MAP_TYPE_HASH_OF_MAPS.
    This results in array_map_gen_lookup incorrectly outputting code that
    always accesses index 0 in the array (as the index will be calculated
    via a multiplication with the element size, which is incorrectly set to
    0).
    
    Set elem_size on the bpf_array object when allocating an array or hash
    of maps to fix this.
    
    Fixes: d937bc34 ("bpf: make uniform use of array->elem_size everywhere in arraymap.c")
    Signed-off-by: default avatarRhys Rustad-Elliott <me@rhysre.net>
    Link: https://lore.kernel.org/r/20230602190110.47068-2-me@rhysre.netSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
    cba41bb7
map_in_map.c 3.57 KB