From nobody Thu Nov 28 06:52:30 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B16C02139C8; Fri, 4 Oct 2024 13:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728050187; cv=none; b=fxhNu1IhYzk9U6sIV1D9SJtv4ckg943Zy+C0vLHhZaV1URXGdNuZPgAhGJCW9J3rp7hryyEGeJ6YrTUgGNm/5yCkFywtXNSWcpE7vKeywdogUJCu7xcc7DokY20fE9lGkT8yam1vyEU9mmFezkOqZ6eZE4uK56WNvvLZ9kXfulw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728050187; c=relaxed/simple; bh=k8cXzyqbg2s7qf7ZrUuCUbyXUbR4GVpJT/q3XIstq7o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=IYb+jgtXxee+Ht2sMm6Y+rA9kvClxk5aFIh5Rk9MszB2ZUrPQqOh/6U39zgUaivsj5lOhbDdoL2afcLjpie2raqvdjSmuWG9RtbacwxNdhLOdtiSpZR/LxG7nDuzSA/tHeeRuuvVc8yq1Oq+pO3i++av4XJACnaO7T5PVIZL14Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8632DC4CECF; Fri, 4 Oct 2024 13:56:27 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1swio7-00000005CA2-3vqH; Fri, 04 Oct 2024 09:57:23 -0400 Message-ID: <20241004135723.800438615@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 04 Oct 2024 09:57:00 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Wei Li Subject: [for-linus][PATCH 5/8] tracing/timerlat: Fix duplicated kthread creation due to CPU online/offline References: <20241004135655.993267242@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wei Li osnoise_hotplug_workfn() is the asynchronous online callback for "trace/osnoise:online". It may be congested when a CPU goes online and offline repeatedly and is invoked for multiple times after a certain online. This will lead to kthread leak and timer corruption. Add a check in start_kthread() to prevent this situation. Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20240924094515.3561410-2-liwei391@huawei.com Fixes: c8895e271f79 ("trace/osnoise: Support hotplug operations") Signed-off-by: Wei Li Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_osnoise.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 1439064f65d6..d1a539913a5f 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -2007,6 +2007,10 @@ static int start_kthread(unsigned int cpu) void *main =3D osnoise_main; char comm[24]; =20 + /* Do not start a new thread if it is already running */ + if (per_cpu(per_cpu_osnoise_var, cpu).kthread) + return 0; + if (timerlat_enabled()) { snprintf(comm, 24, "timerlat/%d", cpu); main =3D timerlat_main; @@ -2061,11 +2065,10 @@ static int start_per_cpu_kthreads(void) if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask)) { struct task_struct *kthread; =20 - kthread =3D per_cpu(per_cpu_osnoise_var, cpu).kthread; + kthread =3D xchg_relaxed(&(per_cpu(per_cpu_osnoise_var, cpu).kthread), = NULL); if (!WARN_ON(!kthread)) kthread_stop(kthread); } - per_cpu(per_cpu_osnoise_var, cpu).kthread =3D NULL; } =20 for_each_cpu(cpu, current_mask) { --=20 2.45.2