From patchwork Mon Jan 8 17:38:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13513747 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 8266E54BCF for ; Mon, 8 Jan 2024 17:38:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC31DC433C8; Mon, 8 Jan 2024 17:38:03 +0000 (UTC) Date: Mon, 8 Jan 2024 12:38:59 -0500 From: Steven Rostedt To: Linux Trace Devel Cc: Vincent Donnefort Subject: [PATCH v2] kbuffer: Update kbuf->next in kbuffer_refresh() Message-ID: <20240108123859.32db3407@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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). Fixes: 7a4d5b24 ("kbuffer: Add kbuffer_refresh() API") Reported-by: Vincent Donnefort Signed-off-by: Steven Rostedt (Google) --- Changes since v1: https://lore.kernel.org/linux-trace-devel/ZZfJQTOyl0dHiTU-@google.com/ - Use "next_event()" call and not just update_pointers() as if the next event is an extended timestamp or absolute timestamp, it is not to be returned to the user. The event that is attached to the timestamp is to be returned. The next_event() will iterate until it gets to the event, skipping over the time stamps. src/kbuffer-parse.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c index 691d53678f5f..48b578011a5a 100644 --- a/src/kbuffer-parse.c +++ b/src/kbuffer-parse.c @@ -180,6 +180,7 @@ static int calc_index(struct kbuffer *kbuf, void *ptr) return (unsigned long)ptr - (unsigned long)kbuf->data; } +static int next_event(struct kbuffer *kbuf); static int __next_event(struct kbuffer *kbuf); /* @@ -299,6 +300,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 +313,20 @@ 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 == kbuf->next) + next_event(kbuf); + return 0; }