Re: [PATCH bpf-next v7 04/11] bpf: Introduce global percpu data
From: Leon Hwang
Date: Wed Jun 24 2026 - 00:11:17 EST
On 24/6/26 06:45, Andrii Nakryiko wrote:
> On Mon, Jun 22, 2026 at 7:37 AM Leon Hwang <leon.hwang@xxxxxxxxx> wrote:
[...]
>> +
>> +static int percpu_array_map_direct_value_meta(const struct bpf_map *map, u64 imm, u32 *off)
>> +{
>> + struct bpf_array *array = container_of(map, struct bpf_array, map);
>> + u64 base = (u64)(__force unsigned long) array->pptrs[0];
>> + u64 range = array->elem_size;
>> +
>> + if (map->max_entries != 1)
>> + return -EOPNOTSUPP;
>> + if (imm < base || imm >= base + range)
>
> nit: not sure what's the value of range local variable, single place
> where you use array->elem_size
>
Hmm, this was copied from array_map_direct_value_meta().
Will drop "range", and use "array->elem_size" here.
>> + return -ENOENT;
>> + if (!bpf_jit_supports_percpu_insn())
>> + return -EOPNOTSUPP;
>> +
>> + *off = imm - base;
>> + return 0;
>> +}
>> +
[...]
>> diff --git a/kernel/bpf/const_fold.c b/kernel/bpf/const_fold.c
>> index b2a19acadb91..5787246bef30 100644
>> --- a/kernel/bpf/const_fold.c
>> +++ b/kernel/bpf/const_fold.c
>> @@ -182,7 +182,6 @@ static void const_reg_xfer(struct bpf_verifier_env *env, struct const_arg_info *
>> u64 val = 0;
>>
>> if (!bpf_map_is_rdonly(map) || !map->ops->map_direct_value_addr ||
>> - map->map_type == BPF_MAP_TYPE_INSN_ARRAY ||
>
> can you please elaborate on why this change is needed?
>
This was suggested by Alexei in v4:
https://lore.kernel.org/bpf/CAADnVQJ0o38xXn6E5ub7kWyoZPiaevr9mwDNxv0GbxyguVTKUg@xxxxxxxxxxxxxx/
Thanks,
Leon
>> off < 0 || off + size > map->value_size ||
>> bpf_map_direct_read(map, off, size, &val, is_ldsx)) {
>> *dst = unknown;
>
> [...]