From patchwork Mon Oct 24 11:32:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp625649wru; Mon, 24 Oct 2022 12:54:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Eq60mHiELL7lekA13p9E0K90EMVGgH2a22itvc6iJ1OzfH7bHUe1VZ1z/+jgHpOjY5bpX X-Received: by 2002:a63:e04:0:b0:46b:2bef:338c with SMTP id d4-20020a630e04000000b0046b2bef338cmr29183239pgl.206.1666641298067; Mon, 24 Oct 2022 12:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666641298; cv=none; d=google.com; s=arc-20160816; b=fCL8jWjVz/RqbA6pXNRmAZX86YrcAGUIyapxWP+D7jHw8juVNFNY4miDCQXY23KMF2 hD1nkHb6kNodCkTZJwg9maoCkTqZrttg0AzS59NG9UbIhfXcTUQr7oHEXmNFlNc6py4A iDrPEy28I4pXrza3LDneZZOaXGlxS/6n7qrp5K+MrP0Rdwebp6TOp9NLHSBJO/i2qgS2 XzFIfwGFLXZ74HubTqbXoUvZ3jPSWnjzy3zGj4tffF0BLhXPk1gW76GvuDtPYCZ2n8TV UsUNwf1DZXjJG7xTeQiWgdAYS/wNNdIUFW6A17sCtLQcdycKzeD+TgMikMnnkAO5e3E0 T8Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G+YdJOFXodV5XEpap+SfrcnmmVA0ibFoW6OENZxUqyE=; b=bMJ4upHlOa/Lk+CoqrDW04TWSXMwT7p8bm3c9W/AwA50hcJDRJctzpoXxa1U6nT/1i 4JLf6dg25ckSQEhuRB5fRDgb5yStbl+/cY/2fHEN/bNRV4w8CzOuAgvnfW/9hv/ftAIj KmQuT0jF5l3YdjcQEV0WgzwwQbIaCqQjLbrd23krDdMx+rm+qp8rcqgXRFccmS7p5chk wvVewq/ebmsVrJLXxMczN3VIPjfCJ4JqzqDDq/GxkwXtpzMluxKQw6wv/aOyUjHZ5xXt 1tnErX1CEoZmR2F7fdTvPtOKgRsnT6R3ED9+saqnUeABE7nDovrTEDhvwALPTPsNAv32 4FkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="OobV/Hlb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w19-20020a656953000000b00462c469b730si373681pgq.648.2022.10.24.12.54.45; Mon, 24 Oct 2022 12:54:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="OobV/Hlb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233548AbiJXTxa (ORCPT + 99 others); Mon, 24 Oct 2022 15:53:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233664AbiJXTwB (ORCPT ); Mon, 24 Oct 2022 15:52:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C4FB1C438; Mon, 24 Oct 2022 11:17:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E5CBDB811BF; Mon, 24 Oct 2022 12:32:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40F9DC433C1; Mon, 24 Oct 2022 12:32:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614751; bh=V9I1S9ZPJGwn5TpHKyAKfFQ4a5L+krK6cws/EQNVcSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OobV/Hlbgv3M7yZYcMeP2o3CtQXNSgEg/GdUR8LHt33tF+bqxcDVALOIAA0+gpTTp Tlm7PCxxOWtuk46PA+yBOOxgsVv/cXJHpP6CdbGdV4olalJ+Eegv5lEGQUPIBCwpLK xjl5eVZdBeyZpJI3I6FqhKuZ+VkGCUuvhASKZhYg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Pavel Begunkov , Thadeu Lima de Souza Cascardo , Jens Axboe , David Bouman Subject: [PATCH 5.10 379/390] io_uring/af_unix: defer registered files gc to io_uring release Date: Mon, 24 Oct 2022 13:32:56 +0200 Message-Id: <20221024113039.118238854@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747600065682174928?= X-GMAIL-MSGID: =?utf-8?q?1747600065682174928?= From: Pavel Begunkov [ upstream commit 0091bfc81741b8d3aeb3b7ab8636f911b2de6e80 ] 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: stable@vger.kernel.org Fixes: 6b06314c47e1 ("io_uring: add file set registration") Reported-and-tested-by: David Bouman Signed-off-by: Pavel Begunkov Signed-off-by: Thadeu Lima de Souza Cascardo [axboe: add kerneldoc comment to skb, fold in skb leak fix] Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 1 + include/linux/skbuff.h | 2 ++ net/unix/garbage.c | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7301,6 +7301,7 @@ static int __io_sqe_files_scm(struct io_ } skb->sk = sk; + skb->scm_io_uring = 1; nr_files = 0; fpl->user = get_uid(ctx->user); --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -681,6 +681,7 @@ typedef unsigned char *sk_buff_data_t; * @csum_level: indicates the number of consecutive checksums found in * the packet minus one that have been verified as * CHECKSUM_UNNECESSARY (max 3) + * @scm_io_uring: SKB holds io_uring registered files * @dst_pending_confirm: need to confirm neighbour * @decrypted: Decrypted SKB * @napi_id: id of the NAPI struct this skb came from @@ -858,6 +859,7 @@ struct sk_buff { #ifdef CONFIG_TLS_DEVICE __u8 decrypted:1; #endif + __u8 scm_io_uring:1; #ifdef CONFIG_NET_SCHED __u16 tc_index; /* traffic control index */ --- a/net/unix/garbage.c +++ b/net/unix/garbage.c @@ -204,6 +204,7 @@ void wait_for_unix_gc(void) /* The external entry point: unix_gc() */ void unix_gc(void) { + struct sk_buff *next_skb, *skb; struct unix_sock *u; struct unix_sock *next; struct sk_buff_head hitlist; @@ -297,11 +298,30 @@ void unix_gc(void) spin_unlock(&unix_gc_lock); + /* We need io_uring to clean its registered files, ignore all io_uring + * originated skbs. It's fine as io_uring doesn't keep references to + * other io_uring instances and so killing all other files in the cycle + * will put all io_uring references forcing it to go through normal + * release.path eventually putting registered files. + */ + skb_queue_walk_safe(&hitlist, skb, next_skb) { + if (skb->scm_io_uring) { + __skb_unlink(skb, &hitlist); + skb_queue_tail(&skb->sk->sk_receive_queue, skb); + } + } + /* Here we are. Hitlist is filled. Die. */ __skb_queue_purge(&hitlist); spin_lock(&unix_gc_lock); + /* There could be io_uring registered files, just push them back to + * the inflight list + */ + list_for_each_entry_safe(u, next, &gc_candidates, link) + list_move_tail(&u->link, &gc_inflight_list); + /* All candidates should have been detached by now. */ BUG_ON(!list_empty(&gc_candidates));