Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp504877img; Thu, 21 Mar 2019 02:59:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwy66sbl44AHGnKziG6GH0xkSe/Oz98iXj5DesuEx4LiNR34LH1BbD2O8gF938vs5zLdnOk X-Received: by 2002:a17:902:586:: with SMTP id f6mr2596484plf.68.1553162360372; Thu, 21 Mar 2019 02:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553162360; cv=none; d=google.com; s=arc-20160816; b=g0PmB8BH1dR21F8ykGwOBt0Dhb2LCekvqMNVWyJzO6zQ033cVHa4UXNuM42mJ6OYjz GqKyDRZgopff2eQVUbfYEBKwtMmujKO19TftfYtzLyAuot4hyRPK//h0SVvpAqg65FcQ U4H0V7H1fmZ+XqcxoWV9vJjyssGgL8GK9OisZY3iIW/JYcDRgsfB7ueKIsITRSDolOd8 JGd4LG+Mnvlj2GrUCTvlQWvUrFt7rDd/7P7idR8cGXiThENLkCkUbG4oOc40gGiAjDjd Jvqvwkajz3Z4dwGw+YIN+IR1oWaULX210/kVuDwk2U9UZAxNK1/IJ4jtcPqZzyPR20i+ dkmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vHpSHzt5NHpVPS+Oump3k8LaMq2C3znc7HaOk8IZ0jU=; b=YbCIFYYic9r1zSJR0D/fEldmzmfXjs1KPiQtmC8rFcM845UlDBKs0EjbE/waX+IZf6 7K9He/VamBThd+XbyMyf+g6JGEhL1LtjwoQCGnVW9cpFwe5o3YIUyqjTjHJt73BnIlTs qME/SINPOfAv1pYKSyPFM73+HqZjjtGs00pR3sN1cQMLQ48QPlQPUqOwJsTEmmJpEjXB 9TakDHwsDvyUp8jAEH7rhf3qmreobPh1F9NDKXSCKU/bHuZM/sEtf51jpXqqklJcR/AO 2jW5pdzOUUP5AoyDtrViOqRNkEF3ExvUAt8sSz6yKLnUu4RplOWuHrJuWX7yRMHcAnx5 vtRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kinvolk.io header.s=google header.b=Zbwd6lRw; 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 r7si3704999pfn.144.2019.03.21.02.59.02; Thu, 21 Mar 2019 02:59:20 -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=@kinvolk.io header.s=google header.b=Zbwd6lRw; 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 S1728300AbfCUJ5p (ORCPT + 99 others); Thu, 21 Mar 2019 05:57:45 -0400 Received: from mail-ot1-f65.google.com ([209.85.210.65]:45997 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727892AbfCUJ5o (ORCPT ); Thu, 21 Mar 2019 05:57:44 -0400 Received: by mail-ot1-f65.google.com with SMTP id e5so3873264otk.12 for ; Thu, 21 Mar 2019 02:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kinvolk.io; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vHpSHzt5NHpVPS+Oump3k8LaMq2C3znc7HaOk8IZ0jU=; b=Zbwd6lRwwOgLY40BiW5v1/GNCPVeznZQvbIpgXsvSa2suE1fJa0JJhgS49FwtFJqwF pnn+93jdrvMeTw23XaB+uJE9mRMm6RWdgbMy1Bo0O9bawomDAI7aPngLl2epX6NtJ0QI dy2RatDWDrKbmYiSRjrEJrlCB9r/MUlDiy2lE= 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=vHpSHzt5NHpVPS+Oump3k8LaMq2C3znc7HaOk8IZ0jU=; b=Nbufq9FROEkGnC/vw0u8QDb6G/nxtBg5yMFhH+d12JpTwWWcLqyPoQO947vhki3860 /b236UGTMAlfLULglBh2OqEyoZMu8TQYcw6Dm8Wac7WDr3EDaCcdaKi71r4wRGEA2fKp 1KAPEooyWVVQibiYg5vQd0Pj+tUtHr6nruEZCRMdeVf9Q/kyMX6hr0B4htdiTzJQdAQQ 6+yv9KutUU0eLz8li/m1Qw37NNuf4OPcKxfvGfALSxVl6umWXmwqYywAjVdUemdMv+am HZY5vy40F8hE7W4jHbU9NqqdVnlFT0PaUw6q6h3beC8xMfSZrQRMKqvU9DNtTSzBwzR0 1uBA== X-Gm-Message-State: APjAAAW+inpUCYa2E4bfqW0DTUYA0jrSZ1WiFs0so1thw7W25s37KE8l MtJC8VxOVTHeHVldR/Cb4b9cUpmHQzV00NhsYHLH7g== X-Received: by 2002:a9d:7f89:: with SMTP id t9mr1784851otp.169.1553162263800; Thu, 21 Mar 2019 02:57:43 -0700 (PDT) MIME-Version: 1.0 References: <20190320173332.18105-1-alban@kinvolk.io> <20190320173332.18105-4-alban@kinvolk.io> <20190320142346.3b552895@cakuba.netronome.com> In-Reply-To: <20190320142346.3b552895@cakuba.netronome.com> From: Alban Crequy Date: Thu, 21 Mar 2019 10:57:32 +0100 Message-ID: Subject: Re: [PATCH bpf-next v1 4/7] tools: bpftool: implement map exec command To: Jakub Kicinski Cc: Alban Crequy , Alexei Starovoitov , Daniel Borkmann , netdev , LKML , =?UTF-8?Q?Iago_L=C3=B3pez_Galeiras?= 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 On Wed, Mar 20, 2019 at 10:23 PM Jakub Kicinski wrote: > > On Wed, 20 Mar 2019 18:33:29 +0100, Alban Crequy wrote: > > 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 > > Would you mind telling us a little more about the use for this feature? > It seems fairly limited. If it's about probing objects (finding out if > they are a map or a program) perhaps we can add a command just for that? I needed to know the name of the map too. I was preparing a demo based on python bcc tools (opensnoop) but with added feature that requires using a pinned map, created and maintained externally. At the moment, the python API for bcc does not support pinning or using external maps. Ideally, this should be added in the python API (some discussion on https://github.com/iovisor/bcc/issues/2223) but meanwhile, I use a workaround by executing bpftool from the python code. Arguably, my use case is a temporary hack until we have better support in python bcc. But other tools implements similar commands to pass file descriptors between processes: "ip netns exec" and "tc exec bpf". So I think it could be useful for other scripting use cases. In my demo, I used the two hacks: - if the pinned map fd is not given to the python script, re-execute itself with bpftool: os.execvp("bpftool", ["bpftool", "map", "exec", "pinned", pin_path, "fd", "90", "cmd", "--"] + sys.argv) - once we have the fd 90 (number specified above) of the pinned map in the python script, overwrite the empty fd created by bcc: os.dup2(90, 6) I call dup2() between the bpf map creation and the bpf program creation. To check which map fd to overwrite, I just call os.system("bpftool map show fd 6..."). Thanks a lot for the reviews. I'll need some time to address it (maybe a week or 2). > (I guess bpftool -f isn't really the cleanest way of getting at that > info.) > > > Documentation and bash completion updated as well. > > > > Signed-off-by: Alban Crequy