net: frag code fixes and RFC for LRU removal
Subsystems (4)
cover net: frag code fixes and RFC for LRU removal
This patchset is mostly fixes I discovered while working on removing the LRU system, which is almost done (included as a RFC patch-03), but I wanted to push these patches for review first.
Patch-01: net: fix race bug in fragmentation create code
- Is a race fix that is only visible with patch-02 in place.
Patch-02: net: fix enforcing of fragment queue hash list depth
- Fixes unfortunately effect of Hannes hash depth limit, but is also part of the direct hash cleaning strategy, which is needed before we can remove the LRU list cleaning system
Patch-03: net: remove fragmentation LRU list system
- This patch is BROKEN do not apply, RFC only. I have a bug in inet_frag_cleanup_netns().
Patchset based on top of net-next commit 953c96e0d8 (v3.9-rc5-1145-g953c96e).
Same test setup:
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).
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
Performance table summary (in Mbit/s):
Test-type: 20G64K 20G3F 20G64K+DoS 20G3F+DoS 20G64K+MQ 20G3F+MQ ---------- ------- ------- ---------- --------- -------- ------- net-next: 17417.4 11376.5 3853.43 6170.56 174.8 402.9 patch-01: 17337.1 11541.4 3803.89 6041.52 171.6 416.1 patch-02: 16674.7 11113.8 3806.43 7892.50 405.5 759.3
(below, work-in-progress removing LRU system, hash clean only)
patch-03: 19108.1 13369.2 9923.58 10235.10 1547.2 1795.5
---
Jesper Dangaard Brouer (3):
net: remove fragmentation LRU list system
net: fix enforcing of fragment queue hash list depth
net: fix race bug in fragmentation create code
include/net/inet_frag.h | 45 ++++----- include/net/ipv6.h | 2 net/ipv4/inet_fragment.c | 150 +++++++++++++++++++------------ net/ipv4/ip_fragment.c | 32 ++----- net/ipv6/netfilter/nf_conntrack_reasm.c | 10 -- net/ipv6/reassembly.c | 23 +++-- 6 files changed, 138 insertions(+), 124 deletions(-)
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Sr. Network Kernel Developer at Red Hat
Author of http://www.iptv-analyzer.org
LinkedIn: http://www.linkedin.com/in/brouer
PATCH 1/3 net: fix race bug in fragmentation create code
During creation of a new inet_frag_queue, the lru_list pointer is updated after releasing the hash bucket lock, which can lead to a race condition (and panic), if the inet_frag_queue is deleted (very quickly) before the lru_list is valid.
This race condition is should not be able to occur with current LRU based evictor. For the planned direct hash based evictor/clean strategy, this race condition is more likely to occur.
---
net/ipv4/inet_fragment.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/ipv4/inet_fragment.c +1 -1
@@ -283,9 +283,9 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,atomic_inc (&qp->refcnt);hlist_add_head (&qp->list, &hb->chain); +inet_frag_lru_add (nf, qp);spin_unlock (&hb->chain_lock);read_unlock (&f->lock); -inet_frag_lru_add (nf, qp);return qp; }
Re: [net-next PATCH 1/3] net: fix race bug in fragmentation create code
Quoted 21 lines · Jesper Dangaard Brouer
During creation of a new
inet_frag_queue, thelru_listpointer is updated after releasing the hash bucket lock, which can lead to a race condition (and panic), if theinet_frag_queueis deleted (very quickly) before thelru_listis valid.This race condition is should not be able to occur with current LRU based evictor. For the planned direct hash based evictor/clean strategy, this race condition is more likely to occur.
Signed-off-by Jesper Dangaard Brouer <[email protected]>---
net/ipv4/inet_fragment.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)net/ipv4/inet_fragment.c +0
-0
net/ipv4/inet_fragment.c static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf, · line 290
Quoted 9 lines
net/ipv4/inet_fragment.c +1
-1@@ -283,9 +283,9 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,atomic_inc (&qp->refcnt);hlist_add_head (&qp->list, &hb->chain); +inet_frag_lru_add (nf, qp);spin_unlock (&hb->chain_lock);read_unlock (&f->lock); -inet_frag_lru_add (nf, qp);return qp; }
If I checked correctly, the current code does not have the race condition? I think this change is ok but maybe we can defer it until the direct hash cleanup patches land?
Thanks,
Hannes
Re: [net-next PATCH 1/3] net: fix race bug in fragmentation create code
Quoted 23 lines · Hannes Frederic Sowa
Quoted 22 lines · Jesper Dangaard Brouer
During creation of a new
inet_frag_queue, thelru_listpointer is updated after releasing the hash bucket lock, which can lead to a race condition (and panic), if theinet_frag_queueis deleted (very quickly) before thelru_listis valid.This race condition is should not be able to occur with current LRU based evictor. For the planned direct hash based evictor/clean strategy, this race condition is more likely to occur.
Signed-off-by Jesper Dangaard Brouer <[email protected]>---
net/ipv4/inet_fragment.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)net/ipv4/inet_fragment.c +0
-0@@ -283,9 +283,9 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
Quoted 12 lines
net/ipv4/inet_fragment.c static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf, · line 290
Quoted 8 lines
net/ipv4/inet_fragment.c +1
-1atomic_inc (&qp->refcnt);hlist_add_head (&qp->list, &hb->chain); +inet_frag_lru_add (nf, qp);spin_unlock (&hb->chain_lock);read_unlock (&f->lock); -inet_frag_lru_add (nf, qp);return qp; }If I checked correctly, the current code does not have the race condition? I think this change is ok but maybe we can defer it until the direct hash cleanup patches land?
Lets hear what others think of collapsing it into the next patch? (I don't have a problem with doing so)
--Jesper
PATCH 2/3 net: fix enforcing of fragment queue hash list depth
In reply to Jesper Dangaard BrouerI have found an issues with commit:
commit 5a3da1fe9561828d0ca7eca664b16ec2b9bf0055
Author: Hannes Frederic Sowa <[email protected]>
Date: Fri Mar 15 11:32:30 2013 +0000
inet: limit length of fragment queue hash table bucket lists
There is a connection between the fixed 128 hash depth limit and the frag mem limit/thresh settings, which limits how high the thresh can be set.
The 128 elems hash depth limit, results in bad behaviour if mem limit thresh holds are increased, via /proc/sys/net ::
/proc/sys/net/ipv4/ipfrag_high_thresh
/proc/sys/net/ipv4/ipfrag_low_thresh
If we increase the thresh, to something allowing 128 elements in each bucket, which is not that high given the hash array size of 64 (64*128=8192), e.g.
big MTU frags (2944(truesize)+208(ipq))*8192(max elems)=25755648
small frags ( 896(truesize)+208(ipq))*8192(max elems)=9043968
The problem with commit 5a3da1fe (inet: limit length of fragment queue hash table bucket lists) is that, once we hit the limit, the we *keep* the existing frag queues, not allowing new frag queues to be created. Thus, an attacker can effectivly block handling of fragments for 30 sec (as each frag queue have a timeout of 30 sec).
Even without increasing the limit, as Hannes showed, an attacker on IPv6 can "attack" a specific hash bucket, and via that change, can block/drop new fragments also (trying to) utilize this bucket.
Summary:
With the default mem limit/thresh settings, this is not general
problem, but adjusting the thresh limits result in some-what unexpected behavior.
Proposed solution:
IMHO instead of keeping existing frag queues, we should kill one of
the frag queues in the hash instead.
Implementation complications:
Killing of frag queues while only holding the hash bucket lock, and
not the frag queue lock, complicates the implementation, as we race and can end up (trying to) remove the hash element twice (resulting in an oops). This have been addressed by using hlist_del_init() and a hlist_unhashed() check in fq_unlink_hash().
Extra:
* Added new sysctl "max_hash_depth" option, to allow users to adjust the hash depth along with adjusting the thresh limits.
* Change max hash depth to 32, thus limit handling to approx 2048 frag queues.
---
include/net/inet_frag.h | 9 +--- net/ipv4/inet_fragment.c | 64 ++++++++++++++++++++----------- net/ipv4/ip_fragment.c | 13 +++++- net/ipv6/netfilter/nf_conntrack_reasm.c | 5 +- net/ipv6/reassembly.c | 15 ++++++- 5 files changed, 68 insertions(+), 38 deletions(-)
include/net/inet_frag.h +2 -7
@@ -42,13 +42,7 @@ struct inet_frag_queue { };#define INETFRAGS_HASHSZ 64 - -/* averaged: -* max_depth = default ipfrag_high_thresh / INETFRAGS_HASHSZ / -* rounded up (SKB_TRUELEN(0) + sizeof(struct ipq or -* struct frag_queue)) -*/ -#define INETFRAGS_MAXDEPTH 128 +#define INETFRAGS_MAX_HASH_DEPTH 32struct inet_frag_bucket {struct hlist_head chain;
@@ -65,6 +59,7 @@ struct inet_frags {int secret_interval;struct timer_list secret_timer;u32 rnd; +u32 max_hash_depth;int qsize;unsigned int (*hashfn)(struct inet_frag_queue *);
net/ipv4/inet_fragment.c +42 -22
111 lines not on this page · raw message
net/ipv4/ip_fragment.c +10 -3
@@ -263,10 +263,8 @@ static inline struct ipq *ip_find(struct net *net, struct iphdr *iph, u32 user) hash =ipqhashfn (iph->id, iph->saddr, iph->daddr, iph->protocol); q =inet_frag_find (&net->ipv4.frags, &ip4_frags, &arg, hash); -if (IS_ERR_OR_NULL (q)) { -inet_frag_maybe_warn_overflow (q,pr_fmt ()); +if (q ==NULL )return NULL ; - } return container_of(q, struct ipq, q); }
@@ -748,6 +746,14 @@ static struct ctl_table ip4_frags_ctl_table[] = { .proc_handler = proc_dointvec_minmax, .extra1 = &zero }, + { + .procname = "ipfrag_max_hash_depth", + .data = &ip4_frags.max_hash_depth, + .maxlen = sizeof(u32), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero + }, { } };
@@ -866,5 +872,6 @@ void __init ipfrag_init(void) ip4_frags.match = ip4_frag_match; ip4_frags.frag_expire = ip_expire; ip4_frags.secret_interval =10 *60 *HZ ; + ip4_frags.max_hash_depth =INETFRAGS_MAX_HASH_DEPTH ;inet_frags_init (&ip4_frags); }
net/ipv6/netfilter/nf_conntrack_reasm.c +2 -3
@@ -189,10 +189,8 @@ static inline struct frag_queue *fq_find(struct net *net, __be32 id, q =inet_frag_find (&net->nf_frag.frags, &nf_frags, &arg, hash);local_bh_enable (); -if (IS_ERR_OR_NULL (q)) { -inet_frag_maybe_warn_overflow (q,pr_fmt ()); +if (q ==NULL )return NULL ; - } return container_of(q, struct frag_queue, q); }
@@ -681,6 +679,7 @@ int nf_ct_frag6_init(void) nf_frags.match = ip6_frag_match; nf_frags.frag_expire = nf_ct_frag6_expire; nf_frags.secret_interval =10 *60 *HZ ; + nf_frags.max_hash_depth =INETFRAGS_MAX_HASH_DEPTH ;inet_frags_init (&nf_frags); ret =register_pernet_subsys (&nf_ct_net_ops);
net/ipv6/reassembly.c +12 -3
@@ -196,10 +196,8 @@ fq_find(struct net *net, __be32 id, const struct in6_addr *src, hash =inet6_hash_frag (id, src, dst, ip6_frags.rnd); q =inet_frag_find (&net->ipv6.frags, &ip6_frags, &arg, hash); -if (IS_ERR_OR_NULL (q)) { -inet_frag_maybe_warn_overflow (q,pr_fmt ()); +if (q ==NULL )return NULL ; - } return container_of(q, struct frag_queue, q); }
@@ -600,6 +598,8 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = { { } }; +static int zero; +static struct ctl_table ip6_frags_ctl_table[] = { { .procname ="ip6frag_secret_interval" ,
@@ -608,6 +608,14 @@ static struct ctl_table ip6_frags_ctl_table[] = { .mode = 0644, .proc_handler = proc_dointvec_jiffies, }, + { + .procname = "ip6frag_max_hash_depth", + .data = &ip6_frags.max_hash_depth, + .maxlen = sizeof(u32), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero + }, { } };
@@ -734,6 +742,7 @@ int __init ipv6_frag_init(void) ip6_frags.match = ip6_frag_match; ip6_frags.frag_expire = ip6_frag_expire; ip6_frags.secret_interval =10 *60 *HZ ; + ip6_frags.max_hash_depth =INETFRAGS_MAX_HASH_DEPTH ;inet_frags_init (&ip6_frags); out:return ret;
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
net/ipv4/inet_fragment.c struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, · line 380
Quoted 7 lines · Jesper Dangaard Brouer
net/ipv4/inet_fragment.c +5
-2-if (PTR_ERR (q) == -ENOBUFS ) -LIMIT_NETDEBUG (KERN_WARNING "%s%s" , prefix, msg); +LIMIT_NETDEBUG (KERN_WARNING "%s(): Fragment hash bucket" +" list length grew over limit (len %d)," +" Dropping another fragment.\n" , + __func__, depth); + }
Simple nice-to-have thingie: Do you see a simple possibility to add the user (e.g. ipv6/ipv6-netfilter/ipv4) to the warning?
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
In reply to Jesper Dangaard BrouerQuoted 34 lines · Jesper Dangaard Brouer
I have found an issues with commit:
commit
5a3da1fe9561828d0ca7eca664b16ec2b9bf0055
Author: Hannes Frederic Sowa <[email protected]>
Date: Fri Mar 15 11:32:30 2013 +0000inet: limit length of fragment queue hash table bucket lists
There is a connection between the fixed 128 hash depth limit and the frag mem limit/thresh settings, which limits how high the thresh can be set.
The 128 elems hash depth limit, results in bad behaviour if mem limit thresh holds are increased, via
/proc/sys/net::
/proc/sys/net/ipv4/ipfrag_high_thresh
/proc/sys/net/ipv4/ipfrag_low_threshIf we increase the thresh, to something allowing 128 elements in each bucket, which is not that high given the hash array size of 64 (64*128=8192), e.g.
big MTU frags (2944(truesize)+208(ipq))*8192(max elems)=25755648
small frags ( 896(truesize)+208(ipq))*8192(max elems)=9043968The problem with commit
5a3da1fe(inet: limit length of fragment queue hash table bucket lists) is that, once we hit the limit, the we *keep* the existing frag queues, not allowing new frag queues to be created. Thus, an attacker can effectivly block handling of fragments for 30 sec (as each frag queue have a timeout of 30 sec).Even without increasing the limit, as Hannes showed, an attacker on IPv6 can "attack" a specific hash bucket, and via that change, can block/drop new fragments also (trying to) utilize this bucket.
Quoted 8 lines
Summary:
With the default mem limit/thresh settings, this is not general
problem, but adjusting the thresh limits result in some-what unexpected behavior.Proposed solution:
IMHO instead of keeping existing frag queues, we should kill one of
the frag queues in the hash instead.
This strategy wont really help DDOS attacks. No frag will ever complete.
I am not sure its worth adding extra complexity.
Quoted 14 lines
Implementation complications:
Killing of frag queues while only holding the hash bucket lock, and
not the frag queue lock, complicates the implementation, as we race and can end up (trying to) remove the hash element twice (resulting in an oops). This have been addressed by usinghlist_del_init()and ahlist_unhashed()check infq_unlink_hash().Extra:
* Added new sysctl "max_hash_depth" option, to allow users to adjust the hash depth along with adjusting the thresh limits.
* Change max hash depth to 32, thus limit handling to approx 2048 frag queues.Signed-off-by Jesper Dangaard Brouer <[email protected]>
Quoted 8 lines
---
include/net/inet_frag.h | 9 +--- net/ipv4/inet_fragment.c | 64 ++++++++++++++++++++----------- net/ipv4/ip_fragment.c | 13 +++++- net/ipv6/netfilter/nf_conntrack_reasm.c | 5 +- net/ipv6/reassembly.c | 15 ++++++- 5 files changed, 68 insertions(+), 38 deletions(-)
Hmm... adding a new sysctl without documentation is a clear sign you'll be the only user of it.
You are also setting a default limit of 32, more likely to hit the problem than current 128 value.
We know the real solution is to have a correctly sized hash table, so why adding a temporary sysctl ?
As soon as /proc/sys/net/ipv4/ipfrag_high_thresh is changed, a resize should be attempted.
But the max depth itself should be a reasonable value, and doesn't need to be tuned IMHO.
The 64 slots hash table was chosen years ago, when machines had 3 order of magnitude less ram than today.
Before hash resizing, I would just bump hash size to something more reasonable like 1024.
That would allow some admin to set /proc/sys/net/ipv4/ipfrag_high_thresh to a quite large value.
RE: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 5 lines
The 64 slots hash table was chosen years ago, when machines had 3 order of magnitude less ram than today.
Before hash resizing, I would just bump hash size to something more reasonable like 1024.
While that is true of many systems, there are embedded systems with much less ram than the typical x86 desktop or server.
There seem to be quite a lot of large hash tables appearing that on many small systems will never contain a significant number of entries and just waste precious memory.
David
RE: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 6 lines · David Laight
Quoted 5 lines
The 64 slots hash table was chosen years ago, when machines had 3 order of magnitude less ram than today.
Before hash resizing, I would just bump hash size to something more reasonable like 1024.
Quoted 6 lines
While that is true of many systems, there are embedded systems with much less ram than the typical x86 desktop or server.
There seem to be quite a lot of large hash tables appearing that on many small systems will never contain a significant number of entries and just waste precious memory.
Embedded systems run linux since ages, and their memory also increased by 2 order of magnitude since 1995.
If they run linux-3.10, using 4096 bytes of 8192 bytes for the hash table is fine.
We are not going to add yet another ifdef, for such a small amount of ram.
The code that we will add to do the resize will be larger than this.
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
In reply to Eric DumazetQuoted 40 lines · Eric Dumazet
Quoted 39 lines · Jesper Dangaard Brouer
I have found an issues with commit:
commit
5a3da1fe9561828d0ca7eca664b16ec2b9bf0055
Author: Hannes Frederic Sowa <[email protected]>
Date: Fri Mar 15 11:32:30 2013 +0000inet: limit length of fragment queue hash table bucket lists
There is a connection between the fixed 128 hash depth limit and the frag mem limit/thresh settings, which limits how high the thresh can be set.
The 128 elems hash depth limit, results in bad behaviour if mem limit thresh holds are increased, via
/proc/sys/net::
/proc/sys/net/ipv4/ipfrag_high_thresh
/proc/sys/net/ipv4/ipfrag_low_threshIf we increase the thresh, to something allowing 128 elements in each bucket, which is not that high given the hash array size of 64 (64*128=8192), e.g.
big MTU frags (2944(truesize)+208(ipq))*8192(max elems)=25755648
small frags ( 896(truesize)+208(ipq))*8192(max elems)=9043968The problem with commit
5a3da1fe(inet: limit length of fragment queue hash table bucket lists) is that, once we hit the limit, the we *keep* the existing frag queues, not allowing new frag queues to be created. Thus, an attacker can effectivly block handling of fragments for 30 sec (as each frag queue have a timeout of 30 sec).Even without increasing the limit, as Hannes showed, an attacker on IPv6 can "attack" a specific hash bucket, and via that change, can block/drop new fragments also (trying to) utilize this bucket.
Summary:
With the default mem limit/thresh settings, this is not general
problem, but adjusting the thresh limits result in some-what unexpected behavior.
Quoted 6 lines
Quoted 3 lines
Proposed solution:
IMHO instead of keeping existing frag queues, we should kill one of
the frag queues in the hash instead.This strategy wont really help DDOS attacks. No frag will ever complete.
I beg to differ.
First if all, I also though keeping fragments were the right choice, BUT then I realized that we cannot tell god-from-bad frags apart, and an attacker will obviously generate more fragments than the real traffic, thus we end up keeping the attackers fragment for 30 sec. Because the attacker will never "finish/complete" his fragment queues. Thus, the real "help" for a DoS attack is to keep fragments.
Second, I have clearly shown, with my performance tests, that frags will complete under DoS.
Consider argument for frags will be able to complete:
For an attacker to "push-out" the real-fragments she will have to
generate enough packets to fill the entire hash queue (to be sure) which is 64 * 32 = 2048 elements, thus generate (some were below) 2048 packets, in the same period the real-fragment sender only needs to send 3 packets (my DNSSEC use case).
That is the reason it works, do you buy that explanation?
Quoted 1 line
I am not sure its worth adding extra complexity.
It's not that complex, and we simply need it, else an attacker can DoS us very easily by sending a burst every 30 sec. We do need this change, else we must revert Hannes patch, and find a complete other approach of removing the LRU list system.
Quoted 22 lines
Quoted 13 lines
Implementation complications:
Killing of frag queues while only holding the hash bucket lock, and
not the frag queue lock, complicates the implementation, as we race and can end up (trying to) remove the hash element twice (resulting in an oops). This have been addressed by usinghlist_del_init()and ahlist_unhashed()check infq_unlink_hash().Extra:
* Added new sysctl "max_hash_depth" option, to allow users to adjust the hash depth along with adjusting the thresh limits.
* Change max hash depth to 32, thus limit handling to approx 2048 frag queues.Signed-off-by Jesper Dangaard Brouer <[email protected]>Quoted 8 lines
---
include/net/inet_frag.h | 9 +--- net/ipv4/inet_fragment.c | 64 ++++++++++++++++++++----------- net/ipv4/ip_fragment.c | 13 +++++- net/ipv6/netfilter/nf_conntrack_reasm.c | 5 +- net/ipv6/reassembly.c | 15 ++++++- 5 files changed, 68 insertions(+), 38 deletions(-)
Quoted 2 lines
Hmm... adding a new sysctl without documentation is a clear sign you'll be the only user of it.
LOL - I know, my next patch contains a note that I need to update the docs too...
Quoted 5 lines
You are also setting a default limit of 32, more likely to hit the problem than current 128 value.
We know the real solution is to have a correctly sized hash table, so why adding a temporary sysctl ?
No, the real solution is to remove LRU list system (that is the real bottleneck). But this patch (and the next) is a step needed before we can remove the LRU list cleanup system.
Quoted 2 lines
As soon as
/proc/sys/net/ipv4/ipfrag_high_threshis changed, a resize should be attempted.
Perhaps, but the ipfrag_high_thresh memory size does not translate easily to number of needed frag queues (hash_size * max_depth). Because the size of a frag queue can range from 1108 bytes to approx 130.000 bytes.
Quoted 2 lines
But the max depth itself should be a reasonable value, and doesn't need to be tuned IMHO.
What is a reasonable max depth value for you?
Quoted 8 lines
The 64 slots hash table was chosen years ago, when machines had 3 order of magnitude less ram than today.
Before hash resizing, I would just bump hash size to something more reasonable like 1024.
That would allow some admin to set
/proc/sys/net/ipv4/ipfrag_high_threshto a quite large value.
When removing the LRU system (which is the real bottleneck, see perf tests in cover mail), and doing direct hash cleaning we are trading-in accuracy.
The reason I don't want a too big hash table is the following.
With direct has cleaning, and even using the mem limit (ipfrag_high_thresh) in the cleaning loop/selection (see patch-02) we should at least allow one frag queue to survive (in a hash bucket). This means that we can violate/exceed the ipfrag_high_thresh a lot (due to size of a frag queue can range from 1108 bytes to approx 130.000 bytes).
Worst case 1024 buckets * 130K bytes = 133 MBytes, which on smaller embedded systems is a lot of kernel memory we are permitting a remote host to "lock-down".
--Jesper
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 11 lines · Jesper Dangaard Brouer
I beg to differ.
First if all, I also though keeping fragments were the right choice, BUT then I realized that we cannot tell god-from-bad frags apart, and an attacker will obviously generate more fragments than the real traffic, thus we end up keeping the attackers fragment for 30 sec. Because the attacker will never "finish/complete" his fragment queues. Thus, the real "help" for a DoS attack is to keep fragments.
Second, I have clearly shown, with my performance tests, that frags will complete under DoS.
How did you simulate the DoS? Did you try to fill up specific buckets or did you try to fill up the whole fragment cache?
Quoted 6 lines
Quoted 1 line
I am not sure its worth adding extra complexity.
It's not that complex, and we simply need it, else an attacker can DoS us very easily by sending a burst every 30 sec. We do need this change, else we must revert Hannes patch, and find a complete other approach of removing the LRU list system.
I agree that we have to do something to mitigate this. I would also drop the sysctl, I do think the kernel should have to take care of that.
Perhaps a way to solve this problem more easily would be to switch back to use a jenkins hash for all inputs of the hash function and not deal with this kind of unfairness regarding the possiblity to fill up one of the buckets.
Perhaps the performance improvements by Jesper (per bucket locking) could make up the more expensive hashing. :)
Just some minor things I found while looking at the patch:
include/net/inet_frag.h struct inet_frag_queue { · line 45
Quoted 8 lines
include/net/inet_frag.h +1
-7- -/* averaged: -* max_depth = default ipfrag_high_thresh / INETFRAGS_HASHSZ / -* rounded up (SKB_TRUELEN(0) + sizeof(struct ipq or -* struct frag_queue)) -*/ -#define INETFRAGS_MAXDEPTH 128 +#define INETFRAGS_MAX_HASH_DEPTH 32
Perhaps a comment could be added, that this is only a default value for the max hash depth.
net/ipv4/inet_fragment.c static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f) · line 155
Quoted 3 lines
net/ipv4/inet_fragment.c +2
-1-void inet_frag_kill (struct inet_frag_queue *fq,struct inet_frags *f) +void __inet_frag_kill (struct inet_frag_queue *fq,struct inet_frags *f, +bool unlink_hash)
This function could be static.
net/ipv4/inet_fragment.c struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, · line 348
Quoted 2 lines
net/ipv4/inet_fragment.c +1
-1-hlist_for_each_entry (q, &hb->chain, list) { +hlist_for_each_entry_safe (q, n, &hb->chain, list) {
Minor, but I think _safe is not needed here.
net/ipv6/reassembly.c static struct ctl_table ip6_frags_ns_ctl_table[] = { · line 602
Quoted 2 lines
net/ipv6/reassembly.c +2
-0+static int zero; +
Could be const.
Thanks,
Hannes
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 10 lines · Hannes Frederic Sowa
Quoted 9 lines · Jesper Dangaard Brouer
I beg to differ.
First if all, I also though keeping fragments were the right choice, BUT then I realized that we cannot tell god-from-bad frags apart, and an attacker will obviously generate more fragments than the real traffic, thus we end up keeping the attackers fragment for 30 sec. Because the attacker will never "finish/complete" his fragment queues. Thus, the real "help" for a DoS attack is to keep fragments.
Quoted 5 lines
Quoted 2 lines
Second, I have clearly shown, with my performance tests, that frags will complete under DoS.
How did you simulate the DoS? Did you try to fill up specific buckets or did you try to fill up the whole fragment cache?
I'm using trafgen (part of netsniff-ng git download from
https://github.com/borkmann/netsniff-ng).
Simple DoS test setup read (scroll down):
http://thread.gmane.org/gmane.linux.network/257155
As mentioned last time:
http://article.gmane.org/gmane.linux.network/263644
I have extended the DoS generator. quote:
'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.'
I have placed the new "multi-queue" trafgen script/input here:
http://people.netfilter.org/hawk/frag_work/trafgen/frag_packet05_small_frag_multi_queue.txf
Perhaps you can tell me, if my trafgen traffic is getting hashed badly?
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
I am not sure its worth adding extra complexity.
It's not that complex, and we simply need it, else an attacker can DoS us very easily by sending a burst every 30 sec. We do need this change, else we must revert Hannes patch, and find a complete other approach of removing the LRU list system.
I agree that we have to do something to mitigate this. I would also drop the sysctl, I do think the kernel should have to take care of that.
Quoted 6 lines
Perhaps a way to solve this problem more easily would be to switch back to use a jenkins hash for all inputs of the hash function and not deal with this kind of unfairness regarding the possiblity to fill up one of the buckets.
Perhaps the performance improvements by Jesper (per bucket locking) could make up the more expensive hashing. :)
Well, I don't know. But we do need some solution, to the current code.
Quoted 13 lines
Just some minor things I found while looking at the patch:
include/net/inet_frag.h struct inet_frag_queue { · line 45
Quoted 8 lines
include/net/inet_frag.h +1
-7- -/* averaged: -* max_depth = default ipfrag_high_thresh / INETFRAGS_HASHSZ / -* rounded up (SKB_TRUELEN(0) + sizeof(struct ipq or -* struct frag_queue)) -*/ -#define INETFRAGS_MAXDEPTH 128 +#define INETFRAGS_MAX_HASH_DEPTH 32Perhaps a comment could be added, that this is only a default value for the max hash depth.
Yes, I though of calling it INETFRAGS_MAX_HASH_DEPTH_DEFAULT, but it was getting too long. But now you and Eric argue against making this tune-able, so it might be the right "name".
Quoted 6 lines
net/ipv4/inet_fragment.c static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f) · line 155
Quoted 4 lines
net/ipv4/inet_fragment.c +2
-1-void inet_frag_kill (struct inet_frag_queue *fq,struct inet_frags *f) +void __inet_frag_kill (struct inet_frag_queue *fq,struct inet_frags *f, +bool unlink_hash)This function could be static.
(Sorry to be dumb) could you explain the benefit of doing so?
Quoted 4 lines
net/ipv4/inet_fragment.c struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, · line 348
Quoted 2 lines
net/ipv4/inet_fragment.c +1
-1-hlist_for_each_entry (q, &hb->chain, list) { +hlist_for_each_entry_safe (q, n, &hb->chain, list) {Minor, but I think
_safeis not needed here.
Yes, the hash unlink happens after we have exited the for_each loop.
Quoted 4 lines
net/ipv6/reassembly.c static struct ctl_table ip6_frags_ns_ctl_table[] = { · line 602
Quoted 2 lines
net/ipv6/reassembly.c +2
-0+static int zero; +Could be const.
Could you also explain the benefit of doing so for a variable?
--Jesper
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 14 lines · Jesper Dangaard Brouer
I'm using trafgen (part of netsniff-ng git download from
https://github.com/borkmann/netsniff-ng).Simple DoS test setup read (scroll down):
http://thread.gmane.org/gmane.linux.network/257155As mentioned last time:
http://article.gmane.org/gmane.linux.network/263644I have extended the DoS generator. quote:
'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.'
Quoted 4 lines
I have placed the new "multi-queue" trafgen script/input here:
http://people.netfilter.org/hawk/frag_work/trafgen/frag_packet05_small_frag_multi_queue.txfPerhaps you can tell me, if my trafgen traffic is getting hashed badly?
Thanks!
IPv4 traffic does not have this problem, as all the information to identify the packet are directly used as input to jhash_3words (the problem is, that IPv6 addresses are xored first and then fed into the jhash). So with this setup you would flood the hash uniformly distributed.
(Btw. I made a tool to generate fragments with colliding hashes:
https://gist.github.com/hannes/5116331).
Quoted 11 lines
Quoted 9 lines
I agree that we have to do something to mitigate this. I would also drop the sysctl, I do think the kernel should have to take care of that.
Perhaps a way to solve this problem more easily would be to switch back to use a jenkins hash for all inputs of the hash function and not deal with this kind of unfairness regarding the possiblity to fill up one of the buckets.
Perhaps the performance improvements by Jesper (per bucket locking) could make up the more expensive hashing. :)
Well, I don't know. But we do need some solution, to the current code.
You do have fancy 10GigE gear? :)
Could you profile a kernel with 279e9f2 ("ipv6: optimize inet6_hash_frag()") reverted? This would only effect IPv6 traffic, so you would have to write an IPv6 txf file. If the numbers show that the effect is not too high we could actually stop worry about per-hash bucket hash utilization in general (still, a limit per hash chain would be reasonable, but a global element limit should catch first).
This would give us the possibility to evict fragments from the fragmentation cache as soon as new fragments come in without caring about which hash bucket the fragment does actually belong, too. This would solve one of your problems of the RFC patch.
Btw, where is the txf file format actually documented?
Quoted 8 lines
Quoted 6 lines
net/ipv4/inet_fragment.c static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f) · line 155
Quoted 4 lines
net/ipv4/inet_fragment.c +2
-1-void inet_frag_kill (struct inet_frag_queue *fq,struct inet_frags *f) +void __inet_frag_kill (struct inet_frag_queue *fq,struct inet_frags *f, +bool unlink_hash)This function could be static.
(Sorry to be dumb) could you explain the benefit of doing so?
The function's namespace will be limited to the current file and won't be exported for linking by other files. It also does give a good hint for developers that the function is not used externally.
Quoted 6 lines
Quoted 4 lines
net/ipv6/reassembly.c static struct ctl_table ip6_frags_ns_ctl_table[] = { · line 602
Quoted 2 lines
net/ipv6/reassembly.c +2
-0+static int zero; +Could be const.
Could you also explain the benefit of doing so for a variable?
Precaution that it won't be changed by any statement in the file (does not add overhead but throws compiler errors if someone accidentally changes the value out of mistake, compile-time).
Thanks,
Hannes
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
In reply to Jesper Dangaard BrouerQuoted 1 line · Jesper Dangaard Brouer
Well, I don't know. But we do need some solution, to the current code.
In <http://article.gmane.org/gmane.linux.network/261361> I said that we could actually have a list lengt of about 370. At this time this number was stable, perhaps you could verify?
I tried to flood the cache with very minimal packets so this was actually the hint that I should have resized the hash back then. With the current fragmentation cache design we could reach optimal behaviour as soon as the memory limits kicks in and lru eviction starts before we limit the fragments queues in the hash chains. The only way to achieve this is to increase the hash table slots and lower the maximum length limit. I would propose a limit of about 25-32 and as Eric said, a hash size of 1024. We could test if we are limited of accepting new fragments by memory limit (which would be fine because lru eviction kicks in) or by chain length (we could recheck the numbers then).
So the chain limit would only kick in if someone tries to exploit the fragment cache by using the method I demonstrated before (which was the reason I introduced this limit).
Thanks,
Hannes
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 18 lines · Hannes Frederic Sowa
Quoted 1 line · Jesper Dangaard Brouer
Well, I don't know. But we do need some solution, to the current code.
In <http://article.gmane.org/gmane.linux.network/261361> I said that we could actually have a list lengt of about 370. At this time this number was stable, perhaps you could verify?
I tried to flood the cache with very minimal packets so this was actually the hint that I should have resized the hash back then. With the current fragmentation cache design we could reach optimal behaviour as soon as the memory limits kicks in and lru eviction starts before we limit the fragments queues in the hash chains. The only way to achieve this is to increase the hash table slots and lower the maximum length limit. I would propose a limit of about 25-32 and as Eric said, a hash size of 1024. We could test if we are limited of accepting new fragments by memory limit (which would be fine because lru eviction kicks in) or by chain length (we could recheck the numbers then).
Quoted 3 lines
So the chain limit would only kick in if someone tries to exploit the fragment cache by using the method I demonstrated before (which was the reason I introduced this limit).
(To avoid pissing people off) I acknowledge that we should change the hash size, as its ridiculously small with 64 entries.
But your mem limit assumption and hash depth limit assumptions are broken, because the mem limit is per netns (network namespace). Thus, starting more netns instances will break these assumptions.
The dangerous part of your change (commit 5a3da1fe) is that you keep the existing frag queues (and don't allow new frag queues to be created). The attackers fragments will never finish (timeout 30 sec), while valid fragments will complete and "exit" the queue, thus the end result is hash bucket is filled with attackers invalid/incomplete fragments.
Besides, after we have implemented per hash bucket locking (in my change commit 19952cc4 "net: frag queue per hash bucket locking"). Then, I don't think it is a big problem that a single hash bucket is being "attacked".
IMHO we should just revert the change (commit 5a3da1fe), and increase the hash size and fix the hashing for IPv6.
And then I'll find another method for fixing the global LRU list scalability problem (than the "direct-hash-cleaning" method).
Signature · 5 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Sr. Network Kernel Developer at Red Hat Author of http://www.iptv-analyzer.org LinkedIn: http://www.linkedin.com/in/brouer
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 6 lines · Jesper Dangaard Brouer
(To avoid pissing people off) I acknowledge that we should change the hash size, as its ridiculously small with 64 entries.
But your mem limit assumption and hash depth limit assumptions are broken, because the mem limit is per netns (network namespace). Thus, starting more netns instances will break these assumptions.
Oh, I see. :/
At first I thought we should make the fragment hash per namespace too, to provide better isolation in case of lxc. But then each chrome tab would allocate its own fragment cache, too. Hmm... but people using namespaces have plenty much memory, don't they? We could also provide an inet_fragment namespace. ;)
Quoted 5 lines
The dangerous part of your change (commit
5a3da1fe) is that you keep the existing frag queues (and don't allow new frag queues to be created). The attackers fragments will never finish (timeout 30 sec), while valid fragments will complete and "exit" the queue, thus the end result is hash bucket is filled with attackers invalid/incomplete fragments.
I would not mind if your change gets accepted (I have not completyl reviewed it yet), but I have my doubts if it is an advantage to the current solution.
First off, I think an attacker can keep the fragment cache pretty much filled up with little cost. The current implementation has the grace period where no new fragments will be accepted after the DoS, this is solved by your patch. But the change makes it easier for an attacker to evict "valid" fragments from the cache in the first 30 seconds of the DoS, too.
I am not sure whether the current fragmentation handling or your solution does perform better in real world (or if it actually matters).
Nonetheless it does add a bit more complexity and a new sysctl which does expose something the kernel should know how to do better.
Quoted 4 lines
Besides, after we have implemented per hash bucket locking (in my change commit
19952cc4"net: frag queue per hash bucket locking"). Then, I don't think it is a big problem that a single hash bucket is being "attacked".
I don't know, I wouldn't say so. The contention point is now the per hash bucket lock but it should show the same symptoms as before.
In my opinion we should start resizing the hash table irrespective of the namespace limits (one needs CAP_NET_ADMIN to connect a netns to the outside world, I think) and try to move forward with Patch 3. This patch 2 would then only be a dependency and would introduce the eviction strategy you need for patch 3. But the focus should be on the removal of the lru cleanup. What do you think?
Thanks,
Hannes
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 1 line · Hannes Frederic Sowa
On Mon, Apr 22, 2013 at 11:10:34AM +0200, Jesper Dangaard Brouer wrote:
[...]
Quoted 7 lines
Quoted 4 lines
Besides, after we have implemented per hash bucket locking (in my change commit
19952cc4"net: frag queue per hash bucket locking"). Then, I don't think it is a big problem that a single hash bucket is being "attacked".I don't know, I wouldn't say so. The contention point is now the per hash bucket lock but it should show the same symptoms as before.
No, the contention point is the LRU list lock, not the hash bucket lock. If you perf record/profile the code, you can easily miss that its the LRU lock, because its inlined. Try to rerun your tests with noinline e.g.:
include/net/inet_frag.h +0 -0
@@ -138,14 +138,14 @@ static inline int sum_frag_mem_limit(struct
netns_frags *n
return res;
}
-static inline void inet_frag_lru_move(struct inet_frag_queue *q) +static noinline void inet_frag_lru_move(struct inet_frag_queue *q)
{
spin_lock(&q->net->lru_lock);
list_move_tail(&q->lru_list, &q->net->lru_list);
spin_unlock(&q->net->lru_lock);}
-static inline void inet_frag_lru_del(struct inet_frag_queue *q) +static noinline void inet_frag_lru_del(struct inet_frag_queue *q)
{
spin_lock(&q->net->lru_lock);
list_del(&q->lru_list);
@@ -153,7 +153,7 @@ static inline void inet_frag_lru_del(struct
inet_frag_queue
spin_unlock(&q->net->lru_lock);}
-static inline void inet_frag_lru_add(struct netns_frags *nf, +static noinline void inet_frag_lru_add(struct netns_frags *nf,
struct inet_frag_queue *q)
{
spin_lock(&nf->lru_lock);Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
In reply to Hannes Frederic SowaQuoted 8 lines · Hannes Frederic Sowa
Quoted 6 lines · Jesper Dangaard Brouer
(To avoid pissing people off) I acknowledge that we should change the hash size, as its ridiculously small with 64 entries.
But your mem limit assumption and hash depth limit assumptions are broken, because the mem limit is per netns (network namespace). Thus, starting more netns instances will break these assumptions.
Quoted 7 lines
Oh, I see. :/
At first I thought we should make the fragment hash per namespace too, to provide better isolation in case of lxc. But then each chrome tab would allocate its own fragment cache, too. Hmm... but people using namespaces have plenty much memory, don't they? We could also provide an
inet_fragmentnamespace. ;)
I'm wondering if we could do the opposite, move the mem limit and LRU list "out-of" the netns?
Either way, this would make the relationship of the mem limit and hash size more sane.
Quoted 10 lines
Quoted 5 lines
The dangerous part of your change (commit
5a3da1fe) is that you keep the existing frag queues (and don't allow new frag queues to be created). The attackers fragments will never finish (timeout 30 sec), while valid fragments will complete and "exit" the queue, thus the end result is hash bucket is filled with attackers invalid/incomplete fragments.I would not mind if your change gets accepted (I have not completyl reviewed it yet), but I have my doubts if it is an advantage to the current solution.
Quoted 6 lines
First off, I think an attacker can keep the fragment cache pretty much filled up with little cost. The current implementation has the grace period where no new fragments will be accepted after the DoS, this is solved by your patch. But the change makes it easier for an attacker to evict "valid" fragments from the cache in the first 30 seconds of the DoS, too.
The "grace period" is quite harmful (where no new fragments will be accepted). Just creating 3 netns (3x 4MB mem limit) we can make all queues reach 128 entries, resulting in a "grace period" of 30 sec where no frags are possible. (min frag size is 1108 bytes with my trafgen script).
Quoted 5 lines
I am not sure whether the current fragmentation handling or your solution does perform better in real world (or if it actually matters).
Nonetheless it does add a bit more complexity and a new sysctl which does expose something the kernel should know how to do better.
Well, actually I don't like exposing the max_hash_depth sysctl, it was a wrong idea/move.
I like Eric's idea of resizing the hash based on the max thresh, unfortunately this does not make sense when the max thresh is per netns and the hash table is global.
I'm also thinking, it is really worth the complexity of having a depth limit on this hash table? Is it that important. The mem limit should at some point kick in and save the day anyhow (before, without per hash bucket locking it might make sense).
Quoted 8 lines
Quoted 4 lines
Besides, after we have implemented per hash bucket locking (in my change commit
19952cc4"net: frag queue per hash bucket locking"). Then, I don't think it is a big problem that a single hash bucket is being "attacked".I don't know, I wouldn't say so. The contention point is now the per hash bucket lock but it should show the same symptoms as before.
Quoted 6 lines
In my opinion we should start resizing the hash table irrespective of the namespace limits (one needs
CAP_NET_ADMINto connect a netns to the outside world, I think) and try to move forward with Patch 3. This patch 2 would then only be a dependency and would introduce the eviction strategy you need for patch 3. But the focus should be on the removal of the lru cleanup. What do you think?
I agree, increasing the hash tables size makes sense, as its ridiculously small with 64 entries.
Yes, removal of the (per netns) "global" LRU list should be the real focus. This was just a dependency for introducing the eviction strategy I needed for patch 3.
But the eviction strategy in patch-3, is actually also "broken" because the mem limit is per netns and we do eviction based on the netns shared hash table... thinking of going back to my original idea of simply doing LRU lists per CPU.
--Jesper
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 8 lines · Jesper Dangaard Brouer
Quoted 1 line · Hannes Frederic Sowa
On Mon, Apr 22, 2013 at 11:10:34AM +0200, Jesper Dangaard Brouer wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Besides, after we have implemented per hash bucket locking (in my change commit
19952cc4"net: frag queue per hash bucket locking"). Then, I don't think it is a big problem that a single hash bucket is being "attacked".
Quoted 7 lines
Quoted 2 lines
I don't know, I wouldn't say so. The contention point is now the per hash bucket lock but it should show the same symptoms as before.
No, the contention point is the LRU list lock, not the hash bucket lock. If you perf record/profile the code, you can easily miss that its the LRU lock, because its inlined. Try to rerun your tests with noinline e.g.:
It depends on the test. Last time I checked with my ipv6 torture test I had most hits in the inet_frag_find loop (I looked at it after your per bucket locks landed in net-next). I think your test setup could provide more meaningful numbers. If you fill up the whole fragment cache it is plausible that the contention will shift towards the lru lock.
Quoted 11 lines · Jesper Dangaard Brouer
Quoted 5 lines · Hannes Frederic Sowa
At first I thought we should make the fragment hash per namespace too, to provide better isolation in case of lxc. But then each chrome tab would allocate its own fragment cache, too. Hmm... but people using namespaces have plenty much memory, don't they? We could also provide an
inet_fragmentnamespace. ;)I'm wondering if we could do the opposite, move the mem limit and LRU list "out-of" the netns?
Either way, this would make the relationship of the mem limit and hash size more sane.
It seems to be the only sane way currently. If we resize on cloning/changing per-ns parameters we would also have to resize the frag hash on every google chrome tab creation/destruction.
Perhaps we sould think about adding lazy allocation/resizing of the fragment cache per-ns (or we do the resize on every rebuild timeout).
Quoted 17 lines
Quoted 10 lines
Quoted 5 lines
The dangerous part of your change (commit
5a3da1fe) is that you keep the existing frag queues (and don't allow new frag queues to be created). The attackers fragments will never finish (timeout 30 sec), while valid fragments will complete and "exit" the queue, thus the end result is hash bucket is filled with attackers invalid/incomplete fragments.I would not mind if your change gets accepted (I have not completyl reviewed it yet), but I have my doubts if it is an advantage to the current solution.
Quoted 6 lines
First off, I think an attacker can keep the fragment cache pretty much filled up with little cost. The current implementation has the grace period where no new fragments will be accepted after the DoS, this is solved by your patch. But the change makes it easier for an attacker to evict "valid" fragments from the cache in the first 30 seconds of the DoS, too.
Quoted 5 lines
The "grace period" is quite harmful (where no new fragments will be accepted). Just creating 3 netns (3x 4MB mem limit) we can make all queues reach 128 entries, resulting in a "grace period" of 30 sec where no frags are possible. (min frag size is 1108 bytes with my trafgen script).
I see your point. But some other fragments would be in the queue perhaps going to be reassembled correctly which would otherwise be evicted. So I really don't know what is the better behavior here.
But this would be changed as a side-effect of this whole patch set. ;)
Quoted 4 lines
I'm also thinking, it is really worth the complexity of having a depth limit on this hash table? Is it that important. The mem limit should at some point kick in and save the day anyhow (before, without per hash bucket locking it might make sense).
Depends on how we proceed with the ipv6 fragment hashing. If we go back to the 3 rounds of jhash for each fragment this would be possible.
Quoted 8 lines
Yes, removal of the (per netns) "global" LRU list should be the real focus. This was just a dependency for introducing the eviction strategy I needed for patch 3.
But the eviction strategy in patch-3, is actually also "broken" because the mem limit is per netns and we do eviction based on the netns shared hash table... thinking of going back to my original idea of simply doing LRU lists per CPU.
That depends on how we proceed with the memory limits. If we don't solve this now we will have to deal with this again if we think about how to calculate a decent hash size.
Greetings,
Hannes
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 17 lines · Hannes Frederic Sowa
Quoted 8 lines · Jesper Dangaard Brouer
Quoted 1 line · Hannes Frederic Sowa
On Mon, Apr 22, 2013 at 11:10:34AM +0200, Jesper Dangaard Brouer wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Besides, after we have implemented per hash bucket locking (in my change commit
19952cc4"net: frag queue per hash bucket locking"). Then, I don't think it is a big problem that a single hash bucket is being "attacked".Quoted 7 lines
Quoted 2 lines
I don't know, I wouldn't say so. The contention point is now the per hash bucket lock but it should show the same symptoms as before.
No, the contention point is the LRU list lock, not the hash bucket lock. If you perf record/profile the code, you can easily miss that its the LRU lock, because its inlined. Try to rerun your tests with noinline e.g.:
Quoted 5 lines
It depends on the test. Last time I checked with my ipv6 torture test I had most hits in the
inet_frag_findloop (I looked at it after your per bucket locks landed in net-next). I think your test setup could provide more meaningful numbers. If you fill up the whole fragment cache it is plausible that the contention will shift towards the lru lock.
Yes, traffic patterns do affect the results, BUT you have to be really careful profiling this:
Notice, that inet_frag_find() also indirectly takes the LRU lock, and the perf tool will blame inet_frag_find(). This is very subtle and happens with a traffic pattern that want to create new frag queues (e.g. not found in the hash list).
The problem is that inet_frag_find() calls inet_frag_create() (if q is not found) which calls inet_frag_intern() which calls inet_frag_lru_add() taking the LRU lock. All of these functions gets inlined by the compiler, thus inet_frag_find() gets the blame.
To avoid pissing people off:
Yes, having a long list in the hash bucket is obviously also contributes significantly. Yes, we still should increase the hash bucket size. I'm just pointing out be careful about what you actually profile ;-)
Please see below, profiling of current next-next, with "noinline" added to inet_frag_intern, inet_frag_alloc and inet_frag_create. Run under test 20G3F+MQ. I hope you can see my point with the LRU list lock, please let me know if I have missed something.
--Jesper
Profile of net-next with below diff/patch, output from command:
perf report -Mintel -C 1 --stdio --call-graph graph,2
Cut down version (full version attached):
-----------------------------------------
# Overhead Command Shared Object Symbol
# ........ ........... ................. .......................................
#
70.12% ksoftirqd/1 [kernel.kallsyms] [k] _raw_spin_lock
|
--- _raw_spin_lock
|
|--19.70%-- ip_defrag
|--17.36%-- inet_frag_kill
| |--15.04%-- inet_frag_evictor
| --2.32%-- ip_defrag
|--17.15%-- inet_frag_intern
--15.52%-- inet_frag_evictor 9.61% swapper [kernel.kallsyms] [k] _raw_spin_lock
|
--- _raw_spin_lock
|
|--2.46%-- inet_frag_kill
|--2.44%-- ip_defrag
|--2.38%-- inet_frag_evictor
--2.28%-- inet_frag_intern
1.91% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_find
1.66% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_intern
1.54% ksoftirqd/1 [kernel.kallsyms] [k] ip_defrag
1.52% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_kill
1.19% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_evictor
1.05% ksoftirqd/1 [kernel.kallsyms] [k] __percpu_counter_add
0.77% ksoftirqd/1 [kernel.kallsyms] [k] __list_del_entry
0.53% ksoftirqd/1 [kernel.kallsyms] [k] _raw_read_lock
0.49% ksoftirqd/1 [kernel.kallsyms] [k] ip4_frag_match
0.44% ksoftirqd/1 [kernel.kallsyms] [k] __list_add
0.42% ksoftirqd/1 [kernel.kallsyms] [k] inet_getpeer "noinline: changes to net-next:
-------------------------------
net/ipv4/inet_fragment.c +3 -3
@@ -241,7 +241,7 @@ int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f, bool force) }EXPORT_SYMBOL (inet_frag_evictor); -static struct inet_frag_queue *inet_frag_intern (struct netns_frags *nf, +static noinline struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,struct inet_frag_queue *qp_in,struct inet_frags *f,void *arg) {
@@ -289,7 +289,7 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,return qp; } -static struct inet_frag_queue *inet_frag_alloc (struct netns_frags *nf, +static noinline struct inet_frag_queue *inet_frag_alloc(struct netns_frags *nf,struct inet_frags *f,void *arg) {struct inet_frag_queue *q;
@@ -309,7 +309,7 @@ static struct inet_frag_queue *inet_frag_alloc(struct netns_frags *nf,return q; } -static struct inet_frag_queue *inet_frag_create (struct netns_frags *nf, +static noinline struct inet_frag_queue *inet_frag_create(struct netns_frags *nf,struct inet_frags *f,void *arg) {struct inet_frag_queue *q;
# ========
# captured on: Tue Apr 23 15:46:09 2013
# hostname : dragon
# os release : 3.9.0-rc5-upstream_frag_work07-LRU-per-CPU+
# perf version : 2.6.32-358.2.1.el6.x86_64.debug
# arch : x86_64
# nrcpus online : 24
# nrcpus avail : 24
# cpudesc : Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz
# cpuid : GenuineIntel,6,45,7
# total memory : 65951448 kB
# cmdline : /usr/bin/perf record -g -a
# event : name = cycles, type = 0, config = 0x0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern = 0, excl_host = 0, excl_guest = 1, precise_ip = 0, id = { 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48 }
# HEADER_CPU_TOPOLOGY info available, use -I to display
# HEADER_NUMA_TOPOLOGY info available, use -I to display
# ========
#
# Samples: 58K of event 'cycles'
# Event count (approx.): 34169718296
#
# Overhead Command Shared Object Symbol
# ........ ........... ................. .......................................
#
70.12% ksoftirqd/1 [kernel.kallsyms] [k] _raw_spin_lock
|
--- _raw_spin_lock
|
|--19.70%-- ip_defrag
| ip_local_deliver
| ip_rcv_finish
| ip_rcv
| __netif_receive_skb_core
| __netif_receive_skb
| netif_receive_skb
| napi_gro_receive
| ixgbe_poll
| net_rx_action
| __do_softirq
| |
| --19.67%-- run_ksoftirqd
| smpboot_thread_fn
| kthread
| ret_from_fork
|
|--17.36%-- inet_frag_kill
| |
| |--15.04%-- inet_frag_evictor
| | ip_defrag
| | ip_local_deliver
| | ip_rcv_finish
| | ip_rcv
| | __netif_receive_skb_core
| | __netif_receive_skb
| | netif_receive_skb
| | napi_gro_receive
| | ixgbe_poll
| | net_rx_action
| | __do_softirq
| | |
| | --14.91%-- run_ksoftirqd
| | smpboot_thread_fn
| | kthread
| | ret_from_fork
| |
| --2.32%-- ip_defrag
| ip_local_deliver
| ip_rcv_finish
| ip_rcv
| __netif_receive_skb_core
| __netif_receive_skb
| netif_receive_skb
| napi_gro_receive
| ixgbe_poll
| net_rx_action
| __do_softirq
| |
| --2.32%-- run_ksoftirqd
| smpboot_thread_fn
| kthread
| ret_from_fork
|
|--17.15%-- inet_frag_intern
| inet_frag_create
| inet_frag_find
| ip_defrag
| ip_local_deliver
| ip_rcv_finish
| ip_rcv
| __netif_receive_skb_core
| __netif_receive_skb
| netif_receive_skb
| napi_gro_receive
| ixgbe_poll
| net_rx_action
| __do_softirq
| |
| --17.13%-- run_ksoftirqd
| smpboot_thread_fn
| kthread
| ret_from_fork
|
--15.52%-- inet_frag_evictor
ip_defrag
ip_local_deliver
ip_rcv_finish
ip_rcv
__netif_receive_skb_core
__netif_receive_skb
netif_receive_skb
napi_gro_receive
ixgbe_poll
net_rx_action
__do_softirq
|
--15.37%-- run_ksoftirqd
smpboot_thread_fn
kthread
ret_from_fork 9.61% swapper [kernel.kallsyms] [k] _raw_spin_lock
|
--- _raw_spin_lock
|
|--2.46%-- inet_frag_kill
| inet_frag_evictor
| ip_defrag
| ip_local_deliver
| ip_rcv_finish
| ip_rcv
| __netif_receive_skb_core
| __netif_receive_skb
| netif_receive_skb
| napi_gro_receive
| ixgbe_poll
| net_rx_action
| __do_softirq
| irq_exit
| do_IRQ
| common_interrupt
| cpuidle_enter_tk
| cpuidle_enter_state
| cpuidle_idle_call
| cpu_idle
| start_secondary
|
|--2.44%-- ip_defrag
| ip_local_deliver
| ip_rcv_finish
| ip_rcv
| __netif_receive_skb_core
| __netif_receive_skb
| netif_receive_skb
| napi_gro_receive
| ixgbe_poll
| net_rx_action
| __do_softirq
| irq_exit
| |
| --2.42%-- do_IRQ
| common_interrupt
| |
| --2.41%-- cpuidle_enter_tk
| cpuidle_enter_state
| cpuidle_idle_call
| cpu_idle
| start_secondary
|
|--2.38%-- inet_frag_evictor
| ip_defrag
| ip_local_deliver
| ip_rcv_finish
| ip_rcv
| __netif_receive_skb_core
| __netif_receive_skb
| netif_receive_skb
| napi_gro_receive
| ixgbe_poll
| net_rx_action
| __do_softirq
| irq_exit
| do_IRQ
| common_interrupt
| cpuidle_enter_tk
| cpuidle_enter_state
| cpuidle_idle_call
| cpu_idle
| start_secondary
|
--2.28%-- inet_frag_intern
inet_frag_create inet_frag_find
ip_defrag
ip_local_deliver
ip_rcv_finish
ip_rcv __netif_receive_skb_core __netif_receive_skb netif_receive_skb napi_gro_receive
ixgbe_poll
net_rx_action
__do_softirq
irq_exit
|
--2.27%-- do_IRQ
common_interrupt
|
--2.25%-- cpuidle_enter_tk
cpuidle_enter_state cpuidle_idle_call cpu_idle start_secondary
1.91% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_find
1.66% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_intern
1.54% ksoftirqd/1 [kernel.kallsyms] [k] ip_defrag
1.52% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_kill
1.19% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_evictor
1.05% ksoftirqd/1 [kernel.kallsyms] [k] __percpu_counter_add
0.77% ksoftirqd/1 [kernel.kallsyms] [k] __list_del_entry
0.53% ksoftirqd/1 [kernel.kallsyms] [k] _raw_read_lock
0.49% ksoftirqd/1 [kernel.kallsyms] [k] ip4_frag_match
0.44% ksoftirqd/1 [kernel.kallsyms] [k] __list_add
0.42% ksoftirqd/1 [kernel.kallsyms] [k] inet_getpeer
0.40% perf [kernel.kallsyms] [k] _raw_spin_lock
0.38% ksoftirqd/1 [kernel.kallsyms] [k] _raw_spin_lock_irqsave
0.33% ksoftirqd/1 [kernel.kallsyms] [k] __slab_free
0.29% ksoftirqd/1 [ixgbe] [k] ixgbe_poll
0.26% ksoftirqd/1 [kernel.kallsyms] [k] fib_table_lookup
0.24% swapper [kernel.kallsyms] [k] inet_frag_find
0.23% ksoftirqd/1 [kernel.kallsyms] [k] __netif_receive_skb_core
0.18% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_destroy
0.18% ksoftirqd/1 [kernel.kallsyms] [k] inet_putpeer
0.17% ksoftirqd/1 [kernel.kallsyms] [k] memcpy
0.16% swapper [kernel.kallsyms] [k] inet_frag_evictor
0.16% swapper [kernel.kallsyms] [k] inet_frag_kill
0.14% swapper [kernel.kallsyms] [k] inet_frag_intern
0.14% swapper [kernel.kallsyms] [k] ip_defrag
0.13% ksoftirqd/1 [kernel.kallsyms] [k] build_skb
0.13% ksoftirqd/1 [kernel.kallsyms] [k] ip_route_input_noref
0.13% ksoftirqd/1 [kernel.kallsyms] [k] __internal_add_timer
0.12% ksoftirqd/1 [kernel.kallsyms] [k] _raw_spin_unlock_irqrestore
0.12% ksoftirqd/1 [kernel.kallsyms] [k] skb_release_data
0.11% ksoftirqd/1 [kernel.kallsyms] [k] ip_rcv
0.11% ksoftirqd/1 [kernel.kallsyms] [k] skb_release_head_state
0.10% swapper [kernel.kallsyms] [k] __percpu_counter_add
0.10% ksoftirqd/1 [kernel.kallsyms] [k] __netdev_alloc_frag
0.10% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_alloc
0.09% ksoftirqd/1 [kernel.kallsyms] [k] ip4_hashfn
0.09% ksoftirqd/1 [kernel.kallsyms] [k] dev_gro_receive
0.09% ksoftirqd/1 [kernel.kallsyms] [k] put_compound_page
0.09% ksoftirqd/1 [kernel.kallsyms] [k] check_leaf
0.09% ksoftirqd/1 [kernel.kallsyms] [k] kmem_cache_free
0.08% ksoftirqd/1 [kernel.kallsyms] [k] kmem_cache_alloc
0.08% ksoftirqd/1 [kernel.kallsyms] [k] put_page
0.08% ksoftirqd/1 [kernel.kallsyms] [k] ip4_frag_free
0.08% ksoftirqd/1 [kernel.kallsyms] [k] nf_iterate
0.08% ksoftirqd/1 [kernel.kallsyms] [k] ip_rcv_finish
0.07% swapper [kernel.kallsyms] [k] __list_del_entry
0.07% swapper [kernel.kallsyms] [k] ip4_frag_match
0.07% ksoftirqd/1 [kernel.kallsyms] [k] __kmalloc
0.06% kworker/1:1 [kernel.kallsyms] [k] _raw_spin_lock
0.06% ksoftirqd/1 [kernel.kallsyms] [k] setup_object
0.06% ksoftirqd/1 [kernel.kallsyms] [k] swiotlb_sync_single_for_cpu
0.06% ksoftirqd/1 [kernel.kallsyms] [k] skb_free_head
0.06% ksoftirqd/1 [kernel.kallsyms] [k] fib_validate_source
0.06% swapper [kernel.kallsyms] [k] __list_add
0.05% ksoftirqd/1 [kernel.kallsyms] [k] memset
0.05% ksoftirqd/1 [kernel.kallsyms] [k] detach_if_pending
0.05% swapper [kernel.kallsyms] [k] _raw_read_lock
0.05% ksoftirqd/1 [kernel.kallsyms] [k] __copy_skb_header
0.05% ksoftirqd/1 [kernel.kallsyms] [k] try_to_wake_up
0.05% swapper [kernel.kallsyms] [k] __slab_free
0.05% ksoftirqd/1 [kernel.kallsyms] [k] idle_cpu
0.04% ksoftirqd/1 [kernel.kallsyms] [k] inet_gro_receive
0.04% swapper [kernel.kallsyms] [k] inet_getpeer
0.04% ksoftirqd/1 [kernel.kallsyms] [k] eth_type_trans
0.04% ksoftirqd/1 [kernel.kallsyms] [k] mod_timer
0.04% ksoftirqd/1 [kernel.kallsyms] [k] __slab_alloc
0.04% ksoftirqd/1 [kernel.kallsyms] [k] nf_hook_slow
0.04% ksoftirqd/1 [kernel.kallsyms] [k] ip_local_deliver
0.04% ksoftirqd/1 [kernel.kallsyms] [k] ip4_frag_init
0.04% ksoftirqd/1 [kernel.kallsyms] [k] __udp4_lib_rcv
0.04% ksoftirqd/1 [kernel.kallsyms] [k] del_timer
0.04% swapper [kernel.kallsyms] [k] _raw_spin_lock_irqsave
0.03% ksoftirqd/1 [kernel.kallsyms] [k] __netdev_alloc_skb
0.03% ksoftirqd/1 [kernel.kallsyms] [k] netif_receive_skb
0.03% ksoftirqd/1 [kernel.kallsyms] [k] napi_gro_receive
0.03% ksoftirqd/1 [kernel.kallsyms] [k] __skb_clone
0.03% ksoftirqd/1 [kernel.kallsyms] [k] __pskb_pull_tail
0.03% ksoftirqd/1 [kernel.kallsyms] [k] sock_def_readable
0.03% ksoftirqd/1 [kernel.kallsyms] [k] new_slab
0.03% ksoftirqd/1 [kernel.kallsyms] [k] get_slab
0.03% ksoftirqd/1 [kernel.kallsyms] [k] find_last_bit
0.03% ksoftirqd/1 [kernel.kallsyms] [k] __udp4_lib_lookup
0.03% ksoftirqd/1 [kernel.kallsyms] [k] get_page_from_freelist
0.03% swapper [kernel.kallsyms] [k] intel_idle
0.03% ksoftirqd/1 [kernel.kallsyms] [k] init_timer_key
0.02% ksoftirqd/1 [kernel.kallsyms] [k] enqueue_task_fair
0.02% ksoftirqd/1 [kernel.kallsyms] [k] skb_try_coalesce
0.02% ksoftirqd/1 [kernel.kallsyms] [k] skb_copy_bits
0.02% swapper [kernel.kallsyms] [k] skb_release_head_state
0.02% ksoftirqd/1 [kernel.kallsyms] [k] __kfree_skb
0.02% ksoftirqd/1 [kernel.kallsyms] [k] __netif_receive_skb
0.02% ksoftirqd/1 [kernel.kallsyms] [k] ktime_get
0.02% ksoftirqd/1 [kernel.kallsyms] [k] kfree
0.02% ksoftirqd/1 [kernel.kallsyms] [k] resched_task
0.02% ksoftirqd/1 [kernel.kallsyms] [k] __sk_mem_schedule
0.02% swapper [ixgbe] [k] ixgbe_poll
0.02% swapper [kernel.kallsyms] [k] __netif_receive_skb_core
0.02% ksoftirqd/1 [kernel.kallsyms] [k] lock_timer_base
0.02% swapper [kernel.kallsyms] [k] inet_putpeer
0.02% ksoftirqd/1 [kernel.kallsyms] [k] list_del
0.02% ksoftirqd/1 [ixgbe] [k] ixgbe_alloc_rx_buffers
0.02% ksoftirqd/1 [kernel.kallsyms] [k] rcu_check_callbacks
0.02% ksoftirqd/1 [kernel.kallsyms] [k] swiotlb_sync_single
0.02% ksoftirqd/1 [bridge] [k] ip_sabotage_in
0.02% ksoftirqd/1 [kernel.kallsyms] [k] apic_timer_interrupt
0.02% swapper [kernel.kallsyms] [k] fib_table_lookup
0.02% ksoftirqd/1 [kernel.kallsyms] [k] update_rq_clock
0.02% ksoftirqd/1 [kernel.kallsyms] [k] find_busiest_group
0.02% ksoftirqd/1 [kernel.kallsyms] [k] internal_add_timer
0.02% swapper [kernel.kallsyms] [k] inet_frag_destroy
0.01% swapper [kernel.kallsyms] [k] ip_rcv_finish
0.01% swapper [kernel.kallsyms] [k] build_skb
0.01% swapper [kernel.kallsyms] [k] find_busiest_group
0.01% swapper [kernel.kallsyms] [k] idle_cpu
0.01% ksoftirqd/1 [kernel.kallsyms] [k] trigger_load_balance
0.01% swapper [kernel.kallsyms] [k] ip4_hashfn
0.01% ksoftirqd/1 [kernel.kallsyms] [k] lapic_next_deadline
0.01% ksoftirqd/1 [kernel.kallsyms] [k] hrtimer_interrupt
0.01% ksoftirqd/1 [kernel.kallsyms] [k] kfree_skb
0.01% ksoftirqd/1 [kernel.kallsyms] [k] sock_queue_rcv_skb
0.01% ksoftirqd/1 [kernel.kallsyms] [k] inet_frag_create
0.01% perf [kernel.kallsyms] [k] copy_user_generic_string
0.01% swapper [kernel.kallsyms] [k] _raw_spin_unlock_irqrestore
0.01% perf [kernel.kallsyms] [k] inet_frag_find
0.01% swapper [kernel.kallsyms] [k] put_compound_page
0.01% ksoftirqd/1 [kernel.kallsyms] [k] update_cfs_rq_blocked_load
0.01% ksoftirqd/1 [kernel.kallsyms] [k] udp_queue_rcv_skb
0.01% swapper [kernel.kallsyms] [k] ip4_frag_free
0.01% swapper [kernel.kallsyms] [k] kmem_cache_alloc
0.01% swapper [kernel.kallsyms] [k] memcpy
0.01% swapper [kernel.kallsyms] [k] get_nohz_timer_target
0.01% swapper [kernel.kallsyms] [k] __kmalloc
0.01% swapper [kernel.kallsyms] [k] ip_rcv
0.01% ksoftirqd/1 [kernel.kallsyms] [k] unfreeze_partials
0.01% perf [kernel.kallsyms] [k] __list_add
0.01% ksoftirqd/1 [kernel.kallsyms] [k] task_tick_fair
0.01% ksoftirqd/1 [kernel.kallsyms] [k] dma_issue_pending_all
0.01% ksoftirqd/1 [kernel.kallsyms] [k] skb_add_rx_frag
0.01% ksoftirqd/1 [kernel.kallsyms] [k] skb_clone
0.01% swapper [kernel.kallsyms] [k] ip_route_input_noref
0.01% ksoftirqd/1 [kernel.kallsyms] [k] irq_enter
0.01% swapper [kernel.kallsyms] [k] inet_frag_alloc
0.01% swapper [kernel.kallsyms] [k] detach_if_pending
0.01% ksoftirqd/1 [kernel.kallsyms] [k] scheduler_tick
0.01% perf [kernel.kallsyms] [k] inet_frag_evictor
0.01% swapper [kernel.kallsyms] [k] __slab_alloc
0.01% swapper [kernel.kallsyms] [k] mod_timer
0.01% ksoftirqd/1 [kernel.kallsyms] [k] __wake_up_sync_key
0.01% ksoftirqd/1 [ixgbe] [k] ixgbe_update_dca
0.01% ksoftirqd/1 [kernel.kallsyms] [k] __udp_queue_rcv_skb
0.01% ksoftirqd/1 [kernel.kallsyms] [k] run_posix_cpu_timers
0.01% ksoftirqd/1 [kernel.kallsyms] [k] ip_local_deliver_finish
0.01% ksoftirqd/1 [kernel.kallsyms] [k] swiotlb_sync_single_for_device
0.01% perf [kernel.kallsyms] [k] inet_frag_kill
0.01% swapper [kernel.kallsyms] [k] dev_gro_receive
0.01% swapper [kernel.kallsyms] [k] __netdev_alloc_frag
0.01% swapper [kernel.kallsyms] [k] ip4_frag_init
0.01% swapper [kernel.kallsyms] [k] update_blocked_averages
0.01% ksoftirqd/1 [kernel.kallsyms] [k] get_partial_node
0.01% ksoftirqd/1 [kernel.kallsyms] [k] put_cpu_partial
0.01% ksoftirqd/1 [kernel.kallsyms] [k] __switch_to
0.01% ksoftirqd/1 [kernel.kallsyms] [k] perf_event_task_tick
0.01% swapper [kernel.kallsyms] [k] skb_release_data
0.01% swapper [kernel.kallsyms] [k] del_timer
0.01% ksoftirqd/1 [kernel.kallsyms] [k] account_system_time
0.01% ksoftirqd/1 [kernel.kallsyms] [k] net_rx_action
0.01% ksoftirqd/1 [kernel.kallsyms] [k] raise_softirq
0.01% ksoftirqd/1 [kernel.kallsyms] [k] __alloc_pages_nodemask
0.01% ksoftirqd/1 [kernel.kallsyms] [k] next_zones_zonelist
0.01% swapper [kernel.kallsyms] [k] put_page
0.01% swapper [kernel.kallsyms] [k] add_interrupt_randomness
0.01% swapper [kernel.kallsyms] [k] swiotlb_sync_single_for_cpu
0.01% swapper [ixgbe] [k] ixgbe_alloc_rx_buffers
0.01% swapper [kernel.kallsyms] [k] nf_hook_slow
0.01% swapper [kernel.kallsyms] [k] cpumask_next_and
0.01% swapper [kernel.kallsyms] [k] __internal_add_timer
0.01% ksoftirqd/1 [kernel.kallsyms] [k] timerqueue_add
0.01% ksoftirqd/1 [kernel.kallsyms] [k] __update_cpu_load
0.01% swapper [kernel.kallsyms] [k] fib_validate_source
0.01% perf [kernel.kallsyms] [k] jbd2_journal_put_journal_head
0.01% perf [kernel.kallsyms] [k] mark_page_accessed
0.01% ksoftirqd/1 [kernel.kallsyms] [k] rebalance_domains
0.01% perf [kernel.kallsyms] [k] ip_defrag
0.01% ksoftirqd/1 [kernel.kallsyms] [k] __irq_work_run
0.01% swapper [kernel.kallsyms] [k] sched_avg_update
0.01% ksoftirqd/1 [kernel.kallsyms] [k] profile_tick
0.01% ksoftirqd/1 [kernel.kallsyms] [k] run_ksoftirqd
0.01% ksoftirqd/1 [kernel.kallsyms] [k] update_curr
0.01% ksoftirqd/1 [kernel.kallsyms] [k] intel_pmu_disable_all
0.01% ksoftirqd/1 [kernel.kallsyms] [k] check_preempt_wakeup
0.01% ksoftirqd/1 [kernel.kallsyms] [k] perf_pmu_disable
0.01% ksoftirqd/1 [kernel.kallsyms] [k] ttwu_do_wakeup
0.00% ksoftirqd/1 [kernel.kallsyms] [k] tick_sched_timer
0.00% kworker/1:1 [kernel.kallsyms] [k] inet_frag_find
0.00% ksoftirqd/1 [kernel.kallsyms] [k] hrtimer_run_queues
0.00% ksoftirqd/1 [kernel.kallsyms] [k] alloc_pages_current
0.00% ksoftirqd/1 [kernel.kallsyms] [k] check_preempt_curr
0.00% ksoftirqd/1 [kernel.kallsyms] [k] fib_compute_spec_dst
0.00% ksoftirqd/1 [kernel.kallsyms] [k] ipv4_pktinfo_prepare
0.00% swapper [kernel.kallsyms] [k] eth_type_trans
0.00% swapper [kernel.kallsyms] [k] nf_iterate
0.00% swapper [kernel.kallsyms] [k] __netdev_alloc_skb
0.00% perf [kernel.kallsyms] [k] inet_getpeer
0.00% ksoftirqd/1 [kernel.kallsyms] [k] _cond_resched
0.00% swapper [kernel.kallsyms] [k] rcu_idle_exit
0.00% ksoftirqd/1 [kernel.kallsyms] [k] load_balance
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __free_pages
0.00% perf [kernel.kallsyms] [k] __percpu_counter_add
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __zone_watermark_ok
0.00% swapper [kernel.kallsyms] [k] get_slab
0.00% swapper [kernel.kallsyms] [k] find_last_bit
0.00% ksoftirqd/1 [kernel.kallsyms] [k] discard_slab
0.00% swapper [kernel.kallsyms] [k] kmem_cache_free
0.00% kworker/1:1 [kernel.kallsyms] [k] dequeue_task
0.00% ksoftirqd/1 [kernel.kallsyms] [k] policy_zonelist
0.00% ksoftirqd/1 [kernel.kallsyms] [k] run_rebalance_domains
0.00% ksoftirqd/1 [kernel.kallsyms] [k] free_one_page
0.00% kworker/1:1 [kernel.kallsyms] [k] __update_entity_load_avg_contrib
0.00% ksoftirqd/1 [kernel.kallsyms] [k] update_process_times
0.00% ksoftirqd/1 [kernel.kallsyms] [k] update_cfs_shares
0.00% swapper [kernel.kallsyms] [k] cpuidle_wrap_enter
0.00% kworker/1:1 [kernel.kallsyms] [k] dequeue_task_fair
0.00% ksoftirqd/1 [kernel.kallsyms] [k] rb_next
0.00% ksoftirqd/1 [kernel.kallsyms] [k] native_sched_clock
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __inc_zone_state
0.00% kworker/1:1 [kernel.kallsyms] [k] __list_del_entry
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __schedule
0.00% ksoftirqd/1 [kernel.kallsyms] [k] run_timer_softirq
0.00% ksoftirqd/1 [kernel.kallsyms] [k] sched_clock_tick
0.00% ksoftirqd/1 [kernel.kallsyms] [k] mod_zone_page_state
0.00% kworker/1:1 [kernel.kallsyms] [k] _raw_spin_lock_irq
0.00% ksoftirqd/1 [kernel.kallsyms] [k] udp_rcv
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __run_hrtimer
0.00% ksoftirqd/1 [kernel.kallsyms] [k] sched_clock_cpu
0.00% ksoftirqd/1 [kernel.kallsyms] [k] perf_adjust_freq_unthr_context
0.00% ksoftirqd/1 [kernel.kallsyms] [k] skb_push
0.00% ksoftirqd/1 [kernel.kallsyms] [k] security_sock_rcv_skb
0.00% swapper [kernel.kallsyms] [k] list_del
0.00% ksoftirqd/1 [kernel.kallsyms] [k] sk_filter
0.00% perf [kernel.kallsyms] [k] __block_commit_write
0.00% swapper [kernel.kallsyms] [k] kfree_skb
0.00% swapper [kernel.kallsyms] [k] lock_timer_base
0.00% perf [kernel.kallsyms] [k] inet_frag_intern
0.00% perf [kernel.kallsyms] [k] ip4_frag_free
0.00% perf [kernel.kallsyms] [k] __kmalloc
0.00% ksoftirqd/1 [kernel.kallsyms] [k] irq_work_run
0.00% swapper [kernel.kallsyms] [k] irq_exit
0.00% swapper [kernel.kallsyms] [k] skb_free_head
0.00% swapper [kernel.kallsyms] [k] menu_select
0.00% swapper [kernel.kallsyms] [k] find_next_bit
0.00% swapper [kernel.kallsyms] [k] memset
0.00% swapper [kernel.kallsyms] [k] lapic_next_deadline
0.00% swapper [kernel.kallsyms] [k] update_cfs_rq_blocked_load
0.00% swapper [kernel.kallsyms] [k] rebalance_domains
0.00% swapper [kernel.kallsyms] [k] irq_entries_start
0.00% swapper [kernel.kallsyms] [k] get_pageblock_flags_group
0.00% perf [kernel.kallsyms] [k] __slab_free
0.00% swapper [kernel.kallsyms] [k] __update_cpu_load
0.00% kworker/1:1 [kernel.kallsyms] [k] __cpufreq_driver_target
0.00% kworker/1:1 [kernel.kallsyms] [k] find_next_bit
0.00% perf [kernel.kallsyms] [k] _raw_read_lock
0.00% swapper [kernel.kallsyms] [k] __hrtimer_start_range_ns
0.00% swapper [kernel.kallsyms] [k] load_balance
0.00% kworker/1:1 [kernel.kallsyms] [k] finish_task_switch
0.00% perf [kernel.kallsyms] [k] net_rx_action
0.00% swapper [kernel.kallsyms] [k] netif_receive_skb
0.00% swapper [kernel.kallsyms] [k] swiotlb_sync_single_for_device
0.00% kworker/1:1 [kernel.kallsyms] [k] ip4_frag_init
0.00% perf [kernel.kallsyms] [k] iov_iter_copy_from_user_atomic
0.00% kworker/1:1 [kernel.kallsyms] [k] ns_to_timespec
0.00% perf [kernel.kallsyms] [k] _raw_spin_unlock_irqrestore
0.00% ksoftirqd/1 [ixgbe] [k] ixgbe_update_itr
0.00% perf [kernel.kallsyms] [k] __ext4_get_inode_loc
0.00% perf [kernel.kallsyms] [k] __netdev_alloc_frag
0.00% perf [kernel.kallsyms] [k] jbd2_journal_add_journal_head
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __mod_zone_page_state
0.00% perf [kernel.kallsyms] [k] _raw_spin_lock_irqsave
0.00% ksoftirqd/1 [kernel.kallsyms] [k] get_pageblock_flags_group
0.00% perf [kernel.kallsyms] [k] check_leaf
0.00% ksoftirqd/1 [kernel.kallsyms] [k] cpuacct_charge
0.00% kworker/1:1 [kernel.kallsyms] [k] __internal_add_timer
0.00% kworker/1:1 [ixgbe] [k] ixgbe_poll
0.00% kworker/1:1 [kernel.kallsyms] [k] _raw_spin_lock_irqsave
0.00% kworker/1:1 [kernel.kallsyms] [k] __compute_runnable_contrib
0.00% kworker/1:1 [kernel.kallsyms] [k] update_curr
0.00% kworker/1:1 [kernel.kallsyms] [k] queue_delayed_work_on
0.00% ksoftirqd/1 [kernel.kallsyms] [k] pick_next_task_fair
0.00% swapper [kernel.kallsyms] [k] __free_pages
0.00% swapper [kernel.kallsyms] [k] __kfree_skb
0.00% swapper [ixgbe] [k] ixgbe_msix_clean_rings
0.00% perf [kernel.kallsyms] [k] jbd2__journal_start
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __queue_work
0.00% ksoftirqd/1 [kernel.kallsyms] [k] handle_edge_irq
0.00% perf [kernel.kallsyms] [k] __rmqueue
0.00% perf [kernel.kallsyms] [k] cpuacct_charge
0.00% ksoftirqd/1 [kernel.kallsyms] [k] intel_pmu_enable_all
0.00% ksoftirqd/1 [kernel.kallsyms] [k] kthread_data
0.00% ksoftirqd/1 [kernel.kallsyms] [k] handle_irq_event_percpu
0.00% kworker/1:1 [kernel.kallsyms] [k] handle_edge_irq
0.00% perf [kernel.kallsyms] [k] __lru_cache_add
0.00% perf [kernel.kallsyms] [k] alloc_pages_current
0.00% ksoftirqd/1 [kernel.kallsyms] [k] raw_local_deliver
0.00% kworker/1:1 [kernel.kallsyms] [k] od_check_cpu
0.00% ksoftirqd/1 [kernel.kallsyms] [k] can_migrate_task
0.00% ksoftirqd/1 [kernel.kallsyms] [k] default_wake_function
0.00% ksoftirqd/1 [kernel.kallsyms] [k] get_work_pool
0.00% perf [kernel.kallsyms] [k] __zone_watermark_ok
0.00% ksoftirqd/1 [kernel.kallsyms] [k] rb_insert_color
0.00% perf [kernel.kallsyms] [k] radix_tree_lookup_slot
0.00% kworker/1:1 [kernel.kallsyms] [k] update_ts_time_stats
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __wake_up_common
0.00% kworker/1:1 [kernel.kallsyms] [k] cpuacct_charge
0.00% ksoftirqd/1 [kernel.kallsyms] [k] tick_sched_handle
0.00% ksoftirqd/1 [kernel.kallsyms] [k] smpboot_thread_fn
0.00% ksoftirqd/1 [kernel.kallsyms] [k] ktime_get_update_offsets
0.00% kworker/1:1 [kernel.kallsyms] [k] ktime_get
0.00% ksoftirqd/1 [kernel.kallsyms] [k] read_tsc
0.00% ksoftirqd/1 [kernel.kallsyms] [k] kfree_skb_partial
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __rmqueue
0.00% kworker/1:1 [kernel.kallsyms] [k] vmstat_update
0.00% perf [kernel.kallsyms] [k] __find_get_block
0.00% swapper [kernel.kallsyms] [k] int_sqrt
0.00% swapper [kernel.kallsyms] [k] native_sched_clock
0.00% ksoftirqd/1 [kernel.kallsyms] [k] cpumask_next_and
0.00% ksoftirqd/1 [ioatdma] [k] ioat2_issue_pending
0.00% kworker/1:1 [kernel.kallsyms] [k] __queue_delayed_work
0.00% ksoftirqd/1 [kernel.kallsyms] [k] restore_args
0.00% perf [kernel.kallsyms] [k] generic_file_buffered_write
0.00% kworker/1:1 [kernel.kallsyms] [k] __percpu_counter_add
0.00% ksoftirqd/1 [kernel.kallsyms] [k] rcu_irq_enter
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __free_pages_ok
0.00% ksoftirqd/1 [kernel.kallsyms] [k] tick_do_update_jiffies64
0.00% kworker/1:1 [kernel.kallsyms] [k] do_drv_write
0.00% ksoftirqd/1 [kernel.kallsyms] [k] slab_node
0.00% kworker/1:1 [kernel.kallsyms] [k] _raw_read_lock
0.00% kworker/1:1 [kernel.kallsyms] [k] memcpy
0.00% ksoftirqd/1 [kernel.kallsyms] [k] consume_skb
0.00% ksoftirqd/1 [kernel.kallsyms] [k] native_smp_send_reschedule
0.00% ksoftirqd/1 [kernel.kallsyms] [k] smp_apic_timer_interrupt
0.00% ksoftirqd/1 [kernel.kallsyms] [k] do_timer
0.00% kworker/1:1 [kernel.kallsyms] [k] ip4_frag_match
0.00% ksoftirqd/1 [kernel.kallsyms] [k] account_process_tick
0.00% ksoftirqd/1 [kernel.kallsyms] [k] default_send_IPI_mask_sequence_phys
0.00% ksoftirqd/1 [kernel.kallsyms] [k] free_pages_prepare
0.00% ksoftirqd/1 [kernel.kallsyms] [k] irq_exit
0.00% ksoftirqd/1 [kernel.kallsyms] [k] sched_avg_update
0.00% perf [kernel.kallsyms] [k] irq_enter
0.00% ksoftirqd/1 [kernel.kallsyms] [k] ttwu_stat
0.00% perf [kernel.kallsyms] [k] mark_buffer_dirty
0.00% perf [kernel.kallsyms] [k] rcu_check_callbacks
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __skb_dst_set_noref
0.00% perf [kernel.kallsyms] [k] skb_release_data
0.00% kworker/1:1 [kernel.kallsyms] [k] kobject_get
0.00% ksoftirqd/1 [kernel.kallsyms] [k] rcu_irq_exit
0.00% perf [kernel.kallsyms] [k] inet_gro_receive
0.00% perf [kernel.kallsyms] [k] kmem_cache_free
0.00% ksoftirqd/1 [kernel.kallsyms] [k] __do_softirq
0.00% perf [kernel.kallsyms] [k] update_cfs_rq_blocked_load
0.00% perf [kernel.kallsyms] [k] __slab_alloc
0.00% perf [kernel.kallsyms] [k] __pollwait
0.00% perf [kernel.kallsyms] [k] ext4_nonda_switch
0.00% perf [kernel.kallsyms] [k] __internal_add_timer
0.00% swapper [kernel.kallsyms] [k] rcu_irq_enter
0.00% perf [kernel.kallsyms] [k] ext4_da_get_block_prep
0.00% perf [kernel.kallsyms] [k] __srcu_read_unlock
0.00% swapper [kernel.kallsyms] [k] exit_idle
0.00% swapper [kernel.kallsyms] [k] __netif_receive_skb
0.00% swapper [kernel.kallsyms] [k] tick_nohz_idle_exit
0.00% swapper [kernel.kallsyms] [k] new_slab
0.00% swapper [kernel.kallsyms] [k] napi_gro_receive
0.00% swapper [kernel.kallsyms] [k] handle_edge_irq
0.00% ksoftirqd/1 [kernel.kallsyms] [k] update_group_power
0.00% swapper [kernel.kallsyms] [k] setup_object
0.00% perf [kernel.kallsyms] [k] perf_poll
0.00% perf [kernel.kallsyms] [k] __getblk
0.00% ksoftirqd/1 [kernel.kallsyms] [k] find_next_bit
0.00% swapper [kernel.kallsyms] [k] __page_cache_release
0.00% swapper [kernel.kallsyms] [k] tick_nohz_idle_enter
0.00% swapper [kernel.kallsyms] [k] cpuidle_idle_call
0.00% swapper [kernel.kallsyms] [k] irq_to_desc
0.00% swapper [kernel.kallsyms] [k] rcu_needs_cpu
0.00% swapper [kernel.kallsyms] [k] alloc_pages_current
0.00% swapper [kernel.kallsyms] [k] init_timer_key
0.00% swapper [kernel.kallsyms] [k] tick_check_idle
0.00% swapper [kernel.kallsyms] [k] napi_complete
#
# (For a higher level overview, try: perf report --sort comm,dso) #
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 13 lines · Jesper Dangaard Brouer
Yes, traffic patterns do affect the results, BUT you have to be really careful profiling this:
Notice, that
inet_frag_find()also indirectly takes the LRU lock, and the perf tool will blameinet_frag_find(). This is very subtle and happens with a traffic pattern that want to create new frag queues (e.g. not found in the hash list).
The problem is thatinet_frag_find()callsinet_frag_create()(if q is not found) which callsinet_frag_intern()which callsinet_frag_lru_add()taking the LRU lock. All of these functions gets inlined by the compiler, thusinet_frag_find()gets the blame.
Quoted 1 line
To avoid pissing people off:
Ah, come on. I don't think you do that. ;)
Quoted 9 lines
Yes, having a long list in the hash bucket is obviously also contributes significantly. Yes, we still should increase the hash bucket size. I'm just pointing out be careful about what you actually profile ;-)
Please see below, profiling of current next-next, with "noinline" added to
inet_frag_intern,inet_frag_allocandinet_frag_create. Run under test 20G3F+MQ. I hope you can see my point with the LRU list lock, please let me know if I have missed something.
I have no objections. My ipv6 test case simply does not get the memory usage of the fragment cache over the thresholds, so I have no contention there, just dropping because of the 128 list length limit.
As soon as I would fill up the fragment cache the contention will be on the lru lock as you showed here.
Greetings,
Hannes
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
In reply to Jesper Dangaard BrouerQuoted 5 lines · Jesper Dangaard Brouer
Quoted 1 line · Eric Dumazet
This strategy wont really help DDOS attacks. No frag will ever complete.
I beg to differ.
We already had a discussion on this topic.
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
In reply to Jesper Dangaard BrouerQuoted 8 lines · Jesper Dangaard Brouer
Quoted 1 line · Eric Dumazet
I am not sure its worth adding extra complexity.
It's not that complex, and we simply need it, else an attacker can DoS us very easily by sending a burst every 30 sec. We do need this change, else we must revert Hannes patch, and find a complete other approach of removing the LRU list system.
Its a never ending stuff.
fragments are fundamentally not suitable for any workload that can be attacked by an hostile guy.
The guy will adapt its strategy knowing yours.
Thats pretty easy for him, linux sources are public.
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
In reply to Jesper Dangaard BrouerQuoted 2 lines · Jesper Dangaard Brouer
What is a reasonable max depth value for you?
Current one is OK.
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
In reply to Jesper Dangaard BrouerQuoted 4 lines · Jesper Dangaard Brouer
When removing the LRU system (which is the real bottleneck, see perf tests in cover mail), and doing direct hash cleaning we are trading-in accuracy.
You are mixing performance issues and correctness.
Quoted 6 lines
The reason I don't want a too big hash table is the following.
Worst case 1024 buckets * 130K bytes = 133 MBytes, which on smaller embedded systems is a lot of kernel memory we are permitting a remote host to "lock-down".
Thats pretty irrelevant, memory is limited by the total amount of memory used by fragments, not by hash table size.
Its called /proc/sys/net/ipv4/ipfrag_high_thresh
It seems you me you are spending time on wrong things.
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Jesper Dangaard Brouer
When removing the LRU system (which is the real bottleneck, see perf tests in cover mail), and doing direct hash cleaning we are trading-in accuracy.
[...]
Quoted 10 lines
Quoted 5 lines
The reason I don't want a too big hash table is the following.
Worst case 1024 buckets * 130K bytes = 133 MBytes, which on smaller embedded systems is a lot of kernel memory we are permitting a remote host to "lock-down".
Thats pretty irrelevant, memory is limited by the total amount of memory used by fragments, not by hash table size.
Its called
/proc/sys/net/ipv4/ipfrag_high_thresh
I was talking about patch-03, where I do "direct hash cleaning", and have moved the mem limit "ipfrag_high_thresh" into the hash cleaning step.
It seems we are talking past each-other...
--Jesper
Re: [net-next PATCH 2/3] net: fix enforcing of fragment queue hash list depth
Quoted 11 lines · Jesper Dangaard Brouer
Quoted 4 lines · Eric Dumazet
Thats pretty irrelevant, memory is limited by the total amount of memory used by fragments, not by hash table size.
Its called
/proc/sys/net/ipv4/ipfrag_high_threshI was talking about patch-03, where I do "direct hash cleaning", and have moved the mem limit "
ipfrag_high_thresh" into the hash cleaning step.
I am fine to remove LRU, as maintaining a LRU is too expensive and this LRU has little purpose.
Old frags are evicted anyway because they have a timer.
We have to keep a global limit, especially if we increase hash table size, because even with perfect hashing and one frag per hash slot we might consume too much ram.
We can rename it if you wish but currently this is ipfrag_high_thresh.
RFC PATCH 3/3 net: remove fragmentation LRU list system
In reply to Jesper Dangaard BrouerWORK-IN-PROGRESS
I have a bug in inet_frag_cleanup_netns(), which clean/deletes fragments when a network namespace is taken down.
TODO:
- netns mem limits and hash cleaning have conflicts
- Howto can we re-add the IPSTATS_MIB_REASMFAILS stats?
- Remove nf->low_thresh
- Doc new max_hash_depth
NOT-signed-off
---
include/net/inet_frag.h | 36 ++++++------ include/net/ipv6.h | 2 - net/ipv4/inet_fragment.c | 96 +++++++++++++++++-------------- net/ipv4/ip_fragment.c | 19 +----- net/ipv6/netfilter/nf_conntrack_reasm.c | 5 -- net/ipv6/reassembly.c | 8 --- 6 files changed, 75 insertions(+), 91 deletions(-)
include/net/inet_frag.h +18 -18
@@ -4,9 +4,7 @@#include <linux/percpu_counter.h> struct netns_frags { -int nqueues; -struct list_head lru_list; -spinlock_t lru_lock; +struct percpu_counter nqueues;/* The percpu_counter "mem" need to be cacheline aligned. * mem.count must not share cacheline with other writers
@@ -133,28 +131,30 @@ static inline int sum_frag_mem_limit(struct netns_frags *nf)return res; } -static inline void inet_frag_lru_move (struct inet_frag_queue *q) +static inline void dec_frag_nqueues (struct inet_frag_queue *q) { -spin_lock (&q->net->lru_lock); -list_move_tail (&q->lru_list, &q->net->lru_list); -spin_unlock (&q->net->lru_lock); +percpu_counter_dec (&q->net->nqueues); } -static inline void inet_frag_lru_del (struct inet_frag_queue *q) +static inline void inc_frag_nqueues (struct inet_frag_queue *q) { -spin_lock (&q->net->lru_lock); -list_del (&q->lru_list); - q->net->nqueues--; -spin_unlock (&q->net->lru_lock); +percpu_counter_inc (&q->net->nqueues); } -static inline void inet_frag_lru_add (struct netns_frags *nf, -struct inet_frag_queue *q) +static inline void init_frag_nqueues (struct netns_frags *nf) { -spin_lock (&nf->lru_lock); -list_add_tail (&q->lru_list, &nf->lru_list); - q->net->nqueues++; -spin_unlock (&nf->lru_lock); +percpu_counter_init (&nf->nqueues,0 ); +} + +static inline int sum_frag_nqueues (struct netns_frags *nf) +{ +int res; + +local_bh_disable (); + res =percpu_counter_sum_positive (&nf->nqueues); +local_bh_enable (); + +return res; }/* RFC 3168 support :
include/net/ipv6.h +1 -1
@@ -286,7 +286,7 @@ static inline bool ipv6_accept_ra(struct inet6_dev *idev)#if IS_ENABLED (CONFIG_IPV6 )static inline int ip6_frag_nqueues (struct net *net) { -return net->ipv6.frags.nqueues; +return sum_frag_nqueues (&net->ipv6.frags); }static inline int ip6_frag_mem (struct net *net)
net/ipv4/inet_fragment.c +53 -43
157 lines not on this page · raw message
net/ipv4/ip_fragment.c +2 -17
@@ -18,6 +18,7 @@* John McDonald : 0 length frag bug. * Alexey Kuznetsov: SMP races, threading, cleanup. * Patrick McHardy : LRU queue of frag heads for evictor. +* Jesper D Brouer : Removed LRU queue for evictor. */ #define pr_fmt (fmt) "IPv4: " fmt
@@ -88,7 +89,7 @@ static struct inet_frags ip4_frags;int ip_frag_nqueues (struct net *net) { -return net->ipv4.frags.nqueues; +return sum_frag_nqueues (&net->ipv4.frags); }int ip_frag_mem (struct net *net)
@@ -176,18 +177,6 @@ static void ipq_kill(struct ipq *ipq)inet_frag_kill (&ipq->q, &ip4_frags); } -/* Memory limiting on fragments. Evictor trashes the oldest -* fragment queue until we are back under the threshold. -*/ -static void ip_evictor (struct net *net) -{ -int evicted; - - evicted =inet_frag_evictor (&net->ipv4.frags, &ip4_frags, false); -if (evicted) -IP_ADD_STATS_BH (net,IPSTATS_MIB_REASMFAILS , evicted); -} -/* * Oops, a fragment queue timed out. Kill it and send an ICMP reply. */
@@ -495,7 +484,6 @@ found: qp->q.meat == qp->q.len)return ip_frag_reasm (qp, prev, dev); -inet_frag_lru_move (&qp->q);return -EINPROGRESS ; err:
@@ -645,9 +633,6 @@ int ip_defrag(struct sk_buff *skb, u32 user) net = skb->dev ?dev_net (skb->dev) :dev_net (skb_dst (skb)->dev);IP_INC_STATS_BH (net,IPSTATS_MIB_REASMREQDS ); -/* Start by cleaning up the memory. */ -ip_evictor (net); -/* Lookup (or create) queue header */ if ((qp =ip_find (net,ip_hdr (skb), user)) !=NULL ) {int ret;
net/ipv6/netfilter/nf_conntrack_reasm.c +0 -5
@@ -338,7 +338,6 @@ found: fq->q.last_in |=INET_FRAG_FIRST_IN ; } -inet_frag_lru_move (&fq->q);return 0 ; discard_fq:
@@ -583,10 +582,6 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user) hdr =ipv6_hdr (clone); fhdr = (struct frag_hdr *)skb_transport_header (clone); -local_bh_disable (); -inet_frag_evictor (&net->nf_frag.frags, &nf_frags, false); -local_bh_enable (); - fq =fq_find (net, fhdr->identification, user, &hdr->saddr, &hdr->daddr,ip6_frag_ecn (hdr));if (fq ==NULL ) {
net/ipv6/reassembly.c +1 -7
@@ -25,6 +25,7 @@* David Stevens and * YOSHIFUJI,H. @USAGI Always remove fragment header to * calculate ICV correctly. +* Jesper Dangaard Brouer Removed LRU queue for evictor. */ #define pr_fmt (fmt) "IPv6: " fmt
@@ -343,7 +344,6 @@ found: fq->q.meat == fq->q.len)return ip6_frag_reasm (fq, prev, dev); -inet_frag_lru_move (&fq->q);return -1 ; discard_fq:
@@ -512,7 +512,6 @@ static int ipv6_frag_rcv(struct sk_buff *skb)struct frag_queue *fq;const struct ipv6hdr *hdr =ipv6_hdr (skb);struct net *net =dev_net (skb_dst (skb)->dev); -int evicted;IP6_INC_STATS_BH (net,ip6_dst_idev (skb_dst (skb)),IPSTATS_MIB_REASMREQDS );
@@ -537,11 +536,6 @@ static int ipv6_frag_rcv(struct sk_buff *skb)return 1 ; } - evicted =inet_frag_evictor (&net->ipv6.frags, &ip6_frags, false); -if (evicted) -IP6_ADD_STATS_BH (net,ip6_dst_idev (skb_dst (skb)), -IPSTATS_MIB_REASMFAILS , evicted); - fq =fq_find (net, fhdr->identification, &hdr->saddr, &hdr->daddr,ip6_frag_ecn (hdr));if (fq !=NULL ) {