* [PATCH] libbpf: Deprecate bpf_objects_list
@ 2021-10-26 22:27 Joe Burton
2021-10-26 22:34 ` Joe Burton
2021-10-26 22:36 ` Joe Burton
0 siblings, 2 replies; 3+ messages in thread
From: Joe Burton @ 2021-10-26 22:27 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: linux-mm, linux-kernel, trivial, Joe Burton
From: Joe Burton <jevburton@google.com>
Add a flag to `enum libbpf_strict_mode' to disable the global
`bpf_objects_list', preventing race conditions when concurrent threads
call bpf_object__open() or bpf_object__close().
bpf_object__next() will return NULL if this option is set.
Callers may achieve the same workflow by tracking bpf_objects in
application code.
[0] Closes: https://github.com/libbpf/libbpf/issues/293
Signed-off-by: Joe Burton <jevburton@google.com>
---
tools/lib/bpf/libbpf.c | 8 +++++++-
tools/lib/bpf/libbpf.h | 3 ++-
tools/lib/bpf/libbpf_legacy.h | 6 ++++++
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2fbed2d4a645..59d39ce9f375 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1148,6 +1148,7 @@ static struct bpf_object *bpf_object__new(const char *path,
size_t obj_buf_sz,
const char *obj_name)
{
+ bool strict = (libbpf_mode & LIBBPF_STRICT_NO_OBJECT_LIST);
struct bpf_object *obj;
char *end;
@@ -1188,7 +1189,8 @@ static struct bpf_object *bpf_object__new(const char *path,
obj->loaded = false;
INIT_LIST_HEAD(&obj->list);
- list_add(&obj->list, &bpf_objects_list);
+ if (!strict)
+ list_add(&obj->list, &bpf_objects_list);
return obj;
}
@@ -7935,6 +7937,10 @@ struct bpf_object *
bpf_object__next(struct bpf_object *prev)
{
struct bpf_object *next;
+ bool strict = (libbpf_mode & LIBBPF_STRICT_NO_OBJECT_LIST);
+
+ if (strict)
+ return NULL;
if (!prev)
next = list_first_entry(&bpf_objects_list,
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index e1900819bfab..defabdbe7760 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -168,7 +168,8 @@ LIBBPF_API struct bpf_program *
bpf_object__find_program_by_name(const struct bpf_object *obj,
const char *name);
-LIBBPF_API struct bpf_object *bpf_object__next(struct bpf_object *prev);
+LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "track bpf_objects in application code instead")
+struct bpf_object *bpf_object__next(struct bpf_object *prev);
#define bpf_object__for_each_safe(pos, tmp) \
for ((pos) = bpf_object__next(NULL), \
(tmp) = bpf_object__next(pos); \
diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h
index 29ccafab11a8..5ba5c9beccfa 100644
--- a/tools/lib/bpf/libbpf_legacy.h
+++ b/tools/lib/bpf/libbpf_legacy.h
@@ -57,6 +57,12 @@ enum libbpf_strict_mode {
* function name instead of section name.
*/
LIBBPF_STRICT_SEC_NAME = 0x04,
+ /*
+ * Disable the global 'bpf_objects_list'. Maintaining this list adds
+ * a race condition to bpf_object__open() and bpf_object__close().
+ * Clients can maintain it on their own if it is valuable for them.
+ */
+ LIBBPF_STRICT_NO_OBJECT_LIST = 0x08,
__LIBBPF_STRICT_LAST,
};
--
2.33.0.1079.g6e70778dc9-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libbpf: Deprecate bpf_objects_list
2021-10-26 22:27 [PATCH] libbpf: Deprecate bpf_objects_list Joe Burton
@ 2021-10-26 22:34 ` Joe Burton
2021-10-26 22:36 ` Joe Burton
1 sibling, 0 replies; 3+ messages in thread
From: Joe Burton @ 2021-10-26 22:34 UTC (permalink / raw)
To: Joe Burton; +Cc: Andrii Nakryiko, linux-mm, linux-kernel, trivial
[-- Attachment #1: Type: text/plain, Size: 3577 bytes --]
I missed up the mailing lists and will be resending this patch series in a
moment. Apologies for the noise.
Best,
Joe Burton
On Tue, Oct 26, 2021 at 3:27 PM Joe Burton <jevburton.kernel@gmail.com>
wrote:
> From: Joe Burton <jevburton@google.com>
>
> Add a flag to `enum libbpf_strict_mode' to disable the global
> `bpf_objects_list', preventing race conditions when concurrent threads
> call bpf_object__open() or bpf_object__close().
>
> bpf_object__next() will return NULL if this option is set.
>
> Callers may achieve the same workflow by tracking bpf_objects in
> application code.
>
> [0] Closes: https://github.com/libbpf/libbpf/issues/293
>
> Signed-off-by: Joe Burton <jevburton@google.com>
> ---
> tools/lib/bpf/libbpf.c | 8 +++++++-
> tools/lib/bpf/libbpf.h | 3 ++-
> tools/lib/bpf/libbpf_legacy.h | 6 ++++++
> 3 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 2fbed2d4a645..59d39ce9f375 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1148,6 +1148,7 @@ static struct bpf_object *bpf_object__new(const char
> *path,
> size_t obj_buf_sz,
> const char *obj_name)
> {
> + bool strict = (libbpf_mode & LIBBPF_STRICT_NO_OBJECT_LIST);
> struct bpf_object *obj;
> char *end;
>
> @@ -1188,7 +1189,8 @@ static struct bpf_object *bpf_object__new(const char
> *path,
> obj->loaded = false;
>
> INIT_LIST_HEAD(&obj->list);
> - list_add(&obj->list, &bpf_objects_list);
> + if (!strict)
> + list_add(&obj->list, &bpf_objects_list);
> return obj;
> }
>
> @@ -7935,6 +7937,10 @@ struct bpf_object *
> bpf_object__next(struct bpf_object *prev)
> {
> struct bpf_object *next;
> + bool strict = (libbpf_mode & LIBBPF_STRICT_NO_OBJECT_LIST);
> +
> + if (strict)
> + return NULL;
>
> if (!prev)
> next = list_first_entry(&bpf_objects_list,
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index e1900819bfab..defabdbe7760 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -168,7 +168,8 @@ LIBBPF_API struct bpf_program *
> bpf_object__find_program_by_name(const struct bpf_object *obj,
> const char *name);
>
> -LIBBPF_API struct bpf_object *bpf_object__next(struct bpf_object *prev);
> +LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "track bpf_objects in
> application code instead")
> +struct bpf_object *bpf_object__next(struct bpf_object *prev);
> #define bpf_object__for_each_safe(pos, tmp) \
> for ((pos) = bpf_object__next(NULL), \
> (tmp) = bpf_object__next(pos); \
> diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h
> index 29ccafab11a8..5ba5c9beccfa 100644
> --- a/tools/lib/bpf/libbpf_legacy.h
> +++ b/tools/lib/bpf/libbpf_legacy.h
> @@ -57,6 +57,12 @@ enum libbpf_strict_mode {
> * function name instead of section name.
> */
> LIBBPF_STRICT_SEC_NAME = 0x04,
> + /*
> + * Disable the global 'bpf_objects_list'. Maintaining this list
> adds
> + * a race condition to bpf_object__open() and bpf_object__close().
> + * Clients can maintain it on their own if it is valuable for them.
> + */
> + LIBBPF_STRICT_NO_OBJECT_LIST = 0x08,
>
> __LIBBPF_STRICT_LAST,
> };
> --
> 2.33.0.1079.g6e70778dc9-goog
>
>
[-- Attachment #2: Type: text/html, Size: 4677 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libbpf: Deprecate bpf_objects_list
2021-10-26 22:27 [PATCH] libbpf: Deprecate bpf_objects_list Joe Burton
2021-10-26 22:34 ` Joe Burton
@ 2021-10-26 22:36 ` Joe Burton
1 sibling, 0 replies; 3+ messages in thread
From: Joe Burton @ 2021-10-26 22:36 UTC (permalink / raw)
To: Joe Burton; +Cc: Andrii Nakryiko, linux-mm, linux-kernel, trivial
I messed up the mailing lists and will be resending this patch series
in a moment. Apologies for the noise.
Best,
Joe Burton
On Tue, Oct 26, 2021 at 3:27 PM Joe Burton <jevburton.kernel@gmail.com> wrote:
>
> From: Joe Burton <jevburton@google.com>
>
> Add a flag to `enum libbpf_strict_mode' to disable the global
> `bpf_objects_list', preventing race conditions when concurrent threads
> call bpf_object__open() or bpf_object__close().
>
> bpf_object__next() will return NULL if this option is set.
>
> Callers may achieve the same workflow by tracking bpf_objects in
> application code.
>
> [0] Closes: https://github.com/libbpf/libbpf/issues/293
>
> Signed-off-by: Joe Burton <jevburton@google.com>
> ---
> tools/lib/bpf/libbpf.c | 8 +++++++-
> tools/lib/bpf/libbpf.h | 3 ++-
> tools/lib/bpf/libbpf_legacy.h | 6 ++++++
> 3 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 2fbed2d4a645..59d39ce9f375 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1148,6 +1148,7 @@ static struct bpf_object *bpf_object__new(const char *path,
> size_t obj_buf_sz,
> const char *obj_name)
> {
> + bool strict = (libbpf_mode & LIBBPF_STRICT_NO_OBJECT_LIST);
> struct bpf_object *obj;
> char *end;
>
> @@ -1188,7 +1189,8 @@ static struct bpf_object *bpf_object__new(const char *path,
> obj->loaded = false;
>
> INIT_LIST_HEAD(&obj->list);
> - list_add(&obj->list, &bpf_objects_list);
> + if (!strict)
> + list_add(&obj->list, &bpf_objects_list);
> return obj;
> }
>
> @@ -7935,6 +7937,10 @@ struct bpf_object *
> bpf_object__next(struct bpf_object *prev)
> {
> struct bpf_object *next;
> + bool strict = (libbpf_mode & LIBBPF_STRICT_NO_OBJECT_LIST);
> +
> + if (strict)
> + return NULL;
>
> if (!prev)
> next = list_first_entry(&bpf_objects_list,
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index e1900819bfab..defabdbe7760 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -168,7 +168,8 @@ LIBBPF_API struct bpf_program *
> bpf_object__find_program_by_name(const struct bpf_object *obj,
> const char *name);
>
> -LIBBPF_API struct bpf_object *bpf_object__next(struct bpf_object *prev);
> +LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "track bpf_objects in application code instead")
> +struct bpf_object *bpf_object__next(struct bpf_object *prev);
> #define bpf_object__for_each_safe(pos, tmp) \
> for ((pos) = bpf_object__next(NULL), \
> (tmp) = bpf_object__next(pos); \
> diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h
> index 29ccafab11a8..5ba5c9beccfa 100644
> --- a/tools/lib/bpf/libbpf_legacy.h
> +++ b/tools/lib/bpf/libbpf_legacy.h
> @@ -57,6 +57,12 @@ enum libbpf_strict_mode {
> * function name instead of section name.
> */
> LIBBPF_STRICT_SEC_NAME = 0x04,
> + /*
> + * Disable the global 'bpf_objects_list'. Maintaining this list adds
> + * a race condition to bpf_object__open() and bpf_object__close().
> + * Clients can maintain it on their own if it is valuable for them.
> + */
> + LIBBPF_STRICT_NO_OBJECT_LIST = 0x08,
>
> __LIBBPF_STRICT_LAST,
> };
> --
> 2.33.0.1079.g6e70778dc9-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-26 22:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 22:27 [PATCH] libbpf: Deprecate bpf_objects_list Joe Burton
2021-10-26 22:34 ` Joe Burton
2021-10-26 22:36 ` Joe Burton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox