All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 1/3] Add error returns to two API functions
@ 2022-04-19 16:03 grantseltzer
  2022-04-19 16:03 ` [PATCH bpf-next v3 2/3] Update API functions usage to check error grantseltzer
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: grantseltzer @ 2022-04-19 16:03 UTC (permalink / raw)
  To: bpf; +Cc: andrii, grantseltzer, song

From: Grant Seltzer <grantseltzer@gmail.com>

This adds an error return to the following API functions:

- bpf_program__set_expected_attach_type()
- bpf_program__set_type()

In both cases, the error occurs when the BPF object has
already been loaded when the function is called. In this
case -EBUSY is returned.

Signed-off-by: Grant Seltzer <grantseltzer@gmail.com>
---
 tools/lib/bpf/libbpf.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index bf4f7ac54ebf..0ed1a8c9c398 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8551,8 +8551,11 @@ enum bpf_prog_type bpf_program__type(const struct bpf_program *prog)
 	return prog->type;
 }
 
-void bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type)
+int bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type)
 {
+	if (prog->obj->loaded)
+		return libbpf_err(-EBUSY);
+
 	prog->type = type;
 }
 
@@ -8598,10 +8601,14 @@ enum bpf_attach_type bpf_program__expected_attach_type(const struct bpf_program
 	return prog->expected_attach_type;
 }
 
-void bpf_program__set_expected_attach_type(struct bpf_program *prog,
+int bpf_program__set_expected_attach_type(struct bpf_program *prog,
 					   enum bpf_attach_type type)
 {
+	if (prog->obj->loaded)
+		return libbpf_err(-EBUSY);
+
 	prog->expected_attach_type = type;
+	return 0;
 }
 
 __u32 bpf_program__flags(const struct bpf_program *prog)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH bpf-next v3 2/3] Update API functions usage to check error
  2022-04-19 16:03 [PATCH bpf-next v3 1/3] Add error returns to two API functions grantseltzer
@ 2022-04-19 16:03 ` grantseltzer
  2022-04-20  5:35   ` Andrii Nakryiko
  2022-04-19 16:03 ` [PATCH bpf-next v3 3/3] Add documentation to API functions grantseltzer
  2022-04-20  5:32 ` [PATCH bpf-next v3 1/3] Add error returns to two " Andrii Nakryiko
  2 siblings, 1 reply; 7+ messages in thread
From: grantseltzer @ 2022-04-19 16:03 UTC (permalink / raw)
  To: bpf; +Cc: andrii, grantseltzer, song

From: Grant Seltzer <grantseltzer@gmail.com>

This updates usage of the following API functions within
libbpf so their newly added error return is checked:

- bpf_program__set_expected_attach_type()
- bpf_program__set_type()

Signed-off-by: Grant Seltzer <grantseltzer@gmail.com>
---
 tools/lib/bpf/libbpf.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 0ed1a8c9c398..7635c50a05c6 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7005,9 +7005,19 @@ static int bpf_object_init_progs(struct bpf_object *obj, const struct bpf_object
 			continue;
 		}
 
-		bpf_program__set_type(prog, prog->sec_def->prog_type);
-		bpf_program__set_expected_attach_type(prog, prog->sec_def->expected_attach_type);
+		err = bpf_program__set_type(prog, prog->sec_def->prog_type);
+		if (err) {
+			pr_warn("prog '%s': failed to initialize: %d, could not set program type\n",
+				prog->name, err);
+			return err;
+		}
 
+		err = bpf_program__set_expected_attach_type(prog, prog->sec_def->expected_attach_type);
+		if (err) {
+			pr_warn("prog '%s': failed to initialize: %d, could not set expected attach type\n",
+				prog->name, err);
+			return err;
+		}
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 		if (prog->sec_def->prog_type == BPF_PROG_TYPE_TRACING ||
@@ -8570,8 +8580,7 @@ int bpf_program__set_##NAME(struct bpf_program *prog)		\
 {								\
 	if (!prog)						\
 		return libbpf_err(-EINVAL);			\
-	bpf_program__set_type(prog, TYPE);			\
-	return 0;						\
+	return bpf_program__set_type(prog, TYPE);			\
 }								\
 								\
 bool bpf_program__is_##NAME(const struct bpf_program *prog)	\
@@ -9678,9 +9687,17 @@ static int bpf_prog_load_xattr2(const struct bpf_prog_load_attr *attr,
 		 * bpf_object__open guessed
 		 */
 		if (attr->prog_type != BPF_PROG_TYPE_UNSPEC) {
-			bpf_program__set_type(prog, attr->prog_type);
-			bpf_program__set_expected_attach_type(prog,
+			err = bpf_program__set_type(prog, attr->prog_type);
+			if (err) {
+				pr_warn("could not set program type\n");
+				return libbpf_err(err);
+			}
+			err = bpf_program__set_expected_attach_type(prog,
 							      attach_type);
+			if (err) {
+				pr_warn("could not set expected attach type\n");
+				return libbpf_err(err);
+			}
 		}
 		if (bpf_program__type(prog) == BPF_PROG_TYPE_UNSPEC) {
 			/*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH bpf-next v3 3/3] Add documentation to API functions
  2022-04-19 16:03 [PATCH bpf-next v3 1/3] Add error returns to two API functions grantseltzer
  2022-04-19 16:03 ` [PATCH bpf-next v3 2/3] Update API functions usage to check error grantseltzer
@ 2022-04-19 16:03 ` grantseltzer
  2022-04-20  5:42   ` Andrii Nakryiko
  2022-04-20  8:23   ` kernel test robot
  2022-04-20  5:32 ` [PATCH bpf-next v3 1/3] Add error returns to two " Andrii Nakryiko
  2 siblings, 2 replies; 7+ messages in thread
From: grantseltzer @ 2022-04-19 16:03 UTC (permalink / raw)
  To: bpf; +Cc: andrii, grantseltzer, song

From: Grant Seltzer <grantseltzer@gmail.com>

This adds documentation for the following API functions:
- bpf_program__set_expected_attach_type()
- bpf_program__set_type()
- bpf_program__set_attach_target()
- bpf_program__attach()
- bpf_program__pin()
- bpf_program__unpin()

Signed-off-by: Grant Seltzer <grantseltzer@gmail.com>
---
 tools/lib/bpf/libbpf.h | 100 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 98 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 63d66f1adf1a..a2b9ec9f0990 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -378,7 +378,31 @@ struct bpf_link;
 LIBBPF_API struct bpf_link *bpf_link__open(const char *path);
 LIBBPF_API int bpf_link__fd(const struct bpf_link *link);
 LIBBPF_API const char *bpf_link__pin_path(const struct bpf_link *link);
+/**
+ * @brief **bpf_link__pin()** pins the BPF link to a file
+ * in the BPF FS specified by a path. This increments the links
+ * reference count, allowing it to stay loaded after the process
+ * which loaded it has exited.
+ *
+ * @param link BPF link to pin, must already be loaded
+ * @param path file path in a BPF file system
+ * @return 0, on success; negative error code, otherwise
+ */
+
 LIBBPF_API int bpf_link__pin(struct bpf_link *link, const char *path);
+
+/**
+ * @brief **bpf_link__unpin()** unpins the BPF link from a file
+ * in the BPFFS specified by a path. This decrements the links
+ * reference count.
+ *
+ * The file pinning the BPF link can also be unlinked by a different
+ * process in which case this function will return an error.
+ *
+ * @param prog BPF program to unpin
+ * @param path file path to the pin in a BPF file system
+ * @return 0, on success; negative error code, otherwise
+ */
 LIBBPF_API int bpf_link__unpin(struct bpf_link *link);
 LIBBPF_API int bpf_link__update_program(struct bpf_link *link,
 					struct bpf_program *prog);
@@ -386,6 +410,22 @@ LIBBPF_API void bpf_link__disconnect(struct bpf_link *link);
 LIBBPF_API int bpf_link__detach(struct bpf_link *link);
 LIBBPF_API int bpf_link__destroy(struct bpf_link *link);
 
+/**
+ * @brief **bpf_program__attach()** is a generic function for attaching
+ * a BPF program based on auto-detection of program type, attach type,
+ * and extra paremeters, where applicable.
+ *
+ * @param prog BPF program to attach
+ * @return Reference to the newly created BPF link; or NULL is returned on error,
+ * error code is stored in errno
+ *
+ * This is supported for:
+ *   - kprobe/kretprobe (depends on SEC() definition)
+ *   - uprobe/uretprobe (depends on SEC() definition)
+ *   - tracepoint
+ *   - raw tracepoint
+ *   - tracing programs (typed raw TP/fentry/fexit/fmod_ret)
+ */
 LIBBPF_API struct bpf_link *
 bpf_program__attach(const struct bpf_program *prog);
 
@@ -686,12 +726,45 @@ LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_program__set_type() instead")
 LIBBPF_API int bpf_program__set_sk_lookup(struct bpf_program *prog);
 
 LIBBPF_API enum bpf_prog_type bpf_program__type(const struct bpf_program *prog);
-LIBBPF_API void bpf_program__set_type(struct bpf_program *prog,
+/**
+ * @brief **bpf_program__set_type()** sets the program
+ * type of the passed BPF program. This must be done
+ * before the program is loaded, otherwise it has no
+ * effect.
+ * @param prog BPF program to set the program type for
+ * @param type program type to set the BPF map to have
+ * @return error code; or 0 if no error. An error occurs
+ * if the object is already loaded.
+ */
+LIBBPF_API int bpf_program__set_type(struct bpf_program *prog,
 				      enum bpf_prog_type type);
 
 LIBBPF_API enum bpf_attach_type
 bpf_program__expected_attach_type(const struct bpf_program *prog);
-LIBBPF_API void
+/**
+ * @brief **bpf_program__set_expected_attach_type()** sets the
+ * attach type of the passed BPF program. This is used for
+ * auto-detection of attachment when programs are loaded.
+ * @param prog BPF program to set the attach type for
+ * @param type attach type to set the BPF map to have
+ * @return error code; or 0 if no error. An error occurs
+ * if the object is already loaded.
+ *
+ * An example workflow:
+ *
+ * ...
+ *   xdp_fd = bpf_prog_get_fd_by_id(id);
+ *   trace_obj = bpf_object__open_file("func.o", NULL);
+ *   prog = bpf_object__find_program_by_title(trace_obj, "fentry/myfunc");
+ *   int err = bpf_program__set_expected_attach_type(prog, BPF_TRACE_FENTRY);
+ *   if (err != 0) {
+ *     // Object already loaded
+ *   }
+ *   bpf_program__set_attach_target(prog, xdp_fd, "xdpfilt_blk_all");
+ *   bpf_object__load(trace_obj);
+ * ...
+ */
+LIBBPF_API int
 bpf_program__set_expected_attach_type(struct bpf_program *prog,
 				      enum bpf_attach_type type);
 
@@ -707,6 +780,29 @@ LIBBPF_API int bpf_program__set_log_level(struct bpf_program *prog, __u32 log_le
 LIBBPF_API const char *bpf_program__log_buf(const struct bpf_program *prog, size_t *log_size);
 LIBBPF_API int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log_size);
 
+/**
+ * @brief **bpf_program__set_attach_target()** sets the
+ * specified BPF program to attach to a specific tracepoint
+ * or kernel function. This can be used to supplement
+ * the BPF program name/section not matching the tracepoint
+ * or function semanics.
+ * @param prog BPF program to set the attach type for
+ * @param type attach type to set the BPF map to have
+ * @return error code; or 0 if no error occurred.
+ * An example workflow:
+ *
+ * ...
+ *   xdp_fd = bpf_prog_get_fd_by_id(id);
+ *   trace_obj = bpf_object__open_file("func.o", NULL);
+ *   prog = bpf_object__find_program_by_title(trace_obj, "fentry/myfunc");
+ *   bpf_program__set_expected_attach_type(prog, BPF_TRACE_FENTRY);
+ *   int err = bpf_program__set_attach_target(prog, xdp_fd, "xdpfilt_blk_all");
+ *   if (err != 0) {
+ *     // Object already loaded
+ *   }
+ *   bpf_object__load(trace_obj);
+ * ...
+ */
 LIBBPF_API int
 bpf_program__set_attach_target(struct bpf_program *prog, int attach_prog_fd,
 			       const char *attach_func_name);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next v3 1/3] Add error returns to two API functions
  2022-04-19 16:03 [PATCH bpf-next v3 1/3] Add error returns to two API functions grantseltzer
  2022-04-19 16:03 ` [PATCH bpf-next v3 2/3] Update API functions usage to check error grantseltzer
  2022-04-19 16:03 ` [PATCH bpf-next v3 3/3] Add documentation to API functions grantseltzer
@ 2022-04-20  5:32 ` Andrii Nakryiko
  2 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-04-20  5:32 UTC (permalink / raw)
  To: grantseltzer; +Cc: bpf, Andrii Nakryiko, Song Liu

On Tue, Apr 19, 2022 at 9:04 AM grantseltzer <grantseltzer@gmail.com> wrote:
>
> From: Grant Seltzer <grantseltzer@gmail.com>
>
> This adds an error return to the following API functions:
>
> - bpf_program__set_expected_attach_type()
> - bpf_program__set_type()
>
> In both cases, the error occurs when the BPF object has
> already been loaded when the function is called. In this
> case -EBUSY is returned.
>
> Signed-off-by: Grant Seltzer <grantseltzer@gmail.com>
> ---
>  tools/lib/bpf/libbpf.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index bf4f7ac54ebf..0ed1a8c9c398 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -8551,8 +8551,11 @@ enum bpf_prog_type bpf_program__type(const struct bpf_program *prog)
>         return prog->type;
>  }
>
> -void bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type)
> +int bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type)
>  {
> +       if (prog->obj->loaded)
> +               return libbpf_err(-EBUSY);
> +
>         prog->type = type;

return 0;

>  }
>
> @@ -8598,10 +8601,14 @@ enum bpf_attach_type bpf_program__expected_attach_type(const struct bpf_program
>         return prog->expected_attach_type;
>  }
>
> -void bpf_program__set_expected_attach_type(struct bpf_program *prog,
> +int bpf_program__set_expected_attach_type(struct bpf_program *prog,
>                                            enum bpf_attach_type type)
>  {
> +       if (prog->obj->loaded)
> +               return libbpf_err(-EBUSY);
> +
>         prog->expected_attach_type = type;
> +       return 0;
>  }
>
>  __u32 bpf_program__flags(const struct bpf_program *prog)
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next v3 2/3] Update API functions usage to check error
  2022-04-19 16:03 ` [PATCH bpf-next v3 2/3] Update API functions usage to check error grantseltzer
@ 2022-04-20  5:35   ` Andrii Nakryiko
  0 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-04-20  5:35 UTC (permalink / raw)
  To: grantseltzer; +Cc: bpf, Andrii Nakryiko, Song Liu

On Tue, Apr 19, 2022 at 9:04 AM grantseltzer <grantseltzer@gmail.com> wrote:
>
> From: Grant Seltzer <grantseltzer@gmail.com>
>
> This updates usage of the following API functions within
> libbpf so their newly added error return is checked:
>
> - bpf_program__set_expected_attach_type()
> - bpf_program__set_type()
>
> Signed-off-by: Grant Seltzer <grantseltzer@gmail.com>
> ---
>  tools/lib/bpf/libbpf.c | 29 +++++++++++++++++++++++------
>  1 file changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 0ed1a8c9c398..7635c50a05c6 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -7005,9 +7005,19 @@ static int bpf_object_init_progs(struct bpf_object *obj, const struct bpf_object
>                         continue;
>                 }
>
> -               bpf_program__set_type(prog, prog->sec_def->prog_type);
> -               bpf_program__set_expected_attach_type(prog, prog->sec_def->expected_attach_type);
> +               err = bpf_program__set_type(prog, prog->sec_def->prog_type);
> +               if (err) {
> +                       pr_warn("prog '%s': failed to initialize: %d, could not set program type\n",
> +                               prog->name, err);
> +                       return err;
> +               }
>
> +               err = bpf_program__set_expected_attach_type(prog, prog->sec_def->expected_attach_type);
> +               if (err) {
> +                       pr_warn("prog '%s': failed to initialize: %d, could not set expected attach type\n",
> +                               prog->name, err);
> +                       return err;
> +               }

this is too paranoid, we know that this will succeed. We can just do:

prog->type = prog->sec_def->prog_type;
prog->expected_attach_type = prog->sec_def->expected_attach_type;

to make this very clear

>  #pragma GCC diagnostic push
>  #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
>                 if (prog->sec_def->prog_type == BPF_PROG_TYPE_TRACING ||
> @@ -8570,8 +8580,7 @@ int bpf_program__set_##NAME(struct bpf_program *prog)             \
>  {                                                              \
>         if (!prog)                                              \
>                 return libbpf_err(-EINVAL);                     \
> -       bpf_program__set_type(prog, TYPE);                      \
> -       return 0;                                               \
> +       return bpf_program__set_type(prog, TYPE);                       \
>  }                                                              \
>                                                                 \
>  bool bpf_program__is_##NAME(const struct bpf_program *prog)    \
> @@ -9678,9 +9687,17 @@ static int bpf_prog_load_xattr2(const struct bpf_prog_load_attr *attr,
>                  * bpf_object__open guessed
>                  */
>                 if (attr->prog_type != BPF_PROG_TYPE_UNSPEC) {
> -                       bpf_program__set_type(prog, attr->prog_type);
> -                       bpf_program__set_expected_attach_type(prog,
> +                       err = bpf_program__set_type(prog, attr->prog_type);
> +                       if (err) {
> +                               pr_warn("could not set program type\n");
> +                               return libbpf_err(err);
> +                       }
> +                       err = bpf_program__set_expected_attach_type(prog,
>                                                               attach_type);
> +                       if (err) {
> +                               pr_warn("could not set expected attach type\n");
> +                               return libbpf_err(err);
> +                       }

same as above, no need to add unnecessary checks and pr_warns


>                 }
>                 if (bpf_program__type(prog) == BPF_PROG_TYPE_UNSPEC) {
>                         /*
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next v3 3/3] Add documentation to API functions
  2022-04-19 16:03 ` [PATCH bpf-next v3 3/3] Add documentation to API functions grantseltzer
@ 2022-04-20  5:42   ` Andrii Nakryiko
  2022-04-20  8:23   ` kernel test robot
  1 sibling, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-04-20  5:42 UTC (permalink / raw)
  To: grantseltzer; +Cc: bpf, Andrii Nakryiko, Song Liu

On Tue, Apr 19, 2022 at 9:04 AM grantseltzer <grantseltzer@gmail.com> wrote:
>
> From: Grant Seltzer <grantseltzer@gmail.com>
>
> This adds documentation for the following API functions:
> - bpf_program__set_expected_attach_type()
> - bpf_program__set_type()
> - bpf_program__set_attach_target()
> - bpf_program__attach()
> - bpf_program__pin()
> - bpf_program__unpin()
>
> Signed-off-by: Grant Seltzer <grantseltzer@gmail.com>
> ---
>  tools/lib/bpf/libbpf.h | 100 ++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 98 insertions(+), 2 deletions(-)
>

[...]

>  LIBBPF_API enum bpf_attach_type
>  bpf_program__expected_attach_type(const struct bpf_program *prog);
> -LIBBPF_API void
> +/**
> + * @brief **bpf_program__set_expected_attach_type()** sets the
> + * attach type of the passed BPF program. This is used for
> + * auto-detection of attachment when programs are loaded.
> + * @param prog BPF program to set the attach type for
> + * @param type attach type to set the BPF map to have
> + * @return error code; or 0 if no error. An error occurs
> + * if the object is already loaded.
> + *
> + * An example workflow:
> + *
> + * ...
> + *   xdp_fd = bpf_prog_get_fd_by_id(id);
> + *   trace_obj = bpf_object__open_file("func.o", NULL);
> + *   prog = bpf_object__find_program_by_title(trace_obj, "fentry/myfunc");


bpf_object__find_program_by_title() is deprecated, we shouldn't use it
in documentation. There is a lot going on in this example workflow
(and workflow itself is using generic API instead of recommended
skeleton). Let's drop it, it might just be adding to confusion.

Just mention that expected attach type has to be set before BPF object
is loaded (same for program type). And that should be enough. In most
cases user won't ever have to use this anyways, IMO.

> + *   int err = bpf_program__set_expected_attach_type(prog, BPF_TRACE_FENTRY);
> + *   if (err != 0) {
> + *     // Object already loaded
> + *   }
> + *   bpf_program__set_attach_target(prog, xdp_fd, "xdpfilt_blk_all");
> + *   bpf_object__load(trace_obj);
> + * ...
> + */
> +LIBBPF_API int
>  bpf_program__set_expected_attach_type(struct bpf_program *prog,
>                                       enum bpf_attach_type type);
>
> @@ -707,6 +780,29 @@ LIBBPF_API int bpf_program__set_log_level(struct bpf_program *prog, __u32 log_le
>  LIBBPF_API const char *bpf_program__log_buf(const struct bpf_program *prog, size_t *log_size);
>  LIBBPF_API int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log_size);
>
> +/**
> + * @brief **bpf_program__set_attach_target()** sets the
> + * specified BPF program to attach to a specific tracepoint
> + * or kernel function. This can be used to supplement
> + * the BPF program name/section not matching the tracepoint
> + * or function semanics.

Not sure what you wanted to say with the last sentence?

How about something along the lines:

"... sets BTF-based attach target for supported BPF program types:
BTF-aware raw tracepoints, fentry/fexit/fmod_ret, lsm, freplace" ?


> + * @param prog BPF program to set the attach type for
> + * @param type attach type to set the BPF map to have
> + * @return error code; or 0 if no error occurred.
> + * An example workflow:
> + *
> + * ...
> + *   xdp_fd = bpf_prog_get_fd_by_id(id);
> + *   trace_obj = bpf_object__open_file("func.o", NULL);
> + *   prog = bpf_object__find_program_by_title(trace_obj, "fentry/myfunc");

same about find_program_by_title, please don't use it; and same about
the overall example, it's not succinct enough to fit in a doc comment,
let's just drop it?

> + *   bpf_program__set_expected_attach_type(prog, BPF_TRACE_FENTRY);
> + *   int err = bpf_program__set_attach_target(prog, xdp_fd, "xdpfilt_blk_all");
> + *   if (err != 0) {
> + *     // Object already loaded
> + *   }
> + *   bpf_object__load(trace_obj);

like here, we don't check error, setting a bad example :(

> + * ...
> + */
>  LIBBPF_API int
>  bpf_program__set_attach_target(struct bpf_program *prog, int attach_prog_fd,
>                                const char *attach_func_name);
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next v3 3/3] Add documentation to API functions
  2022-04-19 16:03 ` [PATCH bpf-next v3 3/3] Add documentation to API functions grantseltzer
  2022-04-20  5:42   ` Andrii Nakryiko
@ 2022-04-20  8:23   ` kernel test robot
  1 sibling, 0 replies; 7+ messages in thread
From: kernel test robot @ 2022-04-20  8:23 UTC (permalink / raw)
  To: grantseltzer, bpf; +Cc: llvm, kbuild-all, andrii, grantseltzer, song

Hi grantseltzer,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bpf-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/grantseltzer/Add-error-returns-to-two-API-functions/20220420-000638
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: s390-randconfig-r023-20220420 (https://download.01.org/0day-ci/archive/20220420/202204201650.TNnvoXPQ-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project bac6cd5bf85669e3376610cfc4c4f9ca015e7b9b)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install s390 cross compiling tool for clang build
        # apt-get install binutils-s390x-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/55a52c4514ab205b288dce0a609d5d7bab485813
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review grantseltzer/Add-error-returns-to-two-API-functions/20220420-000638
        git checkout 55a52c4514ab205b288dce0a609d5d7bab485813
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 prepare

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> libbpf.c:8570:1: error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]
   }
   ^
   1 error generated.
   make[5]: *** [tools/build/Makefile.build:96: tools/bpf/resolve_btfids/libbpf/staticobjs/libbpf.o] Error 1
   make[5]: *** Waiting for unfinished jobs....
   make[4]: *** [Makefile:157: tools/bpf/resolve_btfids/libbpf/staticobjs/libbpf-in.o] Error 2
   make[3]: *** [Makefile:55: tools/bpf/resolve_btfids//libbpf/libbpf.a] Error 2
   make[2]: *** [Makefile:72: bpf/resolve_btfids] Error 2
   make[1]: *** [Makefile:1337: tools/bpf/resolve_btfids] Error 2
   In file included from arch/s390/kernel/asm-offsets.c:11:
   In file included from include/linux/kvm_host.h:41:
   In file included from include/linux/kvm_para.h:5:
   In file included from include/uapi/linux/kvm_para.h:37:
   In file included from arch/s390/include/asm/kvm_para.h:25:
   In file included from arch/s390/include/asm/diag.h:12:
   In file included from include/linux/if_ether.h:19:
   In file included from include/linux/skbuff.h:31:
   In file included from include/linux/dma-mapping.h:10:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:75:
   include/asm-generic/io.h:464:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:477:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
                                                             ^
   include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
   #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
                                                        ^
   In file included from arch/s390/kernel/asm-offsets.c:11:
   In file included from include/linux/kvm_host.h:41:
   In file included from include/linux/kvm_para.h:5:
   In file included from include/uapi/linux/kvm_para.h:37:
   In file included from arch/s390/include/asm/kvm_para.h:25:
   In file included from arch/s390/include/asm/diag.h:12:
   In file included from include/linux/if_ether.h:19:
   In file included from include/linux/skbuff.h:31:
   In file included from include/linux/dma-mapping.h:10:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:75:
   include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
   #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
                                                        ^
   In file included from arch/s390/kernel/asm-offsets.c:11:
   In file included from include/linux/kvm_host.h:41:
   In file included from include/linux/kvm_para.h:5:
   In file included from include/uapi/linux/kvm_para.h:37:
   In file included from arch/s390/include/asm/kvm_para.h:25:
   In file included from arch/s390/include/asm/diag.h:12:
   In file included from include/linux/if_ether.h:19:
   In file included from include/linux/skbuff.h:31:
   In file included from include/linux/dma-mapping.h:10:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:75:
   include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsb(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsw(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsl(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesb(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesw(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesl(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   12 warnings generated.
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:219: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-20  8:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 16:03 [PATCH bpf-next v3 1/3] Add error returns to two API functions grantseltzer
2022-04-19 16:03 ` [PATCH bpf-next v3 2/3] Update API functions usage to check error grantseltzer
2022-04-20  5:35   ` Andrii Nakryiko
2022-04-19 16:03 ` [PATCH bpf-next v3 3/3] Add documentation to API functions grantseltzer
2022-04-20  5:42   ` Andrii Nakryiko
2022-04-20  8:23   ` kernel test robot
2022-04-20  5:32 ` [PATCH bpf-next v3 1/3] Add error returns to two " Andrii Nakryiko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.