Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753959AbdLHOxg (ORCPT ); Fri, 8 Dec 2017 09:53:36 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:48610 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753567AbdLHOxc (ORCPT ); Fri, 8 Dec 2017 09:53:32 -0500 From: Roman Gushchin To: CC: , , , , , , , Quentin Monnet , David Ahern Subject: [PATCH v3 net-next 0/4] bpftool: cgroup bpf operations Date: Fri, 8 Dec 2017 14:52:32 +0000 Message-ID: <20171208145236.12635-1-guro@fb.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c092:180::1:b43a] X-ClientProxiedBy: VI1PR0102CA0086.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::27) To CO1PR15MB1078.namprd15.prod.outlook.com (2a01:111:e400:7b66::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fc6d9be6-6f0c-4f31-addd-08d53e4b644d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307);SRVR:CO1PR15MB1078; X-Microsoft-Exchange-Diagnostics: 1;CO1PR15MB1078;3:9Djfq9HXEZ0XRObUmCPkHL0kWTCFKFs4kpvMsV0Ca9iPeaAqPocpnTLgO5koMVoxSct+FzMyWyNBMx9jEWPuMzlwLtm/TeHvgio9VMj70eGVaq8QQ5dZ0P8SdGnO8P8FyfZHb1g3ytzGKVRCrNAnlyYnyM02Qh1hWRw2aPEULQ2QFAoRamPxbPVB6II8kIJ6CT6cg9XcBX3N7PfvPuQ6cmEG/hp8tbNzICdl+V/CfohxsY8nBCPPcHnIJSl3lIvc;25:oF+6t9vwFSgVbpbH6/Sq5job/wb7sL+iMQEYOwvfsQ58QjQiH22/4g2LxB1IciD4lEbHv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DM/VNWRqmOJmKy3CGyyP;4:ViOHx6wO6NwmiHqTQxS0bGmWiYnC+07PlTdekeNIBr+gChypX1D+RBnXXrNPRw/Ni1k9LvyRsVcX/KfaOUNfdBL1gRw3KlyN36Dy0Ij0yM45+SVYr2A+KuEhvjeH58/qjU4/6PEcakGzfAGSlN5DJvUc9hS/Ur7sFd5+14ILg2pRd/yqJ79NLMhZ6PXdwacgF9iIGN5qgd72oIZIjtTNQb68iQVIZjQaoSHGOOV+nrTyLQokqcwm9LXL6cxWs8jiCXaC/LOPcilfy1ixlhrUpA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(11241501159)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(3231022)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123558100)(20161123560025)(20161123555025)(6072148)(201708071742011);SRVR:CO1PR15MB1078;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CO1PR15MB1078; X-Forefront-PRVS: 0515208626 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(366004)(376002)(346002)(11905935001)(189003)(199004)(7736002)(68736007)(6116002)(86362001)(1076002)(105586002)(48376002)(106356001)(33646002)(2351001)(50226002)(2361001)(305945005)(2906002)(53416004)(6666003)(8936002)(81166006)(50466002)(8676002)(6916009)(81156014)(5890100001)(5660300001)(52116002)(51416003)(69596002)(966005)(6506006)(478600001)(53936002)(52396003)(16586007)(316002)(6486002)(39060400002)(4326008)(36756003)(6512007)(6306002)(25786009)(47776003)(97736004)(54906003)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:CO1PR15MB1078;H:castle.thefacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CO1PR15MB1078;23:sadOabm3pgt9DzZefReBuI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U3GsSQeiXmPbYKR+SMGRRIcqFr5fUvmy64+GpdhzAU16/hDW+puI93Ec2WlY8AHKZhCMuolpyE/HRqUYq75OYFavFrTeeDpguq1ppJ8qoRiiISRt4oD8qM2Oom/PUX3yAZUKM0kxIci2/Ha3Z14ptPVMy4/dnEARq8vuN6bWYQTP7JR3uVBat3stE3qb7KdDxdnKWcbuQulNP5qn3QrmfP4gaGzglbSiEislgXjvA/xGuvx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CO1PR15MB1078;20:CmbQzd5CHB6J4XWuau9zdtilHKVtCJHctnpwObuoJguY3Ve/6G1bQWILjtK6BNHF5qci/CwuNRtqcgUh7qengESPsA10ZjbsHiu6/HcXe+H43BJoG63wLvSojdqHDUwKnCN9LfET0m2Wq5IfQMyRZNYisUV2bWdqDAhUYmiEGj0= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2017 14:53:04.0167 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc6d9be6-6f0c-4f31-addd-08d53e4b644d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR15MB1078 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-08_08:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2300 Lines: 54 This patchset adds basic cgroup bpf operations to bpftool. Right now there is no convenient way to perform these operations. The /samples/bpf/load_sock_ops.c implements attach/detacg operations, but only for BPF_CGROUP_SOCK_OPS programs. Bps (part of bcc) implements bpf introspection, but lacks any cgroup-related specific. I find having a tool to perform these basic operations in the kernel tree very useful, as it can be used in the corresponding bpf documentation without creating additional dependencies. And bpftool seems to be a right tool to extend with such functionality. v3: - SRC replaced with OBJ in prog load docs - Output unknown attach type in hex - License header in SPDX format - Minor style fixes (e.g. variable reordering) v2: - Added prog load operations - All cgroup operations are looking like bpftool cgroup - All cgroup-related stuff is moved to a separate file - Added support for attach flags - Added support for attaching/detaching programs by id, pinned name, etc - Changed cgroup detach arguments order - Added empty json output for succesful programs - Style fixed: includes order, strncmp and macroses, error handling - Added man pages v1: https://lwn.net/Articles/740366/ Roman Gushchin (4): libbpf: add ability to guess program type based on section name libbpf: prefer global symbols as bpf program name source bpftool: implement prog load command bpftool: implement cgroup bpf operations tools/bpf/bpftool/Documentation/bpftool-cgroup.rst | 92 +++++++ tools/bpf/bpftool/Documentation/bpftool-map.rst | 2 +- tools/bpf/bpftool/Documentation/bpftool-prog.rst | 12 +- tools/bpf/bpftool/Documentation/bpftool.rst | 8 +- tools/bpf/bpftool/cgroup.c | 300 +++++++++++++++++++++ tools/bpf/bpftool/common.c | 71 ++--- tools/bpf/bpftool/main.c | 3 +- tools/bpf/bpftool/main.h | 2 + tools/bpf/bpftool/prog.c | 29 +- tools/lib/bpf/libbpf.c | 53 ++++ 10 files changed, 533 insertions(+), 39 deletions(-) create mode 100644 tools/bpf/bpftool/Documentation/bpftool-cgroup.rst create mode 100644 tools/bpf/bpftool/cgroup.c -- 2.14.3