Skip to content

Commit 3ad7b12

Browse files
committed
Merge tag 'trace-v6.4-rc7-v3' of git://git.kernel.org/pub/scm/linux/kernel/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
2 parents 2eb15b4 + d34a271 commit 3ad7b12

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

kernel/trace/trace_events_user.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,8 @@ static ssize_t user_events_write_core(struct file *file, struct iov_iter *i)
20962096

20972097
if (unlikely(faulted))
20982098
return -EFAULT;
2099-
}
2099+
} else
2100+
return -EBADF;
21002101

21012102
return ret;
21022103
}

tools/testing/selftests/user_events/ftrace_test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ TEST_F(user, write_events) {
324324
io[0].iov_base = &reg.write_index;
325325
io[0].iov_len = sizeof(reg.write_index);
326326

327+
/* Write should return -EBADF when event is not enabled */
328+
ASSERT_EQ(-1, writev(self->data_fd, (const struct iovec *)io, 3));
329+
ASSERT_EQ(EBADF, errno);
330+
327331
/* Enable event */
328332
self->enable_fd = open(enable_file, O_RDWR);
329333
ASSERT_NE(-1, write(self->enable_fd, "1", sizeof("1")))
@@ -400,6 +404,10 @@ TEST_F(user, write_fault) {
400404
ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, &reg));
401405
ASSERT_EQ(0, reg.write_index);
402406

407+
/* Enable event */
408+
self->enable_fd = open(enable_file, O_RDWR);
409+
ASSERT_NE(-1, write(self->enable_fd, "1", sizeof("1")))
410+
403411
/* Write should work normally */
404412
ASSERT_NE(-1, writev(self->data_fd, (const struct iovec *)io, 2));
405413

0 commit comments

Comments
 (0)