BPF List
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>,
	Kui-Feng Lee <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 v3 2/3] bpf: struct_ops supports more than one page for trampolines.
Date: Sat, 24 Feb 2024 07:43:07 -0800	[thread overview]
Message-ID: <c3080ecb-abb0-4d47-a8f5-607e7082b1ef@gmail.com> (raw)
In-Reply-To: <9d2dbd18-0d64-458a-8c95-9d549eabd3cf@linux.dev>



On 2/23/24 22:19, Martin KaFai Lau wrote:
> On 2/23/24 7:03 PM, Kui-Feng Lee wrote:
>> +static void bpf_struct_ops_map_free_image(struct bpf_struct_ops_map 
>> *st_map)
>> +{
>> +    int i;
>> +    void *image;
>> +
>> +    bpf_jit_uncharge_modmem(PAGE_SIZE * st_map->image_pages_cnt);
>> +    for (i = 0; i < st_map->image_pages_cnt; i++) {
>> +        image = st_map->image_pages[i];
>> +        arch_free_bpf_trampoline(image, PAGE_SIZE);
>> +    }
>> +    st_map->image_pages_cnt = 0;
>> +}
>> +
> 
> [ ... ]
> 
>> @@ -133,7 +128,8 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, 
>> const union bpf_attr *kattr,
>>       err = bpf_struct_ops_prepare_trampoline(tlinks, link,
>>                           &st_ops->func_models[op_idx],
>>                           &dummy_ops_test_ret_function,
>> -                        image, image + PAGE_SIZE);
>> +                        &image, &image_off,
>> +                        true);
>>       if (err < 0)
>>           goto out;
>> @@ -147,6 +143,8 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, 
>> const union bpf_attr *kattr,
>>           err = -EFAULT;
>>   out:
>>       kfree(args);
>> +    if (image)
>> +        bpf_jit_uncharge_modmem(PAGE_SIZE);
>>       arch_free_bpf_trampoline(image, PAGE_SIZE);
> 
> It seems my last reply on v2 has crossed over with v3.
> 
> The bpf_struct_ops_free_trampoline() highlighted in my last reply should
> address your concern in v2 that the caller needs to remember
> the bpf_jit_uncharge_modmem here.
> 
> I think the trampoline alloc(aka prepare here)/free pair that you also
> suggested in v2 discussion is a nice match here and work as a
> charge+alloc and uncharge+free pair.

sure

> 
>>       if (link)
>>           bpf_link_put(&link->link);
> 

  reply	other threads:[~2024-02-24 15:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-24  3:02 [PATCH bpf-next v3 0/3] Allow struct_ops maps with a large number of programs Kui-Feng Lee
2024-02-24  3:03 ` [PATCH bpf-next v3 1/3] bpf, net: validate struct_ops when updating value Kui-Feng Lee
2024-02-24  3:03 ` [PATCH bpf-next v3 2/3] bpf: struct_ops supports more than one page for trampolines Kui-Feng Lee
2024-02-24  6:19   ` Martin KaFai Lau
2024-02-24 15:43     ` Kui-Feng Lee [this message]
2024-02-24  3:03 ` [PATCH bpf-next v3 3/3] selftests/bpf: Test struct_ops maps with a large number of program links 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=c3080ecb-abb0-4d47-a8f5-607e7082b1ef@gmail.com \
    --to=sinquersw@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuifeng@meta.com \
    --cc=martin.lau@linux.dev \
    --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