From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512363; b=KCc1zZPNNW2ifVy+B/eS+hX/3SYg+PDsjMv/BRYGVyFKYjhJ9WEkAhoCoXojTMI1PGh+ fWVAqysqK0nQoXQVA0Q/6OJln7UgPP/5zSmqb351fPXqEHFLJvSQe4UibA1KncNc3iQbl 5StOOg78iI0hhW8QeTnhl9e6Ez6a6M3aotxUoNN/vVGyviKsLTvQ168NsD2TCPd1/Vtrn H5IKKwBSmbBG0HE37G4hP+DJgoYVWBvgLqSkMLbAWTFB1OQEnlmCN0OWZqT32/Xig/DVD IHWZ5a1otRAOAwYxU+r4esM4kDpmqZ8KWWzML7OfwCL0b736MoD4GRwRftj7p5To3Lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512363; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=GWJM+/KD1pMfEMqymHWh27PbEV7ZAtpZml/JbsURA84=; b=WM/wnfoq5V4mHE8c3wayeLkA1hxZ6BkYMk05g5TZXgfcy02/xDS/py6IrvKhdabU/Qrq xx1yHPIiQ8MyPMf7XnFDtIScTHnLU7uY9ZmqidR0iA0Aqwm8vaEzeaxZhCKk9iez+c5CB syhFtXcZyWi/yj/x4XWiBksLZTkmEA/ytMYeZbQLv300Wa5bAtN1BvdeRx7CWC3h+CTv3 F8BmLPciCBqdqPb5JJJ/BP750MNvu5557Tw8ahTGNObmgJir70NtxSeHJrQYXUZTXzkwf q/IrJzauSJsYGKyogI6UzmW0fM7C1rkQDJp/tv1uoDU+PDNeWSDn4VYXd84Kfw5kzdQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=RZWxa6Cp; arc=none smtp.remote-ip=209.85.210.54 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CDF4606A682 for ; Sat, 5 Dec 2026 23:12:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3CDF4606A682 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=RZWxa6Cp Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-862b9c2e78aso1164166a34.2 for ; Sat, 05 Dec 2026 15:12:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512362; x=1797117162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GWJM+/KD1pMfEMqymHWh27PbEV7ZAtpZml/JbsURA84=; b=RZWxa6Cp5+CvaHL2dP5IVTpteqo4IUXMLDmHFBD2qnSzn3ySi788+JwFBw/97Q0MyR Nnp7bAZPnFdqj+lAflv2uZn0bQYuaQeuSsdFflPzIBI9STL5HGkHSMUPmVwOky+jZaqJ yvx8cqofMuIX72xlXOPi19A0pQGhZU7A388H9sun+Yu/rLLHKkgIATeFVuloCvmBdSMz hiNoDeXnwGD2COkSYmAA2moXSrBkHBaI+2W/0ElI6bmxSmI7EErR/TltaUSu5RVc2SIv EcFZ3zxMwBPc/UE5Svarlmc70PT8Je6W5HtequErUXGPJg+mj8lOTWMufHhFZD5XjVQt 4Kvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512362; x=1797117162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=GWJM+/KD1pMfEMqymHWh27PbEV7ZAtpZml/JbsURA84=; b=R8O8pesu4z+tgzEoCMbz6i3rWymwBOit2J3HYCYUGOKq05LQpPVNGTNgKL7750sSLQ rC6PPVaiVlxFBdhYheis6zxxaEtbeZWq3x6QoJWkGj9CLTYfvhFwCz8D4HKnO3f/Zl/f 8TM2hqSdixa/yBBFiBDSoc99Aww3cfskmkPZMp84wW098Bh4xhv8SWj4JYzCW9nejfnW mF6fUn1JjiPlVhu4aI79hi+TF4aUEJW+NdGf2dFdGmfSsRNTc/xjAyw49lGc+koDbOr7 tsuvqLQWVWbBIhNe41NMVaT1cyea/AajLata/nSjv7E+nM7ZT6vI9WQvgOYy8K0LyJP6 XUdw== X-Gm-Message-State: APuU4Z97QzDCQR1sk6uCTGi1bsD2Eww/AumcMA3v5C3cdIh391aSvAyM KIHheIy3INUU3mjCWSiwlaGjJ4IoL45wviJ3S99+mHE+mPpQz7Wwhw/bQXxAFIZPK8Ff4U27k3S e4ifDr98= X-Gm-Gg: AZFdTZe9zn2bEEavWmxNg7HVBJQzpwh2Yw87Dlu4w9Zd85wO5nJCb5Y85HF4U2GAFQQ 3LHyQFgbs08NM4cPUvWzEBmOECtPVca0SWxaUDiliW51mE7MYe526X4sbW4SSopsM6cHXPrcMSl e2aQcfXd1C3kgKHCz1MD3s2P3ciLoAiBNydxSyw0ttRFZXnmHNH/TOmnmTi1cKr2kpV/WUKnret fc9Jk6YoewrB0iaGnDlhTpbtsfEVZ9QFJLu4QJ0hADrSp94sEb30gSFl9qDfcgRscyX/h2LsVS5 zWUZu4KJAVyAFF/O6qXDqPngvLntxsRRzTektU97GJ629mlYAYJKYhCeT+sbjnhBXfCb6UewEDK PdBxiYZvPb0Ews0HweByogNeBhnKJ9GP4sadjq6QY0Gwx+n1c4ifFb8UVIFI3B5O4xJRIFWy83Y l79iWjf9KLELIRSwNPjGe40u35+EUYq/UEBMxnW97W46QVQBeajZ92dEOBOyHgTZ/twW849Sq1r gw3ux+D8lkuxE2vN9pRex4CFTwteQfJANyFfHjBmUzToOKk8xaIjdokKvfaSkZsSR6d0+m10ZF+ C+88W1yEthXnq7yDMA3u6E4D9vGZL9RWc/ghfeRB0V4Y0b0+9Ff5l3Ccnf+c5kHTbbvZKeS8SD2 PmFCEOLVdYjAh2KmPsro3nsIet97iDPuHTwV0 X-Received: by 2002:a05:6830:6816:b0:863:43a6:24e7 with SMTP id 46e09a7af769-863f89f6d02mr7064271a34.23.1796512362279; Sat, 05 Dec 2026 15:12:42 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f7dd42a8sm6279788a34.0.2026.12.05.15.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:12:41 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.6.y 04/13] io_uring: free the task context after a grace period Date: Sat, 5 Dec 2026 23:12:24 +0000 Message-ID: <20261205231233.4140988-5-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231233.4140988-1-axboe@kernel.dk> References: <20261205231233.4140988-1-axboe@kernel.dk> X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chris Mason Commit 9f5315d3f4368590c9fe06d4313b7247470bcf15 upstream. A task other than the owner can free a request, io_ring_exit_work() running the local task_work of a DEFER_TASKRUN ring for example, or io_do_iopoll() reaping completions. io_put_task() then takes the else branch: percpu_counter_sub(&tctx->inflight, 1); if (unlikely(atomic_read(&tctx->in_cancel))) wake_up(&tctx->wait); put_task_struct(tctx->task); The first line is what lets the owner leave io_uring_cancel_generic(), and on exec it frees the tctx right after. Nothing holds that off for the remaining three lines, the task reference only covers a tctx freed along with the task_struct. It used to work out because io_uring_del_tctx_node() took the uring_lock that the freeing side holds across io_put_task(), until that moved to tctx_lock. Free the tctx with kfree_rcu(), and enter an RCU read section in io_put_task() before the count is dropped. Fixes: 5623eb1ed035 ("io_uring/tctx: add separate lock for list of tctx's in ctx") Signed-off-by: Chris Mason Signed-off-by: Jens Axboe [axboe: 6.6 drops the count in io_put_task_remote(), enter the RCU read section there] --- include/linux/io_uring_types.h | 3 +++ io_uring/io_uring.c | 2 ++ io_uring/tctx.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 8528eff2ae50..302552d8def1 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -62,6 +62,9 @@ struct io_uring_task { atomic_t inflight_tracked; struct percpu_counter inflight; + /* the tctx is freed after a grace period, see io_put_task() */ + struct rcu_head rcu; + struct { /* task_work */ struct llist_head task_list; struct callback_head task_work; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 3fdd48bf62ce..056c8a27df14 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -764,6 +764,8 @@ static void io_put_task_remote(struct task_struct *task) { struct io_uring_task *tctx = task->io_uring; + guard(rcu)(); + percpu_counter_sub(&tctx->inflight, 1); if (unlikely(atomic_read(&tctx->in_cancel))) wake_up(&tctx->wait); diff --git a/io_uring/tctx.c b/io_uring/tctx.c index 1ff01d73e9dd..63c97eec3038 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -65,7 +65,7 @@ void __io_uring_free(struct task_struct *tsk) WARN_ON_ONCE(tctx->cached_refs); percpu_counter_destroy(&tctx->inflight); - kfree(tctx); + kfree_rcu(tctx, rcu); tsk->io_uring = NULL; } -- 2.55.0