From patchwork Fri Jan 5 19:37:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13512516 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDA4B364AB for ; Fri, 5 Jan 2024 19:39:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBBC9C433C8; Fri, 5 Jan 2024 19:39:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rLq3E-000000013uv-2W8j; Fri, 05 Jan 2024 14:40:16 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: Vincent Donnefort , "Steven Rostedt (Google)" Subject: [PATCH 1/3] libtraceevent Documentation: Fix tep_kbuffer() prototype Date: Fri, 5 Jan 2024 14:37:42 -0500 Message-ID: <20240105194015.253165-2-rostedt@goodmis.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240105194015.253165-1-rostedt@goodmis.org> References: <20240105194015.253165-1-rostedt@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Steven Rostedt (Google)" The tep_kbuffer() prototype was missing from its man page and was broken in the libtraceevent top man page. Link: https://lore.kernel.org/linux-trace-devel/20231229121450.7a19ccaa@gandalf.local.home Fixes: 6e637fba207d4 ("libtraceevent: Rename kbuffer_create() to tep_kbuffer()") Signed-off-by: Steven Rostedt (Google) --- Documentation/libtraceevent-handle.txt | 1 + Documentation/libtraceevent.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/libtraceevent-handle.txt b/Documentation/libtraceevent-handle.txt index 64528ebc3433..fd55712db705 100644 --- a/Documentation/libtraceevent-handle.txt +++ b/Documentation/libtraceevent-handle.txt @@ -17,6 +17,7 @@ void *tep_free*(struct tep_handle pass:[*]_tep_); void *tep_ref*(struct tep_handle pass:[*]_tep_); void *tep_unref*(struct tep_handle pass:[*]_tep_); int *tep_get_ref*(struct tep_handle pass:[*]_tep_); +struct kbuffer pass:[*]*tep_kbuffer*(struct tep_handle pass:[*]_tep_); -- DESCRIPTION diff --git a/Documentation/libtraceevent.txt b/Documentation/libtraceevent.txt index 26e3ad2523db..9e7777283c52 100644 --- a/Documentation/libtraceevent.txt +++ b/Documentation/libtraceevent.txt @@ -33,7 +33,7 @@ Management of tep handler data structure and access of its members: int *tep_get_header_timestamp_size*(struct tep_handle pass:[*]_tep_); bool *tep_is_old_format*(struct tep_handle pass:[*]_tep_); int *tep_strerror*(struct tep_handle pass:[*]_tep_, enum tep_errno _errnum_, char pass:[*]_buf_, size_t _buflen_); - struct kbuffer pass:[*]*tep_kbuffer*(struct tep_handle pass:[*]:_tep_); + struct kbuffer pass:[*]*tep_kbuffer*(struct tep_handle pass:[*]_tep_); Register / unregister APIs: int *tep_register_function*(struct tep_handle pass:[*]_tep_, char pass:[*]_name_, unsigned long long _addr_, char pass:[*]_mod_); From patchwork Fri Jan 5 19:37:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13512515 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9828364A1 for ; Fri, 5 Jan 2024 19:39:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF712C433CA; Fri, 5 Jan 2024 19:39:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rLq3E-000000013uy-2d3E; Fri, 05 Jan 2024 14:40:16 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: Vincent Donnefort , "Steven Rostedt (Google)" Subject: [PATCH 2/3] kbuffer: Add event if the buffer just fits in kbuffer_read_buffer() Date: Fri, 5 Jan 2024 14:37:43 -0500 Message-ID: <20240105194015.253165-3-rostedt@goodmis.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240105194015.253165-1-rostedt@goodmis.org> References: <20240105194015.253165-1-rostedt@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Steven Rostedt (Google)" If the buffer passed in is exactly the size needed to add an event, it will not because it checks with: while (len > kbuf->next - save_curr) { Instead of while (len >= kbuf->next - save_curr) { Fixes: 05821189 ("kbuffer: Add kbuffer_read_buffer()") Signed-off-by: Steven Rostedt (Google) --- src/kbuffer-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c index d43fe5d972fd..4801d432c58c 100644 --- a/src/kbuffer-parse.c +++ b/src/kbuffer-parse.c @@ -995,7 +995,7 @@ int kbuffer_read_buffer(struct kbuffer *kbuf, void *buffer, int len) /* Due to timestamps, we must save the current next to use */ last_next = kbuf->next; - while (len > kbuf->next - save_curr) { + while (len >= kbuf->next - save_curr) { last_next = kbuf->next; if (!kbuffer_next_event(kbuf, &ts)) break; From patchwork Fri Jan 5 19:37:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13512517 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FCCA3608E for ; Fri, 5 Jan 2024 19:39:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6ACAC433C7; Fri, 5 Jan 2024 19:39:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rLq3E-000000013v1-2kL9; Fri, 05 Jan 2024 14:40:16 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: Vincent Donnefort , "Steven Rostedt (Google)" Subject: [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() Date: Fri, 5 Jan 2024 14:37:44 -0500 Message-ID: <20240105194015.253165-4-rostedt@goodmis.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240105194015.253165-1-rostedt@goodmis.org> References: <20240105194015.253165-1-rostedt@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Steven Rostedt (Google)" If the kbuffer was read to completion, the kbuf->curr would equal both the size and kbuf->next. The kbuffer_refresh() is to update the kbuf if more data was added to the buffer. But if curr is at the end, the next pointer was not updated, which is incorrect. The next pointer needs to be moved to the end of the newly written event. Update the pointers in kbuffer_refresh() just as if it was loaded new (but still keeping curr at the correct location). Link: https://lore.kernel.org/linux-trace-devel/ZZfJQTOyl0dHiTU-@google.com/ Reported-by: Vincent Donnefort Fixes: 7a4d5b24 ("kbuffer: Add kbuffer_refresh() API") Signed-off-by: Steven Rostedt (Google) --- src/kbuffer-parse.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c index 4801d432c58c..1e1d168b534c 100644 --- a/src/kbuffer-parse.c +++ b/src/kbuffer-parse.c @@ -299,6 +299,9 @@ void kbuffer_free(struct kbuffer *kbuf) free(kbuf); } +static unsigned int old_update_pointers(struct kbuffer *kbuf); +static unsigned int update_pointers(struct kbuffer *kbuf); + /** * kbuffer_refresh - update the meta data from the subbuffer * @kbuf; The kbuffer to update @@ -309,13 +312,24 @@ void kbuffer_free(struct kbuffer *kbuf) int kbuffer_refresh(struct kbuffer *kbuf) { unsigned long long flags; + unsigned int old_size; if (!kbuf || !kbuf->subbuffer) return -1; + old_size = kbuf->size; + flags = read_long(kbuf, kbuf->subbuffer + 8); kbuf->size = (unsigned int)flags & COMMIT_MASK; + /* Update next to be the next element */ + if (kbuf->size != old_size && kbuf->curr == old_size) { + if (kbuf->flags & KBUFFER_FL_OLD_FORMAT) + old_update_pointers(kbuf); + else + update_pointers(kbuf); + } + return 0; }