Skip to contentSkip to conversation

riscv: ptrace: avoid BIT() in UAPI header

PATCH Applied Michael Neuling 4 participants 5 messages Mar 30 – Apr 3

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

PATCH 1/1 riscv: ptrace: avoid BIT() in UAPI header

BIT() is not available in UAPI headers — the installed linux/bits.h (UAPI version) does not define it. Replace BIT() with open-coded (1UL << x) which is the standard practice for UAPI headers, and drop the linux/bits.h include that was added by commit 98545620b0 ("riscv:
ptrace: Fix BIT() compilation issues").

Fixes 98545620b0 ("riscv: ptrace: Fix BIT() compilation issues")
Assisted-by Claude Opus 4.6 (1M context) <[email protected]>
---
 arch/riscv/include/uapi/asm/ptrace.h | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
arch/riscv/include/uapi/asm/ptrace.h +6 -7
index 5b53cea143..7cbd558b9b 100644
@@ -8,7 +8,6 @@
 
 #ifndef __ASSEMBLER__
 
-#include <linux/bits.h>
 #include <linux/types.h>
 
 #define PTRACE_GETFDPIC		33
@@ -139,12 +138,12 @@ struct __sc_riscv_cfi_state {
 #define PTRACE_CFI_SS_LOCK_BIT	4
 #define PTRACE_CFI_SS_PTR_BIT	5
 
-#define PTRACE_CFI_LP_EN_STATE		BIT(PTRACE_CFI_LP_EN_BIT)
-#define PTRACE_CFI_LP_LOCK_STATE	BIT(PTRACE_CFI_LP_LOCK_BIT)
-#define PTRACE_CFI_ELP_STATE		BIT(PTRACE_CFI_ELP_BIT)
-#define PTRACE_CFI_SS_EN_STATE		BIT(PTRACE_CFI_SS_EN_BIT)
-#define PTRACE_CFI_SS_LOCK_STATE	BIT(PTRACE_CFI_SS_LOCK_BIT)
-#define PTRACE_CFI_SS_PTR_STATE		BIT(PTRACE_CFI_SS_PTR_BIT)
+#define PTRACE_CFI_LP_EN_STATE		(1UL << PTRACE_CFI_LP_EN_BIT)
+#define PTRACE_CFI_LP_LOCK_STATE	(1UL << PTRACE_CFI_LP_LOCK_BIT)
+#define PTRACE_CFI_ELP_STATE		(1UL << PTRACE_CFI_ELP_BIT)
+#define PTRACE_CFI_SS_EN_STATE		(1UL << PTRACE_CFI_SS_EN_BIT)
+#define PTRACE_CFI_SS_LOCK_STATE	(1UL << PTRACE_CFI_SS_LOCK_BIT)
+#define PTRACE_CFI_SS_PTR_STATE		(1UL << PTRACE_CFI_SS_PTR_BIT)
 
 #define PRACE_CFI_STATE_INVALID_MASK	~(PTRACE_CFI_LP_EN_STATE | \
 					  PTRACE_CFI_LP_LOCK_STATE | \
Signature · 1 line
2.43.0
#1 lore raw

Paul,

Quoted 1 line
Fixes 98545620b0 ("riscv: ptrace: Fix BIT() compilation issues")

This is fixing a patch in queued in the for-next branch. So this could be taken on top of that patch or merged with that patch to avoid the issue to start with but that would need for-next to be rebased.

Mikey

#2 lore raw
In reply to Michael Neuling
Quoted 5 lines · Michael Neuling

BIT() is not available in UAPI headers — the installed linux/bits.h (UAPI version) does not define it. Replace BIT() with open-coded (1UL << x) which is the standard practice for UAPI headers, and drop the linux/bits.h include that was added by commit 98545620b0 ("riscv:
ptrace: Fix BIT() compilation issues").

There is also the _BITUL macro, which may be preferable.

Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
maintainer
#3 lore raw
Quoted 9 lines · Andreas Schwab
Quoted 5 lines · Michael Neuling

BIT() is not available in UAPI headers — the installed linux/bits.h (UAPI version) does not define it. Replace BIT() with open-coded (1UL << x) which is the standard practice for UAPI headers, and drop the linux/bits.h include that was added by commit 98545620b0 ("riscv:
ptrace: Fix BIT() compilation issues").

There is also the _BITUL macro, which may be preferable.

Thanks everyone. Below is what I ended up with. I'll drop Charlie's two patches to avoid churn.

- Paul

From: Paul Walmsley <[email protected]>
Date: Thu, 2 Apr 2026 17:18:03 -0600
Subject: [PATCH] riscv: use _BITUL macro rather than BIT() in ptrace uapi and
kselftests

Fix the build of non-kernel code that includes the RISC-V ptrace uapi header, and the RISC-V validate_v_ptrace.c kselftest, by using the _BITUL() macro rather than BIT(). BIT() is not available outside the kernel.

Based on patches and comments from Charlie Jenkins, Michael Neuling, and Andreas Schwab.

Fixes 30eb191c895b ("selftests: riscv: verify ptrace rejects invalid vector csr inputs")
Fixes 2af7c9cf021c ("riscv/ptrace: expose riscv CFI status and state via ptrace and in core files")
Cc Andreas Schwab <[email protected]>
Cc Michael Neuling <[email protected]>
Cc Charlie Jenkins <[email protected]>
---
 arch/riscv/include/uapi/asm/ptrace.h                | 13 +++++++------
 .../selftests/riscv/vector/validate_v_ptrace.c      |  4 ++--
 2 files changed, 9 insertions(+), 8 deletions(-)
arch/riscv/include/uapi/asm/ptrace.h +7 -6
index 18988a5f1a63..70a74adad914 100644
@@ -9,6 +9,7 @@
 #ifndef __ASSEMBLER__
 
 #include <linux/types.h>
+#include <linux/const.h>
 
 #define PTRACE_GETFDPIC		33
 
@@ -138,12 +139,12 @@ struct __sc_riscv_cfi_state {
 #define PTRACE_CFI_SS_LOCK_BIT	4
 #define PTRACE_CFI_SS_PTR_BIT	5
 
-#define PTRACE_CFI_LP_EN_STATE		BIT(PTRACE_CFI_LP_EN_BIT)
-#define PTRACE_CFI_LP_LOCK_STATE	BIT(PTRACE_CFI_LP_LOCK_BIT)
-#define PTRACE_CFI_ELP_STATE		BIT(PTRACE_CFI_ELP_BIT)
-#define PTRACE_CFI_SS_EN_STATE		BIT(PTRACE_CFI_SS_EN_BIT)
-#define PTRACE_CFI_SS_LOCK_STATE	BIT(PTRACE_CFI_SS_LOCK_BIT)
-#define PTRACE_CFI_SS_PTR_STATE		BIT(PTRACE_CFI_SS_PTR_BIT)
+#define PTRACE_CFI_LP_EN_STATE		_BITUL(PTRACE_CFI_LP_EN_BIT)
+#define PTRACE_CFI_LP_LOCK_STATE	_BITUL(PTRACE_CFI_LP_LOCK_BIT)
+#define PTRACE_CFI_ELP_STATE		_BITUL(PTRACE_CFI_ELP_BIT)
+#define PTRACE_CFI_SS_EN_STATE		_BITUL(PTRACE_CFI_SS_EN_BIT)
+#define PTRACE_CFI_SS_LOCK_STATE	_BITUL(PTRACE_CFI_SS_LOCK_BIT)
+#define PTRACE_CFI_SS_PTR_STATE		_BITUL(PTRACE_CFI_SS_PTR_BIT)
 
 #define PRACE_CFI_STATE_INVALID_MASK	~(PTRACE_CFI_LP_EN_STATE | \
 					  PTRACE_CFI_LP_LOCK_STATE | \
tools/testing/selftests/riscv/vector/validate_v_ptrace.c +2 -2
index 3589549f7228..7ae6fede496f 100644
@@ -346,8 +346,8 @@ FIXTURE_TEARDOWN(v_csr_invalid)
 {
 }
 
-#define VECTOR_1_0		BIT(0)
-#define XTHEAD_VECTOR_0_7	BIT(1)
+#define VECTOR_1_0		_BITUL(0)
+#define XTHEAD_VECTOR_0_7	_BITUL(1)
 
 #define vector_test(x)		((x) & VECTOR_1_0)
 #define xthead_test(x)		((x) & XTHEAD_VECTOR_0_7)
Signature · 1 line
2.51.0
#4 lore raw
In reply to Michael Neuling
This patch was applied to riscv/linux.git (fixes) by Paul Walmsley <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Paul Walmsley <[email protected]>:

Quoted 11 lines · On Mon, 30 Mar 2026 02:42:48 +0000 you wrote:

BIT() is not available in UAPI headers — the installed linux/bits.h (UAPI version) does not define it. Replace BIT() with open-coded (1UL << x) which is the standard practice for UAPI headers, and drop the linux/bits.h include that was added by commit 98545620b0 ("riscv:
ptrace: Fix BIT() compilation issues").

Fixes 98545620b0 ("riscv: ptrace: Fix BIT() compilation issues")
Assisted-by Claude Opus 4.6 (1M context) <[email protected]>

[...]

Here is the summary with links:
- riscv: ptrace: avoid BIT() in UAPI header

    https://git.kernel.org/riscv/c/640dc01a97f9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html