Skip to content

Commit 0091bfc

Browse files
isilenceaxboe
authored andcommitted
io_uring/af_unix: defer registered files gc to io_uring release
Instead of putting io_uring's registered files in unix_gc() we want it to be done by io_uring itself. The trick here is to consider io_uring registered files for cycle detection but not actually putting them down. Because io_uring can't register other ring instances, this will remove all refs to the ring file triggering the ->release path and clean up with io_ring_ctx_free(). Cc: [email protected] Fixes: 6b06314 ("io_uring: add file set registration") Reported-and-tested-by: David Bouman <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Thadeu Lima de Souza Cascardo <[email protected]> [axboe: add kerneldoc comment to skb, fold in skb leak fix] Signed-off-by: Jens Axboe <[email protected]>
1 parent d7cce96 commit 0091bfc

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

include/linux/skbuff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ typedef unsigned char *sk_buff_data_t;
803803
* @csum_level: indicates the number of consecutive checksums found in
804804
* the packet minus one that have been verified as
805805
* CHECKSUM_UNNECESSARY (max 3)
806+
* @scm_io_uring: SKB holds io_uring registered files
806807
* @dst_pending_confirm: need to confirm neighbour
807808
* @decrypted: Decrypted SKB
808809
* @slow_gro: state present at GRO time, slower prepare step required
@@ -982,6 +983,7 @@ struct sk_buff {
982983
#endif
983984
__u8 slow_gro:1;
984985
__u8 csum_not_inet:1;
986+
__u8 scm_io_uring:1;
985987

986988
#ifdef CONFIG_NET_SCHED
987989
__u16 tc_index; /* traffic control index */

io_uring/rsrc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ int __io_scm_file_account(struct io_ring_ctx *ctx, struct file *file)
855855

856856
UNIXCB(skb).fp = fpl;
857857
skb->sk = sk;
858+
skb->scm_io_uring = 1;
858859
skb->destructor = unix_destruct_scm;
859860
refcount_add(skb->truesize, &sk->sk_wmem_alloc);
860861
}

net/unix/garbage.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ void wait_for_unix_gc(void)
204204
/* The external entry point: unix_gc() */
205205
void unix_gc(void)
206206
{
207+
struct sk_buff *next_skb, *skb;
207208
struct unix_sock *u;
208209
struct unix_sock *next;
209210
struct sk_buff_head hitlist;
@@ -297,11 +298,30 @@ void unix_gc(void)
297298

298299
spin_unlock(&unix_gc_lock);
299300

301+
/* We need io_uring to clean its registered files, ignore all io_uring
302+
* originated skbs. It's fine as io_uring doesn't keep references to
303+
* other io_uring instances and so killing all other files in the cycle
304+
* will put all io_uring references forcing it to go through normal
305+
* release.path eventually putting registered files.
306+
*/
307+
skb_queue_walk_safe(&hitlist, skb, next_skb) {
308+
if (skb->scm_io_uring) {
309+
__skb_unlink(skb, &hitlist);
310+
skb_queue_tail(&skb->sk->sk_receive_queue, skb);
311+
}
312+
}
313+
300314
/* Here we are. Hitlist is filled. Die. */
301315
__skb_queue_purge(&hitlist);
302316

303317
spin_lock(&unix_gc_lock);
304318

319+
/* There could be io_uring registered files, just push them back to
320+
* the inflight list
321+
*/
322+
list_for_each_entry_safe(u, next, &gc_candidates, link)
323+
list_move_tail(&u->link, &gc_inflight_list);
324+
305325
/* All candidates should have been detached by now. */
306326
BUG_ON(!list_empty(&gc_candidates));
307327

0 commit comments

Comments
 (0)