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=1796266955; b=WGllalP9amEMvV8DZLmEI2VusN21O+JnKWrLDlKSvM7tumzwWICRLVoqnPeVglsP7bJf 8VrKXD5k3nhFpxu7zRmIga7Bam1XFakRvt+0X7HJC2v8ezUREiROSNiFvxG/l3zFILCt3 8WT5HBj2ZTLCHVMwyvrze0GbE6/hFYGvuO/s52aUDmpiKXn1Ud2A8I/8EG3dp4OVRf6Hw Eu7IlXE91a0EBq7/ybCEorA1eEPN6sDuChJ9es0B1tra9jWZ3fU5l/WXTKxLbTbZW3Agv 7lVNaCJLZKt86Vd+RFF/PNhFlqhP6kCnFcOCeo6TM2OJlcY7KRctDZBwNkqEN/W2OHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796266955; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=YnJlJ0t0Fne4aWBNf9KJmituXBK50fCXv3szDxf87rs=; b=Hb2shNEs0sifKKFj/+p9EkVq6gFauj/66uFDxyiy+h4W/rQMmnfWhg2XpxTeo5r8NQmW hdK5CkzGXmFhLdFwbJn1ClQVJoZrSPkmhg6Utan/rqdeNSHTxlHZ0E32EoRYubjUeFKIi QSca/q1SMfNRrKYcYgCnoyC+JLn0+UdRCHKeFeaj6LrR9vBTW+SYGCRGsv2gnrEGPgMV4 HfHbhJ4uBYmfyAkrFZUbeS+doPRZxea6xf/yljXxhwT6wE7fU74nMd6lHF2KQdd3awydZ DsV5SIf/jc+KwgcJhv7VADiGvbDQIM/WG09Cb14uKOQKqALaTWZWJYlAj66kjeq0+Zg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jBg0l7ZK; 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 2DE9B606A322 for ; Thu, 3 Dec 2026 03:02:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jBg0l7ZK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 976FB1F000C1; Thu, 3 Dec 2026 03:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796266954; bh=YnJlJ0t0Fne4aWBNf9KJmituXBK50fCXv3szDxf87rs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jBg0l7ZK1EAjwzfXsTBcRGhztRdRwK932NwPIRIbuJkpPVPXseMYc5NxY3pbPqr9G zuYlRdEE+eFwj4p5//YpdnIoK0WfGICodLR3BZwoCNfCqS7kMLOT5HGYhhVlRxLAEJ 6yYMw7XkKWvC0kgghH730THumwg+pKRxaWcMA68ulcF6N8xGzk6tASR2c6SJ9KUY0i mq5XmqyCIU8hfDzmbkV8KVkU/KtErseKcCPHv9Afy1o3sIwXBHHN7AmqN6YyaO4Jae ht5+ZENGQbnNPcrccbBQbNhnsVTk+rKuPWc7xLPufa3a0Mbz29SAAh9rS2PG0+RUQC 1F2ZVACmHBuKA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] tracing: Make event_enable_count_probe() count atomic Reply-To: sashiko-reviews@lists.linux.dev To: "Jaewon Jung" Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: <20261203025249.2117813-1-jaewon8868@gmail.com> References: <20261203025249.2117813-1-jaewon8868@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 03:02:34 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] tracing: multiple count decrements per transition in event_enable_count_probe() - [Medium] tracing: non-NMI-safe atomic64_t used in event_enable_count_probe() -- commit a29411e32443080968e8c32bbea059c5a37f2e52 Author: Jaewon Jung tracing: Make event_enable_count_probe() count atomic This commit converts event_probe_data::count from unsigned long to atomic64_t and updates event_enable_count_probe() to decrement it with an atomic64_cmpxchg() loop. > diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c > index 0d4195b43208e..f17ed3b160c80 100644 > --- a/kernel/trace/trace_events.c > +++ b/kernel/trace/trace_events.c > @@ -4402,7 +4402,7 @@ EXPORT_SYMBOL_GPL(trace_put_event_file); > #ifdef CONFIG_DYNAMIC_FTRACE > struct event_probe_data { > struct trace_event_file *file; > - unsigned long count; > + atomic64_t count; > int ref; > bool enable; > }; [Severity: Medium] Can using atomic64_t for event_probe_data::count deadlock in NMI context on 32-bit architectures with CONFIG_GENERIC_ATOMIC64? On those platforms, generic_atomic64_read() and generic_atomic64_cmpxchg() take a hashed spinlock in atomic64_lock using local_irq_save(), which does not mask NMIs: current task (32-bit CONFIG_GENERIC_ATOMIC64) generic_atomic64_*() local_irq_save(flags) arch_spin_lock(lock) function_trace_probe_call() event_enable_count_probe() atomic64_read(&edata->count) arch_spin_lock(lock) <-- self-deadlock on same lock bucket Using a word-sized atomic_long_t (or long with READ_ONCE() and WRITE_ONCE() matching update_traceon_count() in kernel/trace/trace_functions.c) is lockless and NMI-safe on both 32-bit and 64-bit architectures, and also avoids the mid-block s64 declaration in event_enable_print() and the -1UL conversion in event_enable_func(). > @@ -4447,7 +4447,7 @@ event_enable_count_probe(unsigned long ip, unsigned= long parent_ip, > =20 > edata =3D *pdata; > =20 > - if (!edata->count) > + if (!atomic64_read(&edata->count)) > return; > =20 > /* Skip if the event is in a state we want to switch to */ > @@ -4455,8 +4455,16 @@ event_enable_count_probe(unsigned long ip, unsigne= d long parent_ip, > &edata->file->flags)) > return; > =20 > - if (edata->count !=3D -1) > - (edata->count)--; > + for (;;) { > + s64 count =3D atomic64_read(&edata->count); > + > + if (!count) > + return; > + if (count =3D=3D -1) > + break; > + if (atomic64_cmpxchg(&edata->count, count, count - 1) =3D=3D count) > + break; > + } > =20 > update_event_probe(edata); > } [Severity: Medium] Does this cmpxchg retry loop still decrement edata->count multiple times for a single enable/disable state transition when multiple CPUs hit the probed function concurrently? As described in 3cd715de2611 ("tracing: Add function probe triggers to enable/disable events"), count tracks how many times the probe switches the event state, not calls while the event is already in that state. Because test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &edata->file->flags) is checked before the loop and update_event_probe() only updates the bit after the loop, every CPU that passes test_bit() before the bit is updated retries atomic64_cmpxchg() until it also decrements edata->count: CPU0 CPU1 event_enable_count_probe() event_enable_count_probe() test_bit(..., &edata->file->flags) test_bit(..., &edata->file->flags) atomic64_cmpxchg(&edata->count, 2, 1) =3D=3D 2 atomic64_cmpxchg(&edata->count, 2, 1) !=3D 2 (retr= ies) atomic64_cmpxchg(&edata->count, 1, 0) =3D=3D 1 <-- 2nd decrement for same switch update_event_probe(edata) update_event_probe(edata) Notice how the sibling probe counter in update_traceon_count() avoids this by reading old_count once before checking the state, updating the state, and storing old_count - 1 (or using a single non-retrying cmpxchg): kernel/trace/trace_functions.c:update_traceon_count() { ... old_count =3D *count; if (old_count <=3D 0) return; /* Make sure we see count before checking tracing state */ smp_rmb(); if (on =3D=3D !!tracer_tracing_is_on(tr)) return; if (on) tracer_tracing_on(tr); else tracer_tracing_off(tr); /* Make sure tracing state is visible before updating count */ smp_wmb(); *count =3D old_count - 1; } --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203025249.2117= 813-1-jaewon8868@gmail.com?part=3D1