@@ -17,13 +17,12 @@ static inline struct unix_sock *unix_get_socket(struct file *filp)
}
#endif
-extern unsigned int unix_tot_inflight;
void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver);
void unix_del_edges(struct scm_fp_list *fpl);
void unix_update_edges(struct unix_sock *receiver);
int unix_prepare_fpl(struct scm_fp_list *fpl);
void unix_destroy_fpl(struct scm_fp_list *fpl);
-void unix_gc(void);
+void unix_schedule_gc(void);
struct unix_vertex {
struct list_head edges;
@@ -677,8 +677,7 @@ static void unix_release_sock(struct sock *sk, int embrion)
* What the above comment does talk about? --ANK(980817)
*/
- if (READ_ONCE(unix_tot_inflight))
- unix_gc(); /* Garbage collect fds */
+ unix_schedule_gc();
}
static void init_peercred(struct sock *sk)
@@ -189,7 +189,7 @@ static void unix_free_vertices(struct scm_fp_list *fpl)
}
static DEFINE_SPINLOCK(unix_gc_lock);
-unsigned int unix_tot_inflight;
+static unsigned int unix_tot_inflight;
void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver)
{
@@ -577,11 +577,6 @@ static void __unix_gc(struct work_struct *work)
spin_lock(&unix_gc_lock);
- if (unix_graph_state == UNIX_GRAPH_NOT_CYCLIC) {
- spin_unlock(&unix_gc_lock);
- goto skip_gc;
- }
-
__skb_queue_head_init(&hitlist);
if (unix_graph_state == UNIX_GRAPH_CYCLIC)
@@ -597,18 +592,12 @@ static void __unix_gc(struct work_struct *work)
}
__skb_queue_purge(&hitlist);
-skip_gc:
+
WRITE_ONCE(gc_in_progress, false);
}
static DECLARE_WORK(unix_gc_work, __unix_gc);
-void unix_gc(void)
-{
- WRITE_ONCE(gc_in_progress, true);
- queue_work(system_unbound_wq, &unix_gc_work);
-}
-
#define UNIX_INFLIGHT_SANE_CIRCLES (1 << 10)
#define UNIX_INFLIGHT_SANE_SOCKETS (1 << 14)
#define UNIX_INFLIGHT_SANE_USER (SCM_MAX_FD * 8)
@@ -621,6 +610,9 @@ static void __unix_schedule_gc(struct scm_fp_list *fpl)
if (graph_state == UNIX_GRAPH_NOT_CYCLIC)
return;
+ if (!fpl)
+ goto schedule;
+
/* If the number of inflight sockets or cyclic references
* is insane, schedule garbage collector if not running.
*/
@@ -638,9 +630,17 @@ static void __unix_schedule_gc(struct scm_fp_list *fpl)
if (READ_ONCE(fpl->user->unix_inflight) > UNIX_INFLIGHT_SANE_USER)
wait = true;
- if (!READ_ONCE(gc_in_progress))
- unix_gc();
+schedule:
+ if (!READ_ONCE(gc_in_progress)) {
+ WRITE_ONCE(gc_in_progress, true);
+ queue_work(system_unbound_wq, &unix_gc_work);
+ }
if (wait)
flush_work(&unix_gc_work);
}
+
+void unix_schedule_gc(void)
+{
+ __unix_schedule_gc(NULL);
+}
If unix_tot_inflight is not 0 when AF_UNIX socket is close()d, GC is always scheduled. However, we need not do so if we know no loop exists in the inflight graph. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> --- include/net/af_unix.h | 3 +-- net/unix/af_unix.c | 3 +-- net/unix/garbage.c | 30 +++++++++++++++--------------- 3 files changed, 17 insertions(+), 19 deletions(-)