From patchwork Thu Dec 7 02:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 174885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4515360vqy; Wed, 6 Dec 2023 18:38:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGni0Ogh30BVwx+1AtQyUx3AZihnH7dTvLyC+m0vSR6YCshF2Cl6+GHzMX6+p43otBy/276 X-Received: by 2002:a05:6358:782:b0:170:17eb:2fab with SMTP id n2-20020a056358078200b0017017eb2fabmr1554703rwj.36.1701916718559; Wed, 06 Dec 2023 18:38:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701916718; cv=none; d=google.com; s=arc-20160816; b=CP5WxvMhsS5iHkp76X0XR8VoIdsPO6gFVUr/kpctskJI34Et5xQGIHJlG9shGH2MRW 8bGoLrS/z26GS3fWE9yKTPNzhGg0xjsfTYlOkabgTqk9K73lgSbdFGEIDrrkE64x+KGQ bvhdSuDXqouO5EOL8cPBUCVZSuu/tSmC2nKRoOMx2CyZu2A8SpE7fFkPXYsLYN37eXvS UVJKLsszpsVMvUnga/iz4nx8g7ygjfJYgUAyXbZ2mhL2tTf5O3gS+WUf/Agvoz2mmIYO i4dRbC0ND+yk4gxwSyAsyW+ACAi4eSWNEjvfEBU8IcUDo7mX1JsvUYnRt62TMWARoWuq +6KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=JJwxI75ezX9ei5LZt8tRb50LUhtpIyrSNzy4dlq6nVU=; fh=hu/11vjhAVGN2soHkDrejjtKeeIeHno3fFH7CvZIC0Y=; b=ioV2rMonInPiqjLLSg5hjwp2rwOnqkeI31vT39NnAY9wYmUayW2mGbogN5y/CRsOJm cdA5jykokTA9aqQX4kwcTy/f+PnHM9AWcvJrAXQwjyt3GrVnaLTXrxsAKMJJp1mM5cJx QKVINca8z6sfC4i8B2Nalk/eoo3vJb+Ix+Lt5CSDAwTY17t/whIgSkN3n0IGDF5zzJ4p uSpWSM3nbBiIzQ0qT7Ty2suopEHEJ4iWlso0hBtrMtPdZJ3Rypof3AvPCiK8Wz5Z9hcm tjNRnvFJuhuEz+v3NRVPL+Ejpd6ZWOmVMTQTp6t9FORI81dBH9wiPOmB8VNYx77s4m3h Ld9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id o4-20020a056a0015c400b006c4b01d5f85si378429pfu.16.2023.12.06.18.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 18:38:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 27615801B32F; Wed, 6 Dec 2023 18:38:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443025AbjLGCiG (ORCPT + 99 others); Wed, 6 Dec 2023 21:38:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443058AbjLGChp (ORCPT ); Wed, 6 Dec 2023 21:37:45 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8572AD51 for ; Wed, 6 Dec 2023 18:37:51 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ACC2C433C9; Thu, 7 Dec 2023 02:37:51 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rB4HN-00000001aQB-03PE; Wed, 06 Dec 2023 21:38:21 -0500 Message-ID: <20231207023820.797727180@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 06 Dec 2023 21:38:00 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org Subject: [for-linus][PATCH 8/8] ring-buffer: Test last update in 32bit version of __rb_time_read() References: <20231207023752.712829638@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 18:38:30 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784589025011947378 X-GMAIL-MSGID: 1784589025011947378 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. Link: https://lore.kernel.org/linux-trace-kernel/20231206100050.3100b7bb@gandalf.local.home Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers 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 *ret, unsigned long *cnt) *cnt = rb_time_cnt(top); - /* If top and bottom counts don't match, this interrupted a write */ - if (*cnt != rb_time_cnt(bottom)) + /* If top and msb counts don't match, this interrupted a write */ + if (*cnt != rb_time_cnt(msb)) return false; /* The shift to msb will lose its cnt bits */