Skip to contentSkip to conversation

tracing: Updates for 6.7

PATCH In review Steven Rostedt 2 participants 9 messages Oct 20, 2023 – Oct 23, 2023

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: Updates for 6.7

git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/for-next

Head SHA1: 845e31e1101fc8533be52aff42d8f1ff48636024

Dan Carpenter (1):
tracing: Fix a NULL vs IS_ERR() bug in event_subsystem_dir()

Jiapeng Chong (1):
tracefs/eventfs: Modify mismatched function name

Jonathan Corbet (1):
seq_buf: fix a misleading comment

Matthew Wilcox (Oracle) (1):
tracing: Move readpos from seq_buf to trace_seq

Nathan Chancellor (1):
eventfs: Use ERR_CAST() in eventfs_create_events_dir()

Steven Rostedt (Google) (1):
eventfs: Fix failure path in eventfs_create_events_dir()

----

 fs/tracefs/event_inode.c    |  7 ++++---
 include/linux/seq_buf.h     |  7 ++-----
 include/linux/trace_seq.h   |  2 ++
 kernel/trace/trace.c        | 10 +++++-----
 kernel/trace/trace_events.c |  2 +-
 kernel/trace/trace_seq.c    |  6 +++++-
 lib/seq_buf.c               | 22 ++++++++++------------
 7 files changed, 29 insertions(+), 27 deletions(-)
author maintainer
#1 lore raw

PATCH 1/6 eventfs: Use ERR_CAST() in eventfs_create_events_dir()

From: Nathan Chancellor <[email protected]>

When building with clang and CONFIG_RANDSTRUCT_FULL=y, there is an error due to a cast in eventfs_create_events_dir():

fs/tracefs/event_inode.c:734:10: error: casting from randomized structure pointer type 'struct dentry *' to 'struct eventfs_inode *'

    734 |                 return (struct eventfs_inode *)dentry;
        |                        ^

1 error generated.

Use the ERR_CAST() function to resolve the error, as it was designed for this exact situation (casting an error pointer to another type).

Fixes 5790b1fb3d67 ("eventfs: Remove eventfs_file and just use eventfs_inode")
---
 fs/tracefs/event_inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/tracefs/event_inode.c +1 -1
index 1ccd100bc565..9f19b6608954 100644
@@ -731,7 +731,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 		return NULL;
 
 	if (IS_ERR(dentry))
-		return (struct eventfs_inode *)dentry;
+		return ERR_CAST(dentry);
 
 	ei = kzalloc(sizeof(*ei), GFP_KERNEL);
 	if (!ei)
Signature · 1 line
2.42.0
author maintainer
#2 lore raw

PATCH 2/6 eventfs: Fix failure path in eventfs_create_events_dir()

In reply to Steven Rostedt

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

The failure path of allocating ei goes to a path that dereferences ei. Add another label that skips over the ei dereferences to do the rest of the clean up.

Cc Masami Hiramatsu <[email protected]>
Cc Mark Rutland <[email protected]>
Fixes 5790b1fb3d67 ("eventfs: Remove eventfs_file and just use eventfs_inode")
---
 fs/tracefs/event_inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/tracefs/event_inode.c +2 -1
index 9f19b6608954..1885f1f1f339 100644
@@ -735,7 +735,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 
 	ei = kzalloc(sizeof(*ei), GFP_KERNEL);
 	if (!ei)
-		goto fail;
+		goto fail_ei;
 
 	inode = tracefs_get_inode(dentry->d_sb);
 	if (unlikely(!inode))
@@ -781,6 +781,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
  fail:
 	kfree(ei->d_children);
 	kfree(ei);
+ fail_ei:
 	tracefs_failed_creating(dentry);
 	return ERR_PTR(-ENOMEM);
 }
Signature · 1 line
2.42.0
author maintainer
#3 lore raw

PATCH 3/6 tracing: Fix a NULL vs IS_ERR() bug in event_subsystem_dir()

In reply to Steven Rostedt

From: Dan Carpenter <[email protected]>

The eventfs_create_dir() function returns error pointers, it never returns NULL. Update the check to reflect that.

Cc Masami Hiramatsu <[email protected]>
Fixes 5790b1fb3d67 ("eventfs: Remove eventfs_file and just use eventfs_inode")
---
 kernel/trace/trace_events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events.c +1 -1
index db46d2116500..f9e3e24d8796 100644
@@ -2354,7 +2354,7 @@ event_subsystem_dir(struct trace_array *tr, const char *name,
 		nr_entries = ARRAY_SIZE(system_entries);
 
 	ei = eventfs_create_dir(name, parent, system_entries, nr_entries, dir);
-	if (!ei) {
+	if (IS_ERR(ei)) {
 		pr_warn("Failed to create system directory %s\n", name);
 		__put_system(system);
 		goto out_free;
Signature · 1 line
2.42.0
author maintainer
#4 lore raw

PATCH 4/6 tracefs/eventfs: Modify mismatched function name

In reply to Steven Rostedt

From: Jiapeng Chong <[email protected]>

No functional modification involved.

fs/tracefs/event_inode.c:864: warning: expecting prototype for eventfs_remove(). Prototype was for eventfs_remove_dir() instead.

---
 fs/tracefs/event_inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/tracefs/event_inode.c +1 -1
index 1885f1f1f339..09ab93357957 100644
@@ -856,7 +856,7 @@ static void unhook_dentry(struct dentry **dentry, struct dentry **list)
 	}
 }
 /**
- * eventfs_remove - remove eventfs dir or file from list
+ * eventfs_remove_dir - remove eventfs dir or file from list
  * @ei: eventfs_inode to be removed.
  *
  * This function acquire the eventfs_mutex lock and call eventfs_remove_rec()
Signature · 1 line
2.42.0
author maintainer
#5 lore raw

PATCH 5/6 tracing: Move readpos from seq_buf to trace_seq

In reply to Steven Rostedt

From: "Matthew Wilcox (Oracle)" <[email protected]>

To make seq_buf more lightweight as a string buf, move the readpos member from seq_buf to its container, trace_seq. That puts the responsibility of maintaining the readpos entirely in the tracing code. If some future users want to package up the readpos with a seq_buf, we can define a new struct then.

---
 include/linux/seq_buf.h   |  5 +----
 include/linux/trace_seq.h |  2 ++
 kernel/trace/trace.c      | 10 +++++-----
 kernel/trace/trace_seq.c  |  6 +++++-
 lib/seq_buf.c             | 22 ++++++++++------------
 5 files changed, 23 insertions(+), 22 deletions(-)
include/linux/seq_buf.h +1 -4
index 515d7fcb9634..a0fb013cebdf 100644
@@ -14,19 +14,16 @@
  * @buffer:	pointer to the buffer
  * @size:	size of the buffer
  * @len:	the amount of data inside the buffer
- * @readpos:	The next position to read in the buffer.
  */
 struct seq_buf {
 	char			*buffer;
 	size_t			size;
 	size_t			len;
-	loff_t			readpos;
 };
 
 static inline void seq_buf_clear(struct seq_buf *s)
 {
 	s->len = 0;
-	s->readpos = 0;
 }
 
 static inline void
@@ -143,7 +140,7 @@ extern __printf(2, 0)
 int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args);
 extern int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s);
 extern int seq_buf_to_user(struct seq_buf *s, char __user *ubuf,
-			   int cnt);
+			   size_t start, int cnt);
 extern int seq_buf_puts(struct seq_buf *s, const char *str);
 extern int seq_buf_putc(struct seq_buf *s, unsigned char c);
 extern int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len);
include/linux/trace_seq.h +2 -0
index 6be92bf559fe..3691e0e76a1a 100644
@@ -14,6 +14,7 @@
 struct trace_seq {
 	char			buffer[PAGE_SIZE];
 	struct seq_buf		seq;
+	size_t			readpos;
 	int			full;
 };
 
@@ -22,6 +23,7 @@ trace_seq_init(struct trace_seq *s)
 {
 	seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
 	s->full = 0;
+	s->readpos = 0;
 }
 
 /**
kernel/trace/trace.c +5 -5
index 4383be8fa1b0..d629065c2383 100644
@@ -1731,15 +1731,15 @@ static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)
 {
 	int len;
 
-	if (trace_seq_used(s) <= s->seq.readpos)
+	if (trace_seq_used(s) <= s->readpos)
 		return -EBUSY;
 
-	len = trace_seq_used(s) - s->seq.readpos;
+	len = trace_seq_used(s) - s->readpos;
 	if (cnt > len)
 		cnt = len;
-	memcpy(buf, s->buffer + s->seq.readpos, cnt);
+	memcpy(buf, s->buffer + s->readpos, cnt);
 
-	s->seq.readpos += cnt;
+	s->readpos += cnt;
 	return cnt;
 }
 
@@ -7008,7 +7008,7 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
 
 	/* Now copy what we have to the user */
 	sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
-	if (iter->seq.seq.readpos >= trace_seq_used(&iter->seq))
+	if (iter->seq.readpos >= trace_seq_used(&iter->seq))
 		trace_seq_init(&iter->seq);
 
 	/*
kernel/trace/trace_seq.c +5 -1
index bac06ee3b98b..7be97229ddf8 100644
@@ -370,8 +370,12 @@ EXPORT_SYMBOL_GPL(trace_seq_path);
  */
 int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, int cnt)
 {
+	int ret;
 	__trace_seq_init(s);
-	return seq_buf_to_user(&s->seq, ubuf, cnt);
+	ret = seq_buf_to_user(&s->seq, ubuf, s->readpos, cnt);
+	if (ret > 0)
+		s->readpos += ret;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(trace_seq_to_user);
 
lib/seq_buf.c +10 -12
index 45c450f423fa..b7477aefff53 100644
@@ -324,23 +324,24 @@ int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc)
  * seq_buf_to_user - copy the sequence buffer to user space
  * @s: seq_buf descriptor
  * @ubuf: The userspace memory location to copy to
+ * @start: The first byte in the buffer to copy
  * @cnt: The amount to copy
  *
  * Copies the sequence buffer into the userspace memory pointed to
- * by @ubuf. It starts from the last read position (@s->readpos)
- * and writes up to @cnt characters or till it reaches the end of
- * the content in the buffer (@s->len), which ever comes first.
+ * by @ubuf. It starts from @start and writes up to @cnt characters
+ * or until it reaches the end of the content in the buffer (@s->len),
+ * whichever comes first.
  *
  * On success, it returns a positive number of the number of bytes
  * it copied.
  *
  * On failure it returns -EBUSY if all of the content in the
  * sequence has been already read, which includes nothing in the
- * sequence (@s->len == @s->readpos).
+ * sequence (@s->len == @start).
  *
  * Returns -EFAULT if the copy to userspace fails.
  */
-int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, int cnt)
+int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, size_t start, int cnt)
 {
 	int len;
 	int ret;
@@ -350,20 +351,17 @@ int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, int cnt)
 
 	len = seq_buf_used(s);
 
-	if (len <= s->readpos)
+	if (len <= start)
 		return -EBUSY;
 
-	len -= s->readpos;
+	len -= start;
 	if (cnt > len)
 		cnt = len;
-	ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
+	ret = copy_to_user(ubuf, s->buffer + start, cnt);
 	if (ret == cnt)
 		return -EFAULT;
 
-	cnt -= ret;
-
-	s->readpos += cnt;
-	return cnt;
+	return cnt - ret;
 }
 
 /**
Signature · 1 line
2.42.0
#6 lore raw

Re: [for-next][PATCH 5/6] tracing: Move readpos from seq_buf to trace_seq

Quoted 10 lines · Steven Rostedt

From: "Matthew Wilcox (Oracle)" <[email protected]>

To make seq_buf more lightweight as a string buf, move the readpos member from seq_buf to its container, trace_seq. That puts the responsibility of maintaining the readpos entirely in the tracing code. If some future users want to package up the readpos with a seq_buf, we can define a new struct then.

If we want Link: to be recognized as a tag, we probably should remove the blank line. Maybe new versions of b4 support that, but not all maintainers use it and AFAIK the convention was to have no blank lines in the tag block.

Quoted 11 lines
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#7 lore raw

Re: [for-next][PATCH 5/6] tracing: Move readpos from seq_buf to trace_seq

Quoted 9 lines · On Mon, 23 Oct 2023 12:57:53 +0300 Andy Shevchenko…
Quoted 7 lines · Steven Rostedt

From: "Matthew Wilcox (Oracle)" <[email protected]>

To make seq_buf more lightweight as a string buf, move the readpos member from seq_buf to its container, trace_seq. That puts the responsibility of maintaining the readpos entirely in the tracing code. If some future users want to package up the readpos with a seq_buf, we can define a new struct then.

Quoted 7 lines
Quoted 2 lines

If we want Link: to be recognized as a tag, we probably should remove the blank line. Maybe new versions of b4 support that, but not all maintainers use it and AFAIK the convention was to have no blank lines in the tag block.

So I've been using Link tags for over a decade. I originally had it as part of the tag block, but realized that it's more for humans than bots, and purposely separated it out. What Link tags are good for IMO is for humans that are looking at git blame and want to know more content. I prefer the Link tag to stand out so that it's easier for humans to go back to the archive and see if there was more discussions about why the change was made.

Hence, I don't really care if Link tags are "recognized" by anything but humans. It's actually one of the first tags to show up after Signed-off-by:
Cc: and Acked-by:. I believe it even predates "Fixes". At least the new format for the Fixes tag.

-- Steve

author maintainer
#8 lore raw

PATCH 6/6 seq_buf: fix a misleading comment

In reply to Steven Rostedt

From: Jonathan Corbet <[email protected]>

The comment for seq_buf_has_overflowed() says that an overflow condition is marked by len == size, but that's not what the code is testing. Make the comment match reality.

Fixes 8cd709ae7658a ("tracing: Have seq_buf use full buffer")
---
 include/linux/seq_buf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/seq_buf.h +1 -1
index a0fb013cebdf..8483e4b2d0d2 100644
@@ -36,7 +36,7 @@ seq_buf_init(struct seq_buf *s, char *buf, unsigned int size)
 
 /*
  * seq_buf have a buffer that might overflow. When this happens
- * the len and size are set to be equal.
+ * len is set to be greater than size.
  */
 static inline bool
 seq_buf_has_overflowed(struct seq_buf *s)
Signature · 1 line
2.42.0