selftests: riscv: Fix compilation issues for v_ptrace and cfi
v2 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.
---
Changes in v2:
- Fix compilation issue reported by kernel test bot and Sergey
- Link to v1: https://lore.kernel.org/r/[email protected]
---
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 | 7 +++++-- tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 16 ++++++++++------ 4 files changed, 18 insertions(+), 8 deletions(-)
---
base-commit: c107785c7e8dbabd1c18301a1c362544b5786282
change-id: ${change-id}
- Charlie
PATCH v2 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.
--- tools/testing/selftests/riscv/vector/Makefile | 7 +++++-- tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/riscv/vector/Makefile +5 -2
@@ -2,6 +2,9 @@ # Copyright (C) 2021 ARM Limited # Originally tools/testing/arm64/abi/Makefile +NO_LIBC_CFLAGS := $(CFLAGS) +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
@@ -21,14 +24,14 @@ $(OUTPUT)/vstate_prctl: vstate_prctl.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpe $(OUTPUT)/vstate_exec_nolibc: vstate_exec_nolibc.c $(CC) -nostdlib -static -include ../../../../include/nolibc/nolibc.h \ - -Wall $(CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc + -Wall $(NO_LIBC_CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc $(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 + -Wall $(NO_LIBC_CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc $(OUTPUT)/vstate_ptrace: vstate_ptrace.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpers.o $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
tools/testing/selftests/riscv/vector/validate_v_ptrace.c +1 -0
@@ -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
Re: [PATCH v2 1/4] selftests: riscv: Add definition of BIT() macro
Quoted 7 lines · On Mon, Mar 09, 2026 at 06:52:10PM -0700, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
The
BIT()macros is used by thevalidate_v_ptrace()test case, but not defined. Includelinux/bits.hto pull in this definition. To ensure that the header in the kernel source is used, addtools/includeto the header search path.
Quoted 6 lines
Fixes 30eb191c895b ("selftests: riscv: verify ptrace rejects invalid vector csr inputs")Signed-off-by Charlie Jenkins <[email protected]>--- tools/testing/selftests/riscv/vector/Makefile | 7 +++++-- tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)
Thanks,
Sergey
Paul Walmsley
maintainerRe: [PATCH v2 1/4] selftests: riscv: Add definition of BIT() macro
Quoted 8 lines · Sergey Matyukevich
Quoted 7 lines · On Mon, Mar 09, 2026 at 06:52:10PM -0700, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
The
BIT()macros is used by thevalidate_v_ptrace()test case, but not defined. Includelinux/bits.hto pull in this definition. To ensure that the header in the kernel source is used, addtools/includeto the header search path.
Quoted 8 lines
Quoted 6 lines
Fixes 30eb191c895b ("selftests: riscv: verify ptrace rejects invalid vector csr inputs")Signed-off-by Charlie Jenkins <[email protected]>--- tools/testing/selftests/riscv/vector/Makefile | 7 +++++-- tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)Reviewed-and-Tested-by Sergey Matyukevich <[email protected]>
Thanks for reviewing and testing but please use "Reviewed-and-tested-by" next time so I don't have to fix it up by hand.
- Paul
$ scripts/checkpatch.pl --strict 0001-selftests-riscv-Add-definition-of-BIT-macro.patch WARNING: 'Reviewed-and-tested-by:' is the preferred signature form #13: Reviewed-and-Tested-by: Sergey Matyukevich <[email protected]>
Paul Walmsley
maintainerRe: [PATCH v2 1/4] selftests: riscv: Add definition of BIT() macro
In reply to Charlie JenkinsQuoted 9 lines · On Mon, 9 Mar 2026, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
The
BIT()macros is used by thevalidate_v_ptrace()test case, but not defined. Includelinux/bits.hto pull in this definition. To ensure that the header in the kernel source is used, addtools/includeto the header search path.Fixes 30eb191c895b ("selftests: riscv: verify ptrace rejects invalid vector csr inputs")Signed-off-by Charlie Jenkins <[email protected]>
Thanks, queued for v7.0-rc.
- Paul
PATCH v2 2/4 selftests: riscv: Add braces around EXPECT_EQ()
In reply to Charlie JenkinsEXPECT_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’
--- 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
@@ -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
Re: [PATCH v2 2/4] selftests: riscv: Add braces around EXPECT_EQ()
(adding Kees Cook as he originally submitted this __EXPECT macro)
Quoted 7 lines · On Mon, 2026-03-09 at 18:52 -0700, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[[email protected]](mailto:[email protected])>
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 aroundEXPECT_EQ()to avoid the error even though checkpatch suggests them to be removed:
The __EXPECT macro definition is a multistatement
"do { ... } while (0); OPTIONAL_HANDLER(_assert)Perhaps the multistatement __EXPECT should have another do {} while (0) around both statments like:
do {
do { ... } while (0);
OPTIONAL_HANDLER(_assert);
} while (0)so if else blocks without braces would work.
Perhaps the same for the __EXPECT_STR macro definition.
Re: [PATCH v2 2/4] selftests: riscv: Add braces around EXPECT_EQ()
In reply to Charlie JenkinsQuoted 10 lines · On Mon, Mar 09, 2026 at 06:52:11PM -0700, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
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 aroundEXPECT_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’
Quoted 7 lines
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")Signed-off-by Charlie Jenkins <[email protected]>--- tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
Thanks,
Sergey
Paul Walmsley
maintainerRe: [PATCH v2 2/4] selftests: riscv: Add braces around EXPECT_EQ()
In reply to Charlie JenkinsQuoted 9 lines · On Mon, 9 Mar 2026, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
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 aroundEXPECT_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’
That's annoying. Can't the macro body be wrapped in do { ... } while (0); instead, rather than adding these permanent checkpatch warnings?
- Paul
Paul Walmsley
maintainerRe: [PATCH v2 2/4] selftests: riscv: Add braces around EXPECT_EQ()
Quoted 10 lines · Paul Walmsley
Quoted 8 lines · On Mon, 9 Mar 2026, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
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 aroundEXPECT_EQ()to avoid the error even though checkpatch suggests them to be removed:
Quoted 4 lines
Quoted 1 line
validate_v_ptrace.c:626:17: error: ‘else’ without a previous ‘if’
That's annoying. Can't the macro body be wrapped in do { ... } while (0); instead, rather than adding these permanent checkpatch warnings?
I guess you haven't had the chance to take a look at this. Or maybe you took a look at the kselftest harness macro mess and just decided not to say anything ;-) I did look, after not hearing back, and the way those macros are used would make it a big and painful lift to straighten out - definitely not something for the -rc time frame.
So in the short term, I'm planning to take this as a fix to deal with the immediate issue.
checkpatch.pl clearly needs to be patched to assume that these kselftest harness macros don't follow the rules. Care to take that on?
- Paul
PATCH v2 3/4 riscv: ptrace: Fix BIT() compilation issues
In reply to Charlie JenkinsBIT() 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.
--- arch/riscv/include/uapi/asm/ptrace.h | 1 + 1 file changed, 1 insertion(+)
arch/riscv/include/uapi/asm/ptrace.h +1 -0
@@ -8,6 +8,7 @@#ifndef __ASSEMBLER__ +#include <linux/bits.h> #include <linux/types.h> #define PTRACE_GETFDPIC 33
Signature · 1 line
2.52.0
Re: [PATCH v2 3/4] riscv: ptrace: Fix BIT() compilation issues
Quoted 5 lines · On Mon, Mar 09, 2026 at 06:52:12PM -0700, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
BIT()is being used inptrace.hwithout a definition, resulting in compilation errors intools/testing/selftests/riscv/cfi/cfitests.c:
Quoted 7 lines
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.hto resolve this issue.Fixes 2af7c9cf021c ("riscv/ptrace: expose riscv CFI status and state via ptrace and in core files")Signed-off-by Charlie Jenkins <[email protected]>
Quoted 21 lines
---
arch/riscv/include/uapi/asm/ptrace.h| 1 +1 file changed, 1 insertion(+)arch/riscv/include/uapi/asm/ptrace.h +1
-0@@ -8,6 +8,7 @@#ifndef __ASSEMBLER__ +#include <linux/bits.h> #include <linux/types.h> #define PTRACE_GETFDPIC 33Signature · 2 lines
-- 2.52.0
Paul Walmsley
maintainerRe: [PATCH v2 3/4] riscv: ptrace: Fix BIT() compilation issues
In reply to Charlie JenkinsQuoted 5 lines · On Mon, 9 Mar 2026, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
BIT()is being used inptrace.hwithout a definition, resulting in compilation errors intools/testing/selftests/riscv/cfi/cfitests.c:
Quoted 7 lines
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.hto resolve this issue.Fixes 2af7c9cf021c ("riscv/ptrace: expose riscv CFI status and state via ptrace and in core files")Signed-off-by Charlie Jenkins <[email protected]>
Thanks, queued for v7.0-rc.
- Paul
PATCH v2 4/4 selftests: riscv: Add license to cfi selftest
In reply to Charlie JenkinsThe 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
@@ -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
Re: [PATCH v2 4/4] selftests: riscv: Add license to cfi selftest
Quoted 5 lines · On Mon, Mar 09, 2026 at 06:52:13PM -0700, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
The cfi selftest was missing a license so add it.
Signed-off-by Charlie Jenkins <[email protected]>
Quoted 19 lines
---
tools/testing/selftests/riscv/cfi/Makefile| 2 ++1 file changed, 2 insertions(+)tools/testing/selftests/riscv/cfi/Makefile +2
-0@@ -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
Paul Walmsley
maintainerRe: [PATCH v2 4/4] selftests: riscv: Add license to cfi selftest
In reply to Charlie JenkinsQuoted 5 lines · On Mon, 9 Mar 2026, Charlie Jenkins via B4 Relay wrote:
From: Charlie Jenkins <[email protected]>
The cfi selftest was missing a license so add it.
Signed-off-by Charlie Jenkins <[email protected]>
Thanks, queued for v7.0-rc. This sort of thing probably is best coming from Deepak, since he is the author, but since he added his Reviewed-by:, we're good.
- Paul
This series was applied to riscv/linux.git (fixes) by Paul Walmsley <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Paul Walmsley <[email protected]>:
Quoted 9 lines · On Mon, 09 Mar 2026 18:52:09 -0700 you 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.Signed-off-by Charlie Jenkins <[email protected]>[...]
Here is the summary with links:
- [v2,1/4] selftests: riscv: Add definition of BIT() macro
https://git.kernel.org/riscv/c/e93c2978c9db - [v2,2/4] selftests: riscv: Add braces around EXPECT_EQ() (no matching commit) - [v2,3/4] riscv: ptrace: Fix BIT() compilation issues https://git.kernel.org/riscv/c/b1b59c40962e - [v2,4/4] selftests: riscv: Add license to cfi selftest https://git.kernel.org/riscv/c/5ccc568075c9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
This series was applied to riscv/linux.git (fixes) by Paul Walmsley <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Paul Walmsley <[email protected]>:
Quoted 9 lines · On Mon, 09 Mar 2026 18:52:09 -0700 you 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.Signed-off-by Charlie Jenkins <[email protected]>[...]
Here is the summary with links:
- [v2,1/4] selftests: riscv: Add definition of BIT() macro (no matching commit)
- [v2,2/4] selftests: riscv: Add braces around EXPECT_EQ()
https://git.kernel.org/riscv/c/2ff48e038210
- [v2,3/4] riscv: ptrace: Fix BIT() compilation issues (no matching commit)
- [v2,4/4] selftests: riscv: Add license to cfi selftest (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html