{"id":809449,"url":"http://patchwork.ozlabs.org/api/1.2/patches/809449/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/1504478574-13281-8-git-send-email-pablo@netfilter.org/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.2/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504478574-13281-8-git-send-email-pablo@netfilter.org>","list_archive_url":null,"date":"2017-09-03T22:42:50","name":"[43/47] netfilter: core: batch nf_unregister_net_hooks synchronize_net calls","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"1a886bb7506bc299736c9779128118a2846be2c9","submitter":{"id":1315,"url":"http://patchwork.ozlabs.org/api/1.2/people/1315/?format=json","name":"Pablo Neira Ayuso","email":"pablo@netfilter.org"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/1.2/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/1504478574-13281-8-git-send-email-pablo@netfilter.org/mbox/","series":[{"id":1283,"url":"http://patchwork.ozlabs.org/api/1.2/series/1283/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=1283","date":"2017-09-03T22:40:11","name":null,"version":1,"mbox":"http://patchwork.ozlabs.org/series/1283/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/809449/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/809449/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xlp1J30kGz9s06\n\tfor <patchwork-incoming@ozlabs.org>;\n\tMon,  4 Sep 2017 08:43:48 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753411AbdICWnj (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tSun, 3 Sep 2017 18:43:39 -0400","from mail.us.es ([193.147.175.20]:53066 \"EHLO mail.us.es\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1753503AbdICWnN (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tSun, 3 Sep 2017 18:43:13 -0400","from antivirus1-rhel7.int (unknown [192.168.2.11])\n\tby mail.us.es (Postfix) with ESMTP id 2578C190F63\n\tfor <netdev@vger.kernel.org>; Mon,  4 Sep 2017 00:42:47 +0200 (CEST)","from antivirus1-rhel7.int (localhost [127.0.0.1])\n\tby antivirus1-rhel7.int (Postfix) with ESMTP id 152962DC85\n\tfor <netdev@vger.kernel.org>; Mon,  4 Sep 2017 00:42:47 +0200 (CEST)","by antivirus1-rhel7.int (Postfix, from userid 99)\n\tid 0A9812DC84; Mon,  4 Sep 2017 00:42:47 +0200 (CEST)","from antivirus1-rhel7.int (localhost [127.0.0.1])\n\tby antivirus1-rhel7.int (Postfix) with ESMTP id 08BA2B5027;\n\tMon,  4 Sep 2017 00:42:45 +0200 (CEST)","from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int\n\t(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); \n\tMon, 04 Sep 2017 00:42:45 +0200 (CEST)","from salvia.here (unknown [31.4.193.113])\n\t(Authenticated sender: pneira@us.es)\n\tby entrada.int (Postfix) with ESMTPA id B02EB4265A20;\n\tMon,  4 Sep 2017 00:42:44 +0200 (CEST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.1 (2015-04-28) on\n\tantivirus1-rhel7.int","X-Spam-Level":"","X-Spam-Status":"No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50,\n\tSMTPAUTH_US2,USER_IN_WHITELIST autolearn=disabled version=3.4.1","X-Virus-Status":"clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int)","X-SMTPAUTHUS":"auth mail.us.es","From":"Pablo Neira Ayuso <pablo@netfilter.org>","To":"netfilter-devel@vger.kernel.org","Cc":"davem@davemloft.net, netdev@vger.kernel.org","Subject":"[PATCH 43/47] netfilter: core: batch nf_unregister_net_hooks\n\tsynchronize_net calls","Date":"Mon,  4 Sep 2017 00:42:50 +0200","Message-Id":"<1504478574-13281-8-git-send-email-pablo@netfilter.org>","X-Mailer":"git-send-email 2.1.4","In-Reply-To":"<1504478574-13281-1-git-send-email-pablo@netfilter.org>","References":"<1504478574-13281-1-git-send-email-pablo@netfilter.org>","X-Virus-Scanned":"ClamAV using ClamSMTP","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"From: Florian Westphal <fw@strlen.de>\n\nre-add batching in nf_unregister_net_hooks().\n\nSimilar as before, just store an array with to-be-free'd rule arrays\non stack, then call synchronize_net once per batch.\n\nSigned-off-by: Florian Westphal <fw@strlen.de>\nSigned-off-by: Pablo Neira Ayuso <pablo@netfilter.org>\n---\n net/netfilter/core.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 56 insertions(+), 3 deletions(-)","diff":"diff --git a/net/netfilter/core.c b/net/netfilter/core.c\nindex 164ad20d0bd2..04fe25abc5f6 100644\n--- a/net/netfilter/core.c\n+++ b/net/netfilter/core.c\n@@ -395,10 +395,63 @@ EXPORT_SYMBOL(nf_register_net_hooks);\n void nf_unregister_net_hooks(struct net *net, const struct nf_hook_ops *reg,\n \t\t\t     unsigned int hookcount)\n {\n-\tunsigned int i;\n+\tstruct nf_hook_entries *to_free[16], *p;\n+\tstruct nf_hook_entries __rcu **pp;\n+\tunsigned int i, j, n;\n+\n+\tmutex_lock(&nf_hook_mutex);\n+\tfor (i = 0; i < hookcount; i++) {\n+\t\tpp = nf_hook_entry_head(net, &reg[i]);\n+\t\tif (!pp)\n+\t\t\tcontinue;\n+\n+\t\tp = nf_entry_dereference(*pp);\n+\t\tif (WARN_ON_ONCE(!p))\n+\t\t\tcontinue;\n+\t\t__nf_unregister_net_hook(p, &reg[i]);\n+\t}\n+\tmutex_unlock(&nf_hook_mutex);\n+\n+\tdo {\n+\t\tn = min_t(unsigned int, hookcount, ARRAY_SIZE(to_free));\n+\n+\t\tmutex_lock(&nf_hook_mutex);\n+\n+\t\tfor (i = 0, j = 0; i < hookcount && j < n; i++) {\n+\t\t\tpp = nf_hook_entry_head(net, &reg[i]);\n+\t\t\tif (!pp)\n+\t\t\t\tcontinue;\n+\n+\t\t\tp = nf_entry_dereference(*pp);\n+\t\t\tif (!p)\n+\t\t\t\tcontinue;\n+\n+\t\t\tto_free[j] = __nf_hook_entries_try_shrink(pp);\n+\t\t\tif (to_free[j])\n+\t\t\t\t++j;\n+\t\t}\n+\n+\t\tmutex_unlock(&nf_hook_mutex);\n+\n+\t\tif (j) {\n+\t\t\tunsigned int nfq;\n+\n+\t\t\tsynchronize_net();\n+\n+\t\t\t/* need 2nd synchronize_net() if nfqueue is used, skb\n+\t\t\t * can get reinjected right before nf_queue_hook_drop()\n+\t\t\t */\n+\t\t\tnfq = nf_queue_nf_hook_drop(net);\n+\t\t\tif (nfq)\n+\t\t\t\tsynchronize_net();\n+\n+\t\t\tfor (i = 0; i < j; i++)\n+\t\t\t\tkvfree(to_free[i]);\n+\t\t}\n \n-\tfor (i = 0; i < hookcount; i++)\n-\t\tnf_unregister_net_hook(net, &reg[i]);\n+\t\treg += n;\n+\t\thookcount -= n;\n+\t} while (hookcount > 0);\n }\n EXPORT_SYMBOL(nf_unregister_net_hooks);\n \n","prefixes":["43/47"]}