Re: [PATCH v2 net-next 3/4] bpf: bpf_htab: Add syscall to iterate percpu value of a key

From: Eric Dumazet
Date: Tue Jan 12 2016 - 21:25:04 EST


On Tue, 2016-01-12 at 00:20 -0800, Martin KaFai Lau wrote:
> Add map_lookup_percpu_elem() syscall to lookup value
> of a particular CPU.

...

> +static int map_lookup_percpu_elem(union bpf_attr *attr)
> +{
> + void __user *ukey = u64_to_ptr(attr->key);
> + void __user *uvalue = u64_to_ptr(attr->value);
> + u32 __user ucpu = attr->cpu;
> + int ufd = attr->map_fd;
> + struct percpu_map_value_info value_info;
> + struct bpf_map *map;
> + void *key, *value;
> + struct fd f;
> + int err;
> +
> + if (CHECK_ATTR(BPF_MAP_LOOKUP_PERCPU_ELEM) ||
> + ucpu >= num_possible_cpus())
> + return -EINVAL;

Arg, a num_possible_cpus() wrong call.

You probably want to use (ucpu >= nr_cpu_ids)

hint : You can have hosts with 2 possibles cpus, CPU0 and CPU2

So the userland loop in your changelog is wrong.