Message ID | 1658221305-35718-1-git-send-email-xujia39@huawei.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | [bpf-next] bpf: fix bpf compile error caused by CONFIG_CGROUP_BPF | expand |
On Tue, Jul 19, 2022 at 1:49 AM Xu Jia <xujia39@huawei.com> wrote: > > We failed to compile when CONFIG_BPF_LSM is enabled but CONFIG_CGROUP_BPF > is not set. The failings are shown as below: > > kernel/bpf/trampoline.o: in function `bpf_trampoline_link_cgroup_shim' > trampoline.c: undefined reference to `bpf_cgroup_atype_get' > kernel/bpf/bpf_lsm.o: In function `bpf_lsm_find_cgroup_shim': > bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_current' > bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_sock' > bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_socket' > > Fix them by protecting these functions with CONFIG_CGROUP_BPF. Should be fixed by the following? https://lore.kernel.org/bpf/20220714185404.3647772-1-sdf@google.com/ > Fixes: 69fd337a975c ("bpf: per-cgroup lsm flavor") > Signed-off-by: Xu Jia <xujia39@huawei.com> > --- > include/linux/bpf.h | 12 +++++++++--- > include/linux/bpf_lsm.h | 10 ++++++---- > kernel/bpf/bpf_lsm.c | 2 ++ > kernel/bpf/trampoline.c | 2 ++ > 4 files changed, 19 insertions(+), 7 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 2b21f2a3452f..add8895c02cc 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -1255,9 +1255,7 @@ struct bpf_dummy_ops { > int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, > union bpf_attr __user *uattr); > #endif > -int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, > - int cgroup_atype); > -void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog); > + > #else > static inline const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id) > { > @@ -1281,6 +1279,14 @@ static inline int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map, > { > return -EINVAL; > } > +#endif > + > +#if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL) && \ > + defined(CONFIG_CGROUP_BPF) > +int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, > + int cgroup_atype); > +void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog); > +#else > static inline int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, > int cgroup_atype) > { > diff --git a/include/linux/bpf_lsm.h b/include/linux/bpf_lsm.h > index 4bcf76a9bb06..bed45a0c8a9c 100644 > --- a/include/linux/bpf_lsm.h > +++ b/include/linux/bpf_lsm.h > @@ -42,8 +42,6 @@ extern const struct bpf_func_proto bpf_inode_storage_get_proto; > extern const struct bpf_func_proto bpf_inode_storage_delete_proto; > void bpf_inode_storage_free(struct inode *inode); > > -void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); > - > #else /* !CONFIG_BPF_LSM */ > > static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id) > @@ -67,11 +65,15 @@ static inline void bpf_inode_storage_free(struct inode *inode) > { > } > > +#endif /* CONFIG_BPF_LSM */ > + > +#if defined(CONFIG_BPF_LSM) && defined(CONFIG_BPF_CGROUP) > +void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); > +#else > static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, > bpf_func_t *bpf_func) > { > } > - > -#endif /* CONFIG_BPF_LSM */ > +#endif > > #endif /* _LINUX_BPF_LSM_H */ > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > index d469b7f3deef..29527828b38b 100644 > --- a/kernel/bpf/bpf_lsm.c > +++ b/kernel/bpf/bpf_lsm.c > @@ -63,6 +63,7 @@ BTF_ID(func, bpf_lsm_socket_post_create) > BTF_ID(func, bpf_lsm_socket_socketpair) > BTF_SET_END(bpf_lsm_unlocked_sockopt_hooks) > > +#ifdef CONFIG_BPF_CGROUP > void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, > bpf_func_t *bpf_func) > { > @@ -86,6 +87,7 @@ void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, > #endif > *bpf_func = __cgroup_bpf_run_lsm_current; > } > +#endif /* CONFIG_BPF_CGROUP */ > > int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, > const struct bpf_prog *prog) > diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c > index 6cd226584c33..127924711935 100644 > --- a/kernel/bpf/trampoline.c > +++ b/kernel/bpf/trampoline.c > @@ -525,6 +525,7 @@ static const struct bpf_link_ops bpf_shim_tramp_link_lops = { > .dealloc = bpf_shim_tramp_link_dealloc, > }; > > +#ifdef CONFIG_CGROUP_BPF > static struct bpf_shim_tramp_link *cgroup_shim_alloc(const struct bpf_prog *prog, > bpf_func_t bpf_func, > int cgroup_atype) > @@ -668,6 +669,7 @@ void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog) > > bpf_trampoline_put(tr); /* bpf_trampoline_lookup above */ > } > +#endif /* CONFIG_CGROUP_BPF */ > #endif > > struct bpf_trampoline *bpf_trampoline_get(u64 key, > -- > 2.25.1 >
Hi Xu,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Xu-Jia/bpf-fix-bpf-compile-error-caused-by-CONFIG_CGROUP_BPF/20220719-165058
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: i386-randconfig-a005-20220718 (https://download.01.org/0day-ci/archive/20220720/202207201518.zmoBBoB6-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project dd5635541cd7bbd62cd59b6694dfb759b6e9a0d8)
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
# https://github.com/intel-lab-lkp/linux/commit/cfd7055cd0be7cfd0de5c24a84c29afe0611cb6c
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Xu-Jia/bpf-fix-bpf-compile-error-caused-by-CONFIG_CGROUP_BPF/20220719-165058
git checkout cfd7055cd0be7cfd0de5c24a84c29afe0611cb6c
# 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=i386 SHELL=/bin/bash drivers/ufs/core/ kernel/bpf/
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> kernel/bpf/trampoline.c:526:34: warning: unused variable 'bpf_shim_tramp_link_lops' [-Wunused-const-variable]
static const struct bpf_link_ops bpf_shim_tramp_link_lops = {
^
1 warning generated.
vim +/bpf_shim_tramp_link_lops +526 kernel/bpf/trampoline.c
69fd337a975c7e Stanislav Fomichev 2022-06-28 525
69fd337a975c7e Stanislav Fomichev 2022-06-28 @526 static const struct bpf_link_ops bpf_shim_tramp_link_lops = {
69fd337a975c7e Stanislav Fomichev 2022-06-28 527 .release = bpf_shim_tramp_link_release,
69fd337a975c7e Stanislav Fomichev 2022-06-28 528 .dealloc = bpf_shim_tramp_link_dealloc,
69fd337a975c7e Stanislav Fomichev 2022-06-28 529 };
69fd337a975c7e Stanislav Fomichev 2022-06-28 530
It is fixed, not warning again. Thank you very much! 在 2022/7/19 23:46, Stanislav Fomichev 写道: > On Tue, Jul 19, 2022 at 1:49 AM Xu Jia <xujia39@huawei.com> wrote: >> We failed to compile when CONFIG_BPF_LSM is enabled but CONFIG_CGROUP_BPF >> is not set. The failings are shown as below: >> >> kernel/bpf/trampoline.o: in function `bpf_trampoline_link_cgroup_shim' >> trampoline.c: undefined reference to `bpf_cgroup_atype_get' >> kernel/bpf/bpf_lsm.o: In function `bpf_lsm_find_cgroup_shim': >> bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_current' >> bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_sock' >> bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_socket' >> >> Fix them by protecting these functions with CONFIG_CGROUP_BPF. > Should be fixed by the following? > > https://lore.kernel.org/bpf/20220714185404.3647772-1-sdf@google.com/ > >> Fixes: 69fd337a975c ("bpf: per-cgroup lsm flavor") >> Signed-off-by: Xu Jia <xujia39@huawei.com> >> --- >> include/linux/bpf.h | 12 +++++++++--- >> include/linux/bpf_lsm.h | 10 ++++++---- >> kernel/bpf/bpf_lsm.c | 2 ++ >> kernel/bpf/trampoline.c | 2 ++ >> 4 files changed, 19 insertions(+), 7 deletions(-) >> >> diff --git a/include/linux/bpf.h b/include/linux/bpf.h >> index 2b21f2a3452f..add8895c02cc 100644 >> --- a/include/linux/bpf.h >> +++ b/include/linux/bpf.h >> @@ -1255,9 +1255,7 @@ struct bpf_dummy_ops { >> int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, >> union bpf_attr __user *uattr); >> #endif >> -int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, >> - int cgroup_atype); >> -void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog); >> + >> #else >> static inline const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id) >> { >> @@ -1281,6 +1279,14 @@ static inline int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map, >> { >> return -EINVAL; >> } >> +#endif >> + >> +#if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL) && \ >> + defined(CONFIG_CGROUP_BPF) >> +int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, >> + int cgroup_atype); >> +void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog); >> +#else >> static inline int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, >> int cgroup_atype) >> { >> diff --git a/include/linux/bpf_lsm.h b/include/linux/bpf_lsm.h >> index 4bcf76a9bb06..bed45a0c8a9c 100644 >> --- a/include/linux/bpf_lsm.h >> +++ b/include/linux/bpf_lsm.h >> @@ -42,8 +42,6 @@ extern const struct bpf_func_proto bpf_inode_storage_get_proto; >> extern const struct bpf_func_proto bpf_inode_storage_delete_proto; >> void bpf_inode_storage_free(struct inode *inode); >> >> -void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); >> - >> #else /* !CONFIG_BPF_LSM */ >> >> static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id) >> @@ -67,11 +65,15 @@ static inline void bpf_inode_storage_free(struct inode *inode) >> { >> } >> >> +#endif /* CONFIG_BPF_LSM */ >> + >> +#if defined(CONFIG_BPF_LSM) && defined(CONFIG_BPF_CGROUP) >> +void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); >> +#else >> static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, >> bpf_func_t *bpf_func) >> { >> } >> - >> -#endif /* CONFIG_BPF_LSM */ >> +#endif >> >> #endif /* _LINUX_BPF_LSM_H */ >> diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c >> index d469b7f3deef..29527828b38b 100644 >> --- a/kernel/bpf/bpf_lsm.c >> +++ b/kernel/bpf/bpf_lsm.c >> @@ -63,6 +63,7 @@ BTF_ID(func, bpf_lsm_socket_post_create) >> BTF_ID(func, bpf_lsm_socket_socketpair) >> BTF_SET_END(bpf_lsm_unlocked_sockopt_hooks) >> >> +#ifdef CONFIG_BPF_CGROUP >> void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, >> bpf_func_t *bpf_func) >> { >> @@ -86,6 +87,7 @@ void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, >> #endif >> *bpf_func = __cgroup_bpf_run_lsm_current; >> } >> +#endif /* CONFIG_BPF_CGROUP */ >> >> int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, >> const struct bpf_prog *prog) >> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c >> index 6cd226584c33..127924711935 100644 >> --- a/kernel/bpf/trampoline.c >> +++ b/kernel/bpf/trampoline.c >> @@ -525,6 +525,7 @@ static const struct bpf_link_ops bpf_shim_tramp_link_lops = { >> .dealloc = bpf_shim_tramp_link_dealloc, >> }; >> >> +#ifdef CONFIG_CGROUP_BPF >> static struct bpf_shim_tramp_link *cgroup_shim_alloc(const struct bpf_prog *prog, >> bpf_func_t bpf_func, >> int cgroup_atype) >> @@ -668,6 +669,7 @@ void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog) >> >> bpf_trampoline_put(tr); /* bpf_trampoline_lookup above */ >> } >> +#endif /* CONFIG_CGROUP_BPF */ >> #endif >> >> struct bpf_trampoline *bpf_trampoline_get(u64 key, >> -- >> 2.25.1 >> > .
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 2b21f2a3452f..add8895c02cc 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1255,9 +1255,7 @@ struct bpf_dummy_ops { int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, union bpf_attr __user *uattr); #endif -int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, - int cgroup_atype); -void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog); + #else static inline const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id) { @@ -1281,6 +1279,14 @@ static inline int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map, { return -EINVAL; } +#endif + +#if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL) && \ + defined(CONFIG_CGROUP_BPF) +int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, + int cgroup_atype); +void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog); +#else static inline int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, int cgroup_atype) { diff --git a/include/linux/bpf_lsm.h b/include/linux/bpf_lsm.h index 4bcf76a9bb06..bed45a0c8a9c 100644 --- a/include/linux/bpf_lsm.h +++ b/include/linux/bpf_lsm.h @@ -42,8 +42,6 @@ extern const struct bpf_func_proto bpf_inode_storage_get_proto; extern const struct bpf_func_proto bpf_inode_storage_delete_proto; void bpf_inode_storage_free(struct inode *inode); -void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); - #else /* !CONFIG_BPF_LSM */ static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id) @@ -67,11 +65,15 @@ static inline void bpf_inode_storage_free(struct inode *inode) { } +#endif /* CONFIG_BPF_LSM */ + +#if defined(CONFIG_BPF_LSM) && defined(CONFIG_BPF_CGROUP) +void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); +#else static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func) { } - -#endif /* CONFIG_BPF_LSM */ +#endif #endif /* _LINUX_BPF_LSM_H */ diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c index d469b7f3deef..29527828b38b 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -63,6 +63,7 @@ BTF_ID(func, bpf_lsm_socket_post_create) BTF_ID(func, bpf_lsm_socket_socketpair) BTF_SET_END(bpf_lsm_unlocked_sockopt_hooks) +#ifdef CONFIG_BPF_CGROUP void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func) { @@ -86,6 +87,7 @@ void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, #endif *bpf_func = __cgroup_bpf_run_lsm_current; } +#endif /* CONFIG_BPF_CGROUP */ int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, const struct bpf_prog *prog) diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 6cd226584c33..127924711935 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -525,6 +525,7 @@ static const struct bpf_link_ops bpf_shim_tramp_link_lops = { .dealloc = bpf_shim_tramp_link_dealloc, }; +#ifdef CONFIG_CGROUP_BPF static struct bpf_shim_tramp_link *cgroup_shim_alloc(const struct bpf_prog *prog, bpf_func_t bpf_func, int cgroup_atype) @@ -668,6 +669,7 @@ void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog) bpf_trampoline_put(tr); /* bpf_trampoline_lookup above */ } +#endif /* CONFIG_CGROUP_BPF */ #endif struct bpf_trampoline *bpf_trampoline_get(u64 key,
We failed to compile when CONFIG_BPF_LSM is enabled but CONFIG_CGROUP_BPF is not set. The failings are shown as below: kernel/bpf/trampoline.o: in function `bpf_trampoline_link_cgroup_shim' trampoline.c: undefined reference to `bpf_cgroup_atype_get' kernel/bpf/bpf_lsm.o: In function `bpf_lsm_find_cgroup_shim': bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_current' bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_sock' bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_socket' Fix them by protecting these functions with CONFIG_CGROUP_BPF. Fixes: 69fd337a975c ("bpf: per-cgroup lsm flavor") Signed-off-by: Xu Jia <xujia39@huawei.com> --- include/linux/bpf.h | 12 +++++++++--- include/linux/bpf_lsm.h | 10 ++++++---- kernel/bpf/bpf_lsm.c | 2 ++ kernel/bpf/trampoline.c | 2 ++ 4 files changed, 19 insertions(+), 7 deletions(-)