Re: [PATCH bpf-next v1 4/4] resolve_btfids: change in-place update with raw binary output
From: Ihor Solodrai
Date: Wed Nov 26 2025 - 18:58:24 EST
On 11/26/25 11:13 AM, Ihor Solodrai wrote:
> On 11/26/25 5:03 AM, Donglin Peng wrote:
>> On Wed, Nov 26, 2025 at 9:29 AM Ihor Solodrai <ihor.solodrai@xxxxxxxxx> wrote:
>>>
>>> [...]
>>>
>>> For the kernel modules creating special .bpf.o file is not necessary,
>>> and so embedding of sections data produced by resolve_btfids is
>>> straightforward with the objcopy.
>>
>> The Makefile for the bpf selftests also needs be updated too:
>> https://elixir.bootlin.com/linux/v6.18-rc7/source/tools/testing/selftests/bpf/Makefile#L708
>>
>> This results in the self-test for resolve_btfids failing:
>> $./vmtest.sh -- ./test_progs -t resolve_btfids -v
>> ...
>> test_resolve_btfids:PASS:id_check 0 nsec
>> test_resolve_btfids:FAIL:id_check wrong ID for S (0 != 3)
>
> Good catch, thanks.
>
> I remember I noticed this at some point, and then forgot...
>
> Interestingly this test passes on CI [1]:
>
> 2025-11-26T03:09:52.0908317Z #366 reg_bounds_rand_ranges_u64_u64:OK
> 2025-11-26T03:09:52.0925114Z #367 resolve_btfids:OK
> 2025-11-26T03:09:52.3904190Z #368/1 res_spin_lock_failure/res_spin_lock_arg:OK
>
> I'll take a closer look.
I figured out why this test was flaky.
Even though I removed elf_update() call from resolve_btfids, the ELF
was opened with:
elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
And the buffers which resolve_btfids writes to are from Elf_Data
returned by elf_getdata(). And so the file might actually get written
to in-place, which is why the resolve_btfids test passed for me with
no changes to the selftests.
I switched ELF_C_RDWR_MMAP to ELF_C_READ_MMAP_PRIVATE, and then the
ELF reliably remains intact (and the test fails). From libelf.h:
ELF_C_READ_MMAP_PRIVATE, /* Read, but memory is writable, results are
not written to the file. */
It makes sense to use this for what resolve_btfids is doing.
I'll fix selftests/bpf/Makefile in the next revision.
>
> [1] https://github.com/kernel-patches/bpf/actions/runs/19690981192/job/56406840021
>
>>
>>
>>> [...]
>>>
>