From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, me@ubique.spb.ru,
Florian Westphal <fw@strlen.de>
Subject: [PATCH RFC nf-next 7/9] netfilter: core: do not rebuild bpf program on dying netns
Date: Thu, 14 Oct 2021 14:10:44 +0200 [thread overview]
Message-ID: <20211014121046.29329-9-fw@strlen.de> (raw)
In-Reply-To: <20211014121046.29329-1-fw@strlen.de>
We can save a few cycles on netns destruction.
When a hook is removed we can just skip building a new
program with the remaining hooks, those will be removed too
in the immediate future.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/core.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 56d82822cab7..9a19d4f1673b 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -251,6 +251,7 @@ EXPORT_SYMBOL_GPL(nf_hook_entries_insert_raw);
*
* @old -- current hook blob at @pp
* @pp -- location of hook blob
+ * @recompile -- false if bpf prog should not be replaced
*
* Hook unregistration must always succeed, so to-be-removed hooks
* are replaced by a dummy one that will just move to next hook.
@@ -263,7 +264,8 @@ EXPORT_SYMBOL_GPL(nf_hook_entries_insert_raw);
* Returns address to free, or NULL.
*/
static void *__nf_hook_entries_try_shrink(struct nf_hook_entries *old,
- struct nf_hook_entries __rcu **pp)
+ struct nf_hook_entries __rcu **pp,
+ bool recompile)
{
unsigned int i, j, skip = 0, hook_entries;
struct bpf_prog *hook_bpf_prog = NULL;
@@ -311,10 +313,12 @@ static void *__nf_hook_entries_try_shrink(struct nf_hook_entries *old,
hooks_validate(new);
#if IS_ENABLED(CONFIG_NF_HOOK_BPF)
- /* if this fails fallback prog calls nf_hook_slow. */
- hook_bpf_prog = nf_hook_bpf_create(new);
- if (hook_bpf_prog)
- new->hook_prog = hook_bpf_prog;
+ if (recompile) {
+ /* if this fails fallback prog calls nf_hook_slow. */
+ hook_bpf_prog = nf_hook_bpf_create(new);
+ if (hook_bpf_prog)
+ new->hook_prog = hook_bpf_prog;
+ }
#endif
out_assign:
nf_hook_bpf_change_prog(BPF_DISPATCHER_PTR(nf_hook_base),
@@ -540,7 +544,7 @@ static void __nf_unregister_net_hook(struct net *net, int pf,
WARN_ONCE(1, "hook not found, pf %d num %d", pf, reg->hooknum);
}
- p = __nf_hook_entries_try_shrink(p, pp);
+ p = __nf_hook_entries_try_shrink(p, pp, check_net(net));
mutex_unlock(&nf_hook_mutex);
if (!p)
return;
@@ -571,7 +575,7 @@ void nf_hook_entries_delete_raw(struct nf_hook_entries __rcu **pp,
p = rcu_dereference_raw(*pp);
if (nf_remove_net_hook(p, reg)) {
- p = __nf_hook_entries_try_shrink(p, pp);
+ p = __nf_hook_entries_try_shrink(p, pp, false);
nf_hook_entries_free(p);
}
}
--
2.32.0
next prev parent reply other threads:[~2021-10-14 12:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-14 12:10 [PATCH RFC nf-next 0/9] netfilter: bpf base hook program generator Florian Westphal
2021-10-14 12:10 ` [PATCH 1/1] netfilter: add " Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 1/9] netfilter: nf_queue: carry index in hook state Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 2/9] netfilter: nat: split nat hook iteration into a helper Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 3/9] netfilter: remove hook index from nf_hook_slow arguments Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 4/9] netfilter: make hook functions accept only one argument Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 5/9] netfilter: reduce allowed hook count to 32 Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 6/9] netfilter: add bpf base hook program generator Florian Westphal
2021-10-14 12:10 ` Florian Westphal [this message]
2021-10-14 12:10 ` [PATCH RFC nf-next 8/9] netfilter: ingress: switch to invocation via bpf Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 9/9] netfilter: hook_jit: add prog cache Florian Westphal
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=20211014121046.29329-9-fw@strlen.de \
--to=fw@strlen.de \
--cc=bpf@vger.kernel.org \
--cc=me@ubique.spb.ru \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@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).