Skip to content

Commit

Permalink
af_unix: Replace garbage collection algorithm.
Browse files Browse the repository at this point in the history
If we find a dead SCC during iteration, we call unix_collect_skb()
to splice all skb in the SCC to the global sk_buff_head, hitlist.

After iterating all SCC, we unlock unix_gc_lock and purge the queue.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/r/20240325202425.60930-15-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Kuniyuki Iwashima authored and Jakub Kicinski committed Mar 29, 2024
1 parent a15702d commit 4090fa3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 258 deletions.
8 changes: 0 additions & 8 deletions include/net/af_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ static inline struct unix_sock *unix_get_socket(struct file *filp)

extern spinlock_t unix_gc_lock;
extern unsigned int unix_tot_inflight;

void unix_inflight(struct user_struct *user, struct file *fp);
void unix_notinflight(struct user_struct *user, struct file *fp);
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);
Expand Down Expand Up @@ -85,12 +82,7 @@ struct unix_sock {
struct sock *peer;
struct sock *listener;
struct unix_vertex *vertex;
struct list_head link;
unsigned long inflight;
spinlock_t lock;
unsigned long gc_flags;
#define UNIX_GC_CANDIDATE 0
#define UNIX_GC_MAYBE_CYCLE 1
struct socket_wq peer_wq;
wait_queue_entry_t peer_wake;
struct scm_stat scm_stat;
Expand Down
12 changes: 0 additions & 12 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,12 +980,10 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern,
sk->sk_destruct = unix_sock_destructor;
u = unix_sk(sk);
u->listener = NULL;
u->inflight = 0;
u->vertex = NULL;
u->path.dentry = NULL;
u->path.mnt = NULL;
spin_lock_init(&u->lock);
INIT_LIST_HEAD(&u->link);
mutex_init(&u->iolock); /* single task reading lock */
mutex_init(&u->bindlock); /* single task binding lock */
init_waitqueue_head(&u->peer_wait);
Expand Down Expand Up @@ -1793,8 +1791,6 @@ static inline bool too_many_unix_fds(struct task_struct *p)

static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
{
int i;

if (too_many_unix_fds(current))
return -ETOOMANYREFS;

Expand All @@ -1806,9 +1802,6 @@ static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
if (!UNIXCB(skb).fp)
return -ENOMEM;

for (i = scm->fp->count - 1; i >= 0; i--)
unix_inflight(scm->fp->user, scm->fp->fp[i]);

if (unix_prepare_fpl(UNIXCB(skb).fp))
return -ENOMEM;

Expand All @@ -1817,15 +1810,10 @@ static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)

static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)
{
int i;

scm->fp = UNIXCB(skb).fp;
UNIXCB(skb).fp = NULL;

unix_destroy_fpl(scm->fp);

for (i = scm->fp->count - 1; i >= 0; i--)
unix_notinflight(scm->fp->user, scm->fp->fp[i]);
}

static void unix_peek_fds(struct scm_cookie *scm, struct sk_buff *skb)
Expand Down
Loading

0 comments on commit 4090fa3

Please sign in to comment.