bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>, 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,
	quentin@isovalent.com
Subject: Re: [PATCH bpf-next v4 3/6] libbpf: Convert st_ops->data to shadow type.
Date: Mon, 26 Feb 2024 16:19:37 -0800	[thread overview]
Message-ID: <7f33c7dc-b2bc-48e8-840e-bfd3de5845da@gmail.com> (raw)
In-Reply-To: <0d8d82e5-c55a-4f6f-ba92-3d169daedc8c@linux.dev>



On 2/26/24 14:57, Martin KaFai Lau wrote:
> On 2/22/24 2:26 PM, thinker.li@gmail.com wrote:
>> +/* Convert the data of a struct_ops map to shadow type.
>> + *
>> + * The function pointers are replaced with the pointers of 
>> bpf_program in
>> + * st_ops->progs[].
>> + */
>> +static void struct_ops_convert_shadow(struct bpf_map *map,
>> +                      const struct btf_type *t)
>> +{
>> +    struct btf *btf = map->obj->btf;
>> +    struct bpf_struct_ops *st_ops = map->st_ops;
>> +    const struct btf_member *m;
>> +    const struct btf_type *mtype;
>> +    char *data;
>> +    int i;
>> +
>> +    data = st_ops->data;
>> +
>> +    for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
>> +        mtype = skip_mods_and_typedefs(btf, m->type, NULL);
>> +
>> +        if (btf_kind(mtype) != BTF_KIND_PTR)
>> +            continue;
>> +        if (!resolve_func_ptr(btf, m->type, NULL))
>> +            continue;
>> +
>> +        *((struct bpf_program **)(data + m->offset / 8)) =
>> +            st_ops->progs[i];
> 
> This is to initialize the bpf_program pointer in the st_ops->data.
> Can this be done directly at the bpf_object__collect_st_ops_relos()?

No problem!

> 
>> +    }
>> +}
>> +
> 

  reply	other threads:[~2024-02-27  0:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22 22:26 [PATCH bpf-next v4 0/6] Create shadow types for struct_ops maps in skeletons thinker.li
2024-02-22 22:26 ` [PATCH bpf-next v4 1/6] libbpf: expose resolve_func_ptr() through libbpf_internal.h thinker.li
2024-02-22 22:26 ` [PATCH bpf-next v4 2/6] libbpf: set btf_value_type_id of struct bpf_map for struct_ops thinker.li
2024-02-22 22:26 ` [PATCH bpf-next v4 3/6] libbpf: Convert st_ops->data to shadow type thinker.li
2024-02-26 22:57   ` Martin KaFai Lau
2024-02-27  0:19     ` Kui-Feng Lee [this message]
2024-02-22 22:26 ` [PATCH bpf-next v4 4/6] bpftool: generated shadow variables for struct_ops maps thinker.li
2024-02-22 22:26 ` [PATCH bpf-next v4 5/6] bpftool: Add an example for struct_ops map and shadow type thinker.li
2024-02-22 22:26 ` [PATCH bpf-next v4 6/6] selftests/bpf: Test if shadow types work correctly thinker.li

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=7f33c7dc-b2bc-48e8-840e-bfd3de5845da@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=quentin@isovalent.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;
as well as URLs for NNTP newsgroup(s).