BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kui-Feng Lee <sinquersw@gmail.com>, thinker.li@gmail.com
Cc: kuifeng@meta.com, bpf@vger.kernel.org, ast@kernel.org,
	song@kernel.org, kernel-team@meta.com, andrii@kernel.org
Subject: Re: [PATCH bpf-next v2 2/3] bpf: struct_ops supports more than one page for trampolines.
Date: Fri, 23 Feb 2024 11:15:22 -0800	[thread overview]
Message-ID: <363c4377-f668-49fd-978d-73864c293b4e@linux.dev> (raw)
In-Reply-To: <30ffb867-ee0e-4573-b9e7-9fc0f4430adb@gmail.com>

On 2/23/24 11:05 AM, Kui-Feng Lee wrote:
> 
> 
> 
> On 2/23/24 10:42, Martin KaFai Lau wrote:
>> On 2/23/24 10:29 AM, Kui-Feng Lee wrote:
>>> One thing I forgot to mention is that bpf_dummy_ops has to call
>>> bpf_jit_uncharge_modmem(PAGE_SIZE) as well. The other option is to move
>>> bpf_jit_charge_modmem() out of bpf_struct_ops_prepare_trampoline(),
>>> meaning bpf_struct_ops_map_update_elem() should handle the case that the
>>> allocation in bpf_struct_ops_prepare_trampoline() successes, but
>>> bpf_jit_charge_modmem() fails.
>>
>> Keep the charge/uncharge in bpf_struct_ops_prepare_trampoline().
>>
>> It is fine to have bpf_dummy_ops charge and then uncharge a PAGE_SIZE. There 
>> is no need to optimize for bpf_dummy_ops. Use bpf_struct_ops_free_trampoline() 
>> in bpf_dummy_ops to uncharge and free.
> 
> 
> Then, I don't get the point here.
> I agree with moving the allocation into
> bpf_struct_ops_prepare_trampoline() to avoid duplication of the code
> about flags and tlinks. It really simplifies the code with the fact
> that bpf_dummy_ops is still there. So, I tried to pass a st_map to
> bpf_struct_ops_prepare_trampoline() to keep page managements code
> together. But, you said to simplify the code of bpf_dummy_ops by
> allocating pages in bpf_struct_ops_prepare_trampoline(), do bookkeeping
> in bpf_struct_ops_map_update_elem(), so bpf_dummy_ops doesn't have to

I don't think I ever mentioned to do book keeping in 
bpf_struct_ops_map_update_elem(). Have you looked at my earlier code in 
bpf_struct_ops_prepare_trampoline() which also does the memory charging also?

> allocate memory. But, we have to move a bpf_jit_uncharge_modmem() to
> bpf_dummy_ops. For me, this trade-off that include removing an
> allocation and adding a bpf_jit_uncharge_modmem() make no sense.

Which part make no sense? Having bpf_dummy_ops charge/uncharge memory also?

The bpf_dummy_ops() uses the below bpf_struct_ops_free_trampoline() which does 
uncharge and free. bpf_struct_ops_prepare_trampoline() does charge and alloc.
charge/alloc matches with uncharge/free.

> 
>>
>>
>>>>> void bpf_struct_ops_free_trampoline(void *image)
>>>>> {
>>>>>      bpf_jit_uncharge_modmem(PAGE_SIZE);
>>>>>      arch_free_bpf_trampoline(image, PAGE_SIZE);
>>>>> }
>>>>>
>>


  reply	other threads:[~2024-02-23 19:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 22:59 [PATCH bpf-next v2 0/3] Allow struct_ops maps with a large number of programs thinker.li
2024-02-21 22:59 ` [PATCH bpf-next v2 1/3] bpf, net: validate struct_ops when updating value thinker.li
2024-02-21 22:59 ` [PATCH bpf-next v2 2/3] bpf: struct_ops supports more than one page for trampolines thinker.li
2024-02-23  0:33   ` Martin KaFai Lau
2024-02-23  1:35     ` Kui-Feng Lee
2024-02-23  2:16       ` Martin KaFai Lau
2024-02-23  3:01         ` Kui-Feng Lee
2024-02-23  5:25           ` Martin KaFai Lau
2024-02-23 17:36             ` Kui-Feng Lee
2024-02-23 18:29               ` Kui-Feng Lee
2024-02-23 18:42                 ` Martin KaFai Lau
2024-02-23 19:05                   ` Kui-Feng Lee
2024-02-23 19:15                     ` Martin KaFai Lau [this message]
2024-02-23 22:06                       ` Kui-Feng Lee
2024-02-24  3:20                         ` Martin KaFai Lau
2024-02-23 18:32               ` Martin KaFai Lau
2024-02-21 22:59 ` [PATCH bpf-next v2 3/3] selftests/bpf: Test struct_ops maps with a large number of program links thinker.li
2024-02-21 23:02 ` [PATCH bpf-next v2 0/3] Allow struct_ops maps with a large number of programs Kui-Feng Lee

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=363c4377-f668-49fd-978d-73864c293b4e@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuifeng@meta.com \
    --cc=sinquersw@gmail.com \
    --cc=song@kernel.org \
    --cc=thinker.li@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox