Revert "tracing: Have trace_event_file have ref counters"

This reverts commit 961c4511c7 which is
commit bb32500fb9b78215e4ef6ee8b4345c5f5d7eafb4 upstream.

It breaks the Android ABI and can be brought back later in an abi-safe
way if it is needed.

Bug: 161946584
Change-Id: Id5da117def3da9c182501e30ee84bea05da7e492
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Greg Kroah-Hartman 2023-11-29 12:45:02 +00:00
parent 288ce21693
commit 69365d1ade
5 changed files with 13 additions and 51 deletions

View File

@ -341,7 +341,6 @@ enum {
EVENT_FILE_FL_TRIGGER_COND_BIT,
EVENT_FILE_FL_PID_FILTER_BIT,
EVENT_FILE_FL_WAS_ENABLED_BIT,
EVENT_FILE_FL_FREED_BIT,
};
/*
@ -358,7 +357,6 @@ enum {
* TRIGGER_COND - When set, one or more triggers has an associated filter
* PID_FILTER - When set, the event is filtered based on pid
* WAS_ENABLED - Set when enabled to know to clear trace on module removal
* FREED - File descriptor is freed, all fields should be considered invalid
*/
enum {
EVENT_FILE_FL_ENABLED = (1 << EVENT_FILE_FL_ENABLED_BIT),
@ -372,7 +370,6 @@ enum {
EVENT_FILE_FL_TRIGGER_COND = (1 << EVENT_FILE_FL_TRIGGER_COND_BIT),
EVENT_FILE_FL_PID_FILTER = (1 << EVENT_FILE_FL_PID_FILTER_BIT),
EVENT_FILE_FL_WAS_ENABLED = (1 << EVENT_FILE_FL_WAS_ENABLED_BIT),
EVENT_FILE_FL_FREED = (1 << EVENT_FILE_FL_FREED_BIT),
};
struct trace_event_file {
@ -401,7 +398,6 @@ struct trace_event_file {
* caching and such. Which is mostly OK ;-)
*/
unsigned long flags;
atomic_t ref; /* ref count for opened files */
atomic_t sm_ref; /* soft-mode reference counter */
atomic_t tm_ref; /* trigger-mode reference counter */
};

View File

@ -4257,20 +4257,6 @@ int tracing_open_file_tr(struct inode *inode, struct file *filp)
if (ret)
return ret;
mutex_lock(&event_mutex);
/* Fail if the file is marked for removal */
if (file->flags & EVENT_FILE_FL_FREED) {
trace_array_put(file->tr);
ret = -ENODEV;
} else {
event_file_get(file);
}
mutex_unlock(&event_mutex);
if (ret)
return ret;
filp->private_data = inode->i_private;
return 0;
@ -4281,7 +4267,6 @@ int tracing_release_file_tr(struct inode *inode, struct file *filp)
struct trace_event_file *file = inode->i_private;
trace_array_put(file->tr);
event_file_put(file);
return 0;
}

View File

@ -1696,9 +1696,6 @@ extern int register_event_command(struct event_command *cmd);
extern int unregister_event_command(struct event_command *cmd);
extern int register_trigger_hist_enable_disable_cmds(void);
extern void event_file_get(struct trace_event_file *file);
extern void event_file_put(struct trace_event_file *file);
/**
* struct event_trigger_ops - callbacks for trace event triggers
*

View File

@ -698,33 +698,21 @@ static void remove_subsystem(struct trace_subsystem_dir *dir)
}
}
void event_file_get(struct trace_event_file *file)
{
atomic_inc(&file->ref);
}
void event_file_put(struct trace_event_file *file)
{
if (WARN_ON_ONCE(!atomic_read(&file->ref))) {
if (file->flags & EVENT_FILE_FL_FREED)
kmem_cache_free(file_cachep, file);
return;
}
if (atomic_dec_and_test(&file->ref)) {
/* Count should only go to zero when it is freed */
if (WARN_ON_ONCE(!(file->flags & EVENT_FILE_FL_FREED)))
return;
kmem_cache_free(file_cachep, file);
}
}
static void remove_event_file_dir(struct trace_event_file *file)
{
struct dentry *dir = file->dir;
struct dentry *child;
if (dir) {
spin_lock(&dir->d_lock); /* probably unneeded */
list_for_each_entry(child, &dir->d_subdirs, d_child) {
if (d_really_is_positive(child)) /* probably unneeded */
d_inode(child)->i_private = NULL;
}
spin_unlock(&dir->d_lock);
if (dir)
tracefs_remove_recursive(dir);
}
list_del(&file->list);
remove_subsystem(file->system);
@ -1045,7 +1033,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
flags = file->flags;
mutex_unlock(&event_mutex);
if (!file || flags & EVENT_FILE_FL_FREED)
if (!file)
return -ENODEV;
if (flags & EVENT_FILE_FL_ENABLED &&
@ -1083,7 +1071,7 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
ret = -ENODEV;
mutex_lock(&event_mutex);
file = event_file_data(filp);
if (likely(file && !(file->flags & EVENT_FILE_FL_FREED)))
if (likely(file))
ret = ftrace_event_enable_disable(file, val);
mutex_unlock(&event_mutex);
break;
@ -1352,7 +1340,7 @@ event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
mutex_lock(&event_mutex);
file = event_file_data(filp);
if (file && !(file->flags & EVENT_FILE_FL_FREED))
if (file)
print_event_filter(file, s);
mutex_unlock(&event_mutex);
@ -2276,7 +2264,6 @@ trace_create_new_event(struct trace_event_call *call,
atomic_set(&file->tm_ref, 0);
INIT_LIST_HEAD(&file->triggers);
list_add(&file->list, &tr->events);
event_file_get(file);
return file;
}

View File

@ -1800,9 +1800,6 @@ int apply_event_filter(struct trace_event_file *file, char *filter_string)
struct event_filter *filter = NULL;
int err;
if (file->flags & EVENT_FILE_FL_FREED)
return -ENODEV;
if (!strcmp(strstrip(filter_string), "0")) {
filter_disable(file);
filter = event_filter(file);