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=1796274976; b=TrmkmNAps1mqyRoadZP9hkHrDC7BTjnL/bpEFLEQwEC6KdhnakYUS7ZDj168MPmn4NJX HHIAdCrSpwGgYOEZMtwLXPap/6/+p03ZxEIiUKazXUNmI1q05xBeBtuF56FzG/2VTZ+oX 7n1eIrajqUUpoom74M9lJ9zFCgY9QmxWWyGzhiDQogdu7rLN9yDqiMaf7wIiGiZGwetSG i2VavvokKbOy2dqwIAME2Hm77CgSjyRs1IxFXkZ6rA/DSMtudCDdwYhcHBWrpGIst9zfG ThFNLrhBtb7ie60aLQhtsUfkkUEpTWvyIq9B5H+RqZesSaG0P8YpiC2OpK8PkhBtkgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796274976; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=JmexonqoEnl7pSu85fLSp1FbZp+4F6HRaTo3WY9RCSQ=; b=jo8QAejuGg0AaHl7YJsc3LvLGsCa+S1ifrL8sW2uxSmXAgDadQNGVL2Sfd/C/toMzCN2 4Ttu+gFiqwOChkZcMBEULlZ56KKpzztxma6ZbNbnO4SBnERzlEVVFuoa/XgLyTEBjyN0e Xj+FXDg7MmjceCvxsPLtR//wZOHd2S8HGFHf7V+iZSLmgiVUHywLmtir5ohwgLvbjBFWv nGj0hQd0AP0/Bn5NajYj7ax9sHhTJdFFjiYEmwcJOfELEtXhjUz4cc8O38IoHsxJE3fgk 4+fZicOEugDTONwP0rDwCtEKkM84udsgcHx1zuqCehf10fmNNFEI9tn8UzOHNqZkGxg== 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=duPBTJtJ; 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 D1602606A322 for ; Thu, 3 Dec 2026 05:16:16 +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=duPBTJtJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47D091F00893; Thu, 3 Dec 2026 05:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796274976; bh=JmexonqoEnl7pSu85fLSp1FbZp+4F6HRaTo3WY9RCSQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=duPBTJtJQ6+/1uk83THWvTwxMRm65OSdL2LlMLPXkUEwPKekmix4BO9rA2wRZkjE5 5e0uBfBhYEguyPM+F69BiDoM3Mh48I3qRc8tFpNCAZzcfGJkHLVd/DnP73jPBQTB8N KYCGDGr+393WpOwkjeT+dFCWtHTM4DIlYfJ17D2WoFhhw5rVhKdNoO1y2AhIwqratu sxgFV1At/K/HVXE4yMMfHEJQLOZx6jZrncxFTT/6GdgPgk0AMcnPAxb+1dFJeiYf2f u+5rS7qhFZiymWpOMhtZDY+34gdTP876MUq8rAgNAMIgjH2s1ai1Skcqd13DDJGTkW IIJGyFmwyM8mQ== 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: <20261203045851.2243395-1-jaewon8868@gmail.com> References: <20261203025249.2117813-1-jaewon8868@gmail.com> <20261203045851.2243395-1-jaewon8868@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 05:16:15 +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 3 potential issues to consider: - [Medium] tracing: unchecked cmpxchg loses decrements in event_enable_count_probe() - [Low] tracing: redundant smp_wmb() before atomic_long_cmpxchg() in probe callback - [Low] tracing: commit message omits barrier and reordering rationale -- commit 41e0885247841d0dfe5e2b4d512d00bff70bfd6e Author: Jaewon Jung > tracing: Make event_enable_count_probe() count atomic > > Concurrent callbacks race on the plain count read and decrement. This can > lose updates or turn 0 into -1 (unlimited). Use atomic_long_t and cmpxchg > for the decrement. > > Fixes: 3cd715de2611 ("tracing: Add function probe triggers to enable/disa= ble events") > Signed-off-by: Jaewon Jung [Severity: Low] Could the commit message also explain why update_event_probe() is moved ahead of the count decrement, why the memory barriers are added, and why atomic_long_cmpxchg() ignores failure? Right now it only mentions making count atomic and using cmpxchg, leaving the ordering changes and their rationale undocumented. > diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c > index 0d4195b43208e..72db3921665b1 100644 > --- a/kernel/trace/trace_events.c > +++ b/kernel/trace/trace_events.c [ ... ] > @@ -4447,18 +4447,27 @@ event_enable_count_probe(unsigned long ip, unsign= ed long parent_ip, > =20 > edata =3D *pdata; > =20 > - if (!edata->count) > + long count =3D atomic_long_read(&edata->count); > + > + if (!count) > return; > =20 > + /* Make sure we see count before checking event state */ > + smp_rmb(); > + > /* Skip if the event is in a state we want to switch to */ > if (edata->enable =3D=3D !test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, > &edata->file->flags)) > return; > =20 > - if (edata->count !=3D -1) > - (edata->count)--; > - > update_event_probe(edata); > + > + if (count !=3D -1) { > + /* Make sure event state is visible before updating count */ > + smp_wmb(); [Severity: Low] Is this smp_wmb() redundant before atomic_long_cmpxchg()? Value-returning atomic RMW operations already imply full memory ordering on success, and a failed atomic_long_cmpxchg() performs no write before returning. On weakly ordered architectures such as arm64, this emits back-to-back barriers (dmb ishst before casal). Dropping smp_wmb(), or pairing atomic_long_read_acquire() with atomic_long_cmpxchg_release(), avoids the duplicate barrier. > + > + atomic_long_cmpxchg(&edata->count, count, count - 1); > + } [Severity: Medium] Can discarding the return value of atomic_long_cmpxchg() lose count decrements or let the probe fire after count reaches zero? Suppose edata->enable is true, edata->count is 2, and a paired disable_event probe or tracefs write toggles the event back off between two concurrent callbacks: CPU0 CPU1 CPU2 event_enable_count_probe() read count // 2 test_bit() // disabled update_event_probe() disable event event_enable_count_probe() read count // 2 test_bit() // disabled update_event_probe() cmpxchg(2 -> 1) // ok cmpxchg(2 -> 1) // fails, ignored <-- decrement lost Both CPUs performed an enable transition, but edata->count remains 1 instead of 0, allowing a third enable. With an initial count of 1, the same interleaving lets CPU0 call update_event_probe() and re-enable the event after edata->count has already reached 0. Since EVENT_FILE_FL_SOFT_DISABLED_BIT is a single bit, using test_and_clear_bit() / test_and_set_bit() to claim the state transition and retrying the count decrement on cmpxchg failure would keep the count accurate. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203045851.2243= 395-1-jaewon8868@gmail.com?part=3D1