From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512281; b=DnNoufVpoXkGxMorZ0kccQ8bQFJw0JYHmFqjjF7MfE27zDl3CuWw3VwqZooj5w7SVPmi xP8ktfV2ONawiVCxAFFjN4bKoT/qieL+FaqLvSLrtvIAgSg9YlgsldlbGTajuxooC20lh 2hEAoUY3zmgZFmEbFza2p0eUi6hzx5fuYXQ25YPHCmLz31hETyLXy2g5O7DUTqiJyvMW2 KUBs+qACCfJ/vBdGzpzV9TreoU/cQMB3nHe47SFQJ3Hvb9cNeL3ASsxYEuBZj55AGD5kf LnYnfrLBqHeIagBtsMehBQIZxq5Q9teZDSR7baZtL95hw2wM9SC+rPiULM0Ov5WZf9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512281; 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=kFiL8RyQEhmxhG7+cJkD31M4c4k5I2ypHKe3/7NHBl0=; b=jpdpM8/aFBOnm1uFIFl4F90KA/UpwWgYYJo+Ddi9ecxRFYjR0V+JXiE5/zapbWcozwzX BZAHzSg88V9C08iN8XgnTGqDr4NZ9XTK67pGZ0ldLSEpLSa1g9TflSU2s18CJTE+haFAu dkmgRb46TFyJZYlfu/TwBkxZ+oyfZz9AZHKeWOuY/G41gtmiWUt+dQfCL5Gk0D6DUMvoi nUZ14ExRS80ze6p6jk7O5ruRD8hyPKzFX+OxaUbJ0HWcRQHA9bLqtSYnwUJXEqdxg5HH0 WSu0/MhFIyzd8sBWR8Qt4A/LOhNEnG9dL7arWb8/jaEPyflNB3qhUkNnly4FB+I2aZw== 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=k+o5Lz8z; arc=none smtp.remote-ip=209.85.210.52 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 B8F40606A333 for ; Sat, 5 Dec 2026 23:11:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B8F40606A333 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=k+o5Lz8z Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-8253bc5a613so1480787a34.0 for ; Sat, 05 Dec 2026 15:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512280; x=1797117080; 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=kFiL8RyQEhmxhG7+cJkD31M4c4k5I2ypHKe3/7NHBl0=; b=k+o5Lz8zTpekITEuFaqTOQQ3XAKuLjRdMBQ6nz3r5hGZ2+ccR9fSq3XBjSyma7A7dL s4zEEEtmxmkJ/2p2+SozA4mhL7Onsk+NbK5LmEZ8fe0JL7tQe/HgNzKt6P1Gc3uUiyUg I/Vt0nnf//d/OHMPNXHXqS5L1Vq0RFref8FA+srcHDUGIINh39/0ID/3Lv9oF8IRQP2s 5pYenfM+4Xi3xVFvrbPH70ogFMcsclwOOu0hXmfxMvV9obWUOT7gSOFWbjRqhu3nFINw evyVIJwgk3nJdoalhPGJE9MZ+ampx87unRWqoGFVST6vMfUDyelkzPrgAwPjUy9WaNRc fWkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512280; x=1797117080; 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=kFiL8RyQEhmxhG7+cJkD31M4c4k5I2ypHKe3/7NHBl0=; b=hMHOjUPGYb6u1SU95tPo7Azu3ujZi7hHGM0Wb0f58/e2437QmvYccQFxMWNoaCPcdq 9XmvloXDDyyi8YCltVlV32I6wU5unI9snfUGCm0dW0LuPYEGCKIN2WZcklmAXPjzg+SM Bd2iDx0bC1QHSiklQuzZAzcmEkIvk85PYNruc1V89j1P5bmbkB2UQoPD4VZTRNyCas7n Pgdv5PWCVZ9eslgQ+O/B9qgWDjdMiYOV+Ibn7cn2XE1YOBwom9cJpp5byg+lzlUQGrfd sxWVWMw9W79xR3qIBXF4AdLadr2Gv/b+yMWgR1lymlN7Gs5S2H57wdz2LnTQj/oqW2Bz tO7g== X-Gm-Message-State: APuU4Z//Qd0rAbjBQtrZ73//BD/Fp+TA8QVqj6WKs2z0kvyBTdiVyjaw vcT2wJRJ7HUlwYHh+mRmpNY6sRE8tm5NNmv26nQWBlbO51EaKRiS62o3ZfB2Q2e1PsiD+nZXFQH IsRhiTso= X-Gm-Gg: AZFdTZfclCjYgS4nyeWOYCkSBumTAn1bo3ajI9IpIQZA8Xt8XVZLKLdb3pI0y9udkST dll0ZdVg1AR1DItIUY/iT//JKd98qPy3fUwMZ/7eoaAF6BJV7au+o1WQYuUU/ZdRDjqB23MFnA2 Qm+OZVwnjf/NJKjS5jWssT6LlaYlLE9ksgwnMWd1YA7jxa8VnMkxjTIgZ/U0TDrLv5IXbN+ttHW Cz5eWzEmVj+848mNvK/7weZKqAjr6/CjyXyy1lcQVFPkjdSaZQ61s88N4Ogp0d2+V/36Aiv52Op X1YFzjnPe6S1ZX7i1VgEGz53Z/LdNO6ljBeFMWG82/sLVOqIsyWv/I6QX/XeP9MasjSS3vRbBjK awoopu05jZYP6drZJAugSAA1pf5/X/VN3C0hSoZv0jQqkUyN6OyVvpu4v4J3cH5ywEYO6aB1YmM ON7bLaeCFU//qL4/XWxhKKzreyBUjnWfi3TmlbHNWU/v8YCP81IAIow/rvNDb/PtUpR6Xbuwx89 mAcnv44M3+ZyEvPZwbFc0RXoC0RxtX1GMShSwCHTOkZJC9lCHqtE6UIXpdTMq3/Ffdp4UjBJVtb iZS0BIxwokqb5DRF4Hbm+n+ttFkRpNDyMmxaBEG0tSgaSRoSEGmMU8SL72rhLcwQmtELeT9oD2e FesSQ+fgr1MjwfccTUUsBieFBj5FLaU4POqbNR38cjWsxi9i3lDdoroJTEw== X-Received: by 2002:a05:6808:5396:b0:575:39f9:df77 with SMTP id 5614622812f47-57f20892013mr5230618b6e.55.1796512279754; Sat, 05 Dec 2026 15:11:19 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57f1f65febbsm4163964b6e.6.2026.12.05.15.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:11:18 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.12.y 05/15] io_uring: free the task context after a grace period Date: Sat, 5 Dec 2026 23:10:57 +0000 Message-ID: <20261205231107.4023506-6-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231107.4023506-1-axboe@kernel.dk> References: <20261205231107.4023506-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.12 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 ecf6b8e15fe7..3fa179dd10b4 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -103,6 +103,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 de46d9e21140..3e5201e19bb4 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -685,6 +685,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