Revert "tracing: Have trace_event_file have ref counters"

This reverts commit a98172e36e which is
commit bb32500fb9b78215e4ef6ee8b4345c5f5d7eafb4 upstream.

It breaks the current Android ABI, and if needed, can be brought back in
an abi-safe way in the future.

Bug: 161946584
Change-Id: If981a67442122352b1836c6e75ba2a462cbc731d
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Greg Kroah-Hartman
2023-12-11 08:50:08 +00:00
parent 7999a9a70d
commit 2e1e5e63dd
5 changed files with 15 additions and 53 deletions

View File

@@ -365,7 +365,6 @@ enum {
EVENT_FILE_FL_TRIGGER_COND_BIT, EVENT_FILE_FL_TRIGGER_COND_BIT,
EVENT_FILE_FL_PID_FILTER_BIT, EVENT_FILE_FL_PID_FILTER_BIT,
EVENT_FILE_FL_WAS_ENABLED_BIT, EVENT_FILE_FL_WAS_ENABLED_BIT,
EVENT_FILE_FL_FREED_BIT,
}; };
extern struct trace_event_file *trace_get_event_file(const char *instance, extern struct trace_event_file *trace_get_event_file(const char *instance,
@@ -504,7 +503,6 @@ extern int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...);
* TRIGGER_COND - When set, one or more triggers has an associated filter * TRIGGER_COND - When set, one or more triggers has an associated filter
* PID_FILTER - When set, the event is filtered based on pid * PID_FILTER - When set, the event is filtered based on pid
* WAS_ENABLED - Set when enabled to know to clear trace on module removal * 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 { enum {
EVENT_FILE_FL_ENABLED = (1 << EVENT_FILE_FL_ENABLED_BIT), EVENT_FILE_FL_ENABLED = (1 << EVENT_FILE_FL_ENABLED_BIT),
@@ -518,7 +516,6 @@ enum {
EVENT_FILE_FL_TRIGGER_COND = (1 << EVENT_FILE_FL_TRIGGER_COND_BIT), 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_PID_FILTER = (1 << EVENT_FILE_FL_PID_FILTER_BIT),
EVENT_FILE_FL_WAS_ENABLED = (1 << EVENT_FILE_FL_WAS_ENABLED_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 { struct trace_event_file {
@@ -547,7 +544,6 @@ struct trace_event_file {
* caching and such. Which is mostly OK ;-) * caching and such. Which is mostly OK ;-)
*/ */
unsigned long flags; unsigned long flags;
atomic_t ref; /* ref count for opened files */
atomic_t sm_ref; /* soft-mode reference counter */ atomic_t sm_ref; /* soft-mode reference counter */
atomic_t tm_ref; /* trigger-mode reference counter */ atomic_t tm_ref; /* trigger-mode reference counter */
}; };

View File

@@ -4507,20 +4507,6 @@ int tracing_open_file_tr(struct inode *inode, struct file *filp)
if (ret) if (ret)
return 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; filp->private_data = inode->i_private;
return 0; return 0;
@@ -4531,7 +4517,6 @@ int tracing_release_file_tr(struct inode *inode, struct file *filp)
struct trace_event_file *file = inode->i_private; struct trace_event_file *file = inode->i_private;
trace_array_put(file->tr); trace_array_put(file->tr);
event_file_put(file);
return 0; return 0;
} }

View File

@@ -1780,9 +1780,6 @@ extern int register_event_command(struct event_command *cmd);
extern int unregister_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 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 * struct event_trigger_ops - callbacks for trace event triggers
* *

View File

@@ -746,38 +746,26 @@ 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) static void remove_event_file_dir(struct trace_event_file *file)
{ {
struct dentry *dir = file->dir; struct dentry *dir = file->dir;
struct dentry *child;
tracefs_remove(dir); 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);
tracefs_remove(dir);
}
list_del(&file->list); list_del(&file->list);
remove_subsystem(file->system); remove_subsystem(file->system);
free_event_filter(file->filter); free_event_filter(file->filter);
file->flags |= EVENT_FILE_FL_FREED; kmem_cache_free(file_cachep, file);
event_file_put(file);
} }
/* /*
@@ -1150,7 +1138,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
flags = file->flags; flags = file->flags;
mutex_unlock(&event_mutex); mutex_unlock(&event_mutex);
if (!file || flags & EVENT_FILE_FL_FREED) if (!file)
return -ENODEV; return -ENODEV;
if (flags & EVENT_FILE_FL_ENABLED && if (flags & EVENT_FILE_FL_ENABLED &&
@@ -1188,7 +1176,7 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
ret = -ENODEV; ret = -ENODEV;
mutex_lock(&event_mutex); mutex_lock(&event_mutex);
file = event_file_data(filp); file = event_file_data(filp);
if (likely(file && !(file->flags & EVENT_FILE_FL_FREED))) if (likely(file))
ret = ftrace_event_enable_disable(file, val); ret = ftrace_event_enable_disable(file, val);
mutex_unlock(&event_mutex); mutex_unlock(&event_mutex);
break; break;
@@ -1457,7 +1445,7 @@ event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
mutex_lock(&event_mutex); mutex_lock(&event_mutex);
file = event_file_data(filp); file = event_file_data(filp);
if (file && !(file->flags & EVENT_FILE_FL_FREED)) if (file)
print_event_filter(file, s); print_event_filter(file, s);
mutex_unlock(&event_mutex); mutex_unlock(&event_mutex);
@@ -2494,7 +2482,6 @@ trace_create_new_event(struct trace_event_call *call,
atomic_set(&file->tm_ref, 0); atomic_set(&file->tm_ref, 0);
INIT_LIST_HEAD(&file->triggers); INIT_LIST_HEAD(&file->triggers);
list_add(&file->list, &tr->events); list_add(&file->list, &tr->events);
event_file_get(file);
return file; return file;
} }

View File

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