Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp851748ybl; Fri, 10 Jan 2020 07:46:53 -0800 (PST) X-Google-Smtp-Source: APXvYqwiwzJbURvWaOpJxTLGxo+dZzu4MvNzLw0z7PZmqBh+2s1cc+jvxecHt7hZAejiLec8vask X-Received: by 2002:a05:6830:1402:: with SMTP id v2mr3092578otp.12.1578671213758; Fri, 10 Jan 2020 07:46:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578671213; cv=none; d=google.com; s=arc-20160816; b=UngD9paRqA4fj2+iJQa4mmaEu1mI3fxtMW63rI+ko3a9J8LIIViMCSi3709WzAD4sr nvIU7qxh86S/Eyfm4J/DP9AO9PkhNRJDVZ4bcITUGW/HKznEvMQpjKy+IJdg9K1TTWVT LfwO31n8Ua/+16VwVftXp9B+kK0iLlLriWSBVG7J2lp56amhXKk5AckPqqrYrcgIzXV0 IcZt2KGE1dmeeQwOsDRi3RPQWGsZqoVyo09ifiti3jDrKNsPH9RFtnFni+Vs4s2hiu7Z dIRPKx5GQt8sb6oUz/LNqCfS+iJRJaswMmxWt9q9F5CvtLuxwYfK3jtp3wQEBoVTRojL YKMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=e7IY92TT8uEF1NqXhkjC9P1gwmK8Iq+uyMae8G1wu4o=; b=U2qGi0LLdEp+TRx15LT5ZMoRT26horKAIuJYGE7dfB+5IBKHd9B39QjLE8a9XC7Ktn amiovM0/euo1ZdTylwbCoEBOJR2W4zxhuQNRY+VuvMrEZ6G8mTuPUbiU27Pfyr6dBRrP 1vr0L4OmXr+vtBi9GyBryPNCLJ3J4BXFEfl/sSHJvVp030XnIpPVxLkmQyWXvqBfkwcd rM8l57B+0j5ZFSsSBMHgHOq9FjOw4QVWSmY1sD8X+wrS7oKwlxUUcoVA3Jezie1+W80E 7ws6CK/37liR1nJrHj8yShyTIQ72v1nb+l0x4fOkWbBJTjKTmO1zmY8r5NWTer8tal2b SI0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@flowbird.group header.s=google header.b="FUCgx68/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flowbird.group Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15si1543811otk.120.2020.01.10.07.46.42; Fri, 10 Jan 2020 07:46:53 -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=@flowbird.group header.s=google header.b="FUCgx68/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flowbird.group Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728355AbgAJPoS (ORCPT + 99 others); Fri, 10 Jan 2020 10:44:18 -0500 Received: from mail-ed1-f98.google.com ([209.85.208.98]:34945 "EHLO mail-ed1-f98.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728265AbgAJPoR (ORCPT ); Fri, 10 Jan 2020 10:44:17 -0500 Received: by mail-ed1-f98.google.com with SMTP id f8so1951157edv.2 for ; Fri, 10 Jan 2020 07:44:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flowbird.group; s=google; h=from:to:cc:subject:date:message-id; bh=e7IY92TT8uEF1NqXhkjC9P1gwmK8Iq+uyMae8G1wu4o=; b=FUCgx68/is4pxqg92nv61jUbkTdzo7UjMjbOPg7uwlk8n2Gt2GVhB904yxL4u5c7WO tbdNKo7sZge/WzCQINHfef2PEFf1pokkHHFEBv2xpXXl/3jvg7HR0bndzbZPCm38e2R1 ch9ARMK9LxRWzWdZV4QDlliHWTS1CF6OQE2fmaaJzIUvahOkrQPviF+5B1T+0Ja662ha HSUeEkz1Zj88aTAzUeaPyNT/hIZEQ9P4/s53JFzJwkqS6Gzadp88bMCSCqyePdOq24Ey Dkm/wobCC7ExErApoIYNihReiU7ZwjU8b8hzfMdB0xSz5rMDBBB5/8I2aKoADmAH9DgV b6Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=e7IY92TT8uEF1NqXhkjC9P1gwmK8Iq+uyMae8G1wu4o=; b=OCWMtPU1NQkzrWr7tOZt/gM+vfC1a7Fv54dDnxNSERnZ7KmTVlU8IZv4/nxFkE+llk E44fRXgZv9Cv7i5M5MXQIfCgmYp7L3Z/Mq3fzglf+uHMF0BNwFifmkqJQiBPuYTx8rFA blSSZzX1792UAbglt6mtS8V3eemG6mP/OBgeOU9G2Ot8XFV6gbd5qY+E8xAXcJ+utpF6 ZyIBOToLNaVZZqucExdDqTCESjZNdLi1/2OgqrfeT1WTkaKw0TIy1bDxA1aHN/ljANoH 0RX5mY73/d2rhd8OlLOG3EsXOQAB20ePLJceYvceKHaVtLYsNBlCkh8yf3Fh0FtK+Wsq QH+g== X-Gm-Message-State: APjAAAUDpNFy8iHSmJNwv2sqatRLWIQ6SqIB/1OT3Mh+CPsv4Sghvgh2 dIqeOme9iO3FpfFKaVYNHD03msIxJoMizrkgbqJkxpA6ArrS X-Received: by 2002:a17:906:27cb:: with SMTP id k11mr3662493ejc.301.1578671055111; Fri, 10 Jan 2020 07:44:15 -0800 (PST) Received: from mail.besancon.parkeon.com ([185.149.63.251]) by smtp-relay.gmail.com with ESMTPS id x1sm17444ejs.70.2020.01.10.07.44.14 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 Jan 2020 07:44:15 -0800 (PST) X-Relaying-Domain: flowbird.group Received: from [10.32.51.181] (port=36758 helo=PC12445-BES.dynamic.besancon.parkeon.com) by mail.besancon.parkeon.com with esmtp (Exim 4.71) (envelope-from ) id 1ipwSM-00031I-K5; Fri, 10 Jan 2020 16:44:14 +0100 From: Martin Fuzzey To: Greg Kroah-Hartman Cc: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH] binder: fix log spam for existing debugfs file creation. Date: Fri, 10 Jan 2020 16:44:01 +0100 Message-Id: <1578671054-5982-1-git-send-email-martin.fuzzey@flowbird.group> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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