From mboxrd@z Thu Jan 1 00:00:00 1970 From: Y Song Subject: Re: [PATCH bpf-next v6 2/4] bpf: sockmap, add hash map support Date: Tue, 15 May 2018 14:09:52 -0700 Message-ID: References: <1526317219-7752-1-git-send-email-john.fastabend@gmail.com> <1526317219-7752-3-git-send-email-john.fastabend@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Cc: John Fastabend , Alexei Starovoitov , netdev , David Miller To: Daniel Borkmann Return-path: Received: from mail-ua0-f193.google.com ([209.85.217.193]:39958 "EHLO mail-ua0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752389AbeEOVKd (ORCPT ); Tue, 15 May 2018 17:10:33 -0400 Received: by mail-ua0-f193.google.com with SMTP id g9-v6so1131300uak.7 for ; Tue, 15 May 2018 14:10:33 -0700 (PDT) In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: On Tue, May 15, 2018 at 12:01 PM, Daniel Borkmann wrote: > On 05/14/2018 07:00 PM, John Fastabend wrote: >> Sockmap is currently backed by an array and enforces keys to be >> four bytes. This works well for many use cases and was originally >> modeled after devmap which also uses four bytes keys. However, >> this has become limiting in larger use cases where a hash would >> be more appropriate. For example users may want to use the 5-tuple >> of the socket as the lookup key. >> >> To support this add hash support. >> >> Signed-off-by: John Fastabend >> Acked-by: David S. Miller >> --- >> include/linux/bpf.h | 8 + >> include/linux/bpf_types.h | 1 + >> include/uapi/linux/bpf.h | 52 ++++- >> kernel/bpf/core.c | 1 + >> kernel/bpf/sockmap.c | 494 ++++++++++++++++++++++++++++++++++++++++++++-- >> kernel/bpf/verifier.c | 14 +- >> net/core/filter.c | 58 ++++++ >> 7 files changed, 610 insertions(+), 18 deletions(-) >> >> diff --git a/include/linux/bpf.h b/include/linux/bpf.h >> index a38e474..ed0122b 100644 >> --- a/include/linux/bpf.h >> +++ b/include/linux/bpf.h >> @@ -668,6 +668,7 @@ static inline void bpf_map_offload_map_free(struct bpf_map *map) >> >> #if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_INET) >> struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key); >> +struct sock *__sock_hash_lookup_elem(struct bpf_map *map, void *key); >> int sock_map_prog(struct bpf_map *map, struct bpf_prog *prog, u32 type); >> #else >> static inline struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key) >> @@ -675,6 +676,12 @@ static inline struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key) >> return NULL; >> } >> >> +static inline struct sock *__sock_hash_lookup_elem(struct bpf_map *map, >> + void *key) >> +{ >> + return NULL; >> +} >> + >> static inline int sock_map_prog(struct bpf_map *map, >> struct bpf_prog *prog, >> u32 type) >> @@ -724,6 +731,7 @@ static inline void __xsk_map_flush(struct bpf_map *map) >> extern const struct bpf_func_proto bpf_get_stackid_proto; >> extern const struct bpf_func_proto bpf_get_stack_proto; >> extern const struct bpf_func_proto bpf_sock_map_update_proto; >> +extern const struct bpf_func_proto bpf_sock_hash_update_proto; >> >> /* Shared helpers among cBPF and eBPF. */ >> void bpf_user_rnd_init_once(void); >> diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h >> index d7df1b32..b67f879 100644 >> --- a/include/linux/bpf_types.h >> +++ b/include/linux/bpf_types.h >> @@ -47,6 +47,7 @@ >> BPF_MAP_TYPE(BPF_MAP_TYPE_DEVMAP, dev_map_ops) >> #if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_INET) >> BPF_MAP_TYPE(BPF_MAP_TYPE_SOCKMAP, sock_map_ops) >> +BPF_MAP_TYPE(BPF_MAP_TYPE_SOCKHASH, sock_hash_ops) >> #endif >> BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops) >> #if defined(CONFIG_XDP_SOCKETS) >> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h >> index 02e4112..1205d86 100644 >> --- a/include/uapi/linux/bpf.h >> +++ b/include/uapi/linux/bpf.h >> @@ -118,6 +118,7 @@ enum bpf_map_type { >> BPF_MAP_TYPE_SOCKMAP, >> BPF_MAP_TYPE_CPUMAP, >> BPF_MAP_TYPE_XSKMAP, >> + BPF_MAP_TYPE_SOCKHASH, >> }; >> >> enum bpf_prog_type { >> @@ -1855,6 +1856,52 @@ struct bpf_stack_build_id { >> * Egress device index on success, 0 if packet needs to continue >> * up the stack for further processing or a negative error in case >> * of failure. >> + * int bpf_sock_hash_update(struct bpf_sock_ops_kern *skops, struct bpf_map *map, void *key, u64 flags) > > When you rebase please fix this up properly next time and add a newline in between > the helpers. I fixed this up while applying. I guess the tools/include/uapi/linux/bpf.h may also need fixup to be in sync with main bpf.h.