From nobody Sun Dec 28 17:30:29 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 E2006C4167B for ; Wed, 6 Dec 2023 15:00:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442195AbjLFPAV (ORCPT ); Wed, 6 Dec 2023 10:00:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378993AbjLFPAS (ORCPT ); Wed, 6 Dec 2023 10:00:18 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59B83B5 for ; Wed, 6 Dec 2023 07:00:24 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FCF0C433C7; Wed, 6 Dec 2023 15:00:23 +0000 (UTC) Date: Wed, 6 Dec 2023 10:00:50 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [PATCH] ring-buffer: Test last update in 32bit version of __rb_time_read() Message-ID: <20231206100050.3100b7bb@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)" Since 64 bit cmpxchg() is very expensive on 32bit architectures, the timestamp used by the ring buffer does some interesting tricks to be able to still have an atomic 64 bit number. It originally just used 60 bits and broke it up into two 32 bit words where the extra 2 bits were used for synchronization. But this was not enough for all use cases, and all 64 bits were required. The 32bit version of the ring buffer timestamp was then broken up into 3 32bit words using the same counter trick. But one update was not done. The check to see if the read operation was done without interruption only checked the first two words and not last one (like it had before this update). Fix it by making sure all three updates happen without interruption by comparing the initial counter with the last updated counter. Cc: stable@vger.kernel.org Fixes: f03f2abce4f39 ("ring-buffer: Have 32 bit time stamps use all 64 bits= ") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index a6da2d765c78..8d2a4f00eca9 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -644,8 +644,8 @@ static inline bool __rb_time_read(rb_time_t *t, u64 *re= t, unsigned long *cnt) =20 *cnt =3D rb_time_cnt(top); =20 - /* If top and bottom counts don't match, this interrupted a write */ - if (*cnt !=3D rb_time_cnt(bottom)) + /* If top and msb counts don't match, this interrupted a write */ + if (*cnt !=3D rb_time_cnt(msb)) return false; =20 /* The shift to msb will lose its cnt bits */ --=20 2.42.0