Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2096074ybl; Thu, 30 Jan 2020 11:17:07 -0800 (PST) X-Google-Smtp-Source: APXvYqwfEUwV+Bz+aSBzmpwmTl9VEgvO8JbMI8wJ7r8l8uCZ/20RpFW2l7Tl42trU2+kYxXb+lbx X-Received: by 2002:a9d:10e:: with SMTP id 14mr4674653otu.59.1580411827708; Thu, 30 Jan 2020 11:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580411827; cv=none; d=google.com; s=arc-20160816; b=Qx2w/FIXkc+nM7I+230xG/OlxGNFsB6Hqhujk8vSd7JRfeaY8/wxkXJXbtq8+3I5OE Wx7rVznkZZxJ/i0XXUUlcLosDdbXTPPlQba9ISGHM7/lgwCLtbTmk7Rkx0y3JQ3YG5VH oFj6QvAho7pF1/3O76G1sK1VZJtjrQIXYV1wBi0Qe6q+C1+/BwbDM4MYfyG1Hf6YenPm cuFRPjt6b1hJOxKTp1l7SxBQmdpXb0Gk5LIQ5te3NswVQx+wg1VxoWoULHOkKPOk/+6W wCQH+mOk7oVbnUgFYRjVGvsZOEVcD1H1LwopJrfUK23HlhhlzbT8+uqSNF7rkrcJgc5y eAVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kxfbRJ0KLXPNBH1+FwkyFHeDMWJN1482RMgyblNqmlc=; b=Y/PNYMX3/pHNd6m57n5CoVfP5UkYGLluqtt7s/Mh7KU3N64t7i/RHYy/XWTMXRMZvM DvqNAYIjapIgxsVNE7AQXzRrv+yMKJk1xd2CIGl5KwuU4T217B63KGfequKpMVDo4rmP +H8V2a5NC5QN0fFDdhLOms2FdkrADcxqkbmgFD7DmEpav2gQhM6W49OPRyOeHKpAd2BI 2uIxgl8Ykn0GyQ7dERiaGW6I0CC/bQpaj4ywEL6WCBHvpACDvD7hsA/j70ap4km+qzGU F5yLULRUXvSR1PpNW3r9GTBEWQmHOdy3BWdUxA/B2zOHZemohXsUCTBU6bOy7eaPtvoZ r17w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UlQeN+Z9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si3554957otk.154.2020.01.30.11.16.55; Thu, 30 Jan 2020 11:17:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UlQeN+Z9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730432AbgA3Smk (ORCPT + 99 others); Thu, 30 Jan 2020 13:42:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:50920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbgA3Smg (ORCPT ); Thu, 30 Jan 2020 13:42:36 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4BC092083E; Thu, 30 Jan 2020 18:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580409755; bh=GOS1qZvCtnVV92X2RUs0Xx56D0YfKguWqkXghm3ygQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UlQeN+Z9JhbOP9EQ+nlXb4jLQGGlZMsoR58kHzJ0Vx+e6lb77Wi4ec82MdRFo5fCk dODBY1vHNiUSRG6RfsgK8uLptpFugFQ1Xb9l0atnsur+I3PzAMkhM2fkaxD0zH2oYj f8ULcqCPBejuh1nZK96hDruDBFxjzIY7xcOhh4fc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Fuzzey , Todd Kjos Subject: [PATCH 5.4 021/110] binder: fix log spam for existing debugfs file creation. Date: Thu, 30 Jan 2020 19:37:57 +0100 Message-Id: <20200130183617.460576374@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200130183613.810054545@linuxfoundation.org> References: <20200130183613.810054545@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Fuzzey commit eb143f8756e77c8fcfc4d574922ae9efd3a43ca9 upstream. 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 Acked-by: Todd Kjos Fixes: 43e23b6c0b01 ("debugfs: log errors when something goes wrong") Cc: stable Link: https://lore.kernel.org/r/1578671054-5982-1-git-send-email-martin.fuzzey@flowbird.group Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -5203,10 +5203,11 @@ err_bad_arg: 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 *nod 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 *nod &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 *nod 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); } }