From mboxrd@z Thu Jan 1 00:00:00 1970 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 BB67D39B964 for ; Mon, 30 Mar 2026 21:07:40 +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=1774904860; cv=none; b=PX4RdXan21ec5IIivMidytTgozZ1F39CqhzTEKo9F/juiff995ObERXu36zE8n8tppRW8AO9fxwb1mcx218XcVZmLdIHGvbLpzZQ6QQLbDMpFKegFV+/fx3W7FoWpyN4sf8vjmex+BhoiBzxrHjh4QVIPqiOjdliURuCifzuhco= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774904860; c=relaxed/simple; bh=s/OCvbvYWO04qQ9nXf19LG8CveRke/ugB6HZYecF71U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YCVRdJldLHdFghkZEpWRNG76h2QKxvl4LTlD6CdNIRdiYOWDYIvx13yW1uWWsTY0tIPIZuXHcld9AdhWg7epcgAV1iUN7+jQIMVkGUvJhdXTbkAJvIACY4206rJIP2ybPWtI7B3yiJb7a3Ku4LrqIpPMkwuts8BJIbViqan/a5U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f7mpSTkc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f7mpSTkc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C69EC4CEF7; Mon, 30 Mar 2026 21:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774904860; bh=s/OCvbvYWO04qQ9nXf19LG8CveRke/ugB6HZYecF71U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f7mpSTkcmVL8LqVy3Akb7vQCwZxD4QPkZAHwMGDmwiaQHos0CP6XQnOk9nXNmp3M1 VE1d7ugUuEK+t0uhdBi24dw7LqNRyov2YnBAj2lWNOgHLBxEFDAm6e3mS508/Xsdh3 Zf8+w7begAVNX2nbWw6KdYE9i35mAsdMaVm69Vh6QB3J65h2xEEeT5MZAbgZljMCBA QT6fDzjpxgUSJ1Y86Vm2DyVRahf67CrpdL61P5QGcC9hQpdcj2nZ6b6u9ynpaNnIqu cHePsC3TsAljCGkeonfXfAYmeNN4p4Phe6eTQmBnnMaRSJ6z0jN6SqVisjM8Fay4+7 9B+E9XqaVk+Qw== From: Sasha Levin To: stable@vger.kernel.org Cc: Luo Haiyang , mathieu.desnoyers@efficios.com, zhang.run@zte.com.cn, yang.tao172@zte.com.cn, ran.xiaokai@zte.com.cn, "Masami Hiramatsu (Google)" , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.15.y] tracing: Fix potential deadlock in cpu hotplug with osnoise Date: Mon, 30 Mar 2026 17:07:37 -0400 Message-ID: <20260330210737.1213194-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026032954-repossess-ascension-613b@gregkh> References: <2026032954-repossess-ascension-613b@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luo Haiyang [ Upstream commit 1f9885732248d22f788e4992c739a98c88ab8a55 ] The following sequence may leads deadlock in cpu hotplug: task1 task2 task3 ----- ----- ----- mutex_lock(&interface_lock) [CPU GOING OFFLINE] cpus_write_lock(); osnoise_cpu_die(); kthread_stop(task3); wait_for_completion(); osnoise_sleep(); mutex_lock(&interface_lock); cpus_read_lock(); [DEAD LOCK] Fix by swap the order of cpus_read_lock() and mutex_lock(&interface_lock). Cc: stable@vger.kernel.org Cc: Cc: Cc: Cc: Fixes: bce29ac9ce0bb ("trace: Add osnoise tracer") Link: https://patch.msgid.link/20260326141953414bVSj33dAYktqp9Oiyizq8@zte.com.cn Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Luo Haiyang Signed-off-by: Steven Rostedt (Google) [ adapted guard() macros to lock/unlock calls ] Signed-off-by: Sasha Levin --- kernel/trace/trace_osnoise.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 5959b1d4ee459..66061e77cc514 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -1620,8 +1620,8 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy) if (!osnoise_busy) goto out_unlock_trace; - mutex_lock(&interface_lock); cpus_read_lock(); + mutex_lock(&interface_lock); if (!cpu_online(cpu)) goto out_unlock; @@ -1634,8 +1634,8 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy) start_kthread(cpu); out_unlock: - cpus_read_unlock(); mutex_unlock(&interface_lock); + cpus_read_unlock(); out_unlock_trace: mutex_unlock(&trace_types_lock); } @@ -1772,16 +1772,16 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count, if (running) osnoise_tracer_stop(tr); - mutex_lock(&interface_lock); /* * osnoise_cpumask is read by CPU hotplug operations. */ cpus_read_lock(); + mutex_lock(&interface_lock); cpumask_copy(&osnoise_cpumask, osnoise_cpumask_new); - cpus_read_unlock(); mutex_unlock(&interface_lock); + cpus_read_unlock(); if (running) osnoise_tracer_start(tr); -- 2.53.0