* [PATCH 0/3] kbuffer: Some minor fixes
@ 2024-01-05 19:37 Steven Rostedt
2024-01-05 19:37 ` [PATCH 1/3] libtraceevent Documentation: Fix tep_kbuffer() prototype Steven Rostedt
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Steven Rostedt @ 2024-01-05 19:37 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Vincent Donnefort, Steven Rostedt (Google)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
The kbuffer update to work with libtracefs mmapping code had a few bugs.
1) The man page was missing its prototype for tep_kbuffer()
2) A buffer passed in to kbuffer_read_buffer() that was just big enough to
hold the events, was not completely filled.
3) kbuffer_refresh() left the current event zero size, even if new data was
added after it, if the last read was at the end of the page.
Steven Rostedt (Google) (3):
libtraceevent Documentation: Fix tep_kbuffer() prototype
kbuffer: Add event if the buffer just fits in kbuffer_read_buffer()
kbuffer: Update kbuf->next in kbuffer_refresh()
Documentation/libtraceevent-handle.txt | 1 +
Documentation/libtraceevent.txt | 2 +-
src/kbuffer-parse.c | 16 +++++++++++++++-
3 files changed, 17 insertions(+), 2 deletions(-)
--
2.42.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/3] libtraceevent Documentation: Fix tep_kbuffer() prototype 2024-01-05 19:37 [PATCH 0/3] kbuffer: Some minor fixes Steven Rostedt @ 2024-01-05 19:37 ` Steven Rostedt 2024-01-05 19:37 ` [PATCH 2/3] kbuffer: Add event if the buffer just fits in kbuffer_read_buffer() Steven Rostedt 2024-01-05 19:37 ` [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() Steven Rostedt 2 siblings, 0 replies; 8+ messages in thread From: Steven Rostedt @ 2024-01-05 19:37 UTC (permalink / raw) To: linux-trace-devel; +Cc: Vincent Donnefort, Steven Rostedt (Google) From: "Steven Rostedt (Google)" <rostedt@goodmis.org> 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) <rostedt@goodmis.org> --- 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_); -- 2.42.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] kbuffer: Add event if the buffer just fits in kbuffer_read_buffer() 2024-01-05 19:37 [PATCH 0/3] kbuffer: Some minor fixes Steven Rostedt 2024-01-05 19:37 ` [PATCH 1/3] libtraceevent Documentation: Fix tep_kbuffer() prototype Steven Rostedt @ 2024-01-05 19:37 ` Steven Rostedt 2024-01-05 19:37 ` [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() Steven Rostedt 2 siblings, 0 replies; 8+ messages in thread From: Steven Rostedt @ 2024-01-05 19:37 UTC (permalink / raw) To: linux-trace-devel; +Cc: Vincent Donnefort, Steven Rostedt (Google) From: "Steven Rostedt (Google)" <rostedt@goodmis.org> 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) <rostedt@goodmis.org> --- 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; -- 2.42.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() 2024-01-05 19:37 [PATCH 0/3] kbuffer: Some minor fixes Steven Rostedt 2024-01-05 19:37 ` [PATCH 1/3] libtraceevent Documentation: Fix tep_kbuffer() prototype Steven Rostedt 2024-01-05 19:37 ` [PATCH 2/3] kbuffer: Add event if the buffer just fits in kbuffer_read_buffer() Steven Rostedt @ 2024-01-05 19:37 ` Steven Rostedt 2024-01-05 21:01 ` Vincent Donnefort 2 siblings, 1 reply; 8+ messages in thread From: Steven Rostedt @ 2024-01-05 19:37 UTC (permalink / raw) To: linux-trace-devel; +Cc: Vincent Donnefort, Steven Rostedt (Google) From: "Steven Rostedt (Google)" <rostedt@goodmis.org> 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 <vdonnefort@google.com> Fixes: 7a4d5b24 ("kbuffer: Add kbuffer_refresh() API") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> --- 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; } -- 2.42.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() 2024-01-05 19:37 ` [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() Steven Rostedt @ 2024-01-05 21:01 ` Vincent Donnefort 2024-01-08 11:11 ` Vincent Donnefort 0 siblings, 1 reply; 8+ messages in thread From: Vincent Donnefort @ 2024-01-05 21:01 UTC (permalink / raw) To: Steven Rostedt; +Cc: linux-trace-devel On Fri, Jan 05, 2024 at 02:37:44PM -0500, Steven Rostedt wrote: > From: "Steven Rostedt (Google)" <rostedt@goodmis.org> > > 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 <vdonnefort@google.com> > Fixes: 7a4d5b24 ("kbuffer: Add kbuffer_refresh() API") > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> > --- > 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; > } I've been trying the new stack but I see some weird unexpected events: $ echo 3 > /sys/kernel/debug/tracing/trace_marker <...>-5 44401.178473328 mmiotrace_rw: 0 0 0 0 0 0 // I clearly didn't enable this event <...>-208 44401.178473328 print: tracing_mark_write: 2 Looking closer at the kbuf I see before the kbuffer_refresh() index = 244, curr = 272, next = 272, size = 272, start = 16 And after index = 280, curr = 272, next = 280, size = 312, start = 16 Could this index be the problem as this is used in kbuffer_read_event()? > > -- > 2.42.0 > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() 2024-01-05 21:01 ` Vincent Donnefort @ 2024-01-08 11:11 ` Vincent Donnefort 2024-01-08 16:28 ` Steven Rostedt 0 siblings, 1 reply; 8+ messages in thread From: Vincent Donnefort @ 2024-01-08 11:11 UTC (permalink / raw) To: Steven Rostedt; +Cc: linux-trace-devel On Fri, Jan 05, 2024 at 09:01:28PM +0000, Vincent Donnefort wrote: > On Fri, Jan 05, 2024 at 02:37:44PM -0500, Steven Rostedt wrote: > > From: "Steven Rostedt (Google)" <rostedt@goodmis.org> > > > > 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 <vdonnefort@google.com> > > Fixes: 7a4d5b24 ("kbuffer: Add kbuffer_refresh() API") > > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> > > --- > > 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; > > } > > I've been trying the new stack but I see some weird unexpected events: > > $ echo 3 > /sys/kernel/debug/tracing/trace_marker > > <...>-5 44401.178473328 mmiotrace_rw: 0 0 0 0 0 0 // I clearly didn't enable this event > <...>-208 44401.178473328 print: tracing_mark_write: 2 > > > Looking closer at the kbuf I see before the kbuffer_refresh() > > index = 244, curr = 272, next = 272, size = 272, start = 16 > > And after > > index = 280, curr = 272, next = 280, size = 312, start = 16 > > Could this index be the problem as this is used in kbuffer_read_event()? Yeah it seems that the update_pointers() is not enough. kbuffer_next_event(kbuf, NULL) will make sure curr is also up to date and will do the update until an event type we can read. With that change I don't see any spurious "mmiotrace_rw" on the output. > > > > > -- > > 2.42.0 > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() 2024-01-08 11:11 ` Vincent Donnefort @ 2024-01-08 16:28 ` Steven Rostedt 2024-01-08 16:47 ` Vincent Donnefort 0 siblings, 1 reply; 8+ messages in thread From: Steven Rostedt @ 2024-01-08 16:28 UTC (permalink / raw) To: Vincent Donnefort; +Cc: linux-trace-devel On Mon, 8 Jan 2024 11:11:29 +0000 Vincent Donnefort <vdonnefort@google.com> wrote: > Yeah it seems that the update_pointers() is not enough. > > kbuffer_next_event(kbuf, NULL) will make sure curr is also up to date and will > do the update until an event type we can read. With that change I don't see any > spurious "mmiotrace_rw" on the output. Ah you're right. Try this. -- Steve diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c index 1e1d168..5651797 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); /* @@ -323,12 +324,8 @@ int kbuffer_refresh(struct kbuffer *kbuf) 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); - } + if (kbuf->size != old_size && kbuf->curr == kbuf->next) + next_event(kbuf); return 0; } ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() 2024-01-08 16:28 ` Steven Rostedt @ 2024-01-08 16:47 ` Vincent Donnefort 0 siblings, 0 replies; 8+ messages in thread From: Vincent Donnefort @ 2024-01-08 16:47 UTC (permalink / raw) To: Steven Rostedt; +Cc: linux-trace-devel On Mon, Jan 08, 2024 at 11:28:53AM -0500, Steven Rostedt wrote: > On Mon, 8 Jan 2024 11:11:29 +0000 > Vincent Donnefort <vdonnefort@google.com> wrote: > > > Yeah it seems that the update_pointers() is not enough. > > > > kbuffer_next_event(kbuf, NULL) will make sure curr is also up to date and will > > do the update until an event type we can read. With that change I don't see any > > spurious "mmiotrace_rw" on the output. > > > Ah you're right. Try this. > > -- Steve > > diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c > index 1e1d168..5651797 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); > > /* > @@ -323,12 +324,8 @@ int kbuffer_refresh(struct kbuffer *kbuf) > 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); > - } > + if (kbuf->size != old_size && kbuf->curr == kbuf->next) > + next_event(kbuf); > > return 0; > } That worked! ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-01-08 16:47 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-01-05 19:37 [PATCH 0/3] kbuffer: Some minor fixes Steven Rostedt 2024-01-05 19:37 ` [PATCH 1/3] libtraceevent Documentation: Fix tep_kbuffer() prototype Steven Rostedt 2024-01-05 19:37 ` [PATCH 2/3] kbuffer: Add event if the buffer just fits in kbuffer_read_buffer() Steven Rostedt 2024-01-05 19:37 ` [PATCH 3/3] kbuffer: Update kbuf->next in kbuffer_refresh() Steven Rostedt 2024-01-05 21:01 ` Vincent Donnefort 2024-01-08 11:11 ` Vincent Donnefort 2024-01-08 16:28 ` Steven Rostedt 2024-01-08 16:47 ` Vincent Donnefort
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.