Skip to content

Commit 402fdc9

Browse files
AsphalttKernel Patches Daemon
authored andcommitted
bpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu_cgroup_storage maps
Introduce BPF_F_ALL_CPUS flag support for percpu_cgroup_storage maps to allow updating values for all CPUs with a single value for update_elem API. Introduce BPF_F_CPU flag support for percpu_cgroup_storage maps to allow: * update value for specified CPU for update_elem API. * lookup value for specified CPU for lookup_elem API. The BPF_F_CPU flag is passed via map_flags along with embedded cpu info. Signed-off-by: Leon Hwang <[email protected]>
1 parent f57d785 commit 402fdc9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,6 +3758,7 @@ static inline bool bpf_map_supports_cpu_flags(enum bpf_map_type map_type)
37583758
case BPF_MAP_TYPE_PERCPU_ARRAY:
37593759
case BPF_MAP_TYPE_PERCPU_HASH:
37603760
case BPF_MAP_TYPE_LRU_PERCPU_HASH:
3761+
case BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE:
37613762
return true;
37623763
default:
37633764
return false;

kernel/bpf/local_storage.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ int bpf_percpu_cgroup_storage_copy(struct bpf_map *_map, void *key,
186186
struct bpf_cgroup_storage *storage;
187187
void __percpu *pptr;
188188
u32 size;
189+
int err;
190+
191+
err = bpf_map_check_cpu_flags(map_flags, false);
192+
if (err)
193+
return err;
189194

190195
rcu_read_lock();
191196
storage = cgroup_storage_lookup(map, key, false);
@@ -212,10 +217,15 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *key,
212217
struct bpf_cgroup_storage *storage;
213218
void __percpu *pptr;
214219
u32 size;
220+
int err;
215221

216-
if (map_flags != BPF_ANY && map_flags != BPF_EXIST)
222+
if ((u32)map_flags & ~(BPF_ANY | BPF_EXIST | BPF_F_CPU | BPF_F_ALL_CPUS))
217223
return -EINVAL;
218224

225+
err = bpf_map_check_cpu_flags(map_flags, true);
226+
if (err)
227+
return err;
228+
219229
rcu_read_lock();
220230
storage = cgroup_storage_lookup(map, key, false);
221231
if (!storage) {

0 commit comments

Comments
 (0)