@@ -133,12 +133,14 @@ bool bpf_map_write_active(const struct bpf_map *map)
133133 return atomic64_read (& map -> writecnt ) != 0 ;
134134}
135135
136- static u32 bpf_map_value_size (const struct bpf_map * map )
137- {
138- if (map -> map_type == BPF_MAP_TYPE_PERCPU_HASH ||
139- map -> map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
140- map -> map_type == BPF_MAP_TYPE_PERCPU_ARRAY ||
141- map -> map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE )
136+ static u32 bpf_map_value_size (const struct bpf_map * map , u64 flags )
137+ {
138+ if (flags & (BPF_F_CPU | BPF_F_ALL_CPUS ))
139+ return round_up (map -> value_size , 8 );
140+ else if (map -> map_type == BPF_MAP_TYPE_PERCPU_HASH ||
141+ map -> map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
142+ map -> map_type == BPF_MAP_TYPE_PERCPU_ARRAY ||
143+ map -> map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE )
142144 return round_up (map -> value_size , 8 ) * num_possible_cpus ();
143145 else if (IS_FD_MAP (map ))
144146 return sizeof (u32 );
@@ -1716,15 +1718,15 @@ static int map_lookup_elem(union bpf_attr *attr)
17161718 if (!(map_get_sys_perms (map , f ) & FMODE_CAN_READ ))
17171719 return - EPERM ;
17181720
1719- err = bpf_map_check_op_flags (map , attr -> flags , BPF_F_LOCK );
1721+ err = bpf_map_check_op_flags (map , attr -> flags , BPF_F_LOCK | BPF_F_CPU );
17201722 if (err )
17211723 return err ;
17221724
17231725 key = __bpf_copy_key (ukey , map -> key_size );
17241726 if (IS_ERR (key ))
17251727 return PTR_ERR (key );
17261728
1727- value_size = bpf_map_value_size (map );
1729+ value_size = bpf_map_value_size (map , attr -> flags );
17281730
17291731 err = - ENOMEM ;
17301732 value = kvmalloc (value_size , GFP_USER | __GFP_NOWARN );
@@ -1791,7 +1793,7 @@ static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr)
17911793 goto err_put ;
17921794 }
17931795
1794- value_size = bpf_map_value_size (map );
1796+ value_size = bpf_map_value_size (map , attr -> flags );
17951797 value = kvmemdup_bpfptr (uvalue , value_size );
17961798 if (IS_ERR (value )) {
17971799 err = PTR_ERR (value );
@@ -1987,11 +1989,12 @@ int generic_map_update_batch(struct bpf_map *map, struct file *map_file,
19871989 void * key , * value ;
19881990 int err = 0 ;
19891991
1990- err = bpf_map_check_op_flags (map , attr -> batch .elem_flags , BPF_F_LOCK );
1992+ err = bpf_map_check_op_flags (map , attr -> batch .elem_flags ,
1993+ BPF_F_LOCK | BPF_F_CPU | BPF_F_ALL_CPUS );
19911994 if (err )
19921995 return err ;
19931996
1994- value_size = bpf_map_value_size (map );
1997+ value_size = bpf_map_value_size (map , attr -> batch . elem_flags );
19951998
19961999 max_count = attr -> batch .count ;
19972000 if (!max_count )
@@ -2046,11 +2049,11 @@ int generic_map_lookup_batch(struct bpf_map *map,
20462049 u32 value_size , cp , max_count ;
20472050 int err ;
20482051
2049- err = bpf_map_check_op_flags (map , attr -> batch .elem_flags , BPF_F_LOCK );
2052+ err = bpf_map_check_op_flags (map , attr -> batch .elem_flags , BPF_F_LOCK | BPF_F_CPU );
20502053 if (err )
20512054 return err ;
20522055
2053- value_size = bpf_map_value_size (map );
2056+ value_size = bpf_map_value_size (map , attr -> batch . elem_flags );
20542057
20552058 max_count = attr -> batch .count ;
20562059 if (!max_count )
@@ -2172,7 +2175,7 @@ static int map_lookup_and_delete_elem(union bpf_attr *attr)
21722175 goto err_put ;
21732176 }
21742177
2175- value_size = bpf_map_value_size (map );
2178+ value_size = bpf_map_value_size (map , 0 );
21762179
21772180 err = - ENOMEM ;
21782181 value = kvmalloc (value_size , GFP_USER | __GFP_NOWARN );
0 commit comments