bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Network Development <netdev@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>, Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v4 bpf-next 2/9] bpf: Add map side support for bpf timers.
Date: Sun, 4 Jul 2021 07:23:19 -0700	[thread overview]
Message-ID: <CAADnVQL=BXwNUSjjj8t0B6yenC32-Me_B7BLsLv9pfOeg5mkfg@mail.gmail.com> (raw)
In-Reply-To: <20210702062343.dblrnycfwzjch6py@kafai-mbp.dhcp.thefacebook.com>

On Thu, Jul 1, 2021 at 11:23 PM Martin KaFai Lau <kafai@fb.com> wrote:
>
> On Thu, Jul 01, 2021 at 12:20:37PM -0700, Alexei Starovoitov wrote:
> [ ... ]
>
> > +static void htab_free_prealloced_timers(struct bpf_htab *htab)
> > +{
> > +     u32 num_entries = htab->map.max_entries;
> > +     int i;
> > +
> > +     if (likely(!map_value_has_timer(&htab->map)))
> > +             return;
> > +     if (htab_has_extra_elems(htab))
> > +             num_entries += num_possible_cpus();
> > +
> > +     for (i = 0; i < num_entries; i++) {
> > +             struct htab_elem *elem;
> > +
> > +             elem = get_htab_elem(htab, i);
> > +             bpf_timer_cancel_and_free(elem->key +
> > +                                       round_up(htab->map.key_size, 8) +
> > +                                       htab->map.timer_off);
> > +             cond_resched();
> > +     }
> > +}
> > +
> [ ... ]
>
> > +static void htab_free_malloced_timers(struct bpf_htab *htab)
> > +{
> > +     int i;
> > +
> > +     for (i = 0; i < htab->n_buckets; i++) {
> > +             struct hlist_nulls_head *head = select_bucket(htab, i);
> > +             struct hlist_nulls_node *n;
> > +             struct htab_elem *l;
> > +
> > +             hlist_nulls_for_each_entry(l, n, head, hash_node)
> It is called from map_release_uref() which is not under rcu.
> Either a bucket lock or rcu_read_lock is needed here.

yeah. rcu_read_lock should do it.

> Another question, can prealloc map does the same thing
> like here (i.e. walk the buckets) during map_release_uref()?

you mean instead of for (i = 0; i < num_entries; i++) ?
It can, but it's slower than for loop and there was already a precedent
with similar loop to free per-cpu bits.

  reply	other threads:[~2021-07-04 14:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01 19:20 [PATCH v4 bpf-next 0/9] bpf: Introduce BPF timers Alexei Starovoitov
2021-07-01 19:20 ` [PATCH v4 bpf-next 1/9] bpf: Introduce bpf timers Alexei Starovoitov
2021-07-02  1:04   ` Martin KaFai Lau
2021-07-04 14:19     ` Alexei Starovoitov
2021-07-07  1:38       ` Alexei Starovoitov
2021-07-06 13:57   ` luwei (O)
2021-07-06 15:44     ` Toke Høiland-Jørgensen
2021-07-01 19:20 ` [PATCH v4 bpf-next 2/9] bpf: Add map side support for " Alexei Starovoitov
2021-07-02  6:23   ` Martin KaFai Lau
2021-07-04 14:23     ` Alexei Starovoitov [this message]
2021-07-01 19:20 ` [PATCH v4 bpf-next 3/9] bpf: Prevent pointer mismatch in bpf_timer_init Alexei Starovoitov
2021-07-01 19:20 ` [PATCH v4 bpf-next 4/9] bpf: Remember BTF of inner maps Alexei Starovoitov
2021-07-01 19:20 ` [PATCH v4 bpf-next 5/9] bpf: Relax verifier recursion check Alexei Starovoitov
2021-07-01 19:20 ` [PATCH v4 bpf-next 6/9] bpf: Implement verifier support for validation of async callbacks Alexei Starovoitov
2021-07-01 19:20 ` [PATCH v4 bpf-next 7/9] bpf: Teach stack depth check about " Alexei Starovoitov
2021-07-01 19:20 ` [PATCH v4 bpf-next 8/9] selftests/bpf: Add bpf_timer test Alexei Starovoitov
2021-07-01 19:20 ` [PATCH v4 bpf-next 9/9] selftests/bpf: Add a test with bpf_timer in inner map Alexei Starovoitov

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='CAADnVQL=BXwNUSjjj8t0B6yenC32-Me_B7BLsLv9pfOeg5mkfg@mail.gmail.com' \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.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;
as well as URLs for NNTP newsgroup(s).