OSDN Git Service

netfilter: core: free hooks with call_rcu
authorFlorian Westphal <fw@strlen.de>
Thu, 30 Nov 2017 23:21:04 +0000 (00:21 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 8 Jan 2018 17:01:07 +0000 (18:01 +0100)
commit8c873e2199700c2de7dbd5eedb9d90d5f109462b
tree7c7a2d4d7853659a19a36a725767871351a7aedf
parent26888dfd7e7454686b8d3ea9ba5045d5f236e4d7
netfilter: core: free hooks with call_rcu

Giuseppe Scrivano says:
  "SELinux, if enabled, registers for each new network namespace 6
    netfilter hooks."

Cost for this is high.  With synchronize_net() removed:
   "The net benefit on an SMP machine with two cores is that creating a
   new network namespace takes -40% of the original time."

This patch replaces synchronize_net+kvfree with call_rcu().
We store rcu_head at the tail of a structure that has no fixed layout,
i.e. we cannot use offsetof() to compute the start of the original
allocation.  Thus store this information right after the rcu head.

We could simplify this by just placing the rcu_head at the start
of struct nf_hook_entries.  However, this structure is used in
packet processing hotpath, so only place what is needed for that
at the beginning of the struct.

Reported-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/linux/netfilter.h
net/netfilter/core.c