[PATCH V12 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

2022-04-05 Thread guoren
From: Guo Ren Adds initial skeletal COMPAT Kbuild (Running 32bit U-mode on 64bit S-mode) support. - Setup kconfig & dummy functions for compiling. - Implement compat_start_thread by the way. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner

[PATCH V12 19/20] riscv: compat: ptrace: Add compat_arch_ptrace implement

2022-04-05 Thread guoren
From: Guo Ren Now, you can use native gdb on riscv64 for rv32 app debugging. $ uname -a Linux buildroot 5.16.0-rc4-00036-gbef6b82fdf23-dirty #53 SMP Mon Dec 20 23:06:53 CST 2021 riscv64 GNU/Linux $ cat /proc/cpuinfo processor : 0 hart: 0 isa : rv64imafdcsuh mmu

[PATCH V12 18/20] riscv: compat: signal: Add rt_frame implementation

2022-04-05 Thread guoren
From: Guo Ren Implement compat_setup_rt_frame for sigcontext save & restore. The main process is the same with signal, but the rv32 pt_regs' size is different from rv64's, so we needs convert them. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V12 17/20] riscv: compat: vdso: Add setup additional pages implementation

2022-04-05 Thread guoren
From: Guo Ren Reconstruct __setup_additional_pages() by appending vdso info pointer argument to meet compat_vdso_info requirement. And change vm_special_mapping *dm, *cm initialization into static. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V12 16/20] riscv: compat: vdso: Add COMPAT_VDSO base code implementation

2022-04-05 Thread guoren
From: Guo Ren There is no vgettimeofday supported in rv32 that makes simple to generate rv32 vdso code which only needs riscv64 compiler. Other architectures need change compiler or -m (machine parameter) to support vdso32 compiling. If rv32 support vgettimeofday (which cause C compile) in

[PATCH V12 15/20] riscv: compat: Add hw capability check for elf

2022-04-05 Thread guoren
From: Guo Ren Detect hardware COMPAT (32bit U-mode) capability in rv64. If not support COMPAT mode in hw, compat_elf_check_arch would return false by compat_binfmt_elf.c Add CLASS to enhance (compat_)elf_check_arch to distinguish 32BIT/64BIT elf. Signed-off-by: Guo Ren Signed-off-by: Guo Ren

[PATCH V12 14/20] riscv: compat: Add elf.h implementation

2022-04-05 Thread guoren
From: Guo Ren Implement necessary type and macro for compat elf. See the code comment for detail. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner --- arch/riscv/include/asm/elf.h | 41 +++- 1 file changed,

[PATCH V12 13/20] riscv: compat: process: Add UXL_32 support in start_thread

2022-04-05 Thread guoren
From: Guo Ren If the current task is in COMPAT mode, set SR_UXL_32 in status for returning userspace. We need CONFIG _COMPAT to prevent compiling errors with rv32 defconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc: Palmer Dabbelt ---

[PATCH V12 12/20] riscv: compat: syscall: Add entry.S implementation

2022-04-05 Thread guoren
From: Guo Ren Implement the entry of compat_sys_call_table[] in asm. Ref to riscv-privileged spec 4.1.1 Supervisor Status Register (sstatus): BIT[32:33] = UXL[1:0]: - 1:32 - 2:64 - 3:128 Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko Stuebner

[PATCH V12 11/20] riscv: compat: syscall: Add compat_sys_call_table implementation

2022-04-05 Thread guoren
From: Guo Ren Implement compat sys_call_table and some system call functions: truncate64, ftruncate64, fallocate, pread64, pwrite64, sync_file_range, readahead, fadvise64_64 which need argument translation. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by:

[PATCH V12 10/20] riscv: compat: Support TASK_SIZE for compat mode

2022-04-05 Thread guoren
From: Guo Ren 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

[PATCH V12 09/20] riscv: compat: Add basic compat data type implementation

2022-04-05 Thread guoren
From: Guo Ren Implement riscv asm/compat.h for struct compat_xxx, is_compat_task, compat_user_regset, regset convert. The rv64 compat.h has inherited most of the structs from the generic one. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc:

[PATCH V12 08/20] riscv: Fixup difference with defconfig

2022-04-05 Thread guoren
From: Guo Ren Let's follow the origin patch's spirit: The only difference between rv32_defconfig and defconfig is that rv32_defconfig has CONFIG_ARCH_RV32I=y. This is helpful to compare rv64-compat-rv32 v.s. rv32-linux. Fixes: 1b937e8faa87ccfb ("RISC-V: Add separate defconfig for 32bit

[PATCH V12 07/20] syscalls: compat: Fix the missing part for __SYSCALL_COMPAT

2022-04-05 Thread guoren
From: Guo Ren Make "uapi asm unistd.h" could be used for architectures' COMPAT mode. The __SYSCALL_COMPAT is first used in riscv. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner ---

[PATCH V12 06/20] asm-generic: compat: Cleanup duplicate definitions

2022-04-05 Thread guoren
From: Guo Ren There are 7 64bit architectures that support Linux COMPAT mode to run 32bit applications. A lot of definitions are duplicate: - COMPAT_USER_HZ - COMPAT_RLIM_INFINITY - COMPAT_OFF_T_MAX - __compat_uid_t, __compat_uid_t - compat_dev_t - compat_ipc_pid_t - struct compat_flock

[PATCH V12 05/20] fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT

2022-04-05 Thread guoren
From: Guo Ren RISC-V doesn't neeed compat_stat, so using __ARCH_WANT_COMPAT_STAT to exclude unnecessary SYSCALL functions. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Acked-by: Helge Deller # parisc Cc:

[PATCH V12 04/20] arch: Add SYSVIPC_COMPAT for all architectures

2022-04-05 Thread guoren
From: Guo Ren The existing per-arch definitions are pretty much historic cruft. Move SYSVIPC_COMPAT into init/Kconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Acked-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Acked-by: Helge Deller # parisc Cc: Palmer

[PATCH V12 03/20] compat: consolidate the compat_flock{, 64} definition

2022-04-05 Thread guoren
From: Christoph Hellwig Provide a single common definition for the compat_flock and compat_flock64 structures using the same tricks as for the native variants. Another extra define is added for the packing required on x86. Signed-off-by: Christoph Hellwig Signed-off-by: Guo Ren Reviewed-by:

[PATCH V12 02/20] uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h

2022-04-05 Thread guoren
From: Christoph Hellwig The F_GETLK64/F_SETLK64/F_SETLKW64 fcntl opcodes are only implemented for the 32-bit syscall APIs, but are also needed for compat handling on 64-bit kernels. Consolidate them in unistd.h instead of definining the internal compat definitions in compat.h, which is rather

[PATCH V12 01/20] uapi: simplify __ARCH_FLOCK{,64}_PAD a little

2022-04-05 Thread guoren
From: Christoph Hellwig Don't bother to define the symbols empty, just don't use them. That makes the intent a little more clear. Remove the unused HAVE_ARCH_STRUCT_FLOCK64 define and merge the 32-bit mips struct flock into the generic one. Add a new __ARCH_FLOCK_EXTRA_SYSID macro following

[PATCH V12 00/20] riscv: Add COMPAT mode support for 64BIT

2022-04-05 Thread guoren
o-blk-device,drive=hd0 -append "rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi" -netdev user,id=net0 -device virtio-net-device,netdev=net0 QEMU emulator version 6.2.50 (v6.2.0-29-g196d7182c8) OpenSBI v0.9 [ 0.000000] Linux version 5.16.0-rc6-00017-g750f87086bdd-dirty (guoren@

[PATCH V11 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

2022-04-02 Thread guoren
From: Guo Ren Adds initial skeletal COMPAT Kbuild (Running 32bit U-mode on 64bit S-mode) support. - Setup kconfig & dummy functions for compiling. - Implement compat_start_thread by the way. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner

[PATCH V11 19/20] riscv: compat: ptrace: Add compat_arch_ptrace implement

2022-04-02 Thread guoren
From: Guo Ren Now, you can use native gdb on riscv64 for rv32 app debugging. $ uname -a Linux buildroot 5.16.0-rc4-00036-gbef6b82fdf23-dirty #53 SMP Mon Dec 20 23:06:53 CST 2021 riscv64 GNU/Linux $ cat /proc/cpuinfo processor : 0 hart: 0 isa : rv64imafdcsuh mmu

[PATCH V11 18/20] riscv: compat: signal: Add rt_frame implementation

2022-04-02 Thread guoren
From: Guo Ren Implement compat_setup_rt_frame for sigcontext save & restore. The main process is the same with signal, but the rv32 pt_regs' size is different from rv64's, so we needs convert them. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V11 17/20] riscv: compat: vdso: Add setup additional pages implementation

2022-04-02 Thread guoren
From: Guo Ren Reconstruct __setup_additional_pages() by appending vdso info pointer argument to meet compat_vdso_info requirement. And change vm_special_mapping *dm, *cm initialization into static. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V11 16/20] riscv: compat: vdso: Add COMPAT_VDSO base code implementation

2022-04-02 Thread guoren
From: Guo Ren There is no vgettimeofday supported in rv32 that makes simple to generate rv32 vdso code which only needs riscv64 compiler. Other architectures need change compiler or -m (machine parameter) to support vdso32 compiling. If rv32 support vgettimeofday (which cause C compile) in

[PATCH V11 15/20] riscv: compat: Add hw capability check for elf

2022-04-02 Thread guoren
From: Guo Ren Detect hardware COMPAT (32bit U-mode) capability in rv64. If not support COMPAT mode in hw, compat_elf_check_arch would return false by compat_binfmt_elf.c Add CLASS to enhance (compat_)elf_check_arch to distinguish 32BIT/64BIT elf. Signed-off-by: Guo Ren Signed-off-by: Guo Ren

[PATCH V11 14/20] riscv: compat: Add elf.h implementation

2022-04-02 Thread guoren
From: Guo Ren Implement necessary type and macro for compat elf. See the code comment for detail. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner --- arch/riscv/include/asm/elf.h | 41 +++- 1 file changed,

[PATCH V11 13/20] riscv: compat: process: Add UXL_32 support in start_thread

2022-04-02 Thread guoren
From: Guo Ren If the current task is in COMPAT mode, set SR_UXL_32 in status for returning userspace. We need CONFIG _COMPAT to prevent compiling errors with rv32 defconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc: Palmer Dabbelt ---

[PATCH V11 12/20] riscv: compat: syscall: Add entry.S implementation

2022-04-02 Thread guoren
From: Guo Ren Implement the entry of compat_sys_call_table[] in asm. Ref to riscv-privileged spec 4.1.1 Supervisor Status Register (sstatus): BIT[32:33] = UXL[1:0]: - 1:32 - 2:64 - 3:128 Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko Stuebner

[PATCH V11 11/20] riscv: compat: syscall: Add compat_sys_call_table implementation

2022-04-02 Thread guoren
From: Guo Ren Implement compat sys_call_table and some system call functions: truncate64, ftruncate64, fallocate, pread64, pwrite64, sync_file_range, readahead, fadvise64_64 which need argument translation. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by:

[PATCH V11 10/20] riscv: compat: Support TASK_SIZE for compat mode

2022-04-02 Thread guoren
From: Guo Ren 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

[PATCH V11 09/20] riscv: compat: Add basic compat data type implementation

2022-04-02 Thread guoren
From: Guo Ren Implement riscv asm/compat.h for struct compat_xxx, is_compat_task, compat_user_regset, regset convert. The rv64 compat.h has inherited most of the structs from the generic one. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc:

[PATCH V11 08/20] riscv: Fixup difference with defconfig

2022-04-02 Thread guoren
From: Guo Ren Let's follow the origin patch's spirit: The only difference between rv32_defconfig and defconfig is that rv32_defconfig has CONFIG_ARCH_RV32I=y. This is helpful to compare rv64-compat-rv32 v.s. rv32-linux. Fixes: 1b937e8faa87ccfb ("RISC-V: Add separate defconfig for 32bit

[PATCH V11 07/20] syscalls: compat: Fix the missing part for __SYSCALL_COMPAT

2022-04-02 Thread guoren
From: Guo Ren Make "uapi asm unistd.h" could be used for architectures' COMPAT mode. The __SYSCALL_COMPAT is first used in riscv. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner ---

[PATCH V11 06/20] asm-generic: compat: Cleanup duplicate definitions

2022-04-02 Thread guoren
From: Guo Ren There are 7 64bit architectures that support Linux COMPAT mode to run 32bit applications. A lot of definitions are duplicate: - COMPAT_USER_HZ - COMPAT_RLIM_INFINITY - COMPAT_OFF_T_MAX - __compat_uid_t, __compat_uid_t - compat_dev_t - compat_ipc_pid_t - struct compat_flock

[PATCH V11 05/20] fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT

2022-04-02 Thread guoren
From: Guo Ren RISC-V doesn't neeed compat_stat, so using __ARCH_WANT_COMPAT_STAT to exclude unnecessary SYSCALL functions. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Cc: Palmer Dabbelt ---

[PATCH V11 04/20] arch: Add SYSVIPC_COMPAT for all architectures

2022-04-02 Thread guoren
From: Guo Ren The existing per-arch definitions are pretty much historic cruft. Move SYSVIPC_COMPAT into init/Kconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Acked-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Cc: Palmer Dabbelt --- arch/arm64/Kconfig

[PATCH V11 03/20] compat: consolidate the compat_flock{, 64} definition

2022-04-02 Thread guoren
From: Christoph Hellwig Provide a single common definition for the compat_flock and compat_flock64 structures using the same tricks as for the native variants. Another extra define is added for the packing required on x86. Signed-off-by: Christoph Hellwig Signed-off-by: Guo Ren Reviewed-by:

[PATCH V11 02/20] uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h

2022-04-02 Thread guoren
From: Christoph Hellwig The F_GETLK64/F_SETLK64/F_SETLKW64 fcntl opcodes are only implemented for the 32-bit syscall APIs, but are also needed for compat handling on 64-bit kernels. Consolidate them in unistd.h instead of definining the internal compat definitions in compat.h, which is rather

[PATCH V11 01/20] uapi: simplify __ARCH_FLOCK{,64}_PAD a little

2022-04-02 Thread guoren
From: Christoph Hellwig Don't bother to define the symbols empty, just don't use them. That makes the intent a little more clear. Remove the unused HAVE_ARCH_STRUCT_FLOCK64 define and merge the 32-bit mips struct flock into the generic one. Add a new __ARCH_FLOCK_EXTRA_SYSID macro following

[PATCH V11 00/20] riscv: Add COMPAT mode support for rv64

2022-04-02 Thread guoren
o-blk-device,drive=hd0 -append "rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi" -netdev user,id=net0 -device virtio-net-device,netdev=net0 QEMU emulator version 6.2.50 (v6.2.0-29-g196d7182c8) OpenSBI v0.9 [ 0.000000] Linux version 5.16.0-rc6-00017-g750f87086bdd-dirty (guoren@

[PATCH V10 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

2022-04-02 Thread guoren
From: Guo Ren Adds initial skeletal COMPAT Kbuild (Running 32bit U-mode on 64bit S-mode) support. - Setup kconfig & dummy functions for compiling. - Implement compat_start_thread by the way. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner

[PATCH V10 19/20] riscv: compat: ptrace: Add compat_arch_ptrace implement

2022-04-02 Thread guoren
From: Guo Ren Now, you can use native gdb on riscv64 for rv32 app debugging. $ uname -a Linux buildroot 5.16.0-rc4-00036-gbef6b82fdf23-dirty #53 SMP Mon Dec 20 23:06:53 CST 2021 riscv64 GNU/Linux $ cat /proc/cpuinfo processor : 0 hart: 0 isa : rv64imafdcsuh mmu

[PATCH V10 18/20] riscv: compat: signal: Add rt_frame implementation

2022-04-02 Thread guoren
From: Guo Ren Implement compat_setup_rt_frame for sigcontext save & restore. The main process is the same with signal, but the rv32 pt_regs' size is different from rv64's, so we needs convert them. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V10 17/20] riscv: compat: vdso: Add setup additional pages implementation

2022-04-02 Thread guoren
From: Guo Ren Reconstruct __setup_additional_pages() by appending vdso info pointer argument to meet compat_vdso_info requirement. And change vm_special_mapping *dm, *cm initialization into static. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V10 16/20] riscv: compat: vdso: Add COMPAT_VDSO base code implementation

2022-04-02 Thread guoren
From: Guo Ren There is no vgettimeofday supported in rv32 that makes simple to generate rv32 vdso code which only needs riscv64 compiler. Other architectures need change compiler or -m (machine parameter) to support vdso32 compiling. If rv32 support vgettimeofday (which cause C compile) in

[PATCH V10 15/20] riscv: compat: Add hw capability check for elf

2022-04-02 Thread guoren
From: Guo Ren Detect hardware COMPAT (32bit U-mode) capability in rv64. If not support COMPAT mode in hw, compat_elf_check_arch would return false by compat_binfmt_elf.c Add CLASS to enhance (compat_)elf_check_arch to distinguish 32BIT/64BIT elf. Signed-off-by: Guo Ren Signed-off-by: Guo Ren

[PATCH V10 14/20] riscv: compat: Add elf.h implementation

2022-04-02 Thread guoren
From: Guo Ren Implement necessary type and macro for compat elf. See the code comment for detail. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner --- arch/riscv/include/asm/elf.h | 41 +++- 1 file changed,

[PATCH V10 13/20] riscv: compat: process: Add UXL_32 support in start_thread

2022-04-02 Thread guoren
From: Guo Ren If the current task is in COMPAT mode, set SR_UXL_32 in status for returning userspace. We need CONFIG _COMPAT to prevent compiling errors with rv32 defconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc: Palmer Dabbelt ---

[PATCH V10 12/20] riscv: compat: syscall: Add entry.S implementation

2022-04-02 Thread guoren
From: Guo Ren Implement the entry of compat_sys_call_table[] in asm. Ref to riscv-privileged spec 4.1.1 Supervisor Status Register (sstatus): BIT[32:33] = UXL[1:0]: - 1:32 - 2:64 - 3:128 Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko Stuebner

[PATCH V10 11/20] riscv: compat: syscall: Add compat_sys_call_table implementation

2022-04-02 Thread guoren
From: Guo Ren Implement compat sys_call_table and some system call functions: truncate64, ftruncate64, fallocate, pread64, pwrite64, sync_file_range, readahead, fadvise64_64 which need argument translation. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by:

[PATCH V10 10/20] riscv: compat: Support TASK_SIZE for compat mode

2022-04-02 Thread guoren
From: Guo Ren 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

[PATCH V10 09/20] riscv: compat: Add basic compat data type implementation

2022-04-02 Thread guoren
From: Guo Ren Implement riscv asm/compat.h for struct compat_xxx, is_compat_task, compat_user_regset, regset convert. The rv64 compat.h has inherited most of the structs from the generic one. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc:

[PATCH V10 08/20] riscv: Fixup difference with defconfig

2022-04-02 Thread guoren
From: Guo Ren Let's follow the origin patch's spirit: The only difference between rv32_defconfig and defconfig is that rv32_defconfig has CONFIG_ARCH_RV32I=y. This is helpful to compare rv64-compat-rv32 v.s. rv32-linux. Fixes: 1b937e8faa87ccfb ("RISC-V: Add separate defconfig for 32bit

[PATCH V10 07/20] syscalls: compat: Fix the missing part for __SYSCALL_COMPAT

2022-04-02 Thread guoren
From: Guo Ren Make "uapi asm unistd.h" could be used for architectures' COMPAT mode. The __SYSCALL_COMPAT is first used in riscv. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner ---

[PATCH V10 06/20] asm-generic: compat: Cleanup duplicate definitions

2022-04-02 Thread guoren
From: Guo Ren There are 7 64bit architectures that support Linux COMPAT mode to run 32bit applications. A lot of definitions are duplicate: - COMPAT_USER_HZ - COMPAT_RLIM_INFINITY - COMPAT_OFF_T_MAX - __compat_uid_t, __compat_uid_t - compat_dev_t - compat_ipc_pid_t - struct compat_flock

[PATCH V10 05/20] fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT

2022-04-02 Thread guoren
From: Guo Ren RISC-V doesn't neeed compat_stat, so using __ARCH_WANT_COMPAT_STAT to exclude unnecessary SYSCALL functions. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Cc: Palmer Dabbelt ---

[PATCH V10 04/20] kconfig: Add SYSVIPC_COMPAT for all architectures

2022-04-02 Thread guoren
From: Guo Ren The existing per-arch definitions are pretty much historic cruft. Move SYSVIPC_COMPAT into init/Kconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Acked-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Cc: Palmer Dabbelt --- arch/arm64/Kconfig

[PATCH V10 03/20] compat: consolidate the compat_flock{, 64} definition

2022-04-02 Thread guoren
From: Christoph Hellwig Provide a single common definition for the compat_flock and compat_flock64 structures using the same tricks as for the native variants. Another extra define is added for the packing required on x86. Signed-off-by: Christoph Hellwig Signed-off-by: Guo Ren Reviewed-by:

[PATCH V10 02/20] uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h

2022-04-02 Thread guoren
From: Christoph Hellwig The F_GETLK64/F_SETLK64/F_SETLKW64 fcntl opcodes are only implemented for the 32-bit syscall APIs, but are also needed for compat handling on 64-bit kernels. Consolidate them in unistd.h instead of definining the internal compat definitions in compat.h, which is rather

[PATCH V10 01/20] uapi: simplify __ARCH_FLOCK{,64}_PAD a little

2022-04-02 Thread guoren
From: Christoph Hellwig Don't bother to define the symbols empty, just don't use them. That makes the intent a little more clear. Remove the unused HAVE_ARCH_STRUCT_FLOCK64 define and merge the 32-bit mips struct flock into the generic one. Add a new __ARCH_FLOCK_EXTRA_SYSID macro following

[PATCH V10 00/20] riscv: Add COMPAT mode support for rv64

2022-04-02 Thread guoren
o-blk-device,drive=hd0 -append "rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi" -netdev user,id=net0 -device virtio-net-device,netdev=net0 QEMU emulator version 6.2.50 (v6.2.0-29-g196d7182c8) OpenSBI v0.9 [ 0.000000] Linux version 5.16.0-rc6-00017-g750f87086bdd-dirty (guoren@

[PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

2022-03-22 Thread guoren
From: Guo Ren Adds initial skeletal COMPAT Kbuild (Running 32bit U-mode on 64bit S-mode) support. - Setup kconfig & dummy functions for compiling. - Implement compat_start_thread by the way. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner

[PATCH V9 19/20] riscv: compat: ptrace: Add compat_arch_ptrace implement

2022-03-22 Thread guoren
From: Guo Ren Now, you can use native gdb on riscv64 for rv32 app debugging. $ uname -a Linux buildroot 5.16.0-rc4-00036-gbef6b82fdf23-dirty #53 SMP Mon Dec 20 23:06:53 CST 2021 riscv64 GNU/Linux $ cat /proc/cpuinfo processor : 0 hart: 0 isa : rv64imafdcsuh mmu

[PATCH V9 18/20] riscv: compat: signal: Add rt_frame implementation

2022-03-22 Thread guoren
From: Guo Ren Implement compat_setup_rt_frame for sigcontext save & restore. The main process is the same with signal, but the rv32 pt_regs' size is different from rv64's, so we needs convert them. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V9 17/20] riscv: compat: vdso: Add setup additional pages implementation

2022-03-22 Thread guoren
From: Guo Ren Reconstruct __setup_additional_pages() by appending vdso info pointer argument to meet compat_vdso_info requirement. And change vm_special_mapping *dm, *cm initialization into static. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V9 16/20] riscv: compat: vdso: Add COMPAT_VDSO base code implementation

2022-03-22 Thread guoren
From: Guo Ren There is no vgettimeofday supported in rv32 that makes simple to generate rv32 vdso code which only needs riscv64 compiler. Other architectures need change compiler or -m (machine parameter) to support vdso32 compiling. If rv32 support vgettimeofday (which cause C compile) in

[PATCH V9 15/20] riscv: compat: Add hw capability check for elf

2022-03-22 Thread guoren
From: Guo Ren Detect hardware COMPAT (32bit U-mode) capability in rv64. If not support COMPAT mode in hw, compat_elf_check_arch would return false by compat_binfmt_elf.c Add CLASS to enhance (compat_)elf_check_arch to distinguish 32BIT/64BIT elf. Signed-off-by: Guo Ren Signed-off-by: Guo Ren

[PATCH V9 14/20] riscv: compat: Add elf.h implementation

2022-03-22 Thread guoren
From: Guo Ren Implement necessary type and macro for compat elf. See the code comment for detail. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner --- arch/riscv/include/asm/elf.h | 41 +++- 1 file changed,

[PATCH V9 13/20] riscv: compat: process: Add UXL_32 support in start_thread

2022-03-22 Thread guoren
From: Guo Ren If the current task is in COMPAT mode, set SR_UXL_32 in status for returning userspace. We need CONFIG _COMPAT to prevent compiling errors with rv32 defconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc: Palmer Dabbelt ---

[PATCH V9 12/20] riscv: compat: syscall: Add entry.S implementation

2022-03-22 Thread guoren
From: Guo Ren Implement the entry of compat_sys_call_table[] in asm. Ref to riscv-privileged spec 4.1.1 Supervisor Status Register (sstatus): BIT[32:33] = UXL[1:0]: - 1:32 - 2:64 - 3:128 Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko Stuebner

[PATCH V9 11/20] riscv: compat: syscall: Add compat_sys_call_table implementation

2022-03-22 Thread guoren
From: Guo Ren Implement compat sys_call_table and some system call functions: truncate64, ftruncate64, fallocate, pread64, pwrite64, sync_file_range, readahead, fadvise64_64 which need argument translation. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by:

[PATCH V9 10/20] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT

2022-03-22 Thread guoren
From: Guo Ren 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

[PATCH V9 09/20] riscv: compat: Add basic compat data type implementation

2022-03-22 Thread guoren
From: Guo Ren Implement riscv asm/compat.h for struct compat_xxx, is_compat_task, compat_user_regset, regset convert. The rv64 compat.h has inherited most of the structs from the generic one. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc:

[PATCH V9 08/20] riscv: Fixup difference with defconfig

2022-03-22 Thread guoren
From: Guo Ren Let's follow the origin patch's spirit: The only difference between rv32_defconfig and defconfig is that rv32_defconfig has CONFIG_ARCH_RV32I=y. This is helpful to compare rv64-compat-rv32 v.s. rv32-linux. Fixes: 1b937e8faa87ccfb ("RISC-V: Add separate defconfig for 32bit

[PATCH V9 07/20] syscalls: compat: Fix the missing part for __SYSCALL_COMPAT

2022-03-22 Thread guoren
From: Guo Ren Make "uapi asm unistd.h" could be used for architectures' COMPAT mode. The __SYSCALL_COMPAT is first used in riscv. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner ---

[PATCH V9 06/20] asm-generic: compat: Cleanup duplicate definitions

2022-03-22 Thread guoren
From: Guo Ren There are 7 64bit architectures that support Linux COMPAT mode to run 32bit applications. A lot of definitions are duplicate: - COMPAT_USER_HZ - COMPAT_RLIM_INFINITY - COMPAT_OFF_T_MAX - __compat_uid_t, __compat_uid_t - compat_dev_t - compat_ipc_pid_t - struct compat_flock

[PATCH V9 05/20] fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT

2022-03-22 Thread guoren
From: Guo Ren RISC-V doesn't neeed compat_stat, so using __ARCH_WANT_COMPAT_STAT to exclude unnecessary SYSCALL functions. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Cc: Palmer Dabbelt ---

[PATCH V9 04/20] kconfig: Add SYSVIPC_COMPAT for all architectures

2022-03-22 Thread guoren
From: Guo Ren The existing per-arch definitions are pretty much historic cruft. Move SYSVIPC_COMPAT into init/Kconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Acked-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Cc: Palmer Dabbelt --- arch/arm64/Kconfig

[PATCH V9 03/20] compat: consolidate the compat_flock{, 64} definition

2022-03-22 Thread guoren
From: Christoph Hellwig Provide a single common definition for the compat_flock and compat_flock64 structures using the same tricks as for the native variants. Another extra define is added for the packing required on x86. Signed-off-by: Christoph Hellwig Signed-off-by: Guo Ren Reviewed-by:

[PATCH V9 02/20] uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h

2022-03-22 Thread guoren
From: Christoph Hellwig The F_GETLK64/F_SETLK64/F_SETLKW64 fcntl opcodes are only implemented for the 32-bit syscall APIs, but are also needed for compat handling on 64-bit kernels. Consolidate them in unistd.h instead of definining the internal compat definitions in compat.h, which is rather

[PATCH V9 01/20] uapi: simplify __ARCH_FLOCK{,64}_PAD a little

2022-03-22 Thread guoren
From: Christoph Hellwig Don't bother to define the symbols empty, just don't use them. That makes the intent a little more clear. Remove the unused HAVE_ARCH_STRUCT_FLOCK64 define and merge the 32-bit mips struct flock into the generic one. Add a new __ARCH_FLOCK_EXTRA_SYSID macro following

[PATCH V9 00/20] riscv: compat: Add COMPAT Kbuild skeletal support

2022-03-22 Thread guoren
o-blk-device,drive=hd0 -append "rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi" -netdev user,id=net0 -device virtio-net-device,netdev=net0 QEMU emulator version 6.2.50 (v6.2.0-29-g196d7182c8) OpenSBI v0.9 [ 0.000000] Linux version 5.16.0-rc6-00017-g750f87086bdd-dirty (guoren@guo

[PATCH V8 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

2022-03-16 Thread guoren
From: Guo Ren Adds initial skeletal COMPAT Kbuild (Running 32bit U-mode on 64bit S-mode) support. - Setup kconfig & dummy functions for compiling. - Implement compat_start_thread by the way. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner

[PATCH V8 19/20] riscv: compat: ptrace: Add compat_arch_ptrace implement

2022-03-16 Thread guoren
From: Guo Ren Now, you can use native gdb on riscv64 for rv32 app debugging. $ uname -a Linux buildroot 5.16.0-rc4-00036-gbef6b82fdf23-dirty #53 SMP Mon Dec 20 23:06:53 CST 2021 riscv64 GNU/Linux $ cat /proc/cpuinfo processor : 0 hart: 0 isa : rv64imafdcsuh mmu

[PATCH V8 18/20] riscv: compat: signal: Add rt_frame implementation

2022-03-16 Thread guoren
From: Guo Ren Implement compat_setup_rt_frame for sigcontext save & restore. The main process is the same with signal, but the rv32 pt_regs' size is different from rv64's, so we needs convert them. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V8 17/20] riscv: compat: vdso: Add setup additional pages implementation

2022-03-16 Thread guoren
From: Guo Ren Reconstruct __setup_additional_pages() by appending vdso info pointer argument to meet compat_vdso_info requirement. And change vm_special_mapping *dm, *cm initialization into static. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko

[PATCH V8 16/20] riscv: compat: vdso: Add COMPAT_VDSO base code implementation

2022-03-16 Thread guoren
From: Guo Ren There is no vgettimeofday supported in rv32 that makes simple to generate rv32 vdso code which only needs riscv64 compiler. Other architectures need change compiler or -m (machine parameter) to support vdso32 compiling. If rv32 support vgettimeofday (which cause C compile) in

[PATCH V8 15/20] riscv: compat: Add hw capability check for elf

2022-03-16 Thread guoren
From: Guo Ren Detect hardware COMPAT (32bit U-mode) capability in rv64. If not support COMPAT mode in hw, compat_elf_check_arch would return false by compat_binfmt_elf.c Add CLASS to enhance (compat_)elf_check_arch to distinguish 32BIT/64BIT elf. Signed-off-by: Guo Ren Signed-off-by: Guo Ren

[PATCH V8 14/20] riscv: compat: Add elf.h implementation

2022-03-16 Thread guoren
From: Guo Ren Implement necessary type and macro for compat elf. See the code comment for detail. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner --- arch/riscv/include/asm/elf.h | 41 +++- 1 file changed,

[PATCH V8 13/20] riscv: compat: process: Add UXL_32 support in start_thread

2022-03-16 Thread guoren
From: Guo Ren If the current task is in COMPAT mode, set SR_UXL_32 in status for returning userspace. We need CONFIG _COMPAT to prevent compiling errors with rv32 defconfig. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc: Palmer Dabbelt ---

[PATCH V8 12/20] riscv: compat: syscall: Add entry.S implementation

2022-03-16 Thread guoren
From: Guo Ren Implement the entry of compat_sys_call_table[] in asm. Ref to riscv-privileged spec 4.1.1 Supervisor Status Register (sstatus): BIT[32:33] = UXL[1:0]: - 1:32 - 2:64 - 3:128 Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Tested-by: Heiko Stuebner

[PATCH V8 11/20] riscv: compat: syscall: Add compat_sys_call_table implementation

2022-03-16 Thread guoren
From: Guo Ren Implement compat sys_call_table and some system call functions: truncate64, ftruncate64, fallocate, pread64, pwrite64, sync_file_range, readahead, fadvise64_64 which need argument translation. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by:

[PATCH V8 10/20] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT

2022-03-16 Thread guoren
From: Guo Ren 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

[PATCH V8 09/20] riscv: compat: Add basic compat data type implementation

2022-03-16 Thread guoren
From: Guo Ren Implement riscv asm/compat.h for struct compat_xxx, is_compat_task, compat_user_regset, regset convert. The rv64 compat.h has inherited most of the structs from the generic one. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Tested-by: Heiko Stuebner Cc: Arnd Bergmann Cc:

[PATCH V8 08/20] riscv: Fixup difference with defconfig

2022-03-16 Thread guoren
From: Guo Ren Let's follow the origin patch's spirit: The only difference between rv32_defconfig and defconfig is that rv32_defconfig has CONFIG_ARCH_RV32I=y. This is helpful to compare rv64-compat-rv32 v.s. rv32-linux. Fixes: 1b937e8faa87ccfb ("RISC-V: Add separate defconfig for 32bit

[PATCH V8 07/20] syscalls: compat: Fix the missing part for __SYSCALL_COMPAT

2022-03-16 Thread guoren
From: Guo Ren Make "uapi asm unistd.h" could be used for architectures' COMPAT mode. The __SYSCALL_COMPAT is first used in riscv. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner ---

[PATCH V8 06/20] asm-generic: compat: Cleanup duplicate definitions

2022-03-16 Thread guoren
From: Guo Ren There are 7 64bit architectures that support Linux COMPAT mode to run 32bit applications. A lot of definitions are duplicate: - COMPAT_USER_HZ - COMPAT_RLIM_INFINITY - COMPAT_OFF_T_MAX - __compat_uid_t, __compat_uid_t - compat_dev_t - compat_ipc_pid_t - struct compat_flock

[PATCH V8 05/20] fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT

2022-03-16 Thread guoren
From: Guo Ren RISC-V doesn't neeed compat_stat, so using __ARCH_WANT_COMPAT_STAT to exclude unnecessary SYSCALL functions. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Reviewed-by: Christoph Hellwig Tested-by: Heiko Stuebner Cc: Palmer Dabbelt ---

  1   2   3   >