Skip to content

Comments

RISC-V: Define struct hid_bpf_ctx to fix kselftest hid-bpf compilation#124

Merged
sterling-teng merged 3 commits intoRVCK-Project:rvck-6.6from
woqidaideshi:rvck-6.6-kselftest
Sep 7, 2025
Merged

RISC-V: Define struct hid_bpf_ctx to fix kselftest hid-bpf compilation#124
sterling-teng merged 3 commits intoRVCK-Project:rvck-6.6from
woqidaideshi:rvck-6.6-kselftest

Conversation

@woqidaideshi
Copy link
Contributor

@woqidaideshi woqidaideshi commented Sep 4, 2025

Related issue: #123.
The following error occurred when building the tests for kselftest.

$ make headers
$ make -C tools/testing/selftests
...
gcc -O2 -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wstrict-prototypes -Wswitch-default -Wundef -Wwrite-strings -Wformat -Wno-type-limits -Wstrict-aliasing=3 -Wshadow -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ -I/disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/ -I/disk/workspaces/rvck/tools/testing/selftests/hid/tools/include -I/disk/workspaces/rvck/kernel/bpf/ -I/disk/workspaces/rvck/tools/include -I/disk/workspaces/rvck/tools/include/uapi -g -O0 -DUSE_LIBCAP   /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/btf.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/btf_dumper.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/cfg.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/cgroup.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/common.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/feature.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/gen.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/iter.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/json_writer.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/link.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/main.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/map.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/map_perf_ring.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/net.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/netlink_dumper.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/perf.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/pids.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/prog.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/struct_ops.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/tracelog.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/xlated_dumper.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/disasm.o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/libbpf/libbpf.a -lelf -lz -lcap -o /disk/workspaces/rvck/tools/testing/selftests/hid/tools/build/bpftool/bpftool
  GEN      vmlinux.h
  CLNG-BPF hid.bpf.o
In file included from progs/hid.c:6:
progs/hid_bpf_helpers.h:9:38: error: declaration of 'struct hid_bpf_ctx' will not be visible outside of this function [-Werror,-Wvisibility]
    9 | extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
      |                                      ^
progs/hid.c:23:35: error: incompatible pointer types passing 'struct hid_bpf_ctx *' to parameter of type 'struct hid_bpf_ctx *' [-Werror,-Wincompatible-pointer-types]
   23 |         __u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 3 /* size */);
      |                                          ^~~~~~~
progs/hid_bpf_helpers.h:9:51: note: passing argument to parameter 'ctx' here
    9 | extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
      |                                                   ^
progs/hid.c:32:16: error: incomplete definition of type 'struct hid_bpf_ctx'
   32 |         return hid_ctx->size;
      |                ~~~~~~~^
progs/hid_bpf_helpers.h:13:15: note: forward declaration of 'struct hid_bpf_ctx'
   13 | extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __ksym;
      |               ^
progs/hid.c:38:35: error: incompatible pointer types passing 'struct hid_bpf_ctx *' to parameter of type 'struct hid_bpf_ctx *' [-Werror,-Wincompatible-pointer-types]
   38 |         __u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 4 /* size */);
      |                                          ^~~~~~~
progs/hid_bpf_helpers.h:9:51: note: passing argument to parameter 'ctx' here
    9 | extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
      |                                                   ^
progs/hid.c:45:16: error: incomplete definition of type 'struct hid_bpf_ctx'
   45 |         return hid_ctx->size;
      |                ~~~~~~~^
progs/hid_bpf_helpers.h:13:15: note: forward declaration of 'struct hid_bpf_ctx'
   13 | extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __ksym;
      |               ^
progs/hid.c:51:35: error: incompatible pointer types passing 'struct hid_bpf_ctx *' to parameter of type 'struct hid_bpf_ctx *' [-Werror,-Wincompatible-pointer-types]
   51 |         __u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 3 /* size */);
      |                                          ^~~~~~~
progs/hid_bpf_helpers.h:9:51: note: passing argument to parameter 'ctx' here
    9 | extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
      |                                                   ^
progs/hid.c:66:27: error: use of undeclared identifier 'HID_BPF_FLAG_INSERT_HEAD'
   66 |                                           ctx->insert_head ? HID_BPF_FLAG_INSERT_HEAD :
      |                                                              ^
progs/hid.c:67:13: error: use of undeclared identifier 'HID_BPF_FLAG_NONE'
   67 |                                                              HID_BPF_FLAG_NONE);
      |                                                              ^
progs/hid.c:144:32: error: incompatible pointer types passing 'struct hid_bpf_ctx *' to parameter of type 'struct hid_bpf_ctx *' [-Werror,-Wincompatible-pointer-types]
  144 |         __u8 *data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 4096 /* size */);
      |                                       ^~~~~~~
progs/hid_bpf_helpers.h:9:51: note: passing argument to parameter 'ctx' here
    9 | extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
      |                                                   ^
progs/hid.c:163:32: error: incompatible pointer types passing 'struct hid_bpf_ctx *' to parameter of type 'struct hid_bpf_ctx *' [-Werror,-Wincompatible-pointer-types]
  163 |         __u8 *data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 4 /* size */);
      |                                       ^~~~~~~
progs/hid_bpf_helpers.h:9:51: note: passing argument to parameter 'ctx' here
    9 | extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
      |                                                   ^
progs/hid.c:180:32: error: incompatible pointer types passing 'struct hid_bpf_ctx *' to parameter of type 'struct hid_bpf_ctx *' [-Werror,-Wincompatible-pointer-types]
  180 |         __u8 *data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 4 /* size */);
      |                                       ^~~~~~~
progs/hid_bpf_helpers.h:9:51: note: passing argument to parameter 'ctx' here
    9 | extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
      |                                                   ^
progs/hid.c:197:32: error: incompatible pointer types passing 'struct hid_bpf_ctx *' to parameter of type 'struct hid_bpf_ctx *' [-Werror,-Wincompatible-pointer-types]
  197 |         __u8 *data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 4 /* size */);
      |                                       ^~~~~~~
progs/hid_bpf_helpers.h:9:51: note: passing argument to parameter 'ctx' here
    9 | extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
      |                                                   ^
12 errors generated.
make[1]: *** [Makefile:230: /disk/workspaces/rvck/tools/testing/selftests/hid/hid.bpf.o] Error 1
make[1]: Leaving directory '/disk/workspaces/rvck/tools/testing/selftests/hid'
...

Link: https://lore.kernel.org/all/20230825-wip-selftests-v3-1-639963c54109@kernel.org/

Benjamin Tissoires added 3 commits September 4, 2025 15:48
stable inclusion
from stable-v6.12.1
commit ae7487d
category: bugfix
bugzilla: RVCK-Project#123

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=ae7487d112cf9f310d32f27d5956f53d9f143fea

--------------------------------

For the hid-bpf tests to compile, we need to have the definition of
struct hid_bpf_ctx. This definition is an internal one from the kernel
and it is supposed to be defined in the generated vmlinux.h.

This vmlinux.h header is generated based on the currently running kernel
or if the kernel was already compiled in the tree. If you just compile
the selftests without compiling the kernel beforehand and you are running
on a 6.2 kernel, you'll end up with a vmlinux.h without the hid_bpf_ctx
definition.

Use the clever trick from tools/testing/selftests/bpf/progs/bpf_iter.h
to force the definition of that symbol in case we don't find it in the
BTF and also add __attribute__((preserve_access_index)) to further
support CO-RE functionality for these tests.

Signed-off-by: Justin Stitt <justinstitt@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com> # Build
Tested-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20230825-wip-selftests-v3-1-639963c54109@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Signed-off-by: Yafen Fang <yafen@iscas.ac.cn>
stable inclusion
from stable-v6.12.1
commit 89d024a
category: bugfix
bugzilla: RVCK-Project#123

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=89d024a7ba02b6b969f89ac057442b5d3bcb4272

--------------------------------

"make headers" is a requirement before calling make on the selftests
dir, so we should not have to manually install those headers

Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Tested-by: Nick Desaulniers <ndesaulniers@google.com> # Build
Tested-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20230825-wip-selftests-v3-2-639963c54109@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Signed-off-by: Yafen Fang <yafen@iscas.ac.cn>
stable inclusion
from stable-v6.12.1
commit 9193963
category: bugfix
bugzilla: RVCK-Project#123

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=91939636cac4585e5c99a15c8b9023e0dcabb4e5

--------------------------------

Turns out that we were relying on the globally installed headers, not
the ones we freshly compiled.
Add a manual include in CFLAGS to sort this out.

Tested-by: Nick Desaulniers <ndesaulniers@google.com> # Build
Tested-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20230825-wip-selftests-v3-3-639963c54109@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Signed-off-by: Yafen Fang <yafen@iscas.ac.cn>
@oervci
Copy link

oervci commented Sep 4, 2025

开始测试

@oervci
Copy link

oervci commented Sep 4, 2025

开始测试

@oervci
Copy link

oervci commented Sep 4, 2025

@oervci
Copy link

oervci commented Sep 4, 2025

Kernel build success!

@oervci
Copy link

oervci commented Sep 4, 2025

@oervci
Copy link

oervci commented Sep 4, 2025

Kernel build success!

@oervci
Copy link

oervci commented Sep 4, 2025

@oervci
Copy link

oervci commented Sep 4, 2025

Lava check done! result url: https://lava.oerv.ac.cn/results/648/0_rvck_common-test_qemu

@sterling-teng
Copy link
Contributor

该pr系CI修复相关,不会对其它pr造成合并冲突,紧急合并。

@sterling-teng sterling-teng merged commit 70480ef into RVCK-Project:rvck-6.6 Sep 7, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants