From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384098; b=E1e0hVOKmfMNbLI28TxDJtQDA0hausFDwv0KKyGISV4IDhFiQgYr98FLf7ykb345YaEt jg/S80YzJw6Xtl1hV3h2mZHn8/r6DdknXlr82Sl6+N8gjFyyxuQhDAGkLZaCh4kk/o60Q 5JiFWxX5gUnHA4a8IueE0TNshgje9K+y5sSSLgQBmk3pgcSwXvN6WvBiL+DuVmVW1CIQd fSxnE8NVN3xm7pOd00aO1sLqKbb8ws1r+K9J1jb0EEM7MF7tpcIaRoZZEwWBoGdaOehQZ wOAMYEMO43aLpRyZkVI7zj0gGye5X0rI20wijdZ12uIGnj/cnAp9IOuNaiJnHH++YMg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384098; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=4klEQi7x6j6pnL1qhAcX6aAzFV9MkgTPnOcQ7CU2BWA=; b=dKGs/Wd2suQzUlcfKTBqgnrKlA4WM3bkw+zopYnwHEz0uKqo/6rbnT/aNm+arhCq3Uox cQ1jiCB5+gv7s6xylgdgigbci06s53UR+zaV8sJcsCu7HbtmBk5oQ6PpufZIIwDGwQToR p7+MgS/FUjk+EKasHegyFGtPamgFZLkp7qW0BhhJmsBtB7e8t2NPShyLHuWkr3g0RQqMo /C3BzGNvOpgs4zH7pON4E0RMz1zPyZEZaaB6Viic4v20Dy0QA02B2dDmV0hzVy/hics/X 5LAK05aZ8ZpkU+baBfe1USjw7V6ud05ZQx9KEoOWzjacKYEs6tdrU3x5vD4rnXkd0Vg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=h6X1mnDy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF03A606A322; Fri, 4 Dec 2026 11:34:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=h6X1mnDy Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2851E1F000CE; Fri, 4 Dec 2026 11:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384098; bh=4klEQi7x6j6pnL1qhAcX6aAzFV9MkgTPnOcQ7CU2BWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=h6X1mnDykGuF7JRx0MxA7vHoW6BIOuOb8B8lf8teJeLEAOUZfARAwu7PO8W6EwxqM efThGlvliBESJrkznDUkNtcuFtSVRabjAu1hl7jm8WxgeiiH6Cc941yWak2W/5kO25 b7ZEelqdHC+ZQAljFxIvF3pGs0w3QzWMudhWrmvs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chaosheng Qu , Steven Rostedt Subject: [PATCH 6.12 494/555] tracing/osnoise: Dont start a kthread in timerlat user-space mode Date: Fri, 4 Dec 2026 19:08:57 +0900 Message-ID: <20261204100627.841054133@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chaosheng Qu commit 5f855410554564ca05903979e6dab96e754d8773 upstream. In timerlat user-space mode (NO_OSNOISE_WORKLOAD) the workload is a user task reading timerlat_fd, so there is no per-CPU kernel thread to run. start_kthread() only checks for that in the osnoise branch: if (timerlat_enabled()) { snprintf(comm, 24, "timerlat/%d", cpu); main = timerlat_main; } else { /* if no workload, just return */ if (!test_bit(OSN_WORKLOAD, &osnoise_options)) { ... return 0; } ... } start_per_cpu_kthreads() guards against this mode itself, but osnoise_hotplug_workfn() calls start_kthread() directly. Bringing a CPU online in user-space mode therefore starts a timerlat/N thread and sets its bit in kthread_cpumask while OSN_WORKLOAD is clear. stop_kthread() uses that bit to decide what the recorded task is: if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask) && !WARN_ON(!test_bit(OSN_WORKLOAD, &osnoise_options))) { kthread_stop(kthread); } else if (!WARN_ON(test_bit(OSN_WORKLOAD, &osnoise_options))) { kill_pid(kthread->thread_pid, SIGKILL, 1); put_task_struct(kthread); } The bit is set but OSN_WORKLOAD is not, so the first WARN_ON() fires and the && short-circuits into the user-task branch. A running kernel thread is SIGKILLed and its task_struct is put without ever being stopped, so it keeps executing until it is freed underneath itself. Any write to osnoise/options reaches this: osnoise_options_write() stops the per-CPU threads before applying the new value, so stop_kthread() still sees OSN_WORKLOAD clear. Re-writing the value that is already set triggers it just as well as changing it. echo NO_OSNOISE_WORKLOAD > osnoise/options echo timerlat > current_tracer echo 0 > /sys/devices/system/cpu/cpu1/online echo 1 > /sys/devices/system/cpu/cpu1/online echo NO_OSNOISE_WORKLOAD > osnoise/options The offline/online pair is required, otherwise no kthread is recorded and no bit is set. Running this on 7.3-rc7 with KASAN gives a WARNING in stop_kthread() followed by a slab-use-after-free in update_se(); leaving out the hotplug step produces neither. Keep the check in start_kthread(), where the related hotplug bug was fixed in 0bb0a5c12ecf, instead of adding another copy to the callback. Cc: stable@vger.kernel.org Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface") Link: https://patch.msgid.link/20261014081034.12702-1-chaosheng.qu.linux@gmail.com Signed-off-by: Chaosheng Qu Signed-off-by: Steven Rostedt Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_osnoise.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -2018,6 +2018,14 @@ static int start_kthread(unsigned int cp return 0; if (timerlat_enabled()) { + /* + * In timerlat user-space mode the workload is the user task + * reading timerlat_fd, so there is no kernel thread to start. + * One started here would set its kthread_cpumask bit, which + * stop_kthread() reads as "osnoise workload kthread". + */ + if (!test_bit(OSN_WORKLOAD, &osnoise_options)) + return 0; snprintf(comm, 24, "timerlat/%d", cpu); main = timerlat_main; } else {