1717#include <linux/u64_stats_sync.h>
1818#include <linux/refcount.h>
1919#include <linux/mutex.h>
20+ #include <linux/module.h>
2021
2122struct bpf_verifier_env ;
2223struct bpf_verifier_log ;
@@ -43,6 +44,15 @@ struct bpf_map_ops {
4344 int (* map_get_next_key )(struct bpf_map * map , void * key , void * next_key );
4445 void (* map_release_uref )(struct bpf_map * map );
4546 void * (* map_lookup_elem_sys_only )(struct bpf_map * map , void * key );
47+ int (* map_lookup_batch )(struct bpf_map * map , const union bpf_attr * attr ,
48+ union bpf_attr __user * uattr );
49+ int (* map_lookup_and_delete_batch )(struct bpf_map * map ,
50+ const union bpf_attr * attr ,
51+ union bpf_attr __user * uattr );
52+ int (* map_update_batch )(struct bpf_map * map , const union bpf_attr * attr ,
53+ union bpf_attr __user * uattr );
54+ int (* map_delete_batch )(struct bpf_map * map , const union bpf_attr * attr ,
55+ union bpf_attr __user * uattr );
4656
4757 /* funcs callable from userspace and from eBPF programs */
4858 void * (* map_lookup_elem )(struct bpf_map * map , void * key );
@@ -106,6 +116,7 @@ struct bpf_map {
106116 struct btf * btf ;
107117 struct bpf_map_memory memory ;
108118 char name [BPF_OBJ_NAME_LEN ];
119+ u32 btf_vmlinux_value_type_id ;
109120 bool unpriv_array ;
110121 bool frozen ; /* write-once; write-protected by freeze_mutex */
111122 /* 22 bytes hole */
@@ -183,7 +194,8 @@ static inline bool bpf_map_offload_neutral(const struct bpf_map *map)
183194
184195static inline bool bpf_map_support_seq_show (const struct bpf_map * map )
185196{
186- return map -> btf && map -> ops -> map_seq_show_elem ;
197+ return (map -> btf_value_type_id || map -> btf_vmlinux_value_type_id ) &&
198+ map -> ops -> map_seq_show_elem ;
187199}
188200
189201int map_check_no_btf (const struct bpf_map * map ,
@@ -349,6 +361,10 @@ struct bpf_verifier_ops {
349361 const struct bpf_insn * src ,
350362 struct bpf_insn * dst ,
351363 struct bpf_prog * prog , u32 * target_size );
364+ int (* btf_struct_access )(struct bpf_verifier_log * log ,
365+ const struct btf_type * t , int off , int size ,
366+ enum bpf_access_type atype ,
367+ u32 * next_btf_id );
352368};
353369
354370struct bpf_prog_offload_ops {
@@ -437,7 +453,8 @@ struct btf_func_model {
437453 * fentry = a set of program to run before calling original function
438454 * fexit = a set of program to run after original function
439455 */
440- int arch_prepare_bpf_trampoline (void * image , struct btf_func_model * m , u32 flags ,
456+ int arch_prepare_bpf_trampoline (void * image , void * image_end ,
457+ const struct btf_func_model * m , u32 flags ,
441458 struct bpf_prog * * fentry_progs , int fentry_cnt ,
442459 struct bpf_prog * * fexit_progs , int fexit_cnt ,
443460 void * orig_call );
@@ -448,7 +465,8 @@ void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start);
448465enum bpf_tramp_prog_type {
449466 BPF_TRAMP_FENTRY ,
450467 BPF_TRAMP_FEXIT ,
451- BPF_TRAMP_MAX
468+ BPF_TRAMP_MAX ,
469+ BPF_TRAMP_REPLACE , /* more than MAX */
452470};
453471
454472struct bpf_trampoline {
@@ -463,6 +481,11 @@ struct bpf_trampoline {
463481 void * addr ;
464482 bool ftrace_managed ;
465483 } func ;
484+ /* if !NULL this is BPF_PROG_TYPE_EXT program that extends another BPF
485+ * program by replacing one of its functions. func.addr is the address
486+ * of the function it replaced.
487+ */
488+ struct bpf_prog * extension_prog ;
466489 /* list of BPF programs using this trampoline */
467490 struct hlist_head progs_hlist [BPF_TRAMP_MAX ];
468491 /* Number of attached programs. A counter per kind. */
@@ -558,6 +581,7 @@ static inline void bpf_dispatcher_change_prog(struct bpf_dispatcher *d,
558581#endif
559582
560583struct bpf_func_info_aux {
584+ u16 linkage ;
561585 bool unreliable ;
562586};
563587
@@ -668,6 +692,73 @@ struct bpf_array_aux {
668692 struct work_struct work ;
669693};
670694
695+ struct bpf_struct_ops_value ;
696+ struct btf_type ;
697+ struct btf_member ;
698+
699+ #define BPF_STRUCT_OPS_MAX_NR_MEMBERS 64
700+ struct bpf_struct_ops {
701+ const struct bpf_verifier_ops * verifier_ops ;
702+ int (* init )(struct btf * btf );
703+ int (* check_member )(const struct btf_type * t ,
704+ const struct btf_member * member );
705+ int (* init_member )(const struct btf_type * t ,
706+ const struct btf_member * member ,
707+ void * kdata , const void * udata );
708+ int (* reg )(void * kdata );
709+ void (* unreg )(void * kdata );
710+ const struct btf_type * type ;
711+ const struct btf_type * value_type ;
712+ const char * name ;
713+ struct btf_func_model func_models [BPF_STRUCT_OPS_MAX_NR_MEMBERS ];
714+ u32 type_id ;
715+ u32 value_id ;
716+ };
717+
718+ #if defined(CONFIG_BPF_JIT ) && defined(CONFIG_BPF_SYSCALL )
719+ #define BPF_MODULE_OWNER ((void *)((0xeB9FUL << 2) + POISON_POINTER_DELTA))
720+ const struct bpf_struct_ops * bpf_struct_ops_find (u32 type_id );
721+ void bpf_struct_ops_init (struct btf * btf );
722+ bool bpf_struct_ops_get (const void * kdata );
723+ void bpf_struct_ops_put (const void * kdata );
724+ int bpf_struct_ops_map_sys_lookup_elem (struct bpf_map * map , void * key ,
725+ void * value );
726+ static inline bool bpf_try_module_get (const void * data , struct module * owner )
727+ {
728+ if (owner == BPF_MODULE_OWNER )
729+ return bpf_struct_ops_get (data );
730+ else
731+ return try_module_get (owner );
732+ }
733+ static inline void bpf_module_put (const void * data , struct module * owner )
734+ {
735+ if (owner == BPF_MODULE_OWNER )
736+ bpf_struct_ops_put (data );
737+ else
738+ module_put (owner );
739+ }
740+ #else
741+ static inline const struct bpf_struct_ops * bpf_struct_ops_find (u32 type_id )
742+ {
743+ return NULL ;
744+ }
745+ static inline void bpf_struct_ops_init (struct btf * btf ) { }
746+ static inline bool bpf_try_module_get (const void * data , struct module * owner )
747+ {
748+ return try_module_get (owner );
749+ }
750+ static inline void bpf_module_put (const void * data , struct module * owner )
751+ {
752+ module_put (owner );
753+ }
754+ static inline int bpf_struct_ops_map_sys_lookup_elem (struct bpf_map * map ,
755+ void * key ,
756+ void * value )
757+ {
758+ return - EINVAL ;
759+ }
760+ #endif
761+
671762struct bpf_array {
672763 struct bpf_map map ;
673764 u32 elem_size ;
@@ -906,6 +997,15 @@ void *bpf_map_area_alloc(u64 size, int numa_node);
906997void * bpf_map_area_mmapable_alloc (u64 size , int numa_node );
907998void bpf_map_area_free (void * base );
908999void bpf_map_init_from_attr (struct bpf_map * map , union bpf_attr * attr );
1000+ int generic_map_lookup_batch (struct bpf_map * map ,
1001+ const union bpf_attr * attr ,
1002+ union bpf_attr __user * uattr );
1003+ int generic_map_update_batch (struct bpf_map * map ,
1004+ const union bpf_attr * attr ,
1005+ union bpf_attr __user * uattr );
1006+ int generic_map_delete_batch (struct bpf_map * map ,
1007+ const union bpf_attr * attr ,
1008+ union bpf_attr __user * uattr );
9091009
9101010extern int sysctl_unprivileged_bpf_disabled ;
9111011
@@ -962,7 +1062,9 @@ struct sk_buff;
9621062
9631063struct bpf_dtab_netdev * __dev_map_lookup_elem (struct bpf_map * map , u32 key );
9641064struct bpf_dtab_netdev * __dev_map_hash_lookup_elem (struct bpf_map * map , u32 key );
965- void __dev_map_flush (void );
1065+ void __dev_flush (void );
1066+ int dev_xdp_enqueue (struct net_device * dev , struct xdp_buff * xdp ,
1067+ struct net_device * dev_rx );
9661068int dev_map_enqueue (struct bpf_dtab_netdev * dst , struct xdp_buff * xdp ,
9671069 struct net_device * dev_rx );
9681070int dev_map_generic_redirect (struct bpf_dtab_netdev * dst , struct sk_buff * skb ,
@@ -1006,7 +1108,13 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
10061108 const char * func_name ,
10071109 struct btf_func_model * m );
10081110
1009- int btf_check_func_arg_match (struct bpf_verifier_env * env , int subprog );
1111+ struct bpf_reg_state ;
1112+ int btf_check_func_arg_match (struct bpf_verifier_env * env , int subprog ,
1113+ struct bpf_reg_state * regs );
1114+ int btf_prepare_func_args (struct bpf_verifier_env * env , int subprog ,
1115+ struct bpf_reg_state * reg );
1116+ int btf_check_type_match (struct bpf_verifier_env * env , struct bpf_prog * prog ,
1117+ struct btf * btf , const struct btf_type * t );
10101118
10111119struct bpf_prog * bpf_prog_by_id (u32 id );
10121120
@@ -1071,13 +1179,20 @@ static inline struct net_device *__dev_map_hash_lookup_elem(struct bpf_map *map
10711179 return NULL ;
10721180}
10731181
1074- static inline void __dev_map_flush (void )
1182+ static inline void __dev_flush (void )
10751183{
10761184}
10771185
10781186struct xdp_buff ;
10791187struct bpf_dtab_netdev ;
10801188
1189+ static inline
1190+ int dev_xdp_enqueue (struct net_device * dev , struct xdp_buff * xdp ,
1191+ struct net_device * dev_rx )
1192+ {
1193+ return 0 ;
1194+ }
1195+
10811196static inline
10821197int dev_map_enqueue (struct bpf_dtab_netdev * dst , struct xdp_buff * xdp ,
10831198 struct net_device * dev_rx )
@@ -1299,6 +1414,7 @@ extern const struct bpf_func_proto bpf_get_local_storage_proto;
12991414extern const struct bpf_func_proto bpf_strtol_proto ;
13001415extern const struct bpf_func_proto bpf_strtoul_proto ;
13011416extern const struct bpf_func_proto bpf_tcp_sock_proto ;
1417+ extern const struct bpf_func_proto bpf_jiffies64_proto ;
13021418
13031419/* Shared helpers among cBPF and eBPF. */
13041420void bpf_user_rnd_init_once (void );
0 commit comments