diff mbox series

[bpf-next,1/3] libbpf: use func name when pinning programs with LIBBPF_STRICT_SEC_NAME

Message ID 20211011155636.2666408-1-sdf@google.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next,1/3] libbpf: use func name when pinning programs with LIBBPF_STRICT_SEC_NAME | expand

Checks

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

Commit Message

Stanislav Fomichev Oct. 11, 2021, 3:56 p.m. UTC
We can't use section name anymore because it's not unique
and pinning objects with multiple programs with the same
progtype/secname will fail.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/lib/bpf/libbpf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko Oct. 12, 2021, 4:07 a.m. UTC | #1
On Mon, Oct 11, 2021 at 5:56 PM Stanislav Fomichev <sdf@google.com> wrote:
>
> We can't use section name anymore because it's not unique
> and pinning objects with multiple programs with the same
> progtype/secname will fail.
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---

Seems like you've signed up yourself for [0]? ;)

Please use the following syntax so that when this gets eventually
synced to Github, the issue will be auto-closed.

  [0] Closes: https://github.com/libbpf/libbpf/issues/273

>  tools/lib/bpf/libbpf.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index ae0889bebe32..0373ca86a54c 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -285,7 +285,8 @@ struct bpf_program {
>         size_t sub_insn_off;
>
>         char *name;
> -       /* sec_name with / replaced by _; makes recursive pinning
> +       /* sec_name (or name when using LIBBPF_STRICT_SEC_NAME)
> +        * with / replaced by _; makes recursive pinning

let's remove specific mention of sec_name from this comment. Please
add clarification to LIBBPF_STRICT_SEC_NAME comment instead,
mentioning that it also changes the behavior of pinning.

>          * in bpf_object__pin_programs easier
>          */
>         char *pin_name;
> @@ -614,7 +615,11 @@ static char *__bpf_program__pin_name(struct bpf_program *prog)
>  {
>         char *name, *p;
>
> -       name = p = strdup(prog->sec_name);
> +       if (libbpf_mode & LIBBPF_STRICT_SEC_NAME)
> +               name = p = strdup(prog->name);
> +       else
> +               name = p = strdup(prog->sec_name);

nit: instead of duplicating this double assignment, you can just do `p
= name;` right before the below loop. It will be a bit cleaner.

> +
>         while ((p = strchr(p, '/')))
>                 *p = '_';
>
> --
> 2.33.0.882.g93a45727a2-goog
>
Andrii Nakryiko Oct. 12, 2021, 4:11 a.m. UTC | #2
On Mon, Oct 11, 2021 at 5:56 PM Stanislav Fomichev <sdf@google.com> wrote:
>
> We can't use section name anymore because it's not unique
> and pinning objects with multiple programs with the same
> progtype/secname will fail.
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---

Also, patch sets with more than one related patch should come with the
cover letter, please send one on the next revision. Thanks!

>  tools/lib/bpf/libbpf.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index ae0889bebe32..0373ca86a54c 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -285,7 +285,8 @@ struct bpf_program {
>         size_t sub_insn_off;
>
>         char *name;
> -       /* sec_name with / replaced by _; makes recursive pinning
> +       /* sec_name (or name when using LIBBPF_STRICT_SEC_NAME)
> +        * with / replaced by _; makes recursive pinning
>          * in bpf_object__pin_programs easier
>          */
>         char *pin_name;
> @@ -614,7 +615,11 @@ static char *__bpf_program__pin_name(struct bpf_program *prog)
>  {
>         char *name, *p;
>
> -       name = p = strdup(prog->sec_name);
> +       if (libbpf_mode & LIBBPF_STRICT_SEC_NAME)
> +               name = p = strdup(prog->name);
> +       else
> +               name = p = strdup(prog->sec_name);
> +
>         while ((p = strchr(p, '/')))
>                 *p = '_';
>
> --
> 2.33.0.882.g93a45727a2-goog
>
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index ae0889bebe32..0373ca86a54c 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -285,7 +285,8 @@  struct bpf_program {
 	size_t sub_insn_off;
 
 	char *name;
-	/* sec_name with / replaced by _; makes recursive pinning
+	/* sec_name (or name when using LIBBPF_STRICT_SEC_NAME)
+	 * with / replaced by _; makes recursive pinning
 	 * in bpf_object__pin_programs easier
 	 */
 	char *pin_name;
@@ -614,7 +615,11 @@  static char *__bpf_program__pin_name(struct bpf_program *prog)
 {
 	char *name, *p;
 
-	name = p = strdup(prog->sec_name);
+	if (libbpf_mode & LIBBPF_STRICT_SEC_NAME)
+		name = p = strdup(prog->name);
+	else
+		name = p = strdup(prog->sec_name);
+
 	while ((p = strchr(p, '/')))
 		*p = '_';