Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

riscv: compat: Support TASK_SIZE for compat mode

Make TASK_SIZE from const to dynamic detect TIF_32BIT flag
function. Refer to arm64 to implement DEFAULT_MAP_WINDOW_64 for
efi-stub.

Limit 32-bit compatible process in 0-2GB virtual address range
(which is enough for real scenarios), because it could avoid
address sign extend problem when 32-bit enter 64-bit and ease
software design.

The standard 32-bit TASK_SIZE is 0x9dc00000:FIXADDR_START, and
compared to a compatible 32-bit, it increases 476MB for the
application's virtual address.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Link: https://lore.kernel.org/r/20220405071314.3225832-11-guoren@kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>

authored by

Guo Ren and committed by
Palmer Dabbelt
01abdfea 06d0e372

+16 -3
+11 -2
arch/riscv/include/asm/pgtable.h
··· 707 707 * 63–48 all equal to bit 47, or else a page-fault exception will occur." 708 708 */ 709 709 #ifdef CONFIG_64BIT 710 - #define TASK_SIZE (PGDIR_SIZE * PTRS_PER_PGD / 2) 711 - #define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2) 710 + #define TASK_SIZE_64 (PGDIR_SIZE * PTRS_PER_PGD / 2) 711 + #define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2) 712 + 713 + #ifdef CONFIG_COMPAT 714 + #define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE) 715 + #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ 716 + TASK_SIZE_32 : TASK_SIZE_64) 717 + #else 718 + #define TASK_SIZE TASK_SIZE_64 719 + #endif 720 + 712 721 #else 713 722 #define TASK_SIZE FIXADDR_START 714 723 #define TASK_SIZE_MIN TASK_SIZE
+5 -1
arch/riscv/include/asm/processor.h
··· 19 19 #define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) 20 20 21 21 #define STACK_TOP TASK_SIZE 22 - #define STACK_TOP_MAX STACK_TOP 22 + #ifdef CONFIG_64BIT 23 + #define STACK_TOP_MAX TASK_SIZE_64 24 + #else 25 + #define STACK_TOP_MAX TASK_SIZE 26 + #endif 23 27 #define STACK_ALIGN 16 24 28 25 29 #ifndef __ASSEMBLY__