aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/garbage.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-27 17:05:19 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-27 17:05:19 -0400
commit2decb2682f80759f631c8332f9a2a34a02150a03 (patch)
tree6c30015e4118ff6a56c67043f2ba842ed4a6e011 /net/unix/garbage.c
parentb787f68c36d49bb1d9236f403813641efa74a031 (diff)
parent22a8f237c0551bae95ffcd2a7ff17d6f5fcce7e7 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Pull networking fixes from David Miller: 1) mlx4 doesn't check fully for supported valid RSS hash function, fix from Amir Vadai 2) Off by one in ibmveth_change_mtu(), from David Gibson 3) Prevent altera chip from reporting false error interrupts in some circumstances, from Chee Nouk Phoon 4) Get rid of that stupid endless loop trying to allocate a FIN packet in TCP, and in the process kill deadlocks. From Eric Dumazet 5) Fix get_rps_cpus() crash due to wrong invalid-cpu value, also from Eric Dumazet 6) Fix two bugs in async rhashtable resizing, from Thomas Graf 7) Fix topology server listener socket namespace bug in TIPC, from Ying Xue 8) Add some missing HAS_DMA kconfig dependencies, from Geert Uytterhoeven 9) bgmac driver intends to force re-polling but does so by returning the wrong value from it's ->poll() handler. Fix from Rafał Miłecki 10) When the creater of an rhashtable configures a max size for it, don't bark in the logs and drop insertions when that is exceeded. Fix from Johannes Berg 11) Recover from out of order packets in ppp mppe properly, from Sylvain Rochet * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: (41 commits) bnx2x: really disable TPA if 'disable_tpa' option is set net:treewide: Fix typo in drivers/net net/mlx4_en: Prevent setting invalid RSS hash function mdio-mux-gpio: use new gpiod_get_array and gpiod_put_array functions netfilter; Add some missing default cases to switch statements in nft_reject. ppp: mppe: discard late packet in stateless mode ppp: mppe: sanity error path rework net/bonding: Make DRV macros private net: rfs: fix crash in get_rps_cpus() altera tse: add support for fixed-links. pxa168: fix double deallocation of managed resources net: fix crash in build_skb() net: eth: altera: Resolve false errors from MSGDMA to TSE ehea: Fix memory hook reference counting crashes net/tg3: Release IRQs on permanent error net: mdio-gpio: support access that may sleep inet: fix possible panic in reqsk_queue_unlink() rhashtable: don't attempt to grow when at max_size bgmac: fix requests for extra polling calls from NAPI tcp: avoid looping in tcp_send_fin() ...
Diffstat (limited to 'net/unix/garbage.c')
-rw-r--r--net/unix/garbage.c70
1 files changed, 28 insertions, 42 deletions
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 99f7012b23b9..a73a226f2d33 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -95,39 +95,36 @@ static DECLARE_WAIT_QUEUE_HEAD(unix_gc_wait);
95 95
96unsigned int unix_tot_inflight; 96unsigned int unix_tot_inflight;
97 97
98
99struct sock *unix_get_socket(struct file *filp) 98struct sock *unix_get_socket(struct file *filp)
100{ 99{
101 struct sock *u_sock = NULL; 100 struct sock *u_sock = NULL;
102 struct inode *inode = file_inode(filp); 101 struct inode *inode = file_inode(filp);
103 102
104 /* 103 /* Socket ? */
105 * Socket ?
106 */
107 if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) { 104 if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) {
108 struct socket *sock = SOCKET_I(inode); 105 struct socket *sock = SOCKET_I(inode);
109 struct sock *s = sock->sk; 106 struct sock *s = sock->sk;
110 107
111 /* 108 /* PF_UNIX ? */
112 * PF_UNIX ?
113 */
114 if (s && sock->ops && sock->ops->family == PF_UNIX) 109 if (s && sock->ops && sock->ops->family == PF_UNIX)
115 u_sock = s; 110 u_sock = s;
116 } 111 }
117 return u_sock; 112 return u_sock;
118} 113}
119 114
120/* 115/* Keep the number of times in flight count for the file
121 * Keep the number of times in flight count for the file 116 * descriptor if it is for an AF_UNIX socket.
122 * descriptor if it is for an AF_UNIX socket.
123 */ 117 */
124 118
125void unix_inflight(struct file *fp) 119void unix_inflight(struct file *fp)
126{ 120{
127 struct sock *s = unix_get_socket(fp); 121 struct sock *s = unix_get_socket(fp);
122
128 if (s) { 123 if (s) {
129 struct unix_sock *u = unix_sk(s); 124 struct unix_sock *u = unix_sk(s);
125
130 spin_lock(&unix_gc_lock); 126 spin_lock(&unix_gc_lock);
127
131 if (atomic_long_inc_return(&u->inflight) == 1) { 128 if (atomic_long_inc_return(&u->inflight) == 1) {
132 BUG_ON(!list_empty(&u->link)); 129 BUG_ON(!list_empty(&u->link));
133 list_add_tail(&u->link, &gc_inflight_list); 130 list_add_tail(&u->link, &gc_inflight_list);
@@ -142,10 +139,13 @@ void unix_inflight(struct file *fp)
142void unix_notinflight(struct file *fp) 139void unix_notinflight(struct file *fp)
143{ 140{
144 struct sock *s = unix_get_socket(fp); 141 struct sock *s = unix_get_socket(fp);
142
145 if (s) { 143 if (s) {
146 struct unix_sock *u = unix_sk(s); 144 struct unix_sock *u = unix_sk(s);
145
147 spin_lock(&unix_gc_lock); 146 spin_lock(&unix_gc_lock);
148 BUG_ON(list_empty(&u->link)); 147 BUG_ON(list_empty(&u->link));
148
149 if (atomic_long_dec_and_test(&u->inflight)) 149 if (atomic_long_dec_and_test(&u->inflight))
150 list_del_init(&u->link); 150 list_del_init(&u->link);
151 unix_tot_inflight--; 151 unix_tot_inflight--;
@@ -161,32 +161,27 @@ static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *),
161 161
162 spin_lock(&x->sk_receive_queue.lock); 162 spin_lock(&x->sk_receive_queue.lock);
163 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { 163 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) {
164 /* 164 /* Do we have file descriptors ? */
165 * Do we have file descriptors ?
166 */
167 if (UNIXCB(skb).fp) { 165 if (UNIXCB(skb).fp) {
168 bool hit = false; 166 bool hit = false;
169 /* 167 /* Process the descriptors of this socket */
170 * Process the descriptors of this socket
171 */
172 int nfd = UNIXCB(skb).fp->count; 168 int nfd = UNIXCB(skb).fp->count;
173 struct file **fp = UNIXCB(skb).fp->fp; 169 struct file **fp = UNIXCB(skb).fp->fp;
170
174 while (nfd--) { 171 while (nfd--) {
175 /* 172 /* Get the socket the fd matches if it indeed does so */
176 * Get the socket the fd matches
177 * if it indeed does so
178 */
179 struct sock *sk = unix_get_socket(*fp++); 173 struct sock *sk = unix_get_socket(*fp++);
174
180 if (sk) { 175 if (sk) {
181 struct unix_sock *u = unix_sk(sk); 176 struct unix_sock *u = unix_sk(sk);
182 177
183 /* 178 /* Ignore non-candidates, they could
184 * Ignore non-candidates, they could
185 * have been added to the queues after 179 * have been added to the queues after
186 * starting the garbage collection 180 * starting the garbage collection
187 */ 181 */
188 if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) { 182 if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) {
189 hit = true; 183 hit = true;
184
190 func(u); 185 func(u);
191 } 186 }
192 } 187 }
@@ -203,24 +198,22 @@ static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *),
203static void scan_children(struct sock *x, void (*func)(struct unix_sock *), 198static void scan_children(struct sock *x, void (*func)(struct unix_sock *),
204 struct sk_buff_head *hitlist) 199 struct sk_buff_head *hitlist)
205{ 200{
206 if (x->sk_state != TCP_LISTEN) 201 if (x->sk_state != TCP_LISTEN) {
207 scan_inflight(x, func, hitlist); 202 scan_inflight(x, func, hitlist);
208 else { 203 } else {
209 struct sk_buff *skb; 204 struct sk_buff *skb;
210 struct sk_buff *next; 205 struct sk_buff *next;
211 struct unix_sock *u; 206 struct unix_sock *u;
212 LIST_HEAD(embryos); 207 LIST_HEAD(embryos);
213 208
214 /* 209 /* For a listening socket collect the queued embryos
215 * For a listening socket collect the queued embryos
216 * and perform a scan on them as well. 210 * and perform a scan on them as well.
217 */ 211 */
218 spin_lock(&x->sk_receive_queue.lock); 212 spin_lock(&x->sk_receive_queue.lock);
219 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { 213 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) {
220 u = unix_sk(skb->sk); 214 u = unix_sk(skb->sk);
221 215
222 /* 216 /* An embryo cannot be in-flight, so it's safe
223 * An embryo cannot be in-flight, so it's safe
224 * to use the list link. 217 * to use the list link.
225 */ 218 */
226 BUG_ON(!list_empty(&u->link)); 219 BUG_ON(!list_empty(&u->link));
@@ -249,8 +242,7 @@ static void inc_inflight(struct unix_sock *usk)
249static void inc_inflight_move_tail(struct unix_sock *u) 242static void inc_inflight_move_tail(struct unix_sock *u)
250{ 243{
251 atomic_long_inc(&u->inflight); 244 atomic_long_inc(&u->inflight);
252 /* 245 /* If this still might be part of a cycle, move it to the end
253 * If this still might be part of a cycle, move it to the end
254 * of the list, so that it's checked even if it was already 246 * of the list, so that it's checked even if it was already
255 * passed over 247 * passed over
256 */ 248 */
@@ -263,8 +255,7 @@ static bool gc_in_progress;
263 255
264void wait_for_unix_gc(void) 256void wait_for_unix_gc(void)
265{ 257{
266 /* 258 /* If number of inflight sockets is insane,
267 * If number of inflight sockets is insane,
268 * force a garbage collect right now. 259 * force a garbage collect right now.
269 */ 260 */
270 if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress) 261 if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress)
@@ -288,8 +279,7 @@ void unix_gc(void)
288 goto out; 279 goto out;
289 280
290 gc_in_progress = true; 281 gc_in_progress = true;
291 /* 282 /* First, select candidates for garbage collection. Only
292 * First, select candidates for garbage collection. Only
293 * in-flight sockets are considered, and from those only ones 283 * in-flight sockets are considered, and from those only ones
294 * which don't have any external reference. 284 * which don't have any external reference.
295 * 285 *
@@ -320,15 +310,13 @@ void unix_gc(void)
320 } 310 }
321 } 311 }
322 312
323 /* 313 /* Now remove all internal in-flight reference to children of
324 * Now remove all internal in-flight reference to children of
325 * the candidates. 314 * the candidates.
326 */ 315 */
327 list_for_each_entry(u, &gc_candidates, link) 316 list_for_each_entry(u, &gc_candidates, link)
328 scan_children(&u->sk, dec_inflight, NULL); 317 scan_children(&u->sk, dec_inflight, NULL);
329 318
330 /* 319 /* Restore the references for children of all candidates,
331 * Restore the references for children of all candidates,
332 * which have remaining references. Do this recursively, so 320 * which have remaining references. Do this recursively, so
333 * only those remain, which form cyclic references. 321 * only those remain, which form cyclic references.
334 * 322 *
@@ -350,8 +338,7 @@ void unix_gc(void)
350 } 338 }
351 list_del(&cursor); 339 list_del(&cursor);
352 340
353 /* 341 /* not_cycle_list contains those sockets which do not make up a
354 * not_cycle_list contains those sockets which do not make up a
355 * cycle. Restore these to the inflight list. 342 * cycle. Restore these to the inflight list.
356 */ 343 */
357 while (!list_empty(&not_cycle_list)) { 344 while (!list_empty(&not_cycle_list)) {
@@ -360,8 +347,7 @@ void unix_gc(void)
360 list_move_tail(&u->link, &gc_inflight_list); 347 list_move_tail(&u->link, &gc_inflight_list);
361 } 348 }
362 349
363 /* 350 /* Now gc_candidates contains only garbage. Restore original
364 * Now gc_candidates contains only garbage. Restore original
365 * inflight counters for these as well, and remove the skbuffs 351 * inflight counters for these as well, and remove the skbuffs
366 * which are creating the cycle(s). 352 * which are creating the cycle(s).
367 */ 353 */