Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2875986ybl; Thu, 29 Aug 2019 14:19:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxy3r/R/fY40ZTAXp9jSY8TTF5jygzxhbrvZ8POH00EO3iYb/itCSK+ntQuVRiYfX4ldEKm X-Received: by 2002:a17:902:1126:: with SMTP id d35mr12170663pla.330.1567113594724; Thu, 29 Aug 2019 14:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567113594; cv=none; d=google.com; s=arc-20160816; b=JYs9l2g/85pWwElGIv/GSweH1icJARPkmNEkTRRycBRtVkS7ec3/58Sex0xy3e10p6 S5BzjDuFbDL3h6JEZAl330Kky+t1hoPsUOW7T0lX2dCrgdF4Oewzfw4Zm0/nPk5vTXYP u6dpw/0L1nOfPiUn3ii7Q+vVXlRdTW/vQPYyEWGsukUyMgoItQMHagzEwxW3nJjc9zlc EjePW91xlohmXApaFyhX4AAS5y0fjVvY46aKGQHHgVcGYbiWs3LlAJ9fl1LhM8gk69Wf BPyElG0cRH9ba8WuXZn7dWipGVLmbCksL7eF76qocoPXCS3QwOoFOj+VlRnSOp87qZiX hz2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=x8dW1eobv46xxf8Qk5whq589HTl41TDtcRbBhNUlvgA=; b=uHRmqxaJ7iRIz0RnJwdZ0InmmZpdCK+qux+IBiCxVgRS2S3ZhgJSCdKVQd2PufydtF DBTtTdnJwJt7Y6hQpYM9jPaoc3LZjSpy/Jvx30Y1hymPDVDVISVJvhBoFcKSOvcTN0UP qFCV4PqqspKZF0Vdkekn0B21Sc9+RoOhn9NrbNNOrgha86hngrErG6soDwpz2CVLOLFL 5U2fxIKbSqhRRfKhIWZCRKN85wtaLEP/XbxqXDpkp8ONnL9C8ZhbMEKjOHomasSKZ1C5 wyfaYZVuwlXpwdpUca/EHwU/qHSIctjcQStzOh0jSMlsSz5fiIOeKe5qvFxBQC+6Oaha KFTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oq2JuZDP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t27si2820929pgk.502.2019.08.29.14.19.38; Thu, 29 Aug 2019 14:19:54 -0700 (PDT) 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=@google.com header.s=20161025 header.b=oq2JuZDP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728129AbfH2VSg (ORCPT + 99 others); Thu, 29 Aug 2019 17:18:36 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:36321 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726935AbfH2VSg (ORCPT ); Thu, 29 Aug 2019 17:18:36 -0400 Received: by mail-qt1-f201.google.com with SMTP id 38so4870879qtx.3 for ; Thu, 29 Aug 2019 14:18:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=x8dW1eobv46xxf8Qk5whq589HTl41TDtcRbBhNUlvgA=; b=oq2JuZDPnrdiEZUE2201QMFcPToj3KIqIsam0bd9PtbV9C8qAhCC8foVP5ylX6dGKL BBWR7VUAqiKgeeKCsgQ1BKpieXF7anfbAMDMBYWPlRwQGdN5k4ShEN9Mw0kmgncqn9KI 3t0EOOrM2ajTMkjOLBz+/g4HFjQUFoSi1FVXi10rPtdPJtcHOlVZgjAgAuLsV7qk7WJM 8qaSNXQK/8uTVObl+Bp5exKBPfBRKP6fQrB10oPqJdP6EnqpyfywdkEd3TeR6FlLE8xu rfO+t2Nag8LvY+1+T1jX4NaFnZ94x/AJyebaxzxb5+d7nMGKAZLWs1a2exi4QzB9O7nu PqNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=x8dW1eobv46xxf8Qk5whq589HTl41TDtcRbBhNUlvgA=; b=fjTjfgNI1vSPLDzenFP8ZpYL9Ft957a304Fw5cSkRbtQl+YnfHjrvvhbQBoSvfe188 4UMxA4OmQmT9vuZe2qOoT6KLt5Gt+PQ9HFvaZdS4XTQrgVXE7XIMXUBvVAKJjJjtMX9n 9wJvLuhMH+iZT5nuUVnyWZjR1sSf5+mwdZTs+aWAAaIaPt+w0Gk8Pq+lGzB9QO4lPD8j Sxxrn2SFBxkSxNjuV1YuE1VSoA4C9o91dsY84nQYq9UnxN42tAzQOv0sdYj4jVU7B6xG trcssZAfq5gGghkXTzRRr31i6qT/Y8ARxh4bKcrNw9OSgDJyaCyxaQA1duIkpXM/Mc0H xQHg== X-Gm-Message-State: APjAAAUegEeIEzFRiSbUtEc8s3f5ysbF4CS4Sgtt5wWBEkMoAX9dTcq1 C5JRxow1SHikG6uHa7HsbJDUVhIxops= X-Received: by 2002:a0c:fa89:: with SMTP id o9mr8142896qvn.165.1567113514869; Thu, 29 Aug 2019 14:18:34 -0700 (PDT) Date: Thu, 29 Aug 2019 14:18:09 -0700 In-Reply-To: <20190829211812.32520-1-hridya@google.com> Message-Id: <20190829211812.32520-2-hridya@google.com> Mime-Version: 1.0 References: <20190829211812.32520-1-hridya@google.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog Subject: [PATCH v2 1/4] binder: add a mount option to show global stats From: Hridya Valsaraju To: Greg Kroah-Hartman , "=?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 Cc: kernel-team@android.com, Hridya Valsaraju Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, all binder state and statistics live in debugfs. We need this information even when debugfs is not mounted. This patch adds the mount option 'stats' to enable a binderfs instance to have binder debug information present in the same. 'stats=global' will enable the global binder statistics. In the future, 'stats=local' will enable binder statistics local to the binderfs instance. The two modes 'global' and 'local' will be mutually exclusive. 'stats=global' option is only available for a binderfs instance mounted in the initial user namespace. An attempt to use the option to mount a binderfs instance in another user namespace will return an EPERM error. Signed-off-by: Hridya Valsaraju --- Changes in v2: - Improve error check in binderfs_parse_mount_opts() as per Greg Kroah-Hartman. - Change pr_info() log before failure to pr_err() as per Greg Kroah-Hartman. drivers/android/binderfs.c | 45 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index cc2e71576396..7045bfe5b52b 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -51,18 +51,27 @@ static DEFINE_IDA(binderfs_minors); /** * binderfs_mount_opts - mount options for binderfs * @max: maximum number of allocatable binderfs binder devices + * @stats_mode: enable binder stats in binderfs. */ struct binderfs_mount_opts { int max; + int stats_mode; }; enum { Opt_max, + Opt_stats_mode, Opt_err }; +enum binderfs_stats_mode { + STATS_NONE, + STATS_GLOBAL, +}; + static const match_table_t tokens = { { Opt_max, "max=%d" }, + { Opt_stats_mode, "stats=%s" }, { Opt_err, NULL } }; @@ -290,8 +299,9 @@ static void binderfs_evict_inode(struct inode *inode) static int binderfs_parse_mount_opts(char *data, struct binderfs_mount_opts *opts) { - char *p; + char *p, *stats; opts->max = BINDERFS_MAX_MINOR; + opts->stats_mode = STATS_NONE; while ((p = strsep(&data, ",")) != NULL) { substring_t args[MAX_OPT_ARGS]; @@ -311,6 +321,22 @@ static int binderfs_parse_mount_opts(char *data, opts->max = max_devices; break; + case Opt_stats_mode: + if (!capable(CAP_SYS_ADMIN)) + return -EINVAL; + + stats = match_strdup(&args[0]); + if (!stats) + return -ENOMEM; + + if (strcmp(stats, "global") != 0) { + kfree(stats); + return -EINVAL; + } + + opts->stats_mode = STATS_GLOBAL; + kfree(stats); + break; default: pr_err("Invalid mount options\n"); return -EINVAL; @@ -322,8 +348,21 @@ static int binderfs_parse_mount_opts(char *data, static int binderfs_remount(struct super_block *sb, int *flags, char *data) { + int prev_stats_mode, ret; struct binderfs_info *info = sb->s_fs_info; - return binderfs_parse_mount_opts(data, &info->mount_opts); + + prev_stats_mode = info->mount_opts.stats_mode; + ret = binderfs_parse_mount_opts(data, &info->mount_opts); + if (ret) + return ret; + + if (prev_stats_mode != info->mount_opts.stats_mode) { + pr_err("Binderfs stats mode cannot be changed during a remount\n"); + info->mount_opts.stats_mode = prev_stats_mode; + return -EINVAL; + } + + return 0; } static int binderfs_show_mount_opts(struct seq_file *seq, struct dentry *root) @@ -333,6 +372,8 @@ static int binderfs_show_mount_opts(struct seq_file *seq, struct dentry *root) info = root->d_sb->s_fs_info; if (info->mount_opts.max <= BINDERFS_MAX_MINOR) seq_printf(seq, ",max=%d", info->mount_opts.max); + if (info->mount_opts.stats_mode == STATS_GLOBAL) + seq_printf(seq, ",stats=global"); return 0; } -- 2.23.0.187.g17f5b7556c-goog