Skip to contentSkip to conversation

selftests: riscv: Fix compilation issues for v_ptrace and cfi

PATCH Superseded Charlie Jenkins 3 participants 8 messages Mar 5 – Mar 10

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover selftests: riscv: Fix compilation issues for v_ptrace and cfi

There are a couple of compilation issues of the riscv selftests. Coincidentally two of the issues are independent problems with not including the header that includes the BIT() macro and the other issue is from checkpatch incorrectly suggesting to remove non-redundant braces.

---
Charlie Jenkins (4):
selftests: riscv: Add definition of BIT() macro
selftests: riscv: Add braces around EXPECT_EQ()
riscv: ptrace: Fix BIT() compilation issues
selftests: riscv: Add license to cfi selftest

 arch/riscv/include/uapi/asm/ptrace.h                     |  1 +
 tools/testing/selftests/riscv/cfi/Makefile               |  2 ++
 tools/testing/selftests/riscv/vector/Makefile            |  2 ++
 tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 16 ++++++++++------
 4 files changed, 15 insertions(+), 6 deletions(-)

---
base-commit: c107785c7e8dbabd1c18301a1c362544b5786282
change-id: 20260304-fix_selftests-c3f0ae46b3c7

Best regards,

Signature · 1 line
Charlie Jenkins <[email protected]>
#1 lore raw

PATCH 1/4 selftests: riscv: Add definition of BIT() macro

The BIT() macros is used by the validate_v_ptrace() test case, but not defined. Include linux/bits.h to pull in this definition. To ensure that the header in the kernel source is used, add tools/include to the header search path.

Fixes 30eb191c895b ("selftests: riscv: verify ptrace rejects invalid vector csr inputs")
---
 tools/testing/selftests/riscv/vector/Makefile            | 2 ++
 tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 1 +
 2 files changed, 3 insertions(+)
tools/testing/selftests/riscv/vector/Makefile +2 -0
index 326dafd739bf..92c4cfe5f34d 100644
@@ -2,6 +2,8 @@
 # Copyright (C) 2021 ARM Limited
 # Originally tools/testing/arm64/abi/Makefile
 
+CFLAGS += -I$(top_srcdir)/tools/include
+
 TEST_GEN_PROGS := v_initval vstate_prctl vstate_ptrace validate_v_ptrace
 TEST_GEN_PROGS_EXTENDED := vstate_exec_nolibc v_exec_initval_nolibc
 TEST_GEN_LIBS := v_helpers.c sys_hwprobe.c
tools/testing/selftests/riscv/vector/validate_v_ptrace.c +1 -0
index 3589549f7228..257de36274e9 100644
@@ -6,6 +6,7 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include <linux/bits.h>
 #include <linux/ptrace.h>
 #include <linux/elf.h>
 
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH 1/4] selftests: riscv: Add definition of BIT() macro

kernel test robot noticed the following build errors:

Hi Charlie,

kernel test robot noticed the following build errors:

[auto build test ERROR on c107785c7e8dbabd1c18301a1c362544b5786282]

url:    https://github.com/intel-lab-lkp/linux/commits/Charlie-Jenkins-via-B4-Relay/selftests-riscv-Add-definition-of-BIT-macro/20260305-164838
base:   c107785c7e8dbabd1c18301a1c362544b5786282
patch link:    https://lore.kernel.org/r/20260305-fix_selftests-v1-1-61b62d23500b%40gmail.com
patch subject: [PATCH 1/4] selftests: riscv: Add definition of BIT() macro
config: riscv-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260305/[email protected]/config)
compiler: riscv64-linux-gnu-gcc (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260305/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from /usr/riscv64-linux-gnu/include/stdint.h:34,

                    from /usr/lib/gcc-cross/riscv64-linux-gnu/14/include/stdint.h:9,
                    from tools/testing/selftests/../../../tools/include/linux/types.h:7,
                    from ./../../../../include/nolibc/std.h:19,
                    from ./../../../../include/nolibc/nolibc.h:95,
                    from <command-line>:
>> /usr/riscv64-linux-gnu/include/bits/stdint-intn.h:27:19: error: conflicting types for 'int64_t'; have '__int64_t' {aka 'long int'}
      27 | typedef __int64_t int64_t;
         |                   ^~~~~~~
   In file included from ./../../../../include/nolibc/std.h:16:
   ./../../../../include/nolibc/stdint.h:17:29: note: previous declaration of 'int64_t' with type 'int64_t' {aka 'long long int'}
      17 | typedef   signed long long  int64_t;
         |                             ^~~~~~~
   In file included from /usr/riscv64-linux-gnu/include/stdint.h:37:
>> /usr/riscv64-linux-gnu/include/bits/stdint-uintn.h:27:20: error: conflicting types for 'uint64_t'; have '__uint64_t' {aka 'long unsigned int'}
      27 | typedef __uint64_t uint64_t;
         |                    ^~~~~~~~
   ./../../../../include/nolibc/stdint.h:16:28: note: previous declaration of 'uint64_t' with type 'uint64_t' {aka 'long long unsigned int'}
      16 | typedef unsigned long long uint64_t;
         |                            ^~~~~~~~
   In file included from /usr/riscv64-linux-gnu/include/stdint.h:41:
>> /usr/riscv64-linux-gnu/include/bits/stdint-least.h:28:25: error: conflicting types for 'int_least64_t'; have '__int_least64_t' {aka 'long int'}
      28 | typedef __int_least64_t int_least64_t;
         |                         ^~~~~~~~~~~~~
   ./../../../../include/nolibc/stdint.h:30:23: note: previous declaration of 'int_least64_t' with type 'int_least64_t' {aka 'long long int'}
      30 | typedef  int64_t      int_least64_t;
         |                       ^~~~~~~~~~~~~
>> /usr/riscv64-linux-gnu/include/bits/stdint-least.h:34:26: error: conflicting types for 'uint_least64_t'; have '__uint_least64_t' {aka 'long unsigned int'}
      34 | typedef __uint_least64_t uint_least64_t;
         |                          ^~~~~~~~~~~~~~
   ./../../../../include/nolibc/stdint.h:31:22: note: previous declaration of 'uint_least64_t' with type 'uint_least64_t' {aka 'long long unsigned int'}
      31 | typedef uint64_t     uint_least64_t;
         |                      ^~~~~~~~~~~~~~
>> /usr/riscv64-linux-gnu/include/stdint.h:51:33: error: conflicting types for 'int_fast64_t'; have 'long int'
      51 | typedef long int                int_fast64_t;
         |                                 ^~~~~~~~~~~~
   ./../../../../include/nolibc/stdint.h:39:24: note: previous declaration of 'int_fast64_t' with type 'int_fast64_t' {aka 'long long int'}
      39 | typedef  int64_t       int_fast64_t;
         |                        ^~~~~~~~~~~~
>> /usr/riscv64-linux-gnu/include/stdint.h:64:33: error: conflicting types for 'uint_fast64_t'; have 'long unsigned int'
      64 | typedef unsigned long int       uint_fast64_t;
         |                                 ^~~~~~~~~~~~~
   ./../../../../include/nolibc/stdint.h:40:23: note: previous declaration of 'uint_fast64_t' with type 'uint_fast64_t' {aka 'long long unsigned int'}
      40 | typedef uint64_t      uint_fast64_t;
         |                       ^~~~~~~~~~~~~
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

PATCH 2/4 selftests: riscv: Add braces around EXPECT_EQ()

In reply to Charlie Jenkins

EXPECT_EQ() expands to multiple lines, breaking up one-line if statements. This issue was not present in the patch on the mailing list but was instead introduced by the maintainer when attempting to fix up checkpatch warnings. Add braces around EXPECT_EQ() to avoid the error even though checkpatch suggests them to be removed:

validate_v_ptrace.c:626:17: error: ‘else’ without a previous ‘if’

Fixes 3789d5eecd5a ("selftests: riscv: verify syscalls discard vector context")
Fixes 30eb191c895b ("selftests: riscv: verify ptrace rejects invalid vector csr inputs")
Fixes 849f05ae1ea6 ("selftests: riscv: verify ptrace accepts valid vector csr values")
---
 tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
tools/testing/selftests/riscv/vector/validate_v_ptrace.c +9 -6
index 257de36274e9..5724e6eb3309 100644
@@ -291,10 +291,11 @@ TEST(ptrace_v_syscall_clobbering)
 
 		/* verify initial vsetvli settings */
 
-		if (is_xtheadvector_supported())
+		if (is_xtheadvector_supported()) {
 			EXPECT_EQ(5UL, regset_data->vtype);
-		else
+		} else {
 			EXPECT_EQ(9UL, regset_data->vtype);
+		}
 
 		EXPECT_EQ(regset_data->vlenb, regset_data->vl);
 		EXPECT_EQ(vlenb, regset_data->vlenb);
@@ -620,10 +621,11 @@ TEST_F(v_csr_invalid, ptrace_v_invalid_values)
 
 		/* verify initial vsetvli settings */
 
-		if (is_xtheadvector_supported())
+		if (is_xtheadvector_supported()) {
 			EXPECT_EQ(5UL, regset_data->vtype);
-		else
+		} else {
 			EXPECT_EQ(9UL, regset_data->vtype);
+		}
 
 		EXPECT_EQ(regset_data->vlenb, regset_data->vl);
 		EXPECT_EQ(vlenb, regset_data->vlenb);
@@ -828,10 +830,11 @@ TEST_F(v_csr_valid, ptrace_v_valid_values)
 
 		/* verify initial vsetvli settings */
 
-		if (is_xtheadvector_supported())
+		if (is_xtheadvector_supported()) {
 			EXPECT_EQ(5UL, regset_data->vtype);
-		else
+		} else {
 			EXPECT_EQ(9UL, regset_data->vtype);
+		}
 
 		EXPECT_EQ(regset_data->vlenb, regset_data->vl);
 		EXPECT_EQ(vlenb, regset_data->vlenb);
Signature · 1 line
2.52.0
#4 lore raw

PATCH 3/4 riscv: ptrace: Fix BIT() compilation issues

In reply to Charlie Jenkins

BIT() is being used in ptrace.h without a definition, resulting in compilation errors in tools/testing/selftests/riscv/cfi/cfitests.c:

cfitests.c:101:60: error: implicit declaration of function ‘BIT’ [-Wimplicit-function-declaration]
101 | if ((cfi_reg.cfi_status.cfi_state & CFI_ENABLE_MASK) != CFI_ENABLE_MASK)

Include linux/bits.h to resolve this issue.

Fixes 2af7c9cf021c ("riscv/ptrace: expose riscv CFI status and state via ptrace and in core files")
---
 arch/riscv/include/uapi/asm/ptrace.h | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/include/uapi/asm/ptrace.h +1 -0
index 18988a5f1a63..5b53cea14355 100644
@@ -8,6 +8,7 @@
 
 #ifndef __ASSEMBLER__
 
+#include <linux/bits.h>
 #include <linux/types.h>
 
 #define PTRACE_GETFDPIC		33
Signature · 1 line
2.52.0
#5 lore raw

PATCH 4/4 selftests: riscv: Add license to cfi selftest

In reply to Charlie Jenkins

The cfi selftest was missing a license so add it.

---
 tools/testing/selftests/riscv/cfi/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/riscv/cfi/Makefile +2 -0
index 96a4dc4b69c3..93b4738c0e2e 100644
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
 CFLAGS += $(KHDR_INCLUDES)
 CFLAGS += -I$(top_srcdir)/tools/include
 
Signature · 1 line
2.52.0
#6 lore raw
In reply to Charlie Jenkins

Hello Charlie,

Quoted 19 lines · On Thu, Mar 05, 2026 at 12:11:28AM -0800, Charlie Jenkins via B4 Relay wrote:

There are a couple of compilation issues of the riscv selftests. Coincidentally two of the issues are independent problems with not including the header that includes the BIT() macro and the other issue is from checkpatch incorrectly suggesting to remove non-redundant braces.

---
Charlie Jenkins (4):
selftests: riscv: Add definition of BIT() macro
selftests: riscv: Add braces around EXPECT_EQ()
riscv: ptrace: Fix BIT() compilation issues
selftests: riscv: Add license to cfi selftest

 arch/riscv/include/uapi/asm/ptrace.h                     |  1 +
 tools/testing/selftests/riscv/cfi/Makefile               |  2 ++
 tools/testing/selftests/riscv/vector/Makefile            |  2 ++
 tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 16 ++++++++++------
 4 files changed, 15 insertions(+), 6 deletions(-)
Quoted 7 lines

---
base-commit: c107785c7e8dbabd1c18301a1c362544b5786282
change-id: 20260304-fix_selftests-c3f0ae46b3c7

Best regards,

Signature · 1 line
Charlie Jenkins <[email protected]>

Thanks for catching this !

On rc3 I can also reproduce the issue reported by the kernel test robot for v_exec_initval_nolibc.c and vstate_exec_nolibc.c. The following addition to your fixes seems to resolve it:

tools/testing/selftests/riscv/vector/Makefile +2 -4
index 92c4cfe5f34d..48d6cd5e72f6 100644
@@ -22,15 +22,13 @@ $(OUTPUT)/vstate_prctl: vstate_prctl.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpe
 	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
 
 $(OUTPUT)/vstate_exec_nolibc: vstate_exec_nolibc.c
-	$(CC) -nostdlib -static -include ../../../../include/nolibc/nolibc.h \
-		-Wall $(CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc
+	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
 
 $(OUTPUT)/v_initval: v_initval.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpers.o
 	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
 
 $(OUTPUT)/v_exec_initval_nolibc: v_exec_initval_nolibc.c
-	$(CC) -nostdlib -static -include ../../../../include/nolibc/nolibc.h \
-		-Wall $(CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc
+	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
 
 $(OUTPUT)/vstate_ptrace: vstate_ptrace.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpers.o
 	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
tools/testing/selftests/riscv/vector/v_exec_initval_nolibc.c +4 -0
index 4dde05e45a04..e3f062c85452 100644
@@ -9,6 +9,10 @@
  * To be "clean" all values must be all zeroes.
  */
 
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
 #define __stringify_1(x...)	#x
 #define __stringify(x...)	__stringify_1(x)
 
tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c +7 -1
index 12f1b1b1c7aa..ecd687bb8359 100644
@@ -1,6 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
-#include <linux/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <sys/prctl.h>
+#include <sys/wait.h>
 
 #define THIS_PROGRAM "./vstate_exec_nolibc"
 

Regards,
Sergey

#7 lore raw
Quoted 30 lines · Sergey Matyukevich

Hello Charlie,

Quoted 19 lines · On Thu, Mar 05, 2026 at 12:11:28AM -0800, Charlie Jenkins via B4 Relay wrote:

There are a couple of compilation issues of the riscv selftests. Coincidentally two of the issues are independent problems with not including the header that includes the BIT() macro and the other issue is from checkpatch incorrectly suggesting to remove non-redundant braces.

---
Charlie Jenkins (4):
selftests: riscv: Add definition of BIT() macro
selftests: riscv: Add braces around EXPECT_EQ()
riscv: ptrace: Fix BIT() compilation issues
selftests: riscv: Add license to cfi selftest

 arch/riscv/include/uapi/asm/ptrace.h                     |  1 +
 tools/testing/selftests/riscv/cfi/Makefile               |  2 ++
 tools/testing/selftests/riscv/vector/Makefile            |  2 ++
 tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 16 ++++++++++------
 4 files changed, 15 insertions(+), 6 deletions(-)
Quoted 7 lines

---
base-commit: c107785c7e8dbabd1c18301a1c362544b5786282
change-id: 20260304-fix_selftests-c3f0ae46b3c7

Best regards,

Signature · 1 line
Charlie Jenkins <[email protected]>
Quoted 5 lines

Thanks for catching this !

On rc3 I can also reproduce the issue reported by the kernel test robot for v_exec_initval_nolibc.c and vstate_exec_nolibc.c. The following addition to your fixes seems to resolve it:

I missed that locally since those file compilations were cached for me!

I think we want to keep those as nolibc so instead we can only add the header to the CFLAGS for only the tests that want libc, I'll send out an updated version.

- Charlie

Quoted 59 lines
tools/testing/selftests/riscv/vector/Makefile +2 -4
index 92c4cfe5f34d..48d6cd5e72f6 100644
@@ -22,15 +22,13 @@ $(OUTPUT)/vstate_prctl: vstate_prctl.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpe
 	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
 
 $(OUTPUT)/vstate_exec_nolibc: vstate_exec_nolibc.c
-	$(CC) -nostdlib -static -include ../../../../include/nolibc/nolibc.h \
-		-Wall $(CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc
+	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
 
 $(OUTPUT)/v_initval: v_initval.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpers.o
 	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
 
 $(OUTPUT)/v_exec_initval_nolibc: v_exec_initval_nolibc.c
-	$(CC) -nostdlib -static -include ../../../../include/nolibc/nolibc.h \
-		-Wall $(CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc
+	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
 
 $(OUTPUT)/vstate_ptrace: vstate_ptrace.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpers.o
 	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
tools/testing/selftests/riscv/vector/v_exec_initval_nolibc.c +4 -0
index 4dde05e45a04..e3f062c85452 100644
@@ -9,6 +9,10 @@
  * To be "clean" all values must be all zeroes.
  */
 
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
 #define __stringify_1(x...)	#x
 #define __stringify(x...)	__stringify_1(x)
 
tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c +7 -1
index 12f1b1b1c7aa..ecd687bb8359 100644
@@ -1,6 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
-#include <linux/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <sys/prctl.h>
+#include <sys/wait.h>
 
 #define THIS_PROGRAM "./vstate_exec_nolibc"
 

Regards,
Sergey