public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Sachin Sant <sachinp@linux.ibm.com>
Subject: Re: [GIT PULL] tracing: Prevent trace_marker being bigger than unsigned short
Date: Sun, 3 Mar 2024 07:59:37 -0500	[thread overview]
Message-ID: <20240303075937.36fc6043@rorschach.local.home> (raw)
In-Reply-To: <CAHk-=wioeo5vyEWUZcGBKMsf3jnjrnnHc3uJiV=JjSKPdvZOEw@mail.gmail.com>

On Sat, 2 Mar 2024 12:55:10 -0800
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Sat, 2 Mar 2024 at 12:47, Steven Rostedt <rostedt@goodmis.org> wrote:
> >
> > I'm fine with just making it 4K with a comment saying that "4K is the
> > minimum page size on most archs, and to keep this consistent for crazy
> > architectures like PowerPC and it's 64K pages, we hard code 4K to keep
> > all architectures acting the same".  
> 
> 4k is at least a somewhat sane limit, and yes, being hw-independent is
> a good idea.
> 
> We have other strings that have that limit for similar reasons (ie PATH_MAX).
> 

I believe I was trying to solve this wrong. The vsprintf() is called on
reading of the ring buffer, and I was trying to fix it on the write
side. I believe that the fix should be on the read side where the
vsprintf() is called.

Sachin, can you try this patch.

diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 3e7fa44dc2b2..5c7962d612de 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -1588,11 +1588,20 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter,
 	struct print_entry *field;
 	struct trace_seq *s = &iter->seq;
 	int max = iter->ent_size - offsetof(struct print_entry, buf);
+	const char *p;
 
 	trace_assign_type(field, iter->ent);
 
 	seq_print_ip_sym(s, field->ip, flags);
-	trace_seq_printf(s, ": %.*s", max, field->buf);
+	trace_seq_puts(s, ": ");
+	/* Write 1K chunks at a time */
+	p = field->buf;
+	do {
+		int pre = max > 1024 ? 1024 : max;
+		trace_seq_printf(s, "%.*s", pre, p);
+		max -= pre;
+		p += pre;
+	} while (max > 0);
 
 	return trace_handle_return(s);
 }
@@ -1602,10 +1611,19 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
 {
 	struct print_entry *field;
 	int max = iter->ent_size - offsetof(struct print_entry, buf);
+	const char *p;
 
 	trace_assign_type(field, iter->ent);
 
-	trace_seq_printf(&iter->seq, "# %lx %.*s", field->ip, max, field->buf);
+	trace_seq_printf(&iter->seq, "# %lx", field->ip);
+	/* Write 1K chunks at a time */
+	p = field->buf;
+	do {
+		int pre = max > 1024 ? 1024 : max;
+		trace_seq_printf(&iter->seq, "%.*s", pre, p);
+		max -= pre;
+		p += pre;
+	} while (max > 0);
 
 	return trace_handle_return(&iter->seq);
 }

  reply	other threads:[~2024-03-03 12:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-02 16:12 [GIT PULL] tracing: Prevent trace_marker being bigger than unsigned short Steven Rostedt
2024-03-02 17:24 ` Linus Torvalds
2024-03-02 19:59   ` Steven Rostedt
2024-03-02 20:25     ` Linus Torvalds
2024-03-02 20:33     ` Linus Torvalds
2024-03-02 20:47       ` Steven Rostedt
2024-03-02 20:55         ` Linus Torvalds
2024-03-03 12:59           ` Steven Rostedt [this message]
2024-03-03 13:02             ` Steven Rostedt
2024-03-03 17:38             ` Linus Torvalds
2024-03-03 19:07               ` Steven Rostedt
2024-03-03 20:09                 ` Linus Torvalds
2024-03-03 21:00                   ` Steven Rostedt
2024-03-04 21:42                     ` Steven Rostedt
2024-03-04 21:50                       ` Linus Torvalds
2024-03-04 22:10                         ` Steven Rostedt
2024-03-04 23:20                           ` Linus Torvalds
2024-03-04 23:47                             ` Steven Rostedt
2024-03-04 23:52                               ` Steven Rostedt
2024-03-05  0:17                                 ` Linus Torvalds
2024-03-05  0:43                                   ` Steven Rostedt
2024-03-05  1:20                                     ` Mathieu Desnoyers
2024-03-02 20:26   ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240303075937.36fc6043@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=sachinp@linux.ibm.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox