aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/inet_frag.h22
-rw-r--r--net/ipv4/inet_fragment.c12
-rw-r--r--net/ipv4/ip_fragment.c4
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c5
-rw-r--r--net/ipv6/reassembly.c4
5 files changed, 33 insertions, 14 deletions
diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h
index e0eec7450f15..3f237db0a426 100644
--- a/include/net/inet_frag.h
+++ b/include/net/inet_frag.h
@@ -6,6 +6,7 @@
6struct netns_frags { 6struct netns_frags {
7 int nqueues; 7 int nqueues;
8 struct list_head lru_list; 8 struct list_head lru_list;
9 spinlock_t lru_lock;
9 10
10 /* The percpu_counter "mem" need to be cacheline aligned. 11 /* The percpu_counter "mem" need to be cacheline aligned.
11 * mem.count must not share cacheline with other writers 12 * mem.count must not share cacheline with other writers
@@ -116,4 +117,25 @@ static inline int sum_frag_mem_limit(struct netns_frags *nf)
116 return percpu_counter_sum_positive(&nf->mem); 117 return percpu_counter_sum_positive(&nf->mem);
117} 118}
118 119
120static inline void inet_frag_lru_move(struct inet_frag_queue *q)
121{
122 spin_lock(&q->net->lru_lock);
123 list_move_tail(&q->lru_list, &q->net->lru_list);
124 spin_unlock(&q->net->lru_lock);
125}
126
127static inline void inet_frag_lru_del(struct inet_frag_queue *q)
128{
129 spin_lock(&q->net->lru_lock);
130 list_del(&q->lru_list);
131 spin_unlock(&q->net->lru_lock);
132}
133
134static inline void inet_frag_lru_add(struct netns_frags *nf,
135 struct inet_frag_queue *q)
136{
137 spin_lock(&nf->lru_lock);
138 list_add_tail(&q->lru_list, &nf->lru_list);
139 spin_unlock(&nf->lru_lock);
140}
119#endif 141#endif
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index b82520565098..2e453bde6992 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -75,6 +75,7 @@ void inet_frags_init_net(struct netns_frags *nf)
75 nf->nqueues = 0; 75 nf->nqueues = 0;
76 init_frag_mem_limit(nf); 76 init_frag_mem_limit(nf);
77 INIT_LIST_HEAD(&nf->lru_list); 77 INIT_LIST_HEAD(&nf->lru_list);
78 spin_lock_init(&nf->lru_lock);
78} 79}
79EXPORT_SYMBOL(inet_frags_init_net); 80EXPORT_SYMBOL(inet_frags_init_net);
80 81
@@ -100,9 +101,9 @@ static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f)
100{ 101{
101 write_lock(&f->lock); 102 write_lock(&f->lock);
102 hlist_del(&fq->list); 103 hlist_del(&fq->list);
103 list_del(&fq->lru_list);
104 fq->net->nqueues--; 104 fq->net->nqueues--;
105 write_unlock(&f->lock); 105 write_unlock(&f->lock);
106 inet_frag_lru_del(fq);
106} 107}
107 108
108void inet_frag_kill(struct inet_frag_queue *fq, struct inet_frags *f) 109void inet_frag_kill(struct inet_frag_queue *fq, struct inet_frags *f)
@@ -170,16 +171,17 @@ int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f, bool force)
170 171
171 work = frag_mem_limit(nf) - nf->low_thresh; 172 work = frag_mem_limit(nf) - nf->low_thresh;
172 while (work > 0) { 173 while (work > 0) {
173 read_lock(&f->lock); 174 spin_lock(&nf->lru_lock);
175
174 if (list_empty(&nf->lru_list)) { 176 if (list_empty(&nf->lru_list)) {
175 read_unlock(&f->lock); 177 spin_unlock(&nf->lru_lock);
176 break; 178 break;
177 } 179 }
178 180
179 q = list_first_entry(&nf->lru_list, 181 q = list_first_entry(&nf->lru_list,
180 struct inet_frag_queue, lru_list); 182 struct inet_frag_queue, lru_list);
181 atomic_inc(&q->refcnt); 183 atomic_inc(&q->refcnt);
182 read_unlock(&f->lock); 184 spin_unlock(&nf->lru_lock);
183 185
184 spin_lock(&q->lock); 186 spin_lock(&q->lock);
185 if (!(q->last_in & INET_FRAG_COMPLETE)) 187 if (!(q->last_in & INET_FRAG_COMPLETE))
@@ -233,9 +235,9 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
233 235
234 atomic_inc(&qp->refcnt); 236 atomic_inc(&qp->refcnt);
235 hlist_add_head(&qp->list, &f->hash[hash]); 237 hlist_add_head(&qp->list, &f->hash[hash]);
236 list_add_tail(&qp->lru_list, &nf->lru_list);
237 nf->nqueues++; 238 nf->nqueues++;
238 write_unlock(&f->lock); 239 write_unlock(&f->lock);
240 inet_frag_lru_add(nf, qp);
239 return qp; 241 return qp;
240} 242}
241 243
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 927fe58caf46..1211613c6c34 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -529,9 +529,7 @@ found:
529 qp->q.meat == qp->q.len) 529 qp->q.meat == qp->q.len)
530 return ip_frag_reasm(qp, prev, dev); 530 return ip_frag_reasm(qp, prev, dev);
531 531
532 write_lock(&ip4_frags.lock); 532 inet_frag_lru_move(&qp->q);
533 list_move_tail(&qp->q.lru_list, &qp->q.net->lru_list);
534 write_unlock(&ip4_frags.lock);
535 return -EINPROGRESS; 533 return -EINPROGRESS;
536 534
537err: 535err:
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 07ef2949c946..c674f158efa8 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -328,9 +328,8 @@ found:
328 fq->nhoffset = nhoff; 328 fq->nhoffset = nhoff;
329 fq->q.last_in |= INET_FRAG_FIRST_IN; 329 fq->q.last_in |= INET_FRAG_FIRST_IN;
330 } 330 }
331 write_lock(&nf_frags.lock); 331
332 list_move_tail(&fq->q.lru_list, &fq->q.net->lru_list); 332 inet_frag_lru_move(&fq->q);
333 write_unlock(&nf_frags.lock);
334 return 0; 333 return 0;
335 334
336discard_fq: 335discard_fq:
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index 18cb8defcdb2..bab2c270f292 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -341,9 +341,7 @@ found:
341 fq->q.meat == fq->q.len) 341 fq->q.meat == fq->q.len)
342 return ip6_frag_reasm(fq, prev, dev); 342 return ip6_frag_reasm(fq, prev, dev);
343 343
344 write_lock(&ip6_frags.lock); 344 inet_frag_lru_move(&fq->q);
345 list_move_tail(&fq->q.lru_list, &fq->q.net->lru_list);
346 write_unlock(&ip6_frags.lock);
347 return -1; 345 return -1;
348 346
349discard_fq: 347discard_fq: