Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

af_unix: Remove io_uring code for GC.

Since commit 705318a99a13 ("io_uring/af_unix: disable sending
io_uring over sockets"), io_uring's unix socket cannot be passed
via SCM_RIGHTS, so it does not contribute to cyclic reference and
no longer be candidate for garbage collection.

Also, commit 6e5e6d274956 ("io_uring: drop any code related to
SCM_RIGHTS") cleaned up SCM_RIGHTS code in io_uring.

Let's do it in AF_UNIX as well by reverting commit 0091bfc81741
("io_uring/af_unix: defer registered files gc to io_uring release")
and commit 10369080454d ("net: reclaim skb->scm_io_uring bit").

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Acked-by: Jens Axboe <axboe@kernel.dk>
Link: https://lore.kernel.org/r/20240129190435.57228-3-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kuniyuki Iwashima and committed by
Jakub Kicinski
11498715 d0f6dc26

+2 -30
-1
include/net/af_unix.h
··· 20 20 void unix_inflight(struct user_struct *user, struct file *fp); 21 21 void unix_notinflight(struct user_struct *user, struct file *fp); 22 22 void unix_destruct_scm(struct sk_buff *skb); 23 - void io_uring_destruct_scm(struct sk_buff *skb); 24 23 void unix_gc(void); 25 24 void wait_for_unix_gc(struct scm_fp_list *fpl); 26 25 struct sock *unix_peer_get(struct sock *sk);
+2 -23
net/unix/garbage.c
··· 184 184 185 185 static void __unix_gc(struct work_struct *work) 186 186 { 187 - struct sk_buff *next_skb, *skb; 188 - struct unix_sock *u; 189 - struct unix_sock *next; 190 187 struct sk_buff_head hitlist; 191 - struct list_head cursor; 188 + struct unix_sock *u, *next; 192 189 LIST_HEAD(not_cycle_list); 190 + struct list_head cursor; 193 191 194 192 spin_lock(&unix_gc_lock); 195 193 ··· 267 269 268 270 spin_unlock(&unix_gc_lock); 269 271 270 - /* We need io_uring to clean its registered files, ignore all io_uring 271 - * originated skbs. It's fine as io_uring doesn't keep references to 272 - * other io_uring instances and so killing all other files in the cycle 273 - * will put all io_uring references forcing it to go through normal 274 - * release.path eventually putting registered files. 275 - */ 276 - skb_queue_walk_safe(&hitlist, skb, next_skb) { 277 - if (skb->destructor == io_uring_destruct_scm) { 278 - __skb_unlink(skb, &hitlist); 279 - skb_queue_tail(&skb->sk->sk_receive_queue, skb); 280 - } 281 - } 282 - 283 272 /* Here we are. Hitlist is filled. Die. */ 284 273 __skb_queue_purge(&hitlist); 285 274 286 275 spin_lock(&unix_gc_lock); 287 - 288 - /* There could be io_uring registered files, just push them back to 289 - * the inflight list 290 - */ 291 - list_for_each_entry_safe(u, next, &gc_candidates, link) 292 - list_move_tail(&u->link, &gc_inflight_list); 293 276 294 277 /* All candidates should have been detached by now. */ 295 278 WARN_ON_ONCE(!list_empty(&gc_candidates));
-6
net/unix/scm.c
··· 148 148 sock_wfree(skb); 149 149 } 150 150 EXPORT_SYMBOL(unix_destruct_scm); 151 - 152 - void io_uring_destruct_scm(struct sk_buff *skb) 153 - { 154 - unix_destruct_scm(skb); 155 - } 156 - EXPORT_SYMBOL(io_uring_destruct_scm);