From patchwork Fri Nov 6 22:25:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 11888291 X-Patchwork-Delegate: bpf@iogearbox.net 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=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 0CE99C2D0A3 for ; Fri, 6 Nov 2020 22:25:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A725A20B1F for ; Fri, 6 Nov 2020 22:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604701529; bh=MxtDh91tqgz0bZsm04ncy+v2uuUFfG+v7iZiHD1oomU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=WeQVwrnsOgad7T8+ytBIrqnlKmsAMYDm6bVjLz7w1mQ3eV2J0T29bwUZd0tSNQBQS TLACRi9dFFuPY7JIG7+OY6/Xii3oI5pVWA+jM1DB4PxAaoJYWAlh4k1Atq2il08ZvJ jP9yufUTW4FTqBTPEOHLm6o52W+f2etJTLb3OefU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728624AbgKFWZ3 convert rfc822-to-8bit (ORCPT ); Fri, 6 Nov 2020 17:25:29 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:49166 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728518AbgKFWZ3 (ORCPT ); Fri, 6 Nov 2020 17:25:29 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-320-x82FjvCKOTGliHA5Th65Xw-1; Fri, 06 Nov 2020 17:25:24 -0500 X-MC-Unique: x82FjvCKOTGliHA5Th65Xw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83919107ACF9; Fri, 6 Nov 2020 22:25:22 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFFB57512B; Fri, 6 Nov 2020 22:25:19 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Yonghong Song , Song Liu , dwarves@vger.kernel.org, bpf@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Hao Luo , "Frank Ch. Eigler" , Mark Wielaard Subject: [PATCH 1/3] bpf: Move iterator functions into special init section Date: Fri, 6 Nov 2020 23:25:10 +0100 Message-Id: <20201106222512.52454-2-jolsa@kernel.org> In-Reply-To: <20201106222512.52454-1-jolsa@kernel.org> References: <20201106222512.52454-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net With upcoming changes to pahole, that change the way how and which kernel functions are stored in BTF data, we need a way to recognize iterator functions. Iterator functions need to be in BTF data, but have no real body and are currently placed in .init.text section, so they are freed after kernel init and are filtered out of BTF data because of that. The solution is to place these functions under new section: .init.bpf.preserve_type And add 2 new symbols to mark that area: __init_bpf_preserve_type_begin __init_bpf_preserve_type_end The code in pahole responsible for picking up the functions will be able to recognize functions from this section and add them to the BTF data and filter out all other .init.text functions. Suggested-by: Yonghong Song Acked-by: Song Liu Signed-off-by: Jiri Olsa --- include/asm-generic/vmlinux.lds.h | 16 +++++++++++++++- include/linux/bpf.h | 8 +++++++- include/linux/init.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index cd14444bf600..e18e1030dabf 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -685,8 +685,21 @@ .BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \ *(.BTF_ids) \ } + +/* + * .init.bpf.preserve_type + * + * This section store special BPF function and marks them + * with begin/end symbols pair for the sake of pahole tool. + */ +#define INIT_BPF_PRESERVE_TYPE \ + __init_bpf_preserve_type_begin = .; \ + *(.init.bpf.preserve_type) \ + __init_bpf_preserve_type_end = .; \ + MEM_DISCARD(init.bpf.preserve_type) #else #define BTF +#define INIT_BPF_PRESERVE_TYPE #endif /* @@ -740,7 +753,8 @@ #define INIT_TEXT \ *(.init.text .init.text.*) \ *(.text.startup) \ - MEM_DISCARD(init.text*) + MEM_DISCARD(init.text*) \ + INIT_BPF_PRESERVE_TYPE #define EXIT_DATA \ *(.exit.data .exit.data.*) \ diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 73d5381a5d5c..894f66c7703e 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1277,10 +1277,16 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd); int bpf_obj_pin_user(u32 ufd, const char __user *pathname); int bpf_obj_get_user(const char __user *pathname, int flags); +#ifdef CONFIG_DEBUG_INFO_BTF +#define BPF_INIT __init_bpf_preserve_type +#else +#define BPF_INIT __init +#endif + #define BPF_ITER_FUNC_PREFIX "bpf_iter_" #define DEFINE_BPF_ITER_FUNC(target, args...) \ extern int bpf_iter_ ## target(args); \ - int __init bpf_iter_ ## target(args) { return 0; } + int BPF_INIT bpf_iter_ ## target(args) { return 0; } struct bpf_iter_aux_info { struct bpf_map *map; diff --git a/include/linux/init.h b/include/linux/init.h index 212fc9e2f691..133462863711 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -52,6 +52,7 @@ #define __initconst __section(.init.rodata) #define __exitdata __section(.exit.data) #define __exit_call __used __section(.exitcall.exit) +#define __init_bpf_preserve_type __section(.init.bpf.preserve_type) /* * modpost check for section mismatches during the kernel build.