Commit eb143f87 authored by Martin Fuzzey's avatar Martin Fuzzey Committed by Greg Kroah-Hartman

binder: fix log spam for existing debugfs file creation.

Since commit 43e23b6c ("debugfs: log errors when something goes wrong")
debugfs logs attempts to create existing files.

However binder attempts to create multiple debugfs files with
the same name when a single PID has multiple contexts, this leads
to log spamming during an Android boot (17 such messages during
boot on my system).

Fix this by checking if we already know the PID and only create
the debugfs entry for the first context per PID.

Do the same thing for binderfs for symmetry.
Signed-off-by: default avatarMartin Fuzzey <martin.fuzzey@flowbird.group>
Acked-by: default avatarTodd Kjos <tkjos@google.com>
Fixes: 43e23b6c ("debugfs: log errors when something goes wrong")
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/1578671054-5982-1-git-send-email-martin.fuzzey@flowbird.groupSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 10d3e38c
...@@ -5199,10 +5199,11 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma) ...@@ -5199,10 +5199,11 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
static int binder_open(struct inode *nodp, struct file *filp) static int binder_open(struct inode *nodp, struct file *filp)
{ {
struct binder_proc *proc; struct binder_proc *proc, *itr;
struct binder_device *binder_dev; struct binder_device *binder_dev;
struct binderfs_info *info; struct binderfs_info *info;
struct dentry *binder_binderfs_dir_entry_proc = NULL; struct dentry *binder_binderfs_dir_entry_proc = NULL;
bool existing_pid = false;
binder_debug(BINDER_DEBUG_OPEN_CLOSE, "%s: %d:%d\n", __func__, binder_debug(BINDER_DEBUG_OPEN_CLOSE, "%s: %d:%d\n", __func__,
current->group_leader->pid, current->pid); current->group_leader->pid, current->pid);
...@@ -5235,19 +5236,24 @@ static int binder_open(struct inode *nodp, struct file *filp) ...@@ -5235,19 +5236,24 @@ static int binder_open(struct inode *nodp, struct file *filp)
filp->private_data = proc; filp->private_data = proc;
mutex_lock(&binder_procs_lock); mutex_lock(&binder_procs_lock);
hlist_for_each_entry(itr, &binder_procs, proc_node) {
if (itr->pid == proc->pid) {
existing_pid = true;
break;
}
}
hlist_add_head(&proc->proc_node, &binder_procs); hlist_add_head(&proc->proc_node, &binder_procs);
mutex_unlock(&binder_procs_lock); mutex_unlock(&binder_procs_lock);
if (binder_debugfs_dir_entry_proc) { if (binder_debugfs_dir_entry_proc && !existing_pid) {
char strbuf[11]; char strbuf[11];
snprintf(strbuf, sizeof(strbuf), "%u", proc->pid); snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
/* /*
* proc debug entries are shared between contexts, so * proc debug entries are shared between contexts.
* this will fail if the process tries to open the driver * Only create for the first PID to avoid debugfs log spamming
* again with a different context. The priting code will * The printing code will anyway print all contexts for a given
* anyway print all contexts that a given PID has, so this * PID so this is not a problem.
* is not a problem.
*/ */
proc->debugfs_entry = debugfs_create_file(strbuf, 0444, proc->debugfs_entry = debugfs_create_file(strbuf, 0444,
binder_debugfs_dir_entry_proc, binder_debugfs_dir_entry_proc,
...@@ -5255,19 +5261,16 @@ static int binder_open(struct inode *nodp, struct file *filp) ...@@ -5255,19 +5261,16 @@ static int binder_open(struct inode *nodp, struct file *filp)
&proc_fops); &proc_fops);
} }
if (binder_binderfs_dir_entry_proc) { if (binder_binderfs_dir_entry_proc && !existing_pid) {
char strbuf[11]; char strbuf[11];
struct dentry *binderfs_entry; struct dentry *binderfs_entry;
snprintf(strbuf, sizeof(strbuf), "%u", proc->pid); snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
/* /*
* Similar to debugfs, the process specific log file is shared * Similar to debugfs, the process specific log file is shared
* between contexts. If the file has already been created for a * between contexts. Only create for the first PID.
* process, the following binderfs_create_file() call will * This is ok since same as debugfs, the log file will contain
* fail with error code EEXIST if another context of the same * information on all contexts of a given PID.
* process invoked binder_open(). This is ok since same as
* debugfs, the log file will contain information on all
* contexts of a given PID.
*/ */
binderfs_entry = binderfs_create_file(binder_binderfs_dir_entry_proc, binderfs_entry = binderfs_create_file(binder_binderfs_dir_entry_proc,
strbuf, &proc_fops, (void *)(unsigned long)proc->pid); strbuf, &proc_fops, (void *)(unsigned long)proc->pid);
...@@ -5277,10 +5280,8 @@ static int binder_open(struct inode *nodp, struct file *filp) ...@@ -5277,10 +5280,8 @@ static int binder_open(struct inode *nodp, struct file *filp)
int error; int error;
error = PTR_ERR(binderfs_entry); error = PTR_ERR(binderfs_entry);
if (error != -EEXIST) { pr_warn("Unable to create file %s in binderfs (error %d)\n",
pr_warn("Unable to create file %s in binderfs (error %d)\n", strbuf, error);
strbuf, error);
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment