Skip to content

Commit 36aaf5b

Browse files
AsphalttKernel Patches Daemon
authored andcommitted
bpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu_array maps
Introduce support for the BPF_F_ALL_CPUS flag in percpu_array maps to allow updating values for all CPUs with a single value for both update_elem and update_batch APIs. Introduce support for the BPF_F_CPU flag in percpu_array maps to allow: * update value for specified CPU for both update_elem and update_batch APIs. * lookup value for specified CPU for both lookup_elem and lookup_batch APIs. The BPF_F_CPU flag is passed via: * map_flags of lookup_elem and update_elem APIs along with embedded cpu info. * elem_flags of lookup_batch and update_batch APIs along with embedded cpu info. Signed-off-by: Leon Hwang <[email protected]>
1 parent 0957532 commit 36aaf5b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

include/linux/bpf.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3754,7 +3754,12 @@ struct bpf_prog *bpf_prog_find_from_stack(void);
37543754

37553755
static inline bool bpf_map_supports_cpu_flags(enum bpf_map_type map_type)
37563756
{
3757-
return false;
3757+
switch (map_type) {
3758+
case BPF_MAP_TYPE_PERCPU_ARRAY:
3759+
return true;
3760+
default:
3761+
return false;
3762+
}
37583763
}
37593764

37603765
static inline int bpf_map_check_op_flags(struct bpf_map *map, u64 flags, u64 allowed_flags)

kernel/bpf/arraymap.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value, u64 map_f
301301
u32 index = *(u32 *)key;
302302
void __percpu *pptr;
303303
u32 size;
304+
int err;
305+
306+
err = bpf_map_check_cpu_flags(map_flags, false);
307+
if (unlikely(err))
308+
return err;
304309

305310
if (unlikely(index >= array->map.max_entries))
306311
return -ENOENT;
@@ -383,10 +388,11 @@ int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,
383388
u32 index = *(u32 *)key;
384389
void __percpu *pptr;
385390
u32 size;
391+
int err;
386392

387-
if (unlikely(map_flags > BPF_EXIST))
388-
/* unknown flags */
389-
return -EINVAL;
393+
err = bpf_map_check_cpu_flags(map_flags, true);
394+
if (unlikely(err))
395+
return err;
390396

391397
if (unlikely(index >= array->map.max_entries))
392398
/* all elements were pre-allocated, cannot insert a new one */

0 commit comments

Comments
 (0)