Skip to contentSkip to conversation

tracing: Have trace_marker break up by lines by size of trace_seq

PATCH In review Steven Rostedt 3 participants 4 messages Dec 13, 2023 – Dec 14, 2023 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 tracing: Have trace_marker break up by lines by size of trace_seq

From: "Steven Rostedt (Google)" <[email protected]>

If a trace_marker write is bigger than what trace_seq can hold, then it will print "LINE TOO BIG" message and not what was written.

Instead, if check if the write is bigger than the trace_seq and break it up by that size.

Ideally, we could make the trace_seq dynamic that could hold this. But that's for another time.

---
 kernel/trace/trace.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/trace/trace.c +5 -0
index 893e749713d3..2a21bc840fe7 100644
@@ -7298,6 +7298,11 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 	if (cnt < FAULTED_SIZE)
 		size += FAULTED_SIZE - cnt;
 
+	if (size > TRACE_SEQ_BUFFER_SIZE) {
+		cnt -= size - TRACE_SEQ_BUFFER_SIZE;
+		goto again;
+	}
+
 	buffer = tr->array_buffer.buffer;
 	event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
 					    tracing_gen_ctx());
Signature · 1 line
2.42.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Tue, 12 Dec 2023 19:04:22 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (Google)" <[email protected]>

If a trace_marker write is bigger than what trace_seq can hold, then it will print "LINE TOO BIG" message and not what was written.

Instead, if check if the write is bigger than the trace_seq and break it

Instead, check if ... ?

Quoted 4 lines

up by that size.

Ideally, we could make the trace_seq dynamic that could hold this. But that's for another time.

I think this is OK, but if possible it is better to be merged with the "LINE TOO BIG" patch (by updating the version).

Thank you,

Quoted 25 lines
---
 kernel/trace/trace.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/trace/trace.c +5 -0
index 893e749713d3..2a21bc840fe7 100644
@@ -7298,6 +7298,11 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 	if (cnt < FAULTED_SIZE)
 		size += FAULTED_SIZE - cnt;
 
+	if (size > TRACE_SEQ_BUFFER_SIZE) {
+		cnt -= size - TRACE_SEQ_BUFFER_SIZE;
+		goto again;
+	}
+
 	buffer = tr->array_buffer.buffer;
 	event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
 					    tracing_gen_ctx());
Signature · 1 line
2.42.0
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
author maintainer
#2 lore raw
Quoted 11 lines · On Wed, 13 Dec 2023 09:19:33 +0900 Masami Hiramatsu (Google)…
Quoted 6 lines · On Tue, 12 Dec 2023 19:04:22 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (Google)" <[email protected]>

If a trace_marker write is bigger than what trace_seq can hold, then it will print "LINE TOO BIG" message and not what was written.

Instead, if check if the write is bigger than the trace_seq and break it

Instead, check if ... ?

Ah yes, thank you.

Quoted 8 lines
Quoted 5 lines

up by that size.

Ideally, we could make the trace_seq dynamic that could hold this. But that's for another time.

I think this is OK, but if possible it is better to be merged with the "LINE TOO BIG" patch (by updating the version).

What do you mean by "updating the version"?

Note, the LINE TOO BIG doesn't happen today. It only happens when applying the sub buffer resize change, and then when I run the tests, it breaks when the subbuffer is bigger than the trace_seq.

Quoted 2 lines

Thanks!

-- Steve

#3 lore raw
In reply to Steven Rostedt
kernel test robot noticed the following build errors:

Hi Steven,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.7-rc5 next-20231213]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Steven-Rostedt/tracing-Have-trace_marker-break-up-by-lines-by-size-of-trace_seq/20231213-080530
base:   linus/master
patch link:    https://lore.kernel.org/r/20231212190422.1eaf224f%40gandalf.local.home
patch subject: [PATCH] tracing: Have trace_marker break up by lines by size of trace_seq
config: arc-defconfig (https://download.01.org/0day-ci/archive/20231214/[email protected]/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231214/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

kernel/trace/trace.c: In function 'tracing_mark_write':
kernel/trace/trace.c:7296:20: error: 'TRACE_SEQ_BUFFER_SIZE' undeclared (first use in this function); did you mean 'TRACE_BUF_SIZE'?

    7296 |         if (size > TRACE_SEQ_BUFFER_SIZE) {
         |                    ^~~~~~~~~~~~~~~~~~~~~
         |                    TRACE_BUF_SIZE
   kernel/trace/trace.c:7296:20: note: each undeclared identifier is reported only once for each function it appears in
>> kernel/trace/trace.c:7298:17: error: label 'again' used but not defined
    7298 |                 goto again;
         |                 ^~~~

vim +/again +7298 kernel/trace/trace.c

7278
7279 if (tracing_disabled)
7280 return -EINVAL;
7281
7282 if (!(tr->trace_flags & TRACE_ITER_MARKERS))
7283 return -EINVAL;
7284
7285 if (cnt > TRACE_BUF_SIZE)
7286 cnt = TRACE_BUF_SIZE;
7287
7288 BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE);
7289
7290 size = sizeof(*entry) + cnt + 2; /* add '\0' and possible '\n' */
7291
7292 /* If less than "<faulted>", then make sure we can still add that */
7293 if (cnt < FAULTED_SIZE)
7294 size += FAULTED_SIZE - cnt;
7295
7296 if (size > TRACE_SEQ_BUFFER_SIZE) {
7297 cnt -= size - TRACE_SEQ_BUFFER_SIZE;

> 7298			goto again;

7299 }
7300
7301 buffer = tr->array_buffer.buffer;
7302 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
7303 tracing_gen_ctx());
7304 if (unlikely(!event))
7305 /* Ring buffer disabled, return as if not open for write */
7306 return -EBADF;
7307
7308 entry = ring_buffer_event_data(event);
7309 entry->ip = _THIS_IP_;
7310
7311 len = __copy_from_user_inatomic(&entry->buf, ubuf, cnt);
7312 if (len) {
7313 memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE);
7314 cnt = FAULTED_SIZE;
7315 written = -EFAULT;
7316 } else
7317 written = cnt;
7318
7319 if (tr->trace_marker_file && !list_empty(&tr->trace_marker_file->triggers)) {
7320 /* do not add \n before testing triggers, but add \0 */
7321 entry->buf[cnt] = '\0';
7322 tt = event_triggers_call(tr->trace_marker_file, buffer, entry, event);
7323 }
7324
7325 if (entry->buf[cnt - 1] != '\n') {
7326 entry->buf[cnt] = '\n';
7327 entry->buf[cnt + 1] = '\0';
7328 } else
7329 entry->buf[cnt] = '\0';
7330
7331 if (static_branch_unlikely(&trace_marker_exports_enabled))
7332 ftrace_exports(event, TRACE_EXPORT_MARKER);
7333 __buffer_unlock_commit(buffer, event);
7334
7335 if (tt)
7336 event_triggers_post_call(tr->trace_marker_file, tt);
7337
7338 return written;
7339 }
7340

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki