From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512281; b=2LmwsMK7E3ZGrB5vW0UJXxYX8Mc9eQ0zaiTb1oa8yUToEbzn0qVUCwfPZWTej0z+d47b +3yE95YqB6ln6OmR/U7hD8UZkSjGRF5PqYzAZTUytQIMAeGiBx3d8rAL7nAHeKRYZWQMi pAgN+XOx6HfRXCjGuu1vddEUDy6gBIY9zI8JBs+rkfhM56jsHqV05QJY476YYdzy5VW6b cMgsemcGi1FqRIao4XjySdRyMzDljDRgIRpl6ummpYeCodmsDnmFWi81BRkEGSvAGkorQ iBYaYf+KfyRTdQeiDsDHkWCmSkn15o4zLjTiaB/n+wXFUKsX8rxhUkRzap55ev7lU4g== 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=gG9rCIwv1i6hEDrit+/VyEnOh58GfcTuMC8byF/qSqXLg8uNuek8sabEOWQEzJG3qUZF 01dVfG1aw1OPI6v9ffjA/Ch8EPtyOex7vA6SVIKXg0bsfB+F5s7/BwzbEqcpXs3eEYtob 284cvo7SgMP1IuuO5jMmxhykktf++Jx3PFQrIgpiRRkO3r4WeGo+LlAR5mnqYgmPoZ3qm gEsafPcNA5JvohsyeTn9jD5EVSyz5eScDrZ1wyI47aKJmSJbEosfhy+Vap4R4nSmV/piH L4zadg+bwA++jL3n5K2VL8u7q0t9SA42oDLEemV2Yp39hp/VLT6D1QXFplXfF/LKp6g== 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.49 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (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 B908D606A337 for ; Sat, 5 Dec 2026 23:11:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B908D606A337 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-f49.google.com with SMTP id 46e09a7af769-8631e07b756so1281877a34.3 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=ZN6mQMaf6efcxrefWlBdr+HJ+AKWpctfKKlZzzaaLxAsTVeexngKMjZBw5G6h8FUmI 0u9ff/PMr44K0aZ0MCnExc6A/M6JzpbGTeIkb2zLlC4ZBmOCK5OQy46NpJiRS1TX4i7k pnDTjbODXmX5uM0vl1uEXn0ulRMFqKPrMO7jAQ3vMtzHdzQ25Kk1Tgc+DtJZafbbNkse +kiuDHNkVwleX/QbHqcSGlp/EW2YsVG6j/sGSMLkf5pepweDfGaeuGAqC+uykqD7yaLC z+6igraiBo1d3yZY6YlANjQ8NL6jQwVr6tj3tDUC2GxH4/VlaHD30wMz/Jr+63tRm6zm mk3w== X-Gm-Message-State: APuU4Z9nEyIodD7JYRwojh+leUjTzorg6RCTrlk++TiwnQqtXYCGv84C p472OVaLM9xcRglRT3LM/IToDPgrLf2TUCoRGmyazqaUxJsWjRvIx24SMOMMzqHKt4zTVDfE36/ hF5wakbM= X-Gm-Gg: AZFdTZf0W/ftaby8ZuAjKkdswpYYLtSzOk+Tda3kvW3aYPrV54DMFRq2Izr2cLnSuAl pXYsOFOUOahwZy7tM2GQmJAnkT5SOQWeq0H+tbvnoplfrkM5jXlrw5HIScmUHmUFuWjJKr8nDFY 3ddN8ok/Qv2d2kJYPd/8/ddUaE5NkTudyBWtSNPmuTOLJt9iizixxfLqdTnGTZfdIK4HIsfiwkZ 4v9Jkrll+WYy8mJcT0teDVrstRu2YHyL3RWDsYUC1tfnDXR8lwRQPJUIQEHW92BwZCr4xGgqfqJ PER/NBglQWNBTG40B7DSB7X3qwY9ZMSnFxeQMgNaF2JD1p8uulZRSbL2OkAE+wH/NgoihSOvI4T dv1ZprsQQ88WbIy7XuMKJcjJez/kRKKHq8KfMrXSEoG6un3T0nGmai65uJ8plvxvWBWQpO3RiUn NjG/3Sp77l1Gf4oTsNtBBMd9qeLTSOyMFd6M+B/RE94C+ayEMNfiChBj84w1Fl8jf+LfZ2tXFvV MynG+q79ylH9J92H/G/WhNEnDn6NOr631aN7/1T5oq2ttFbIiScwrlShjEeFYkATnaN9xR5ZN1L dPmm4I7E+x5mhcm94R8jgflPk5HHwCOwFxFRBtF/lotVC0XRlm3k3bF0pDaJoRMkbrKQaE4HyAT MxT3qKHkclq8Qb5PPWqU8zYRvW0lGtHg2SicHbR/N/5MxXV3J6cfCMMjxXA== 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: 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.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