From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512363; b=y+4l06HvEy0Nmgzc5MCJiggfg72XNOy5lFWa8k2Rcb1cU+PZ+QnDQuwGvRxvmxW2a2cd 5KU4tx8nWpBxCWj2o7Uk4BOWrhbStj0DS11Xua2m1zofU1ANBHl2ba2CTlh7B7iFm1z8d ncm/aMvvM/c5pakNQTthU4HF+cgOLW6NS0Jm+k6nmvsfahnSkFOqhHLpvG92NUneV7keZ KXO0K93Oz9g0m3UEJ4TIj2vY8sPfxMCqOWnDmia1uZ0Tos4GyAn/iMUGBwi3LWoga7vp7 DwOoL1pG3y9jT1GUZm4/IHDUIyrF8aBi60+8Fr2uWzOs/r7HECSqkogbSG4etazryNw== 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=LcwgwvsK5CGIpCvr5rWGWyym6vpHlkPqYXAx9S4nGU7bBckoywT2hIMtqxS8AWjM9XkF 7y7Ae9tFdfrnYVAoZrQ93GDLXD7ChEzMzMC5Z0WWBpEHMnRYXOAf3XuIzXe9kRzYF9YQS xEi0dv6tlEGojIsY06h4aLF5+4fxavz09z46O+++iVHLh0yiQlmcLaa9E240pdNf6dpxY N5v+YdH7/DYn3oXWN9aQlzMkSGC2xM1H1Q3H20atWmY2JnRH1O8iHkaaiih4NSUEE5Mp7 j/a0xLTnkraEsSU/kfjSSkU9O1y1o8lqZzV6vKRfy8orWbHjhefBK2aEYWpIr8k+e9Q== 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.51 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 53154606A687 for ; Sat, 5 Dec 2026 23:12:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 53154606A687 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-f51.google.com with SMTP id 46e09a7af769-847ac7ccd85so1210093a34.3 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=SY78KUe7QWijd6pFvnyk8lEy+HLQqpbYKm69LNSbH9O9QWcAL6RxHy3N8MFrqld9FZ yAik41B1HxYEd1pQt6qlTM2aQLji8KUvPqIyjNzu8KyNnNJ/do4ykTNN7HQ6IOUyCAKg n+ugUKcYfWNb0TDwiW88bUf1DPeuKNgqt+6Jr79y9uUgjX7fQf0R+xm5O2k+PyH0pRUh A5rUESll6kXWqgDRLBD4I5vgtJTgRbgMuPOJ7YhbzwhppyHM0FT5zm0RQXDA+gM3lJTq QwCQH1kJRGT6180BgVu7OxKPCTYFK+FEK2spkfu4RnBnPZgbDTnLvo/pcZxwlJ4LHBZx ahUw== X-Gm-Message-State: APuU4Z8svqxYxPekObL0Kdb++phHATe+bhrrC1emLXhHeMWZvCKe82UP grsL95lipACvTDsrBqSX9Euca3k5lhpdY3cA2O6ceq3rWRAxzncod7267VyfNevVPKgkV9TU9mc LRBMXufk= X-Gm-Gg: AZFdTZdtW7vrtP9nvdY4MRgm2QkYDAryct3+Ono7UFZdFq+NVyMVoNCnal4ZTx8fzvu LI1J68ylkFrvoSP/dQTIHUrzhh3/DazEJ381tLCpwFOo1WaT00xiCv4dSLXWlSQhPBDUOry5qGF mwrrig+YtQdduG3twpQe0jtOrjpSQ5/9qAYXJCmLJSwkwryfI6q1m8YOiblgsm1NjtbmIOqfNys yFGcZVtzLU86i3kDjMqxDq7xCosMDUfICxM2AygZo31+UQ4c44otw5lsj9b0EVqag/NP3jl1uNi kY74GG2tn66NL6luRJQkP84bkQdA8oZk8lqzwQj3Ho+uqW+5BMAlvZFgQmZJkVK+QxPjgDsauGz RBKMHJgDnzRryp1qWyDVpYeMFU9SrjpR77cp2qqhCOhQX+Ff4C/x8L2og7iIsv1+DpZCQfdv0QU pULiFTs4A6RTbnbCeKfIURhCA/S1cUhTZfHPyEVbyPaSxekkOtid0LscYqF/26Qg7p8MiqOtUHy n5cxTMCh3CFOjvZclldmEpwm5Ha+0B8QDQ0gdhZNRdCnNl/pErD7Bam6D9GMBmw0i5TM+R8OGzS RmxvjxZuBGvvRhvIILxeAIz8ul9t/6cTNqO7dtlTEZjYbNTM6iMk+kSu9yantbQcVyXLoivQrRw ECWVro9sOkjupFBKGXz6BQ8tuFA1Q9MQ3QRfh 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: stable@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