Skip to content

Commit 5f23b73

Browse files
dann frazierdavem330
authored andcommitted
net: Fix soft lockups/OOM issues w/ unix garbage collector
This is an implementation of David Miller's suggested fix in: https://bugzilla.redhat.com/show_bug.cgi?id=470201 It has been updated to use wait_event() instead of wait_event_interruptible(). Paraphrasing the description from the above report, it makes sendmsg() block while UNIX garbage collection is in progress. This avoids a situation where child processes continue to queue new FDs over a AF_UNIX socket to a parent which is in the exit path and running garbage collection on these FDs. This contention can result in soft lockups and oom-killing of unrelated processes. Signed-off-by: dann frazier <dannf@hp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent efbbced commit 5f23b73

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎include/net/af_unix.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
extern void unix_inflight(struct file *fp);
1010
extern void unix_notinflight(struct file *fp);
1111
extern void unix_gc(void);
12+
extern void wait_for_unix_gc(void);
1213

1314
#define UNIX_HASH_SIZE 256
1415

‎net/unix/af_unix.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
13431343

13441344
if (NULL == siocb->scm)
13451345
siocb->scm = &tmp_scm;
1346+
wait_for_unix_gc();
13461347
err = scm_send(sock, msg, siocb->scm);
13471348
if (err < 0)
13481349
return err;
@@ -1493,6 +1494,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
14931494

14941495
if (NULL == siocb->scm)
14951496
siocb->scm = &tmp_scm;
1497+
wait_for_unix_gc();
14961498
err = scm_send(sock, msg, siocb->scm);
14971499
if (err < 0)
14981500
return err;

‎net/unix/garbage.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include <linux/file.h>
8181
#include <linux/proc_fs.h>
8282
#include <linux/mutex.h>
83+
#include <linux/wait.h>
8384

8485
#include <net/sock.h>
8586
#include <net/af_unix.h>
@@ -91,6 +92,7 @@
9192
static LIST_HEAD(gc_inflight_list);
9293
static LIST_HEAD(gc_candidates);
9394
static DEFINE_SPINLOCK(unix_gc_lock);
95+
static DECLARE_WAIT_QUEUE_HEAD(unix_gc_wait);
9496

9597
unsigned int unix_tot_inflight;
9698

@@ -266,12 +268,16 @@ static void inc_inflight_move_tail(struct unix_sock *u)
266268
list_move_tail(&u->link, &gc_candidates);
267269
}
268270

269-
/* The external entry point: unix_gc() */
271+
static bool gc_in_progress = false;
270272

271-
void unix_gc(void)
273+
void wait_for_unix_gc(void)
272274
{
273-
static bool gc_in_progress = false;
275+
wait_event(unix_gc_wait, gc_in_progress == false);
276+
}
274277

278+
/* The external entry point: unix_gc() */
279+
void unix_gc(void)
280+
{
275281
struct unix_sock *u;
276282
struct unix_sock *next;
277283
struct sk_buff_head hitlist;
@@ -376,6 +382,7 @@ void unix_gc(void)
376382
/* All candidates should have been detached by now. */
377383
BUG_ON(!list_empty(&gc_candidates));
378384
gc_in_progress = false;
385+
wake_up(&unix_gc_wait);
379386

380387
out:
381388
spin_unlock(&unix_gc_lock);

0 commit comments

Comments
 (0)