Skip to content

[PW_SID:1121150] riscv: fix PIO helpers and add optimized percpu ops#2210

Closed
linux-riscv-bot wants to merge 4 commits into
workflow__riscv__fixesfrom
pw1121150
Closed

[PW_SID:1121150] riscv: fix PIO helpers and add optimized percpu ops#2210
linux-riscv-bot wants to merge 4 commits into
workflow__riscv__fixesfrom
pw1121150

Conversation

@linux-riscv-bot

Copy link
Copy Markdown

PR for series 1121150 applied to workflow__riscv__fixes

Name: riscv: fix PIO helpers and add optimized percpu ops
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1121150
Version: 8

Linux RISC-V bot and others added 4 commits July 1, 2026 03:48
When port I/O is not supported, exposing the port-string helpers is both
unnecessary and can make clang diagnose null-pointer arithmetic from the
PCI_IOBASE based address expression.  Keep the MMIO string helpers
available as before, but only provide the port I/O variants when
CONFIG_HAS_IOPORT is enabled.

Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Add RISC-V specific this_cpu helpers so common percpu operations can use
short architecture sequences instead of the generic implementation.
Native-width operations use AMOs, while 8/16-bit operations use Zabha when
available and a local 32-bit LR/SC fallback otherwise.

Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
RISC-V percpu addressing currently derives the base offset from the CPU
number and __per_cpu_offset[]. Cache the current CPU percpu offset in
thread_info so percpu accesses can load it directly.

Keep the cached value up to date for the boot CPU, context switches and
secondary CPU bringup. Initialize secondary idle tasks before they start
running so early percpu accesses use the secondary CPU offset rather than
inheriting the boot CPU value.

With asm_per_cpu no longer deriving the offset from the CPU number, drop
the stale TASK_TI_CPU_NUM asm offset as well.

Link: https://lists.riscv.org/g/tech-privileged/topic/risc_v_tech_arch_review/113437553?page=2
Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 121.63 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 2195.40 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 2911.09 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 22.34 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 23.73 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.67 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 78.97 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
kdoc
Desc: Detects for kdoc errors
Duration: 0.71 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
module-param
Desc: Detect module_param changes
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v8,1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 121.95 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 2630.03 seconds
Result: ERROR
Output:

Redirect to /build/tmp.qOdJM77AMe and /build/tmp.8aZgIciGXX
Tree base:
1b9c9f0363579 ("riscv: io: avoid null-pointer arithmetic in PIO helpers")
Building the whole tree with the patch
Building the tree before the patch
Building the tree with the patch
New errors added:
--- /build/tmp.itk5vkUNCc	2026-07-03 15:45:29.739044199 +0000
+++ /build/tmp.mBJb3R29xZ	2026-07-03 15:45:29.741044150 +0000
@@ -170,0 +171 @@
+      1 /build/tmph0nz0gem/kernel/fork.c:268:8: warning: variable '__old' is uninitialized when used within its own initialization [-Wuninitialized]
Per-file breakdown
error/warning file pre:
error/warning file post:
pre: 220 post: 221



real	16m44.457s
user	587m44.601s
sys	122m53.703s

real	20m21.418s
user	602m6.445s
sys	124m46.404s

real	6m29.756s
user	48m1.456s
sys	26m52.248s

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 3132.25 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 22.18 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 24.06 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.98 seconds
Result: ERROR
Output:

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#19: 
new file mode 100644

ERROR: Macros with complex values should be enclosed in parentheses
#68: FILE: arch/riscv/include/asm/percpu.h:45:
+#define PERCPU_OP(name, amo_insn)					\
+	__PERCPU_AMO_OP_CASE(.w, name, 32, amo_insn)			\
+	__PERCPU_AMO_OP_CASE(.d, name, 64, amo_insn)

BUT SEE:

   do {} while (0) advice is over-stated in a few situations:

   The more obvious case is macros, like MODULE_PARM_DESC, invoked at
   file-scope, where C disallows code (it must be in functions).  See
   $exceptions if you have one to add by name.

   More troublesome is declarative macros used at top of new scope,
   like DECLARE_PER_CPU.  These might just compile with a do-while-0
   wrapper, but would be incorrect.  Most of these are handled by
   detecting struct,union,etc declaration primitives in $exceptions.

   Theres also macros called inside an if (block), which "return" an
   expression.  These cannot do-while, and need a ({}) wrapper.

   Enjoy this qualification while we work to improve our heuristics.

ERROR: Macros with complex values should be enclosed in parentheses
#84: FILE: arch/riscv/include/asm/percpu.h:61:
+#define __PERCPU_AMO_RET_OP_CASE(sfx, name, sz, amo_insn)		\
+static inline u##sz							\
+__percpu_##name##_return_amo_case_##sz(void *ptr, unsigned long val)	\
+{									\
+	register u##sz ret;						\
+									\
+	asm volatile (							\
+		"amo" #amo_insn #sfx " %[ret], %[val], %[ptr]"		\
+		: [ptr] "+A" (*(u##sz *)ptr), [ret] "=r" (ret)		\
+		: [val] "r" ((u##sz)(val))				\
+		: "memory");						\
+									\
+	return ret + val;						\
+}

BUT SEE:

   do {} while (0) advice is over-stated in a few situations:

   The more obvious case is macros, like MODULE_PARM_DESC, invoked at
   file-scope, where C disallows code (it must be in functions).  See
   $exceptions if you have one to add by name.

   More troublesome is declarative macros used at top of new scope,
   like DECLARE_PER_CPU.  These might just compile with a do-while-0
   wrapper, but would be incorrect.  Most of these are handled by
   detecting struct,union,etc declaration primitives in $exceptions.

   Theres also macros called inside an if (block), which "return" an
   expression.  These cannot do-while, and need a ({}) wrapper.

   Enjoy this qualification while we work to improve our heuristics.

ERROR: Macros with complex values should be enclosed in parentheses
#100: FILE: arch/riscv/include/asm/percpu.h:77:
+#define PERCPU_RET_OP(name, amo_insn)					\
+	__PERCPU_AMO_RET_OP_CASE(.w, name, 32, amo_insn)		\
+	__PERCPU_AMO_RET_OP_CASE(.d, name, 64, amo_insn)

BUT SEE:

   do {} while (0) advice is over-stated in a few situations:

   The more obvious case is macros, like MODULE_PARM_DESC, invoked at
   file-scope, where C disallows code (it must be in functions).  See
   $exceptions if you have one to add by name.

   More troublesome is declarative macros used at top of new scope,
   like DECLARE_PER_CPU.  These might just compile with a do-while-0
   wrapper, but would be incorrect.  Most of these are handled by
   detecting struct,union,etc declaration primitives in $exceptions.

   Theres also macros called inside an if (block), which "return" an
   expression.  These cannot do-while, and need a ({}) wrapper.

   Enjoy this qualification while we work to improve our heuristics.

CHECK: Macro argument 'val_type' may be better as '(val_type)' to avoid precedence issues
#114: FILE: arch/riscv/include/asm/percpu.h:91:
+#define PERCPU_8_16_OP(name, amo_insn, sz, sfx, val_type, new_val_expr, asm_op)			\
+static inline void __percpu_##name##_amo_case_##sz(void *ptr, unsigned long val)		\
+{												\
+	if (IS_ENABLED(CONFIG_RISCV_ISA_ZABHA) &&						\
+		riscv_has_extension_unlikely(RISCV_ISA_EXT_ZABHA)) {				\
+		asm volatile ("amo" #amo_insn #sfx " zero, %[val], %[ptr]"			\
+			: [ptr] "+A"(*(val_type *)ptr)						\
+			: [val] "r"((val_type)((new_val_expr) & PERCPU_8_16_GET_MASK(sz)))	\
+			: "memory");								\
+	} else {										\
+		u32 *ptr32 = PERCPU_8_16_GET_PTR32(ptr);					\
+		const unsigned long shift = PERCPU_8_16_GET_SHIFT(ptr);				\
+		const u32 mask = PERCPU_8_16_GET_MASK(sz) << shift;				\
+		const val_type val_trunc = (val_type)((new_val_expr)				\
+					   & PERCPU_8_16_GET_MASK(sz));				\
+		u32 old, new;									\
+		val_type field;									\
+												\
+		asm volatile (									\
+			"0: lr.w %0, %2\n"							\
+			"and %3, %0, %4\n"							\
+			"srl %3, %3, %5\n"							\
+			#asm_op " %3, %3, %6\n"							\
+			"and %3, %3, %8\n"							\
+			"sll %3, %3, %5\n"							\
+			"and %1, %0, %7\n"							\
+			"or %1, %1, %3\n"							\
+			"sc.w %1, %1, %2\n"							\
+			"bnez %1, 0b\n"								\
+			: "=&r"(old), "=&r"(new), "+A"(*ptr32), "=&r"(field)			\
+			: "r"(mask), "r"(shift), "r"(val_trunc), "r"(~mask),			\
+			  "r"(PERCPU_8_16_GET_MASK(sz))						\
+			: "memory");								\
+		}										\
+}

WARNING: Non-declarative macros with multiple statements should be enclosed in a do - while loop
#150: FILE: arch/riscv/include/asm/percpu.h:127:
+#define PERCPU_OP_8_16(op_name, op, expr, final_op)			\
+	PERCPU_8_16_OP(op_name, op, 8, .b, u8, expr, final_op);		\
+	PERCPU_8_16_OP(op_name, op, 16, .h, u16, expr, final_op)

BUT SEE:

   do {} while (0) advice is over-stated in a few situations:

   The more obvious case is macros, like MODULE_PARM_DESC, invoked at
   file-scope, where C disallows code (it must be in functions).  See
   $exceptions if you have one to add by name.

   More troublesome is declarative macros used at top of new scope,
   like DECLARE_PER_CPU.  These might just compile with a do-while-0
   wrapper, but would be incorrect.  Most of these are handled by
   detecting struct,union,etc declaration primitives in $exceptions.

   Theres also macros called inside an if (block), which "return" an
   expression.  These cannot do-while, and need a ({}) wrapper.

   Enjoy this qualification while we work to improve our heuristics.

total: 3 errors, 2 warnings, 1 checks, 296 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit 36f3cddd7903 ("riscv: introduce percpu.h into include/asm") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
CHECK: Macro argument 'val_type' may be better as '(val_type)' to avoid precedence issues
ERROR: Macros with complex values should be enclosed in parentheses
WARNING: Non-declarative macros with multiple statements should be enclosed in a do - while loop
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?


@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 81.91 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
kdoc
Desc: Detects for kdoc errors
Duration: 0.74 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v8,2/3] riscv: introduce percpu.h into include/asm"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 121.14 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 2542.09 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 3120.28 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 22.54 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 23.92 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 2.48 seconds
Result: WARNING
Output:

CHECK: Consider using #include <linux/thread_info.h> instead of <asm/thread_info.h>
#58: FILE: arch/riscv/include/asm/percpu.h:14:
+#include <asm/thread_info.h>

total: 0 errors, 0 warnings, 1 checks, 121 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit 239e9a1de2f6 ("riscv: store percpu offset into thread_info") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 0 warnings, 1 checks, 121 lines checked
CHECK: Consider using #include <linux/thread_info.h> instead of <asm/thread_info.h>


@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 80.33 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
kdoc
Desc: Detects for kdoc errors
Duration: 0.76 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v8,3/3] riscv: store percpu offset into thread_info"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
linux-riscv-bot force-pushed the workflow__riscv__fixes branch 5 times, most recently from 2b6a725 to da477a6 Compare July 11, 2026 01:54
@linux-riscv-bot
linux-riscv-bot deleted the pw1121150 branch July 11, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants