2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-10-15 09:31:52 +00:00
|
|
|
/*
|
|
|
|
* inet fragments management
|
|
|
|
*
|
|
|
|
* Authors: Pavel Emelyanov <xemul@openvz.org>
|
|
|
|
* Started as consolidation of ipv4/ip_fragment.c,
|
|
|
|
* ipv6/reassembly. and ipv6 nf conntrack reassembly
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/mm.h>
|
2007-10-15 09:38:08 +00:00
|
|
|
#include <linux/random.h>
|
2007-10-15 09:39:14 +00:00
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2018-06-18 02:52:50 +00:00
|
|
|
#include <linux/rhashtable.h>
|
2007-10-15 09:31:52 +00:00
|
|
|
|
2013-03-15 11:32:30 +00:00
|
|
|
#include <net/sock.h>
|
2007-10-15 09:31:52 +00:00
|
|
|
#include <net/inet_frag.h>
|
2013-03-22 08:24:37 +00:00
|
|
|
#include <net/inet_ecn.h>
|
2019-01-22 18:02:50 +00:00
|
|
|
#include <net/ip.h>
|
|
|
|
#include <net/ipv6.h>
|
|
|
|
|
|
|
|
/* Use skb->cb to track consecutive/adjacent fragments coming at
|
|
|
|
* the end of the queue. Nodes in the rb-tree queue will
|
|
|
|
* contain "runs" of one or more adjacent fragments.
|
|
|
|
*
|
|
|
|
* Invariants:
|
|
|
|
* - next_frag is NULL at the tail of a "run";
|
|
|
|
* - the head of a "run" has the sum of all fragment lengths in frag_run_len.
|
|
|
|
*/
|
|
|
|
struct ipfrag_skb_cb {
|
|
|
|
union {
|
|
|
|
struct inet_skb_parm h4;
|
|
|
|
struct inet6_skb_parm h6;
|
|
|
|
};
|
|
|
|
struct sk_buff *next_frag;
|
|
|
|
int frag_run_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FRAG_CB(skb) ((struct ipfrag_skb_cb *)((skb)->cb))
|
|
|
|
|
|
|
|
static void fragcb_clear(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
RB_CLEAR_NODE(&skb->rbnode);
|
|
|
|
FRAG_CB(skb)->next_frag = NULL;
|
|
|
|
FRAG_CB(skb)->frag_run_len = skb->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append skb to the last "run". */
|
|
|
|
static void fragrun_append_to_last(struct inet_frag_queue *q,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
fragcb_clear(skb);
|
|
|
|
|
|
|
|
FRAG_CB(q->last_run_head)->frag_run_len += skb->len;
|
|
|
|
FRAG_CB(q->fragments_tail)->next_frag = skb;
|
|
|
|
q->fragments_tail = skb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new "run" with the skb. */
|
|
|
|
static void fragrun_create(struct inet_frag_queue *q, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
BUILD_BUG_ON(sizeof(struct ipfrag_skb_cb) > sizeof(skb->cb));
|
|
|
|
fragcb_clear(skb);
|
|
|
|
|
|
|
|
if (q->last_run_head)
|
|
|
|
rb_link_node(&skb->rbnode, &q->last_run_head->rbnode,
|
|
|
|
&q->last_run_head->rbnode.rb_right);
|
|
|
|
else
|
|
|
|
rb_link_node(&skb->rbnode, NULL, &q->rb_fragments.rb_node);
|
|
|
|
rb_insert_color(&skb->rbnode, &q->rb_fragments);
|
|
|
|
|
|
|
|
q->fragments_tail = skb;
|
|
|
|
q->last_run_head = skb;
|
|
|
|
}
|
2013-03-22 08:24:37 +00:00
|
|
|
|
|
|
|
/* Given the OR values of all fragments, apply RFC 3168 5.3 requirements
|
|
|
|
* Value : 0xff if frame should be dropped.
|
|
|
|
* 0 or INET_ECN_CE value, to be ORed in to final iph->tos field
|
|
|
|
*/
|
|
|
|
const u8 ip_frag_ecn_table[16] = {
|
|
|
|
/* at least one fragment had CE, and others ECT_0 or ECT_1 */
|
|
|
|
[IPFRAG_ECN_CE | IPFRAG_ECN_ECT_0] = INET_ECN_CE,
|
|
|
|
[IPFRAG_ECN_CE | IPFRAG_ECN_ECT_1] = INET_ECN_CE,
|
|
|
|
[IPFRAG_ECN_CE | IPFRAG_ECN_ECT_0 | IPFRAG_ECN_ECT_1] = INET_ECN_CE,
|
|
|
|
|
|
|
|
/* invalid combinations : drop frame */
|
|
|
|
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_CE] = 0xff,
|
|
|
|
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_ECT_0] = 0xff,
|
|
|
|
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_ECT_1] = 0xff,
|
|
|
|
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_ECT_0 | IPFRAG_ECN_ECT_1] = 0xff,
|
|
|
|
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_CE | IPFRAG_ECN_ECT_0] = 0xff,
|
|
|
|
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_CE | IPFRAG_ECN_ECT_1] = 0xff,
|
|
|
|
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_CE | IPFRAG_ECN_ECT_0 | IPFRAG_ECN_ECT_1] = 0xff,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL(ip_frag_ecn_table);
|
2007-10-15 09:31:52 +00:00
|
|
|
|
2014-08-01 10:29:48 +00:00
|
|
|
int inet_frags_init(struct inet_frags *f)
|
2007-10-15 09:31:52 +00:00
|
|
|
{
|
2014-08-01 10:29:48 +00:00
|
|
|
f->frags_cachep = kmem_cache_create(f->frags_cache_name, f->qsize, 0, 0,
|
|
|
|
NULL);
|
|
|
|
if (!f->frags_cachep)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-05-27 23:56:49 +00:00
|
|
|
refcount_set(&f->refcnt, 1);
|
|
|
|
init_completion(&f->completion);
|
2014-08-01 10:29:48 +00:00
|
|
|
return 0;
|
2007-10-15 09:31:52 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frags_init);
|
|
|
|
|
|
|
|
void inet_frags_fini(struct inet_frags *f)
|
|
|
|
{
|
2019-05-27 23:56:49 +00:00
|
|
|
if (refcount_dec_and_test(&f->refcnt))
|
|
|
|
complete(&f->completion);
|
|
|
|
|
|
|
|
wait_for_completion(&f->completion);
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
|
2014-08-01 10:29:48 +00:00
|
|
|
kmem_cache_destroy(f->frags_cachep);
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
f->frags_cachep = NULL;
|
2007-10-15 09:31:52 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frags_fini);
|
2007-10-15 09:37:18 +00:00
|
|
|
|
2019-05-24 16:03:40 +00:00
|
|
|
/* called from rhashtable_free_and_destroy() at netns_frags dismantle */
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
static void inet_frags_free_cb(void *ptr, void *arg)
|
2007-10-15 09:37:18 +00:00
|
|
|
{
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
struct inet_frag_queue *fq = ptr;
|
2019-05-24 16:03:40 +00:00
|
|
|
int count;
|
2014-07-24 14:50:36 +00:00
|
|
|
|
2019-05-24 16:03:40 +00:00
|
|
|
count = del_timer_sync(&fq->timer) ? 1 : 0;
|
net: frag queue per hash bucket locking
This patch implements per hash bucket locking for the frag queue
hash. This removes two write locks, and the only remaining write
lock is for protecting hash rebuild. This essentially reduce the
readers-writer lock to a rebuild lock.
This patch is part of "net: frag performance followup"
http://thread.gmane.org/gmane.linux.network/263644
of which two patches have already been accepted:
Same test setup as previous:
(http://thread.gmane.org/gmane.linux.network/257155)
Two 10G interfaces, on seperate NUMA nodes, are under-test, and uses
Ethernet flow-control. A third interface is used for generating the
DoS attack (with trafgen).
Notice, I have changed the frag DoS generator script to be more
efficient/deadly. Before it would only hit one RX queue, now its
sending packets causing multi-queue RX, due to "better" RX hashing.
Test types summary (netperf UDP_STREAM):
Test-20G64K == 2x10G with 65K fragments
Test-20G3F == 2x10G with 3x fragments (3*1472 bytes)
Test-20G64K+DoS == Same as 20G64K with frag DoS
Test-20G3F+DoS == Same as 20G3F with frag DoS
Test-20G64K+MQ == Same as 20G64K with Multi-Queue frag DoS
Test-20G3F+MQ == Same as 20G3F with Multi-Queue frag DoS
When I rebased this-patch(03) (on top of net-next commit a210576c) and
removed the _bh spinlock, I saw a performance regression. BUT this
was caused by some unrelated change in-between. See tests below.
Test (A) is what I reported before for patch-02, accepted in commit 1b5ab0de.
Test (B) verifying-retest of commit 1b5ab0de corrospond to patch-02.
Test (C) is what I reported before for this-patch
Test (D) is net-next master HEAD (commit a210576c), which reveals some
(unknown) performance regression (compared against test (B)).
Test (D) function as a new base-test.
Performance table summary (in Mbit/s):
(#) Test-type: 20G64K 20G3F 20G64K+DoS 20G3F+DoS 20G64K+MQ 20G3F+MQ
---------- ------- ------- ---------- --------- -------- -------
(A) Patch-02 : 18848.7 13230.1 4103.04 5310.36 130.0 440.2
(B) 1b5ab0de : 18841.5 13156.8 4101.08 5314.57 129.0 424.2
(C) Patch-03v1: 18838.0 13490.5 4405.11 6814.72 196.6 461.6
(D) a210576c : 18321.5 11250.4 3635.34 5160.13 119.1 405.2
(E) with _bh : 17247.3 11492.6 3994.74 6405.29 166.7 413.6
(F) without bh: 17471.3 11298.7 3818.05 6102.11 165.7 406.3
Test (E) and (F) is this-patch(03), with(V1) and without(V2) the _bh spinlocks.
I cannot explain the slow down for 20G64K (but its an artificial
"lab-test" so I'm not worried). But the other results does show
improvements. And test (E) "with _bh" version is slightly better.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Acked-by: Eric Dumazet <edumazet@google.com>
----
V2:
- By analysis from Hannes Frederic Sowa and Eric Dumazet, we don't
need the spinlock _bh versions, as Netfilter currently does a
local_bh_disable() before entering inet_fragment.
- Fold-in desc from cover-mail
V3:
- Drop the chain_len counter per hash bucket.
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-03 23:38:16 +00:00
|
|
|
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
spin_lock_bh(&fq->lock);
|
|
|
|
if (!(fq->flags & INET_FRAG_COMPLETE)) {
|
|
|
|
fq->flags |= INET_FRAG_COMPLETE;
|
2019-05-24 16:03:40 +00:00
|
|
|
count++;
|
|
|
|
} else if (fq->flags & INET_FRAG_HASH_DEAD) {
|
|
|
|
count++;
|
2014-07-24 14:50:36 +00:00
|
|
|
}
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
spin_unlock_bh(&fq->lock);
|
2014-07-24 14:50:36 +00:00
|
|
|
|
2019-05-24 16:03:40 +00:00
|
|
|
if (refcount_sub_and_test(count, &fq->refcnt))
|
|
|
|
inet_frag_destroy(fq);
|
2014-07-24 14:50:36 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 16:03:40 +00:00
|
|
|
static void fqdir_rwork_fn(struct work_struct *work)
|
2014-07-24 14:50:36 +00:00
|
|
|
{
|
2019-05-24 16:03:40 +00:00
|
|
|
struct fqdir *fqdir = container_of(to_rcu_work(work),
|
|
|
|
struct fqdir, destroy_rwork);
|
2019-05-27 23:56:49 +00:00
|
|
|
struct inet_frags *f = fqdir->f;
|
2014-07-24 14:50:36 +00:00
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
rhashtable_free_and_destroy(&fqdir->rhashtable, inet_frags_free_cb, NULL);
|
2019-05-27 23:56:49 +00:00
|
|
|
|
|
|
|
/* We need to make sure all ongoing call_rcu(..., inet_frag_destroy_rcu)
|
|
|
|
* have completed, since they need to dereference fqdir.
|
|
|
|
* Would it not be nice to have kfree_rcu_barrier() ? :)
|
|
|
|
*/
|
|
|
|
rcu_barrier();
|
|
|
|
|
|
|
|
if (refcount_dec_and_test(&f->refcnt))
|
|
|
|
complete(&f->completion);
|
|
|
|
|
2019-05-24 16:03:39 +00:00
|
|
|
kfree(fqdir);
|
2007-10-15 09:37:18 +00:00
|
|
|
}
|
2019-05-24 16:03:40 +00:00
|
|
|
|
2019-05-27 23:56:47 +00:00
|
|
|
int fqdir_init(struct fqdir **fqdirp, struct inet_frags *f, struct net *net)
|
|
|
|
{
|
|
|
|
struct fqdir *fqdir = kzalloc(sizeof(*fqdir), GFP_KERNEL);
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (!fqdir)
|
|
|
|
return -ENOMEM;
|
|
|
|
fqdir->f = f;
|
|
|
|
fqdir->net = net;
|
|
|
|
res = rhashtable_init(&fqdir->rhashtable, &fqdir->f->rhash_params);
|
|
|
|
if (res < 0) {
|
|
|
|
kfree(fqdir);
|
|
|
|
return res;
|
|
|
|
}
|
2019-05-27 23:56:49 +00:00
|
|
|
refcount_inc(&f->refcnt);
|
2019-05-27 23:56:47 +00:00
|
|
|
*fqdirp = fqdir;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fqdir_init);
|
|
|
|
|
2019-05-24 16:03:40 +00:00
|
|
|
void fqdir_exit(struct fqdir *fqdir)
|
|
|
|
{
|
|
|
|
fqdir->high_thresh = 0; /* prevent creation of new frags */
|
|
|
|
|
2019-05-29 05:40:26 +00:00
|
|
|
fqdir->dead = true;
|
|
|
|
|
|
|
|
/* call_rcu is supposed to provide memory barrier semantics,
|
|
|
|
* separating the setting of fqdir->dead with the destruction
|
|
|
|
* work. This implicit barrier is paired with inet_frag_kill().
|
2019-05-24 16:03:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
INIT_RCU_WORK(&fqdir->destroy_rwork, fqdir_rwork_fn);
|
|
|
|
queue_rcu_work(system_wq, &fqdir->destroy_rwork);
|
|
|
|
|
|
|
|
}
|
2019-05-24 16:03:31 +00:00
|
|
|
EXPORT_SYMBOL(fqdir_exit);
|
2007-10-15 09:37:18 +00:00
|
|
|
|
2018-03-31 19:58:44 +00:00
|
|
|
void inet_frag_kill(struct inet_frag_queue *fq)
|
2007-10-15 09:37:18 +00:00
|
|
|
{
|
|
|
|
if (del_timer(&fq->timer))
|
2017-06-30 10:08:07 +00:00
|
|
|
refcount_dec(&fq->refcnt);
|
2007-10-15 09:37:18 +00:00
|
|
|
|
2014-08-01 10:29:44 +00:00
|
|
|
if (!(fq->flags & INET_FRAG_COMPLETE)) {
|
2019-05-24 16:03:30 +00:00
|
|
|
struct fqdir *fqdir = fq->fqdir;
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
|
|
|
|
fq->flags |= INET_FRAG_COMPLETE;
|
2019-05-24 16:03:40 +00:00
|
|
|
rcu_read_lock();
|
2019-05-29 05:40:26 +00:00
|
|
|
/* The RCU read lock provides a memory barrier
|
|
|
|
* guaranteeing that if fqdir->dead is false then
|
|
|
|
* the hash table destruction will not start until
|
|
|
|
* after we unlock. Paired with inet_frags_exit_net().
|
2019-05-24 16:03:40 +00:00
|
|
|
*/
|
2019-05-29 05:40:26 +00:00
|
|
|
if (!fqdir->dead) {
|
2019-05-24 16:03:40 +00:00
|
|
|
rhashtable_remove_fast(&fqdir->rhashtable, &fq->node,
|
|
|
|
fqdir->f->rhash_params);
|
|
|
|
refcount_dec(&fq->refcnt);
|
|
|
|
} else {
|
|
|
|
fq->flags |= INET_FRAG_HASH_DEAD;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2007-10-15 09:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frag_kill);
|
2007-10-15 09:39:14 +00:00
|
|
|
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
static void inet_frag_destroy_rcu(struct rcu_head *head)
|
|
|
|
{
|
|
|
|
struct inet_frag_queue *q = container_of(head, struct inet_frag_queue,
|
|
|
|
rcu);
|
2019-05-24 16:03:30 +00:00
|
|
|
struct inet_frags *f = q->fqdir->f;
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
|
|
|
|
if (f->destructor)
|
|
|
|
f->destructor(q);
|
|
|
|
kmem_cache_free(f->frags_cachep, q);
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:02:50 +00:00
|
|
|
unsigned int inet_frag_rbtree_purge(struct rb_root *root)
|
|
|
|
{
|
|
|
|
struct rb_node *p = rb_first(root);
|
|
|
|
unsigned int sum = 0;
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
struct sk_buff *skb = rb_entry(p, struct sk_buff, rbnode);
|
|
|
|
|
|
|
|
p = rb_next(p);
|
|
|
|
rb_erase(&skb->rbnode, root);
|
|
|
|
while (skb) {
|
|
|
|
struct sk_buff *next = FRAG_CB(skb)->next_frag;
|
|
|
|
|
|
|
|
sum += skb->truesize;
|
|
|
|
kfree_skb(skb);
|
|
|
|
skb = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frag_rbtree_purge);
|
|
|
|
|
2018-03-31 19:58:44 +00:00
|
|
|
void inet_frag_destroy(struct inet_frag_queue *q)
|
2007-10-15 09:39:14 +00:00
|
|
|
{
|
2019-05-24 16:03:30 +00:00
|
|
|
struct fqdir *fqdir;
|
2013-01-28 23:45:12 +00:00
|
|
|
unsigned int sum, sum_truesize = 0;
|
2018-03-31 19:58:44 +00:00
|
|
|
struct inet_frags *f;
|
2007-10-15 09:39:14 +00:00
|
|
|
|
2014-08-01 10:29:44 +00:00
|
|
|
WARN_ON(!(q->flags & INET_FRAG_COMPLETE));
|
2008-07-26 04:43:18 +00:00
|
|
|
WARN_ON(del_timer(&q->timer) != 0);
|
2007-10-15 09:39:14 +00:00
|
|
|
|
|
|
|
/* Release all fragment data. */
|
2019-05-24 16:03:30 +00:00
|
|
|
fqdir = q->fqdir;
|
|
|
|
f = fqdir->f;
|
2019-02-26 01:43:46 +00:00
|
|
|
sum_truesize = inet_frag_rbtree_purge(&q->rb_fragments);
|
2013-01-28 23:45:12 +00:00
|
|
|
sum = sum_truesize + f->qsize;
|
2007-10-15 09:39:14 +00:00
|
|
|
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
call_rcu(&q->rcu, inet_frag_destroy_rcu);
|
2015-07-23 10:05:39 +00:00
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
sub_frag_mem_limit(fqdir, sum);
|
2007-10-15 09:39:14 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frag_destroy);
|
2007-10-15 09:40:06 +00:00
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
static struct inet_frag_queue *inet_frag_alloc(struct fqdir *fqdir,
|
2014-08-01 10:29:46 +00:00
|
|
|
struct inet_frags *f,
|
|
|
|
void *arg)
|
2007-10-18 02:45:23 +00:00
|
|
|
{
|
|
|
|
struct inet_frag_queue *q;
|
|
|
|
|
2014-08-01 10:29:48 +00:00
|
|
|
q = kmem_cache_zalloc(f->frags_cachep, GFP_ATOMIC);
|
2015-04-03 08:17:26 +00:00
|
|
|
if (!q)
|
2007-10-18 02:45:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
q->fqdir = fqdir;
|
2007-10-18 02:46:47 +00:00
|
|
|
f->constructor(q, arg);
|
2019-05-24 16:03:30 +00:00
|
|
|
add_frag_mem_limit(fqdir, f->qsize);
|
2013-01-28 23:45:12 +00:00
|
|
|
|
2017-10-17 00:29:20 +00:00
|
|
|
timer_setup(&q->timer, f->frag_expire, 0);
|
2007-10-18 02:45:23 +00:00
|
|
|
spin_lock_init(&q->lock);
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
refcount_set(&q->refcnt, 3);
|
2007-10-18 02:45:23 +00:00
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
2007-10-18 02:46:47 +00:00
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
static struct inet_frag_queue *inet_frag_create(struct fqdir *fqdir,
|
2018-11-09 01:34:27 +00:00
|
|
|
void *arg,
|
|
|
|
struct inet_frag_queue **prev)
|
2007-10-18 02:46:47 +00:00
|
|
|
{
|
2019-05-24 16:03:30 +00:00
|
|
|
struct inet_frags *f = fqdir->f;
|
2007-10-18 02:46:47 +00:00
|
|
|
struct inet_frag_queue *q;
|
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
q = inet_frag_alloc(fqdir, f, arg);
|
2018-11-09 01:34:27 +00:00
|
|
|
if (!q) {
|
|
|
|
*prev = ERR_PTR(-ENOMEM);
|
2007-10-18 02:46:47 +00:00
|
|
|
return NULL;
|
2018-11-09 01:34:27 +00:00
|
|
|
}
|
2019-05-24 16:03:30 +00:00
|
|
|
mod_timer(&q->timer, jiffies + fqdir->timeout);
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
*prev = rhashtable_lookup_get_insert_key(&fqdir->rhashtable, &q->key,
|
2018-11-09 01:34:27 +00:00
|
|
|
&q->node, f->rhash_params);
|
|
|
|
if (*prev) {
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
q->flags |= INET_FRAG_COMPLETE;
|
|
|
|
inet_frag_kill(q);
|
|
|
|
inet_frag_destroy(q);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return q;
|
2007-10-18 02:46:47 +00:00
|
|
|
}
|
2007-10-18 02:47:21 +00:00
|
|
|
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
/* TODO : call from rcu_read_lock() and no longer use refcount_inc_not_zero() */
|
2019-05-24 16:03:30 +00:00
|
|
|
struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key)
|
2007-10-18 02:47:21 +00:00
|
|
|
{
|
2018-11-09 01:34:27 +00:00
|
|
|
struct inet_frag_queue *fq = NULL, *prev;
|
2007-10-18 02:47:21 +00:00
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
if (!fqdir->high_thresh || frag_mem_limit(fqdir) > fqdir->high_thresh)
|
2018-07-31 03:09:11 +00:00
|
|
|
return NULL;
|
|
|
|
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
rcu_read_lock();
|
2014-07-24 14:50:35 +00:00
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
prev = rhashtable_lookup(&fqdir->rhashtable, key, fqdir->f->rhash_params);
|
2018-11-09 01:34:27 +00:00
|
|
|
if (!prev)
|
2019-05-24 16:03:30 +00:00
|
|
|
fq = inet_frag_create(fqdir, key, &prev);
|
2018-11-09 01:34:27 +00:00
|
|
|
if (prev && !IS_ERR(prev)) {
|
|
|
|
fq = prev;
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
if (!refcount_inc_not_zero(&fq->refcnt))
|
|
|
|
fq = NULL;
|
2014-07-24 14:50:35 +00:00
|
|
|
}
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 19:58:49 +00:00
|
|
|
rcu_read_unlock();
|
2018-11-09 01:34:27 +00:00
|
|
|
return fq;
|
2007-10-18 02:47:21 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frag_find);
|
2019-01-22 18:02:50 +00:00
|
|
|
|
|
|
|
int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb,
|
|
|
|
int offset, int end)
|
|
|
|
{
|
|
|
|
struct sk_buff *last = q->fragments_tail;
|
|
|
|
|
|
|
|
/* RFC5722, Section 4, amended by Errata ID : 3089
|
|
|
|
* When reassembling an IPv6 datagram, if
|
|
|
|
* one or more its constituent fragments is determined to be an
|
|
|
|
* overlapping fragment, the entire datagram (and any constituent
|
|
|
|
* fragments) MUST be silently discarded.
|
|
|
|
*
|
|
|
|
* Duplicates, however, should be ignored (i.e. skb dropped, but the
|
|
|
|
* queue/fragments kept for later reassembly).
|
|
|
|
*/
|
|
|
|
if (!last)
|
|
|
|
fragrun_create(q, skb); /* First fragment. */
|
|
|
|
else if (last->ip_defrag_offset + last->len < end) {
|
|
|
|
/* This is the common case: skb goes to the end. */
|
|
|
|
/* Detect and discard overlaps. */
|
|
|
|
if (offset < last->ip_defrag_offset + last->len)
|
|
|
|
return IPFRAG_OVERLAP;
|
|
|
|
if (offset == last->ip_defrag_offset + last->len)
|
|
|
|
fragrun_append_to_last(q, skb);
|
|
|
|
else
|
|
|
|
fragrun_create(q, skb);
|
|
|
|
} else {
|
|
|
|
/* Binary search. Note that skb can become the first fragment,
|
|
|
|
* but not the last (covered above).
|
|
|
|
*/
|
|
|
|
struct rb_node **rbn, *parent;
|
|
|
|
|
|
|
|
rbn = &q->rb_fragments.rb_node;
|
|
|
|
do {
|
|
|
|
struct sk_buff *curr;
|
|
|
|
int curr_run_end;
|
|
|
|
|
|
|
|
parent = *rbn;
|
|
|
|
curr = rb_to_skb(parent);
|
|
|
|
curr_run_end = curr->ip_defrag_offset +
|
|
|
|
FRAG_CB(curr)->frag_run_len;
|
|
|
|
if (end <= curr->ip_defrag_offset)
|
|
|
|
rbn = &parent->rb_left;
|
|
|
|
else if (offset >= curr_run_end)
|
|
|
|
rbn = &parent->rb_right;
|
|
|
|
else if (offset >= curr->ip_defrag_offset &&
|
|
|
|
end <= curr_run_end)
|
|
|
|
return IPFRAG_DUP;
|
|
|
|
else
|
|
|
|
return IPFRAG_OVERLAP;
|
|
|
|
} while (*rbn);
|
|
|
|
/* Here we have parent properly set, and rbn pointing to
|
|
|
|
* one of its NULL left/right children. Insert skb.
|
|
|
|
*/
|
|
|
|
fragcb_clear(skb);
|
|
|
|
rb_link_node(&skb->rbnode, parent, rbn);
|
|
|
|
rb_insert_color(&skb->rbnode, &q->rb_fragments);
|
|
|
|
}
|
|
|
|
|
|
|
|
skb->ip_defrag_offset = offset;
|
|
|
|
|
|
|
|
return IPFRAG_OK;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frag_queue_insert);
|
|
|
|
|
|
|
|
void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb,
|
|
|
|
struct sk_buff *parent)
|
|
|
|
{
|
|
|
|
struct sk_buff *fp, *head = skb_rb_first(&q->rb_fragments);
|
|
|
|
struct sk_buff **nextp;
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
if (head != skb) {
|
|
|
|
fp = skb_clone(skb, GFP_ATOMIC);
|
|
|
|
if (!fp)
|
|
|
|
return NULL;
|
|
|
|
FRAG_CB(fp)->next_frag = FRAG_CB(skb)->next_frag;
|
|
|
|
if (RB_EMPTY_NODE(&skb->rbnode))
|
|
|
|
FRAG_CB(parent)->next_frag = fp;
|
|
|
|
else
|
|
|
|
rb_replace_node(&skb->rbnode, &fp->rbnode,
|
|
|
|
&q->rb_fragments);
|
|
|
|
if (q->fragments_tail == skb)
|
|
|
|
q->fragments_tail = fp;
|
|
|
|
skb_morph(skb, head);
|
|
|
|
FRAG_CB(skb)->next_frag = FRAG_CB(head)->next_frag;
|
|
|
|
rb_replace_node(&head->rbnode, &skb->rbnode,
|
|
|
|
&q->rb_fragments);
|
|
|
|
consume_skb(head);
|
|
|
|
head = skb;
|
|
|
|
}
|
|
|
|
WARN_ON(head->ip_defrag_offset != 0);
|
|
|
|
|
|
|
|
delta = -head->truesize;
|
|
|
|
|
|
|
|
/* Head of list must not be cloned. */
|
|
|
|
if (skb_unclone(head, GFP_ATOMIC))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
delta += head->truesize;
|
|
|
|
if (delta)
|
2019-05-24 16:03:30 +00:00
|
|
|
add_frag_mem_limit(q->fqdir, delta);
|
2019-01-22 18:02:50 +00:00
|
|
|
|
|
|
|
/* If the first fragment is fragmented itself, we split
|
|
|
|
* it to two chunks: the first with data and paged part
|
|
|
|
* and the second, holding only fragments.
|
|
|
|
*/
|
|
|
|
if (skb_has_frag_list(head)) {
|
|
|
|
struct sk_buff *clone;
|
|
|
|
int i, plen = 0;
|
|
|
|
|
|
|
|
clone = alloc_skb(0, GFP_ATOMIC);
|
|
|
|
if (!clone)
|
|
|
|
return NULL;
|
|
|
|
skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list;
|
|
|
|
skb_frag_list_init(head);
|
|
|
|
for (i = 0; i < skb_shinfo(head)->nr_frags; i++)
|
|
|
|
plen += skb_frag_size(&skb_shinfo(head)->frags[i]);
|
|
|
|
clone->data_len = head->data_len - plen;
|
|
|
|
clone->len = clone->data_len;
|
|
|
|
head->truesize += clone->truesize;
|
|
|
|
clone->csum = 0;
|
|
|
|
clone->ip_summed = head->ip_summed;
|
2019-05-24 16:03:30 +00:00
|
|
|
add_frag_mem_limit(q->fqdir, clone->truesize);
|
2019-01-22 18:02:50 +00:00
|
|
|
skb_shinfo(head)->frag_list = clone;
|
|
|
|
nextp = &clone->next;
|
|
|
|
} else {
|
|
|
|
nextp = &skb_shinfo(head)->frag_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextp;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frag_reasm_prepare);
|
|
|
|
|
|
|
|
void inet_frag_reasm_finish(struct inet_frag_queue *q, struct sk_buff *head,
|
|
|
|
void *reasm_data)
|
|
|
|
{
|
|
|
|
struct sk_buff **nextp = (struct sk_buff **)reasm_data;
|
|
|
|
struct rb_node *rbn;
|
|
|
|
struct sk_buff *fp;
|
|
|
|
|
|
|
|
skb_push(head, head->data - skb_network_header(head));
|
|
|
|
|
|
|
|
/* Traverse the tree in order, to build frag_list. */
|
|
|
|
fp = FRAG_CB(head)->next_frag;
|
|
|
|
rbn = rb_next(&head->rbnode);
|
|
|
|
rb_erase(&head->rbnode, &q->rb_fragments);
|
|
|
|
while (rbn || fp) {
|
|
|
|
/* fp points to the next sk_buff in the current run;
|
|
|
|
* rbn points to the next run.
|
|
|
|
*/
|
|
|
|
/* Go through the current run. */
|
|
|
|
while (fp) {
|
|
|
|
*nextp = fp;
|
|
|
|
nextp = &fp->next;
|
|
|
|
fp->prev = NULL;
|
|
|
|
memset(&fp->rbnode, 0, sizeof(fp->rbnode));
|
|
|
|
fp->sk = NULL;
|
|
|
|
head->data_len += fp->len;
|
|
|
|
head->len += fp->len;
|
|
|
|
if (head->ip_summed != fp->ip_summed)
|
|
|
|
head->ip_summed = CHECKSUM_NONE;
|
|
|
|
else if (head->ip_summed == CHECKSUM_COMPLETE)
|
|
|
|
head->csum = csum_add(head->csum, fp->csum);
|
|
|
|
head->truesize += fp->truesize;
|
|
|
|
fp = FRAG_CB(fp)->next_frag;
|
|
|
|
}
|
|
|
|
/* Move to the next run. */
|
|
|
|
if (rbn) {
|
|
|
|
struct rb_node *rbnext = rb_next(rbn);
|
|
|
|
|
|
|
|
fp = rb_to_skb(rbn);
|
|
|
|
rb_erase(rbn, &q->rb_fragments);
|
|
|
|
rbn = rbnext;
|
|
|
|
}
|
|
|
|
}
|
2019-05-24 16:03:30 +00:00
|
|
|
sub_frag_mem_limit(q->fqdir, head->truesize);
|
2019-01-22 18:02:50 +00:00
|
|
|
|
|
|
|
*nextp = NULL;
|
|
|
|
skb_mark_not_on_list(head);
|
|
|
|
head->prev = NULL;
|
|
|
|
head->tstamp = q->stamp;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frag_reasm_finish);
|
|
|
|
|
|
|
|
struct sk_buff *inet_frag_pull_head(struct inet_frag_queue *q)
|
|
|
|
{
|
2019-02-26 01:43:46 +00:00
|
|
|
struct sk_buff *head, *skb;
|
2019-01-22 18:02:50 +00:00
|
|
|
|
2019-02-26 01:43:46 +00:00
|
|
|
head = skb_rb_first(&q->rb_fragments);
|
|
|
|
if (!head)
|
|
|
|
return NULL;
|
|
|
|
skb = FRAG_CB(head)->next_frag;
|
|
|
|
if (skb)
|
|
|
|
rb_replace_node(&head->rbnode, &skb->rbnode,
|
|
|
|
&q->rb_fragments);
|
|
|
|
else
|
|
|
|
rb_erase(&head->rbnode, &q->rb_fragments);
|
|
|
|
memset(&head->rbnode, 0, sizeof(head->rbnode));
|
|
|
|
barrier();
|
2019-01-22 18:02:50 +00:00
|
|
|
|
|
|
|
if (head == q->fragments_tail)
|
|
|
|
q->fragments_tail = NULL;
|
|
|
|
|
2019-05-24 16:03:30 +00:00
|
|
|
sub_frag_mem_limit(q->fqdir, head->truesize);
|
2019-01-22 18:02:50 +00:00
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(inet_frag_pull_head);
|