From patchwork Wed Apr 29 00:16:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 220370 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAC8AC83004 for ; Wed, 29 Apr 2020 00:16:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C669320737 for ; Wed, 29 Apr 2020 00:16:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="HJr4CQHw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726423AbgD2AQ0 (ORCPT ); Tue, 28 Apr 2020 20:16:26 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:9856 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726363AbgD2AQZ (ORCPT ); Tue, 28 Apr 2020 20:16:25 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 03T08HB1032750 for ; Tue, 28 Apr 2020 17:16:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=G1RWv4KWcpGYqbUynxFTMnu0QYs9FOLTC6GONx5brFE=; b=HJr4CQHwh0O1I+Npya/LteRpR16BAaNOQubGkyPvm9nMH+BlP/dSefIbzzXuBkmHQTb4 trOwHC9geS0iLRHU6ITCxvbmdgcuIDB0DbPTdM+qgjnk48t9pMLYq4KRm1fVusfV2ezK g9gEx1sWfdpSpdFO4U6wuIzvBz6/YiCdmWc= Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net with ESMTP id 30mgvnqcsx-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 28 Apr 2020 17:16:23 -0700 Received: from intmgw004.03.ash8.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Tue, 28 Apr 2020 17:16:22 -0700 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id 2387D2EC309B; Tue, 28 Apr 2020 17:16:18 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Andrii Nakryiko Smtp-Origin-Hostname: devbig012.ftw2.facebook.com To: , , , CC: , , Andrii Nakryiko Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v3 bpf-next 00/10] bpf_link observability APIs Date: Tue, 28 Apr 2020 17:16:04 -0700 Message-ID: <20200429001614.1544-1-andriin@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-28_15:2020-04-28,2020-04-28 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=11 phishscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 spamscore=11 mlxscore=11 priorityscore=1501 impostorscore=0 mlxlogscore=93 clxscore=1015 suspectscore=8 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004280186 X-FB-Internal: deliver Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch series adds various observability APIs to bpf_link: - each bpf_link now gets ID, similar to bpf_map and bpf_prog, by which user-space can iterate over all existing bpf_links and create limited FD from ID; - allows to get extra object information with bpf_link general and type-specific information; - implements `bpf link show` command which lists all active bpf_links in the system; - implements `bpf link pin` allowing to pin bpf_link by ID or from other pinned path. v2->v3: - improve spin locking around bpf_link ID (Alexei); - simplify bpf_link_info handling and fix compilation error on sh arch; v1->v2: - simplified `bpftool link show` implementation (Quentin); - fixed formatting of bpftool-link.rst (Quentin); - fixed attach type printing logic (Quentin); rfc->v1: - dropped read-only bpf_links (Alexei); - fixed bug in bpf_link_cleanup() not removing ID; - fixed bpftool link pinning search logic; - added bash-completion and man page. Andrii Nakryiko (10): bpf: refactor bpf_link update handling bpf: allocate ID for bpf_link bpf: support GET_FD_BY_ID and GET_NEXT_ID for bpf_link bpf: add support for BPF_OBJ_GET_INFO_BY_FD for bpf_link libbpf: add low-level APIs for new bpf_link commands selftests/bpf: test bpf_link's get_next_id, get_fd_by_id, and get_obj_info bpftool: expose attach_type-to-string array to non-cgroup code bpftool: add bpf_link show and pin support bpftool: add bpftool-link manpage bpftool: add link bash completions include/linux/bpf-cgroup.h | 14 - include/linux/bpf.h | 26 +- include/linux/bpf_types.h | 6 + include/uapi/linux/bpf.h | 31 ++ kernel/bpf/btf.c | 2 + kernel/bpf/cgroup.c | 87 ++++- kernel/bpf/syscall.c | 354 ++++++++++++++---- kernel/bpf/verifier.c | 2 + kernel/cgroup/cgroup.c | 27 -- .../bpftool/Documentation/bpftool-link.rst | 118 ++++++ tools/bpf/bpftool/bash-completion/bpftool | 39 ++ tools/bpf/bpftool/cgroup.c | 48 +-- tools/bpf/bpftool/common.c | 2 + tools/bpf/bpftool/link.c | 333 ++++++++++++++++ tools/bpf/bpftool/main.c | 6 +- tools/bpf/bpftool/main.h | 37 ++ tools/include/uapi/linux/bpf.h | 31 ++ tools/lib/bpf/bpf.c | 19 +- tools/lib/bpf/bpf.h | 4 +- tools/lib/bpf/libbpf.map | 6 + .../selftests/bpf/prog_tests/bpf_obj_id.c | 110 +++++- .../testing/selftests/bpf/progs/test_obj_id.c | 14 +- 22 files changed, 1132 insertions(+), 184 deletions(-) create mode 100644 tools/bpf/bpftool/Documentation/bpftool-link.rst create mode 100644 tools/bpf/bpftool/link.c