Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp28454img; Thu, 21 Mar 2019 13:17:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQtbyJX2IEaFB8Ckw4pnHbwd+ByiXAgxM+8QUUtkPpmEYDE2Vl+kHxTvv+8Z7i75/agAdv X-Received: by 2002:a63:5325:: with SMTP id h37mr4917148pgb.353.1553199459811; Thu, 21 Mar 2019 13:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553199459; cv=none; d=google.com; s=arc-20160816; b=WUoqYsSOYJJ6PjRCu21hCi4DK74koTnXCLHEItN7qikhg2mUWgbNGdD9LGKqcEDwXV CgwifSfyEdxpKpPgB9LYmbXRbQuvYIsBHx1yEnWI4jkSRwI7D54x3t7vF/5+1p5rBhIN cP+TNU+uTKxX24vlBtnqrmpTlE77W22aNlS5Rd0JObUX5xOAqSCCXda3IshD5IXJfRSZ vVrJ5JK6nO5vr0ZV2LVbwkkmOVnNP1koKBqsccij9nz3DHCrF2WziF6/az5lXLuSrnTy lZjBoG/e9El2Xs5dzYvcKrBA63AQHcFZReoXVX1KwCgOpUSs7hbkqYj6JtBLmPSnEVVD EcTw== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=TZutz0HSRXq5ErCpqJa4uDbIJRNEZqu0EunDY52N++0=; b=xsVam/ImiR9yrVJ92tr41jihXSn7J6f0tnM9/b6P+U2UIph5TQcebXDdDA8LAtYk1S zB5BUCI9dNJ2tbzRoikmtFBHxrDruHYgOmiUzjFNevNehhqqfqUrwAdCl8VCQlcIrVsZ d6XQxkojasFsAceugHKlcJxnDVOaAIlF0apJrs7XC7u5X0u2bpl1FZtPeKDV2zxVx+My 4xeyr1gPFaTYhd9WxiTnQRI1rED3KTUcPaS0tVeJvccNN76kNMZ7rVCor2N/JuyW+K2W WeiwNp6oIF8rBqzJpUL5sV2gXUAwxX7E/pXH1sGvOkIvKga9psGDPI9s0tCkc3FZW3qU pTNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=saVgs75x; 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 33si5240632ply.361.2019.03.21.13.17.19; Thu, 21 Mar 2019 13:17:39 -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=saVgs75x; 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 S1728712AbfCUUQN (ORCPT + 99 others); Thu, 21 Mar 2019 16:16:13 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:38647 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728316AbfCUUQN (ORCPT ); Thu, 21 Mar 2019 16:16:13 -0400 Received: by mail-qk1-f194.google.com with SMTP id g1so12911642qki.5 for ; Thu, 21 Mar 2019 13:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=TZutz0HSRXq5ErCpqJa4uDbIJRNEZqu0EunDY52N++0=; b=saVgs75xs/p55sqZXVUuu7J1pH8F37lUPJYRLpSnRXLoZZGh8O5tzqyTyXFxsmRads FG+qTs3P3DN9iyeUbqazqfZ5LXmB7aftSgnvaaFuUYUc9ay1IFMLpLu3fh9BklqWDn53 TPs4RSsAqLHZVIjHDg+9rm8pqlMgUqGMEjrYmKcq3HC7dZpMCGi2UpEuDbDWZP+evWhC qF+5xFYYNT/JvEkoxRzX/bVfSF/UeT2fbN1ISSrWnysWrTf6csI7jXUuShSuzB6A9zNI 1ZFECREmgiKoH63GVh+MULr++Z8IR8BpNVMq58cwutBAR7cQW8MczH3l8a47Wk4YVAF8 e5GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=TZutz0HSRXq5ErCpqJa4uDbIJRNEZqu0EunDY52N++0=; b=gpNmlegyAIL8TnlzjZUk46iYeaO2qLhAAQ0R7IejjAChotZHCWQggLpQ9Rlr0yyPd0 GlZ9LH0r+WZzBnQCx+j7NWdNF7RiJexBJxSeW4GVJWAJUnf5lSViYc249jXFTjCdoYMs +3AQBcx4xI1gtMxtDUUBQ1q+iGqMFEpsG3oM0vE4yShaZ7waIZpG46vy0QntZDcuT3Ek zubfI8131CYqfsIYyWwqIsBhw+/0Yq7+heiyQswNH5ZqLnCN5u1hkTIIccXgRQcr1x/m NohmIoocT2VRwXj9cZO1f9a8wOJ3GSXZ0eX/Ypr4zL9IlQV7ki/9zcgvv2om23DdVb7B Ehqw== X-Gm-Message-State: APjAAAVivAGCcvKq+UACLWIwFn9RNpc+HRKSSBO1QgYiRAHxO9Xru2iS /m77Aw6wWwQ/dEWPLlLiWplq2g== X-Received: by 2002:a37:aa8c:: with SMTP id t134mr4283678qke.93.1553199371893; Thu, 21 Mar 2019 13:16:11 -0700 (PDT) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id s5sm3415511qkf.87.2019.03.21.13.16.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Mar 2019 13:16:11 -0700 (PDT) Date: Thu, 21 Mar 2019 13:16:06 -0700 From: Jakub Kicinski To: Alban Crequy Cc: Alban Crequy , Alexei Starovoitov , Daniel Borkmann , netdev , LKML , Iago =?UTF-8?B?TMOzcGV6?= Galeiras Subject: Re: [PATCH bpf-next v1 4/7] tools: bpftool: implement map exec command Message-ID: <20190321131606.2acb3bb6@cakuba.netronome.com> In-Reply-To: References: <20190320173332.18105-1-alban@kinvolk.io> <20190320173332.18105-4-alban@kinvolk.io> <20190320142346.3b552895@cakuba.netronome.com> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 21 Mar 2019 10:57:32 +0100, Alban Crequy wrote: > 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. The thing is the receiver of the FD has to be bpf-aware, because there isn't really much one can do with that file descriptor, in which case it's kind of strange that the receiver doesn't know how to open a pinned object.. > 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..."). I see, thanks for the explanation. That does indeed seems like a hack. > 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