Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp841706img; Wed, 20 Mar 2019 12:02:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzn59yWxme06gDvLVVStua+HP5AX8Bl+OZke6I05gM9sCR56OJ75NRKxNMxvMulZYpOczAQ X-Received: by 2002:a63:6193:: with SMTP id v141mr8814846pgb.392.1553108534790; Wed, 20 Mar 2019 12:02:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553108534; cv=none; d=google.com; s=arc-20160816; b=I+J2jQPglxhFAiJg8P9N+nN6aRUlecD9PvJasxYBqSQdhWPf2O1Xa/hoU25uub7zsv X3+lEjWOAYrolTa1f6Z+YfONUxLyOa4Cs7WaxfOecgSKBHeOWyTxWBrR0BYwogSRq1J6 +Wn7Ebey+ApRaJXYvs4EDsB4Av/7BX+G4QKC6sKPOsjMPGB8YC+ZNdv0odim681fBNHk b7XIX5T31tsBxIiIehkWzmWCE9RgCBI52wX0O4vm2PNT+26LPsOOLkKKRBfY6oig+IvT Up8GQVnMBvyECcw0EEwg9XO8r3jutU+DZPE7fJhafqQLQVRk5iD9W6kEsgFCpJiSihEu +P/w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:openpgp:from:references:cc:to :dkim-signature; bh=zcRCVq3B+iwwZzRJrXnuwilWuPQVL4V6o04ieqitPfQ=; b=LnGvppbxD172vWvQm/eLpqZziTKnj89kgLp/CNt5jaD+9wmDhgOsJN/mrrjUbHH0NF V35+k1qGGCB19AhJQtmJwibR3RKuaoDeixqW65PBOXorbm4y/J6NgWccmyRBLlIjKw30 qzDts+PNe7wqIZhBcIn1r5HIU7pZVQlp2cdGnlcaXjBMmCjqWWosyGZWBpptEqI3KsY7 71HsBQWepWyhhDr+DoDOmzJmk+qDt/qbpy3SrybDIw5Kq69tEETupH+aupbQA5k+7NWd +PQuWUnhCOgESg59A0Ga8pwzuhZ5fI1MDoxIUyt9KtScBcTbsU7hCIaykP29exa+9OPz o7fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=VAnn82FZ; 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 t9si2290197pgl.290.2019.03.20.12.01.59; Wed, 20 Mar 2019 12:02:14 -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=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=VAnn82FZ; 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 S1727496AbfCTTBF (ORCPT + 99 others); Wed, 20 Mar 2019 15:01:05 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35579 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727099AbfCTTBF (ORCPT ); Wed, 20 Mar 2019 15:01:05 -0400 Received: by mail-wm1-f66.google.com with SMTP id y197so321896wmd.0 for ; Wed, 20 Mar 2019 12:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=to:cc:references:from:openpgp:autocrypt:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zcRCVq3B+iwwZzRJrXnuwilWuPQVL4V6o04ieqitPfQ=; b=VAnn82FZaA+TzmputmzDuvnrv9DkO+e3kVqRf/9CsVPjSsK7w1oOCIiKvWBqX2nXAM pPN0l4GN5Hqz/sudxKvFQg2z6ep7u6o5s5N20rNC2zn1gXVQ6zlt8tLpfEIqLpo8ljky 2g8DFTjYa/IcBIm3L0XGUaV/jn+QEOBCj0Tu3yC9t7hP9inYbT+ZGgtKl+VRM+iDcJOc BIQrCJVB46y8knCG+lhZIODTXV1sv87iChZ0n6kcLxKKmS0NMBi8OSUZBF/MPh5lpFIq L0KV2kInrD+emk6DSe6yBJAucoKfBz42nSRLEJSkCI72hXvV8mvjxI68f5K0wZ9MTow/ ci/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:openpgp:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=zcRCVq3B+iwwZzRJrXnuwilWuPQVL4V6o04ieqitPfQ=; b=DDbxq8JZDaRqEm0elZHPWD60kj3mto9+wgk3ee5JNEjxRSJYO2Px1Sxanhds8Ndxb2 7VA6X16aCG+tlBiqhHigjYsuBm11nA0evk303rp4myCPp9i4cgDMQAxbI1gIHCiV/7tj I4MPadYtuMCKIRB6cD6c5p+IrtZCeMBNWhhxcqCX/WW1U5nXSgpdsjqjIgb5VnuQhHv7 DBwTSAR5OIkRrULv7ViiK8ZwkxfaHjaPY7tAzHqNTTMnFMz5oQH8knbSNJ2jXQHfcmxW 6FuNzMVTEeasY6Y3NfMai6aBjdnpG2bBK58V3IW3TDVcOkdcdfBZTaor2TZTGoFJJw0q JBHQ== X-Gm-Message-State: APjAAAXsLqph2TX6UkuSHhvBBQIPnsRqdQBdS/MY0prKbdy0SuvgwLlN VuCDrcvQa5br2FdbczFz/EFLKQ== X-Received: by 2002:a1c:4d:: with SMTP id 74mr9029583wma.129.1553108462606; Wed, 20 Mar 2019 12:01:02 -0700 (PDT) Received: from [172.20.1.106] ([217.38.71.146]) by smtp.gmail.com with ESMTPSA id t2sm5487793wra.9.2019.03.20.12.01.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 12:01:01 -0700 (PDT) To: Alban Crequy , ast@kernel.org, daniel@iogearbox.net Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alban@kinvolk.io, iago@kinvolk.io References: <20190320173332.18105-1-alban@kinvolk.io> <20190320173332.18105-4-alban@kinvolk.io> From: Quentin Monnet Openpgp: preference=signencrypt Autocrypt: addr=quentin.monnet@netronome.com; prefer-encrypt=mutual; keydata= mQINBFnqRlsBEADfkCdH/bkkfjbglpUeGssNbYr/TD4aopXiDZ0dL2EwafFImsGOWmCIIva2 MofTQHQ0tFbwY3Ir74exzU9X0aUqrtHirQHLkKeMwExgDxJYysYsZGfM5WfW7j8X4aVwYtfs AVRXxAOy6/bw1Mccq8ZMTYKhdCgS3BfC7qK+VYC4bhM2AOWxSQWlH5WKQaRbqGOVLyq8Jlxk 2FGLThUsPRlXKz4nl+GabKCX6x3rioSuNoHoWdoPDKsRgYGbP9LKRRQy3ZeJha4x+apy8rAM jcGHppIrciyfH38+LdV1FVi6sCx8sRKX++ypQc3fa6O7d7mKLr6uy16xS9U7zauLu1FYLy2U N/F1c4F+bOlPMndxEzNc/XqMOM9JZu1XLluqbi2C6JWGy0IYfoyirddKpwzEtKIwiDBI08JJ Cv4jtTWKeX8pjTmstay0yWbe0sTINPh+iDw+ybMwgXhr4A/jZ1wcKmPCFOpb7U3JYC+ysD6m 6+O/eOs21wVag/LnnMuOKHZa2oNsi6Zl0Cs6C7Vve87jtj+3xgeZ8NLvYyWrQhIHRu1tUeuf T8qdexDphTguMGJbA8iOrncHXjpxWhMWykIyN4TYrNwnyhqP9UgqRPLwJt5qB1FVfjfAlaPV sfsxuOEwvuIt19B/3pAP0nbevNymR3QpMPRl4m3zXCy+KPaSSQARAQABtC1RdWVudGluIE1v bm5ldCA8cXVlbnRpbi5tb25uZXRAbmV0cm9ub21lLmNvbT6JAj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xBhWGuZ9CpBuXjtPrnRSd8xdrw36AL53goTt/NiLHUd RHhSHGnKaQ6MfrTge5Q0h5A= Subject: Re: [PATCH bpf-next v1 4/7] tools: bpftool: implement map exec command Message-ID: <391274e4-7634-a1ac-5969-02403abd77ac@netronome.com> Date: Wed, 20 Mar 2019 19:01:01 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <20190320173332.18105-4-alban@kinvolk.io> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2019-03-20 18:33 UTC+0100 ~ Alban Crequy > From: Alban Crequy > > The map exec commands allows to open an existing map and pass the file > descriptor to a child process. This enables applications to use an > existing BPF map even when they don't support bpffs. > > Example of usage: > # bpftool map exec pinned /sys/fs/bpf/foo fd 99 cmd -- readlink /proc/self/fd/99 > anon_inode:bpf-map > > Documentation and bash completion updated as well. > > Signed-off-by: Alban Crequy > --- > .../bpf/bpftool/Documentation/bpftool-map.rst | 11 ++++ > tools/bpf/bpftool/bash-completion/bpftool | 22 +++++++- > tools/bpf/bpftool/map.c | 53 +++++++++++++++++++ > 3 files changed, 85 insertions(+), 1 deletion(-) > > diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst b/tools/bpf/bpftool/Documentation/bpftool-map.rst > index b685641bfd74..dfd8352fa453 100644 > --- a/tools/bpf/bpftool/Documentation/bpftool-map.rst > +++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst > @@ -30,6 +30,7 @@ MAP COMMANDS > | **bpftool** **map getnext** *MAP* [**key** *DATA*] > | **bpftool** **map delete** *MAP* **key** *DATA* > | **bpftool** **map pin** *MAP* *FILE* > +| **bpftool** **map exec** *MAP* **fd** *FD* **cmd** -- *CMD* > | **bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*] > | **bpftool** **map peek** *MAP* > | **bpftool** **map push** *MAP* **value** *VALUE* > @@ -101,6 +102,10 @@ DESCRIPTION > contain a dot character ('.'), which is reserved for future > extensions of *bpffs*. > > + **bpftool map exec** *MAP* **fd** *FD* **cmd** -- *CMD* > + Load map and exec an external command, passing the file > + descriptor. > + Please use tabs for indent. Could you please add a line to explain that the process spawned get the the link to the map in the file descriptor passed as *FD*? I'm being pedantic, I know it's not that hard to understand with the examples, just trying to make things as clear as possible for users reading the page. I have nothing against the double dash in the examples or the commit log, but putting it in the description in the command itself makes it look like it is some kind of mandatory syntax. Would you consider removing the occurrences above? We don't really "exec" the map... Just thinking... Would another keyword like "pass" or "passfd" be more relevant? > **bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*] > Read events from a BPF_MAP_TYPE_PERF_EVENT_ARRAY map. > > @@ -254,6 +259,12 @@ would be lost as soon as bpftool exits). > key: 00 00 00 00 value: 22 02 00 00 > Found 1 element > > +**# bpftool map exec pinned /sys/fs/bpf/foo fd 99 cmd -- readlink /proc/self/fd/99** > + > +:: > + > + anon_inode:bpf-map > + > SEE ALSO > ======== > **bpf**\ (2), > diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool > index 9e37de8bb227..63cd53c4d3a7 100644 > --- a/tools/bpf/bpftool/bash-completion/bpftool > +++ b/tools/bpf/bpftool/bash-completion/bpftool > @@ -583,6 +583,26 @@ _bpftool() > fi > return 0 > ;; > + exec) > + case $prev in > + $command) > + COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) ) > + return 0 > + ;; > + fd) > + return 0 > + ;; > + cmd) > + COMPREPLY=( $(compgen -c -- "$cur" ) ) > + return 0 > + ;; > + *) > + _bpftool_once_attr 'fd' > + _bpftool_once_attr 'cmd' > + return 0 > + ;; > + esac > + ;; > event_pipe) > case $prev in > $command) > @@ -610,7 +630,7 @@ _bpftool() > [[ $prev == $object ]] && \ > COMPREPLY=( $( compgen -W 'delete dump getnext help \ > lookup pin event_pipe show list update create \ > - peek push enqueue pop dequeue' -- \ > + peek push enqueue pop dequeue exec' -- \ > "$cur" ) ) > ;; > esac > diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c > index a576f2a019be..768497364cee 100644 > --- a/tools/bpf/bpftool/map.c > +++ b/tools/bpf/bpftool/map.c > @@ -883,6 +883,58 @@ static int do_update(int argc, char **argv) > return err; > } > > +static int do_exec(int argc, char **argv) > +{ > + struct bpf_map_info info = {}; > + __u32 len = sizeof(info); > + int fd, ret; > + __u32 outfd = 0; Reverse-Christmas tree. > + > + if (argc < 2) > + usage(); > + > + fd = map_parse_fd_and_info(&argc, &argv, &info, &len); > + if (fd < 0) > + return -1; > + > + while (argc) { > + if (is_prefix(*argv, "fd")) { > + if (parse_u32_arg(&argc, &argv, &outfd, > + "out fd")) > + return -1; > + } else if (is_prefix(*argv, "cmd")){ > + NEXT_ARG(); > + if (!REQ_ARGS(1)) > + return -1; > + > + break; > + } else { > + p_err("unknown arg %s", *argv); > + return -1; > + } > + } > + > + if (outfd == 0) { > + p_err("invalid fd"); > + return -1; > + } > + if (*argv == NULL) { > + p_err("empty command"); > + return -1; > + } > + > + Spurious blank line. > + ret = dup2(fd, (int)outfd); > + if (ret == -1) { > + p_err("dup2 failed: %s", strerror(errno)); > + return -1; > + } > + > + execvp(argv[0], argv); > + p_err("execvp failed: %s", strerror(errno)); > + return -1; > +} > + > static void print_key_value(struct bpf_map_info *info, void *key, > void *value) > { > @@ -1355,6 +1407,7 @@ static const struct cmd cmds[] = { > { "enqueue", do_update }, > { "pop", do_pop_dequeue }, > { "dequeue", do_pop_dequeue }, > + { "exec", do_exec }, > { 0 } > }; > > Please also add the new command in the interactive help (do_help()). By the way, I like this new command a lot!