On 2/7/26 03:31, Andrii Nakryiko wrote:
> On Mon, Jun 29, 2026 at 8:24 AM Leon Hwang <[email protected]> wrote:
[...]
>> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
>> index 3cf2cc6e3ab6..4f84d087ca69 100644
>> --- a/kernel/bpf/fixups.c
>> +++ b/kernel/bpf/fixups.c
>> @@ -1819,6 +1819,38 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
>>                         goto next_insn;
>>                 }
>>
>> +               if (env->prog->jit_requested &&
>> +                   bpf_jit_supports_percpu_insn() &&
>> +                   insn->code == (BPF_LD | BPF_IMM | BPF_DW) &&
>> +                   (insn->src_reg == BPF_PSEUDO_MAP_VALUE ||
>> +                    insn->src_reg == BPF_PSEUDO_MAP_IDX_VALUE)) {
>> +                       struct bpf_map *map;
>> +
>> +                       aux = &env->insn_aux_data[i + delta];
>> +                       map = env->used_maps[aux->map_index];
>> +                       if (map->map_type != BPF_MAP_TYPE_PERCPU_ARRAY)
>> +                               goto next_insn;
>> +
>> +                       /*
>> +                        * Reuse the original ld_imm64 insn, and add one
>> +                        * mov64_percpu_reg insn.
>> +                        */
>> +
>> +                       insn_buf[0] = insn[1];
>> +                       insn_buf[1] = BPF_MOV64_PERCPU_REG(insn->dst_reg, 
>> insn->dst_reg);
>> +                       cnt = 2;
>> +
>> +                       i++;
> 
> oof, this was a subtle head scratcher for me.. that i++ is easy to
> miss. let's update the comment to be more explicit: we are *skipping*
> first half of ld_imm64, patching over second half of it with that same
> half + percpu mov. All because bpf_patch_insn_data() can only replace
> one 8-byte instruction, which doesn't work well for ldimm64.
> 
> Anyways, this looks correct, it just took me a bit to figure this out
> and while the above comment warned me about this, it didn't really
> make it any easier for figure out what's going on.
> 

Ack. Will update the comment.

Thanks,
Leon


Reply via email to