> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> index 4f495dcbf670c..c4683d0e4c149 100644
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
> @@ -1056,12 +1056,12 @@ static void pcpu_init_value(struct bpf_htab *htab,
> void __percpu *pptr,
> * known initial values for cpus other than current one
> * (onallcpus=false always when coming from bpf prog).
> */
> - if (!onallcpus) {
> - int current_cpu = raw_smp_processor_id();
> + if (!onallcpus || (map_flags & BPF_F_CPU)) {
> + int init_cpu = onallcpus ? map_flags >> 32 :
> raw_smp_processor_id();
> int cpu;
>
> for_each_possible_cpu(cpu) {
> - if (cpu == current_cpu)
> + if (cpu == init_cpu)
> copy_map_value(&htab->map, per_cpu_ptr(pptr,
> cpu), value);
> else /* Since elem is preallocated, we cannot touch
> special fields */
> zero_map_value(&htab->map, per_cpu_ptr(pptr,
> cpu));
Does the block comment above this condition need updating? It says the value
goes to the "current one" and explains the whole branch with "onallcpus=false
always when coming from bpf prog."
With the patch, the branch is also taken when onallcpus is true and BPF_F_CPU
is set. In that case:
if (!onallcpus || (map_flags & BPF_F_CPU)) {
int init_cpu = onallcpus ? map_flags >> 32 : raw_smp_processor_id();
the value goes to the CPU named in map_flags >> 32, while the current CPU
might be one of the CPUs that gets zero-filled.
The rationale also seems specific to the BPF program case. For BPF_F_CPU
updates there is no BPF program involved (htab_map_check_update_flags()
returns -EINVAL for !onallcpus && map_flags > BPF_EXIST), so the reason to
zero the other slots is that the per-cpu area is recycled and must not hand
back the previous tenant's values, as the commit message explains.
Could the comment be updated to cover both entry conditions?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/35502758763