Skip to contentSkip to conversation

selftests/bpf: Fix bpf selftest build error

PATCH In review Saket Kumar Bhaskar 4 participants 6 messages May 9, 2025 – May 12, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: Fix bpf selftest build error

On linux-next, build for bpf selftest displays an error due to mismatch in the expected function signature of bpf_testmod_test_read and bpf_testmod_test_write.

Commit 97d06802d10a ("sysfs: constify bin_attribute argument of bin_attribute::read/write()") changed the required type for struct bin_attribute to const struct bin_attribute.

To resolve the error, update corresponding signature for the callback.

---
 tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +2 -2
index 2e54b95ad898..194c442580ee 100644
@@ -385,7 +385,7 @@ int bpf_testmod_fentry_ok;
 
 noinline ssize_t
 bpf_testmod_test_read(struct file *file, struct kobject *kobj,
-		      struct bin_attribute *bin_attr,
+		      const struct bin_attribute *bin_attr,
 		      char *buf, loff_t off, size_t len)
 {
 	struct bpf_testmod_test_read_ctx ctx = {
@@ -465,7 +465,7 @@ ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO);
 
 noinline ssize_t
 bpf_testmod_test_write(struct file *file, struct kobject *kobj,
-		      struct bin_attribute *bin_attr,
+		      const struct bin_attribute *bin_attr,
 		      char *buf, loff_t off, size_t len)
 {
 	struct bpf_testmod_test_write_ctx ctx = {
Signature · 1 line
2.43.5
#1 lore raw
Quoted 22 lines · Saket Kumar Bhaskar

On linux-next, build for bpf selftest displays an error due to mismatch in the expected function signature of bpf_testmod_test_read and bpf_testmod_test_write.

Commit 97d06802d10a ("sysfs: constify bin_attribute argument of bin_attribute::read/write()") changed the required type for struct bin_attribute to const struct bin_attribute.

To resolve the error, update corresponding signature for the callback.

---
 tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +0 -0
index 2e54b95ad898..194c442580ee 100644

tools/testing/selftests/bpf/test_kmods/bpf_testmod.c int bpf_testmod_fentry_ok; · line 389

Quoted 6 lines
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +1 -1
@@ -385,7 +385,7 @@ int bpf_testmod_fentry_ok;
 
 noinline ssize_t
 bpf_testmod_test_read(struct file *file, struct kobject *kobj,
-                     struct bin_attribute *bin_attr,
+                     const struct bin_attribute *bin_attr,
                      char *buf, loff_t off, size_t len)

You didn't even compile it :(

Instead of fixing the build, it breaks the build.

pw-bot: cr

#2 lore raw

Hi Alexei,

Quoted 33 lines · On Fri, 9 May 2025 10:04:18 -0700 Alexei Starovoitov…
Quoted 22 lines · Saket Kumar Bhaskar

On linux-next, build for bpf selftest displays an error due to mismatch in the expected function signature of bpf_testmod_test_read and bpf_testmod_test_write.

Commit 97d06802d10a ("sysfs: constify bin_attribute argument of bin_attribute::read/write()") changed the required type for struct bin_attribute to const struct bin_attribute.

To resolve the error, update corresponding signature for the callback.

---
 tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +0 -0
index 2e54b95ad898..194c442580ee 100644

tools/testing/selftests/bpf/test_kmods/bpf_testmod.c int bpf_testmod_fentry_ok; · line 389

Quoted 6 lines
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +1 -1
@@ -385,7 +385,7 @@ int bpf_testmod_fentry_ok;
 
 noinline ssize_t
 bpf_testmod_test_read(struct file *file, struct kobject *kobj,
-                     struct bin_attribute *bin_attr,
+                     const struct bin_attribute *bin_attr,
                      char *buf, loff_t off, size_t len)  

You didn't even compile it :(

Quoted 3 lines

Instead of fixing the build, it breaks the build.

pw-bot: cr

This patch is only needed in linux-next. It should be applied to the driver-core tree - since that includes commit 97d06802d10a. It should also have a Fixes tag referencing commit 97d06802d10a.

Signature · 2 lines
Cheers,
Stephen Rothwell
#3 lore raw
Quoted 36 lines · Stephen Rothwell

Hi Alexei,

Quoted 33 lines · On Fri, 9 May 2025 10:04:18 -0700 Alexei Starovoitov…
Quoted 22 lines · Saket Kumar Bhaskar

On linux-next, build for bpf selftest displays an error due to mismatch in the expected function signature of bpf_testmod_test_read and bpf_testmod_test_write.

Commit 97d06802d10a ("sysfs: constify bin_attribute argument of bin_attribute::read/write()") changed the required type for struct bin_attribute to const struct bin_attribute.

To resolve the error, update corresponding signature for the callback.

---
 tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +0 -0
index 2e54b95ad898..194c442580ee 100644

tools/testing/selftests/bpf/test_kmods/bpf_testmod.c int bpf_testmod_fentry_ok; · line 389

Quoted 6 lines
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +1 -1
@@ -385,7 +385,7 @@ int bpf_testmod_fentry_ok;
 
 noinline ssize_t
 bpf_testmod_test_read(struct file *file, struct kobject *kobj,
-                     struct bin_attribute *bin_attr,
+                     const struct bin_attribute *bin_attr,
                      char *buf, loff_t off, size_t len)  

You didn't even compile it :(

Quoted 10 lines
Quoted 3 lines

Instead of fixing the build, it breaks the build.

pw-bot: cr

This patch is only needed in linux-next. It should be applied to the driver-core tree - since that includes commit 97d06802d10a. It should also have a Fixes tag referencing commit 97d06802d10a.

Signature · 2 lines
Cheers,
Stephen Rothwell

Hi Stephen,

Apologies for missing the Fixes tag. Would you like me to resend the patch with the Fixes tag included?

Thanks,
Saket

#4 lore raw

Hi Saket,

Quoted 3 lines · On Mon, 12 May 2025 10:55:59 +0530 Saket Kumar Bhaskar <[email protected]>…

Apologies for missing the Fixes tag. Would you like me to resend the patch with the Fixes tag included?

Yes, please, but send it to Greg (keeping the ccs) so that he can apply it to the driver-core tree.

Signature · 2 lines
Cheers,
Stephen Rothwell
Tested-by on v1 1/1
#5 lore raw
In reply to Saket Kumar Bhaskar
Quoted 30 lines · Saket Kumar Bhaskar

On linux-next, build for bpf selftest displays an error due to mismatch in the expected function signature of bpf_testmod_test_read and bpf_testmod_test_write.

Commit 97d06802d10a ("sysfs: constify bin_attribute argument of bin_attribute::read/write()") changed the required type for struct bin_attribute to const struct bin_attribute.

To resolve the error, update corresponding signature for the callback.

---
  tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +1 -1
index 2e54b95ad898..194c442580ee 100644
@@ -385,7 +385,7 @@ int bpf_testmod_fentry_ok;
 
  noinline ssize_t
  bpf_testmod_test_read(struct file *file, struct kobject *kobj,
-		      struct bin_attribute *bin_attr,
+		      const struct bin_attribute *bin_attr,
  		      char *buf, loff_t off, size_t len)
  {
  	struct bpf_testmod_test_read_ctx ctx = {

tools/testing/selftests/bpf/test_kmods/bpf_testmod.c ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO); · line 471

Quoted 8 lines
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +1 -1
@@ -465,7 +465,7 @@ ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO);
 
  noinline ssize_t
  bpf_testmod_test_write(struct file *file, struct kobject *kobj,
-		      struct bin_attribute *bin_attr,
+		      const struct bin_attribute *bin_attr,
  		      char *buf, loff_t off, size_t len)
  {
  	struct bpf_testmod_test_write_ctx ctx = {

Tested this patch by applying on top of next-20250508 and if fixes the build issue. Hence,

commit f48887a98b78880b7711aca311fbbbcaad6c4e3b (tag: next-20250508, origin/master, origin/HEAD, bpf_arena)
Author: Stephen Rothwell <[email protected]>
Date:   Thu May 8 18:45:50 2025 +1000

    Add linux-next specific files for 20250508

After this patch:

  TEST-OBJ [test_progs-cpuv4] xdp_flowtable.test.o TEST-OBJ [test_progs-cpuv4] xdp_info.test.o TEST-OBJ [test_progs-cpuv4] xdp_link.test.o TEST-OBJ [test_progs-cpuv4] xdp_metadata.test.o TEST-OBJ [test_progs-cpuv4] xdp_noinline.test.o TEST-OBJ [test_progs-cpuv4] xdp_perf.test.o TEST-OBJ [test_progs-cpuv4] xdp_synproxy.test.o TEST-OBJ [test_progs-cpuv4] xdp_vlan.test.o TEST-OBJ [test_progs-cpuv4] xdpwall.test.o TEST-OBJ [test_progs-cpuv4] xfrm_info.test.o BINARY   bench
  BINARY   test_maps
  BINARY   test_progs
  BINARY   test_progs-no_alu32
  BINARY   test_progs-cpuv4

Before this patch:

  CLANG /root/linux-next/tools/testing/selftests/bpf/tools/build/bpftool/profiler.bpf.o
bpf_testmod.c:494:17: error: initialization of ‘ssize_t (*)(struct file *, struct kobject *, const struct bin_attribute *, char *, loff_t,  size_t)’ {aka ‘long int (*)(struct file *, struct kobject *, const struct bin_attribute *, char *, long long int,  long unsigned int)’} from incompatible pointer type ‘ssize_t (*)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t)’ {aka ‘long int (*)(struct file *, struct kobject *, struct bin_attribute *, char *, long long int,  long unsigned int)’} [-Wincompatible-pointer-types] 494 |         .read = bpf_testmod_test_read,
      |                 ^~~~~~~~~~~~~~~~~~~~~
bpf_testmod.c:494:17: note: (near initialization for ‘bin_attr_bpf_testmod_file.read’)
bpf_testmod.c:495:18: error: initialization of ‘ssize_t (*)(struct file *, struct kobject *, const struct bin_attribute *, char *, loff_t,  size_t)’ {aka ‘long int (*)(struct file *, struct kobject *, const struct bin_attribute *, char *, long long int,  long unsigned int)’} from incompatible pointer type ‘ssize_t (*)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t)’ {aka ‘long int (*)(struct file *, struct kobject *, struct bin_attribute *, char *, long long int,  long unsigned int)’} [-Wincompatible-pointer-types] 495 |         .write = bpf_testmod_test_write,
      |                  ^~~~~~~~~~~~~~~~~~~~~~
bpf_testmod.c:495:18: note: (near initialization for ‘bin_attr_bpf_testmod_file.write’)
make[4]: *** [/root/linux-next/scripts/Makefile.build:203: bpf_testmod.o] Error 1
make[3]: *** [/root/linux-next/Makefile:2009: .] Error 2
make[2]: *** [Makefile:248: __sub-make] Error 2
make[1]: *** [Makefile:18: all] Error 2
make: *** [Makefile:282: test_kmods/bpf_testmod.ko] Error 2

Regards,

Venkat.