Message ID | 20220905193359.969347-3-toke@redhat.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | A couple of small refactorings of BPF program call sites | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Clearly marked for bpf-next, async |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/subject_prefix | success | Link |
netdev/cover_letter | success | Series has a cover letter |
netdev/patch_count | success | Link |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 1699 this patch: 1699 |
netdev/cc_maintainers | success | CCed 22 of 22 maintainers |
netdev/build_clang | success | Errors and warnings before: 173 this patch: 173 |
netdev/module_param | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/check_selftest | success | No net selftest shell script |
netdev/verify_fixes | success | No Fixes tag |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 1693 this patch: 1693 |
netdev/checkpatch | warning | WARNING: line length of 81 exceeds 80 columns WARNING: line length of 96 exceeds 80 columns |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
bpf/vmtest-bpf-next-PR | fail | PR summary |
bpf/vmtest-bpf-next-VM_Test-1 | success | Logs for build for s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-13 | success | Logs for test_progs_no_alu32 on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-16 | success | Logs for test_verifier on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-17 | success | Logs for test_verifier on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-10 | success | Logs for test_progs on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-11 | success | Logs for test_progs on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-14 | success | Logs for test_progs_no_alu32 on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-7 | success | Logs for test_maps on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-8 | success | Logs for test_maps on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-9 | fail | Logs for test_progs on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-12 | fail | Logs for test_progs_no_alu32 on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-15 | success | Logs for test_verifier on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-4 | success | Logs for llvm-toolchain |
bpf/vmtest-bpf-next-VM_Test-2 | success | Logs for build for x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-3 | success | Logs for build for x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-5 | success | Logs for llvm-toolchain |
bpf/vmtest-bpf-next-VM_Test-6 | success | Logs for set-matrix |
On Mon, Sep 5, 2022 at 12:34 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > > For queueing packets in XDP we want to add a new redirect map type with > support for 64-bit indexes. To prepare fore this, expand the width of the > 'key' argument to the bpf_redirect_map() helper. Since BPF registers are > always 64-bit, this should be safe to do after the fact. > > Reviewed-by: Stanislav Fomichev <sdf@google.com> > Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Acked-by: Song Liu <song@kernel.org> > --- > include/linux/bpf.h | 2 +- > include/linux/filter.h | 12 ++++++------ > include/uapi/linux/bpf.h | 2 +- > kernel/bpf/cpumap.c | 4 ++-- > kernel/bpf/devmap.c | 4 ++-- > kernel/bpf/verifier.c | 2 +- > net/core/filter.c | 4 ++-- > net/xdp/xskmap.c | 4 ++-- > 8 files changed, 17 insertions(+), 17 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 9c1674973e03..222cba23e6d9 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -134,7 +134,7 @@ struct bpf_map_ops { > struct bpf_local_storage __rcu ** (*map_owner_storage_ptr)(void *owner); > > /* Misc helpers.*/ > - int (*map_redirect)(struct bpf_map *map, u32 ifindex, u64 flags); > + int (*map_redirect)(struct bpf_map *map, u64 key, u64 flags); > > /* map_meta_equal must be implemented for maps that can be > * used as an inner map. It is a runtime check to ensure > diff --git a/include/linux/filter.h b/include/linux/filter.h > index 527ae1d64e27..eff295509f03 100644 > --- a/include/linux/filter.h > +++ b/include/linux/filter.h > @@ -637,13 +637,13 @@ struct bpf_nh_params { > }; > > struct bpf_redirect_info { > - u32 flags; > - u32 tgt_index; > + u64 tgt_index; > void *tgt_value; > struct bpf_map *map; > + u32 flags; > + u32 kern_flags; > u32 map_id; > enum bpf_map_type map_type; > - u32 kern_flags; > struct bpf_nh_params nh; > }; > > @@ -1493,7 +1493,7 @@ static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol, > } > #endif /* IS_ENABLED(CONFIG_IPV6) */ > > -static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u32 ifindex, > +static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u64 index, > u64 flags, const u64 flag_mask, > void *lookup_elem(struct bpf_map *map, u32 key)) > { > @@ -1504,7 +1504,7 @@ static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u32 ifind > if (unlikely(flags & ~(action_mask | flag_mask))) > return XDP_ABORTED; > > - ri->tgt_value = lookup_elem(map, ifindex); > + ri->tgt_value = lookup_elem(map, index); > if (unlikely(!ri->tgt_value) && !(flags & BPF_F_BROADCAST)) { > /* If the lookup fails we want to clear out the state in the > * redirect_info struct completely, so that if an eBPF program > @@ -1516,7 +1516,7 @@ static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u32 ifind > return flags & action_mask; > } > > - ri->tgt_index = ifindex; > + ri->tgt_index = index; > ri->map_id = map->id; > ri->map_type = map->map_type; > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > index 837c0f9b7fdd..c6d37ac2b87c 100644 > --- a/include/uapi/linux/bpf.h > +++ b/include/uapi/linux/bpf.h > @@ -2629,7 +2629,7 @@ union bpf_attr { > * Return > * 0 on success, or a negative error in case of failure. > * > - * long bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags) > + * long bpf_redirect_map(struct bpf_map *map, u64 key, u64 flags) > * Description > * Redirect the packet to the endpoint referenced by *map* at > * index *key*. Depending on its type, this *map* can contain > diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c > index b5ba34ddd4b6..39ed08a2bb52 100644 > --- a/kernel/bpf/cpumap.c > +++ b/kernel/bpf/cpumap.c > @@ -668,9 +668,9 @@ static int cpu_map_get_next_key(struct bpf_map *map, void *key, void *next_key) > return 0; > } > > -static int cpu_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) > +static int cpu_map_redirect(struct bpf_map *map, u64 index, u64 flags) > { > - return __bpf_xdp_redirect_map(map, ifindex, flags, 0, > + return __bpf_xdp_redirect_map(map, index, flags, 0, > __cpu_map_lookup_elem); > } > > diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c > index f9a87dcc5535..d01e4c55b376 100644 > --- a/kernel/bpf/devmap.c > +++ b/kernel/bpf/devmap.c > @@ -992,14 +992,14 @@ static int dev_map_hash_update_elem(struct bpf_map *map, void *key, void *value, > map, key, value, map_flags); > } > > -static int dev_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) > +static int dev_map_redirect(struct bpf_map *map, u64 ifindex, u64 flags) > { > return __bpf_xdp_redirect_map(map, ifindex, flags, > BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS, > __dev_map_lookup_elem); > } > > -static int dev_hash_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) > +static int dev_hash_map_redirect(struct bpf_map *map, u64 ifindex, u64 flags) > { > return __bpf_xdp_redirect_map(map, ifindex, flags, > BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS, > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 068b20ed34d2..844a44694b6f 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -14169,7 +14169,7 @@ static int do_misc_fixups(struct bpf_verifier_env *env) > BUILD_BUG_ON(!__same_type(ops->map_peek_elem, > (int (*)(struct bpf_map *map, void *value))NULL)); > BUILD_BUG_ON(!__same_type(ops->map_redirect, > - (int (*)(struct bpf_map *map, u32 ifindex, u64 flags))NULL)); > + (int (*)(struct bpf_map *map, u64 index, u64 flags))NULL)); > BUILD_BUG_ON(!__same_type(ops->map_for_each_callback, > (int (*)(struct bpf_map *map, > bpf_callback_t callback_fn, > diff --git a/net/core/filter.c b/net/core/filter.c > index ee768bb5b5ab..285eaee2b373 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -4408,10 +4408,10 @@ static const struct bpf_func_proto bpf_xdp_redirect_proto = { > .arg2_type = ARG_ANYTHING, > }; > > -BPF_CALL_3(bpf_xdp_redirect_map, struct bpf_map *, map, u32, ifindex, > +BPF_CALL_3(bpf_xdp_redirect_map, struct bpf_map *, map, u64, key, > u64, flags) > { > - return map->ops->map_redirect(map, ifindex, flags); > + return map->ops->map_redirect(map, key, flags); > } > > static const struct bpf_func_proto bpf_xdp_redirect_map_proto = { > diff --git a/net/xdp/xskmap.c b/net/xdp/xskmap.c > index acc8e52a4f5f..771d0fa90ef5 100644 > --- a/net/xdp/xskmap.c > +++ b/net/xdp/xskmap.c > @@ -231,9 +231,9 @@ static int xsk_map_delete_elem(struct bpf_map *map, void *key) > return 0; > } > > -static int xsk_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) > +static int xsk_map_redirect(struct bpf_map *map, u64 index, u64 flags) > { > - return __bpf_xdp_redirect_map(map, ifindex, flags, 0, > + return __bpf_xdp_redirect_map(map, index, flags, 0, > __xsk_map_lookup_elem); > } > > -- > 2.37.2 >
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 9c1674973e03..222cba23e6d9 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -134,7 +134,7 @@ struct bpf_map_ops { struct bpf_local_storage __rcu ** (*map_owner_storage_ptr)(void *owner); /* Misc helpers.*/ - int (*map_redirect)(struct bpf_map *map, u32 ifindex, u64 flags); + int (*map_redirect)(struct bpf_map *map, u64 key, u64 flags); /* map_meta_equal must be implemented for maps that can be * used as an inner map. It is a runtime check to ensure diff --git a/include/linux/filter.h b/include/linux/filter.h index 527ae1d64e27..eff295509f03 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -637,13 +637,13 @@ struct bpf_nh_params { }; struct bpf_redirect_info { - u32 flags; - u32 tgt_index; + u64 tgt_index; void *tgt_value; struct bpf_map *map; + u32 flags; + u32 kern_flags; u32 map_id; enum bpf_map_type map_type; - u32 kern_flags; struct bpf_nh_params nh; }; @@ -1493,7 +1493,7 @@ static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol, } #endif /* IS_ENABLED(CONFIG_IPV6) */ -static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u32 ifindex, +static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u64 index, u64 flags, const u64 flag_mask, void *lookup_elem(struct bpf_map *map, u32 key)) { @@ -1504,7 +1504,7 @@ static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u32 ifind if (unlikely(flags & ~(action_mask | flag_mask))) return XDP_ABORTED; - ri->tgt_value = lookup_elem(map, ifindex); + ri->tgt_value = lookup_elem(map, index); if (unlikely(!ri->tgt_value) && !(flags & BPF_F_BROADCAST)) { /* If the lookup fails we want to clear out the state in the * redirect_info struct completely, so that if an eBPF program @@ -1516,7 +1516,7 @@ static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u32 ifind return flags & action_mask; } - ri->tgt_index = ifindex; + ri->tgt_index = index; ri->map_id = map->id; ri->map_type = map->map_type; diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 837c0f9b7fdd..c6d37ac2b87c 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -2629,7 +2629,7 @@ union bpf_attr { * Return * 0 on success, or a negative error in case of failure. * - * long bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags) + * long bpf_redirect_map(struct bpf_map *map, u64 key, u64 flags) * Description * Redirect the packet to the endpoint referenced by *map* at * index *key*. Depending on its type, this *map* can contain diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index b5ba34ddd4b6..39ed08a2bb52 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -668,9 +668,9 @@ static int cpu_map_get_next_key(struct bpf_map *map, void *key, void *next_key) return 0; } -static int cpu_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) +static int cpu_map_redirect(struct bpf_map *map, u64 index, u64 flags) { - return __bpf_xdp_redirect_map(map, ifindex, flags, 0, + return __bpf_xdp_redirect_map(map, index, flags, 0, __cpu_map_lookup_elem); } diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index f9a87dcc5535..d01e4c55b376 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -992,14 +992,14 @@ static int dev_map_hash_update_elem(struct bpf_map *map, void *key, void *value, map, key, value, map_flags); } -static int dev_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) +static int dev_map_redirect(struct bpf_map *map, u64 ifindex, u64 flags) { return __bpf_xdp_redirect_map(map, ifindex, flags, BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS, __dev_map_lookup_elem); } -static int dev_hash_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) +static int dev_hash_map_redirect(struct bpf_map *map, u64 ifindex, u64 flags) { return __bpf_xdp_redirect_map(map, ifindex, flags, BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS, diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 068b20ed34d2..844a44694b6f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14169,7 +14169,7 @@ static int do_misc_fixups(struct bpf_verifier_env *env) BUILD_BUG_ON(!__same_type(ops->map_peek_elem, (int (*)(struct bpf_map *map, void *value))NULL)); BUILD_BUG_ON(!__same_type(ops->map_redirect, - (int (*)(struct bpf_map *map, u32 ifindex, u64 flags))NULL)); + (int (*)(struct bpf_map *map, u64 index, u64 flags))NULL)); BUILD_BUG_ON(!__same_type(ops->map_for_each_callback, (int (*)(struct bpf_map *map, bpf_callback_t callback_fn, diff --git a/net/core/filter.c b/net/core/filter.c index ee768bb5b5ab..285eaee2b373 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4408,10 +4408,10 @@ static const struct bpf_func_proto bpf_xdp_redirect_proto = { .arg2_type = ARG_ANYTHING, }; -BPF_CALL_3(bpf_xdp_redirect_map, struct bpf_map *, map, u32, ifindex, +BPF_CALL_3(bpf_xdp_redirect_map, struct bpf_map *, map, u64, key, u64, flags) { - return map->ops->map_redirect(map, ifindex, flags); + return map->ops->map_redirect(map, key, flags); } static const struct bpf_func_proto bpf_xdp_redirect_map_proto = { diff --git a/net/xdp/xskmap.c b/net/xdp/xskmap.c index acc8e52a4f5f..771d0fa90ef5 100644 --- a/net/xdp/xskmap.c +++ b/net/xdp/xskmap.c @@ -231,9 +231,9 @@ static int xsk_map_delete_elem(struct bpf_map *map, void *key) return 0; } -static int xsk_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) +static int xsk_map_redirect(struct bpf_map *map, u64 index, u64 flags) { - return __bpf_xdp_redirect_map(map, ifindex, flags, 0, + return __bpf_xdp_redirect_map(map, index, flags, 0, __xsk_map_lookup_elem); }