All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] binder: fix log spam for existing debugfs file creation.
@ 2020-01-10 15:44 ` Martin Fuzzey
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Fuzzey @ 2020-01-10 15:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
	Joel Fernandes, Christian Brauner, devel, linux-kernel

Since commit 43e23b6c0b01 ("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: Martin Fuzzey <martin.fuzzey@flowbird.group>
---
 drivers/android/binder.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 976a694..254f87b 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -5203,10 +5203,11 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 
 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 binderfs_info *info;
 	struct dentry *binder_binderfs_dir_entry_proc = NULL;
+	bool existing_pid = false;
 
 	binder_debug(BINDER_DEBUG_OPEN_CLOSE, "%s: %d:%d\n", __func__,
 		     current->group_leader->pid, current->pid);
@@ -5239,19 +5240,24 @@ static int binder_open(struct inode *nodp, struct file *filp)
 	filp->private_data = proc;
 
 	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);
 	mutex_unlock(&binder_procs_lock);
 
-	if (binder_debugfs_dir_entry_proc) {
+	if (binder_debugfs_dir_entry_proc && !existing_pid) {
 		char strbuf[11];
 
 		snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
 		/*
-		 * proc debug entries are shared between contexts, so
-		 * this will fail if the process tries to open the driver
-		 * again with a different context. The priting code will
-		 * anyway print all contexts that a given PID has, so this
-		 * is not a problem.
+		 * proc debug entries are shared between contexts.
+		 * Only create for the first PID to avoid debugfs log spamming
+		 * The printing code will anyway print all contexts for a given
+		 * PID so this is not a problem.
 		 */
 		proc->debugfs_entry = debugfs_create_file(strbuf, 0444,
 			binder_debugfs_dir_entry_proc,
@@ -5259,19 +5265,16 @@ static int binder_open(struct inode *nodp, struct file *filp)
 			&proc_fops);
 	}
 
-	if (binder_binderfs_dir_entry_proc) {
+	if (binder_binderfs_dir_entry_proc && !existing_pid) {
 		char strbuf[11];
 		struct dentry *binderfs_entry;
 
 		snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
 		/*
 		 * Similar to debugfs, the process specific log file is shared
-		 * between contexts. If the file has already been created for a
-		 * process, the following binderfs_create_file() call will
-		 * fail with error code EEXIST if another context of the same
-		 * process invoked binder_open(). This is ok since same as
-		 * debugfs, the log file will contain information on all
-		 * contexts of a given PID.
+		 * between contexts. Only create for the first PID.
+		 * 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,
 			strbuf, &proc_fops, (void *)(unsigned long)proc->pid);
@@ -5281,10 +5284,8 @@ static int binder_open(struct inode *nodp, struct file *filp)
 			int error;
 
 			error = PTR_ERR(binderfs_entry);
-			if (error != -EEXIST) {
-				pr_warn("Unable to create file %s in binderfs (error %d)\n",
-					strbuf, error);
-			}
+			pr_warn("Unable to create file %s in binderfs (error %d)\n",
+				strbuf, error);
 		}
 	}
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] binder: fix log spam for existing debugfs file creation.
@ 2020-01-10 15:44 ` Martin Fuzzey
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Fuzzey @ 2020-01-10 15:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, Todd Kjos, linux-kernel, Arve Hjønnevåg,
	Joel Fernandes, Martijn Coenen, Christian Brauner

Since commit 43e23b6c0b01 ("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: Martin Fuzzey <martin.fuzzey@flowbird.group>
---
 drivers/android/binder.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 976a694..254f87b 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -5203,10 +5203,11 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 
 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 binderfs_info *info;
 	struct dentry *binder_binderfs_dir_entry_proc = NULL;
+	bool existing_pid = false;
 
 	binder_debug(BINDER_DEBUG_OPEN_CLOSE, "%s: %d:%d\n", __func__,
 		     current->group_leader->pid, current->pid);
@@ -5239,19 +5240,24 @@ static int binder_open(struct inode *nodp, struct file *filp)
 	filp->private_data = proc;
 
 	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);
 	mutex_unlock(&binder_procs_lock);
 
-	if (binder_debugfs_dir_entry_proc) {
+	if (binder_debugfs_dir_entry_proc && !existing_pid) {
 		char strbuf[11];
 
 		snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
 		/*
-		 * proc debug entries are shared between contexts, so
-		 * this will fail if the process tries to open the driver
-		 * again with a different context. The priting code will
-		 * anyway print all contexts that a given PID has, so this
-		 * is not a problem.
+		 * proc debug entries are shared between contexts.
+		 * Only create for the first PID to avoid debugfs log spamming
+		 * The printing code will anyway print all contexts for a given
+		 * PID so this is not a problem.
 		 */
 		proc->debugfs_entry = debugfs_create_file(strbuf, 0444,
 			binder_debugfs_dir_entry_proc,
@@ -5259,19 +5265,16 @@ static int binder_open(struct inode *nodp, struct file *filp)
 			&proc_fops);
 	}
 
-	if (binder_binderfs_dir_entry_proc) {
+	if (binder_binderfs_dir_entry_proc && !existing_pid) {
 		char strbuf[11];
 		struct dentry *binderfs_entry;
 
 		snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
 		/*
 		 * Similar to debugfs, the process specific log file is shared
-		 * between contexts. If the file has already been created for a
-		 * process, the following binderfs_create_file() call will
-		 * fail with error code EEXIST if another context of the same
-		 * process invoked binder_open(). This is ok since same as
-		 * debugfs, the log file will contain information on all
-		 * contexts of a given PID.
+		 * between contexts. Only create for the first PID.
+		 * 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,
 			strbuf, &proc_fops, (void *)(unsigned long)proc->pid);
@@ -5281,10 +5284,8 @@ static int binder_open(struct inode *nodp, struct file *filp)
 			int error;
 
 			error = PTR_ERR(binderfs_entry);
-			if (error != -EEXIST) {
-				pr_warn("Unable to create file %s in binderfs (error %d)\n",
-					strbuf, error);
-			}
+			pr_warn("Unable to create file %s in binderfs (error %d)\n",
+				strbuf, error);
 		}
 	}
 
-- 
1.9.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] binder: fix log spam for existing debugfs file creation.
  2020-01-10 15:44 ` Martin Fuzzey
@ 2020-01-14 15:22   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2020-01-14 15:22 UTC (permalink / raw)
  To: Martin Fuzzey
  Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
	Joel Fernandes, Christian Brauner, devel, linux-kernel

On Fri, Jan 10, 2020 at 04:44:01PM +0100, Martin Fuzzey wrote:
> Since commit 43e23b6c0b01 ("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: Martin Fuzzey <martin.fuzzey@flowbird.group>

Does this need a "Fixes:" and cc: stable tag?

And it would be good to get a review from the binder maintainer(s) to
see if this is sane or not...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] binder: fix log spam for existing debugfs file creation.
@ 2020-01-14 15:22   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2020-01-14 15:22 UTC (permalink / raw)
  To: Martin Fuzzey
  Cc: devel, Todd Kjos, linux-kernel, Arve Hjønnevåg,
	Joel Fernandes, Martijn Coenen, Christian Brauner

On Fri, Jan 10, 2020 at 04:44:01PM +0100, Martin Fuzzey wrote:
> Since commit 43e23b6c0b01 ("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: Martin Fuzzey <martin.fuzzey@flowbird.group>

Does this need a "Fixes:" and cc: stable tag?

And it would be good to get a review from the binder maintainer(s) to
see if this is sane or not...

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] binder: fix log spam for existing debugfs file creation.
  2020-01-14 15:22   ` Greg Kroah-Hartman
@ 2020-01-17 22:30     ` Todd Kjos
  -1 siblings, 0 replies; 6+ messages in thread
From: Todd Kjos @ 2020-01-17 22:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Martin Fuzzey, Arve Hjønnevåg, Todd Kjos,
	Martijn Coenen, Joel Fernandes, Christian Brauner,
	open list:ANDROID DRIVERS, LKML

On Tue, Jan 14, 2020 at 7:22 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Fri, Jan 10, 2020 at 04:44:01PM +0100, Martin Fuzzey wrote:
> > Since commit 43e23b6c0b01 ("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: Martin Fuzzey <martin.fuzzey@flowbird.group>
>
> Does this need a "Fixes:" and cc: stable tag?

It would probably make sense to take it into 5.4 (spam issue was
introduced in 5.2).

Please add "Fixes:" as Greg suggests citing the commit above.
Acked-by: Todd Kjos <tkjos@google.com>

>
> And it would be good to get a review from the binder maintainer(s) to
> see if this is sane or not...
>
> thanks,
>
> greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] binder: fix log spam for existing debugfs file creation.
@ 2020-01-17 22:30     ` Todd Kjos
  0 siblings, 0 replies; 6+ messages in thread
From: Todd Kjos @ 2020-01-17 22:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: open list:ANDROID DRIVERS, Todd Kjos, LKML,
	Arve Hjønnevåg, Martin Fuzzey, Joel Fernandes,
	Martijn Coenen, Christian Brauner

On Tue, Jan 14, 2020 at 7:22 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Fri, Jan 10, 2020 at 04:44:01PM +0100, Martin Fuzzey wrote:
> > Since commit 43e23b6c0b01 ("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: Martin Fuzzey <martin.fuzzey@flowbird.group>
>
> Does this need a "Fixes:" and cc: stable tag?

It would probably make sense to take it into 5.4 (spam issue was
introduced in 5.2).

Please add "Fixes:" as Greg suggests citing the commit above.
Acked-by: Todd Kjos <tkjos@google.com>

>
> And it would be good to get a review from the binder maintainer(s) to
> see if this is sane or not...
>
> thanks,
>
> greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-01-17 22:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10 15:44 [PATCH] binder: fix log spam for existing debugfs file creation Martin Fuzzey
2020-01-10 15:44 ` Martin Fuzzey
2020-01-14 15:22 ` Greg Kroah-Hartman
2020-01-14 15:22   ` Greg Kroah-Hartman
2020-01-17 22:30   ` Todd Kjos
2020-01-17 22:30     ` Todd Kjos

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.