linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] tracing: Support reading trace event format file larger than PAGE_SIZE
@ 2025-01-02 17:43 shiju.jose
  2025-01-06 17:22 ` Steven Rostedt
  0 siblings, 1 reply; 9+ messages in thread
From: shiju.jose @ 2025-01-02 17:43 UTC (permalink / raw)
  To: rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel,
	linux-kernel
  Cc: linuxarm, jonathan.cameron, tanxiaofei, prime.zeng, shiju.jose

From: Shiju Jose <shiju.jose@huawei.com>

When userspace reads a trace event format file, the maximum data size
that can be read is limited to PAGE_SIZE by the seq_read() and
seq_read_iter() functions. This results in userspace receiving partial
data if the format file is larger than PAGE_SIZE, requiring a workaround
to read the complete data from the format file.

Add support for reading trace event format files larger than PAGE_SIZE when
needed by userspace.

Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
---
 kernel/trace/trace_events.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 1545cc8b49d0..ef33614e7f22 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1801,6 +1801,36 @@ static int trace_format_open(struct inode *inode, struct file *file)
 	return 0;
 }
 
+/**
+ *      trace_format_read - read() method for format file.
+ *      @file: the file to read from
+ *      @buf: the buffer to read to
+ *      @size: the maximum number of bytes to read
+ *      @ppos: the current position in the file
+ *
+ *  * Return:
+ *  * %0  - No bytes copied (EOF).
+ *  * %>0 - Number of bytes copied.
+ *  * %<0 - Error code.
+ */
+static ssize_t trace_format_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
+{
+	ssize_t copied = 0;
+	ssize_t ret;
+
+	do {
+		ret = seq_read(file, buf + copied, size - copied, ppos);
+		if (ret < 0)
+			return ret;
+
+		copied += ret;
+		if (copied >= size)
+			break;
+	} while (ret);
+
+	return copied;
+}
+
 #ifdef CONFIG_PERF_EVENTS
 static ssize_t
 event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
@@ -2284,7 +2314,7 @@ static const struct file_operations ftrace_enable_fops = {
 
 static const struct file_operations ftrace_event_format_fops = {
 	.open = trace_format_open,
-	.read = seq_read,
+	.read = trace_format_read,
 	.llseek = seq_lseek,
 	.release = seq_release,
 };
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-01-08 10:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-02 17:43 [PATCH 1/1] tracing: Support reading trace event format file larger than PAGE_SIZE shiju.jose
2025-01-06 17:22 ` Steven Rostedt
2025-01-06 18:15   ` Shiju Jose
2025-01-06 22:11     ` Steven Rostedt
2025-01-07 11:04       ` Shiju Jose
2025-01-07 23:02         ` Steven Rostedt
2025-01-07 23:19           ` Steven Rostedt
2025-01-08 10:34             ` Shiju Jose
2025-01-08 10:19           ` Shiju Jose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).