All of lore.kernel.org
 help / color / mirror / Atom feed
From: Puranjay Mohan <puranjay@kernel.org>
To: Song Liu <song@kernel.org>
Cc: Hengqi Chen <hengqi.chen@gmail.com>,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, xukuohai@huaweicloud.com,
	bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next] bpf, arm64: Call bpf_jit_binary_pack_finalize() in bpf_jit_free()
Date: Tue, 16 Sep 2025 12:51:13 +0000	[thread overview]
Message-ID: <mb61p4it2a7cu.fsf@kernel.org> (raw)
In-Reply-To: <CAPhsuW5-Q7F9-6hUWJ9XhS37fZrJjk7YNmbHriQM_rDW07X5KA@mail.gmail.com>

Song Liu <song@kernel.org> writes:

> Sorry for the late reply.
>
> On Thu, Aug 28, 2025 at 5:10 AM Puranjay Mohan <puranjay@kernel.org> wrote:
> [...]
>> Thanks for this patch!
>>
>> So, this is fixing a bug because bpf_jit_binary_pack_finalize() will do
>> kvfree(rw_header); but without it currently, jit_data->header is never
>> freed.
>>
>> But I think we shouldn't use bpf_jit_binary_pack_finalize() here as it
>> copies the whole rw_header to ro_header using  bpf_arch_text_copy()
>> which is an expensive operation (patch_map/unmap in loop +
>> flush_icache_range()) and not needed here because we are going
>> to free ro_header anyway.
>>
>> We only need to copy jit_data->header->size to jit_data->ro_header->size
>> because this size is later used by bpf_jit_binary_pack_free(), see
>> comment above bpf_jit_binary_pack_free().
>>
>> How I suggest we should fix the code and the comment:
>>
>> -- >8 --
>>
>> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
>> index 5083886d6e66b..cb4c50eeada13 100644
>> --- a/arch/arm64/net/bpf_jit_comp.c
>> +++ b/arch/arm64/net/bpf_jit_comp.c
>> @@ -3093,12 +3093,14 @@ void bpf_jit_free(struct bpf_prog *prog)
>>
>>                 /*
>>                  * If we fail the final pass of JIT (from jit_subprogs),
>> -                * the program may not be finalized yet. Call finalize here
>> -                * before freeing it.
>> +                * the program may not be finalized yet. Copy the header size
>> +                * from rw_header to ro_header before freeing the ro_header
>> +                * with bpf_jit_binary_pack_free().
>>                  */
>>                 if (jit_data) {
>>                         bpf_arch_text_copy(&jit_data->ro_header->size, &jit_data->header->size,
>>                                            sizeof(jit_data->header->size));
>> +                       kvfree(jit_data->header);
>>                         kfree(jit_data);
>>                 }
>>                 prog->bpf_func -= cfi_get_offset();
>>
>> -- 8< --
>>
>> Song,
>>
>> Do you think this optimization is worth it or should we just call
>> bpf_jit_binary_pack_finalize() here like this patch is doing?
>
> This is a good optimization. However, given this is not a hot path,
> I don't have a strong preference either way. At the moment, most
> other architectures use bpf_jit_binary_pack_finalize(), so it is good
> to just use bpf_jit_binary_pack_finalize and keep the logic
> consistent.

So, in that case we can merge this patch.

Acked-by: Puranjay Mohan <puranjay@kernel.org>

Thanks,
Puranjay

  reply	other threads:[~2025-09-16 12:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-28  1:34 [PATCH bpf-next] bpf, arm64: Call bpf_jit_binary_pack_finalize() in bpf_jit_free() Hengqi Chen
2025-08-28 12:10 ` Puranjay Mohan
2025-09-15 16:43   ` Song Liu
2025-09-16 12:51     ` Puranjay Mohan [this message]
2025-09-16 14:58       ` Alexei Starovoitov
2025-09-17  1:26         ` Hengqi Chen
  -- strict thread matches above, loose matches on Subject: below --
2025-09-16 23:26 Hengqi Chen
2025-09-17  5:34 ` Song Liu
2025-09-17 14:05 ` Puranjay Mohan
2025-09-17 18:30 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mb61p4it2a7cu.fsf@kernel.org \
    --to=puranjay@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hengqi.chen@gmail.com \
    --cc=martin.lau@linux.dev \
    --cc=song@kernel.org \
    --cc=xukuohai@huaweicloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.