Skip to content

Commit

Permalink
Merge tag 'trace-v6.4-rc7-v3' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/git/trace/linux-trace

Pull tracing fix from Steven Rostedt:
 "Fix user event write on buffer disabled.

  The user events write currently returns the size of what was supposed
  to be written when tracing is disabled and nothing was written.

  Instead, behave like trace_marker and return -EBADF, as that is what
  is returned if a file is opened for read only, and a write is
  performed on it. Writing to the buffer that is disabled is like trying
  to write to a file opened for read only, as the buffer still can be
  read, but just not written to.

  This also includes test cases for this use case"

* tag 'trace-v6.4-rc7-v3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
  selftests/user_events: Add test cases when event is disabled
  selftests/user_events: Enable the event before write_fault test in ftrace self-test
  tracing/user_events: Fix incorrect return value for writing operation when events are disabled
  • Loading branch information
Linus Torvalds committed Jun 30, 2023
2 parents 2eb15b4 + d34a271 commit 3ad7b12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kernel/trace/trace_events_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,8 @@ static ssize_t user_events_write_core(struct file *file, struct iov_iter *i)

if (unlikely(faulted))
return -EFAULT;
}
} else
return -EBADF;

return ret;
}
Expand Down
8 changes: 8 additions & 0 deletions tools/testing/selftests/user_events/ftrace_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ TEST_F(user, write_events) {
io[0].iov_base = &reg.write_index;
io[0].iov_len = sizeof(reg.write_index);

/* Write should return -EBADF when event is not enabled */
ASSERT_EQ(-1, writev(self->data_fd, (const struct iovec *)io, 3));
ASSERT_EQ(EBADF, errno);

/* Enable event */
self->enable_fd = open(enable_file, O_RDWR);
ASSERT_NE(-1, write(self->enable_fd, "1", sizeof("1")))
Expand Down Expand Up @@ -400,6 +404,10 @@ TEST_F(user, write_fault) {
ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, &reg));
ASSERT_EQ(0, reg.write_index);

/* Enable event */
self->enable_fd = open(enable_file, O_RDWR);
ASSERT_NE(-1, write(self->enable_fd, "1", sizeof("1")))

/* Write should work normally */
ASSERT_NE(-1, writev(self->data_fd, (const struct iovec *)io, 2));

Expand Down

0 comments on commit 3ad7b12

Please sign in to comment.