From: Guo Ren <[email protected]>
Currently, most 64-bit architectures (x86, parisc, powerpc, arm64,
s390, mips, sparc) have supported COMPAT mode. But they all have
history issues and can't use standard linux unistd.h. RISC-V would
be first standard __SYSCALL_COMPAT user of include/uapi/asm-generic
/unistd.h.
The patchset are based on v5.18-rc1, you can compare rv64-compat
v.s. rv32-native in qemu with following steps:
- Prepare rv32 rootfs & fw_jump.bin by buildroot.org
$ git clone git://git.busybox.net/buildroot
$ cd buildroot
$ make qemu_riscv32_virt_defconfig O=qemu_riscv32_virt_defconfig
$ make -C qemu_riscv32_virt_defconfig
$ make qemu_riscv64_virt_defconfig O=qemu_riscv64_virt_defconfig
$ make -C qemu_riscv64_virt_defconfig
(Got fw_jump.bin & rootfs.ext2 in qemu_riscvXX_virt_defconfig/images)
- Prepare Linux rv32 & rv64 Image
$ git clone [email protected]:c-sky/csky-linux.git -b riscv_compat_v12 linux
$ cd linux
$ echo "CONFIG_STRICT_KERNEL_RWX=n" >> arch/riscv/configs/defconfig
$ echo "CONFIG_STRICT_MODULE_RWX=n" >> arch/riscv/configs/defconfig
$ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ rv32_defconfig
$ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ Image
$ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ defconfig
$ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ Image
- Prepare Qemu:
$ git clone https://gitlab.com/qemu-project/qemu.git -b master linux
$ cd qemu
$ ./configure --target-list="riscv64-softmmu riscv32-softmmu"
$ make
Now let's compare rv64-compat with rv32-native memory footprint with almost the same
defconfig, rootfs, opensbi in one qemu.
- Run rv64 with rv32 rootfs in compat mode:
$ ./build/qemu-system-riscv64 -cpu rv64 -M virt -m 64m -nographic -bios qemu_riscv64_virt_defconfig/images/fw_jump.bin -kernel build-rv64/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv64-unknown-linux-gnu-gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.37) #96 SMP Tue Dec 28 21:01:55 CST 2021
[ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
[ 0.000000] Machine model: riscv-virtio,qemu
[ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
[ 0.000000] printk: bootconsole [sbi0] enabled
[ 0.000000] efi: UEFI not found.
[ 0.000000] Zone ranges:
[ 0.000000] DMA32 [mem 0x0000000080200000-0x0000000083ffffff]
[ 0.000000] Normal empty
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000080200000-0x0000000083ffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x0000000083ffffff]
[ 0.000000] SBI specification v0.2 detected
[ 0.000000] SBI implementation ID=0x1 Version=0x9
[ 0.000000] SBI TIME extension detected
[ 0.000000] SBI IPI extension detected
[ 0.000000] SBI RFENCE extension detected
[ 0.000000] SBI v0.2 HSM extension detected
[ 0.000000] riscv: ISA extensions acdfhimsu
[ 0.000000] riscv: ELF capabilities acdfim
[ 0.000000] percpu: Embedded 17 pages/cpu s30696 r8192 d30744 u69632
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15655
[ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
[ 0.000000] Dentry cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 4096 (order: 3, 32768 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Virtual kernel memory layout:
[ 0.000000] fixmap : 0xffffffcefee00000 - 0xffffffceff000000 (2048 kB)
[ 0.000000] pci io : 0xffffffceff000000 - 0xffffffcf00000000 ( 16 MB)
[ 0.000000] vmemmap : 0xffffffcf00000000 - 0xffffffcfffffffff (4095 MB)
[ 0.000000] vmalloc : 0xffffffd000000000 - 0xffffffdfffffffff (65535 MB)
[ 0.000000] lowmem : 0xffffffe000000000 - 0xffffffe003e00000 ( 62 MB)
[ 0.000000] kernel : 0xffffffff80000000 - 0xffffffffffffffff (2047 MB)
[ 0.000000] Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved, 0K cma-reserved)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
[ 0.000000] rcu: RCU debug extended QS entry/exit.
[ 0.000000] Tracing variant of Tasks RCU enabled.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[ 0.000000] riscv-intc: 64 local interrupts mapped
[ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
...
Welcome to Buildroot
buildroot login: root
# cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv64imafdcsuh
mmu : sv48
# file /bin/busybox
/bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
# ca[ 78.386630] random: fast init done
# cat /proc/meminfo
MemTotal: 53076 kB
MemFree: 40264 kB
MemAvailable: 40244 kB
Buffers: 236 kB
Cached: 1560 kB
SwapCached: 0 kB
Active: 1700 kB
Inactive: 516 kB
Active(anon): 40 kB
Inactive(anon): 424 kB
Active(file): 1660 kB
Inactive(file): 92 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 444 kB
Mapped: 1188 kB
Shmem: 44 kB
KReclaimable: 952 kB
Slab: 5744 kB
SReclaimable: 952 kB
SUnreclaim: 4792 kB
KernelStack: 624 kB
PageTables: 156 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 26536 kB
Committed_AS: 1748 kB
VmallocTotal: 67108863 kB
VmallocUsed: 652 kB
VmallocChunk: 0 kB
Percpu: 80 kB
#
- Run rv32 with rv32 rootfs:
$ ./build/qemu-system-riscv32 -cpu rv32 -M virt -m 64m -nographic -bios qemu_riscv32_virt_defconfig/images/fw_jump.bin -kernel build-rv32/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.11-201-g7600ca7960-dirty) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #7 SMP Tue Dec 28 21:02:21 CST 2021
[ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80400000
[ 0.000000] Machine model: riscv-virtio,qemu
[ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
[ 0.000000] printk: bootconsole [sbi0] enabled
[ 0.000000] efi: UEFI not found.
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x0000000080400000-0x0000000083ffffff]
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000080400000-0x0000000083ffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000080400000-0x0000000083ffffff]
[ 0.000000] SBI specification v0.2 detected
[ 0.000000] SBI implementation ID=0x1 Version=0x9
[ 0.000000] SBI TIME extension detected
[ 0.000000] SBI IPI extension detected
[ 0.000000] SBI RFENCE extension detected
[ 0.000000] SBI v0.2 HSM extension detected
[ 0.000000] riscv: ISA extensions acdfhimsu
[ 0.000000] riscv: ELF capabilities acdfim
[ 0.000000] percpu: Embedded 12 pages/cpu s16600 r8192 d24360 u49152
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15240
[ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
[ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Virtual kernel memory layout:
[ 0.000000] fixmap : 0x9dc00000 - 0x9e000000 (4096 kB)
[ 0.000000] pci io : 0x9e000000 - 0x9f000000 ( 16 MB)
[ 0.000000] vmemmap : 0x9f000000 - 0x9fffffff ( 15 MB)
[ 0.000000] vmalloc : 0xa0000000 - 0xbfffffff ( 511 MB)
[ 0.000000] lowmem : 0xc0000000 - 0xc3c00000 ( 60 MB)
[ 0.000000] Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved, 0K cma-reserved)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
[ 0.000000] rcu: RCU debug extended QS entry/exit.
[ 0.000000] Tracing variant of Tasks RCU enabled.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[ 0.000000] riscv-intc: 32 local interrupts mapped
[ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
...
Welcome to Buildroot
buildroot login: root
# cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv32imafdcsuh
mmu : sv32
# file /bin/busybox
/bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
[ 79.320589] random: fast init done
# cat /proc/meminfo
MemTotal: 52176 kB
MemFree: 41012 kB
MemAvailable: 42176 kB
Buffers: 644 kB
Cached: 2724 kB
SwapCached: 0 kB
Active: 3128 kB
Inactive: 752 kB
Active(anon): 40 kB
Inactive(anon): 516 kB
Active(file): 3088 kB
Inactive(file): 236 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 4 kB
Writeback: 0 kB
AnonPages: 556 kB
Mapped: 2172 kB
Shmem: 44 kB
KReclaimable: 656 kB
Slab: 3684 kB
SReclaimable: 656 kB
SUnreclaim: 3028 kB
KernelStack: 312 kB
PageTables: 88 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 26088 kB
Committed_AS: 2088 kB
VmallocTotal: 524287 kB
VmallocUsed: 12 kB
VmallocChunk: 0 kB
Percpu: 60 kB
#
Some conclusions:
- kernel statics:
64: Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved)
32: Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved)
rv32 better than rv64: 1% 22% 17% 13% 19% 11%
The code size is very similar, but data size rv32 would be better.
- rv32 kernel runtime KernelStack, Slab... are smaller,
rv64: MemTotal: 53076 kB, MemFree: 40264 kB
rv32: MemTotal: 52176 + 2048 kB, MemFree: 41012 + 2048 kB
rv32 better than rv64: 2% 6%
(Because opensbi problem, we could add another 2MB for rv32.)
Overall in 64MB memory situation, rv64-compat is 6% worse than rv32-native
at memory footprint. If the userspace memory usage increases, I think
the gap will be further reduced.
Changes in v12:
- Rebase on 5.18-rc1
- Fixup compile conflicts with 5.18-rc1
- Fixup $(srctree) == $(objtree) compile error reported by Nathan
Changes in v11:
- Using arch instead of kconfig for commit subject by Masahiro Yamada
Changes in v10:
- Fixup arm64 compile error with compat_statfs definition
- Fixup compat_sys_fadvise64_64 function arguments error cause ltp failure
Changes in v9:
- Fixup rv32 call rv64 segment fault
- Ready for 5.18
Changes in v8:
- Enhanced elf_check_arch with EI_CLASS
- Fixup SR_UXL doesn't exist in CONFIG_32BIT
- Add Tested-by with Heiko
- Update qemu compile tips with upstream repo
Changes in v7:
- Re-construct compat_vdso/Makefile
- Fixup disable COMPAT compile error by csr.h's macro.
- Optimize coding convention for lo/hi in compat.h
Changes in v6:
- Rebase on linux-5.17-rc5
- Optimize hw capability check for elf
- Optimize comment in thread_info.h
- Optimize start_thread with SR_UXL setting
- Optimize vdso.c with direct panic
Changes in v5:
- Rebase on linux-5.17-rc2
- Include consolidate the fcntl patches by Christoph Hellwig
- Remove F_GETLK64/F_SETLK64/F_SETLKW64 from asm/compat.h
- Change COMPAT_RLIM_INFINITY from 0x7fffffff to 0xffffffff
- Bring back "Add hw-cap detect in setup_arch patch" in v1
Changes in v4:
- Rebase on linux-5.17-rc1
- Optimize compat_sys_call_table implementation with Arnd's advice
- Add reviewed-by for Arnd. Thx :)
- Remove FIXME comment in elf.h
- Optimize Cleanup duplicate definitions in compat.h with Arnd's advice
Changes in v3:
- Rebase on newest master (pre linux-5.17-rc1)
- Using newest qemu version v7 for test
- Remove fcntl common modification
- Fixup SET_PERSONALITY in elf.h by Arnd
- Fixup KVM Kconfig
- Update Acked-by & Reviewed-by
Changes in v2:
- Add __ARCH_WANT_COMPAT_STAT suggested
- Cleanup fcntl compatduplicate definitions
- Cleanup compat.h
- Move rv32_defconfig into Makefile
- Fixup rv64 rootfs boot failed, remove hw_compat_mode_detect
- Move SYSVIPC_COMPAT into init/Kconfig
- Simplify compat_elf_check
Christoph Hellwig (3):
uapi: simplify __ARCH_FLOCK{,64}_PAD a little
uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
compat: consolidate the compat_flock{,64} definition
Guo Ren (17):
arch: Add SYSVIPC_COMPAT for all architectures
fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT
asm-generic: compat: Cleanup duplicate definitions
syscalls: compat: Fix the missing part for __SYSCALL_COMPAT
riscv: Fixup difference with defconfig
riscv: compat: Add basic compat data type implementation
riscv: compat: Support TASK_SIZE for compat mode
riscv: compat: syscall: Add compat_sys_call_table implementation
riscv: compat: syscall: Add entry.S implementation
riscv: compat: process: Add UXL_32 support in start_thread
riscv: compat: Add elf.h implementation
riscv: compat: Add hw capability check for elf
riscv: compat: vdso: Add COMPAT_VDSO base code implementation
riscv: compat: vdso: Add setup additional pages implementation
riscv: compat: signal: Add rt_frame implementation
riscv: compat: ptrace: Add compat_arch_ptrace implement
riscv: compat: Add COMPAT Kbuild skeletal support
arch/arm64/Kconfig | 4 -
arch/arm64/include/asm/compat.h | 93 +------
arch/arm64/include/asm/unistd.h | 1 +
arch/mips/Kconfig | 5 -
arch/mips/include/asm/compat.h | 41 +--
arch/mips/include/asm/unistd.h | 2 +
arch/mips/include/uapi/asm/fcntl.h | 30 +--
arch/parisc/Kconfig | 4 -
arch/parisc/include/asm/compat.h | 45 +---
arch/parisc/include/asm/unistd.h | 1 +
arch/powerpc/Kconfig | 5 -
arch/powerpc/include/asm/compat.h | 50 +---
arch/powerpc/include/asm/unistd.h | 1 +
arch/riscv/Kconfig | 19 ++
arch/riscv/Makefile | 9 +
arch/riscv/include/asm/compat.h | 129 ++++++++++
arch/riscv/include/asm/csr.h | 7 +
arch/riscv/include/asm/elf.h | 50 +++-
arch/riscv/include/asm/mmu.h | 1 +
arch/riscv/include/asm/pgtable.h | 13 +-
arch/riscv/include/asm/processor.h | 6 +-
arch/riscv/include/asm/syscall.h | 1 +
arch/riscv/include/asm/thread_info.h | 1 +
arch/riscv/include/asm/unistd.h | 11 +
arch/riscv/include/asm/vdso.h | 9 +
arch/riscv/include/uapi/asm/unistd.h | 2 +-
arch/riscv/kernel/Makefile | 3 +
arch/riscv/kernel/compat_signal.c | 242 ++++++++++++++++++
arch/riscv/kernel/compat_syscall_table.c | 19 ++
arch/riscv/kernel/compat_vdso/.gitignore | 2 +
arch/riscv/kernel/compat_vdso/Makefile | 78 ++++++
arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +
.../kernel/compat_vdso/compat_vdso.lds.S | 3 +
arch/riscv/kernel/compat_vdso/flush_icache.S | 3 +
.../compat_vdso/gen_compat_vdso_offsets.sh | 5 +
arch/riscv/kernel/compat_vdso/getcpu.S | 3 +
arch/riscv/kernel/compat_vdso/note.S | 3 +
arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 +
arch/riscv/kernel/entry.S | 18 +-
arch/riscv/kernel/process.c | 37 +++
arch/riscv/kernel/ptrace.c | 87 ++++++-
arch/riscv/kernel/signal.c | 13 +-
arch/riscv/kernel/sys_riscv.c | 6 +-
arch/riscv/kernel/vdso.c | 105 +++++---
arch/riscv/kernel/vdso/vdso.S | 6 +-
arch/s390/Kconfig | 3 -
arch/s390/include/asm/compat.h | 99 +------
arch/s390/include/asm/unistd.h | 1 +
arch/sparc/Kconfig | 5 -
arch/sparc/include/asm/compat.h | 61 ++---
arch/sparc/include/asm/unistd.h | 1 +
arch/x86/Kconfig | 4 -
arch/x86/include/asm/compat.h | 104 ++------
arch/x86/include/asm/unistd.h | 1 +
fs/open.c | 24 ++
fs/read_write.c | 16 ++
fs/stat.c | 2 +-
fs/sync.c | 9 +
include/asm-generic/compat.h | 113 ++++++++
include/linux/compat.h | 68 +++++
include/uapi/asm-generic/fcntl.h | 23 +-
include/uapi/asm-generic/unistd.h | 4 +-
init/Kconfig | 4 +
mm/fadvise.c | 11 +
mm/readahead.c | 7 +
tools/include/uapi/asm-generic/fcntl.h | 21 +-
tools/include/uapi/asm-generic/unistd.h | 4 +-
67 files changed, 1206 insertions(+), 563 deletions(-)
create mode 100644 arch/riscv/include/asm/compat.h
create mode 100644 arch/riscv/kernel/compat_signal.c
create mode 100644 arch/riscv/kernel/compat_syscall_table.c
create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore
create mode 100644 arch/riscv/kernel/compat_vdso/Makefile
create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S
create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S
create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S
create mode 100644 arch/riscv/kernel/compat_vdso/note.S
create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S
--
2.25.1
From: Guo Ren <[email protected]>
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 <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Arnd Bergmann <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
---
arch/riscv/Kconfig | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 00fd9c548f26..def9798e9675 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -76,6 +76,7 @@ config RISCV
select HAVE_ARCH_KGDB if !XIP_KERNEL
select HAVE_ARCH_KGDB_QXFER_PKT
select HAVE_ARCH_MMAP_RND_BITS if MMU
+ select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_TRACEHOOK
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if 64BIT && MMU
@@ -127,12 +128,18 @@ config ARCH_MMAP_RND_BITS_MIN
default 18 if 64BIT
default 8
+config ARCH_MMAP_RND_COMPAT_BITS_MIN
+ default 8
+
# max bits determined by the following formula:
# VA_BITS - PAGE_SHIFT - 3
config ARCH_MMAP_RND_BITS_MAX
default 24 if 64BIT # SV39 based
default 17
+config ARCH_MMAP_RND_COMPAT_BITS_MAX
+ default 17
+
# set if we run in machine mode, cleared if we run in supervisor mode
config RISCV_M_MODE
bool
@@ -394,6 +401,18 @@ config CRASH_DUMP
For more details see Documentation/admin-guide/kdump/kdump.rst
+config COMPAT
+ bool "Kernel support for 32-bit U-mode"
+ default 64BIT
+ depends on 64BIT && MMU
+ help
+ This option enables support for a 32-bit U-mode running under a 64-bit
+ kernel at S-mode. riscv32-specific components such as system calls,
+ the user helper functions (vdso), signal rt_frame functions and the
+ ptrace interface are handled appropriately by the kernel.
+
+ If you want to execute 32-bit userspace applications, say Y.
+
endmenu
menu "Boot options"
--
2.25.1
From: Guo Ren <[email protected]>
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 <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Arnd Bergmann <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
---
include/uapi/asm-generic/unistd.h | 4 ++--
tools/include/uapi/asm-generic/unistd.h | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
index 1c48b0ae3ba3..45fa180cc56a 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -383,7 +383,7 @@ __SYSCALL(__NR_syslog, sys_syslog)
/* kernel/ptrace.c */
#define __NR_ptrace 117
-__SYSCALL(__NR_ptrace, sys_ptrace)
+__SC_COMP(__NR_ptrace, sys_ptrace, compat_sys_ptrace)
/* kernel/sched/core.c */
#define __NR_sched_setparam 118
@@ -779,7 +779,7 @@ __SYSCALL(__NR_rseq, sys_rseq)
#define __NR_kexec_file_load 294
__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load)
/* 295 through 402 are unassigned to sync up with generic numbers, don't use */
-#if __BITS_PER_LONG == 32
+#if defined(__SYSCALL_COMPAT) || __BITS_PER_LONG == 32
#define __NR_clock_gettime64 403
__SYSCALL(__NR_clock_gettime64, sys_clock_gettime)
#define __NR_clock_settime64 404
diff --git a/tools/include/uapi/asm-generic/unistd.h b/tools/include/uapi/asm-generic/unistd.h
index 1c48b0ae3ba3..45fa180cc56a 100644
--- a/tools/include/uapi/asm-generic/unistd.h
+++ b/tools/include/uapi/asm-generic/unistd.h
@@ -383,7 +383,7 @@ __SYSCALL(__NR_syslog, sys_syslog)
/* kernel/ptrace.c */
#define __NR_ptrace 117
-__SYSCALL(__NR_ptrace, sys_ptrace)
+__SC_COMP(__NR_ptrace, sys_ptrace, compat_sys_ptrace)
/* kernel/sched/core.c */
#define __NR_sched_setparam 118
@@ -779,7 +779,7 @@ __SYSCALL(__NR_rseq, sys_rseq)
#define __NR_kexec_file_load 294
__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load)
/* 295 through 402 are unassigned to sync up with generic numbers, don't use */
-#if __BITS_PER_LONG == 32
+#if defined(__SYSCALL_COMPAT) || __BITS_PER_LONG == 32
#define __NR_clock_gettime64 403
__SYSCALL(__NR_clock_gettime64, sys_clock_gettime)
#define __NR_clock_settime64 404
--
2.25.1
From: Guo Ren <[email protected]>
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
- struct compat_flock64
- struct compat_statfs
- struct compat_ipc64_perm, compat_semid64_ds,
compat_msqid64_ds, compat_shmid64_ds
Cleanup duplicate definitions and merge them into asm-generic.
Signed-off-by: Guo Ren <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Arnd Bergmann <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
Acked-by: Helge Deller <[email protected]> # parisc
Cc: Palmer Dabbelt <[email protected]>
---
arch/arm64/include/asm/compat.h | 73 +++-----------------
arch/mips/include/asm/compat.h | 18 ++---
arch/parisc/include/asm/compat.h | 29 ++------
arch/powerpc/include/asm/compat.h | 30 ++-------
arch/s390/include/asm/compat.h | 79 ++++------------------
arch/sparc/include/asm/compat.h | 39 ++++-------
arch/x86/include/asm/compat.h | 80 ++++------------------
include/asm-generic/compat.h | 106 ++++++++++++++++++++++++++++++
8 files changed, 170 insertions(+), 284 deletions(-)
diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index e0faec1984a1..9f362274a4f7 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -8,6 +8,15 @@
#define compat_mode_t compat_mode_t
typedef u16 compat_mode_t;
+#define __compat_uid_t __compat_uid_t
+typedef u16 __compat_uid_t;
+typedef u16 __compat_gid_t;
+
+#define compat_ipc_pid_t compat_ipc_pid_t
+typedef u16 compat_ipc_pid_t;
+
+#define compat_statfs compat_statfs
+
#include <asm-generic/compat.h>
#ifdef CONFIG_COMPAT
@@ -19,21 +28,15 @@ typedef u16 compat_mode_t;
#include <linux/sched.h>
#include <linux/sched/task_stack.h>
-#define COMPAT_USER_HZ 100
#ifdef __AARCH64EB__
#define COMPAT_UTS_MACHINE "armv8b\0\0"
#else
#define COMPAT_UTS_MACHINE "armv8l\0\0"
#endif
-typedef u16 __compat_uid_t;
-typedef u16 __compat_gid_t;
typedef u16 __compat_uid16_t;
typedef u16 __compat_gid16_t;
-typedef u32 compat_dev_t;
typedef s32 compat_nlink_t;
-typedef u16 compat_ipc_pid_t;
-typedef __kernel_fsid_t compat_fsid_t;
struct compat_stat {
#ifdef __AARCH64EB__
@@ -87,64 +90,6 @@ struct compat_statfs {
#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
#define COMPAT_MINSIGSTKSZ 2048
-struct compat_ipc64_perm {
- compat_key_t key;
- __compat_uid32_t uid;
- __compat_gid32_t gid;
- __compat_uid32_t cuid;
- __compat_gid32_t cgid;
- unsigned short mode;
- unsigned short __pad1;
- unsigned short seq;
- unsigned short __pad2;
- compat_ulong_t unused1;
- compat_ulong_t unused2;
-};
-
-struct compat_semid64_ds {
- struct compat_ipc64_perm sem_perm;
- compat_ulong_t sem_otime;
- compat_ulong_t sem_otime_high;
- compat_ulong_t sem_ctime;
- compat_ulong_t sem_ctime_high;
- compat_ulong_t sem_nsems;
- compat_ulong_t __unused3;
- compat_ulong_t __unused4;
-};
-
-struct compat_msqid64_ds {
- struct compat_ipc64_perm msg_perm;
- compat_ulong_t msg_stime;
- compat_ulong_t msg_stime_high;
- compat_ulong_t msg_rtime;
- compat_ulong_t msg_rtime_high;
- compat_ulong_t msg_ctime;
- compat_ulong_t msg_ctime_high;
- compat_ulong_t msg_cbytes;
- compat_ulong_t msg_qnum;
- compat_ulong_t msg_qbytes;
- compat_pid_t msg_lspid;
- compat_pid_t msg_lrpid;
- compat_ulong_t __unused4;
- compat_ulong_t __unused5;
-};
-
-struct compat_shmid64_ds {
- struct compat_ipc64_perm shm_perm;
- compat_size_t shm_segsz;
- compat_ulong_t shm_atime;
- compat_ulong_t shm_atime_high;
- compat_ulong_t shm_dtime;
- compat_ulong_t shm_dtime_high;
- compat_ulong_t shm_ctime;
- compat_ulong_t shm_ctime_high;
- compat_pid_t shm_cpid;
- compat_pid_t shm_lpid;
- compat_ulong_t shm_nattch;
- compat_ulong_t __unused4;
- compat_ulong_t __unused5;
-};
-
static inline int is_compat_task(void)
{
return test_thread_flag(TIF_32BIT);
diff --git a/arch/mips/include/asm/compat.h b/arch/mips/include/asm/compat.h
index 6d6e5a451f4d..ec01dc000a41 100644
--- a/arch/mips/include/asm/compat.h
+++ b/arch/mips/include/asm/compat.h
@@ -9,28 +9,28 @@
#include <asm/page.h>
#include <asm/ptrace.h>
+#define __compat_uid_t __compat_uid_t
typedef s32 __compat_uid_t;
typedef s32 __compat_gid_t;
+
typedef __compat_uid_t __compat_uid32_t;
typedef __compat_gid_t __compat_gid32_t;
#define __compat_uid32_t __compat_uid32_t
-#define __compat_gid32_t __compat_gid32_t
+
+#define compat_statfs compat_statfs
+#define compat_ipc64_perm compat_ipc64_perm
#define _COMPAT_NSIG 128 /* Don't ask !$@#% ... */
#define _COMPAT_NSIG_BPW 32
typedef u32 compat_sigset_word;
+#define COMPAT_RLIM_INFINITY 0x7fffffffUL
+
#include <asm-generic/compat.h>
-#define COMPAT_USER_HZ 100
#define COMPAT_UTS_MACHINE "mips\0\0\0"
-typedef u32 compat_dev_t;
typedef u32 compat_nlink_t;
-typedef s32 compat_ipc_pid_t;
-typedef struct {
- s32 val[2];
-} compat_fsid_t;
struct compat_stat {
compat_dev_t st_dev;
@@ -73,10 +73,6 @@ struct compat_statfs {
int f_spare[5];
};
-#define COMPAT_RLIM_INFINITY 0x7fffffffUL
-
-#define COMPAT_OFF_T_MAX 0x7fffffff
-
struct compat_ipc64_perm {
compat_key_t key;
__compat_uid32_t uid;
diff --git a/arch/parisc/include/asm/compat.h b/arch/parisc/include/asm/compat.h
index a1e4534d8050..339d1b833fa7 100644
--- a/arch/parisc/include/asm/compat.h
+++ b/arch/parisc/include/asm/compat.h
@@ -11,16 +11,16 @@
#define compat_mode_t compat_mode_t
typedef u16 compat_mode_t;
+#define compat_ipc_pid_t compat_ipc_pid_t
+typedef u16 compat_ipc_pid_t;
+
+#define compat_ipc64_perm compat_ipc64_perm
+
#include <asm-generic/compat.h>
-#define COMPAT_USER_HZ 100
#define COMPAT_UTS_MACHINE "parisc\0\0"
-typedef u32 __compat_uid_t;
-typedef u32 __compat_gid_t;
-typedef u32 compat_dev_t;
typedef u16 compat_nlink_t;
-typedef u16 compat_ipc_pid_t;
struct compat_stat {
compat_dev_t st_dev; /* dev_t is 32 bits on parisc */
@@ -53,21 +53,6 @@ struct compat_stat {
u32 st_spare4[3];
};
-struct compat_statfs {
- s32 f_type;
- s32 f_bsize;
- s32 f_blocks;
- s32 f_bfree;
- s32 f_bavail;
- s32 f_files;
- s32 f_ffree;
- __kernel_fsid_t f_fsid;
- s32 f_namelen;
- s32 f_frsize;
- s32 f_flags;
- s32 f_spare[4];
-};
-
struct compat_sigcontext {
compat_int_t sc_flags;
compat_int_t sc_gr[32]; /* PSW in sc_gr[0] */
@@ -77,10 +62,6 @@ struct compat_sigcontext {
compat_int_t sc_sar; /* cr11 */
};
-#define COMPAT_RLIM_INFINITY 0xffffffff
-
-#define COMPAT_OFF_T_MAX 0x7fffffff
-
struct compat_ipc64_perm {
compat_key_t key;
__compat_uid_t uid;
diff --git a/arch/powerpc/include/asm/compat.h b/arch/powerpc/include/asm/compat.h
index 5ef3c7c83c34..dda4091fd012 100644
--- a/arch/powerpc/include/asm/compat.h
+++ b/arch/powerpc/include/asm/compat.h
@@ -8,21 +8,20 @@
#include <linux/types.h>
#include <linux/sched.h>
+#define compat_ipc_pid_t compat_ipc_pid_t
+typedef u16 compat_ipc_pid_t;
+
+#define compat_ipc64_perm compat_ipc64_perm
+
#include <asm-generic/compat.h>
-#define COMPAT_USER_HZ 100
#ifdef __BIG_ENDIAN__
#define COMPAT_UTS_MACHINE "ppc\0\0"
#else
#define COMPAT_UTS_MACHINE "ppcle\0\0"
#endif
-typedef u32 __compat_uid_t;
-typedef u32 __compat_gid_t;
-typedef u32 compat_dev_t;
typedef s16 compat_nlink_t;
-typedef u16 compat_ipc_pid_t;
-typedef __kernel_fsid_t compat_fsid_t;
struct compat_stat {
compat_dev_t st_dev;
@@ -44,25 +43,6 @@ struct compat_stat {
u32 __unused4[2];
};
-struct compat_statfs {
- int f_type;
- int f_bsize;
- int f_blocks;
- int f_bfree;
- int f_bavail;
- int f_files;
- int f_ffree;
- compat_fsid_t f_fsid;
- int f_namelen; /* SunOS ignores this field. */
- int f_frsize;
- int f_flags;
- int f_spare[4];
-};
-
-#define COMPAT_RLIM_INFINITY 0xffffffff
-
-#define COMPAT_OFF_T_MAX 0x7fffffff
-
/*
* ipc64_perm is actually 32/64bit clean but since the compat layer refers to
* it we may as well define it.
diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index 07f04d37068b..ad809cf3dd97 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -12,6 +12,18 @@
#define compat_mode_t compat_mode_t
typedef u16 compat_mode_t;
+#define __compat_uid_t __compat_uid_t
+typedef u16 __compat_uid_t;
+typedef u16 __compat_gid_t;
+
+#define compat_dev_t compat_dev_t
+typedef u16 compat_dev_t;
+
+#define compat_ipc_pid_t compat_ipc_pid_t
+typedef u16 compat_ipc_pid_t;
+
+#define compat_statfs compat_statfs
+
#include <asm-generic/compat.h>
#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p( \
@@ -53,15 +65,9 @@ typedef u16 compat_mode_t;
PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | \
PSW32_ASC_PRIMARY)
-#define COMPAT_USER_HZ 100
#define COMPAT_UTS_MACHINE "s390\0\0\0\0"
-typedef u16 __compat_uid_t;
-typedef u16 __compat_gid_t;
-typedef u16 compat_dev_t;
typedef u16 compat_nlink_t;
-typedef u16 compat_ipc_pid_t;
-typedef __kernel_fsid_t compat_fsid_t;
typedef struct {
u32 mask;
@@ -132,10 +138,6 @@ struct compat_statfs64 {
u32 f_spare[4];
};
-#define COMPAT_RLIM_INFINITY 0xffffffff
-
-#define COMPAT_OFF_T_MAX 0x7fffffff
-
/*
* A pointer passed in from user mode. This should not
* be used for syscall parameters, just declare them
@@ -158,61 +160,4 @@ static inline int is_compat_task(void)
#endif
-struct compat_ipc64_perm {
- compat_key_t key;
- __compat_uid32_t uid;
- __compat_gid32_t gid;
- __compat_uid32_t cuid;
- __compat_gid32_t cgid;
- compat_mode_t mode;
- unsigned short __pad1;
- unsigned short seq;
- unsigned short __pad2;
- unsigned int __unused1;
- unsigned int __unused2;
-};
-
-struct compat_semid64_ds {
- struct compat_ipc64_perm sem_perm;
- compat_ulong_t sem_otime;
- compat_ulong_t sem_otime_high;
- compat_ulong_t sem_ctime;
- compat_ulong_t sem_ctime_high;
- compat_ulong_t sem_nsems;
- compat_ulong_t __unused1;
- compat_ulong_t __unused2;
-};
-
-struct compat_msqid64_ds {
- struct compat_ipc64_perm msg_perm;
- compat_ulong_t msg_stime;
- compat_ulong_t msg_stime_high;
- compat_ulong_t msg_rtime;
- compat_ulong_t msg_rtime_high;
- compat_ulong_t msg_ctime;
- compat_ulong_t msg_ctime_high;
- compat_ulong_t msg_cbytes;
- compat_ulong_t msg_qnum;
- compat_ulong_t msg_qbytes;
- compat_pid_t msg_lspid;
- compat_pid_t msg_lrpid;
- compat_ulong_t __unused1;
- compat_ulong_t __unused2;
-};
-
-struct compat_shmid64_ds {
- struct compat_ipc64_perm shm_perm;
- compat_size_t shm_segsz;
- compat_ulong_t shm_atime;
- compat_ulong_t shm_atime_high;
- compat_ulong_t shm_dtime;
- compat_ulong_t shm_dtime_high;
- compat_ulong_t shm_ctime;
- compat_ulong_t shm_ctime_high;
- compat_pid_t shm_cpid;
- compat_pid_t shm_lpid;
- compat_ulong_t shm_nattch;
- compat_ulong_t __unused1;
- compat_ulong_t __unused2;
-};
#endif /* _ASM_S390X_COMPAT_H */
diff --git a/arch/sparc/include/asm/compat.h b/arch/sparc/include/asm/compat.h
index d78fb44942e0..e4382d2efa56 100644
--- a/arch/sparc/include/asm/compat.h
+++ b/arch/sparc/include/asm/compat.h
@@ -9,17 +9,25 @@
#define compat_mode_t compat_mode_t
typedef u16 compat_mode_t;
+#define __compat_uid_t __compat_uid_t
+typedef u16 __compat_uid_t;
+typedef u16 __compat_gid_t;
+
+#define compat_dev_t compat_dev_t
+typedef u16 compat_dev_t;
+
+#define compat_ipc_pid_t compat_ipc_pid_t
+typedef u16 compat_ipc_pid_t;
+
+#define compat_ipc64_perm compat_ipc64_perm
+
+#define COMPAT_RLIM_INFINITY 0x7fffffff
+
#include <asm-generic/compat.h>
-#define COMPAT_USER_HZ 100
#define COMPAT_UTS_MACHINE "sparc\0\0"
-typedef u16 __compat_uid_t;
-typedef u16 __compat_gid_t;
-typedef u16 compat_dev_t;
typedef s16 compat_nlink_t;
-typedef u16 compat_ipc_pid_t;
-typedef __kernel_fsid_t compat_fsid_t;
struct compat_stat {
compat_dev_t st_dev;
@@ -77,25 +85,6 @@ struct compat_stat64 {
#define __ARCH_COMPAT_FLOCK_PAD short __unused;
-struct compat_statfs {
- int f_type;
- int f_bsize;
- int f_blocks;
- int f_bfree;
- int f_bavail;
- int f_files;
- int f_ffree;
- compat_fsid_t f_fsid;
- int f_namelen; /* SunOS ignores this field. */
- int f_frsize;
- int f_flags;
- int f_spare[4];
-};
-
-#define COMPAT_RLIM_INFINITY 0x7fffffff
-
-#define COMPAT_OFF_T_MAX 0x7fffffff
-
struct compat_ipc64_perm {
compat_key_t key;
__compat_uid32_t uid;
diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
index de794d895866..e74a107de0d0 100644
--- a/arch/x86/include/asm/compat.h
+++ b/arch/x86/include/asm/compat.h
@@ -15,17 +15,23 @@
#define compat_mode_t compat_mode_t
typedef u16 compat_mode_t;
+#define __compat_uid_t __compat_uid_t
+typedef u16 __compat_uid_t;
+typedef u16 __compat_gid_t;
+
+#define compat_dev_t compat_dev_t
+typedef u16 compat_dev_t;
+
+#define compat_ipc_pid_t compat_ipc_pid_t
+typedef u16 compat_ipc_pid_t;
+
+#define compat_statfs compat_statfs
+
#include <asm-generic/compat.h>
-#define COMPAT_USER_HZ 100
#define COMPAT_UTS_MACHINE "i686\0\0"
-typedef u16 __compat_uid_t;
-typedef u16 __compat_gid_t;
-typedef u16 compat_dev_t;
typedef u16 compat_nlink_t;
-typedef u16 compat_ipc_pid_t;
-typedef __kernel_fsid_t compat_fsid_t;
struct compat_stat {
compat_dev_t st_dev;
@@ -71,68 +77,6 @@ struct compat_statfs {
int f_spare[4];
};
-#define COMPAT_RLIM_INFINITY 0xffffffff
-
-#define COMPAT_OFF_T_MAX 0x7fffffff
-
-struct compat_ipc64_perm {
- compat_key_t key;
- __compat_uid32_t uid;
- __compat_gid32_t gid;
- __compat_uid32_t cuid;
- __compat_gid32_t cgid;
- unsigned short mode;
- unsigned short __pad1;
- unsigned short seq;
- unsigned short __pad2;
- compat_ulong_t unused1;
- compat_ulong_t unused2;
-};
-
-struct compat_semid64_ds {
- struct compat_ipc64_perm sem_perm;
- compat_ulong_t sem_otime;
- compat_ulong_t sem_otime_high;
- compat_ulong_t sem_ctime;
- compat_ulong_t sem_ctime_high;
- compat_ulong_t sem_nsems;
- compat_ulong_t __unused3;
- compat_ulong_t __unused4;
-};
-
-struct compat_msqid64_ds {
- struct compat_ipc64_perm msg_perm;
- compat_ulong_t msg_stime;
- compat_ulong_t msg_stime_high;
- compat_ulong_t msg_rtime;
- compat_ulong_t msg_rtime_high;
- compat_ulong_t msg_ctime;
- compat_ulong_t msg_ctime_high;
- compat_ulong_t msg_cbytes;
- compat_ulong_t msg_qnum;
- compat_ulong_t msg_qbytes;
- compat_pid_t msg_lspid;
- compat_pid_t msg_lrpid;
- compat_ulong_t __unused4;
- compat_ulong_t __unused5;
-};
-
-struct compat_shmid64_ds {
- struct compat_ipc64_perm shm_perm;
- compat_size_t shm_segsz;
- compat_ulong_t shm_atime;
- compat_ulong_t shm_atime_high;
- compat_ulong_t shm_dtime;
- compat_ulong_t shm_dtime_high;
- compat_ulong_t shm_ctime;
- compat_ulong_t shm_ctime_high;
- compat_pid_t shm_cpid;
- compat_pid_t shm_lpid;
- compat_ulong_t shm_nattch;
- compat_ulong_t __unused4;
- compat_ulong_t __unused5;
-};
-
#ifdef CONFIG_X86_X32_ABI
#define COMPAT_USE_64BIT_TIME \
(!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
diff --git a/include/asm-generic/compat.h b/include/asm-generic/compat.h
index d46c0201cc34..11653d6846cc 100644
--- a/include/asm-generic/compat.h
+++ b/include/asm-generic/compat.h
@@ -2,6 +2,18 @@
#ifndef __ASM_GENERIC_COMPAT_H
#define __ASM_GENERIC_COMPAT_H
+#ifndef COMPAT_USER_HZ
+#define COMPAT_USER_HZ 100
+#endif
+
+#ifndef COMPAT_RLIM_INFINITY
+#define COMPAT_RLIM_INFINITY 0xffffffff
+#endif
+
+#ifndef COMPAT_OFF_T_MAX
+#define COMPAT_OFF_T_MAX 0x7fffffff
+#endif
+
/* These types are common across all compat ABIs */
typedef u32 compat_size_t;
typedef s32 compat_ssize_t;
@@ -24,6 +36,11 @@ typedef u32 compat_caddr_t;
typedef u32 compat_aio_context_t;
typedef u32 compat_old_sigset_t;
+#ifndef __compat_uid_t
+typedef u32 __compat_uid_t;
+typedef u32 __compat_gid_t;
+#endif
+
#ifndef __compat_uid32_t
typedef u32 __compat_uid32_t;
typedef u32 __compat_gid32_t;
@@ -47,4 +64,93 @@ typedef u32 compat_sigset_word;
#define _COMPAT_NSIG_BPW 32
#endif
+#ifndef compat_dev_t
+typedef u32 compat_dev_t;
+#endif
+
+#ifndef compat_ipc_pid_t
+typedef s32 compat_ipc_pid_t;
+#endif
+
+#ifndef compat_fsid_t
+typedef __kernel_fsid_t compat_fsid_t;
+#endif
+
+#ifndef compat_statfs
+struct compat_statfs {
+ compat_int_t f_type;
+ compat_int_t f_bsize;
+ compat_int_t f_blocks;
+ compat_int_t f_bfree;
+ compat_int_t f_bavail;
+ compat_int_t f_files;
+ compat_int_t f_ffree;
+ compat_fsid_t f_fsid;
+ compat_int_t f_namelen;
+ compat_int_t f_frsize;
+ compat_int_t f_flags;
+ compat_int_t f_spare[4];
+};
+#endif
+
+#ifndef compat_ipc64_perm
+struct compat_ipc64_perm {
+ compat_key_t key;
+ __compat_uid32_t uid;
+ __compat_gid32_t gid;
+ __compat_uid32_t cuid;
+ __compat_gid32_t cgid;
+ compat_mode_t mode;
+ unsigned char __pad1[4 - sizeof(compat_mode_t)];
+ compat_ushort_t seq;
+ compat_ushort_t __pad2;
+ compat_ulong_t unused1;
+ compat_ulong_t unused2;
+};
+
+struct compat_semid64_ds {
+ struct compat_ipc64_perm sem_perm;
+ compat_ulong_t sem_otime;
+ compat_ulong_t sem_otime_high;
+ compat_ulong_t sem_ctime;
+ compat_ulong_t sem_ctime_high;
+ compat_ulong_t sem_nsems;
+ compat_ulong_t __unused3;
+ compat_ulong_t __unused4;
+};
+
+struct compat_msqid64_ds {
+ struct compat_ipc64_perm msg_perm;
+ compat_ulong_t msg_stime;
+ compat_ulong_t msg_stime_high;
+ compat_ulong_t msg_rtime;
+ compat_ulong_t msg_rtime_high;
+ compat_ulong_t msg_ctime;
+ compat_ulong_t msg_ctime_high;
+ compat_ulong_t msg_cbytes;
+ compat_ulong_t msg_qnum;
+ compat_ulong_t msg_qbytes;
+ compat_pid_t msg_lspid;
+ compat_pid_t msg_lrpid;
+ compat_ulong_t __unused4;
+ compat_ulong_t __unused5;
+};
+
+struct compat_shmid64_ds {
+ struct compat_ipc64_perm shm_perm;
+ compat_size_t shm_segsz;
+ compat_ulong_t shm_atime;
+ compat_ulong_t shm_atime_high;
+ compat_ulong_t shm_dtime;
+ compat_ulong_t shm_dtime_high;
+ compat_ulong_t shm_ctime;
+ compat_ulong_t shm_ctime_high;
+ compat_pid_t shm_cpid;
+ compat_pid_t shm_lpid;
+ compat_ulong_t shm_nattch;
+ compat_ulong_t __unused4;
+ compat_ulong_t __unused5;
+};
+#endif
+
#endif
--
2.25.1
From: Guo Ren <[email protected]>
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 future, we would add CROSS_COMPILE to support
that makes more requirement on compiler enviornment.
linux-rv64/arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg:
file format elf64-littleriscv
Disassembly of section .text:
0000000000000800 <__vdso_rt_sigreturn>:
800: 08b00893 li a7,139
804: 00000073 ecall
808: 0000 unimp
...
000000000000080c <__vdso_getcpu>:
80c: 0a800893 li a7,168
810: 00000073 ecall
814: 8082 ret
...
0000000000000818 <__vdso_flush_icache>:
818: 10300893 li a7,259
81c: 00000073 ecall
820: 8082 ret
linux-rv32/arch/riscv/kernel/vdso/vdso.so.dbg:
file format elf32-littleriscv
Disassembly of section .text:
00000800 <__vdso_rt_sigreturn>:
800: 08b00893 li a7,139
804: 00000073 ecall
808: 0000 unimp
...
0000080c <__vdso_getcpu>:
80c: 0a800893 li a7,168
810: 00000073 ecall
814: 8082 ret
...
00000818 <__vdso_flush_icache>:
818: 10300893 li a7,259
81c: 00000073 ecall
820: 8082 ret
Finally, reuse all *.S from vdso in compat_vdso that makes
implementation clear and readable.
Signed-off-by: Guo Ren <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
---
arch/riscv/Makefile | 5 ++
arch/riscv/include/asm/vdso.h | 9 +++
arch/riscv/kernel/Makefile | 1 +
arch/riscv/kernel/compat_vdso/.gitignore | 2 +
arch/riscv/kernel/compat_vdso/Makefile | 78 +++++++++++++++++++
arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 ++
.../kernel/compat_vdso/compat_vdso.lds.S | 3 +
arch/riscv/kernel/compat_vdso/flush_icache.S | 3 +
.../compat_vdso/gen_compat_vdso_offsets.sh | 5 ++
arch/riscv/kernel/compat_vdso/getcpu.S | 3 +
arch/riscv/kernel/compat_vdso/note.S | 3 +
arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 +
arch/riscv/kernel/vdso/vdso.S | 6 +-
13 files changed, 128 insertions(+), 1 deletion(-)
create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore
create mode 100644 arch/riscv/kernel/compat_vdso/Makefile
create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S
create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S
create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S
create mode 100644 arch/riscv/kernel/compat_vdso/note.S
create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index c6ca1b9cbf71..6a494029b8bd 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -112,12 +112,17 @@ libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
PHONY += vdso_install
vdso_install:
$(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
+ $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
+ $(build)=arch/riscv/kernel/compat_vdso $@)
ifeq ($(KBUILD_EXTMOD),)
ifeq ($(CONFIG_MMU),y)
prepare: vdso_prepare
vdso_prepare: prepare0
$(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
+ $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
+ $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
+
endif
endif
diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h
index bc6f75f3a199..af981426fe0f 100644
--- a/arch/riscv/include/asm/vdso.h
+++ b/arch/riscv/include/asm/vdso.h
@@ -21,6 +21,15 @@
#define VDSO_SYMBOL(base, name) \
(void __user *)((unsigned long)(base) + __vdso_##name##_offset)
+
+#ifdef CONFIG_COMPAT
+#include <generated/compat_vdso-offsets.h>
+
+#define COMPAT_VDSO_SYMBOL(base, name) \
+ (void __user *)((unsigned long)(base) + compat__vdso_##name##_offset)
+
+#endif /* CONFIG_COMPAT */
+
#endif /* !__ASSEMBLY__ */
#endif /* CONFIG_MMU */
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index 2fa06d6572bb..fec77d101f9e 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -70,3 +70,4 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o
obj-$(CONFIG_EFI) += efi.o
obj-$(CONFIG_COMPAT) += compat_syscall_table.o
+obj-$(CONFIG_COMPAT) += compat_vdso/
diff --git a/arch/riscv/kernel/compat_vdso/.gitignore b/arch/riscv/kernel/compat_vdso/.gitignore
new file mode 100644
index 000000000000..19d83d846c1e
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/.gitignore
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+compat_vdso.lds
diff --git a/arch/riscv/kernel/compat_vdso/Makefile b/arch/riscv/kernel/compat_vdso/Makefile
new file mode 100644
index 000000000000..260daf3236d3
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/Makefile
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for compat_vdso
+#
+
+# Symbols present in the compat_vdso
+compat_vdso-syms = rt_sigreturn
+compat_vdso-syms += getcpu
+compat_vdso-syms += flush_icache
+
+COMPAT_CC := $(CC)
+COMPAT_LD := $(LD)
+
+COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
+COMPAT_LD_FLAGS := -melf32lriscv
+
+# Files to link into the compat_vdso
+obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o
+
+# Build rules
+targets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds
+obj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso))
+
+obj-y += compat_vdso.o
+CPPFLAGS_compat_vdso.lds += -P -C -U$(ARCH)
+
+# Disable profiling and instrumentation for VDSO code
+GCOV_PROFILE := n
+KCOV_INSTRUMENT := n
+KASAN_SANITIZE := n
+UBSAN_SANITIZE := n
+
+# Force dependency
+$(obj)/compat_vdso.o: $(obj)/compat_vdso.so
+
+# link rule for the .so file, .lds has to be first
+$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE
+ $(call if_changed,compat_vdsold)
+LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \
+ --build-id=sha1 --hash-style=both --eh-frame-hdr
+
+$(obj-compat_vdso): %.o: %.S FORCE
+ $(call if_changed_dep,compat_vdsoas)
+
+# strip rule for the .so file
+$(obj)/%.so: OBJCOPYFLAGS := -S
+$(obj)/%.so: $(obj)/%.so.dbg FORCE
+ $(call if_changed,objcopy)
+
+# Generate VDSO offsets using helper script
+gen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh
+quiet_cmd_compat_vdsosym = VDSOSYM $@
+ cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@
+
+include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE
+ $(call if_changed,compat_vdsosym)
+
+# actual build commands
+# The DSO images are built using a special linker script
+# Make sure only to export the intended __compat_vdso_xxx symbol offsets.
+quiet_cmd_compat_vdsold = VDSOLD $@
+ cmd_compat_vdsold = $(COMPAT_LD) $(ld_flags) $(COMPAT_LD_FLAGS) -T $(filter-out FORCE,$^) -o [email protected] && \
+ $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) [email protected] $@ && \
+ rm [email protected]
+
+# actual build commands
+quiet_cmd_compat_vdsoas = VDSOAS $@
+ cmd_compat_vdsoas = $(COMPAT_CC) $(a_flags) $(COMPAT_CC_FLAGS) -c -o $@ $<
+
+# install commands for the unstripped file
+quiet_cmd_compat_vdso_install = INSTALL $@
+ cmd_compat_vdso_install = cp $(obj)/[email protected] $(MODLIB)/compat_vdso/$@
+
+compat_vdso.so: $(obj)/compat_vdso.so.dbg
+ @mkdir -p $(MODLIB)/compat_vdso
+ $(call cmd,compat_vdso_install)
+
+compat_vdso_install: compat_vdso.so
diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.S b/arch/riscv/kernel/compat_vdso/compat_vdso.S
new file mode 100644
index 000000000000..ffd66237e091
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/compat_vdso.S
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#define vdso_start compat_vdso_start
+#define vdso_end compat_vdso_end
+
+#define __VDSO_PATH "arch/riscv/kernel/compat_vdso/compat_vdso.so"
+
+#include "../vdso/vdso.S"
diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
new file mode 100644
index 000000000000..c7c9355d311e
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include "../vdso/vdso.lds.S"
diff --git a/arch/riscv/kernel/compat_vdso/flush_icache.S b/arch/riscv/kernel/compat_vdso/flush_icache.S
new file mode 100644
index 000000000000..523dd8b96045
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/flush_icache.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include "../vdso/flush_icache.S"
diff --git a/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
new file mode 100755
index 000000000000..8ac070c783b3
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+LC_ALL=C
+sed -n -e 's/^[0]\+\(0[0-9a-fA-F]*\) . \(__vdso_[a-zA-Z0-9_]*\)$/\#define compat\2_offset\t0x\1/p'
diff --git a/arch/riscv/kernel/compat_vdso/getcpu.S b/arch/riscv/kernel/compat_vdso/getcpu.S
new file mode 100644
index 000000000000..10f463efe271
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/getcpu.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include "../vdso/getcpu.S"
diff --git a/arch/riscv/kernel/compat_vdso/note.S b/arch/riscv/kernel/compat_vdso/note.S
new file mode 100644
index 000000000000..b10312907542
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/note.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include "../vdso/note.S"
diff --git a/arch/riscv/kernel/compat_vdso/rt_sigreturn.S b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S
new file mode 100644
index 000000000000..884aada4facc
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include "../vdso/rt_sigreturn.S"
diff --git a/arch/riscv/kernel/vdso/vdso.S b/arch/riscv/kernel/vdso/vdso.S
index df222245be05..83f1c899e8d8 100644
--- a/arch/riscv/kernel/vdso/vdso.S
+++ b/arch/riscv/kernel/vdso/vdso.S
@@ -7,12 +7,16 @@
#include <linux/linkage.h>
#include <asm/page.h>
+#ifndef __VDSO_PATH
+#define __VDSO_PATH "arch/riscv/kernel/vdso/vdso.so"
+#endif
+
__PAGE_ALIGNED_DATA
.globl vdso_start, vdso_end
.balign PAGE_SIZE
vdso_start:
- .incbin "arch/riscv/kernel/vdso/vdso.so"
+ .incbin __VDSO_PATH
.balign PAGE_SIZE
vdso_end:
--
2.25.1
On Thu, 28 Apr 2022 05:25:19 PDT (-0700), [email protected] wrote:
> Hi Palmer,
>
> I see you have taken v12 into your riscv-compat branch and added
> asm/signal32.h. Do you need me help put compat_sigcontext &
> compat_ucontext & compat_rt_sigframe into signal32.h? And could we
> rename signal32.h to compat_signal.h to match compat_signal.c?
>
> In the end, thx for taking care of compat patch series.
No problem. I was just trying to get something clean through all the
autobuilders before making it look good, I think it didn't fail this
time so I'll do a bit more refactoring. Shouldn't be too much longer at
this point.
>
>
> On Tue, Apr 5, 2022 at 3:13 PM <[email protected]> wrote:
>>
>> From: Guo Ren <[email protected]>
>>
>> Currently, most 64-bit architectures (x86, parisc, powerpc, arm64,
>> s390, mips, sparc) have supported COMPAT mode. But they all have
>> history issues and can't use standard linux unistd.h. RISC-V would
>> be first standard __SYSCALL_COMPAT user of include/uapi/asm-generic
>> /unistd.h.
>>
>> The patchset are based on v5.18-rc1, you can compare rv64-compat
>> v.s. rv32-native in qemu with following steps:
>>
>> - Prepare rv32 rootfs & fw_jump.bin by buildroot.org
>> $ git clone git://git.busybox.net/buildroot
>> $ cd buildroot
>> $ make qemu_riscv32_virt_defconfig O=qemu_riscv32_virt_defconfig
>> $ make -C qemu_riscv32_virt_defconfig
>> $ make qemu_riscv64_virt_defconfig O=qemu_riscv64_virt_defconfig
>> $ make -C qemu_riscv64_virt_defconfig
>> (Got fw_jump.bin & rootfs.ext2 in qemu_riscvXX_virt_defconfig/images)
>>
>> - Prepare Linux rv32 & rv64 Image
>> $ git clone [email protected]:c-sky/csky-linux.git -b riscv_compat_v12 linux
>> $ cd linux
>> $ echo "CONFIG_STRICT_KERNEL_RWX=n" >> arch/riscv/configs/defconfig
>> $ echo "CONFIG_STRICT_MODULE_RWX=n" >> arch/riscv/configs/defconfig
>> $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ rv32_defconfig
>> $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ Image
>> $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ defconfig
>> $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ Image
>>
>> - Prepare Qemu:
>> $ git clone https://gitlab.com/qemu-project/qemu.git -b master linux
>> $ cd qemu
>> $ ./configure --target-list="riscv64-softmmu riscv32-softmmu"
>> $ make
>>
>> Now let's compare rv64-compat with rv32-native memory footprint with almost the same
>> defconfig, rootfs, opensbi in one qemu.
>>
>> - Run rv64 with rv32 rootfs in compat mode:
>> $ ./build/qemu-system-riscv64 -cpu rv64 -M virt -m 64m -nographic -bios qemu_riscv64_virt_defconfig/images/fw_jump.bin -kernel build-rv64/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv64-unknown-linux-gnu-gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.37) #96 SMP Tue Dec 28 21:01:55 CST 2021
>> [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
>> [ 0.000000] Machine model: riscv-virtio,qemu
>> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
>> [ 0.000000] printk: bootconsole [sbi0] enabled
>> [ 0.000000] efi: UEFI not found.
>> [ 0.000000] Zone ranges:
>> [ 0.000000] DMA32 [mem 0x0000000080200000-0x0000000083ffffff]
>> [ 0.000000] Normal empty
>> [ 0.000000] Movable zone start for each node
>> [ 0.000000] Early memory node ranges
>> [ 0.000000] node 0: [mem 0x0000000080200000-0x0000000083ffffff]
>> [ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x0000000083ffffff]
>> [ 0.000000] SBI specification v0.2 detected
>> [ 0.000000] SBI implementation ID=0x1 Version=0x9
>> [ 0.000000] SBI TIME extension detected
>> [ 0.000000] SBI IPI extension detected
>> [ 0.000000] SBI RFENCE extension detected
>> [ 0.000000] SBI v0.2 HSM extension detected
>> [ 0.000000] riscv: ISA extensions acdfhimsu
>> [ 0.000000] riscv: ELF capabilities acdfim
>> [ 0.000000] percpu: Embedded 17 pages/cpu s30696 r8192 d30744 u69632
>> [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15655
>> [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
>> [ 0.000000] Dentry cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
>> [ 0.000000] Inode-cache hash table entries: 4096 (order: 3, 32768 bytes, linear)
>> [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
>> [ 0.000000] Virtual kernel memory layout:
>> [ 0.000000] fixmap : 0xffffffcefee00000 - 0xffffffceff000000 (2048 kB)
>> [ 0.000000] pci io : 0xffffffceff000000 - 0xffffffcf00000000 ( 16 MB)
>> [ 0.000000] vmemmap : 0xffffffcf00000000 - 0xffffffcfffffffff (4095 MB)
>> [ 0.000000] vmalloc : 0xffffffd000000000 - 0xffffffdfffffffff (65535 MB)
>> [ 0.000000] lowmem : 0xffffffe000000000 - 0xffffffe003e00000 ( 62 MB)
>> [ 0.000000] kernel : 0xffffffff80000000 - 0xffffffffffffffff (2047 MB)
>> [ 0.000000] Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved, 0K cma-reserved)
>> [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
>> [ 0.000000] rcu: Hierarchical RCU implementation.
>> [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
>> [ 0.000000] rcu: RCU debug extended QS entry/exit.
>> [ 0.000000] Tracing variant of Tasks RCU enabled.
>> [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
>> [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
>> [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
>> [ 0.000000] riscv-intc: 64 local interrupts mapped
>> [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
>> ...
>> Welcome to Buildroot
>> buildroot login: root
>> # cat /proc/cpuinfo
>> processor : 0
>> hart : 0
>> isa : rv64imafdcsuh
>> mmu : sv48
>>
>> # file /bin/busybox
>> /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
>> # ca[ 78.386630] random: fast init done
>> # cat /proc/meminfo
>> MemTotal: 53076 kB
>> MemFree: 40264 kB
>> MemAvailable: 40244 kB
>> Buffers: 236 kB
>> Cached: 1560 kB
>> SwapCached: 0 kB
>> Active: 1700 kB
>> Inactive: 516 kB
>> Active(anon): 40 kB
>> Inactive(anon): 424 kB
>> Active(file): 1660 kB
>> Inactive(file): 92 kB
>> Unevictable: 0 kB
>> Mlocked: 0 kB
>> SwapTotal: 0 kB
>> SwapFree: 0 kB
>> Dirty: 0 kB
>> Writeback: 0 kB
>> AnonPages: 444 kB
>> Mapped: 1188 kB
>> Shmem: 44 kB
>> KReclaimable: 952 kB
>> Slab: 5744 kB
>> SReclaimable: 952 kB
>> SUnreclaim: 4792 kB
>> KernelStack: 624 kB
>> PageTables: 156 kB
>> NFS_Unstable: 0 kB
>> Bounce: 0 kB
>> WritebackTmp: 0 kB
>> CommitLimit: 26536 kB
>> Committed_AS: 1748 kB
>> VmallocTotal: 67108863 kB
>> VmallocUsed: 652 kB
>> VmallocChunk: 0 kB
>> Percpu: 80 kB
>> #
>>
>> - Run rv32 with rv32 rootfs:
>> $ ./build/qemu-system-riscv32 -cpu rv32 -M virt -m 64m -nographic -bios qemu_riscv32_virt_defconfig/images/fw_jump.bin -kernel build-rv32/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.11-201-g7600ca7960-dirty) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #7 SMP Tue Dec 28 21:02:21 CST 2021
>> [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80400000
>> [ 0.000000] Machine model: riscv-virtio,qemu
>> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
>> [ 0.000000] printk: bootconsole [sbi0] enabled
>> [ 0.000000] efi: UEFI not found.
>> [ 0.000000] Zone ranges:
>> [ 0.000000] Normal [mem 0x0000000080400000-0x0000000083ffffff]
>> [ 0.000000] Movable zone start for each node
>> [ 0.000000] Early memory node ranges
>> [ 0.000000] node 0: [mem 0x0000000080400000-0x0000000083ffffff]
>> [ 0.000000] Initmem setup node 0 [mem 0x0000000080400000-0x0000000083ffffff]
>> [ 0.000000] SBI specification v0.2 detected
>> [ 0.000000] SBI implementation ID=0x1 Version=0x9
>> [ 0.000000] SBI TIME extension detected
>> [ 0.000000] SBI IPI extension detected
>> [ 0.000000] SBI RFENCE extension detected
>> [ 0.000000] SBI v0.2 HSM extension detected
>> [ 0.000000] riscv: ISA extensions acdfhimsu
>> [ 0.000000] riscv: ELF capabilities acdfim
>> [ 0.000000] percpu: Embedded 12 pages/cpu s16600 r8192 d24360 u49152
>> [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15240
>> [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
>> [ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
>> [ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
>> [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
>> [ 0.000000] Virtual kernel memory layout:
>> [ 0.000000] fixmap : 0x9dc00000 - 0x9e000000 (4096 kB)
>> [ 0.000000] pci io : 0x9e000000 - 0x9f000000 ( 16 MB)
>> [ 0.000000] vmemmap : 0x9f000000 - 0x9fffffff ( 15 MB)
>> [ 0.000000] vmalloc : 0xa0000000 - 0xbfffffff ( 511 MB)
>> [ 0.000000] lowmem : 0xc0000000 - 0xc3c00000 ( 60 MB)
>> [ 0.000000] Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved, 0K cma-reserved)
>> [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
>> [ 0.000000] rcu: Hierarchical RCU implementation.
>> [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
>> [ 0.000000] rcu: RCU debug extended QS entry/exit.
>> [ 0.000000] Tracing variant of Tasks RCU enabled.
>> [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
>> [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
>> [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
>> [ 0.000000] riscv-intc: 32 local interrupts mapped
>> [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
>> ...
>> Welcome to Buildroot
>> buildroot login: root
>> # cat /proc/cpuinfo
>> processor : 0
>> hart : 0
>> isa : rv32imafdcsuh
>> mmu : sv32
>>
>> # file /bin/busybox
>> /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
>> [ 79.320589] random: fast init done
>> # cat /proc/meminfo
>> MemTotal: 52176 kB
>> MemFree: 41012 kB
>> MemAvailable: 42176 kB
>> Buffers: 644 kB
>> Cached: 2724 kB
>> SwapCached: 0 kB
>> Active: 3128 kB
>> Inactive: 752 kB
>> Active(anon): 40 kB
>> Inactive(anon): 516 kB
>> Active(file): 3088 kB
>> Inactive(file): 236 kB
>> Unevictable: 0 kB
>> Mlocked: 0 kB
>> SwapTotal: 0 kB
>> SwapFree: 0 kB
>> Dirty: 4 kB
>> Writeback: 0 kB
>> AnonPages: 556 kB
>> Mapped: 2172 kB
>> Shmem: 44 kB
>> KReclaimable: 656 kB
>> Slab: 3684 kB
>> SReclaimable: 656 kB
>> SUnreclaim: 3028 kB
>> KernelStack: 312 kB
>> PageTables: 88 kB
>> NFS_Unstable: 0 kB
>> Bounce: 0 kB
>> WritebackTmp: 0 kB
>> CommitLimit: 26088 kB
>> Committed_AS: 2088 kB
>> VmallocTotal: 524287 kB
>> VmallocUsed: 12 kB
>> VmallocChunk: 0 kB
>> Percpu: 60 kB
>> #
>>
>> Some conclusions:
>> - kernel statics:
>> 64: Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved)
>> 32: Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved)
>> rv32 better than rv64: 1% 22% 17% 13% 19% 11%
>> The code size is very similar, but data size rv32 would be better.
>>
>> - rv32 kernel runtime KernelStack, Slab... are smaller,
>> rv64: MemTotal: 53076 kB, MemFree: 40264 kB
>> rv32: MemTotal: 52176 + 2048 kB, MemFree: 41012 + 2048 kB
>> rv32 better than rv64: 2% 6%
>>
>> (Because opensbi problem, we could add another 2MB for rv32.)
>> Overall in 64MB memory situation, rv64-compat is 6% worse than rv32-native
>> at memory footprint. If the userspace memory usage increases, I think
>> the gap will be further reduced.
>>
>> Changes in v12:
>> - Rebase on 5.18-rc1
>> - Fixup compile conflicts with 5.18-rc1
>> - Fixup $(srctree) == $(objtree) compile error reported by Nathan
>>
>> Changes in v11:
>> - Using arch instead of kconfig for commit subject by Masahiro Yamada
>>
>> Changes in v10:
>> - Fixup arm64 compile error with compat_statfs definition
>> - Fixup compat_sys_fadvise64_64 function arguments error cause ltp failure
>>
>> Changes in v9:
>> - Fixup rv32 call rv64 segment fault
>> - Ready for 5.18
>>
>> Changes in v8:
>> - Enhanced elf_check_arch with EI_CLASS
>> - Fixup SR_UXL doesn't exist in CONFIG_32BIT
>> - Add Tested-by with Heiko
>> - Update qemu compile tips with upstream repo
>>
>> Changes in v7:
>> - Re-construct compat_vdso/Makefile
>> - Fixup disable COMPAT compile error by csr.h's macro.
>> - Optimize coding convention for lo/hi in compat.h
>>
>> Changes in v6:
>> - Rebase on linux-5.17-rc5
>> - Optimize hw capability check for elf
>> - Optimize comment in thread_info.h
>> - Optimize start_thread with SR_UXL setting
>> - Optimize vdso.c with direct panic
>>
>> Changes in v5:
>> - Rebase on linux-5.17-rc2
>> - Include consolidate the fcntl patches by Christoph Hellwig
>> - Remove F_GETLK64/F_SETLK64/F_SETLKW64 from asm/compat.h
>> - Change COMPAT_RLIM_INFINITY from 0x7fffffff to 0xffffffff
>> - Bring back "Add hw-cap detect in setup_arch patch" in v1
>>
>> Changes in v4:
>> - Rebase on linux-5.17-rc1
>> - Optimize compat_sys_call_table implementation with Arnd's advice
>> - Add reviewed-by for Arnd. Thx :)
>> - Remove FIXME comment in elf.h
>> - Optimize Cleanup duplicate definitions in compat.h with Arnd's advice
>>
>> Changes in v3:
>> - Rebase on newest master (pre linux-5.17-rc1)
>> - Using newest qemu version v7 for test
>> - Remove fcntl common modification
>> - Fixup SET_PERSONALITY in elf.h by Arnd
>> - Fixup KVM Kconfig
>> - Update Acked-by & Reviewed-by
>>
>> Changes in v2:
>> - Add __ARCH_WANT_COMPAT_STAT suggested
>> - Cleanup fcntl compatduplicate definitions
>> - Cleanup compat.h
>> - Move rv32_defconfig into Makefile
>> - Fixup rv64 rootfs boot failed, remove hw_compat_mode_detect
>> - Move SYSVIPC_COMPAT into init/Kconfig
>> - Simplify compat_elf_check
>>
>> Christoph Hellwig (3):
>> uapi: simplify __ARCH_FLOCK{,64}_PAD a little
>> uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
>> compat: consolidate the compat_flock{,64} definition
>>
>> Guo Ren (17):
>> arch: Add SYSVIPC_COMPAT for all architectures
>> fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT
>> asm-generic: compat: Cleanup duplicate definitions
>> syscalls: compat: Fix the missing part for __SYSCALL_COMPAT
>> riscv: Fixup difference with defconfig
>> riscv: compat: Add basic compat data type implementation
>> riscv: compat: Support TASK_SIZE for compat mode
>> riscv: compat: syscall: Add compat_sys_call_table implementation
>> riscv: compat: syscall: Add entry.S implementation
>> riscv: compat: process: Add UXL_32 support in start_thread
>> riscv: compat: Add elf.h implementation
>> riscv: compat: Add hw capability check for elf
>> riscv: compat: vdso: Add COMPAT_VDSO base code implementation
>> riscv: compat: vdso: Add setup additional pages implementation
>> riscv: compat: signal: Add rt_frame implementation
>> riscv: compat: ptrace: Add compat_arch_ptrace implement
>> riscv: compat: Add COMPAT Kbuild skeletal support
>>
>> arch/arm64/Kconfig | 4 -
>> arch/arm64/include/asm/compat.h | 93 +------
>> arch/arm64/include/asm/unistd.h | 1 +
>> arch/mips/Kconfig | 5 -
>> arch/mips/include/asm/compat.h | 41 +--
>> arch/mips/include/asm/unistd.h | 2 +
>> arch/mips/include/uapi/asm/fcntl.h | 30 +--
>> arch/parisc/Kconfig | 4 -
>> arch/parisc/include/asm/compat.h | 45 +---
>> arch/parisc/include/asm/unistd.h | 1 +
>> arch/powerpc/Kconfig | 5 -
>> arch/powerpc/include/asm/compat.h | 50 +---
>> arch/powerpc/include/asm/unistd.h | 1 +
>> arch/riscv/Kconfig | 19 ++
>> arch/riscv/Makefile | 9 +
>> arch/riscv/include/asm/compat.h | 129 ++++++++++
>> arch/riscv/include/asm/csr.h | 7 +
>> arch/riscv/include/asm/elf.h | 50 +++-
>> arch/riscv/include/asm/mmu.h | 1 +
>> arch/riscv/include/asm/pgtable.h | 13 +-
>> arch/riscv/include/asm/processor.h | 6 +-
>> arch/riscv/include/asm/syscall.h | 1 +
>> arch/riscv/include/asm/thread_info.h | 1 +
>> arch/riscv/include/asm/unistd.h | 11 +
>> arch/riscv/include/asm/vdso.h | 9 +
>> arch/riscv/include/uapi/asm/unistd.h | 2 +-
>> arch/riscv/kernel/Makefile | 3 +
>> arch/riscv/kernel/compat_signal.c | 242 ++++++++++++++++++
>> arch/riscv/kernel/compat_syscall_table.c | 19 ++
>> arch/riscv/kernel/compat_vdso/.gitignore | 2 +
>> arch/riscv/kernel/compat_vdso/Makefile | 78 ++++++
>> arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +
>> .../kernel/compat_vdso/compat_vdso.lds.S | 3 +
>> arch/riscv/kernel/compat_vdso/flush_icache.S | 3 +
>> .../compat_vdso/gen_compat_vdso_offsets.sh | 5 +
>> arch/riscv/kernel/compat_vdso/getcpu.S | 3 +
>> arch/riscv/kernel/compat_vdso/note.S | 3 +
>> arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 +
>> arch/riscv/kernel/entry.S | 18 +-
>> arch/riscv/kernel/process.c | 37 +++
>> arch/riscv/kernel/ptrace.c | 87 ++++++-
>> arch/riscv/kernel/signal.c | 13 +-
>> arch/riscv/kernel/sys_riscv.c | 6 +-
>> arch/riscv/kernel/vdso.c | 105 +++++---
>> arch/riscv/kernel/vdso/vdso.S | 6 +-
>> arch/s390/Kconfig | 3 -
>> arch/s390/include/asm/compat.h | 99 +------
>> arch/s390/include/asm/unistd.h | 1 +
>> arch/sparc/Kconfig | 5 -
>> arch/sparc/include/asm/compat.h | 61 ++---
>> arch/sparc/include/asm/unistd.h | 1 +
>> arch/x86/Kconfig | 4 -
>> arch/x86/include/asm/compat.h | 104 ++------
>> arch/x86/include/asm/unistd.h | 1 +
>> fs/open.c | 24 ++
>> fs/read_write.c | 16 ++
>> fs/stat.c | 2 +-
>> fs/sync.c | 9 +
>> include/asm-generic/compat.h | 113 ++++++++
>> include/linux/compat.h | 68 +++++
>> include/uapi/asm-generic/fcntl.h | 23 +-
>> include/uapi/asm-generic/unistd.h | 4 +-
>> init/Kconfig | 4 +
>> mm/fadvise.c | 11 +
>> mm/readahead.c | 7 +
>> tools/include/uapi/asm-generic/fcntl.h | 21 +-
>> tools/include/uapi/asm-generic/unistd.h | 4 +-
>> 67 files changed, 1206 insertions(+), 563 deletions(-)
>> create mode 100644 arch/riscv/include/asm/compat.h
>> create mode 100644 arch/riscv/kernel/compat_signal.c
>> create mode 100644 arch/riscv/kernel/compat_syscall_table.c
>> create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore
>> create mode 100644 arch/riscv/kernel/compat_vdso/Makefile
>> create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S
>> create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
>> create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S
>> create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
>> create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S
>> create mode 100644 arch/riscv/kernel/compat_vdso/note.S
>> create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S
>>
>> --
>> 2.25.1
>>
Hi Palmer,
I see you have taken v12 into your riscv-compat branch and added
asm/signal32.h. Do you need me help put compat_sigcontext &
compat_ucontext & compat_rt_sigframe into signal32.h? And could we
rename signal32.h to compat_signal.h to match compat_signal.c?
In the end, thx for taking care of compat patch series.
On Tue, Apr 5, 2022 at 3:13 PM <[email protected]> wrote:
>
> From: Guo Ren <[email protected]>
>
> Currently, most 64-bit architectures (x86, parisc, powerpc, arm64,
> s390, mips, sparc) have supported COMPAT mode. But they all have
> history issues and can't use standard linux unistd.h. RISC-V would
> be first standard __SYSCALL_COMPAT user of include/uapi/asm-generic
> /unistd.h.
>
> The patchset are based on v5.18-rc1, you can compare rv64-compat
> v.s. rv32-native in qemu with following steps:
>
> - Prepare rv32 rootfs & fw_jump.bin by buildroot.org
> $ git clone git://git.busybox.net/buildroot
> $ cd buildroot
> $ make qemu_riscv32_virt_defconfig O=qemu_riscv32_virt_defconfig
> $ make -C qemu_riscv32_virt_defconfig
> $ make qemu_riscv64_virt_defconfig O=qemu_riscv64_virt_defconfig
> $ make -C qemu_riscv64_virt_defconfig
> (Got fw_jump.bin & rootfs.ext2 in qemu_riscvXX_virt_defconfig/images)
>
> - Prepare Linux rv32 & rv64 Image
> $ git clone [email protected]:c-sky/csky-linux.git -b riscv_compat_v12 linux
> $ cd linux
> $ echo "CONFIG_STRICT_KERNEL_RWX=n" >> arch/riscv/configs/defconfig
> $ echo "CONFIG_STRICT_MODULE_RWX=n" >> arch/riscv/configs/defconfig
> $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ rv32_defconfig
> $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ Image
> $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ defconfig
> $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ Image
>
> - Prepare Qemu:
> $ git clone https://gitlab.com/qemu-project/qemu.git -b master linux
> $ cd qemu
> $ ./configure --target-list="riscv64-softmmu riscv32-softmmu"
> $ make
>
> Now let's compare rv64-compat with rv32-native memory footprint with almost the same
> defconfig, rootfs, opensbi in one qemu.
>
> - Run rv64 with rv32 rootfs in compat mode:
> $ ./build/qemu-system-riscv64 -cpu rv64 -M virt -m 64m -nographic -bios qemu_riscv64_virt_defconfig/images/fw_jump.bin -kernel build-rv64/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv64-unknown-linux-gnu-gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.37) #96 SMP Tue Dec 28 21:01:55 CST 2021
> [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
> [ 0.000000] Machine model: riscv-virtio,qemu
> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> [ 0.000000] printk: bootconsole [sbi0] enabled
> [ 0.000000] efi: UEFI not found.
> [ 0.000000] Zone ranges:
> [ 0.000000] DMA32 [mem 0x0000000080200000-0x0000000083ffffff]
> [ 0.000000] Normal empty
> [ 0.000000] Movable zone start for each node
> [ 0.000000] Early memory node ranges
> [ 0.000000] node 0: [mem 0x0000000080200000-0x0000000083ffffff]
> [ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x0000000083ffffff]
> [ 0.000000] SBI specification v0.2 detected
> [ 0.000000] SBI implementation ID=0x1 Version=0x9
> [ 0.000000] SBI TIME extension detected
> [ 0.000000] SBI IPI extension detected
> [ 0.000000] SBI RFENCE extension detected
> [ 0.000000] SBI v0.2 HSM extension detected
> [ 0.000000] riscv: ISA extensions acdfhimsu
> [ 0.000000] riscv: ELF capabilities acdfim
> [ 0.000000] percpu: Embedded 17 pages/cpu s30696 r8192 d30744 u69632
> [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15655
> [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
> [ 0.000000] Dentry cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
> [ 0.000000] Inode-cache hash table entries: 4096 (order: 3, 32768 bytes, linear)
> [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
> [ 0.000000] Virtual kernel memory layout:
> [ 0.000000] fixmap : 0xffffffcefee00000 - 0xffffffceff000000 (2048 kB)
> [ 0.000000] pci io : 0xffffffceff000000 - 0xffffffcf00000000 ( 16 MB)
> [ 0.000000] vmemmap : 0xffffffcf00000000 - 0xffffffcfffffffff (4095 MB)
> [ 0.000000] vmalloc : 0xffffffd000000000 - 0xffffffdfffffffff (65535 MB)
> [ 0.000000] lowmem : 0xffffffe000000000 - 0xffffffe003e00000 ( 62 MB)
> [ 0.000000] kernel : 0xffffffff80000000 - 0xffffffffffffffff (2047 MB)
> [ 0.000000] Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved, 0K cma-reserved)
> [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> [ 0.000000] rcu: Hierarchical RCU implementation.
> [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
> [ 0.000000] rcu: RCU debug extended QS entry/exit.
> [ 0.000000] Tracing variant of Tasks RCU enabled.
> [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
> [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> [ 0.000000] riscv-intc: 64 local interrupts mapped
> [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
> ...
> Welcome to Buildroot
> buildroot login: root
> # cat /proc/cpuinfo
> processor : 0
> hart : 0
> isa : rv64imafdcsuh
> mmu : sv48
>
> # file /bin/busybox
> /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
> # ca[ 78.386630] random: fast init done
> # cat /proc/meminfo
> MemTotal: 53076 kB
> MemFree: 40264 kB
> MemAvailable: 40244 kB
> Buffers: 236 kB
> Cached: 1560 kB
> SwapCached: 0 kB
> Active: 1700 kB
> Inactive: 516 kB
> Active(anon): 40 kB
> Inactive(anon): 424 kB
> Active(file): 1660 kB
> Inactive(file): 92 kB
> Unevictable: 0 kB
> Mlocked: 0 kB
> SwapTotal: 0 kB
> SwapFree: 0 kB
> Dirty: 0 kB
> Writeback: 0 kB
> AnonPages: 444 kB
> Mapped: 1188 kB
> Shmem: 44 kB
> KReclaimable: 952 kB
> Slab: 5744 kB
> SReclaimable: 952 kB
> SUnreclaim: 4792 kB
> KernelStack: 624 kB
> PageTables: 156 kB
> NFS_Unstable: 0 kB
> Bounce: 0 kB
> WritebackTmp: 0 kB
> CommitLimit: 26536 kB
> Committed_AS: 1748 kB
> VmallocTotal: 67108863 kB
> VmallocUsed: 652 kB
> VmallocChunk: 0 kB
> Percpu: 80 kB
> #
>
> - Run rv32 with rv32 rootfs:
> $ ./build/qemu-system-riscv32 -cpu rv32 -M virt -m 64m -nographic -bios qemu_riscv32_virt_defconfig/images/fw_jump.bin -kernel build-rv32/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.11-201-g7600ca7960-dirty) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #7 SMP Tue Dec 28 21:02:21 CST 2021
> [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80400000
> [ 0.000000] Machine model: riscv-virtio,qemu
> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> [ 0.000000] printk: bootconsole [sbi0] enabled
> [ 0.000000] efi: UEFI not found.
> [ 0.000000] Zone ranges:
> [ 0.000000] Normal [mem 0x0000000080400000-0x0000000083ffffff]
> [ 0.000000] Movable zone start for each node
> [ 0.000000] Early memory node ranges
> [ 0.000000] node 0: [mem 0x0000000080400000-0x0000000083ffffff]
> [ 0.000000] Initmem setup node 0 [mem 0x0000000080400000-0x0000000083ffffff]
> [ 0.000000] SBI specification v0.2 detected
> [ 0.000000] SBI implementation ID=0x1 Version=0x9
> [ 0.000000] SBI TIME extension detected
> [ 0.000000] SBI IPI extension detected
> [ 0.000000] SBI RFENCE extension detected
> [ 0.000000] SBI v0.2 HSM extension detected
> [ 0.000000] riscv: ISA extensions acdfhimsu
> [ 0.000000] riscv: ELF capabilities acdfim
> [ 0.000000] percpu: Embedded 12 pages/cpu s16600 r8192 d24360 u49152
> [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15240
> [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
> [ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
> [ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
> [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
> [ 0.000000] Virtual kernel memory layout:
> [ 0.000000] fixmap : 0x9dc00000 - 0x9e000000 (4096 kB)
> [ 0.000000] pci io : 0x9e000000 - 0x9f000000 ( 16 MB)
> [ 0.000000] vmemmap : 0x9f000000 - 0x9fffffff ( 15 MB)
> [ 0.000000] vmalloc : 0xa0000000 - 0xbfffffff ( 511 MB)
> [ 0.000000] lowmem : 0xc0000000 - 0xc3c00000 ( 60 MB)
> [ 0.000000] Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved, 0K cma-reserved)
> [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> [ 0.000000] rcu: Hierarchical RCU implementation.
> [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
> [ 0.000000] rcu: RCU debug extended QS entry/exit.
> [ 0.000000] Tracing variant of Tasks RCU enabled.
> [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
> [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> [ 0.000000] riscv-intc: 32 local interrupts mapped
> [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
> ...
> Welcome to Buildroot
> buildroot login: root
> # cat /proc/cpuinfo
> processor : 0
> hart : 0
> isa : rv32imafdcsuh
> mmu : sv32
>
> # file /bin/busybox
> /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
> [ 79.320589] random: fast init done
> # cat /proc/meminfo
> MemTotal: 52176 kB
> MemFree: 41012 kB
> MemAvailable: 42176 kB
> Buffers: 644 kB
> Cached: 2724 kB
> SwapCached: 0 kB
> Active: 3128 kB
> Inactive: 752 kB
> Active(anon): 40 kB
> Inactive(anon): 516 kB
> Active(file): 3088 kB
> Inactive(file): 236 kB
> Unevictable: 0 kB
> Mlocked: 0 kB
> SwapTotal: 0 kB
> SwapFree: 0 kB
> Dirty: 4 kB
> Writeback: 0 kB
> AnonPages: 556 kB
> Mapped: 2172 kB
> Shmem: 44 kB
> KReclaimable: 656 kB
> Slab: 3684 kB
> SReclaimable: 656 kB
> SUnreclaim: 3028 kB
> KernelStack: 312 kB
> PageTables: 88 kB
> NFS_Unstable: 0 kB
> Bounce: 0 kB
> WritebackTmp: 0 kB
> CommitLimit: 26088 kB
> Committed_AS: 2088 kB
> VmallocTotal: 524287 kB
> VmallocUsed: 12 kB
> VmallocChunk: 0 kB
> Percpu: 60 kB
> #
>
> Some conclusions:
> - kernel statics:
> 64: Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved)
> 32: Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved)
> rv32 better than rv64: 1% 22% 17% 13% 19% 11%
> The code size is very similar, but data size rv32 would be better.
>
> - rv32 kernel runtime KernelStack, Slab... are smaller,
> rv64: MemTotal: 53076 kB, MemFree: 40264 kB
> rv32: MemTotal: 52176 + 2048 kB, MemFree: 41012 + 2048 kB
> rv32 better than rv64: 2% 6%
>
> (Because opensbi problem, we could add another 2MB for rv32.)
> Overall in 64MB memory situation, rv64-compat is 6% worse than rv32-native
> at memory footprint. If the userspace memory usage increases, I think
> the gap will be further reduced.
>
> Changes in v12:
> - Rebase on 5.18-rc1
> - Fixup compile conflicts with 5.18-rc1
> - Fixup $(srctree) == $(objtree) compile error reported by Nathan
>
> Changes in v11:
> - Using arch instead of kconfig for commit subject by Masahiro Yamada
>
> Changes in v10:
> - Fixup arm64 compile error with compat_statfs definition
> - Fixup compat_sys_fadvise64_64 function arguments error cause ltp failure
>
> Changes in v9:
> - Fixup rv32 call rv64 segment fault
> - Ready for 5.18
>
> Changes in v8:
> - Enhanced elf_check_arch with EI_CLASS
> - Fixup SR_UXL doesn't exist in CONFIG_32BIT
> - Add Tested-by with Heiko
> - Update qemu compile tips with upstream repo
>
> Changes in v7:
> - Re-construct compat_vdso/Makefile
> - Fixup disable COMPAT compile error by csr.h's macro.
> - Optimize coding convention for lo/hi in compat.h
>
> Changes in v6:
> - Rebase on linux-5.17-rc5
> - Optimize hw capability check for elf
> - Optimize comment in thread_info.h
> - Optimize start_thread with SR_UXL setting
> - Optimize vdso.c with direct panic
>
> Changes in v5:
> - Rebase on linux-5.17-rc2
> - Include consolidate the fcntl patches by Christoph Hellwig
> - Remove F_GETLK64/F_SETLK64/F_SETLKW64 from asm/compat.h
> - Change COMPAT_RLIM_INFINITY from 0x7fffffff to 0xffffffff
> - Bring back "Add hw-cap detect in setup_arch patch" in v1
>
> Changes in v4:
> - Rebase on linux-5.17-rc1
> - Optimize compat_sys_call_table implementation with Arnd's advice
> - Add reviewed-by for Arnd. Thx :)
> - Remove FIXME comment in elf.h
> - Optimize Cleanup duplicate definitions in compat.h with Arnd's advice
>
> Changes in v3:
> - Rebase on newest master (pre linux-5.17-rc1)
> - Using newest qemu version v7 for test
> - Remove fcntl common modification
> - Fixup SET_PERSONALITY in elf.h by Arnd
> - Fixup KVM Kconfig
> - Update Acked-by & Reviewed-by
>
> Changes in v2:
> - Add __ARCH_WANT_COMPAT_STAT suggested
> - Cleanup fcntl compatduplicate definitions
> - Cleanup compat.h
> - Move rv32_defconfig into Makefile
> - Fixup rv64 rootfs boot failed, remove hw_compat_mode_detect
> - Move SYSVIPC_COMPAT into init/Kconfig
> - Simplify compat_elf_check
>
> Christoph Hellwig (3):
> uapi: simplify __ARCH_FLOCK{,64}_PAD a little
> uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
> compat: consolidate the compat_flock{,64} definition
>
> Guo Ren (17):
> arch: Add SYSVIPC_COMPAT for all architectures
> fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT
> asm-generic: compat: Cleanup duplicate definitions
> syscalls: compat: Fix the missing part for __SYSCALL_COMPAT
> riscv: Fixup difference with defconfig
> riscv: compat: Add basic compat data type implementation
> riscv: compat: Support TASK_SIZE for compat mode
> riscv: compat: syscall: Add compat_sys_call_table implementation
> riscv: compat: syscall: Add entry.S implementation
> riscv: compat: process: Add UXL_32 support in start_thread
> riscv: compat: Add elf.h implementation
> riscv: compat: Add hw capability check for elf
> riscv: compat: vdso: Add COMPAT_VDSO base code implementation
> riscv: compat: vdso: Add setup additional pages implementation
> riscv: compat: signal: Add rt_frame implementation
> riscv: compat: ptrace: Add compat_arch_ptrace implement
> riscv: compat: Add COMPAT Kbuild skeletal support
>
> arch/arm64/Kconfig | 4 -
> arch/arm64/include/asm/compat.h | 93 +------
> arch/arm64/include/asm/unistd.h | 1 +
> arch/mips/Kconfig | 5 -
> arch/mips/include/asm/compat.h | 41 +--
> arch/mips/include/asm/unistd.h | 2 +
> arch/mips/include/uapi/asm/fcntl.h | 30 +--
> arch/parisc/Kconfig | 4 -
> arch/parisc/include/asm/compat.h | 45 +---
> arch/parisc/include/asm/unistd.h | 1 +
> arch/powerpc/Kconfig | 5 -
> arch/powerpc/include/asm/compat.h | 50 +---
> arch/powerpc/include/asm/unistd.h | 1 +
> arch/riscv/Kconfig | 19 ++
> arch/riscv/Makefile | 9 +
> arch/riscv/include/asm/compat.h | 129 ++++++++++
> arch/riscv/include/asm/csr.h | 7 +
> arch/riscv/include/asm/elf.h | 50 +++-
> arch/riscv/include/asm/mmu.h | 1 +
> arch/riscv/include/asm/pgtable.h | 13 +-
> arch/riscv/include/asm/processor.h | 6 +-
> arch/riscv/include/asm/syscall.h | 1 +
> arch/riscv/include/asm/thread_info.h | 1 +
> arch/riscv/include/asm/unistd.h | 11 +
> arch/riscv/include/asm/vdso.h | 9 +
> arch/riscv/include/uapi/asm/unistd.h | 2 +-
> arch/riscv/kernel/Makefile | 3 +
> arch/riscv/kernel/compat_signal.c | 242 ++++++++++++++++++
> arch/riscv/kernel/compat_syscall_table.c | 19 ++
> arch/riscv/kernel/compat_vdso/.gitignore | 2 +
> arch/riscv/kernel/compat_vdso/Makefile | 78 ++++++
> arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +
> .../kernel/compat_vdso/compat_vdso.lds.S | 3 +
> arch/riscv/kernel/compat_vdso/flush_icache.S | 3 +
> .../compat_vdso/gen_compat_vdso_offsets.sh | 5 +
> arch/riscv/kernel/compat_vdso/getcpu.S | 3 +
> arch/riscv/kernel/compat_vdso/note.S | 3 +
> arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 +
> arch/riscv/kernel/entry.S | 18 +-
> arch/riscv/kernel/process.c | 37 +++
> arch/riscv/kernel/ptrace.c | 87 ++++++-
> arch/riscv/kernel/signal.c | 13 +-
> arch/riscv/kernel/sys_riscv.c | 6 +-
> arch/riscv/kernel/vdso.c | 105 +++++---
> arch/riscv/kernel/vdso/vdso.S | 6 +-
> arch/s390/Kconfig | 3 -
> arch/s390/include/asm/compat.h | 99 +------
> arch/s390/include/asm/unistd.h | 1 +
> arch/sparc/Kconfig | 5 -
> arch/sparc/include/asm/compat.h | 61 ++---
> arch/sparc/include/asm/unistd.h | 1 +
> arch/x86/Kconfig | 4 -
> arch/x86/include/asm/compat.h | 104 ++------
> arch/x86/include/asm/unistd.h | 1 +
> fs/open.c | 24 ++
> fs/read_write.c | 16 ++
> fs/stat.c | 2 +-
> fs/sync.c | 9 +
> include/asm-generic/compat.h | 113 ++++++++
> include/linux/compat.h | 68 +++++
> include/uapi/asm-generic/fcntl.h | 23 +-
> include/uapi/asm-generic/unistd.h | 4 +-
> init/Kconfig | 4 +
> mm/fadvise.c | 11 +
> mm/readahead.c | 7 +
> tools/include/uapi/asm-generic/fcntl.h | 21 +-
> tools/include/uapi/asm-generic/unistd.h | 4 +-
> 67 files changed, 1206 insertions(+), 563 deletions(-)
> create mode 100644 arch/riscv/include/asm/compat.h
> create mode 100644 arch/riscv/kernel/compat_signal.c
> create mode 100644 arch/riscv/kernel/compat_syscall_table.c
> create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore
> create mode 100644 arch/riscv/kernel/compat_vdso/Makefile
> create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S
> create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
> create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S
> create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
> create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S
> create mode 100644 arch/riscv/kernel/compat_vdso/note.S
> create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S
>
> --
> 2.25.1
>
--
Best Regards
Guo Ren
ML: https://lore.kernel.org/linux-csky/
On Fri, Apr 29, 2022 at 2:22 AM Palmer Dabbelt <[email protected]> wrote:
>
> On Thu, 28 Apr 2022 05:25:19 PDT (-0700), [email protected] wrote:
> > Hi Palmer,
> >
> > I see you have taken v12 into your riscv-compat branch and added
> > asm/signal32.h. Do you need me help put compat_sigcontext &
> > compat_ucontext & compat_rt_sigframe into signal32.h? And could we
> > rename signal32.h to compat_signal.h to match compat_signal.c?
> >
> > In the end, thx for taking care of compat patch series.
>
> No problem. I was just trying to get something clean through all the
> autobuilders before making it look good, I think it didn't fail this
> time so I'll do a bit more refactoring. Shouldn't be too much longer at
> this point.
Cool, thank you. Hope it could be in v5.19.
>
> >
> >
> > On Tue, Apr 5, 2022 at 3:13 PM <[email protected]> wrote:
> >>
> >> From: Guo Ren <[email protected]>
> >>
> >> Currently, most 64-bit architectures (x86, parisc, powerpc, arm64,
> >> s390, mips, sparc) have supported COMPAT mode. But they all have
> >> history issues and can't use standard linux unistd.h. RISC-V would
> >> be first standard __SYSCALL_COMPAT user of include/uapi/asm-generic
> >> /unistd.h.
> >>
> >> The patchset are based on v5.18-rc1, you can compare rv64-compat
> >> v.s. rv32-native in qemu with following steps:
> >>
> >> - Prepare rv32 rootfs & fw_jump.bin by buildroot.org
> >> $ git clone git://git.busybox.net/buildroot
> >> $ cd buildroot
> >> $ make qemu_riscv32_virt_defconfig O=qemu_riscv32_virt_defconfig
> >> $ make -C qemu_riscv32_virt_defconfig
> >> $ make qemu_riscv64_virt_defconfig O=qemu_riscv64_virt_defconfig
> >> $ make -C qemu_riscv64_virt_defconfig
> >> (Got fw_jump.bin & rootfs.ext2 in qemu_riscvXX_virt_defconfig/images)
> >>
> >> - Prepare Linux rv32 & rv64 Image
> >> $ git clone [email protected]:c-sky/csky-linux.git -b riscv_compat_v12 linux
> >> $ cd linux
> >> $ echo "CONFIG_STRICT_KERNEL_RWX=n" >> arch/riscv/configs/defconfig
> >> $ echo "CONFIG_STRICT_MODULE_RWX=n" >> arch/riscv/configs/defconfig
> >> $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ rv32_defconfig
> >> $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ Image
> >> $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ defconfig
> >> $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ Image
> >>
> >> - Prepare Qemu:
> >> $ git clone https://gitlab.com/qemu-project/qemu.git -b master linux
> >> $ cd qemu
> >> $ ./configure --target-list="riscv64-softmmu riscv32-softmmu"
> >> $ make
> >>
> >> Now let's compare rv64-compat with rv32-native memory footprint with almost the same
> >> defconfig, rootfs, opensbi in one qemu.
> >>
> >> - Run rv64 with rv32 rootfs in compat mode:
> >> $ ./build/qemu-system-riscv64 -cpu rv64 -M virt -m 64m -nographic -bios qemu_riscv64_virt_defconfig/images/fw_jump.bin -kernel build-rv64/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv64-unknown-linux-gnu-gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.37) #96 SMP Tue Dec 28 21:01:55 CST 2021
> >> [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
> >> [ 0.000000] Machine model: riscv-virtio,qemu
> >> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> >> [ 0.000000] printk: bootconsole [sbi0] enabled
> >> [ 0.000000] efi: UEFI not found.
> >> [ 0.000000] Zone ranges:
> >> [ 0.000000] DMA32 [mem 0x0000000080200000-0x0000000083ffffff]
> >> [ 0.000000] Normal empty
> >> [ 0.000000] Movable zone start for each node
> >> [ 0.000000] Early memory node ranges
> >> [ 0.000000] node 0: [mem 0x0000000080200000-0x0000000083ffffff]
> >> [ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x0000000083ffffff]
> >> [ 0.000000] SBI specification v0.2 detected
> >> [ 0.000000] SBI implementation ID=0x1 Version=0x9
> >> [ 0.000000] SBI TIME extension detected
> >> [ 0.000000] SBI IPI extension detected
> >> [ 0.000000] SBI RFENCE extension detected
> >> [ 0.000000] SBI v0.2 HSM extension detected
> >> [ 0.000000] riscv: ISA extensions acdfhimsu
> >> [ 0.000000] riscv: ELF capabilities acdfim
> >> [ 0.000000] percpu: Embedded 17 pages/cpu s30696 r8192 d30744 u69632
> >> [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15655
> >> [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
> >> [ 0.000000] Dentry cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
> >> [ 0.000000] Inode-cache hash table entries: 4096 (order: 3, 32768 bytes, linear)
> >> [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
> >> [ 0.000000] Virtual kernel memory layout:
> >> [ 0.000000] fixmap : 0xffffffcefee00000 - 0xffffffceff000000 (2048 kB)
> >> [ 0.000000] pci io : 0xffffffceff000000 - 0xffffffcf00000000 ( 16 MB)
> >> [ 0.000000] vmemmap : 0xffffffcf00000000 - 0xffffffcfffffffff (4095 MB)
> >> [ 0.000000] vmalloc : 0xffffffd000000000 - 0xffffffdfffffffff (65535 MB)
> >> [ 0.000000] lowmem : 0xffffffe000000000 - 0xffffffe003e00000 ( 62 MB)
> >> [ 0.000000] kernel : 0xffffffff80000000 - 0xffffffffffffffff (2047 MB)
> >> [ 0.000000] Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved, 0K cma-reserved)
> >> [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> >> [ 0.000000] rcu: Hierarchical RCU implementation.
> >> [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
> >> [ 0.000000] rcu: RCU debug extended QS entry/exit.
> >> [ 0.000000] Tracing variant of Tasks RCU enabled.
> >> [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> >> [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
> >> [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> >> [ 0.000000] riscv-intc: 64 local interrupts mapped
> >> [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
> >> ...
> >> Welcome to Buildroot
> >> buildroot login: root
> >> # cat /proc/cpuinfo
> >> processor : 0
> >> hart : 0
> >> isa : rv64imafdcsuh
> >> mmu : sv48
> >>
> >> # file /bin/busybox
> >> /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
> >> # ca[ 78.386630] random: fast init done
> >> # cat /proc/meminfo
> >> MemTotal: 53076 kB
> >> MemFree: 40264 kB
> >> MemAvailable: 40244 kB
> >> Buffers: 236 kB
> >> Cached: 1560 kB
> >> SwapCached: 0 kB
> >> Active: 1700 kB
> >> Inactive: 516 kB
> >> Active(anon): 40 kB
> >> Inactive(anon): 424 kB
> >> Active(file): 1660 kB
> >> Inactive(file): 92 kB
> >> Unevictable: 0 kB
> >> Mlocked: 0 kB
> >> SwapTotal: 0 kB
> >> SwapFree: 0 kB
> >> Dirty: 0 kB
> >> Writeback: 0 kB
> >> AnonPages: 444 kB
> >> Mapped: 1188 kB
> >> Shmem: 44 kB
> >> KReclaimable: 952 kB
> >> Slab: 5744 kB
> >> SReclaimable: 952 kB
> >> SUnreclaim: 4792 kB
> >> KernelStack: 624 kB
> >> PageTables: 156 kB
> >> NFS_Unstable: 0 kB
> >> Bounce: 0 kB
> >> WritebackTmp: 0 kB
> >> CommitLimit: 26536 kB
> >> Committed_AS: 1748 kB
> >> VmallocTotal: 67108863 kB
> >> VmallocUsed: 652 kB
> >> VmallocChunk: 0 kB
> >> Percpu: 80 kB
> >> #
> >>
> >> - Run rv32 with rv32 rootfs:
> >> $ ./build/qemu-system-riscv32 -cpu rv32 -M virt -m 64m -nographic -bios qemu_riscv32_virt_defconfig/images/fw_jump.bin -kernel build-rv32/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.11-201-g7600ca7960-dirty) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #7 SMP Tue Dec 28 21:02:21 CST 2021
> >> [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80400000
> >> [ 0.000000] Machine model: riscv-virtio,qemu
> >> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> >> [ 0.000000] printk: bootconsole [sbi0] enabled
> >> [ 0.000000] efi: UEFI not found.
> >> [ 0.000000] Zone ranges:
> >> [ 0.000000] Normal [mem 0x0000000080400000-0x0000000083ffffff]
> >> [ 0.000000] Movable zone start for each node
> >> [ 0.000000] Early memory node ranges
> >> [ 0.000000] node 0: [mem 0x0000000080400000-0x0000000083ffffff]
> >> [ 0.000000] Initmem setup node 0 [mem 0x0000000080400000-0x0000000083ffffff]
> >> [ 0.000000] SBI specification v0.2 detected
> >> [ 0.000000] SBI implementation ID=0x1 Version=0x9
> >> [ 0.000000] SBI TIME extension detected
> >> [ 0.000000] SBI IPI extension detected
> >> [ 0.000000] SBI RFENCE extension detected
> >> [ 0.000000] SBI v0.2 HSM extension detected
> >> [ 0.000000] riscv: ISA extensions acdfhimsu
> >> [ 0.000000] riscv: ELF capabilities acdfim
> >> [ 0.000000] percpu: Embedded 12 pages/cpu s16600 r8192 d24360 u49152
> >> [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15240
> >> [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
> >> [ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
> >> [ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
> >> [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
> >> [ 0.000000] Virtual kernel memory layout:
> >> [ 0.000000] fixmap : 0x9dc00000 - 0x9e000000 (4096 kB)
> >> [ 0.000000] pci io : 0x9e000000 - 0x9f000000 ( 16 MB)
> >> [ 0.000000] vmemmap : 0x9f000000 - 0x9fffffff ( 15 MB)
> >> [ 0.000000] vmalloc : 0xa0000000 - 0xbfffffff ( 511 MB)
> >> [ 0.000000] lowmem : 0xc0000000 - 0xc3c00000 ( 60 MB)
> >> [ 0.000000] Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved, 0K cma-reserved)
> >> [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> >> [ 0.000000] rcu: Hierarchical RCU implementation.
> >> [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
> >> [ 0.000000] rcu: RCU debug extended QS entry/exit.
> >> [ 0.000000] Tracing variant of Tasks RCU enabled.
> >> [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> >> [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
> >> [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> >> [ 0.000000] riscv-intc: 32 local interrupts mapped
> >> [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
> >> ...
> >> Welcome to Buildroot
> >> buildroot login: root
> >> # cat /proc/cpuinfo
> >> processor : 0
> >> hart : 0
> >> isa : rv32imafdcsuh
> >> mmu : sv32
> >>
> >> # file /bin/busybox
> >> /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
> >> [ 79.320589] random: fast init done
> >> # cat /proc/meminfo
> >> MemTotal: 52176 kB
> >> MemFree: 41012 kB
> >> MemAvailable: 42176 kB
> >> Buffers: 644 kB
> >> Cached: 2724 kB
> >> SwapCached: 0 kB
> >> Active: 3128 kB
> >> Inactive: 752 kB
> >> Active(anon): 40 kB
> >> Inactive(anon): 516 kB
> >> Active(file): 3088 kB
> >> Inactive(file): 236 kB
> >> Unevictable: 0 kB
> >> Mlocked: 0 kB
> >> SwapTotal: 0 kB
> >> SwapFree: 0 kB
> >> Dirty: 4 kB
> >> Writeback: 0 kB
> >> AnonPages: 556 kB
> >> Mapped: 2172 kB
> >> Shmem: 44 kB
> >> KReclaimable: 656 kB
> >> Slab: 3684 kB
> >> SReclaimable: 656 kB
> >> SUnreclaim: 3028 kB
> >> KernelStack: 312 kB
> >> PageTables: 88 kB
> >> NFS_Unstable: 0 kB
> >> Bounce: 0 kB
> >> WritebackTmp: 0 kB
> >> CommitLimit: 26088 kB
> >> Committed_AS: 2088 kB
> >> VmallocTotal: 524287 kB
> >> VmallocUsed: 12 kB
> >> VmallocChunk: 0 kB
> >> Percpu: 60 kB
> >> #
> >>
> >> Some conclusions:
> >> - kernel statics:
> >> 64: Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved)
> >> 32: Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved)
> >> rv32 better than rv64: 1% 22% 17% 13% 19% 11%
> >> The code size is very similar, but data size rv32 would be better.
> >>
> >> - rv32 kernel runtime KernelStack, Slab... are smaller,
> >> rv64: MemTotal: 53076 kB, MemFree: 40264 kB
> >> rv32: MemTotal: 52176 + 2048 kB, MemFree: 41012 + 2048 kB
> >> rv32 better than rv64: 2% 6%
> >>
> >> (Because opensbi problem, we could add another 2MB for rv32.)
> >> Overall in 64MB memory situation, rv64-compat is 6% worse than rv32-native
> >> at memory footprint. If the userspace memory usage increases, I think
> >> the gap will be further reduced.
> >>
> >> Changes in v12:
> >> - Rebase on 5.18-rc1
> >> - Fixup compile conflicts with 5.18-rc1
> >> - Fixup $(srctree) == $(objtree) compile error reported by Nathan
> >>
> >> Changes in v11:
> >> - Using arch instead of kconfig for commit subject by Masahiro Yamada
> >>
> >> Changes in v10:
> >> - Fixup arm64 compile error with compat_statfs definition
> >> - Fixup compat_sys_fadvise64_64 function arguments error cause ltp failure
> >>
> >> Changes in v9:
> >> - Fixup rv32 call rv64 segment fault
> >> - Ready for 5.18
> >>
> >> Changes in v8:
> >> - Enhanced elf_check_arch with EI_CLASS
> >> - Fixup SR_UXL doesn't exist in CONFIG_32BIT
> >> - Add Tested-by with Heiko
> >> - Update qemu compile tips with upstream repo
> >>
> >> Changes in v7:
> >> - Re-construct compat_vdso/Makefile
> >> - Fixup disable COMPAT compile error by csr.h's macro.
> >> - Optimize coding convention for lo/hi in compat.h
> >>
> >> Changes in v6:
> >> - Rebase on linux-5.17-rc5
> >> - Optimize hw capability check for elf
> >> - Optimize comment in thread_info.h
> >> - Optimize start_thread with SR_UXL setting
> >> - Optimize vdso.c with direct panic
> >>
> >> Changes in v5:
> >> - Rebase on linux-5.17-rc2
> >> - Include consolidate the fcntl patches by Christoph Hellwig
> >> - Remove F_GETLK64/F_SETLK64/F_SETLKW64 from asm/compat.h
> >> - Change COMPAT_RLIM_INFINITY from 0x7fffffff to 0xffffffff
> >> - Bring back "Add hw-cap detect in setup_arch patch" in v1
> >>
> >> Changes in v4:
> >> - Rebase on linux-5.17-rc1
> >> - Optimize compat_sys_call_table implementation with Arnd's advice
> >> - Add reviewed-by for Arnd. Thx :)
> >> - Remove FIXME comment in elf.h
> >> - Optimize Cleanup duplicate definitions in compat.h with Arnd's advice
> >>
> >> Changes in v3:
> >> - Rebase on newest master (pre linux-5.17-rc1)
> >> - Using newest qemu version v7 for test
> >> - Remove fcntl common modification
> >> - Fixup SET_PERSONALITY in elf.h by Arnd
> >> - Fixup KVM Kconfig
> >> - Update Acked-by & Reviewed-by
> >>
> >> Changes in v2:
> >> - Add __ARCH_WANT_COMPAT_STAT suggested
> >> - Cleanup fcntl compatduplicate definitions
> >> - Cleanup compat.h
> >> - Move rv32_defconfig into Makefile
> >> - Fixup rv64 rootfs boot failed, remove hw_compat_mode_detect
> >> - Move SYSVIPC_COMPAT into init/Kconfig
> >> - Simplify compat_elf_check
> >>
> >> Christoph Hellwig (3):
> >> uapi: simplify __ARCH_FLOCK{,64}_PAD a little
> >> uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
> >> compat: consolidate the compat_flock{,64} definition
> >>
> >> Guo Ren (17):
> >> arch: Add SYSVIPC_COMPAT for all architectures
> >> fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT
> >> asm-generic: compat: Cleanup duplicate definitions
> >> syscalls: compat: Fix the missing part for __SYSCALL_COMPAT
> >> riscv: Fixup difference with defconfig
> >> riscv: compat: Add basic compat data type implementation
> >> riscv: compat: Support TASK_SIZE for compat mode
> >> riscv: compat: syscall: Add compat_sys_call_table implementation
> >> riscv: compat: syscall: Add entry.S implementation
> >> riscv: compat: process: Add UXL_32 support in start_thread
> >> riscv: compat: Add elf.h implementation
> >> riscv: compat: Add hw capability check for elf
> >> riscv: compat: vdso: Add COMPAT_VDSO base code implementation
> >> riscv: compat: vdso: Add setup additional pages implementation
> >> riscv: compat: signal: Add rt_frame implementation
> >> riscv: compat: ptrace: Add compat_arch_ptrace implement
> >> riscv: compat: Add COMPAT Kbuild skeletal support
> >>
> >> arch/arm64/Kconfig | 4 -
> >> arch/arm64/include/asm/compat.h | 93 +------
> >> arch/arm64/include/asm/unistd.h | 1 +
> >> arch/mips/Kconfig | 5 -
> >> arch/mips/include/asm/compat.h | 41 +--
> >> arch/mips/include/asm/unistd.h | 2 +
> >> arch/mips/include/uapi/asm/fcntl.h | 30 +--
> >> arch/parisc/Kconfig | 4 -
> >> arch/parisc/include/asm/compat.h | 45 +---
> >> arch/parisc/include/asm/unistd.h | 1 +
> >> arch/powerpc/Kconfig | 5 -
> >> arch/powerpc/include/asm/compat.h | 50 +---
> >> arch/powerpc/include/asm/unistd.h | 1 +
> >> arch/riscv/Kconfig | 19 ++
> >> arch/riscv/Makefile | 9 +
> >> arch/riscv/include/asm/compat.h | 129 ++++++++++
> >> arch/riscv/include/asm/csr.h | 7 +
> >> arch/riscv/include/asm/elf.h | 50 +++-
> >> arch/riscv/include/asm/mmu.h | 1 +
> >> arch/riscv/include/asm/pgtable.h | 13 +-
> >> arch/riscv/include/asm/processor.h | 6 +-
> >> arch/riscv/include/asm/syscall.h | 1 +
> >> arch/riscv/include/asm/thread_info.h | 1 +
> >> arch/riscv/include/asm/unistd.h | 11 +
> >> arch/riscv/include/asm/vdso.h | 9 +
> >> arch/riscv/include/uapi/asm/unistd.h | 2 +-
> >> arch/riscv/kernel/Makefile | 3 +
> >> arch/riscv/kernel/compat_signal.c | 242 ++++++++++++++++++
> >> arch/riscv/kernel/compat_syscall_table.c | 19 ++
> >> arch/riscv/kernel/compat_vdso/.gitignore | 2 +
> >> arch/riscv/kernel/compat_vdso/Makefile | 78 ++++++
> >> arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +
> >> .../kernel/compat_vdso/compat_vdso.lds.S | 3 +
> >> arch/riscv/kernel/compat_vdso/flush_icache.S | 3 +
> >> .../compat_vdso/gen_compat_vdso_offsets.sh | 5 +
> >> arch/riscv/kernel/compat_vdso/getcpu.S | 3 +
> >> arch/riscv/kernel/compat_vdso/note.S | 3 +
> >> arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 +
> >> arch/riscv/kernel/entry.S | 18 +-
> >> arch/riscv/kernel/process.c | 37 +++
> >> arch/riscv/kernel/ptrace.c | 87 ++++++-
> >> arch/riscv/kernel/signal.c | 13 +-
> >> arch/riscv/kernel/sys_riscv.c | 6 +-
> >> arch/riscv/kernel/vdso.c | 105 +++++---
> >> arch/riscv/kernel/vdso/vdso.S | 6 +-
> >> arch/s390/Kconfig | 3 -
> >> arch/s390/include/asm/compat.h | 99 +------
> >> arch/s390/include/asm/unistd.h | 1 +
> >> arch/sparc/Kconfig | 5 -
> >> arch/sparc/include/asm/compat.h | 61 ++---
> >> arch/sparc/include/asm/unistd.h | 1 +
> >> arch/x86/Kconfig | 4 -
> >> arch/x86/include/asm/compat.h | 104 ++------
> >> arch/x86/include/asm/unistd.h | 1 +
> >> fs/open.c | 24 ++
> >> fs/read_write.c | 16 ++
> >> fs/stat.c | 2 +-
> >> fs/sync.c | 9 +
> >> include/asm-generic/compat.h | 113 ++++++++
> >> include/linux/compat.h | 68 +++++
> >> include/uapi/asm-generic/fcntl.h | 23 +-
> >> include/uapi/asm-generic/unistd.h | 4 +-
> >> init/Kconfig | 4 +
> >> mm/fadvise.c | 11 +
> >> mm/readahead.c | 7 +
> >> tools/include/uapi/asm-generic/fcntl.h | 21 +-
> >> tools/include/uapi/asm-generic/unistd.h | 4 +-
> >> 67 files changed, 1206 insertions(+), 563 deletions(-)
> >> create mode 100644 arch/riscv/include/asm/compat.h
> >> create mode 100644 arch/riscv/kernel/compat_signal.c
> >> create mode 100644 arch/riscv/kernel/compat_syscall_table.c
> >> create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore
> >> create mode 100644 arch/riscv/kernel/compat_vdso/Makefile
> >> create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S
> >> create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
> >> create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S
> >> create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
> >> create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S
> >> create mode 100644 arch/riscv/kernel/compat_vdso/note.S
> >> create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S
> >>
> >> --
> >> 2.25.1
> >>
--
Best Regards
Guo Ren
ML: https://lore.kernel.org/linux-csky/
On Tue, 05 Apr 2022 00:12:54 PDT (-0700), [email protected] wrote:
> From: Guo Ren <[email protected]>
>
> Currently, most 64-bit architectures (x86, parisc, powerpc, arm64,
> s390, mips, sparc) have supported COMPAT mode. But they all have
> history issues and can't use standard linux unistd.h. RISC-V would
> be first standard __SYSCALL_COMPAT user of include/uapi/asm-generic
> /unistd.h.
>
> The patchset are based on v5.18-rc1, you can compare rv64-compat
> v.s. rv32-native in qemu with following steps:
>
> - Prepare rv32 rootfs & fw_jump.bin by buildroot.org
> $ git clone git://git.busybox.net/buildroot
> $ cd buildroot
> $ make qemu_riscv32_virt_defconfig O=qemu_riscv32_virt_defconfig
> $ make -C qemu_riscv32_virt_defconfig
> $ make qemu_riscv64_virt_defconfig O=qemu_riscv64_virt_defconfig
> $ make -C qemu_riscv64_virt_defconfig
> (Got fw_jump.bin & rootfs.ext2 in qemu_riscvXX_virt_defconfig/images)
>
> - Prepare Linux rv32 & rv64 Image
> $ git clone [email protected]:c-sky/csky-linux.git -b riscv_compat_v12 linux
> $ cd linux
> $ echo "CONFIG_STRICT_KERNEL_RWX=n" >> arch/riscv/configs/defconfig
> $ echo "CONFIG_STRICT_MODULE_RWX=n" >> arch/riscv/configs/defconfig
> $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ rv32_defconfig
> $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ Image
> $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ defconfig
> $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ Image
>
> - Prepare Qemu:
> $ git clone https://gitlab.com/qemu-project/qemu.git -b master linux
> $ cd qemu
> $ ./configure --target-list="riscv64-softmmu riscv32-softmmu"
> $ make
>
> Now let's compare rv64-compat with rv32-native memory footprint with almost the same
> defconfig, rootfs, opensbi in one qemu.
>
> - Run rv64 with rv32 rootfs in compat mode:
> $ ./build/qemu-system-riscv64 -cpu rv64 -M virt -m 64m -nographic -bios qemu_riscv64_virt_defconfig/images/fw_jump.bin -kernel build-rv64/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv64-unknown-linux-gnu-gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.37) #96 SMP Tue Dec 28 21:01:55 CST 2021
> [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
> [ 0.000000] Machine model: riscv-virtio,qemu
> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> [ 0.000000] printk: bootconsole [sbi0] enabled
> [ 0.000000] efi: UEFI not found.
> [ 0.000000] Zone ranges:
> [ 0.000000] DMA32 [mem 0x0000000080200000-0x0000000083ffffff]
> [ 0.000000] Normal empty
> [ 0.000000] Movable zone start for each node
> [ 0.000000] Early memory node ranges
> [ 0.000000] node 0: [mem 0x0000000080200000-0x0000000083ffffff]
> [ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x0000000083ffffff]
> [ 0.000000] SBI specification v0.2 detected
> [ 0.000000] SBI implementation ID=0x1 Version=0x9
> [ 0.000000] SBI TIME extension detected
> [ 0.000000] SBI IPI extension detected
> [ 0.000000] SBI RFENCE extension detected
> [ 0.000000] SBI v0.2 HSM extension detected
> [ 0.000000] riscv: ISA extensions acdfhimsu
> [ 0.000000] riscv: ELF capabilities acdfim
> [ 0.000000] percpu: Embedded 17 pages/cpu s30696 r8192 d30744 u69632
> [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15655
> [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
> [ 0.000000] Dentry cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
> [ 0.000000] Inode-cache hash table entries: 4096 (order: 3, 32768 bytes, linear)
> [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
> [ 0.000000] Virtual kernel memory layout:
> [ 0.000000] fixmap : 0xffffffcefee00000 - 0xffffffceff000000 (2048 kB)
> [ 0.000000] pci io : 0xffffffceff000000 - 0xffffffcf00000000 ( 16 MB)
> [ 0.000000] vmemmap : 0xffffffcf00000000 - 0xffffffcfffffffff (4095 MB)
> [ 0.000000] vmalloc : 0xffffffd000000000 - 0xffffffdfffffffff (65535 MB)
> [ 0.000000] lowmem : 0xffffffe000000000 - 0xffffffe003e00000 ( 62 MB)
> [ 0.000000] kernel : 0xffffffff80000000 - 0xffffffffffffffff (2047 MB)
> [ 0.000000] Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved, 0K cma-reserved)
> [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> [ 0.000000] rcu: Hierarchical RCU implementation.
> [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
> [ 0.000000] rcu: RCU debug extended QS entry/exit.
> [ 0.000000] Tracing variant of Tasks RCU enabled.
> [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
> [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> [ 0.000000] riscv-intc: 64 local interrupts mapped
> [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
> ...
> Welcome to Buildroot
> buildroot login: root
> # cat /proc/cpuinfo
> processor : 0
> hart : 0
> isa : rv64imafdcsuh
> mmu : sv48
>
> # file /bin/busybox
> /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
> # ca[ 78.386630] random: fast init done
> # cat /proc/meminfo
> MemTotal: 53076 kB
> MemFree: 40264 kB
> MemAvailable: 40244 kB
> Buffers: 236 kB
> Cached: 1560 kB
> SwapCached: 0 kB
> Active: 1700 kB
> Inactive: 516 kB
> Active(anon): 40 kB
> Inactive(anon): 424 kB
> Active(file): 1660 kB
> Inactive(file): 92 kB
> Unevictable: 0 kB
> Mlocked: 0 kB
> SwapTotal: 0 kB
> SwapFree: 0 kB
> Dirty: 0 kB
> Writeback: 0 kB
> AnonPages: 444 kB
> Mapped: 1188 kB
> Shmem: 44 kB
> KReclaimable: 952 kB
> Slab: 5744 kB
> SReclaimable: 952 kB
> SUnreclaim: 4792 kB
> KernelStack: 624 kB
> PageTables: 156 kB
> NFS_Unstable: 0 kB
> Bounce: 0 kB
> WritebackTmp: 0 kB
> CommitLimit: 26536 kB
> Committed_AS: 1748 kB
> VmallocTotal: 67108863 kB
> VmallocUsed: 652 kB
> VmallocChunk: 0 kB
> Percpu: 80 kB
> #
>
> - Run rv32 with rv32 rootfs:
> $ ./build/qemu-system-riscv32 -cpu rv32 -M virt -m 64m -nographic -bios qemu_riscv32_virt_defconfig/images/fw_jump.bin -kernel build-rv32/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.11-201-g7600ca7960-dirty) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #7 SMP Tue Dec 28 21:02:21 CST 2021
> [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80400000
> [ 0.000000] Machine model: riscv-virtio,qemu
> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> [ 0.000000] printk: bootconsole [sbi0] enabled
> [ 0.000000] efi: UEFI not found.
> [ 0.000000] Zone ranges:
> [ 0.000000] Normal [mem 0x0000000080400000-0x0000000083ffffff]
> [ 0.000000] Movable zone start for each node
> [ 0.000000] Early memory node ranges
> [ 0.000000] node 0: [mem 0x0000000080400000-0x0000000083ffffff]
> [ 0.000000] Initmem setup node 0 [mem 0x0000000080400000-0x0000000083ffffff]
> [ 0.000000] SBI specification v0.2 detected
> [ 0.000000] SBI implementation ID=0x1 Version=0x9
> [ 0.000000] SBI TIME extension detected
> [ 0.000000] SBI IPI extension detected
> [ 0.000000] SBI RFENCE extension detected
> [ 0.000000] SBI v0.2 HSM extension detected
> [ 0.000000] riscv: ISA extensions acdfhimsu
> [ 0.000000] riscv: ELF capabilities acdfim
> [ 0.000000] percpu: Embedded 12 pages/cpu s16600 r8192 d24360 u49152
> [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15240
> [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
> [ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
> [ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
> [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
> [ 0.000000] Virtual kernel memory layout:
> [ 0.000000] fixmap : 0x9dc00000 - 0x9e000000 (4096 kB)
> [ 0.000000] pci io : 0x9e000000 - 0x9f000000 ( 16 MB)
> [ 0.000000] vmemmap : 0x9f000000 - 0x9fffffff ( 15 MB)
> [ 0.000000] vmalloc : 0xa0000000 - 0xbfffffff ( 511 MB)
> [ 0.000000] lowmem : 0xc0000000 - 0xc3c00000 ( 60 MB)
> [ 0.000000] Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved, 0K cma-reserved)
> [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> [ 0.000000] rcu: Hierarchical RCU implementation.
> [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
> [ 0.000000] rcu: RCU debug extended QS entry/exit.
> [ 0.000000] Tracing variant of Tasks RCU enabled.
> [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
> [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> [ 0.000000] riscv-intc: 32 local interrupts mapped
> [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
> ...
> Welcome to Buildroot
> buildroot login: root
> # cat /proc/cpuinfo
> processor : 0
> hart : 0
> isa : rv32imafdcsuh
> mmu : sv32
>
> # file /bin/busybox
> /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
> [ 79.320589] random: fast init done
> # cat /proc/meminfo
> MemTotal: 52176 kB
> MemFree: 41012 kB
> MemAvailable: 42176 kB
> Buffers: 644 kB
> Cached: 2724 kB
> SwapCached: 0 kB
> Active: 3128 kB
> Inactive: 752 kB
> Active(anon): 40 kB
> Inactive(anon): 516 kB
> Active(file): 3088 kB
> Inactive(file): 236 kB
> Unevictable: 0 kB
> Mlocked: 0 kB
> SwapTotal: 0 kB
> SwapFree: 0 kB
> Dirty: 4 kB
> Writeback: 0 kB
> AnonPages: 556 kB
> Mapped: 2172 kB
> Shmem: 44 kB
> KReclaimable: 656 kB
> Slab: 3684 kB
> SReclaimable: 656 kB
> SUnreclaim: 3028 kB
> KernelStack: 312 kB
> PageTables: 88 kB
> NFS_Unstable: 0 kB
> Bounce: 0 kB
> WritebackTmp: 0 kB
> CommitLimit: 26088 kB
> Committed_AS: 2088 kB
> VmallocTotal: 524287 kB
> VmallocUsed: 12 kB
> VmallocChunk: 0 kB
> Percpu: 60 kB
> #
>
> Some conclusions:
> - kernel statics:
> 64: Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved)
> 32: Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved)
> rv32 better than rv64: 1% 22% 17% 13% 19% 11%
> The code size is very similar, but data size rv32 would be better.
>
> - rv32 kernel runtime KernelStack, Slab... are smaller,
> rv64: MemTotal: 53076 kB, MemFree: 40264 kB
> rv32: MemTotal: 52176 + 2048 kB, MemFree: 41012 + 2048 kB
> rv32 better than rv64: 2% 6%
>
> (Because opensbi problem, we could add another 2MB for rv32.)
> Overall in 64MB memory situation, rv64-compat is 6% worse than rv32-native
> at memory footprint. If the userspace memory usage increases, I think
> the gap will be further reduced.
>
> Changes in v12:
> - Rebase on 5.18-rc1
> - Fixup compile conflicts with 5.18-rc1
> - Fixup $(srctree) == $(objtree) compile error reported by Nathan
>
> Changes in v11:
> - Using arch instead of kconfig for commit subject by Masahiro Yamada
>
> Changes in v10:
> - Fixup arm64 compile error with compat_statfs definition
> - Fixup compat_sys_fadvise64_64 function arguments error cause ltp failure
>
> Changes in v9:
> - Fixup rv32 call rv64 segment fault
> - Ready for 5.18
>
> Changes in v8:
> - Enhanced elf_check_arch with EI_CLASS
> - Fixup SR_UXL doesn't exist in CONFIG_32BIT
> - Add Tested-by with Heiko
> - Update qemu compile tips with upstream repo
>
> Changes in v7:
> - Re-construct compat_vdso/Makefile
> - Fixup disable COMPAT compile error by csr.h's macro.
> - Optimize coding convention for lo/hi in compat.h
>
> Changes in v6:
> - Rebase on linux-5.17-rc5
> - Optimize hw capability check for elf
> - Optimize comment in thread_info.h
> - Optimize start_thread with SR_UXL setting
> - Optimize vdso.c with direct panic
>
> Changes in v5:
> - Rebase on linux-5.17-rc2
> - Include consolidate the fcntl patches by Christoph Hellwig
> - Remove F_GETLK64/F_SETLK64/F_SETLKW64 from asm/compat.h
> - Change COMPAT_RLIM_INFINITY from 0x7fffffff to 0xffffffff
> - Bring back "Add hw-cap detect in setup_arch patch" in v1
>
> Changes in v4:
> - Rebase on linux-5.17-rc1
> - Optimize compat_sys_call_table implementation with Arnd's advice
> - Add reviewed-by for Arnd. Thx :)
> - Remove FIXME comment in elf.h
> - Optimize Cleanup duplicate definitions in compat.h with Arnd's advice
>
> Changes in v3:
> - Rebase on newest master (pre linux-5.17-rc1)
> - Using newest qemu version v7 for test
> - Remove fcntl common modification
> - Fixup SET_PERSONALITY in elf.h by Arnd
> - Fixup KVM Kconfig
> - Update Acked-by & Reviewed-by
>
> Changes in v2:
> - Add __ARCH_WANT_COMPAT_STAT suggested
> - Cleanup fcntl compatduplicate definitions
> - Cleanup compat.h
> - Move rv32_defconfig into Makefile
> - Fixup rv64 rootfs boot failed, remove hw_compat_mode_detect
> - Move SYSVIPC_COMPAT into init/Kconfig
> - Simplify compat_elf_check
>
> Christoph Hellwig (3):
> uapi: simplify __ARCH_FLOCK{,64}_PAD a little
> uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
> compat: consolidate the compat_flock{,64} definition
>
> Guo Ren (17):
> arch: Add SYSVIPC_COMPAT for all architectures
> fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT
> asm-generic: compat: Cleanup duplicate definitions
> syscalls: compat: Fix the missing part for __SYSCALL_COMPAT
> riscv: Fixup difference with defconfig
> riscv: compat: Add basic compat data type implementation
> riscv: compat: Support TASK_SIZE for compat mode
> riscv: compat: syscall: Add compat_sys_call_table implementation
> riscv: compat: syscall: Add entry.S implementation
> riscv: compat: process: Add UXL_32 support in start_thread
> riscv: compat: Add elf.h implementation
> riscv: compat: Add hw capability check for elf
> riscv: compat: vdso: Add COMPAT_VDSO base code implementation
> riscv: compat: vdso: Add setup additional pages implementation
> riscv: compat: signal: Add rt_frame implementation
> riscv: compat: ptrace: Add compat_arch_ptrace implement
> riscv: compat: Add COMPAT Kbuild skeletal support
>
> arch/arm64/Kconfig | 4 -
> arch/arm64/include/asm/compat.h | 93 +------
> arch/arm64/include/asm/unistd.h | 1 +
> arch/mips/Kconfig | 5 -
> arch/mips/include/asm/compat.h | 41 +--
> arch/mips/include/asm/unistd.h | 2 +
> arch/mips/include/uapi/asm/fcntl.h | 30 +--
> arch/parisc/Kconfig | 4 -
> arch/parisc/include/asm/compat.h | 45 +---
> arch/parisc/include/asm/unistd.h | 1 +
> arch/powerpc/Kconfig | 5 -
> arch/powerpc/include/asm/compat.h | 50 +---
> arch/powerpc/include/asm/unistd.h | 1 +
> arch/riscv/Kconfig | 19 ++
> arch/riscv/Makefile | 9 +
> arch/riscv/include/asm/compat.h | 129 ++++++++++
> arch/riscv/include/asm/csr.h | 7 +
> arch/riscv/include/asm/elf.h | 50 +++-
> arch/riscv/include/asm/mmu.h | 1 +
> arch/riscv/include/asm/pgtable.h | 13 +-
> arch/riscv/include/asm/processor.h | 6 +-
> arch/riscv/include/asm/syscall.h | 1 +
> arch/riscv/include/asm/thread_info.h | 1 +
> arch/riscv/include/asm/unistd.h | 11 +
> arch/riscv/include/asm/vdso.h | 9 +
> arch/riscv/include/uapi/asm/unistd.h | 2 +-
> arch/riscv/kernel/Makefile | 3 +
> arch/riscv/kernel/compat_signal.c | 242 ++++++++++++++++++
> arch/riscv/kernel/compat_syscall_table.c | 19 ++
> arch/riscv/kernel/compat_vdso/.gitignore | 2 +
> arch/riscv/kernel/compat_vdso/Makefile | 78 ++++++
> arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +
> .../kernel/compat_vdso/compat_vdso.lds.S | 3 +
> arch/riscv/kernel/compat_vdso/flush_icache.S | 3 +
> .../compat_vdso/gen_compat_vdso_offsets.sh | 5 +
> arch/riscv/kernel/compat_vdso/getcpu.S | 3 +
> arch/riscv/kernel/compat_vdso/note.S | 3 +
> arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 +
> arch/riscv/kernel/entry.S | 18 +-
> arch/riscv/kernel/process.c | 37 +++
> arch/riscv/kernel/ptrace.c | 87 ++++++-
> arch/riscv/kernel/signal.c | 13 +-
> arch/riscv/kernel/sys_riscv.c | 6 +-
> arch/riscv/kernel/vdso.c | 105 +++++---
> arch/riscv/kernel/vdso/vdso.S | 6 +-
> arch/s390/Kconfig | 3 -
> arch/s390/include/asm/compat.h | 99 +------
> arch/s390/include/asm/unistd.h | 1 +
> arch/sparc/Kconfig | 5 -
> arch/sparc/include/asm/compat.h | 61 ++---
> arch/sparc/include/asm/unistd.h | 1 +
> arch/x86/Kconfig | 4 -
> arch/x86/include/asm/compat.h | 104 ++------
> arch/x86/include/asm/unistd.h | 1 +
> fs/open.c | 24 ++
> fs/read_write.c | 16 ++
> fs/stat.c | 2 +-
> fs/sync.c | 9 +
> include/asm-generic/compat.h | 113 ++++++++
> include/linux/compat.h | 68 +++++
> include/uapi/asm-generic/fcntl.h | 23 +-
> include/uapi/asm-generic/unistd.h | 4 +-
> init/Kconfig | 4 +
> mm/fadvise.c | 11 +
> mm/readahead.c | 7 +
> tools/include/uapi/asm-generic/fcntl.h | 21 +-
> tools/include/uapi/asm-generic/unistd.h | 4 +-
> 67 files changed, 1206 insertions(+), 563 deletions(-)
> create mode 100644 arch/riscv/include/asm/compat.h
> create mode 100644 arch/riscv/kernel/compat_signal.c
> create mode 100644 arch/riscv/kernel/compat_syscall_table.c
> create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore
> create mode 100644 arch/riscv/kernel/compat_vdso/Makefile
> create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S
> create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
> create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S
> create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
> create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S
> create mode 100644 arch/riscv/kernel/compat_vdso/note.S
> create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S
Thanks.
This touches a bunch of other trees, which I try to avoid without the
relevant acks and such. In this case I'm OK taking it because Arnd and
Christoph have written/reviewed/ack'd so much of it, and because some
autobuilders found build issues (and thus I'm assuming there aren't any
more).
There's been a bunch of versions of this and I'm pretty sure I've said
this a handful of times without any comments. Now that it's passing all
my tests and I'm not getting any autobuilding breakages I've put it on
for-next, but happy to try and spin up some sort of multi-tree merge if
that's an issue for anyone.
On Fri, May 20, 2022 at 1:50 AM Palmer Dabbelt <[email protected]> wrote:
>
> On Tue, 05 Apr 2022 00:12:54 PDT (-0700), [email protected] wrote:
> > From: Guo Ren <[email protected]>
> >
> > Currently, most 64-bit architectures (x86, parisc, powerpc, arm64,
> > s390, mips, sparc) have supported COMPAT mode. But they all have
> > history issues and can't use standard linux unistd.h. RISC-V would
> > be first standard __SYSCALL_COMPAT user of include/uapi/asm-generic
> > /unistd.h.
> >
> > The patchset are based on v5.18-rc1, you can compare rv64-compat
> > v.s. rv32-native in qemu with following steps:
> >
> > - Prepare rv32 rootfs & fw_jump.bin by buildroot.org
> > $ git clone git://git.busybox.net/buildroot
> > $ cd buildroot
> > $ make qemu_riscv32_virt_defconfig O=qemu_riscv32_virt_defconfig
> > $ make -C qemu_riscv32_virt_defconfig
> > $ make qemu_riscv64_virt_defconfig O=qemu_riscv64_virt_defconfig
> > $ make -C qemu_riscv64_virt_defconfig
> > (Got fw_jump.bin & rootfs.ext2 in qemu_riscvXX_virt_defconfig/images)
> >
> > - Prepare Linux rv32 & rv64 Image
> > $ git clone [email protected]:c-sky/csky-linux.git -b riscv_compat_v12 linux
> > $ cd linux
> > $ echo "CONFIG_STRICT_KERNEL_RWX=n" >> arch/riscv/configs/defconfig
> > $ echo "CONFIG_STRICT_MODULE_RWX=n" >> arch/riscv/configs/defconfig
> > $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ rv32_defconfig
> > $ make ARCH=riscv CROSS_COMPILE=riscv32-buildroot-linux-gnu- O=../build-rv32/ Image
> > $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ defconfig
> > $ make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- O=../build-rv64/ Image
> >
> > - Prepare Qemu:
> > $ git clone https://gitlab.com/qemu-project/qemu.git -b master linux
> > $ cd qemu
> > $ ./configure --target-list="riscv64-softmmu riscv32-softmmu"
> > $ make
> >
> > Now let's compare rv64-compat with rv32-native memory footprint with almost the same
> > defconfig, rootfs, opensbi in one qemu.
> >
> > - Run rv64 with rv32 rootfs in compat mode:
> > $ ./build/qemu-system-riscv64 -cpu rv64 -M virt -m 64m -nographic -bios qemu_riscv64_virt_defconfig/images/fw_jump.bin -kernel build-rv64/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv64-unknown-linux-gnu-gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.37) #96 SMP Tue Dec 28 21:01:55 CST 2021
> > [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
> > [ 0.000000] Machine model: riscv-virtio,qemu
> > [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> > [ 0.000000] printk: bootconsole [sbi0] enabled
> > [ 0.000000] efi: UEFI not found.
> > [ 0.000000] Zone ranges:
> > [ 0.000000] DMA32 [mem 0x0000000080200000-0x0000000083ffffff]
> > [ 0.000000] Normal empty
> > [ 0.000000] Movable zone start for each node
> > [ 0.000000] Early memory node ranges
> > [ 0.000000] node 0: [mem 0x0000000080200000-0x0000000083ffffff]
> > [ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x0000000083ffffff]
> > [ 0.000000] SBI specification v0.2 detected
> > [ 0.000000] SBI implementation ID=0x1 Version=0x9
> > [ 0.000000] SBI TIME extension detected
> > [ 0.000000] SBI IPI extension detected
> > [ 0.000000] SBI RFENCE extension detected
> > [ 0.000000] SBI v0.2 HSM extension detected
> > [ 0.000000] riscv: ISA extensions acdfhimsu
> > [ 0.000000] riscv: ELF capabilities acdfim
> > [ 0.000000] percpu: Embedded 17 pages/cpu s30696 r8192 d30744 u69632
> > [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15655
> > [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
> > [ 0.000000] Dentry cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
> > [ 0.000000] Inode-cache hash table entries: 4096 (order: 3, 32768 bytes, linear)
> > [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
> > [ 0.000000] Virtual kernel memory layout:
> > [ 0.000000] fixmap : 0xffffffcefee00000 - 0xffffffceff000000 (2048 kB)
> > [ 0.000000] pci io : 0xffffffceff000000 - 0xffffffcf00000000 ( 16 MB)
> > [ 0.000000] vmemmap : 0xffffffcf00000000 - 0xffffffcfffffffff (4095 MB)
> > [ 0.000000] vmalloc : 0xffffffd000000000 - 0xffffffdfffffffff (65535 MB)
> > [ 0.000000] lowmem : 0xffffffe000000000 - 0xffffffe003e00000 ( 62 MB)
> > [ 0.000000] kernel : 0xffffffff80000000 - 0xffffffffffffffff (2047 MB)
> > [ 0.000000] Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved, 0K cma-reserved)
> > [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> > [ 0.000000] rcu: Hierarchical RCU implementation.
> > [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
> > [ 0.000000] rcu: RCU debug extended QS entry/exit.
> > [ 0.000000] Tracing variant of Tasks RCU enabled.
> > [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> > [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
> > [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> > [ 0.000000] riscv-intc: 64 local interrupts mapped
> > [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
> > ...
> > Welcome to Buildroot
> > buildroot login: root
> > # cat /proc/cpuinfo
> > processor : 0
> > hart : 0
> > isa : rv64imafdcsuh
> > mmu : sv48
> >
> > # file /bin/busybox
> > /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
> > # ca[ 78.386630] random: fast init done
> > # cat /proc/meminfo
> > MemTotal: 53076 kB
> > MemFree: 40264 kB
> > MemAvailable: 40244 kB
> > Buffers: 236 kB
> > Cached: 1560 kB
> > SwapCached: 0 kB
> > Active: 1700 kB
> > Inactive: 516 kB
> > Active(anon): 40 kB
> > Inactive(anon): 424 kB
> > Active(file): 1660 kB
> > Inactive(file): 92 kB
> > Unevictable: 0 kB
> > Mlocked: 0 kB
> > SwapTotal: 0 kB
> > SwapFree: 0 kB
> > Dirty: 0 kB
> > Writeback: 0 kB
> > AnonPages: 444 kB
> > Mapped: 1188 kB
> > Shmem: 44 kB
> > KReclaimable: 952 kB
> > Slab: 5744 kB
> > SReclaimable: 952 kB
> > SUnreclaim: 4792 kB
> > KernelStack: 624 kB
> > PageTables: 156 kB
> > NFS_Unstable: 0 kB
> > Bounce: 0 kB
> > WritebackTmp: 0 kB
> > CommitLimit: 26536 kB
> > Committed_AS: 1748 kB
> > VmallocTotal: 67108863 kB
> > VmallocUsed: 652 kB
> > VmallocChunk: 0 kB
> > Percpu: 80 kB
> > #
> >
> > - Run rv32 with rv32 rootfs:
> > $ ./build/qemu-system-riscv32 -cpu rv32 -M virt -m 64m -nographic -bios qemu_riscv32_virt_defconfig/images/fw_jump.bin -kernel build-rv32/Image -drive file qemu_riscv32_virt_defconfig/images/rootfs.ext2,format=raw,id=hd0 -device virtio-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@guoren-Z87-HD3) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.11-201-g7600ca7960-dirty) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #7 SMP Tue Dec 28 21:02:21 CST 2021
> > [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80400000
> > [ 0.000000] Machine model: riscv-virtio,qemu
> > [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> > [ 0.000000] printk: bootconsole [sbi0] enabled
> > [ 0.000000] efi: UEFI not found.
> > [ 0.000000] Zone ranges:
> > [ 0.000000] Normal [mem 0x0000000080400000-0x0000000083ffffff]
> > [ 0.000000] Movable zone start for each node
> > [ 0.000000] Early memory node ranges
> > [ 0.000000] node 0: [mem 0x0000000080400000-0x0000000083ffffff]
> > [ 0.000000] Initmem setup node 0 [mem 0x0000000080400000-0x0000000083ffffff]
> > [ 0.000000] SBI specification v0.2 detected
> > [ 0.000000] SBI implementation ID=0x1 Version=0x9
> > [ 0.000000] SBI TIME extension detected
> > [ 0.000000] SBI IPI extension detected
> > [ 0.000000] SBI RFENCE extension detected
> > [ 0.000000] SBI v0.2 HSM extension detected
> > [ 0.000000] riscv: ISA extensions acdfhimsu
> > [ 0.000000] riscv: ELF capabilities acdfim
> > [ 0.000000] percpu: Embedded 12 pages/cpu s16600 r8192 d24360 u49152
> > [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 15240
> > [ 0.000000] Kernel command line: rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi
> > [ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
> > [ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
> > [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
> > [ 0.000000] Virtual kernel memory layout:
> > [ 0.000000] fixmap : 0x9dc00000 - 0x9e000000 (4096 kB)
> > [ 0.000000] pci io : 0x9e000000 - 0x9f000000 ( 16 MB)
> > [ 0.000000] vmemmap : 0x9f000000 - 0x9fffffff ( 15 MB)
> > [ 0.000000] vmalloc : 0xa0000000 - 0xbfffffff ( 511 MB)
> > [ 0.000000] lowmem : 0xc0000000 - 0xc3c00000 ( 60 MB)
> > [ 0.000000] Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved, 0K cma-reserved)
> > [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> > [ 0.000000] rcu: Hierarchical RCU implementation.
> > [ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
> > [ 0.000000] rcu: RCU debug extended QS entry/exit.
> > [ 0.000000] Tracing variant of Tasks RCU enabled.
> > [ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> > [ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
> > [ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> > [ 0.000000] riscv-intc: 32 local interrupts mapped
> > [ 0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
> > ...
> > Welcome to Buildroot
> > buildroot login: root
> > # cat /proc/cpuinfo
> > processor : 0
> > hart : 0
> > isa : rv32imafdcsuh
> > mmu : sv32
> >
> > # file /bin/busybox
> > /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
> > [ 79.320589] random: fast init done
> > # cat /proc/meminfo
> > MemTotal: 52176 kB
> > MemFree: 41012 kB
> > MemAvailable: 42176 kB
> > Buffers: 644 kB
> > Cached: 2724 kB
> > SwapCached: 0 kB
> > Active: 3128 kB
> > Inactive: 752 kB
> > Active(anon): 40 kB
> > Inactive(anon): 516 kB
> > Active(file): 3088 kB
> > Inactive(file): 236 kB
> > Unevictable: 0 kB
> > Mlocked: 0 kB
> > SwapTotal: 0 kB
> > SwapFree: 0 kB
> > Dirty: 4 kB
> > Writeback: 0 kB
> > AnonPages: 556 kB
> > Mapped: 2172 kB
> > Shmem: 44 kB
> > KReclaimable: 656 kB
> > Slab: 3684 kB
> > SReclaimable: 656 kB
> > SUnreclaim: 3028 kB
> > KernelStack: 312 kB
> > PageTables: 88 kB
> > NFS_Unstable: 0 kB
> > Bounce: 0 kB
> > WritebackTmp: 0 kB
> > CommitLimit: 26088 kB
> > Committed_AS: 2088 kB
> > VmallocTotal: 524287 kB
> > VmallocUsed: 12 kB
> > VmallocChunk: 0 kB
> > Percpu: 60 kB
> > #
> >
> > Some conclusions:
> > - kernel statics:
> > 64: Memory: 52788K/63488K available (6184K kernel code, 888K rwdata, 1917K rodata, 294K init, 297K bss, 10700K reserved)
> > 32: Memory: 51924K/61440K available (6117K kernel code, 695K rwdata, 1594K rodata, 255K init, 241K bss, 9516K reserved)
> > rv32 better than rv64: 1% 22% 17% 13% 19% 11%
> > The code size is very similar, but data size rv32 would be better.
> >
> > - rv32 kernel runtime KernelStack, Slab... are smaller,
> > rv64: MemTotal: 53076 kB, MemFree: 40264 kB
> > rv32: MemTotal: 52176 + 2048 kB, MemFree: 41012 + 2048 kB
> > rv32 better than rv64: 2% 6%
> >
> > (Because opensbi problem, we could add another 2MB for rv32.)
> > Overall in 64MB memory situation, rv64-compat is 6% worse than rv32-native
> > at memory footprint. If the userspace memory usage increases, I think
> > the gap will be further reduced.
> >
> > Changes in v12:
> > - Rebase on 5.18-rc1
> > - Fixup compile conflicts with 5.18-rc1
> > - Fixup $(srctree) == $(objtree) compile error reported by Nathan
> >
> > Changes in v11:
> > - Using arch instead of kconfig for commit subject by Masahiro Yamada
> >
> > Changes in v10:
> > - Fixup arm64 compile error with compat_statfs definition
> > - Fixup compat_sys_fadvise64_64 function arguments error cause ltp failure
> >
> > Changes in v9:
> > - Fixup rv32 call rv64 segment fault
> > - Ready for 5.18
> >
> > Changes in v8:
> > - Enhanced elf_check_arch with EI_CLASS
> > - Fixup SR_UXL doesn't exist in CONFIG_32BIT
> > - Add Tested-by with Heiko
> > - Update qemu compile tips with upstream repo
> >
> > Changes in v7:
> > - Re-construct compat_vdso/Makefile
> > - Fixup disable COMPAT compile error by csr.h's macro.
> > - Optimize coding convention for lo/hi in compat.h
> >
> > Changes in v6:
> > - Rebase on linux-5.17-rc5
> > - Optimize hw capability check for elf
> > - Optimize comment in thread_info.h
> > - Optimize start_thread with SR_UXL setting
> > - Optimize vdso.c with direct panic
> >
> > Changes in v5:
> > - Rebase on linux-5.17-rc2
> > - Include consolidate the fcntl patches by Christoph Hellwig
> > - Remove F_GETLK64/F_SETLK64/F_SETLKW64 from asm/compat.h
> > - Change COMPAT_RLIM_INFINITY from 0x7fffffff to 0xffffffff
> > - Bring back "Add hw-cap detect in setup_arch patch" in v1
> >
> > Changes in v4:
> > - Rebase on linux-5.17-rc1
> > - Optimize compat_sys_call_table implementation with Arnd's advice
> > - Add reviewed-by for Arnd. Thx :)
> > - Remove FIXME comment in elf.h
> > - Optimize Cleanup duplicate definitions in compat.h with Arnd's advice
> >
> > Changes in v3:
> > - Rebase on newest master (pre linux-5.17-rc1)
> > - Using newest qemu version v7 for test
> > - Remove fcntl common modification
> > - Fixup SET_PERSONALITY in elf.h by Arnd
> > - Fixup KVM Kconfig
> > - Update Acked-by & Reviewed-by
> >
> > Changes in v2:
> > - Add __ARCH_WANT_COMPAT_STAT suggested
> > - Cleanup fcntl compatduplicate definitions
> > - Cleanup compat.h
> > - Move rv32_defconfig into Makefile
> > - Fixup rv64 rootfs boot failed, remove hw_compat_mode_detect
> > - Move SYSVIPC_COMPAT into init/Kconfig
> > - Simplify compat_elf_check
> >
> > Christoph Hellwig (3):
> > uapi: simplify __ARCH_FLOCK{,64}_PAD a little
> > uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
> > compat: consolidate the compat_flock{,64} definition
> >
> > Guo Ren (17):
> > arch: Add SYSVIPC_COMPAT for all architectures
> > fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT
> > asm-generic: compat: Cleanup duplicate definitions
> > syscalls: compat: Fix the missing part for __SYSCALL_COMPAT
> > riscv: Fixup difference with defconfig
> > riscv: compat: Add basic compat data type implementation
> > riscv: compat: Support TASK_SIZE for compat mode
> > riscv: compat: syscall: Add compat_sys_call_table implementation
> > riscv: compat: syscall: Add entry.S implementation
> > riscv: compat: process: Add UXL_32 support in start_thread
> > riscv: compat: Add elf.h implementation
> > riscv: compat: Add hw capability check for elf
> > riscv: compat: vdso: Add COMPAT_VDSO base code implementation
> > riscv: compat: vdso: Add setup additional pages implementation
> > riscv: compat: signal: Add rt_frame implementation
> > riscv: compat: ptrace: Add compat_arch_ptrace implement
> > riscv: compat: Add COMPAT Kbuild skeletal support
> >
> > arch/arm64/Kconfig | 4 -
> > arch/arm64/include/asm/compat.h | 93 +------
> > arch/arm64/include/asm/unistd.h | 1 +
> > arch/mips/Kconfig | 5 -
> > arch/mips/include/asm/compat.h | 41 +--
> > arch/mips/include/asm/unistd.h | 2 +
> > arch/mips/include/uapi/asm/fcntl.h | 30 +--
> > arch/parisc/Kconfig | 4 -
> > arch/parisc/include/asm/compat.h | 45 +---
> > arch/parisc/include/asm/unistd.h | 1 +
> > arch/powerpc/Kconfig | 5 -
> > arch/powerpc/include/asm/compat.h | 50 +---
> > arch/powerpc/include/asm/unistd.h | 1 +
> > arch/riscv/Kconfig | 19 ++
> > arch/riscv/Makefile | 9 +
> > arch/riscv/include/asm/compat.h | 129 ++++++++++
> > arch/riscv/include/asm/csr.h | 7 +
> > arch/riscv/include/asm/elf.h | 50 +++-
> > arch/riscv/include/asm/mmu.h | 1 +
> > arch/riscv/include/asm/pgtable.h | 13 +-
> > arch/riscv/include/asm/processor.h | 6 +-
> > arch/riscv/include/asm/syscall.h | 1 +
> > arch/riscv/include/asm/thread_info.h | 1 +
> > arch/riscv/include/asm/unistd.h | 11 +
> > arch/riscv/include/asm/vdso.h | 9 +
> > arch/riscv/include/uapi/asm/unistd.h | 2 +-
> > arch/riscv/kernel/Makefile | 3 +
> > arch/riscv/kernel/compat_signal.c | 242 ++++++++++++++++++
> > arch/riscv/kernel/compat_syscall_table.c | 19 ++
> > arch/riscv/kernel/compat_vdso/.gitignore | 2 +
> > arch/riscv/kernel/compat_vdso/Makefile | 78 ++++++
> > arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +
> > .../kernel/compat_vdso/compat_vdso.lds.S | 3 +
> > arch/riscv/kernel/compat_vdso/flush_icache.S | 3 +
> > .../compat_vdso/gen_compat_vdso_offsets.sh | 5 +
> > arch/riscv/kernel/compat_vdso/getcpu.S | 3 +
> > arch/riscv/kernel/compat_vdso/note.S | 3 +
> > arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 +
> > arch/riscv/kernel/entry.S | 18 +-
> > arch/riscv/kernel/process.c | 37 +++
> > arch/riscv/kernel/ptrace.c | 87 ++++++-
> > arch/riscv/kernel/signal.c | 13 +-
> > arch/riscv/kernel/sys_riscv.c | 6 +-
> > arch/riscv/kernel/vdso.c | 105 +++++---
> > arch/riscv/kernel/vdso/vdso.S | 6 +-
> > arch/s390/Kconfig | 3 -
> > arch/s390/include/asm/compat.h | 99 +------
> > arch/s390/include/asm/unistd.h | 1 +
> > arch/sparc/Kconfig | 5 -
> > arch/sparc/include/asm/compat.h | 61 ++---
> > arch/sparc/include/asm/unistd.h | 1 +
> > arch/x86/Kconfig | 4 -
> > arch/x86/include/asm/compat.h | 104 ++------
> > arch/x86/include/asm/unistd.h | 1 +
> > fs/open.c | 24 ++
> > fs/read_write.c | 16 ++
> > fs/stat.c | 2 +-
> > fs/sync.c | 9 +
> > include/asm-generic/compat.h | 113 ++++++++
> > include/linux/compat.h | 68 +++++
> > include/uapi/asm-generic/fcntl.h | 23 +-
> > include/uapi/asm-generic/unistd.h | 4 +-
> > init/Kconfig | 4 +
> > mm/fadvise.c | 11 +
> > mm/readahead.c | 7 +
> > tools/include/uapi/asm-generic/fcntl.h | 21 +-
> > tools/include/uapi/asm-generic/unistd.h | 4 +-
> > 67 files changed, 1206 insertions(+), 563 deletions(-)
> > create mode 100644 arch/riscv/include/asm/compat.h
> > create mode 100644 arch/riscv/kernel/compat_signal.c
> > create mode 100644 arch/riscv/kernel/compat_syscall_table.c
> > create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore
> > create mode 100644 arch/riscv/kernel/compat_vdso/Makefile
> > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S
> > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
> > create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S
> > create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
> > create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S
> > create mode 100644 arch/riscv/kernel/compat_vdso/note.S
> > create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S
>
> Thanks.
>
> This touches a bunch of other trees, which I try to avoid without the
> relevant acks and such. In this case I'm OK taking it because Arnd and
> Christoph have written/reviewed/ack'd so much of it, and because some
> autobuilders found build issues (and thus I'm assuming there aren't any
> more).
>
> There's been a bunch of versions of this and I'm pretty sure I've said
> this a handful of times without any comments. Now that it's passing all
> my tests and I'm not getting any autobuilding breakages I've put it on
> for-next, but happy to try and spin up some sort of multi-tree merge if
Sounds good to me. Thx.
> that's an issue for anyone.
--
Best Regards
Guo Ren
ML: https://lore.kernel.org/linux-csky/