From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Hou Tao <houtao@huaweicloud.com>, bpf@vger.kernel.org
Cc: "Martin KaFai Lau" <martin.lau@linux.dev>,
"Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Song Liu" <song@kernel.org>, "Hao Luo" <haoluo@google.com>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Jiri Olsa" <jolsa@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Thomas Weißschuh" <linux@weissschuh.net>,
houtao1@huawei.com, xukuohai@huawei.com
Subject: Re: [PATCH bpf-next 04/10] bpf: Handle in-place update for full LPM trie correctly
Date: Thu, 21 Nov 2024 11:53:58 +0100 [thread overview]
Message-ID: <878qtcj1rt.fsf@toke.dk> (raw)
In-Reply-To: <20241118010808.2243555-5-houtao@huaweicloud.com>
Hou Tao <houtao@huaweicloud.com> writes:
> From: Hou Tao <houtao1@huawei.com>
>
> When a LPM trie is full, in-place updates of existing elements
> incorrectly return -ENOSPC.
>
> Fix this by deferring the check of trie->n_entries. For new insertions,
> n_entries must not exceed max_entries. However, in-place updates are
> allowed even when the trie is full.
>
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
> kernel/bpf/lpm_trie.c | 46 +++++++++++++++++++++----------------------
> 1 file changed, 23 insertions(+), 23 deletions(-)
>
> diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c
> index 4300bd51ec6e..ff57e35357ae 100644
> --- a/kernel/bpf/lpm_trie.c
> +++ b/kernel/bpf/lpm_trie.c
> @@ -310,6 +310,15 @@ static struct lpm_trie_node *lpm_trie_node_alloc(const struct lpm_trie *trie,
> return node;
> }
>
> +static int trie_check_noreplace_update(const struct lpm_trie *trie, u64 flags)
I think this function name is hard to parse (took me a few tries). How
about trie_check_add_entry() instead?
> +{
> + if (flags == BPF_EXIST)
> + return -ENOENT;
> + if (trie->n_entries == trie->map.max_entries)
> + return -ENOSPC;
The calls to this function are always paired with a trie->n_entries++; -
so how about moving that into the function after the checks? You'll have
to then add a decrement if the im_node allocation fails, but I think
that is still clearer than having the n_entries++ statements scattered
around the function.
-Toke
next prev parent reply other threads:[~2024-11-21 10:54 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 1:07 [PATCH bpf-next 00/10] Fixes for LPM trie Hou Tao
2024-11-18 1:07 ` [PATCH bpf-next 01/10] bpf: Remove unnecessary check when updating " Hou Tao
2024-11-21 10:22 ` Toke Høiland-Jørgensen
2024-11-18 1:08 ` [PATCH bpf-next 02/10] bpf: Remove unnecessary kfree(im_node) in lpm_trie_update_elem Hou Tao
2024-11-21 10:25 ` Toke Høiland-Jørgensen
2024-11-18 1:08 ` [PATCH bpf-next 03/10] bpf: Handle BPF_EXIST and BPF_NOEXIST for LPM trie Hou Tao
2024-11-18 13:39 ` Thomas Weißschuh
2024-11-19 1:08 ` Hou Tao
2024-11-21 10:32 ` Toke Høiland-Jørgensen
2024-11-18 1:08 ` [PATCH bpf-next 04/10] bpf: Handle in-place update for full LPM trie correctly Hou Tao
2024-11-18 13:13 ` Sebastian Andrzej Siewior
2024-11-19 1:05 ` Hou Tao
2024-11-21 10:53 ` Toke Høiland-Jørgensen [this message]
2024-11-22 2:06 ` Hou Tao
2024-11-18 1:08 ` [PATCH bpf-next 05/10] bpf: Fix exact match conditions in trie_get_next_key() Hou Tao
2024-11-21 11:01 ` Toke Høiland-Jørgensen
2024-11-18 1:08 ` [PATCH bpf-next 06/10] bpf: Add bpf_mem_cache_is_mergeable() helper Hou Tao
2024-11-18 13:29 ` Thomas Weißschuh
2024-11-19 1:06 ` Hou Tao
2024-11-18 1:08 ` [PATCH bpf-next 07/10] bpf: Switch to bpf mem allocator for LPM trie Hou Tao
2024-11-18 13:30 ` Sebastian Andrzej Siewior
2024-11-18 16:56 ` Yonghong Song
2024-11-20 1:16 ` Alexei Starovoitov
2024-11-21 1:20 ` Hou Tao
2024-11-23 3:29 ` Alexei Starovoitov
2024-11-21 11:39 ` Toke Høiland-Jørgensen
2024-11-21 11:52 ` Thomas Weißschuh
2024-11-21 12:50 ` Toke Høiland-Jørgensen
2024-11-22 3:36 ` Hou Tao
2024-11-18 1:08 ` [PATCH bpf-next 08/10] bpf: Use raw_spinlock_t " Hou Tao
2024-11-18 1:08 ` [PATCH bpf-next 09/10] selftests/bpf: Move test_lpm_map.c to map_tests Hou Tao
2024-11-18 1:08 ` [PATCH bpf-next 10/10] selftests/bpf: Add more test cases for LPM trie Hou Tao
2024-11-18 17:46 ` Daniel Borkmann
2024-11-19 1:10 ` Hou Tao
[not found] ` <46268aa9ef13a24388af833b17f6cef8bdd3a7be8402fec7640e65a2f1118468@mail.kernel.org>
2024-11-18 6:20 ` [PATCH bpf-next 00/10] Fixes " Hou Tao
2024-11-18 17:43 ` Daniel Xu
2024-11-19 1:09 ` Hou Tao
2024-11-18 15:39 ` Sebastian Andrzej Siewior
2024-11-19 1:35 ` Hou Tao
2024-11-19 14:15 ` Sebastian Andrzej Siewior
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=878qtcj1rt.fsf@toke.dk \
--to=toke@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=houtao1@huawei.com \
--cc=houtao@huaweicloud.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux@weissschuh.net \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=tglx@linutronix.de \
--cc=xukuohai@huawei.com \
--cc=yonghong.song@linux.dev \
/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