From nobody Thu Dec 18 01:01:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C3C4C10DC3 for ; Mon, 11 Dec 2023 16:59:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344270AbjLKQ7G (ORCPT ); Mon, 11 Dec 2023 11:59:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbjLKQ7E (ORCPT ); Mon, 11 Dec 2023 11:59:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8EF18E for ; Mon, 11 Dec 2023 08:59:10 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0FE0C433C7; Mon, 11 Dec 2023 16:59:09 +0000 (UTC) Date: Mon, 11 Dec 2023 11:59:49 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [PATCH] ring-buffer: Never use absolute timestamp for start event Message-ID: <20231211115949.4692e429@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" On 32bit machines, the 64 bit timestamps are broken up into 32 bit words to keep from using local64_cmpxchg(), as that is very expensive on 32 bit architectures. On 32 bit architectures, reading these timestamps can happen in a middle of an update. In this case, the read returns "false", telling the caller that the timestamp is in the middle of an update, and it needs to assume it is corrupted. The code then accommodates this. When first reserving space on the ring buffer, a "before_stamp" and "write_stamp" are read. If they do not match, or if either is in the process of being updated (false was returned from the read), an absolute timestamp is added and the delta is not used, as that requires reading theses timestamps without being corrupted. The one case that this does not matter is if the event is the first event on the sub-buffer, in which case, the event uses the sub-buffer's timestamp and doesn't need the other stamps for calculating them. After some work to consolidate the code, if the before or write stamps are in the process of updating, an absolute timestamp will be added regardless if the event is the first event on the sub-buffer. This is wrong as it should not care about the success of these reads if it is the first event on the sub-buffer. Fix up the parenthesis so that even if the timestamps are corrupted, if the event is the first event on the sub-buffer (w =3D=3D 0) it still does n= ot force an absolute timestamp. Cc: stable@vger.kernel.org Fixes: 58fbc3c63275c ("ring-buffer: Consolidate add_timestamp to remove som= e branches") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 02bc9986fe0d..bc70cb9bbdb7 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3584,7 +3584,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buf= fer, * absolute timestamp. * Don't bother if this is the start of a new page (w =3D=3D 0). */ - if (unlikely(!a_ok || !b_ok || (info->before !=3D info->after && w))) { + if (unlikely((!a_ok || !b_ok || info->before !=3D info->after) && w)) { info->add_timestamp |=3D RB_ADD_STAMP_FORCE | RB_ADD_STAMP_EXTEND; info->length +=3D RB_LEN_TIME_EXTEND; } else { --=20 2.42.0