From: Geliang Tang <tanggeliang@kylinos.cn>
This patch extracts duplicate code on error path when btf_get_module_btf()
returns NULL from the functions __register_btf_kfunc_id_set() and
register_btf_id_dtor_kfuncs() into a new helper named
register_check_missing_btf() to check CONFIG_DEBUG_INFO_BTF,
CONFIG_DEBUG_INFO_BTF_MODULES and CONFIG_MODULE_ALLOW_BTF_MISMATCH in it.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
kernel/bpf/btf.c | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index f7725cb6e564..1ebe26a3a7a5 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -7738,6 +7738,24 @@ static struct btf *btf_get_module_btf(const struct module *module)
return btf;
}
+static int register_check_missing_btf(const struct module *module, const char *msg)
+{
+ if (!module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
+ pr_err("missing vmlinux BTF, cannot register %s\n", msg);
+ return -ENOENT;
+ }
+ if (module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) {
+ if (IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) {
+ pr_warn("allow module %s BTF mismatch, skip register %s\n",
+ module->name, msg);
+ return 0;
+ }
+ pr_err("missing module %s BTF, cannot register %s\n", module->name, msg);
+ return -ENOENT;
+ }
+ return 0;
+}
+
BPF_CALL_4(bpf_btf_find_by_name_kind, char *, name, int, name_sz, u32, kind, int, flags)
{
struct btf *btf = NULL;
@@ -8098,15 +8116,8 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,
int ret, i;
btf = btf_get_module_btf(kset->owner);
- if (!btf) {
- if (!kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
- pr_err("missing vmlinux BTF, cannot register kfuncs\n");
- return -ENOENT;
- }
- if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
- pr_warn("missing module BTF, cannot register kfuncs\n");
- return 0;
- }
+ if (!btf)
+ return register_check_missing_btf(kset->owner, "kfuncs");
if (IS_ERR(btf))
return PTR_ERR(btf);
@@ -8214,17 +8225,8 @@ int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_c
int ret;
btf = btf_get_module_btf(owner);
- if (!btf) {
- if (!owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
- pr_err("missing vmlinux BTF, cannot register dtor kfuncs\n");
- return -ENOENT;
- }
- if (owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) {
- pr_err("missing module BTF, cannot register dtor kfuncs\n");
- return -ENOENT;
- }
- return 0;
- }
+ if (!btf)
+ return register_check_missing_btf(owner, "dtor kfuncs");
if (IS_ERR(btf))
return PTR_ERR(btf);
--
2.40.1
Hi Geliang, kernel test robot noticed the following build errors: [auto build test ERROR on bpf-next/master] url: https://github.com/intel-lab-lkp/linux/commits/Geliang-Tang/bpf-btf-Add-register_check_missing_btf-helper/20240203-155524 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/f4b147ddaa8fe8c07c7ba77a1d61780bffc49bb6.1706946547.git.tanggeliang%40kylinos.cn patch subject: [PATCH bpf-next v2 1/2] bpf, btf: Add register_check_missing_btf helper config: arm-imxrt_defconfig (https://download.01.org/0day-ci/archive/20240204/202402040934.Fph0XeEo-lkp@intel.com/config) compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 7dd790db8b77c4a833c06632e903dc4f13877a64) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240204/202402040934.Fph0XeEo-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202402040934.Fph0XeEo-lkp@intel.com/ All errors (new ones prefixed by >>): >> kernel/bpf/btf.c:7750:11: error: incomplete definition of type 'struct module' 7750 | module->name, msg); | ~~~~~~^ include/linux/printk.h:508:37: note: expanded from macro 'pr_warn' 508 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | ^~~~~~~~~~~ include/linux/printk.h:455:60: note: expanded from macro 'printk' 455 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__) | ^~~~~~~~~~~ include/linux/printk.h:427:19: note: expanded from macro 'printk_index_wrap' 427 | _p_func(_fmt, ##__VA_ARGS__); \ | ^~~~~~~~~~~ include/linux/printk.h:348:8: note: forward declaration of 'struct module' 348 | struct module; | ^ kernel/bpf/btf.c:7753:63: error: incomplete definition of type 'struct module' 7753 | pr_err("missing module %s BTF, cannot register %s\n", module->name, msg); | ~~~~~~^ include/linux/printk.h:498:33: note: expanded from macro 'pr_err' 498 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | ^~~~~~~~~~~ include/linux/printk.h:455:60: note: expanded from macro 'printk' 455 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__) | ^~~~~~~~~~~ include/linux/printk.h:427:19: note: expanded from macro 'printk_index_wrap' 427 | _p_func(_fmt, ##__VA_ARGS__); \ | ^~~~~~~~~~~ include/linux/printk.h:348:8: note: forward declaration of 'struct module' 348 | struct module; | ^ 2 errors generated. vim +7750 kernel/bpf/btf.c 7740 7741 static int register_check_missing_btf(const struct module *module, const char *msg) 7742 { 7743 if (!module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { 7744 pr_err("missing vmlinux BTF, cannot register %s\n", msg); 7745 return -ENOENT; 7746 } 7747 if (module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) { 7748 if (IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) { 7749 pr_warn("allow module %s BTF mismatch, skip register %s\n", > 7750 module->name, msg); 7751 return 0; 7752 } 7753 pr_err("missing module %s BTF, cannot register %s\n", module->name, msg); 7754 return -ENOENT; 7755 } 7756 return 0; 7757 } 7758 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Hi Geliang, kernel test robot noticed the following build errors: [auto build test ERROR on bpf-next/master] url: https://github.com/intel-lab-lkp/linux/commits/Geliang-Tang/bpf-btf-Add-register_check_missing_btf-helper/20240203-155524 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/f4b147ddaa8fe8c07c7ba77a1d61780bffc49bb6.1706946547.git.tanggeliang%40kylinos.cn patch subject: [PATCH bpf-next v2 1/2] bpf, btf: Add register_check_missing_btf helper config: arm-randconfig-001-20240204 (https://download.01.org/0day-ci/archive/20240204/202402040740.WcfFYJQX-lkp@intel.com/config) compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240204/202402040740.WcfFYJQX-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202402040740.WcfFYJQX-lkp@intel.com/ All errors (new ones prefixed by >>): kernel/bpf/btf.c: In function 'btf_seq_show': kernel/bpf/btf.c:7286:29: warning: function 'btf_seq_show' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format] 7286 | seq_vprintf((struct seq_file *)show->target, fmt, args); | ^~~~~~~~ kernel/bpf/btf.c: In function 'btf_snprintf_show': kernel/bpf/btf.c:7323:9: warning: function 'btf_snprintf_show' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format] 7323 | len = vsnprintf(show->target, ssnprintf->len_left, fmt, args); | ^~~ In file included from include/asm-generic/bug.h:22, from arch/arm/include/asm/bug.h:60, from include/linux/bug.h:5, from include/linux/thread_info.h:13, from include/linux/sched.h:14, from include/linux/ptrace.h:6, from include/uapi/asm-generic/bpf_perf_event.h:4, from ./arch/arm/include/generated/uapi/asm/bpf_perf_event.h:1, from include/uapi/linux/bpf_perf_event.h:11, from kernel/bpf/btf.c:6: kernel/bpf/btf.c: In function 'register_check_missing_btf': >> kernel/bpf/btf.c:7750:39: error: invalid use of undefined type 'const struct module' 7750 | module->name, msg); | ^~ include/linux/printk.h:427:33: note: in definition of macro 'printk_index_wrap' 427 | _p_func(_fmt, ##__VA_ARGS__); \ | ^~~~~~~~~~~ include/linux/printk.h:508:9: note: in expansion of macro 'printk' 508 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | ^~~~~~ kernel/bpf/btf.c:7749:25: note: in expansion of macro 'pr_warn' 7749 | pr_warn("allow module %s BTF mismatch, skip register %s\n", | ^~~~~~~ kernel/bpf/btf.c:7753:77: error: invalid use of undefined type 'const struct module' 7753 | pr_err("missing module %s BTF, cannot register %s\n", module->name, msg); | ^~ include/linux/printk.h:427:33: note: in definition of macro 'printk_index_wrap' 427 | _p_func(_fmt, ##__VA_ARGS__); \ | ^~~~~~~~~~~ include/linux/printk.h:498:9: note: in expansion of macro 'printk' 498 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | ^~~~~~ kernel/bpf/btf.c:7753:17: note: in expansion of macro 'pr_err' 7753 | pr_err("missing module %s BTF, cannot register %s\n", module->name, msg); | ^~~~~~ vim +7750 kernel/bpf/btf.c 7740 7741 static int register_check_missing_btf(const struct module *module, const char *msg) 7742 { 7743 if (!module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { 7744 pr_err("missing vmlinux BTF, cannot register %s\n", msg); 7745 return -ENOENT; 7746 } 7747 if (module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) { 7748 if (IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) { 7749 pr_warn("allow module %s BTF mismatch, skip register %s\n", > 7750 module->name, msg); 7751 return 0; 7752 } 7753 pr_err("missing module %s BTF, cannot register %s\n", module->name, msg); 7754 return -ENOENT; 7755 } 7756 return 0; 7757 } 7758 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2024 Red Hat, Inc.