riscv: minor thread_info.cpu improvements
Subsystems (2)
v2 cover riscv: minor thread_info.cpu improvements
Hello,
I noticed that we give thread_info.cpu two different names in the assembly, load it as a wider type, and store it suboptimally.
v2 is split for easy backporting.
Thanks.
v2:
* transform [v1 2/3] into [v2 1-2/4] to simplify backports [Alex]
* tested and reviewed by Alex
v1: https://lore.kernel.org/lkml/[email protected]/
Radim Krčmář (4):
riscv: use lw when reading int cpu in new_vmalloc_check
riscv: use lw when reading int cpu in asm_per_cpu
riscv: use TASK_TI_CPU instead of TASK_TI_CPU_NUM
riscv: pack rv64 thread_info better
arch/riscv/include/asm/asm.h | 2 +- arch/riscv/include/asm/thread_info.h | 2 +- arch/riscv/kernel/asm-offsets.c | 1 - arch/riscv/kernel/entry.S | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-)
Signature · 1 line
2.50.0
PATCH v2 1/4 riscv: use lw when reading int cpu in new_vmalloc_check
REG_L is wrong, because thread_info.cpu is 32-bit, not xlen-bit wide. The struct currently has a hole after cpu, so little endian accesses seemed fine.
---
v2: split for stable [Alex]
--- arch/riscv/kernel/entry.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/entry.S +1 -1
@@ -46,7 +46,7 @@ * a0 = &new_vmalloc[BIT_WORD(cpu)] * a1 = BIT_MASK(cpu) */ - REG_L a2, TASK_TI_CPU(tp) + lw a2, TASK_TI_CPU(tp) /* * Compute the new_vmalloc element position: * (cpu / 64) * 8 = (cpu >> 6) << 3
Signature · 1 line
2.50.0
PATCH v2 2/4 riscv: use lw when reading int cpu in asm_per_cpu
In reply to Radim KrčmářREG_L is wrong, because thread_info.cpu is 32-bit, not xlen-bit wide. The struct currently has a hole after cpu, so little endian accesses seemed fine.
---
v2: split for stable [Alex]
--- arch/riscv/include/asm/asm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/asm.h +1 -1
@@ -91,7 +91,7 @@#endif .macro asm_per_cpu dst sym tmp - REG_L \tmp, TASK_TI_CPU_NUM(tp) + lw \tmp, TASK_TI_CPU_NUM(tp) slli \tmp, \tmp, PER_CPU_OFFSET_SHIFT la \dst, __per_cpu_offset add \dst, \dst, \tmp
Signature · 1 line
2.50.0
PATCH v2 3/4 riscv: use TASK_TI_CPU instead of TASK_TI_CPU_NUM
In reply to Radim KrčmářThe offsets of TASK_TI_CPU and TASK_TI_CPU_NUM are identical, and TASK_TI_CPU is a better name for thread_info.cpu.
---
v2: moved after patches for stable [Alex]
--- arch/riscv/include/asm/asm.h | 2 +- arch/riscv/kernel/asm-offsets.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
arch/riscv/include/asm/asm.h +1 -1
@@ -91,7 +91,7 @@#endif .macro asm_per_cpu dst sym tmp - lw \tmp, TASK_TI_CPU_NUM(tp) + lw \tmp, TASK_TI_CPU(tp) slli \tmp, \tmp, PER_CPU_OFFSET_SHIFT la \dst, __per_cpu_offset add \dst, \dst, \tmp
arch/riscv/kernel/asm-offsets.c +0 -1
@@ -49,7 +49,6 @@ void asm_offsets(void)OFFSET (TASK_TI_A2 , task_struct, thread_info.a2);#endif -OFFSET (TASK_TI_CPU_NUM , task_struct, thread_info.cpu);OFFSET (TASK_THREAD_F0 , task_struct, thread.fstate.f[0 ]);OFFSET (TASK_THREAD_F1 , task_struct, thread.fstate.f[1 ]);OFFSET (TASK_THREAD_F2 , task_struct, thread.fstate.f[2 ]);
Signature · 1 line
2.50.0
PATCH v2 4/4 riscv: pack rv64 thread_info better
In reply to Radim KrčmářOn rv64, preempt_count and cpu were both 32-bit followed by 64-bit, so placing one in the hole saves 8 bytes in the struct.
---
v2: tested and reviewed by Alex
--- arch/riscv/include/asm/thread_info.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/thread_info.h +1 -1
@@ -53,6 +53,7 @@struct thread_info {unsigned long flags;/* low level flags */ int preempt_count;/* 0=>preemptible, <0=>BUG */ +int cpu;/* * These stack pointers are overwritten on every system call or * exception. SP is also saved to the stack it can be recovered when
@@ -60,7 +61,6 @@ struct thread_info {*/ long kernel_sp;/* Kernel stack pointer */ long user_sp;/* User stack pointer */ -int cpu;unsigned long syscall_work;/* SYSCALL_WORK_ flags */ #ifdef CONFIG_SHADOW_CALL_STACK void *scs_base;
Signature · 1 line
2.50.0
Alexandre Ghiti
reviewerHi Radim,
Quoted 20 lines · Radim Krčmář
Hello,
I noticed that we give thread_info.cpu two different names in the assembly, load it as a wider type, and store it suboptimally.
v2 is split for easy backporting.
Thanks.
v2:
* transform [v1 2/3] into [v2 1-2/4] to simplify backports [Alex]
* tested and reviewed by Alex
v1: https://lore.kernel.org/lkml/[email protected]/Radim Krčmář (4):
riscv: use lw when reading int cpu innew_vmalloc_check
riscv: use lw when reading int cpu inasm_per_cpu
riscv: useTASK_TI_CPUinstead ofTASK_TI_CPU_NUM
riscv: pack rv64thread_infobetter
Quoted 6 lines
arch/riscv/include/asm/asm.h | 2 +- arch/riscv/include/asm/thread_info.h | 2 +- arch/riscv/kernel/asm-offsets.c | 1 - arch/riscv/kernel/entry.S | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-)
Thanks for the quick respin, I'll take that for 6.17.
Thanks,
Alex
This series was applied to riscv/linux.git (for-next) by Alexandre Ghiti <[email protected]>:
Hello:
This series was applied to riscv/linux.git (for-next) by Alexandre Ghiti <[email protected]>:
Quoted 8 lines · On Fri, 25 Jul 2025 18:54:08 +0200 you wrote:
Hello,
I noticed that we give thread_info.cpu two different names in the assembly, load it as a wider type, and store it suboptimally.
v2 is split for easy backporting.
[...]
Here is the summary with links:
- [v2,1/4] riscv: use lw when reading int cpu in new_vmalloc_check
https://git.kernel.org/riscv/c/5fcea028d8b8 - [v2,2/4] riscv: use lw when reading int cpu in asm_per_cpu https://git.kernel.org/riscv/c/47e006cf9789 - [v2,3/4] riscv: use TASK_TI_CPU instead of TASK_TI_CPU_NUM https://git.kernel.org/riscv/c/a1984b2541b0 - [v2,4/4] riscv: pack rv64 thread_info better https://git.kernel.org/riscv/c/9b3a86b7b14c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html