From patchwork Thu Nov 19 23:22:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 11919129 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=-12.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 D6D58C388F9 for ; Thu, 19 Nov 2020 23:22:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92154221FE for ; Thu, 19 Nov 2020 23:22:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725890AbgKSXW4 convert rfc822-to-8bit (ORCPT ); Thu, 19 Nov 2020 18:22:56 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:38622 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbgKSXW4 (ORCPT ); Thu, 19 Nov 2020 18:22:56 -0500 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AJNK4jm032595 for ; Thu, 19 Nov 2020 15:22:54 -0800 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 34wjmxetnj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 19 Nov 2020 15:22:54 -0800 Received: from intmgw003.08.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 19 Nov 2020 15:22:47 -0800 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id AF24B2EC9B9C; Thu, 19 Nov 2020 15:22:45 -0800 (PST) From: Andrii Nakryiko To: , , , CC: , Subject: [PATCH bpf-next 0/6] libbpf: add support for kernel module BTF CO-RE relocations Date: Thu, 19 Nov 2020 15:22:38 -0800 Message-ID: <20201119232244.2776720-1-andrii@kernel.org> 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.312,18.0.737 definitions=2020-11-19_14:2020-11-19,2020-11-19 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 phishscore=0 impostorscore=0 mlxlogscore=862 malwarescore=0 adultscore=0 clxscore=1015 spamscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=8 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011190160 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Implement libbpf support for performing CO-RE relocations against types in kernel module BTFs, in addition to existing vmlinux BTF support. This is a first step towards fully supporting kernel module BTFs. Subsequent patch sets will expand kernel and libbpf sides to allow using other BTF-powered capabilities (fentry/fexit, struct_ops, ksym externs, etc). For CO-RE relocations support, though, no extra kernel changes are necessary. This patch set also sets up a convenient and fully-controlled custom kernel module (called "bpf_sidecar"), that is a predictable playground for all the BPF selftests, that rely on module BTFs. Andrii Nakryiko (6): bpf: fix bpf_put_raw_tracepoint()'s use of __module_address() libbpf: add internal helper to load BTF data by FD libbpf: refactor CO-RE relocs to not assume a single BTF object libbpf: add kernel module BTF support for CO-RE relocations selftests/bpf: add bpf_sidecar kernel module for testing selftests/bpf: add CO-RE relocs selftest relying on kernel module BTF kernel/trace/bpf_trace.c | 6 +- tools/lib/bpf/btf.c | 61 +-- tools/lib/bpf/libbpf.c | 352 ++++++++++++++---- tools/lib/bpf/libbpf_internal.h | 1 + tools/testing/selftests/bpf/.gitignore | 1 + tools/testing/selftests/bpf/Makefile | 12 +- .../selftests/bpf/bpf_sidecar/.gitignore | 6 + .../selftests/bpf/bpf_sidecar/Makefile | 20 + .../bpf/bpf_sidecar/bpf_sidecar-events.h | 36 ++ .../selftests/bpf/bpf_sidecar/bpf_sidecar.c | 51 +++ .../selftests/bpf/bpf_sidecar/bpf_sidecar.h | 14 + .../selftests/bpf/prog_tests/core_reloc.c | 72 +++- .../selftests/bpf/progs/core_reloc_types.h | 17 + .../bpf/progs/test_core_reloc_module.c | 66 ++++ tools/testing/selftests/bpf/test_progs.c | 52 +++ 15 files changed, 647 insertions(+), 120 deletions(-) create mode 100644 tools/testing/selftests/bpf/bpf_sidecar/.gitignore create mode 100644 tools/testing/selftests/bpf/bpf_sidecar/Makefile create mode 100644 tools/testing/selftests/bpf/bpf_sidecar/bpf_sidecar-events.h create mode 100644 tools/testing/selftests/bpf/bpf_sidecar/bpf_sidecar.c create mode 100644 tools/testing/selftests/bpf/bpf_sidecar/bpf_sidecar.h create mode 100644 tools/testing/selftests/bpf/progs/test_core_reloc_module.c