From patchwork Wed Apr 18 22:55:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin KaFai Lau X-Patchwork-Id: 900435 Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=fb.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="ZDvBegqf"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40RHYD6ZcQz9s15 for ; Thu, 19 Apr 2018 08:56:32 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752744AbeDRW4L (ORCPT ); Wed, 18 Apr 2018 18:56:11 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:43932 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750872AbeDRW4J (ORCPT ); Wed, 18 Apr 2018 18:56:09 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.22/8.16.0.22) with SMTP id w3IMT245007595 for ; Wed, 18 Apr 2018 15:56:08 -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-type; s=facebook; bh=2cH4Vj2Q7SgOKlMWXsaW+3iecO/wsDW1j9zkRzowehQ=; b=ZDvBegqfgYRDaD7urF13ykytXn3cc6FES9CagofcNIdFYPtSW6/0rp0SkALlYv76vyQq h3HP64L3EtT7RxzcoJ+QhaAXTb5qYAMnOaolTQDAmHq5SGz+i4UlitFz/kpJ0czK73v7 NfxBRIguG/ZAmPCVyRYGTtFsvxIYEw1BOHE= Received: from mail.thefacebook.com ([199.201.64.23]) by m0089730.ppops.net with ESMTP id 2heehbg3c9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 18 Apr 2018 15:56:08 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB04.TheFacebook.com (192.168.16.14) with Microsoft SMTP Server id 14.3.361.1; Wed, 18 Apr 2018 15:56:07 -0700 Received: by devbig738.prn1.facebook.com (Postfix, from userid 6611) id E3CCE4500A36; Wed, 18 Apr 2018 15:56:06 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Martin KaFai Lau Smtp-Origin-Hostname: devbig738.prn1.facebook.com To: CC: Alexei Starovoitov , Daniel Borkmann , , Arnaldo Carvalho de Melo Smtp-Origin-Cluster: prn1c29 Subject: [PATCH bpf-next v5 00/10] BTF: BPF Type Format Date: Wed, 18 Apr 2018 15:55:56 -0700 Message-ID: <20180418225606.2771620-1-kafai@fb.com> X-Mailer: git-send-email 2.9.5 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-04-18_05:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch introduces BPF Type Format (BTF). BTF (BPF Type Format) is the meta data format which describes the data types of BPF program/map. Hence, it basically focus on the C programming language which the modern BPF is primary using. The first use case is to provide a generic pretty print capability for a BPF map. A modified pahole that can convert dwarf to BTF is here: https://github.com/iamkafai/pahole/tree/btf (Arnaldo, there is some BTF_KIND numbering changes on Apr 18th, d61426c1571) Please see individual patch for details. v5: - Remove BTF_KIND_FLOAT and BTF_KIND_FUNC which are not currently used. They can be added in the future. Some bpf_df_xxx() are removed together. - Add comment in patch 7 to clarify that the new bpffs_map_fops should not be extended further. v4: - Fix warning (remove unneeded semicolon) - Remove a redundant variable (nr_bytes) from btf_int_check_meta() in patch 1. Caught by W=1. v3: - Rebase to bpf-next - Fix sparse warning (by adding static) - Add BTF header logging: btf_verifier_log_hdr() - Fix the alignment test on btf->type_off - Add tests for the BTF header - Lower the max BTF size to 16MB. It should be enough for some time. We could raise it later if it would be needed. v2: - Use kvfree where needed in patch 1 and 2 - Also consider BTF_INT_OFFSET() in the btf_int_check_meta() in patch 1 - Fix an incorrect goto target in map_create() during the btf-error-path in patch 7 - re-org some local vars to keep the rev xmas tree in btf.c Martin KaFai Lau (10): bpf: btf: Introduce BPF Type Format (BTF) bpf: btf: Validate type reference bpf: btf: Check members of struct/union bpf: btf: Add pretty print capability for data with BTF type info bpf: btf: Add BPF_BTF_LOAD command bpf: btf: Add BPF_OBJ_GET_INFO_BY_FD support to BTF fd bpf: btf: Add pretty print support to the basic arraymap bpf: btf: Sync bpf.h and btf.h to tools/ bpf: btf: Add BTF support to libbpf bpf: btf: Add BTF tests include/linux/bpf.h | 20 +- include/linux/btf.h | 48 + include/uapi/linux/bpf.h | 12 + include/uapi/linux/btf.h | 130 ++ kernel/bpf/Makefile | 1 + kernel/bpf/arraymap.c | 50 + kernel/bpf/btf.c | 2064 ++++++++++++++++++++++++++ kernel/bpf/inode.c | 156 +- kernel/bpf/syscall.c | 51 +- tools/include/uapi/linux/bpf.h | 12 + tools/include/uapi/linux/btf.h | 130 ++ tools/lib/bpf/Build | 2 +- tools/lib/bpf/bpf.c | 92 +- tools/lib/bpf/bpf.h | 16 + tools/lib/bpf/btf.c | 374 +++++ tools/lib/bpf/btf.h | 22 + tools/lib/bpf/libbpf.c | 148 +- tools/lib/bpf/libbpf.h | 3 + tools/testing/selftests/bpf/Makefile | 26 +- tools/testing/selftests/bpf/test_btf.c | 1669 +++++++++++++++++++++ tools/testing/selftests/bpf/test_btf_haskv.c | 48 + tools/testing/selftests/bpf/test_btf_nokv.c | 43 + 22 files changed, 5076 insertions(+), 41 deletions(-) create mode 100644 include/linux/btf.h create mode 100644 include/uapi/linux/btf.h create mode 100644 kernel/bpf/btf.c create mode 100644 tools/include/uapi/linux/btf.h create mode 100644 tools/lib/bpf/btf.c create mode 100644 tools/lib/bpf/btf.h create mode 100644 tools/testing/selftests/bpf/test_btf.c create mode 100644 tools/testing/selftests/bpf/test_btf_haskv.c create mode 100644 tools/testing/selftests/bpf/test_btf_nokv.c