Skip to content

Commit 7e2b2e2

Browse files
Paolo Abenigregkh
authored andcommitted
bpftool: fix percpu maps updating
[ Upstream commit b0ca5ec ] When updating a percpu map, bpftool currently copies the provided value only into the first per CPU copy of the specified value, all others instances are left zeroed. This change explicitly copies the user-provided bytes to all the per CPU instances, keeping the sub-command syntax unchanged. v2 -> v3: - drop unused argument, as per Quentin's suggestion v1 -> v2: - rename the helper as per Quentin's suggestion Fixes: 71bb428 ("tools: bpf: add bpftool") Signed-off-by: Paolo Abeni <pabeni@redhat.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1da961d commit 7e2b2e2

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎tools/bpf/bpftool/map.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,20 @@ static char **parse_bytes(char **argv, const char *name, unsigned char *val,
370370
return argv + i;
371371
}
372372

373+
/* on per cpu maps we must copy the provided value on all value instances */
374+
static void fill_per_cpu_value(struct bpf_map_info *info, void *value)
375+
{
376+
unsigned int i, n, step;
377+
378+
if (!map_is_per_cpu(info->type))
379+
return;
380+
381+
n = get_possible_cpus();
382+
step = round_up(info->value_size, 8);
383+
for (i = 1; i < n; i++)
384+
memcpy(value + i * step, value, info->value_size);
385+
}
386+
373387
static int parse_elem(char **argv, struct bpf_map_info *info,
374388
void *key, void *value, __u32 key_size, __u32 value_size,
375389
__u32 *flags, __u32 **value_fd)
@@ -449,6 +463,8 @@ static int parse_elem(char **argv, struct bpf_map_info *info,
449463
argv = parse_bytes(argv, "value", value, value_size);
450464
if (!argv)
451465
return -1;
466+
467+
fill_per_cpu_value(info, value);
452468
}
453469

454470
return parse_elem(argv, info, key, NULL, key_size, value_size,

0 commit comments

Comments
 (0)