Most of the maps do not use max_entries during verification time. Thus, those map_meta_equal() do not need to enforce max_entries when it is inserted as an inner map during runtime. The max_entries check is removed from the default implementation bpf_map_meta_equal(). The prog_array_map and xsk_map are exception. Its map_gen_lookup uses max_entries to generate inline lookup code. Thus, they will implement its own map_meta_equal() to enforce max_entries. Since there are only two cases now, the max_entries check is not refactored and stays in its own .c file.
Unified · Split
| @@ -487,6 +487,13 @@ static int array_map_mmap(struct bpf_map *map, struct vm_area_struct *vma) · 486 unmodified lines | |||
| 487 | vma->vm_pgoff + pgoff); | 487 | vma->vm_pgoff + pgoff); |
| 488 | } | 488 | } |
| 489 | 489 | ||
| 490 | static bool array_map_meta_equal(const struct bpf_map *meta0, | ||
| 491 | const struct bpf_map *meta1) | ||
| 492 | { | ||
| 493 | return meta0->max_entries == meta1->max_entries && | ||
| 494 | bpf_map_meta_equal(meta0, meta1); | ||
| 495 | } | ||
| 496 | |||
| 490 | struct bpf_iter_seq_array_map_info { | 497 | struct bpf_iter_seq_array_map_info { |
| 491 | struct bpf_map *map; | 498 | struct bpf_map *map; |
| 492 | void *percpu_value_buf; | 499 | void *percpu_value_buf; |
| @@ -625,7 +632,7 @@ static const struct bpf_iter_seq_info iter_seq_info = { · 132 unmodified lines | |||
| 625 | 632 | ||
| 626 | static int array_map_btf_id; | 633 | static int array_map_btf_id; |
| 627 | const struct bpf_map_ops array_map_ops = { | 634 | const struct bpf_map_ops array_map_ops = { |
| 628 | .map_meta_equal = bpf_map_meta_equal, | 635 | .map_meta_equal = array_map_meta_equal, |
| 629 | .map_alloc_check = array_map_alloc_check, | 636 | .map_alloc_check = array_map_alloc_check, |
| 630 | .map_alloc = array_map_alloc, | 637 | .map_alloc = array_map_alloc, |
| 631 | .map_free = array_map_free, | 638 | .map_free = array_map_free, |
| @@ -75,8 +75,7 @@ bool bpf_map_meta_equal(const struct bpf_map *meta0, · 74 unmodified lines | |||
| 75 | return meta0->map_type == meta1->map_type && | 75 | return meta0->map_type == meta1->map_type && |
| 76 | meta0->key_size == meta1->key_size && | 76 | meta0->key_size == meta1->key_size && |
| 77 | meta0->value_size == meta1->value_size && | 77 | meta0->value_size == meta1->value_size && |
| 78 | meta0->map_flags == meta1->map_flags && | 78 | meta0->map_flags == meta1->map_flags; |
| 79 | meta0->max_entries == meta1->max_entries; | ||
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | void *bpf_map_fd_get_ptr(struct bpf_map *map, | 81 | void *bpf_map_fd_get_ptr(struct bpf_map *map, |
| @@ -254,9 +254,16 @@ void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs, · 253 unmodified lines | |||
| 254 | spin_unlock_bh(&map->lock); | 254 | spin_unlock_bh(&map->lock); |
| 255 | } | 255 | } |
| 256 | 256 | ||
| 257 | static bool xsk_map_meta_equal(const struct bpf_map *meta0, | ||
| 258 | const struct bpf_map *meta1) | ||
| 259 | { | ||
| 260 | return meta0->max_entries == meta1->max_entries && | ||
| 261 | bpf_map_meta_equal(meta0, meta1); | ||
| 262 | } | ||
| 263 | |||
| 257 | static int xsk_map_btf_id; | 264 | static int xsk_map_btf_id; |
| 258 | const struct bpf_map_ops xsk_map_ops = { | 265 | const struct bpf_map_ops xsk_map_ops = { |
| 259 | .map_meta_equal = bpf_map_meta_equal, | 266 | .map_meta_equal = xsk_map_meta_equal, |
| 260 | .map_alloc = xsk_map_alloc, | 267 | .map_alloc = xsk_map_alloc, |
| 261 | .map_free = xsk_map_free, | 268 | .map_free = xsk_map_free, |
| 262 | .map_get_next_key = xsk_map_get_next_key, | 269 | .map_get_next_key = xsk_map_get_next_key, |