bpf: Remove BPF_MAP_OFF_ARR_MAX
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Mon, 14 Nov 2022 19:15:23 +0000 (00:45 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 15 Nov 2022 05:52:45 +0000 (21:52 -0800)
In f71b2f64177a ("bpf: Refactor map->off_arr handling"), map->off_arr
was refactored to be btf_field_offs. The number of field offsets is
equal to maximum possible fields limited by BTF_FIELDS_MAX. Hence, reuse
BTF_FIELDS_MAX as spin_lock and timer no longer are to be handled
specially for offset sorting, fix the comment, and remove incorrect
WARN_ON as its rec->cnt can never exceed this value. The reason to keep
separate constant was the it was always more 2 more than total kptrs.
This is no longer the case.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20221114191547.1694267-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/btf.c

index 798aec816970a42f83abc2efe6a3dcc9af7e0e78..1a66a1df1af16afaa7cd88c9bb961dae9d4b0287 100644 (file)
@@ -165,9 +165,8 @@ struct bpf_map_ops {
 };
 
 enum {
-       /* Support at most 8 pointers in a BTF type */
-       BTF_FIELDS_MAX        = 10,
-       BPF_MAP_OFF_ARR_MAX   = BTF_FIELDS_MAX,
+       /* Support at most 10 fields in a BTF type */
+       BTF_FIELDS_MAX     = 10,
 };
 
 enum btf_field_type {
@@ -203,8 +202,8 @@ struct btf_record {
 
 struct btf_field_offs {
        u32 cnt;
-       u32 field_off[BPF_MAP_OFF_ARR_MAX];
-       u8 field_sz[BPF_MAP_OFF_ARR_MAX];
+       u32 field_off[BTF_FIELDS_MAX];
+       u8 field_sz[BTF_FIELDS_MAX];
 };
 
 struct bpf_map {
index 5579ff3a5b54c81a55924b884b4192372c5c9c71..12361d7b24987b6a491763a07a5de2e3e98839d1 100644 (file)
@@ -3584,7 +3584,7 @@ struct btf_field_offs *btf_parse_field_offs(struct btf_record *rec)
        u8 *sz;
 
        BUILD_BUG_ON(ARRAY_SIZE(foffs->field_off) != ARRAY_SIZE(foffs->field_sz));
-       if (IS_ERR_OR_NULL(rec) || WARN_ON_ONCE(rec->cnt > sizeof(foffs->field_off)))
+       if (IS_ERR_OR_NULL(rec))
                return NULL;
 
        foffs = kzalloc(sizeof(*foffs), GFP_KERNEL | __GFP_NOWARN);