Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'bpf, btf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops'

Geliang Tang says:

====================
bpf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops

This patch set avoids module loading failure when the module
trying to register a struct_ops and the module has its btf section
stripped. This will then work similarly as module kfunc registration in
commit 3de4d22cc9ac ("bpf, btf: Warn but return no error for NULL btf from __register_btf_kfunc_id_set()")

v5:
- drop CONFIG_MODULE_ALLOW_BTF_MISMATCH check as Martin suggested.

v4:
- add a new patch to fix error checks for btf_get_module_btf.
- rename the helper to check_btf_kconfigs.

v3:
- fix this build error:
kernel/bpf/btf.c:7750:11: error: incomplete definition of type 'struct module'

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202402040934.Fph0XeEo-lkp@intel.com/

v2:
- add register_check_missing_btf helper as Jiri suggested.
====================

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

+18 -21
+18 -21
kernel/bpf/btf.c
··· 7738 7738 return btf; 7739 7739 } 7740 7740 7741 + static int check_btf_kconfigs(const struct module *module, const char *feature) 7742 + { 7743 + if (!module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { 7744 + pr_err("missing vmlinux BTF, cannot register %s\n", feature); 7745 + return -ENOENT; 7746 + } 7747 + if (module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) 7748 + pr_warn("missing module BTF, cannot register %s\n", feature); 7749 + return 0; 7750 + } 7751 + 7741 7752 BPF_CALL_4(bpf_btf_find_by_name_kind, char *, name, int, name_sz, u32, kind, int, flags) 7742 7753 { 7743 7754 struct btf *btf = NULL; ··· 8109 8098 int ret, i; 8110 8099 8111 8100 btf = btf_get_module_btf(kset->owner); 8112 - if (!btf) { 8113 - if (!kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { 8114 - pr_err("missing vmlinux BTF, cannot register kfuncs\n"); 8115 - return -ENOENT; 8116 - } 8117 - if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) 8118 - pr_warn("missing module BTF, cannot register kfuncs\n"); 8119 - return 0; 8120 - } 8101 + if (!btf) 8102 + return check_btf_kconfigs(kset->owner, "kfunc"); 8121 8103 if (IS_ERR(btf)) 8122 8104 return PTR_ERR(btf); 8123 8105 ··· 8218 8214 int ret; 8219 8215 8220 8216 btf = btf_get_module_btf(owner); 8221 - if (!btf) { 8222 - if (!owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { 8223 - pr_err("missing vmlinux BTF, cannot register dtor kfuncs\n"); 8224 - return -ENOENT; 8225 - } 8226 - if (owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) { 8227 - pr_err("missing module BTF, cannot register dtor kfuncs\n"); 8228 - return -ENOENT; 8229 - } 8230 - return 0; 8231 - } 8217 + if (!btf) 8218 + return check_btf_kconfigs(owner, "dtor kfuncs"); 8232 8219 if (IS_ERR(btf)) 8233 8220 return PTR_ERR(btf); 8234 8221 ··· 8882 8887 8883 8888 btf = btf_get_module_btf(st_ops->owner); 8884 8889 if (!btf) 8885 - return -EINVAL; 8890 + return check_btf_kconfigs(st_ops->owner, "struct_ops"); 8891 + if (IS_ERR(btf)) 8892 + return PTR_ERR(btf); 8886 8893 8887 8894 log = kzalloc(sizeof(*log), GFP_KERNEL | __GFP_NOWARN); 8888 8895 if (!log) {