11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * NET3: Garbage Collector For AF_UNIX sockets 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Garbage Collector: 51da177e4SLinus Torvalds * Copyright (C) Barak A. Pearlmutter. 61da177e4SLinus Torvalds * Released under the GPL version 2 or later. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Chopped about by Alan Cox 22/3/96 to make it fit the AF_UNIX socket problem. 91da177e4SLinus Torvalds * If it doesn't work blame me, it worked when Barak sent it. 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * Assumptions: 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * - object w/ a bit 141da177e4SLinus Torvalds * - free list 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * Current optimizations: 171da177e4SLinus Torvalds * 181da177e4SLinus Torvalds * - explicit stack instead of recursion 191da177e4SLinus Torvalds * - tail recurse on first born instead of immediate push/pop 201da177e4SLinus Torvalds * - we gather the stuff that should not be killed into tree 211da177e4SLinus Torvalds * and stack is just a path from root to the current pointer. 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * Future optimizations: 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * - don't just push entire root set; process in place 261da177e4SLinus Torvalds * 271da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 281da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 291da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 301da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 311da177e4SLinus Torvalds * 321da177e4SLinus Torvalds * Fixes: 331da177e4SLinus Torvalds * Alan Cox 07 Sept 1997 Vmalloc internal stack as needed. 341da177e4SLinus Torvalds * Cope with changing max_files. 351da177e4SLinus Torvalds * Al Viro 11 Oct 1998 361da177e4SLinus Torvalds * Graph may have cycles. That is, we can send the descriptor 371da177e4SLinus Torvalds * of foo to bar and vice versa. Current code chokes on that. 381da177e4SLinus Torvalds * Fix: move SCM_RIGHTS ones into the separate list and then 391da177e4SLinus Torvalds * skb_free() them all instead of doing explicit fput's. 401da177e4SLinus Torvalds * Another problem: since fput() may block somebody may 411da177e4SLinus Torvalds * create a new unix_socket when we are in the middle of sweep 421da177e4SLinus Torvalds * phase. Fix: revert the logic wrt MARKED. Mark everything 431da177e4SLinus Torvalds * upon the beginning and unmark non-junk ones. 441da177e4SLinus Torvalds * 451da177e4SLinus Torvalds * [12 Oct 1998] AAARGH! New code purges all SCM_RIGHTS 461da177e4SLinus Torvalds * sent to connect()'ed but still not accept()'ed sockets. 471da177e4SLinus Torvalds * Fixed. Old code had slightly different problem here: 481da177e4SLinus Torvalds * extra fput() in situation when we passed the descriptor via 491da177e4SLinus Torvalds * such socket and closed it (descriptor). That would happen on 501da177e4SLinus Torvalds * each unix_gc() until the accept(). Since the struct file in 511da177e4SLinus Torvalds * question would go to the free list and might be reused... 521da177e4SLinus Torvalds * That might be the reason of random oopses on filp_close() 531da177e4SLinus Torvalds * in unrelated processes. 541da177e4SLinus Torvalds * 551da177e4SLinus Torvalds * AV 28 Feb 1999 561da177e4SLinus Torvalds * Kill the explicit allocation of stack. Now we keep the tree 571da177e4SLinus Torvalds * with root in dummy + pointer (gc_current) to one of the nodes. 581da177e4SLinus Torvalds * Stack is represented as path from gc_current to dummy. Unmark 591da177e4SLinus Torvalds * now means "add to tree". Push == "make it a son of gc_current". 601da177e4SLinus Torvalds * Pop == "move gc_current to parent". We keep only pointers to 611da177e4SLinus Torvalds * parents (->gc_tree). 621da177e4SLinus Torvalds * AV 1 Mar 1999 631da177e4SLinus Torvalds * Damn. Added missing check for ->dead in listen queues scanning. 641da177e4SLinus Torvalds * 651fd05ba5SMiklos Szeredi * Miklos Szeredi 25 Jun 2007 661fd05ba5SMiklos Szeredi * Reimplement with a cycle collecting algorithm. This should 671fd05ba5SMiklos Szeredi * solve several problems with the previous code, like being racy 681fd05ba5SMiklos Szeredi * wrt receive and holding up unrelated socket operations. 691da177e4SLinus Torvalds */ 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds #include <linux/kernel.h> 721da177e4SLinus Torvalds #include <linux/string.h> 731da177e4SLinus Torvalds #include <linux/socket.h> 741da177e4SLinus Torvalds #include <linux/un.h> 751da177e4SLinus Torvalds #include <linux/net.h> 761da177e4SLinus Torvalds #include <linux/fs.h> 771da177e4SLinus Torvalds #include <linux/skbuff.h> 781da177e4SLinus Torvalds #include <linux/netdevice.h> 791da177e4SLinus Torvalds #include <linux/file.h> 801da177e4SLinus Torvalds #include <linux/proc_fs.h> 814a3e2f71SArjan van de Ven #include <linux/mutex.h> 825f23b734Sdann frazier #include <linux/wait.h> 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds #include <net/sock.h> 851da177e4SLinus Torvalds #include <net/af_unix.h> 861da177e4SLinus Torvalds #include <net/scm.h> 87c752f073SArnaldo Carvalho de Melo #include <net/tcp_states.h> 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds /* Internal data structures and random procedures: */ 901da177e4SLinus Torvalds 911fd05ba5SMiklos Szeredi static LIST_HEAD(gc_inflight_list); 921fd05ba5SMiklos Szeredi static LIST_HEAD(gc_candidates); 931fd05ba5SMiklos Szeredi static DEFINE_SPINLOCK(unix_gc_lock); 945f23b734Sdann frazier static DECLARE_WAIT_QUEUE_HEAD(unix_gc_wait); 951da177e4SLinus Torvalds 969305cfa4SPavel Emelyanov unsigned int unix_tot_inflight; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds 9925888e30SEric Dumazet struct sock *unix_get_socket(struct file *filp) 1001da177e4SLinus Torvalds { 1011da177e4SLinus Torvalds struct sock *u_sock = NULL; 102496ad9aaSAl Viro struct inode *inode = file_inode(filp); 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds /* 1051da177e4SLinus Torvalds * Socket ? 1061da177e4SLinus Torvalds */ 107326be7b4SAl Viro if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) { 1081da177e4SLinus Torvalds struct socket *sock = SOCKET_I(inode); 1091da177e4SLinus Torvalds struct sock *s = sock->sk; 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* 1121da177e4SLinus Torvalds * PF_UNIX ? 1131da177e4SLinus Torvalds */ 1141da177e4SLinus Torvalds if (s && sock->ops && sock->ops->family == PF_UNIX) 1151da177e4SLinus Torvalds u_sock = s; 1161da177e4SLinus Torvalds } 1171da177e4SLinus Torvalds return u_sock; 1181da177e4SLinus Torvalds } 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds /* 1211da177e4SLinus Torvalds * Keep the number of times in flight count for the file 1221da177e4SLinus Torvalds * descriptor if it is for an AF_UNIX socket. 1231da177e4SLinus Torvalds */ 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds void unix_inflight(struct file *fp) 1261da177e4SLinus Torvalds { 1271da177e4SLinus Torvalds struct sock *s = unix_get_socket(fp); 1281da177e4SLinus Torvalds if (s) { 1291fd05ba5SMiklos Szeredi struct unix_sock *u = unix_sk(s); 1301fd05ba5SMiklos Szeredi spin_lock(&unix_gc_lock); 131516e0cc5SAl Viro if (atomic_long_inc_return(&u->inflight) == 1) { 1321fd05ba5SMiklos Szeredi BUG_ON(!list_empty(&u->link)); 1331fd05ba5SMiklos Szeredi list_add_tail(&u->link, &gc_inflight_list); 1341fd05ba5SMiklos Szeredi } else { 1351fd05ba5SMiklos Szeredi BUG_ON(list_empty(&u->link)); 1361fd05ba5SMiklos Szeredi } 1379305cfa4SPavel Emelyanov unix_tot_inflight++; 1381fd05ba5SMiklos Szeredi spin_unlock(&unix_gc_lock); 1391da177e4SLinus Torvalds } 1401da177e4SLinus Torvalds } 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds void unix_notinflight(struct file *fp) 1431da177e4SLinus Torvalds { 1441da177e4SLinus Torvalds struct sock *s = unix_get_socket(fp); 1451da177e4SLinus Torvalds if (s) { 1461fd05ba5SMiklos Szeredi struct unix_sock *u = unix_sk(s); 1471fd05ba5SMiklos Szeredi spin_lock(&unix_gc_lock); 1481fd05ba5SMiklos Szeredi BUG_ON(list_empty(&u->link)); 149516e0cc5SAl Viro if (atomic_long_dec_and_test(&u->inflight)) 1501fd05ba5SMiklos Szeredi list_del_init(&u->link); 1519305cfa4SPavel Emelyanov unix_tot_inflight--; 1521fd05ba5SMiklos Szeredi spin_unlock(&unix_gc_lock); 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds } 1551da177e4SLinus Torvalds 1565c80f1aeSPavel Emelyanov static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *), 1571fd05ba5SMiklos Szeredi struct sk_buff_head *hitlist) 1581da177e4SLinus Torvalds { 1591da177e4SLinus Torvalds struct sk_buff *skb; 1601fd05ba5SMiklos Szeredi struct sk_buff *next; 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds spin_lock(&x->sk_receive_queue.lock); 163a2f3be17SIlpo Järvinen skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { 1641da177e4SLinus Torvalds /* 1651da177e4SLinus Torvalds * Do we have file descriptors ? 1661da177e4SLinus Torvalds */ 1671fd05ba5SMiklos Szeredi if (UNIXCB(skb).fp) { 1681fd05ba5SMiklos Szeredi bool hit = false; 1691da177e4SLinus Torvalds /* 1701da177e4SLinus Torvalds * Process the descriptors of this socket 1711da177e4SLinus Torvalds */ 1721da177e4SLinus Torvalds int nfd = UNIXCB(skb).fp->count; 1731da177e4SLinus Torvalds struct file **fp = UNIXCB(skb).fp->fp; 1741fd05ba5SMiklos Szeredi while (nfd--) { 1751da177e4SLinus Torvalds /* 1761fd05ba5SMiklos Szeredi * Get the socket the fd matches 1771fd05ba5SMiklos Szeredi * if it indeed does so 1781da177e4SLinus Torvalds */ 1791fd05ba5SMiklos Szeredi struct sock *sk = unix_get_socket(*fp++); 1801fd05ba5SMiklos Szeredi if (sk) { 1816209344fSMiklos Szeredi struct unix_sock *u = unix_sk(sk); 1826209344fSMiklos Szeredi 1836209344fSMiklos Szeredi /* 1846209344fSMiklos Szeredi * Ignore non-candidates, they could 1856209344fSMiklos Szeredi * have been added to the queues after 1866209344fSMiklos Szeredi * starting the garbage collection 1876209344fSMiklos Szeredi */ 18860bc851aSEric Dumazet if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) { 1891fd05ba5SMiklos Szeredi hit = true; 1906209344fSMiklos Szeredi func(u); 1916209344fSMiklos Szeredi } 1921da177e4SLinus Torvalds } 1931da177e4SLinus Torvalds } 1941fd05ba5SMiklos Szeredi if (hit && hitlist != NULL) { 1951fd05ba5SMiklos Szeredi __skb_unlink(skb, &x->sk_receive_queue); 1961fd05ba5SMiklos Szeredi __skb_queue_tail(hitlist, skb); 1971da177e4SLinus Torvalds } 1981fd05ba5SMiklos Szeredi } 1991da177e4SLinus Torvalds } 2001da177e4SLinus Torvalds spin_unlock(&x->sk_receive_queue.lock); 2011da177e4SLinus Torvalds } 2021da177e4SLinus Torvalds 2035c80f1aeSPavel Emelyanov static void scan_children(struct sock *x, void (*func)(struct unix_sock *), 2041fd05ba5SMiklos Szeredi struct sk_buff_head *hitlist) 2051da177e4SLinus Torvalds { 2061fd05ba5SMiklos Szeredi if (x->sk_state != TCP_LISTEN) 2071fd05ba5SMiklos Szeredi scan_inflight(x, func, hitlist); 2081fd05ba5SMiklos Szeredi else { 2091fd05ba5SMiklos Szeredi struct sk_buff *skb; 2101fd05ba5SMiklos Szeredi struct sk_buff *next; 2111fd05ba5SMiklos Szeredi struct unix_sock *u; 2121fd05ba5SMiklos Szeredi LIST_HEAD(embryos); 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds /* 2151fd05ba5SMiklos Szeredi * For a listening socket collect the queued embryos 2161fd05ba5SMiklos Szeredi * and perform a scan on them as well. 2171da177e4SLinus Torvalds */ 2181fd05ba5SMiklos Szeredi spin_lock(&x->sk_receive_queue.lock); 219a2f3be17SIlpo Järvinen skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { 2201fd05ba5SMiklos Szeredi u = unix_sk(skb->sk); 2211da177e4SLinus Torvalds 2221fd05ba5SMiklos Szeredi /* 2231fd05ba5SMiklos Szeredi * An embryo cannot be in-flight, so it's safe 2241fd05ba5SMiklos Szeredi * to use the list link. 2251fd05ba5SMiklos Szeredi */ 2261fd05ba5SMiklos Szeredi BUG_ON(!list_empty(&u->link)); 2271fd05ba5SMiklos Szeredi list_add_tail(&u->link, &embryos); 2281fd05ba5SMiklos Szeredi } 2291fd05ba5SMiklos Szeredi spin_unlock(&x->sk_receive_queue.lock); 2301fd05ba5SMiklos Szeredi 2311fd05ba5SMiklos Szeredi while (!list_empty(&embryos)) { 2321fd05ba5SMiklos Szeredi u = list_entry(embryos.next, struct unix_sock, link); 2331fd05ba5SMiklos Szeredi scan_inflight(&u->sk, func, hitlist); 2341fd05ba5SMiklos Szeredi list_del_init(&u->link); 2351fd05ba5SMiklos Szeredi } 2361fd05ba5SMiklos Szeredi } 2371fd05ba5SMiklos Szeredi } 2381fd05ba5SMiklos Szeredi 2395c80f1aeSPavel Emelyanov static void dec_inflight(struct unix_sock *usk) 2401fd05ba5SMiklos Szeredi { 241516e0cc5SAl Viro atomic_long_dec(&usk->inflight); 2421fd05ba5SMiklos Szeredi } 2431fd05ba5SMiklos Szeredi 2445c80f1aeSPavel Emelyanov static void inc_inflight(struct unix_sock *usk) 2451fd05ba5SMiklos Szeredi { 246516e0cc5SAl Viro atomic_long_inc(&usk->inflight); 2471fd05ba5SMiklos Szeredi } 2481fd05ba5SMiklos Szeredi 2495c80f1aeSPavel Emelyanov static void inc_inflight_move_tail(struct unix_sock *u) 2501fd05ba5SMiklos Szeredi { 251516e0cc5SAl Viro atomic_long_inc(&u->inflight); 2521fd05ba5SMiklos Szeredi /* 2536209344fSMiklos Szeredi * If this still might be part of a cycle, move it to the end 2546209344fSMiklos Szeredi * of the list, so that it's checked even if it was already 2556209344fSMiklos Szeredi * passed over 2561fd05ba5SMiklos Szeredi */ 25760bc851aSEric Dumazet if (test_bit(UNIX_GC_MAYBE_CYCLE, &u->gc_flags)) 2581fd05ba5SMiklos Szeredi list_move_tail(&u->link, &gc_candidates); 2591fd05ba5SMiklos Szeredi } 2601fd05ba5SMiklos Szeredi 261*505e907dSFabian Frederick static bool gc_in_progress; 2629915672dSEric Dumazet #define UNIX_INFLIGHT_TRIGGER_GC 16000 2631fd05ba5SMiklos Szeredi 2645f23b734Sdann frazier void wait_for_unix_gc(void) 2655f23b734Sdann frazier { 2669915672dSEric Dumazet /* 2679915672dSEric Dumazet * If number of inflight sockets is insane, 2689915672dSEric Dumazet * force a garbage collect right now. 2699915672dSEric Dumazet */ 2709915672dSEric Dumazet if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress) 2719915672dSEric Dumazet unix_gc(); 2725f23b734Sdann frazier wait_event(unix_gc_wait, gc_in_progress == false); 2735f23b734Sdann frazier } 2745f23b734Sdann frazier 2755f23b734Sdann frazier /* The external entry point: unix_gc() */ 2765f23b734Sdann frazier void unix_gc(void) 2775f23b734Sdann frazier { 2781fd05ba5SMiklos Szeredi struct unix_sock *u; 2791fd05ba5SMiklos Szeredi struct unix_sock *next; 2801fd05ba5SMiklos Szeredi struct sk_buff_head hitlist; 2811fd05ba5SMiklos Szeredi struct list_head cursor; 2826209344fSMiklos Szeredi LIST_HEAD(not_cycle_list); 2831fd05ba5SMiklos Szeredi 2841fd05ba5SMiklos Szeredi spin_lock(&unix_gc_lock); 2851fd05ba5SMiklos Szeredi 2861fd05ba5SMiklos Szeredi /* Avoid a recursive GC. */ 2871fd05ba5SMiklos Szeredi if (gc_in_progress) 2881fd05ba5SMiklos Szeredi goto out; 2891fd05ba5SMiklos Szeredi 2901fd05ba5SMiklos Szeredi gc_in_progress = true; 2911fd05ba5SMiklos Szeredi /* 2921fd05ba5SMiklos Szeredi * First, select candidates for garbage collection. Only 2931fd05ba5SMiklos Szeredi * in-flight sockets are considered, and from those only ones 2941fd05ba5SMiklos Szeredi * which don't have any external reference. 2951fd05ba5SMiklos Szeredi * 2961fd05ba5SMiklos Szeredi * Holding unix_gc_lock will protect these candidates from 2971fd05ba5SMiklos Szeredi * being detached, and hence from gaining an external 2986209344fSMiklos Szeredi * reference. Since there are no possible receivers, all 2996209344fSMiklos Szeredi * buffers currently on the candidates' queues stay there 3006209344fSMiklos Szeredi * during the garbage collection. 3016209344fSMiklos Szeredi * 3026209344fSMiklos Szeredi * We also know that no new candidate can be added onto the 3036209344fSMiklos Szeredi * receive queues. Other, non candidate sockets _can_ be 3046209344fSMiklos Szeredi * added to queue, so we must make sure only to touch 3056209344fSMiklos Szeredi * candidates. 3061fd05ba5SMiklos Szeredi */ 3071fd05ba5SMiklos Szeredi list_for_each_entry_safe(u, next, &gc_inflight_list, link) { 308516e0cc5SAl Viro long total_refs; 309516e0cc5SAl Viro long inflight_refs; 3101fd05ba5SMiklos Szeredi 3111fd05ba5SMiklos Szeredi total_refs = file_count(u->sk.sk_socket->file); 312516e0cc5SAl Viro inflight_refs = atomic_long_read(&u->inflight); 3131fd05ba5SMiklos Szeredi 3141fd05ba5SMiklos Szeredi BUG_ON(inflight_refs < 1); 3151fd05ba5SMiklos Szeredi BUG_ON(total_refs < inflight_refs); 3161fd05ba5SMiklos Szeredi if (total_refs == inflight_refs) { 3171fd05ba5SMiklos Szeredi list_move_tail(&u->link, &gc_candidates); 31860bc851aSEric Dumazet __set_bit(UNIX_GC_CANDIDATE, &u->gc_flags); 31960bc851aSEric Dumazet __set_bit(UNIX_GC_MAYBE_CYCLE, &u->gc_flags); 3201fd05ba5SMiklos Szeredi } 3211fd05ba5SMiklos Szeredi } 3221fd05ba5SMiklos Szeredi 3231fd05ba5SMiklos Szeredi /* 3241fd05ba5SMiklos Szeredi * Now remove all internal in-flight reference to children of 3251fd05ba5SMiklos Szeredi * the candidates. 3261fd05ba5SMiklos Szeredi */ 3271fd05ba5SMiklos Szeredi list_for_each_entry(u, &gc_candidates, link) 3281fd05ba5SMiklos Szeredi scan_children(&u->sk, dec_inflight, NULL); 3291fd05ba5SMiklos Szeredi 3301fd05ba5SMiklos Szeredi /* 3311fd05ba5SMiklos Szeredi * Restore the references for children of all candidates, 3321fd05ba5SMiklos Szeredi * which have remaining references. Do this recursively, so 3331fd05ba5SMiklos Szeredi * only those remain, which form cyclic references. 3341fd05ba5SMiklos Szeredi * 3351fd05ba5SMiklos Szeredi * Use a "cursor" link, to make the list traversal safe, even 3361fd05ba5SMiklos Szeredi * though elements might be moved about. 3371fd05ba5SMiklos Szeredi */ 3381fd05ba5SMiklos Szeredi list_add(&cursor, &gc_candidates); 3391fd05ba5SMiklos Szeredi while (cursor.next != &gc_candidates) { 3401fd05ba5SMiklos Szeredi u = list_entry(cursor.next, struct unix_sock, link); 3411fd05ba5SMiklos Szeredi 3421fd05ba5SMiklos Szeredi /* Move cursor to after the current position. */ 3431fd05ba5SMiklos Szeredi list_move(&cursor, &u->link); 3441fd05ba5SMiklos Szeredi 345516e0cc5SAl Viro if (atomic_long_read(&u->inflight) > 0) { 3466209344fSMiklos Szeredi list_move_tail(&u->link, ¬_cycle_list); 34760bc851aSEric Dumazet __clear_bit(UNIX_GC_MAYBE_CYCLE, &u->gc_flags); 3481fd05ba5SMiklos Szeredi scan_children(&u->sk, inc_inflight_move_tail, NULL); 3491fd05ba5SMiklos Szeredi } 3501fd05ba5SMiklos Szeredi } 3511fd05ba5SMiklos Szeredi list_del(&cursor); 3521fd05ba5SMiklos Szeredi 3531fd05ba5SMiklos Szeredi /* 3546209344fSMiklos Szeredi * not_cycle_list contains those sockets which do not make up a 3556209344fSMiklos Szeredi * cycle. Restore these to the inflight list. 3566209344fSMiklos Szeredi */ 3576209344fSMiklos Szeredi while (!list_empty(¬_cycle_list)) { 3586209344fSMiklos Szeredi u = list_entry(not_cycle_list.next, struct unix_sock, link); 35960bc851aSEric Dumazet __clear_bit(UNIX_GC_CANDIDATE, &u->gc_flags); 3606209344fSMiklos Szeredi list_move_tail(&u->link, &gc_inflight_list); 3616209344fSMiklos Szeredi } 3626209344fSMiklos Szeredi 3636209344fSMiklos Szeredi /* 3641fd05ba5SMiklos Szeredi * Now gc_candidates contains only garbage. Restore original 3651fd05ba5SMiklos Szeredi * inflight counters for these as well, and remove the skbuffs 3661fd05ba5SMiklos Szeredi * which are creating the cycle(s). 3671fd05ba5SMiklos Szeredi */ 3681fd05ba5SMiklos Szeredi skb_queue_head_init(&hitlist); 3691fd05ba5SMiklos Szeredi list_for_each_entry(u, &gc_candidates, link) 3701fd05ba5SMiklos Szeredi scan_children(&u->sk, inc_inflight, &hitlist); 3711fd05ba5SMiklos Szeredi 3721fd05ba5SMiklos Szeredi spin_unlock(&unix_gc_lock); 3731fd05ba5SMiklos Szeredi 3741fd05ba5SMiklos Szeredi /* Here we are. Hitlist is filled. Die. */ 3751da177e4SLinus Torvalds __skb_queue_purge(&hitlist); 3761fd05ba5SMiklos Szeredi 3771fd05ba5SMiklos Szeredi spin_lock(&unix_gc_lock); 3781fd05ba5SMiklos Szeredi 3791fd05ba5SMiklos Szeredi /* All candidates should have been detached by now. */ 3801fd05ba5SMiklos Szeredi BUG_ON(!list_empty(&gc_candidates)); 3811fd05ba5SMiklos Szeredi gc_in_progress = false; 3825f23b734Sdann frazier wake_up(&unix_gc_wait); 3831fd05ba5SMiklos Szeredi 3841fd05ba5SMiklos Szeredi out: 3851fd05ba5SMiklos Szeredi spin_unlock(&unix_gc_lock); 3861da177e4SLinus Torvalds } 387