Re: [PATCH bpf-next v2 1/2] bpf: Have bpf_rdonly_cast() take a const pointer

From: Jiri Olsa
Date: Tue Feb 06 2024 - 08:44:53 EST


On Sun, Feb 04, 2024 at 02:06:34PM -0700, Daniel Xu wrote:
> Since 20d59ee55172 ("libbpf: add bpf_core_cast() macro"), libbpf is now
> exporting a const arg version of bpf_rdonly_cast(). This causes the
> following conflicting type error when generating kfunc prototypes from
> BTF:
>
> In file included from skeleton/pid_iter.bpf.c:5:
> /home/dxu/dev/linux/tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_core_read.h:297:14: error: conflicting types for 'bpf_rdonly_cast'
> extern void *bpf_rdonly_cast(const void *obj__ign, __u32 btf_id__k) __ksym __weak;
> ^
> ./vmlinux.h:135625:14: note: previous declaration is here
> extern void *bpf_rdonly_cast(void *obj__ign, u32 btf_id__k) __weak __ksym;

hi,
I'm hiting more of these when compiling bpf selftests (attached),
it looks like some kfuncs declarations in bpf_kfuncs.h might be in conflict

jirka


---
CLNG-BPF [test_maps] connect_unix_prog.bpf.o
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:11:12: error: conflicting types for 'bpf_dynptr_from_skb'
extern int bpf_dynptr_from_skb(struct __sk_buff *skb, __u64 flags,
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164853:12: note: previous declaration is here
extern int bpf_dynptr_from_skb(struct sk_buff *skb, u64 flags, struct bpf_dynptr_kern *ptr__uninit) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:19:12: error: conflicting types for 'bpf_dynptr_from_xdp'
extern int bpf_dynptr_from_xdp(struct xdp_md *xdp, __u64 flags,
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164855:12: note: previous declaration is here
extern int bpf_dynptr_from_xdp(struct xdp_buff *xdp, u64 flags, struct bpf_dynptr_kern *ptr__uninit) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:28:14: error: conflicting types for 'bpf_dynptr_slice'
extern void *bpf_dynptr_slice(const struct bpf_dynptr *ptr, __u32 offset,
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164747:14: note: previous declaration is here
extern void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset, void *buffer__opt, u32 buffer__szk) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:37:14: error: conflicting types for 'bpf_dynptr_slice_rdwr'
extern void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr *ptr, __u32 offset,
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164749:14: note: previous declaration is here
extern void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr_kern *ptr, u32 offset, void *buffer__opt, u32 buffer__szk) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:40:12: error: conflicting types for 'bpf_dynptr_adjust'
extern int bpf_dynptr_adjust(const struct bpf_dynptr *ptr, __u32 start, __u32 end) __ksym __weak;
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164781:12: note: previous declaration is here
extern int bpf_dynptr_adjust(struct bpf_dynptr_kern *ptr, u32 start, u32 end) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:41:13: error: conflicting types for 'bpf_dynptr_is_null'
extern bool bpf_dynptr_is_null(const struct bpf_dynptr *ptr) __ksym __weak;
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164783:13: note: previous declaration is here
extern bool bpf_dynptr_is_null(struct bpf_dynptr_kern *ptr) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:42:13: error: conflicting types for 'bpf_dynptr_is_rdonly'
extern bool bpf_dynptr_is_rdonly(const struct bpf_dynptr *ptr) __ksym __weak;
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164785:13: note: previous declaration is here
extern bool bpf_dynptr_is_rdonly(struct bpf_dynptr_kern *ptr) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:43:14: error: conflicting types for 'bpf_dynptr_size'
extern __u32 bpf_dynptr_size(const struct bpf_dynptr *ptr) __ksym __weak;
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164787:14: note: previous declaration is here
extern __u32 bpf_dynptr_size(const struct bpf_dynptr_kern *ptr) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:44:12: error: conflicting types for 'bpf_dynptr_clone'
extern int bpf_dynptr_clone(const struct bpf_dynptr *ptr, struct bpf_dynptr *clone__init) __ksym __weak;
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164789:12: note: previous declaration is here
extern int bpf_dynptr_clone(struct bpf_dynptr_kern *ptr, struct bpf_dynptr_kern *clone__uninit) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:61:12: error: conflicting types for 'bpf_sk_assign_tcp_reqsk'
extern int bpf_sk_assign_tcp_reqsk(struct __sk_buff *skb, struct sock *sk,
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164859:12: note: previous declaration is here
extern int bpf_sk_assign_tcp_reqsk(struct sk_buff *skb, struct sock *sk, struct bpf_tcp_req_attrs *attrs, int attrs__sz) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:68:12: error: conflicting types for 'bpf_get_file_xattr'
extern int bpf_get_file_xattr(struct file *file, const char *name,
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164691:12: note: previous declaration is here
extern int bpf_get_file_xattr(struct file *file, const char *name__str, struct bpf_dynptr_kern *value_ptr) __weak __ksym;
^
In file included from progs/connect_unix_prog.c:9:
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/bpf_kfuncs.h:75:12: error: conflicting types for 'bpf_verify_pkcs7_signature'
extern int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_ptr,
^
/home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/tools/include/vmlinux.h:164689:12: note: previous declaration is here
extern int bpf_verify_pkcs7_signature(struct bpf_dynptr_kern *data_ptr, struct bpf_dynptr_kern *sig_ptr, struct bpf_key *trusted_keyring) __weak __ksym;
^
12 errors generated.
make: *** [Makefile:642: /home/jolsa/kernel/linux-qemu/tools/testing/selftests/bpf/connect_unix_prog.bpf.o] Error 1