Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp812043pxv; Fri, 9 Jul 2021 09:33:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYjWju1P0bPZXf6Na0w2D8pKzLC3oSVI2AEgWH1wl/CXWcI1KLBBoophZDQb3G+wiDdmzK X-Received: by 2002:a05:6e02:b4a:: with SMTP id f10mr27865360ilu.280.1625848409857; Fri, 09 Jul 2021 09:33:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625848409; cv=none; d=google.com; s=arc-20160816; b=pg1g0ssqV5pYl7i7FZrypgTsL62Sp0DlY69OOWqkABQ+6IVaizXspoEdUTp4ZZxSYE CFSkhy3Pen5AJisenuLSNVNLmDaOFUFgecxTqveRhiMqhL1q/ldJWPVuu+GfDmZKd32S 0rTPg3qBRY1JDQKTUjLldd0W2N1e3S3qLg3VpOf+0XWfb5LUqf/iPTluQh6cPBAHrKmM 9FDQdIHAqRw2cIcD3G+xY2rzRt3Idx3OQsMVozpwB2g4C4h4K3GcX3WaI4EaSc5sOWmd RToR+73SQ/ScIb9Se+f+j+vE6XGFfqqCFFtPfmotLWlnwDnn2XX8PegIM2YdQeSgoR7j 9Zpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vO8Sr6hsS6w6E2PiDmqu8K8jLh8340IFcgCMK9Q53eg=; b=JQ++Tw0erex3sTDPp459L3xdIskQqLV6aHHfBFuMJvk8ddOO8oWidk1oFvlvZ6gaCr 6w/wuIDpXYhztPYKxsV69abN9ylPWXpqv0rRws4cCFjZlqB+Wzh4/xzWWLeEPQw1NUuE ttQKOqIiccyaoFeLSzZg40kosB+JtFc2isFGXgto3mJJ5d9dWBcZwFlL5GQB9BtRVKSj O7b8HTfTdk0gUjRaV+qMH6ozBW4IcC63VxEqcoFY13Qqrr0QhnSoF4BL3VOuKEgr84dC jE5JW4GWzfCCa6eI4r6tvLZPDH5j8Lo3eLh/jT4EJOBQ9lM+rvdG5Lu+HjnwXf8dTiDL /JIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GXvKBVfb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id w5si7130833ilh.139.2021.07.09.09.33.18; Fri, 09 Jul 2021 09:33:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GXvKBVfb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229535AbhGIQfN (ORCPT + 99 others); Fri, 9 Jul 2021 12:35:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbhGIQfL (ORCPT ); Fri, 9 Jul 2021 12:35:11 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DBD2C0613DD for ; Fri, 9 Jul 2021 09:32:27 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id b13so15581980ybk.4 for ; Fri, 09 Jul 2021 09:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vO8Sr6hsS6w6E2PiDmqu8K8jLh8340IFcgCMK9Q53eg=; b=GXvKBVfbU3Q6MECdvqq54c6yO9nYvnkQsqBL/Drgc0ldCyNujDJlCHgVAsT3ZNPjx6 Mnd7T3gW4T2VM3bnwYpJu8ganttdwGi3whFHJMYLEnDK4T5tUJLmpwyEF8KVm0ixULsH rkM2HmYcw1y8J6Ya6M2JNqud0hyRg+l2pNTqfHwzW6SCG7XLDoQqlSxydWRewSzHvc2l HZdmLoTlRxiFiVdB0hR+zPIWsd0hTUxSEcNKRYWKlB6CWy6VAxQ6+zQIs0K3IFIrRoRR R37FwqmnUD/+wvV+ZRKod9fpu7rRSCKMLAcPfq3byh/ZHuxrvSsQLefKQXzdpiSU8YdT yaxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vO8Sr6hsS6w6E2PiDmqu8K8jLh8340IFcgCMK9Q53eg=; b=DbxGz+eudt/bUjqpcHLs6basj4bpOFpwCsPbt4j7XD+kuDeZWGuvXLbAlJZ5xElIXz KtO00PDr423IjaxwO2EZKsuMa5gAEO8koh3RMNYlsWvR1g6deM5ObSn1qeW6nFyECBrl 92bATMlBZddtESc6nfuwEJbbTrYsmbJ18J1pmIjNFvHfW82yTnTkUz48pitCsjc6YBuC PkdQK/ItPuFjezY36Dim9LS7pdHLhGijToBpbzWBUAhkDckY5wulbCj6vxdIFxxkQW1l Mpw95+qkoFZ1XhG872ZotJCWrKcn5zLzlkQuy7K+EGHZWKqx7RYLPyAdcD83WyokPHHD qnww== X-Gm-Message-State: AOAM5326Zvz/XMX2NXciuOtkw/59VN5K5jDQLm4zY02u5G3OcY2PH/+S mHschqHPFNCbVSdh51posjYx9NcuKOYv79VgP92GuA== X-Received: by 2002:a25:4212:: with SMTP id p18mr5274514yba.346.1625848346342; Fri, 09 Jul 2021 09:32:26 -0700 (PDT) MIME-Version: 1.0 References: <20210707162419.15510-1-cmllamas@google.com> <20210709085557.2bx2vojtyw23jzch@wittgenstein> In-Reply-To: <20210709085557.2bx2vojtyw23jzch@wittgenstein> From: Carlos Llamas Date: Fri, 9 Jul 2021 10:32:14 -0600 Message-ID: Subject: Re: [PATCH] ANDROID: binderfs: add capabilities support To: Christian Brauner Cc: Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Christian Brauner , Joel Fernandes , Steven Moreland , kernel-team@android.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 9, 2021 at 2:56 AM Christian Brauner wrote: > > On Wed, Jul 07, 2021 at 04:24:19PM +0000, Carlos Llamas wrote: > > Provide userspace with a mechanism to discover binder driver > > capabilities to refrain from using these unsupported features > > Hey Carlos, > > The model will be one file per feature? Yes. I dropped a previous single bitmask file idea per Greg's suggestion. The file per feature improves on a number of areas such as feature count limit, readability and it's easier to manage (add/remove features). > > Instead of calling the directory "caps" should this maybe be called > "features"? I'm not fuzzed about it and if you want to keep "caps" > that's fine. The term is just a bit overused and makes me think of other > things than this. I have no problems switching over to "features". > > > in the first place. Note that older capabilities are assumed > > to be supported and only new ones will be added. > > What if you ever want to deprecate one? :) If the file for a feature doesn't exist then such feature is not supported. So we can avoid creating such file if a feature were to be deprecated. > > > > > Signed-off-by: Carlos Llamas > > --- > > drivers/android/binderfs.c | 45 ++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 45 insertions(+) > > > > diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c > > index e80ba93c62a9..f793887f6dc8 100644 > > --- a/drivers/android/binderfs.c > > +++ b/drivers/android/binderfs.c > > @@ -58,6 +58,10 @@ enum binderfs_stats_mode { > > binderfs_stats_mode_global, > > }; > > > > +struct binder_capabilities { > > + bool oneway_spam; > > +}; > > + > > static const struct constant_table binderfs_param_stats[] = { > > { "global", binderfs_stats_mode_global }, > > {} > > @@ -69,6 +73,10 @@ static const struct fs_parameter_spec binderfs_fs_parameters[] = { > > {} > > }; > > > > +static struct binder_capabilities binder_caps = { > > + .oneway_spam = true, > > I know this is the oneway spam _detection_ feature but this file makes > it sound like the binder driver has the capability to generate one-way > spam. :) Maybe name at least name the file "oneway_spam_detection". That's true. I'll rename it as suggested. > > > +}; > > + > > static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb) > > { > > return sb->s_fs_info; > > @@ -583,6 +591,39 @@ static struct dentry *binderfs_create_dir(struct dentry *parent, > > return dentry; > > } > > > > +static int binder_caps_show(struct seq_file *m, void *unused) > > +{ > > + bool *cap = m->private; > > + > > + seq_printf(m, "%d\n", *cap); > > + > > + return 0; > > +} > > +DEFINE_SHOW_ATTRIBUTE(binder_caps); > > + > > +static int init_binder_caps(struct super_block *sb) > > You can drop the goto here and just always return directly. I also noticed this and I decided to keep it consistent with init_binder_logs() structure. But I don't have a strong preference so I'll switch to early returns. > > > +{ > > + struct dentry *dentry, *root; > > Please name this "dir" instead of "root". "root" is conventionally used > for sb->s_root and especially here in this file I only ever used it to > indicate s_root. ok, sounds good. > > > + int ret = 0; > > + > > + root = binderfs_create_dir(sb->s_root, "caps"); > > + if (IS_ERR(root)) { > > + ret = PTR_ERR(root); > > return PTR_ERR(root); > > > + goto out; > > + } > > + > > + dentry = binderfs_create_file(root, "oneway_spam", > > + &binder_caps_fops, > > + &binder_caps.oneway_spam); > > + if (IS_ERR(dentry)) { > > + ret = PTR_ERR(dentry); > > return PTR_ERR(root); > > > + goto out; > > + } > > + > > +out: > > + return ret; > > +} > > + > > static int init_binder_logs(struct super_block *sb) > > { > > struct dentry *binder_logs_root_dir, *dentry, *proc_log_dir; > > @@ -723,6 +764,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc) > > name++; > > } > > > > + ret = init_binder_caps(sb); > > + if (ret) > > + return ret; > > + > > if (info->mount_opts.stats_mode == binderfs_stats_mode_global) > > return init_binder_logs(sb); > > > > -- > > 2.32.0.93.g670b81a890-goog > > thanks, carlos llamas