diff mbox series

[bpf-next,v3,1/5] libbpf: .text routines are subprograms in strict mode

Message ID b239588581c1a1367b3ae901a9e3058bbb7a9eb7.1647382072.git.delyank@fb.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Subskeleton support for BPF libraries | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 6 maintainers not CCed: netdev@vger.kernel.org songliubraving@fb.com yhs@fb.com john.fastabend@gmail.com kafai@fb.com kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next fail VM_Test

Commit Message

Delyan Kratunov March 15, 2022, 10:15 p.m. UTC
Currently, libbpf considers a single routine in .text to be a program. This
is particularly confusing when it comes to library objects - a single routine
meant to be used as an extern will instead be considered a bpf_program.

This patch hides this compatibility behavior behind the pre-existing
SEC_NAME strict mode flag.

Signed-off-by: Delyan Kratunov <delyank@fb.com>
---
 tools/lib/bpf/libbpf.c        | 7 +++++++
 tools/lib/bpf/libbpf_legacy.h | 4 +++-
 2 files changed, 10 insertions(+), 1 deletion(-)

Comments

Andrii Nakryiko March 16, 2022, 5:28 a.m. UTC | #1
On Tue, Mar 15, 2022 at 3:15 PM Delyan Kratunov <delyank@fb.com> wrote:
>
> Currently, libbpf considers a single routine in .text to be a program. This
> is particularly confusing when it comes to library objects - a single routine
> meant to be used as an extern will instead be considered a bpf_program.
>
> This patch hides this compatibility behavior behind the pre-existing
> SEC_NAME strict mode flag.
>
> Signed-off-by: Delyan Kratunov <delyank@fb.com>
> ---
>  tools/lib/bpf/libbpf.c        | 7 +++++++
>  tools/lib/bpf/libbpf_legacy.h | 4 +++-
>  2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 43161fdd44bb..aa26163e4ca1 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -3832,7 +3832,14 @@ static bool prog_is_subprog(const struct bpf_object *obj,
>          * .text programs are subprograms (even if they are not called from
>          * other programs), because libbpf never explicitly supported mixing
>          * SEC()-designated BPF programs and .text entry-point BPF programs.
> +        *
> +        * In libbpf 1.0 strict mode, we always consider .text
> +        * programs to be subprograms.
>          */
> +
> +       if (libbpf_mode & LIBBPF_STRICT_SEC_NAME)
> +               return prog->sec_idx == obj->efile.text_shndx;
> +
>         return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1;
>  }
>
> diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h
> index a283cf031665..8d2e632aec79 100644
> --- a/tools/lib/bpf/libbpf_legacy.h
> +++ b/tools/lib/bpf/libbpf_legacy.h
> @@ -53,7 +53,9 @@ enum libbpf_strict_mode {
>          * SEC("xdp") and SEC("perf_event").
>          *
>          * Note, in this mode the program pin path will be based on the
> -        * function name instead of section name.
> +        * function name instead of section name. Additionally, routines in the
> +        * .text section are always considered sub-programs. (Legacy behavior
> +        * allows for a single routine in .text to be a program.)

nit: pinning doesn't have much in common with this, so please put the
new text on a separate paragraph


>          */
>         LIBBPF_STRICT_SEC_NAME = 0x04,
>         /*
> --
> 2.34.1
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 43161fdd44bb..aa26163e4ca1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -3832,7 +3832,14 @@  static bool prog_is_subprog(const struct bpf_object *obj,
 	 * .text programs are subprograms (even if they are not called from
 	 * other programs), because libbpf never explicitly supported mixing
 	 * SEC()-designated BPF programs and .text entry-point BPF programs.
+	 *
+	 * In libbpf 1.0 strict mode, we always consider .text
+	 * programs to be subprograms.
 	 */
+
+	if (libbpf_mode & LIBBPF_STRICT_SEC_NAME)
+		return prog->sec_idx == obj->efile.text_shndx;
+
 	return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1;
 }
 
diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h
index a283cf031665..8d2e632aec79 100644
--- a/tools/lib/bpf/libbpf_legacy.h
+++ b/tools/lib/bpf/libbpf_legacy.h
@@ -53,7 +53,9 @@  enum libbpf_strict_mode {
 	 * SEC("xdp") and SEC("perf_event").
 	 *
 	 * Note, in this mode the program pin path will be based on the
-	 * function name instead of section name.
+	 * function name instead of section name. Additionally, routines in the
+	 * .text section are always considered sub-programs. (Legacy behavior
+	 * allows for a single routine in .text to be a program.)
 	 */
 	LIBBPF_STRICT_SEC_NAME = 0x04,
 	/*