Skip to contentSkip to conversation

Fixes for kfunc-mod regressions and warnings

PATCH Superseded Kumar Kartikeya Dwivedi 2 participants 7 messages Nov 16, 2021 – Nov 19, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
author maintainer
#3 lore raw

PATCH 3/3 tools/resolve_btfids: Demote unresolved symbol message to debug

In reply to Kumar Kartikeya Dwivedi

resolve_btfids prints a warning when it finds an unresolved symbol, (id == 0) in id_patch. This can be the case for BTF sets that are empty (due to disabled config options), hence printing warnings for certain builds, most recently seen in [0]. Hence, demote the warning to debug log level to avoid build time noise.

[0]: https://lore.kernel.org/all/[email protected]

Fixes 0e32dfc80bae ("bpf: Enable TCP congestion control kfunc from modules")
---
 tools/bpf/resolve_btfids/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/resolve_btfids/main.c +1 -1
index a59cb0ee609c..833bfcc9ccf6 100644
@@ -569,7 +569,7 @@ static int id_patch(struct object *obj, struct btf_id *id)
 	int i;
 
 	if (!id->id) {
-		pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
+		pr_debug("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
 	}
 
 	for (i = 0; i < id->addr_cnt; i++) {
Signature · 1 line
2.33.1

Kumar Kartikeya Dwivedi

author maintainer
#0 lore raw

cover Fixes for kfunc-mod regressions and warnings

This set includes fixes for two regressions and one build warning introduced by the kfunc for modules series.

Kumar Kartikeya Dwivedi (3):
bpf: Make CONFIG_DEBUG_INFO_BTF depend upon CONFIG_BPF_SYSCALL
bpf: Fix bpf_check_mod_kfunc_call for built-in modules tools/resolve_btfids: Demote unresolved symbol message to debug

 include/linux/btf.h             | 14 ++++++++++----
 kernel/bpf/btf.c                | 11 ++---------
 lib/Kconfig.debug               |  1 +
 tools/bpf/resolve_btfids/main.c |  2 +-
 4 files changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
2.33.1
author maintainer
#1 lore raw

PATCH 1/3 bpf: Make CONFIG_DEBUG_INFO_BTF depend upon CONFIG_BPF_SYSCALL

Vinicius Costa Gomes reported [0] that build fails when CONFIG_DEBUG_INFO_BTF is enabled and CONFIG_BPF_SYSCALL is disabled. This leads to btf.c not being compiled, and then no symbol being present in vmlinux for the declarations in btf.h. Since BTF is not useful without enabling BPF subsystem, disallow this combination.

However, theoretically disabling both now could still fail, as the symbol for kfunc_btf_id_list variables is not available. This isn't a problem as the compiler usually optimizes the whole register/unregister call, but at lower optimization levels it can fail the build in linking stage.

Fix that by adding dummy variables so that modules taking address of them still work, but the whole thing is a noop.

[0]: https://lore.kernel.org/bpf/[email protected]

Fixes 14f267d95fe4 ("bpf: btf: Introduce helpers for dynamic BTF set registration")
---
 include/linux/btf.h | 14 ++++++++++----
 kernel/bpf/btf.c    |  9 ++-------
 lib/Kconfig.debug   |  1 +
 3 files changed, 13 insertions(+), 11 deletions(-)
include/linux/btf.h +10 -4
index 203eef993d76..0e1b6281fd8f 100644
@@ -245,7 +245,10 @@ struct kfunc_btf_id_set {
 	struct module *owner;
 };
 
-struct kfunc_btf_id_list;
+struct kfunc_btf_id_list {
+	struct list_head list;
+	struct mutex mutex;
+};
 
 #ifdef CONFIG_DEBUG_INFO_BTF_MODULES
 void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
@@ -254,6 +257,9 @@ void unregister_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
 				 struct kfunc_btf_id_set *s);
 bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
 			      struct module *owner);
+
+extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
+extern struct kfunc_btf_id_list prog_test_kfunc_list;
 #else
 static inline void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
 					     struct kfunc_btf_id_set *s)
@@ -268,13 +274,13 @@ static inline bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist,
 {
 	return false;
 }
+
+static struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list __maybe_unused;
+static struct kfunc_btf_id_list prog_test_kfunc_list __maybe_unused;
 #endif
 
 #define DEFINE_KFUNC_BTF_ID_SET(set, name)                                     \
 	struct kfunc_btf_id_set name = { LIST_HEAD_INIT(name.list), (set),     \
 					 THIS_MODULE }
 
-extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
-extern struct kfunc_btf_id_list prog_test_kfunc_list;
-
 #endif
kernel/bpf/btf.c +2 -7
index 6b9d23be1e99..3ace85d496ae 100644
@@ -6361,11 +6361,6 @@ BTF_TRACING_TYPE_xxx
 
 /* BTF ID set registration API for modules */
 
-struct kfunc_btf_id_list {
-	struct list_head list;
-	struct mutex mutex;
-};
-
 #ifdef CONFIG_DEBUG_INFO_BTF_MODULES
 
 void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
@@ -6404,8 +6399,6 @@ bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
 	return false;
 }
 
-#endif
-
 #define DEFINE_KFUNC_BTF_ID_LIST(name)                                         \
 	struct kfunc_btf_id_list name = { LIST_HEAD_INIT(name.list),           \
 					  __MUTEX_INITIALIZER(name.mutex) };   \
@@ -6413,3 +6406,5 @@ bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
 
 DEFINE_KFUNC_BTF_ID_LIST(bpf_tcp_ca_kfunc_list);
 DEFINE_KFUNC_BTF_ID_LIST(prog_test_kfunc_list);
+
+#endif
lib/Kconfig.debug +1 -0
index 6fdbf9613aec..eae860c86e26 100644
@@ -316,6 +316,7 @@ config DEBUG_INFO_BTF
 	bool "Generate BTF typeinfo"
 	depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
 	depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
+	depends on BPF_SYSCALL
 	help
 	  Generate deduplicated BTF type information from DWARF debug info.
 	  Turning this on expects presence of pahole tool, which will convert
Signature · 1 line
2.33.1
author maintainer
#2 lore raw

PATCH 2/3 bpf: Fix bpf_check_mod_kfunc_call for built-in modules

In reply to Kumar Kartikeya Dwivedi

When module registering its set is built-in, THIS_MODULE will be NULL, hence we cannot return early in case owner is NULL.

Fixes 14f267d95fe4 ("bpf: btf: Introduce helpers for dynamic BTF set registration")
---
 kernel/bpf/btf.c | 2 --
 1 file changed, 2 deletions(-)
kernel/bpf/btf.c +0 -2
index 3ace85d496ae..48cdf5b425a7 100644
@@ -6386,8 +6386,6 @@ bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
 {
 	struct kfunc_btf_id_set *s;
 
-	if (!owner)
-		return false;
 	mutex_lock(&klist->mutex);
 	list_for_each_entry(s, &klist->list, list) {
 		if (s->owner == owner && btf_id_set_contains(s->set, kfunc_id)) {
Signature · 1 line
2.33.1
#4 lore raw

Re: [PATCH bpf v1 3/3] tools/resolve_btfids: Demote unresolved symbol message to debug

In reply to Kumar Kartikeya Dwivedi
Quoted 21 lines · Kumar Kartikeya Dwivedi

resolve_btfids prints a warning when it finds an unresolved symbol, (id == 0) in id_patch. This can be the case for BTF sets that are empty (due to disabled config options), hence printing warnings for certain builds, most recently seen in [0]. Hence, demote the warning to debug log level to avoid build time noise.

[0]: https://lore.kernel.org/all/[email protected]

Fixes 0e32dfc80bae ("bpf: Enable TCP congestion control kfunc from modules")
---
 tools/bpf/resolve_btfids/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/resolve_btfids/main.c +0 -0
index a59cb0ee609c..833bfcc9ccf6 100644

tools/bpf/resolve_btfids/main.c static int id_patch(struct object *obj, struct btf_id *id) · line 572

Quoted 5 lines
tools/bpf/resolve_btfids/main.c +1 -1
@@ -569,7 +569,7 @@ static int id_patch(struct object *obj, struct btf_id *id)
        int i;
 
        if (!id->id) {
-               pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
+               pr_debug("WARN: resolve_btfids: unresolved symbol %s\n", id->name);

This is an important warning that helps detect some misconfiguration, we cannot just hide it. If it really is happening for empty lists (why?), we should handle empty lists better, but not hide the warning.

Quoted 6 lines
tools/bpf/resolve_btfids/main.c +0 -1
        }
 
        for (i = 0; i < id->addr_cnt; i++) {
--

2.33.1

author maintainer
#5 lore raw

Re: [PATCH bpf v1 3/3] tools/resolve_btfids: Demote unresolved symbol message to debug

Quoted 25 lines · Andrii Nakryiko
Quoted 23 lines · Kumar Kartikeya Dwivedi

resolve_btfids prints a warning when it finds an unresolved symbol, (id == 0) in id_patch. This can be the case for BTF sets that are empty (due to disabled config options), hence printing warnings for certain builds, most recently seen in [0]. Hence, demote the warning to debug log level to avoid build time noise.

[0]: https://lore.kernel.org/all/[email protected]

Fixes 0e32dfc80bae ("bpf: Enable TCP congestion control kfunc from modules")
---
 tools/bpf/resolve_btfids/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/resolve_btfids/main.c +0 -0
index a59cb0ee609c..833bfcc9ccf6 100644
@@ -569,7 +569,7 @@ static int id_patch(struct object *obj, struct btf_id *id)
        int i;
 
Quoted 8 lines

tools/bpf/resolve_btfids/main.c static int id_patch(struct object *obj, struct btf_id *id) · line 572

Quoted 3 lines
tools/bpf/resolve_btfids/main.c +1 -1
        if (!id->id) {
-               pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
+               pr_debug("WARN: resolve_btfids: unresolved symbol %s\n", id->name);

This is an important warning that helps detect some misconfiguration, we cannot just hide it. If it really is happening for empty lists (why?), we should handle empty lists better, but not hide the warning.

+Cc Jiri

Sorry for the delay. The 'why' is because in case of empty BTF set, the id->cnt aliasing over id->id (for non-set __BTF_ID_*) is zero, so it trips over when it sees it as 0 for empty set in id_patch.

So, what would be your opinion on how to handle this case? Ignore the warning case for empty sets specifically? (e.g. using string comparison in id_patch for id->name, or split id and cnt out of union and assign non-zero to id in case cnt == 0, otherwise copy (saving strncmp for all symbols in id_patch))

Also, if I'm respinning, any comments on the first two which are also fixes for bugs I introduced, so that we can avoid another round?

--
Kartikeya

author maintainer
#6 lore raw

Re: [PATCH bpf v1 3/3] tools/resolve_btfids: Demote unresolved symbol message to debug

Quoted 37 lines · Kumar Kartikeya Dwivedi
Quoted 25 lines · Andrii Nakryiko
Quoted 23 lines · Kumar Kartikeya Dwivedi

resolve_btfids prints a warning when it finds an unresolved symbol, (id == 0) in id_patch. This can be the case for BTF sets that are empty (due to disabled config options), hence printing warnings for certain builds, most recently seen in [0]. Hence, demote the warning to debug log level to avoid build time noise.

[0]: https://lore.kernel.org/all/[email protected]

Fixes 0e32dfc80bae ("bpf: Enable TCP congestion control kfunc from modules")
---
 tools/bpf/resolve_btfids/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/resolve_btfids/main.c +0 -0
index a59cb0ee609c..833bfcc9ccf6 100644
@@ -569,7 +569,7 @@ static int id_patch(struct object *obj, struct btf_id *id)
        int i;
 
Quoted 8 lines

tools/bpf/resolve_btfids/main.c static int id_patch(struct object *obj, struct btf_id *id) · line 572

Quoted 3 lines
tools/bpf/resolve_btfids/main.c +1 -1
        if (!id->id) {
-               pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
+               pr_debug("WARN: resolve_btfids: unresolved symbol %s\n", id->name);

This is an important warning that helps detect some misconfiguration, we cannot just hide it. If it really is happening for empty lists (why?), we should handle empty lists better, but not hide the warning.

+Cc Jiri

Quoted 7 lines

Sorry for the delay. The 'why' is because in case of empty BTF set, the id->cnt aliasing over id->id (for non-set __BTF_ID_*) is zero, so it trips over when it sees it as 0 for empty set in id_patch.

So, what would be your opinion on how to handle this case? Ignore the warning case for empty sets specifically? (e.g. using string comparison in id_patch for id->name, or split id and cnt out of union and assign non-zero to id in case cnt

Ah, I realized after sending that actually would be far more work (and also confusing/error prone), since it is copied to ptr[idx] as id->id once in id_patch and then used as cnt for sorting in sets_patch, which would break qsort. Just recording that it is a set in btf_id struct might be better.

--
Kartikeya