From mboxrd@z Thu Jan 1 00:00:00 1970 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 C8F52947B for ; Sun, 3 Mar 2024 12:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709470780; cv=none; b=EK8ZxWsXfBWgxzU3ycP9oe3pE8xviFMhTO/gUyMYr/2ksFVPyOFbMlYuW7tV2SMuKe9EkqFmlF+mtXFKEj2ON9PpBC06GdgNHtBSdJEPBid/i3i4yqRohqqFAJKzsiOWXvzj7k1ZuDdYC9loTAv8Z8cnH6UfRrMQimczgA6MPsw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709470780; c=relaxed/simple; bh=efOaSPpHNMKkGkKPOPd5Oo42Pwvrx70v2nA/t76V7XQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oO9J5iqFYTUv3CPorFxvSqWkVkSsb/StQxf1LPjP6OcBdzQRmWkWtnwfqUf6iICPk9cfgAAjizhxTCIdHFFfg5rucjBS0PkdZ7zAHhXxJqscw0zZDvepAVuRiHsD4IYjnKun8NEGGFIih9o4LaRDzzvQET3sPNxsUBarr8G7D24= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74B8CC433F1; Sun, 3 Mar 2024 12:59:39 +0000 (UTC) Date: Sun, 3 Mar 2024 07:59:37 -0500 From: Steven Rostedt To: Linus Torvalds Cc: LKML , Masami Hiramatsu , Mathieu Desnoyers , Sachin Sant Subject: Re: [GIT PULL] tracing: Prevent trace_marker being bigger than unsigned short Message-ID: <20240303075937.36fc6043@rorschach.local.home> In-Reply-To: References: <20240302111244.3a1674be@gandalf.local.home> <20240302145958.05aabdd2@rorschach.local.home> <20240302154713.71e29402@rorschach.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 2 Mar 2024 12:55:10 -0800 Linus Torvalds wrote: > On Sat, 2 Mar 2024 at 12:47, Steven Rostedt 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); }