From patchwork Thu Dec 7 02:37:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 17654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4515255vqy; Wed, 6 Dec 2023 18:38:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmrUkJd1ARYw5zRq9H9kyKm5FTl0irtAJwDF35ma56egk8GcbY6vhK5y64mn0SOQ7+Qc/I X-Received: by 2002:a17:90b:4b45:b0:286:b2ca:4bc3 with SMTP id mi5-20020a17090b4b4500b00286b2ca4bc3mr2056448pjb.32.1701916691433; Wed, 06 Dec 2023 18:38:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701916691; cv=none; d=google.com; s=arc-20160816; b=zHZdWlnTXsOtBoHgEaQCOMJZ0CNGWlDGN1epYd6FJ1Pz3UIX73PP9ultAe51Me+Ljq qMDYydHEBxH+Ik9+3sKiUwfKf3ZkIe0f9aiBhfWOfOHXeCM8tJVB+X9rNqXgRkfj+Uxw uBdjtub/IfJU2+B9qe007cY90AEFZAtOd//GEdJe3FbRIbwV5aj9r9B7yotIgp+dC0mr Nm/Pfo8TGw77/xl4H77fuMAB+Ksc684ZZGWs4lxogUs2aB21Ve/muNyo6bVJn8C87fbB SKxThUbp68S9oa+9xueeMnhHY291lt13RleE38vR5gOSkySbFcZWUgC995BZT7NGRtzt s8lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:user-agent:message-id; bh=LHC+RH/86a+89Z3yLdayYkIkqN0WGM4YVjlAcsA88Ro=; fh=mTYg3JJ8i2GBNLFt8qb4bgYwOyk0kmrOzICLbi6qJ1c=; b=DuyF/to5J0mZCHoFzcpjd7MyUvQgtkybapKEN9rI5NTJmzEb5iT+o9atY4z3igCaFW yQnx7oxydPJIYA3YxdE7dTBNR82VJznftkO/sz8qqlxXwXAqsaYbiFtpbOu+WLSj9cug qaeeZrtKP2FVARzDmGWvKivVnRLkfH04tVt+FTsADcDpNntRinn2VJq5oMtjUBkIuMFr /mX6ejPETjC7FxNp6TazJOkn00Sw+WS6kmcK1sGQgmGOLkB2Kn9N6k6gMkg0XSPWRxkW NNR0ND8kvp+fv+fwuFoxAOau72tmeeo2lsr/dAsW0erFvsewnG6yWlFaudky5mf9vUh+ JHig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id w13-20020a17090a8a0d00b00286c34f1dc6si239040pjn.162.2023.12.06.18.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 18:38:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 346658142D9E; Wed, 6 Dec 2023 18:38:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443054AbjLGChr (ORCPT + 99 others); Wed, 6 Dec 2023 21:37:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231196AbjLGChn (ORCPT ); Wed, 6 Dec 2023 21:37:43 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 801F2D4B for ; Wed, 6 Dec 2023 18:37:49 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1632BC433C8; Thu, 7 Dec 2023 02:37:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rB4HK-00000001aMD-2rIq; Wed, 06 Dec 2023 21:38:18 -0500 Message-ID: <20231207023752.712829638@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 06 Dec 2023 21:37:52 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-linus][PATCH 0/8] tracing: Updates for v6.7-rc4 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 06 Dec 2023 18:38:05 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784588996540916836 X-GMAIL-MSGID: 1784588996540916836 tracing fixes for v6.7-rc4: - Snapshot buffer issues 1. When instances started allowing latency tracers, it uses a snapshot buffer (another buffer that is not written to but swapped with the main buffer that is). The snapshot buffer needs to be the same size as the main buffer. But when the snapshot buffers were added to instances, the code to make the snapshot equal to the main buffer still was only doing it for the main buffer and not the instances. 2. Need to stop the current tracer when resizing the buffers. Otherwise there can be a race if the tracer decides to make a snapshot between resizing the main buffer and the snapshot buffer. 3. When a tracer is "stopped" in disables both the main buffer and the snapshot buffer. This needs to be done for instances and not only the main buffer, now that instances also have a snapshot buffer. - Buffered event for filtering issues When filtering is enabled, because events can be dropped often, it is quicker to copy the event into a temp buffer and write that into the main buffer if it is not filtered or just drop the event if it is, than to write the event into the ring buffer and then try to discard it. This temp buffer is allocated and needs special synchronization to do so. But there were some issues with that: 1. When disabling the filter and freeing the buffer, a call to all CPUs is required to stop each per_cpu usage. But the code called smp_call_function_many() which does not include the current CPU. If the task is migrated to another CPU when it enables the CPUs via smp_call_function_many(), it will not enable the one it is currently on and this causes issues later on. Use on_each_cpu_mask() instead, which includes the current CPU. 2. When the allocation of the buffered event fails, it can give a warning. But the buffered event is just an optimization (it's still OK to write to the ring buffer and free it). Do not WARN in this case. 3. The freeing of the buffer event requires synchronization. First a counter is decremented to zero so that no new uses of it will happen. Then it sets the buffered event to NULL, and finally it frees the buffered event. There's a synchronize_rcu() between the counter decrement and the setting the variable to NULL, but only a smp_wmb() between that and the freeing of the buffer. It is theoretically possible that a user missed seeing the decrement, but will use the buffer after it is free. Another synchronize_rcu() is needed in place of that smp_wmb(). - ring buffer timestamps on 32 bit machines The ring buffer timestamp on 32 bit machines has to break the 64 bit number into multiple values as cmpxchg is required on it, and a 64 bit cmpxchg on 32 bit architectures is very slow. The code use to just use two 32 bit values and make it a 60 bit timestamp where the other 4 bits were used as counters for synchronization. It later came known that the timestamp on 32 bit still need all 64 bits in some cases. So 3 words were created to handle the 64 bits. But issues arised with this: 1. The synchronization logic still only compared the counter with the first two, but not with the third number, so the synchronization could fail unknowingly. 2. A check on discard of an event could race if an event happened between the discard and updating one of the counters. The counter needs to be updated (forcing an absolute timestamp and not to use a delta) before the actual discard happens. git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git trace/urgent Head SHA1: f458a1453424e03462b5bb539673c9a3cddda480 Petr Pavlu (3): tracing: Fix incomplete locking when disabling buffered events tracing: Fix a warning when allocating buffered events fails tracing: Fix a possible race when disabling buffered events Steven Rostedt (Google) (5): tracing: Always update snapshot buffer size tracing: Stop current tracer when resizing buffer tracing: Disable snapshot buffer when stopping instance tracers ring-buffer: Force absolute timestamp on discard of event ring-buffer: Test last update in 32bit version of __rb_time_read() ---- kernel/trace/ring_buffer.c | 23 +++---- kernel/trace/trace.c | 158 +++++++++++++++++---------------------------- 2 files changed, 69 insertions(+), 112 deletions(-)