public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>, Kui-Feng Lee <kuifeng@meta.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, song@kernel.org,
	kernel-team@meta.com, andrii@kernel.org, sdf@google.com
Subject: Re: [PATCH bpf-next v9 5/8] bpf: Update the struct_ops of a bpf_link.
Date: Tue, 21 Mar 2023 16:04:24 -0700	[thread overview]
Message-ID: <aa8b4ae3-9ea7-43cd-db57-4bd84f89ca96@gmail.com> (raw)
In-Reply-To: <9d370e0b-f57b-0a3e-9b1b-58930b0dfee1@linux.dev>



On 3/21/23 11:18, Martin KaFai Lau wrote:
> On 3/20/23 12:56 PM, Kui-Feng Lee wrote:
>> +static int bpf_struct_ops_map_link_update(struct bpf_link *link, 
>> struct bpf_map *new_map,
>> +                      struct bpf_map *expected_old_map)
>> +{
>> +    struct bpf_struct_ops_map *st_map, *old_st_map;
>> +    struct bpf_map *old_map;
>> +    struct bpf_struct_ops_link *st_link;
>> +    int err = 0;
>> +
>> +    st_link = container_of(link, struct bpf_struct_ops_link, link);
>> +    st_map = container_of(new_map, struct bpf_struct_ops_map, map);
>> +
>> +    if (!bpf_struct_ops_valid_to_reg(new_map))
>> +        return -EINVAL;
>> +
>> +    mutex_lock(&update_mutex);
>> +
>> +    old_map = rcu_dereference_protected(st_link->map, 
>> lockdep_is_held(&update_mutex));
>> +    if (expected_old_map && old_map != expected_old_map) {
>> +        err = -EINVAL;
>> +        goto err_out;
>> +    }
>> +
>> +    old_st_map = container_of(old_map, struct bpf_struct_ops_map, map);
>> +    /* The new and old struct_ops must be the same type. */
>> +    if (st_map->st_ops != old_st_map->st_ops) {
>> +        err = -EINVAL;
> 
> Other ".update_prog" implementation returns -EPERM. eg. take a look at 
> cgroup_bpf_replace().

Discussed offline.  For consistency, it will return -EPERM.

> 
>> +        goto err_out;
>> +    }
>> +
>> +    err = st_map->st_ops->update(st_map->kvalue.data, 
>> old_st_map->kvalue.data);
>> +    if (err)
>> +        goto err_out;
>> +
>> +    bpf_map_inc(new_map);
>> +    rcu_assign_pointer(st_link->map, new_map);
>> +    bpf_map_put(old_map);
>> +
>> +err_out:
>> +    mutex_unlock(&update_mutex);
>> +
>> +    return err;
>> +}
>> +
> 
> 

  reply	other threads:[~2023-03-21 23:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20 19:56 [PATCH bpf-next v9 0/8] Transit between BPF TCP congestion controls Kui-Feng Lee
2023-03-20 19:56 ` [PATCH bpf-next v9 1/8] bpf: Retire the struct_ops map kvalue->refcnt Kui-Feng Lee
2023-03-20 19:56 ` [PATCH bpf-next v9 2/8] net: Update an existing TCP congestion control algorithm Kui-Feng Lee
2023-03-20 19:56 ` [PATCH bpf-next v9 3/8] bpf: Create links for BPF struct_ops maps Kui-Feng Lee
2023-03-20 19:56 ` [PATCH bpf-next v9 4/8] libbpf: Create a bpf_link in bpf_map__attach_struct_ops() Kui-Feng Lee
2023-03-21 17:49   ` Martin KaFai Lau
2023-03-21 23:03     ` Kui-Feng Lee
2023-03-20 19:56 ` [PATCH bpf-next v9 5/8] bpf: Update the struct_ops of a bpf_link Kui-Feng Lee
2023-03-21 18:18   ` Martin KaFai Lau
2023-03-21 23:04     ` Kui-Feng Lee [this message]
2023-03-20 19:56 ` [PATCH bpf-next v9 6/8] libbpf: Update a bpf_link with another struct_ops Kui-Feng Lee
2023-03-21 21:04   ` Martin KaFai Lau
2023-03-21 23:04     ` Kui-Feng Lee
2023-03-20 19:56 ` [PATCH bpf-next v9 7/8] libbpf: Use .struct_ops.link section to indicate a struct_ops with a link Kui-Feng Lee
2023-03-20 19:56 ` [PATCH bpf-next v9 8/8] selftests/bpf: Test switching TCP Congestion Control algorithms Kui-Feng Lee
2023-03-21 21:05   ` Martin KaFai Lau
2023-03-21 23:05     ` Kui-Feng Lee
  -- strict thread matches above, loose matches on Subject: below --
2023-03-20 19:24 [PATCH bpf-next v9 0/8] Transit between BPF TCP congestion controls Kui-Feng Lee
2023-03-20 19:24 ` [PATCH bpf-next v9 5/8] bpf: Update the struct_ops of a bpf_link 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=aa8b4ae3-9ea7-43cd-db57-4bd84f89ca96@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=sdf@google.com \
    --cc=song@kernel.org \
    /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