2022-03-22 18:37:33

by Guo Ren

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

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.17-rc8, 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_v8 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 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):
kconfig: 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: Re-implement TASK_SIZE for COMPAT_32BIT
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 | 91 +------
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/configs/rv32_defconfig | 135 ----------
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 | 243 ++++++++++++++++++
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 +-
68 files changed, 1205 insertions(+), 698 deletions(-)
delete mode 100644 arch/riscv/configs/rv32_defconfig
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


2022-03-22 20:02:12

by Guo Ren

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

From: Guo Ren <[email protected]>

Implement compat sys_call_table and some system call functions:
truncate64, ftruncate64, fallocate, pread64, pwrite64,
sync_file_range, readahead, fadvise64_64 which need argument
translation.

Signed-off-by: Guo Ren <[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/include/asm/syscall.h | 1 +
arch/riscv/include/asm/unistd.h | 11 +++++++
arch/riscv/include/uapi/asm/unistd.h | 2 +-
arch/riscv/kernel/Makefile | 1 +
arch/riscv/kernel/compat_syscall_table.c | 19 ++++++++++++
arch/riscv/kernel/sys_riscv.c | 6 ++--
fs/open.c | 24 +++++++++++++++
fs/read_write.c | 16 ++++++++++
fs/sync.c | 9 ++++++
include/asm-generic/compat.h | 7 +++++
include/linux/compat.h | 37 ++++++++++++++++++++++++
mm/fadvise.c | 11 +++++++
mm/readahead.c | 7 +++++
13 files changed, 148 insertions(+), 3 deletions(-)
create mode 100644 arch/riscv/kernel/compat_syscall_table.c

diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h
index 7ac6a0e275f2..384a63b86420 100644
--- a/arch/riscv/include/asm/syscall.h
+++ b/arch/riscv/include/asm/syscall.h
@@ -16,6 +16,7 @@

/* The array of function pointers for syscalls. */
extern void * const sys_call_table[];
+extern void * const compat_sys_call_table[];

/*
* Only the low 32 bits of orig_r0 are meaningful, so we return int.
diff --git a/arch/riscv/include/asm/unistd.h b/arch/riscv/include/asm/unistd.h
index 6c316093a1e5..5ddac412b578 100644
--- a/arch/riscv/include/asm/unistd.h
+++ b/arch/riscv/include/asm/unistd.h
@@ -11,6 +11,17 @@
#define __ARCH_WANT_SYS_CLONE
#define __ARCH_WANT_MEMFD_SECRET

+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_TRUNCATE64
+#define __ARCH_WANT_COMPAT_FTRUNCATE64
+#define __ARCH_WANT_COMPAT_FALLOCATE
+#define __ARCH_WANT_COMPAT_PREAD64
+#define __ARCH_WANT_COMPAT_PWRITE64
+#define __ARCH_WANT_COMPAT_SYNC_FILE_RANGE
+#define __ARCH_WANT_COMPAT_READAHEAD
+#define __ARCH_WANT_COMPAT_FADVISE64_64
+#endif
+
#include <uapi/asm/unistd.h>

#define NR_syscalls (__NR_syscalls)
diff --git a/arch/riscv/include/uapi/asm/unistd.h b/arch/riscv/include/uapi/asm/unistd.h
index 8062996c2dfd..c9e50eed14aa 100644
--- a/arch/riscv/include/uapi/asm/unistd.h
+++ b/arch/riscv/include/uapi/asm/unistd.h
@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

-#ifdef __LP64__
+#if defined(__LP64__) && !defined(__SYSCALL_COMPAT)
#define __ARCH_WANT_NEW_STAT
#define __ARCH_WANT_SET_GET_RLIMIT
#endif /* __LP64__ */
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index ffc87e76b1dd..3b3e425aadd2 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -68,3 +68,4 @@ obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
obj-$(CONFIG_JUMP_LABEL) += jump_label.o

obj-$(CONFIG_EFI) += efi.o
+obj-$(CONFIG_COMPAT) += compat_syscall_table.o
diff --git a/arch/riscv/kernel/compat_syscall_table.c b/arch/riscv/kernel/compat_syscall_table.c
new file mode 100644
index 000000000000..651f2b009c28
--- /dev/null
+++ b/arch/riscv/kernel/compat_syscall_table.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define __SYSCALL_COMPAT
+
+#include <linux/compat.h>
+#include <linux/syscalls.h>
+#include <asm-generic/mman-common.h>
+#include <asm-generic/syscalls.h>
+#include <asm/syscall.h>
+
+#undef __SYSCALL
+#define __SYSCALL(nr, call) [nr] = (call),
+
+asmlinkage long compat_sys_rt_sigreturn(void);
+
+void * const compat_sys_call_table[__NR_syscalls] = {
+ [0 ... __NR_syscalls - 1] = sys_ni_syscall,
+#include <asm/unistd.h>
+};
diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c
index 12f8a7fce78b..9c0194f176fc 100644
--- a/arch/riscv/kernel/sys_riscv.c
+++ b/arch/riscv/kernel/sys_riscv.c
@@ -33,7 +33,9 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
{
return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 0);
}
-#else
+#endif
+
+#if defined(CONFIG_32BIT) || defined(CONFIG_COMPAT)
SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags,
unsigned long, fd, off_t, offset)
@@ -44,7 +46,7 @@ SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
*/
return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 12);
}
-#endif /* !CONFIG_64BIT */
+#endif

/*
* Allows the instruction cache to be flushed from userspace. Despite RISC-V
diff --git a/fs/open.c b/fs/open.c
index 9ff2f621b760..b25613f7c0a7 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -224,6 +224,21 @@ SYSCALL_DEFINE2(ftruncate64, unsigned int, fd, loff_t, length)
}
#endif /* BITS_PER_LONG == 32 */

+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_TRUNCATE64)
+COMPAT_SYSCALL_DEFINE3(truncate64, const char __user *, pathname,
+ compat_arg_u64_dual(length))
+{
+ return ksys_truncate(pathname, compat_arg_u64_glue(length));
+}
+#endif
+
+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_FTRUNCATE64)
+COMPAT_SYSCALL_DEFINE3(ftruncate64, unsigned int, fd,
+ compat_arg_u64_dual(length))
+{
+ return ksys_ftruncate(fd, compat_arg_u64_glue(length));
+}
+#endif

int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
{
@@ -339,6 +354,15 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
return ksys_fallocate(fd, mode, offset, len);
}

+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_FALLOCATE)
+COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode, compat_arg_u64_dual(offset),
+ compat_arg_u64_dual(len))
+{
+ return ksys_fallocate(fd, mode, compat_arg_u64_glue(offset),
+ compat_arg_u64_glue(len));
+}
+#endif
+
/*
* access() needs to use the real uid/gid, not the effective uid/gid.
* We do this by temporarily clearing all FS-related capabilities and
diff --git a/fs/read_write.c b/fs/read_write.c
index 0074afa7ecb3..548657c462e8 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -681,6 +681,14 @@ SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
return ksys_pread64(fd, buf, count, pos);
}

+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_PREAD64)
+COMPAT_SYSCALL_DEFINE5(pread64, unsigned int, fd, char __user *, buf,
+ size_t, count, compat_arg_u64_dual(pos))
+{
+ return ksys_pread64(fd, buf, count, compat_arg_u64_glue(pos));
+}
+#endif
+
ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf,
size_t count, loff_t pos)
{
@@ -707,6 +715,14 @@ SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
return ksys_pwrite64(fd, buf, count, pos);
}

+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_PWRITE64)
+COMPAT_SYSCALL_DEFINE5(pwrite64, unsigned int, fd, const char __user *, buf,
+ size_t, count, compat_arg_u64_dual(pos))
+{
+ return ksys_pwrite64(fd, buf, count, compat_arg_u64_glue(pos));
+}
+#endif
+
static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter,
loff_t *ppos, int type, rwf_t flags)
{
diff --git a/fs/sync.c b/fs/sync.c
index c7690016453e..dc725914e1ed 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -373,6 +373,15 @@ SYSCALL_DEFINE4(sync_file_range, int, fd, loff_t, offset, loff_t, nbytes,
return ksys_sync_file_range(fd, offset, nbytes, flags);
}

+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_SYNC_FILE_RANGE)
+COMPAT_SYSCALL_DEFINE6(sync_file_range, int, fd, compat_arg_u64_dual(offset),
+ compat_arg_u64_dual(nbytes), unsigned int, flags)
+{
+ return ksys_sync_file_range(fd, compat_arg_u64_glue(offset),
+ compat_arg_u64_glue(nbytes), flags);
+}
+#endif
+
/* It would be nice if people remember that not all the world's an i386
when they introduce new system calls */
SYSCALL_DEFINE4(sync_file_range2, int, fd, unsigned int, flags,
diff --git a/include/asm-generic/compat.h b/include/asm-generic/compat.h
index 11653d6846cc..d06308a2a7a8 100644
--- a/include/asm-generic/compat.h
+++ b/include/asm-generic/compat.h
@@ -14,6 +14,13 @@
#define COMPAT_OFF_T_MAX 0x7fffffff
#endif

+#if !defined(compat_arg_u64) && !defined(CONFIG_CPU_BIG_ENDIAN)
+#define compat_arg_u64(name) u32 name##_lo, u32 name##_hi
+#define compat_arg_u64_dual(name) u32, name##_lo, u32, name##_hi
+#define compat_arg_u64_glue(name) (((u64)name##_lo & 0xffffffffUL) | \
+ ((u64)name##_hi << 32))
+#endif
+
/* These types are common across all compat ABIs */
typedef u32 compat_size_t;
typedef s32 compat_ssize_t;
diff --git a/include/linux/compat.h b/include/linux/compat.h
index a0481fe6c5d5..8779e283a1e9 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -926,6 +926,43 @@ asmlinkage long compat_sys_sigaction(int sig,
/* obsolete: net/socket.c */
asmlinkage long compat_sys_socketcall(int call, u32 __user *args);

+#ifdef __ARCH_WANT_COMPAT_TRUNCATE64
+asmlinkage long compat_sys_truncate64(const char __user *pathname, compat_arg_u64(len));
+#endif
+
+#ifdef __ARCH_WANT_COMPAT_FTRUNCATE64
+asmlinkage long compat_sys_ftruncate64(unsigned int fd, compat_arg_u64(len));
+#endif
+
+#ifdef __ARCH_WANT_COMPAT_FALLOCATE
+asmlinkage long compat_sys_fallocate(int fd, int mode, compat_arg_u64(offset),
+ compat_arg_u64(len));
+#endif
+
+#ifdef __ARCH_WANT_COMPAT_PREAD64
+asmlinkage long compat_sys_pread64(unsigned int fd, char __user *buf, size_t count,
+ compat_arg_u64(pos));
+#endif
+
+#ifdef __ARCH_WANT_COMPAT_PWRITE64
+asmlinkage long compat_sys_pwrite64(unsigned int fd, const char __user *buf, size_t count,
+ compat_arg_u64(pos));
+#endif
+
+#ifdef __ARCH_WANT_COMPAT_SYNC_FILE_RANGE
+asmlinkage long compat_sys_sync_file_range(int fd, compat_arg_u64(pos),
+ compat_arg_u64(nbytes), unsigned int flags);
+#endif
+
+#ifdef __ARCH_WANT_COMPAT_FADVISE64_64
+asmlinkage long compat_sys_fadvise64_64(int fd, int advice, compat_arg_u64(pos),
+ compat_arg_u64(len));
+#endif
+
+#ifdef __ARCH_WANT_COMPAT_READAHEAD
+asmlinkage long compat_sys_readahead(int fd, compat_arg_u64(offset), size_t count);
+#endif
+
#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */

/**
diff --git a/mm/fadvise.c b/mm/fadvise.c
index d6baa4f451c5..8950f7c05d20 100644
--- a/mm/fadvise.c
+++ b/mm/fadvise.c
@@ -215,5 +215,16 @@ SYSCALL_DEFINE4(fadvise64, int, fd, loff_t, offset, size_t, len, int, advice)
return ksys_fadvise64_64(fd, offset, len, advice);
}

+#endif
+
+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_FADVISE64_64)
+
+COMPAT_SYSCALL_DEFINE6(fadvise64_64, int, fd, int, advice, compat_arg_u64_dual(offset),
+ compat_arg_u64_dual(len))
+{
+ return ksys_fadvise64_64(fd, compat_arg_u64_glue(offset),
+ compat_arg_u64_glue(len), advice);
+}
+
#endif
#endif
diff --git a/mm/readahead.c b/mm/readahead.c
index cf0dcf89eb69..9adf57044299 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -640,6 +640,13 @@ SYSCALL_DEFINE3(readahead, int, fd, loff_t, offset, size_t, count)
return ksys_readahead(fd, offset, count);
}

+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_READAHEAD)
+COMPAT_SYSCALL_DEFINE4(readahead, int, fd, compat_arg_u64_dual(offset), size_t, count)
+{
+ return ksys_readahead(fd, compat_arg_u64_glue(offset), count);
+}
+#endif
+
/**
* readahead_expand - Expand a readahead request
* @ractl: The request to be expanded
--
2.25.1

2022-03-22 20:22:02

by Guo Ren

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

From: Christoph Hellwig <[email protected]>

Provide a single common definition for the compat_flock and
compat_flock64 structures using the same tricks as for the native
variants. Another extra define is added for the packing required on
x86.

Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Arnd Bergmann <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
---
arch/arm64/include/asm/compat.h | 16 ----------------
arch/mips/include/asm/compat.h | 19 ++-----------------
arch/parisc/include/asm/compat.h | 16 ----------------
arch/powerpc/include/asm/compat.h | 16 ----------------
arch/s390/include/asm/compat.h | 16 ----------------
arch/sparc/include/asm/compat.h | 18 +-----------------
arch/x86/include/asm/compat.h | 20 +++-----------------
include/linux/compat.h | 31 +++++++++++++++++++++++++++++++
8 files changed, 37 insertions(+), 115 deletions(-)

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index 276328765408..e0faec1984a1 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -65,22 +65,6 @@ struct compat_stat {
compat_ulong_t __unused4[2];
};

-struct compat_flock {
- short l_type;
- short l_whence;
- compat_off_t l_start;
- compat_off_t l_len;
- compat_pid_t l_pid;
-};
-
-struct compat_flock64 {
- short l_type;
- short l_whence;
- compat_loff_t l_start;
- compat_loff_t l_len;
- compat_pid_t l_pid;
-};
-
struct compat_statfs {
int f_type;
int f_bsize;
diff --git a/arch/mips/include/asm/compat.h b/arch/mips/include/asm/compat.h
index 6a350c1f70d7..6d6e5a451f4d 100644
--- a/arch/mips/include/asm/compat.h
+++ b/arch/mips/include/asm/compat.h
@@ -55,23 +55,8 @@ struct compat_stat {
s32 st_pad4[14];
};

-struct compat_flock {
- short l_type;
- short l_whence;
- compat_off_t l_start;
- compat_off_t l_len;
- s32 l_sysid;
- compat_pid_t l_pid;
- s32 pad[4];
-};
-
-struct compat_flock64 {
- short l_type;
- short l_whence;
- compat_loff_t l_start;
- compat_loff_t l_len;
- compat_pid_t l_pid;
-};
+#define __ARCH_COMPAT_FLOCK_EXTRA_SYSID s32 l_sysid;
+#define __ARCH_COMPAT_FLOCK_PAD s32 pad[4];

struct compat_statfs {
int f_type;
diff --git a/arch/parisc/include/asm/compat.h b/arch/parisc/include/asm/compat.h
index c04f5a637c39..a1e4534d8050 100644
--- a/arch/parisc/include/asm/compat.h
+++ b/arch/parisc/include/asm/compat.h
@@ -53,22 +53,6 @@ struct compat_stat {
u32 st_spare4[3];
};

-struct compat_flock {
- short l_type;
- short l_whence;
- compat_off_t l_start;
- compat_off_t l_len;
- compat_pid_t l_pid;
-};
-
-struct compat_flock64 {
- short l_type;
- short l_whence;
- compat_loff_t l_start;
- compat_loff_t l_len;
- compat_pid_t l_pid;
-};
-
struct compat_statfs {
s32 f_type;
s32 f_bsize;
diff --git a/arch/powerpc/include/asm/compat.h b/arch/powerpc/include/asm/compat.h
index 83d8f70779cb..5ef3c7c83c34 100644
--- a/arch/powerpc/include/asm/compat.h
+++ b/arch/powerpc/include/asm/compat.h
@@ -44,22 +44,6 @@ struct compat_stat {
u32 __unused4[2];
};

-struct compat_flock {
- short l_type;
- short l_whence;
- compat_off_t l_start;
- compat_off_t l_len;
- compat_pid_t l_pid;
-};
-
-struct compat_flock64 {
- short l_type;
- short l_whence;
- compat_loff_t l_start;
- compat_loff_t l_len;
- compat_pid_t l_pid;
-};
-
struct compat_statfs {
int f_type;
int f_bsize;
diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index 0f14b3188b1b..07f04d37068b 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -102,22 +102,6 @@ struct compat_stat {
u32 __unused5;
};

-struct compat_flock {
- short l_type;
- short l_whence;
- compat_off_t l_start;
- compat_off_t l_len;
- compat_pid_t l_pid;
-};
-
-struct compat_flock64 {
- short l_type;
- short l_whence;
- compat_loff_t l_start;
- compat_loff_t l_len;
- compat_pid_t l_pid;
-};
-
struct compat_statfs {
u32 f_type;
u32 f_bsize;
diff --git a/arch/sparc/include/asm/compat.h b/arch/sparc/include/asm/compat.h
index 108078751bb5..d78fb44942e0 100644
--- a/arch/sparc/include/asm/compat.h
+++ b/arch/sparc/include/asm/compat.h
@@ -75,23 +75,7 @@ struct compat_stat64 {
unsigned int __unused5;
};

-struct compat_flock {
- short l_type;
- short l_whence;
- compat_off_t l_start;
- compat_off_t l_len;
- compat_pid_t l_pid;
- short __unused;
-};
-
-struct compat_flock64 {
- short l_type;
- short l_whence;
- compat_loff_t l_start;
- compat_loff_t l_len;
- compat_pid_t l_pid;
- short __unused;
-};
+#define __ARCH_COMPAT_FLOCK_PAD short __unused;

struct compat_statfs {
int f_type;
diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
index 8d19a212f4f2..de794d895866 100644
--- a/arch/x86/include/asm/compat.h
+++ b/arch/x86/include/asm/compat.h
@@ -50,25 +50,11 @@ struct compat_stat {
u32 __unused5;
};

-struct compat_flock {
- short l_type;
- short l_whence;
- compat_off_t l_start;
- compat_off_t l_len;
- compat_pid_t l_pid;
-};
-
/*
- * IA32 uses 4 byte alignment for 64 bit quantities,
- * so we need to pack this structure.
+ * IA32 uses 4 byte alignment for 64 bit quantities, so we need to pack the
+ * compat flock64 structure.
*/
-struct compat_flock64 {
- short l_type;
- short l_whence;
- compat_loff_t l_start;
- compat_loff_t l_len;
- compat_pid_t l_pid;
-} __attribute__((packed));
+#define __ARCH_NEED_COMPAT_FLOCK64_PACKED

struct compat_statfs {
int f_type;
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 1c758b0e0359..a0481fe6c5d5 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -258,6 +258,37 @@ struct compat_rlimit {
compat_ulong_t rlim_max;
};

+#ifdef __ARCH_NEED_COMPAT_FLOCK64_PACKED
+#define __ARCH_COMPAT_FLOCK64_PACK __attribute__((packed))
+#else
+#define __ARCH_COMPAT_FLOCK64_PACK
+#endif
+
+struct compat_flock {
+ short l_type;
+ short l_whence;
+ compat_off_t l_start;
+ compat_off_t l_len;
+#ifdef __ARCH_COMPAT_FLOCK_EXTRA_SYSID
+ __ARCH_COMPAT_FLOCK_EXTRA_SYSID
+#endif
+ compat_pid_t l_pid;
+#ifdef __ARCH_COMPAT_FLOCK_PAD
+ __ARCH_COMPAT_FLOCK_PAD
+#endif
+};
+
+struct compat_flock64 {
+ short l_type;
+ short l_whence;
+ compat_loff_t l_start;
+ compat_loff_t l_len;
+ compat_pid_t l_pid;
+#ifdef __ARCH_COMPAT_FLOCK64_PAD
+ __ARCH_COMPAT_FLOCK64_PAD
+#endif
+} __ARCH_COMPAT_FLOCK64_PACK;
+
struct compat_rusage {
struct old_timeval32 ru_utime;
struct old_timeval32 ru_stime;
--
2.25.1

2022-03-22 20:51:52

by Guo Ren

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

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 5adcbd9b5e88..6f11df8c189f 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -73,6 +73,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
@@ -123,12 +124,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
@@ -406,6 +413,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

2022-03-22 21:36:18

by Guo Ren

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

From: Guo Ren <[email protected]>

Now, you can use native gdb on riscv64 for rv32 app debugging.

$ uname -a
Linux buildroot 5.16.0-rc4-00036-gbef6b82fdf23-dirty #53 SMP Mon Dec 20 23:06:53 CST 2021 riscv64 GNU/Linux
$ cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv64imafdcsuh
mmu : 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
$ file /usr/bin/gdb
/usr/bin/gdb: ELF 32-bit LSB shared object, UCB RISC-V, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
$ /usr/bin/gdb /bin/busybox
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
...
Reading symbols from /bin/busybox...
(No debugging symbols found in /bin/busybox)
(gdb) b main
Breakpoint 1 at 0x8ddc
(gdb) r
Starting program: /bin/busybox
Failed to read a valid object file image from memory.

Breakpoint 1, 0x555a8ddc in main ()
(gdb) i r
ra 0x77df0b74 0x77df0b74
sp 0x7fdd3d10 0x7fdd3d10
gp 0x5567e800 0x5567e800 <bb_common_bufsiz1+160>
tp 0x77f64280 0x77f64280
t0 0x0 0
t1 0x555a6fac 1431990188
t2 0x77dd8db4 2011008436
fp 0x7fdd3e34 0x7fdd3e34
s1 0x7fdd3e34 2145205812
a0 0xffffffff -1
a1 0x2000 8192
a2 0x7fdd3e3c 2145205820
a3 0x0 0
a4 0x7fdd3d30 2145205552
a5 0x555a8dc0 1431997888
a6 0x77f2c170 2012397936
a7 0x6a7c7a2f 1786542639
s2 0x0 0
s3 0x0 0
s4 0x555a8dc0 1431997888
s5 0x77f8a3a8 2012783528
s6 0x7fdd3e3c 2145205820
s7 0x5567cecc 1432866508
--Type <RET> for more, q to quit, c to continue without paging--
s8 0x1 1
s9 0x0 0
s10 0x55634448 1432568904
s11 0x0 0
t3 0x77df0bb8 2011106232
t4 0x42fc 17148
t5 0x0 0
t6 0x40 64
pc 0x555a8ddc 0x555a8ddc <main+28>
(gdb) si
0x555a78f0 in mallopt@plt ()
(gdb) c
Continuing.
BusyBox v1.34.1 (2021-12-19 22:39:48 CST) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.

Usage: busybox [function [arguments]...]
or: busybox --list[-full]
...
[Inferior 1 (process 107) exited normally]
(gdb) q

Signed-off-by: Guo Ren <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Palmer Dabbelt <[email protected]>
Reviewed-by: Arnd Bergmann <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
---
arch/riscv/kernel/ptrace.c | 87 +++++++++++++++++++++++++++++++++++---
1 file changed, 82 insertions(+), 5 deletions(-)

diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c
index a89243730153..bb387593a121 100644
--- a/arch/riscv/kernel/ptrace.c
+++ b/arch/riscv/kernel/ptrace.c
@@ -12,6 +12,7 @@
#include <asm/thread_info.h>
#include <asm/switch_to.h>
#include <linux/audit.h>
+#include <linux/compat.h>
#include <linux/ptrace.h>
#include <linux/elf.h>
#include <linux/regset.h>
@@ -111,11 +112,6 @@ static const struct user_regset_view riscv_user_native_view = {
.n = ARRAY_SIZE(riscv_user_regset),
};

-const struct user_regset_view *task_user_regset_view(struct task_struct *task)
-{
- return &riscv_user_native_view;
-}
-
struct pt_regs_offset {
const char *name;
int offset;
@@ -273,3 +269,84 @@ __visible void do_syscall_trace_exit(struct pt_regs *regs)
trace_sys_exit(regs, regs_return_value(regs));
#endif
}
+
+#ifdef CONFIG_COMPAT
+static int compat_riscv_gpr_get(struct task_struct *target,
+ const struct user_regset *regset,
+ struct membuf to)
+{
+ struct compat_user_regs_struct cregs;
+
+ regs_to_cregs(&cregs, task_pt_regs(target));
+
+ return membuf_write(&to, &cregs,
+ sizeof(struct compat_user_regs_struct));
+}
+
+static int compat_riscv_gpr_set(struct task_struct *target,
+ const struct user_regset *regset,
+ unsigned int pos, unsigned int count,
+ const void *kbuf, const void __user *ubuf)
+{
+ int ret;
+ struct compat_user_regs_struct cregs;
+
+ ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &cregs, 0, -1);
+
+ cregs_to_regs(&cregs, task_pt_regs(target));
+
+ return ret;
+}
+
+static const struct user_regset compat_riscv_user_regset[] = {
+ [REGSET_X] = {
+ .core_note_type = NT_PRSTATUS,
+ .n = ELF_NGREG,
+ .size = sizeof(compat_elf_greg_t),
+ .align = sizeof(compat_elf_greg_t),
+ .regset_get = compat_riscv_gpr_get,
+ .set = compat_riscv_gpr_set,
+ },
+#ifdef CONFIG_FPU
+ [REGSET_F] = {
+ .core_note_type = NT_PRFPREG,
+ .n = ELF_NFPREG,
+ .size = sizeof(elf_fpreg_t),
+ .align = sizeof(elf_fpreg_t),
+ .regset_get = riscv_fpr_get,
+ .set = riscv_fpr_set,
+ },
+#endif
+};
+
+static const struct user_regset_view compat_riscv_user_native_view = {
+ .name = "riscv",
+ .e_machine = EM_RISCV,
+ .regsets = compat_riscv_user_regset,
+ .n = ARRAY_SIZE(compat_riscv_user_regset),
+};
+
+long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
+ compat_ulong_t caddr, compat_ulong_t cdata)
+{
+ long ret = -EIO;
+
+ switch (request) {
+ default:
+ ret = compat_ptrace_request(child, request, caddr, cdata);
+ break;
+ }
+
+ return ret;
+}
+#endif /* CONFIG_COMPAT */
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+#ifdef CONFIG_COMPAT
+ if (test_tsk_thread_flag(task, TIF_32BIT))
+ return &compat_riscv_user_native_view;
+ else
+#endif
+ return &riscv_user_native_view;
+}
--
2.25.1

2022-03-22 21:48:18

by Guo Ren

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

From: Guo Ren <[email protected]>

Implement compat_setup_rt_frame for sigcontext save & restore. The
main process is the same with signal, but the rv32 pt_regs' size
is different from rv64's, so we needs convert them.

Signed-off-by: Guo Ren <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Palmer Dabbelt <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
Cc: Arnd Bergmann <[email protected]>
---
arch/riscv/kernel/Makefile | 1 +
arch/riscv/kernel/compat_signal.c | 243 ++++++++++++++++++++++++++++++
arch/riscv/kernel/signal.c | 13 +-
3 files changed, 256 insertions(+), 1 deletion(-)
create mode 100644 arch/riscv/kernel/compat_signal.c

diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index 6365f382d2fd..2712a5925515 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -69,4 +69,5 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o

obj-$(CONFIG_EFI) += efi.o
obj-$(CONFIG_COMPAT) += compat_syscall_table.o
+obj-$(CONFIG_COMPAT) += compat_signal.o
obj-$(CONFIG_COMPAT) += compat_vdso/
diff --git a/arch/riscv/kernel/compat_signal.c b/arch/riscv/kernel/compat_signal.c
new file mode 100644
index 000000000000..7041742ded08
--- /dev/null
+++ b/arch/riscv/kernel/compat_signal.c
@@ -0,0 +1,243 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/compat.h>
+#include <linux/signal.h>
+#include <linux/uaccess.h>
+#include <linux/syscalls.h>
+#include <linux/tracehook.h>
+#include <linux/linkage.h>
+
+#include <asm/ucontext.h>
+#include <asm/vdso.h>
+#include <asm/switch_to.h>
+#include <asm/csr.h>
+
+#define COMPAT_DEBUG_SIG 0
+
+struct compat_sigcontext {
+ struct compat_user_regs_struct sc_regs;
+ union __riscv_fp_state sc_fpregs;
+};
+
+struct compat_ucontext {
+ compat_ulong_t uc_flags;
+ struct compat_ucontext *uc_link;
+ compat_stack_t uc_stack;
+ sigset_t uc_sigmask;
+ /* There's some padding here to allow sigset_t to be expanded in the
+ * future. Though this is unlikely, other architectures put uc_sigmask
+ * at the end of this structure and explicitly state it can be
+ * expanded, so we didn't want to box ourselves in here. */
+ __u8 __unused[1024 / 8 - sizeof(sigset_t)];
+ /* We can't put uc_sigmask at the end of this structure because we need
+ * to be able to expand sigcontext in the future. For example, the
+ * vector ISA extension will almost certainly add ISA state. We want
+ * to ensure all user-visible ISA state can be saved and restored via a
+ * ucontext, so we're putting this at the end in order to allow for
+ * infinite extensibility. Since we know this will be extended and we
+ * assume sigset_t won't be extended an extreme amount, we're
+ * prioritizing this. */
+ struct compat_sigcontext uc_mcontext;
+};
+
+struct compat_rt_sigframe {
+ struct compat_siginfo info;
+ struct compat_ucontext uc;
+};
+
+#ifdef CONFIG_FPU
+static long compat_restore_fp_state(struct pt_regs *regs,
+ union __riscv_fp_state __user *sc_fpregs)
+{
+ long err;
+ struct __riscv_d_ext_state __user *state = &sc_fpregs->d;
+ size_t i;
+
+ err = __copy_from_user(&current->thread.fstate, state, sizeof(*state));
+ if (unlikely(err))
+ return err;
+
+ fstate_restore(current, regs);
+
+ /* We support no other extension state at this time. */
+ for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
+ u32 value;
+
+ err = __get_user(value, &sc_fpregs->q.reserved[i]);
+ if (unlikely(err))
+ break;
+ if (value != 0)
+ return -EINVAL;
+ }
+
+ return err;
+}
+
+static long compat_save_fp_state(struct pt_regs *regs,
+ union __riscv_fp_state __user *sc_fpregs)
+{
+ long err;
+ struct __riscv_d_ext_state __user *state = &sc_fpregs->d;
+ size_t i;
+
+ fstate_save(current, regs);
+ err = __copy_to_user(state, &current->thread.fstate, sizeof(*state));
+ if (unlikely(err))
+ return err;
+
+ /* We support no other extension state at this time. */
+ for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
+ err = __put_user(0, &sc_fpregs->q.reserved[i]);
+ if (unlikely(err))
+ break;
+ }
+
+ return err;
+}
+#else
+#define compat_save_fp_state(task, regs) (0)
+#define compat_restore_fp_state(task, regs) (0)
+#endif
+
+static long compat_restore_sigcontext(struct pt_regs *regs,
+ struct compat_sigcontext __user *sc)
+{
+ long err;
+ struct compat_user_regs_struct cregs;
+
+ /* sc_regs is structured the same as the start of pt_regs */
+ err = __copy_from_user(&cregs, &sc->sc_regs, sizeof(sc->sc_regs));
+
+ cregs_to_regs(&cregs, regs);
+
+ /* Restore the floating-point state. */
+ if (has_fpu())
+ err |= compat_restore_fp_state(regs, &sc->sc_fpregs);
+ return err;
+}
+
+COMPAT_SYSCALL_DEFINE0(rt_sigreturn)
+{
+ struct pt_regs *regs = current_pt_regs();
+ struct compat_rt_sigframe __user *frame;
+ struct task_struct *task;
+ sigset_t set;
+
+ /* Always make any pending restarted system calls return -EINTR */
+ current->restart_block.fn = do_no_restart_syscall;
+
+ frame = (struct compat_rt_sigframe __user *)regs->sp;
+
+ if (!access_ok(frame, sizeof(*frame)))
+ goto badframe;
+
+ if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
+ goto badframe;
+
+ set_current_blocked(&set);
+
+ if (compat_restore_sigcontext(regs, &frame->uc.uc_mcontext))
+ goto badframe;
+
+ if (compat_restore_altstack(&frame->uc.uc_stack))
+ goto badframe;
+
+ return regs->a0;
+
+badframe:
+ task = current;
+ if (show_unhandled_signals) {
+ pr_info_ratelimited(
+ "%s[%d]: bad frame in %s: frame=%p pc=%p sp=%p\n",
+ task->comm, task_pid_nr(task), __func__,
+ frame, (void *)regs->epc, (void *)regs->sp);
+ }
+ force_sig(SIGSEGV);
+ return 0;
+}
+
+static long compat_setup_sigcontext(struct compat_rt_sigframe __user *frame,
+ struct pt_regs *regs)
+{
+ struct compat_sigcontext __user *sc = &frame->uc.uc_mcontext;
+ struct compat_user_regs_struct cregs;
+ long err;
+
+ regs_to_cregs(&cregs, regs);
+
+ /* sc_regs is structured the same as the start of pt_regs */
+ err = __copy_to_user(&sc->sc_regs, &cregs, sizeof(sc->sc_regs));
+ /* Save the floating-point state. */
+ if (has_fpu())
+ err |= compat_save_fp_state(regs, &sc->sc_fpregs);
+ return err;
+}
+
+static inline void __user *compat_get_sigframe(struct ksignal *ksig,
+ struct pt_regs *regs, size_t framesize)
+{
+ unsigned long sp;
+ /* Default to using normal stack */
+ sp = regs->sp;
+
+ /*
+ * If we are on the alternate signal stack and would overflow it, don't.
+ * Return an always-bogus address instead so we will die with SIGSEGV.
+ */
+ if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
+ return (void __user __force *)(-1UL);
+
+ /* This is the X/Open sanctioned signal stack switching. */
+ sp = sigsp(sp, ksig) - framesize;
+
+ /* Align the stack frame. */
+ sp &= ~0xfUL;
+
+ return (void __user *)sp;
+}
+
+int compat_setup_rt_frame(struct ksignal *ksig, sigset_t *set,
+ struct pt_regs *regs)
+{
+ struct compat_rt_sigframe __user *frame;
+ long err = 0;
+
+ frame = compat_get_sigframe(ksig, regs, sizeof(*frame));
+ if (!access_ok(frame, sizeof(*frame)))
+ return -EFAULT;
+
+ err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
+
+ /* Create the ucontext. */
+ err |= __put_user(0, &frame->uc.uc_flags);
+ err |= __put_user(NULL, &frame->uc.uc_link);
+ err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
+ err |= compat_setup_sigcontext(frame, regs);
+ err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
+ if (err)
+ return -EFAULT;
+
+ regs->ra = (unsigned long)COMPAT_VDSO_SYMBOL(
+ current->mm->context.vdso, rt_sigreturn);
+
+ /*
+ * Set up registers for signal handler.
+ * Registers that we don't modify keep the value they had from
+ * user-space at the time we took the signal.
+ * We always pass siginfo and mcontext, regardless of SA_SIGINFO,
+ * since some things rely on this (e.g. glibc's debug/segfault.c).
+ */
+ regs->epc = (unsigned long)ksig->ka.sa.sa_handler;
+ regs->sp = (unsigned long)frame;
+ regs->a0 = ksig->sig; /* a0: signal number */
+ regs->a1 = (unsigned long)(&frame->info); /* a1: siginfo pointer */
+ regs->a2 = (unsigned long)(&frame->uc); /* a2: ucontext pointer */
+
+#if COMPAT_DEBUG_SIG
+ pr_info("SIG deliver (%s:%d): sig=%d pc=%p ra=%p sp=%p\n",
+ current->comm, task_pid_nr(current), ksig->sig,
+ (void *)regs->epc, (void *)regs->ra, frame);
+#endif
+
+ return 0;
+}
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index c2d5ecbe5526..27d8f39228c4 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -6,6 +6,7 @@
* Copyright (C) 2012 Regents of the University of California
*/

+#include <linux/compat.h>
#include <linux/signal.h>
#include <linux/uaccess.h>
#include <linux/syscalls.h>
@@ -229,6 +230,11 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
return 0;
}

+#ifdef CONFIG_COMPAT
+extern int compat_setup_rt_frame(struct ksignal *ksig, sigset_t *set,
+ struct pt_regs *regs);
+#endif
+
static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
{
sigset_t *oldset = sigmask_to_save();
@@ -258,8 +264,13 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
}
}

+#ifdef CONFIG_COMPAT
/* Set up the stack frame */
- ret = setup_rt_frame(ksig, oldset, regs);
+ if (is_compat_task())
+ ret = compat_setup_rt_frame(ksig, oldset, regs);
+ else
+#endif
+ ret = setup_rt_frame(ksig, oldset, regs);

signal_setup_done(ret, ksig, 0);
}
--
2.25.1

2022-03-22 22:04:40

by Guo Ren

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

From: Guo Ren <[email protected]>

Implement riscv asm/compat.h for struct compat_xxx,
is_compat_task, compat_user_regset, regset convert.

The rv64 compat.h has inherited most of the structs
from the generic one.

Signed-off-by: Guo Ren <[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/include/asm/compat.h | 129 +++++++++++++++++++++++++++
arch/riscv/include/asm/thread_info.h | 1 +
2 files changed, 130 insertions(+)
create mode 100644 arch/riscv/include/asm/compat.h

diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compat.h
new file mode 100644
index 000000000000..2ac955b51148
--- /dev/null
+++ b/arch/riscv/include/asm/compat.h
@@ -0,0 +1,129 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_COMPAT_H
+#define __ASM_COMPAT_H
+
+#define COMPAT_UTS_MACHINE "riscv\0\0"
+
+/*
+ * Architecture specific compatibility types
+ */
+#include <linux/types.h>
+#include <linux/sched.h>
+#include <linux/sched/task_stack.h>
+#include <asm-generic/compat.h>
+
+static inline int is_compat_task(void)
+{
+ return test_thread_flag(TIF_32BIT);
+}
+
+struct compat_user_regs_struct {
+ compat_ulong_t pc;
+ compat_ulong_t ra;
+ compat_ulong_t sp;
+ compat_ulong_t gp;
+ compat_ulong_t tp;
+ compat_ulong_t t0;
+ compat_ulong_t t1;
+ compat_ulong_t t2;
+ compat_ulong_t s0;
+ compat_ulong_t s1;
+ compat_ulong_t a0;
+ compat_ulong_t a1;
+ compat_ulong_t a2;
+ compat_ulong_t a3;
+ compat_ulong_t a4;
+ compat_ulong_t a5;
+ compat_ulong_t a6;
+ compat_ulong_t a7;
+ compat_ulong_t s2;
+ compat_ulong_t s3;
+ compat_ulong_t s4;
+ compat_ulong_t s5;
+ compat_ulong_t s6;
+ compat_ulong_t s7;
+ compat_ulong_t s8;
+ compat_ulong_t s9;
+ compat_ulong_t s10;
+ compat_ulong_t s11;
+ compat_ulong_t t3;
+ compat_ulong_t t4;
+ compat_ulong_t t5;
+ compat_ulong_t t6;
+};
+
+static inline void regs_to_cregs(struct compat_user_regs_struct *cregs,
+ struct pt_regs *regs)
+{
+ cregs->pc = (compat_ulong_t) regs->epc;
+ cregs->ra = (compat_ulong_t) regs->ra;
+ cregs->sp = (compat_ulong_t) regs->sp;
+ cregs->gp = (compat_ulong_t) regs->gp;
+ cregs->tp = (compat_ulong_t) regs->tp;
+ cregs->t0 = (compat_ulong_t) regs->t0;
+ cregs->t1 = (compat_ulong_t) regs->t1;
+ cregs->t2 = (compat_ulong_t) regs->t2;
+ cregs->s0 = (compat_ulong_t) regs->s0;
+ cregs->s1 = (compat_ulong_t) regs->s1;
+ cregs->a0 = (compat_ulong_t) regs->a0;
+ cregs->a1 = (compat_ulong_t) regs->a1;
+ cregs->a2 = (compat_ulong_t) regs->a2;
+ cregs->a3 = (compat_ulong_t) regs->a3;
+ cregs->a4 = (compat_ulong_t) regs->a4;
+ cregs->a5 = (compat_ulong_t) regs->a5;
+ cregs->a6 = (compat_ulong_t) regs->a6;
+ cregs->a7 = (compat_ulong_t) regs->a7;
+ cregs->s2 = (compat_ulong_t) regs->s2;
+ cregs->s3 = (compat_ulong_t) regs->s3;
+ cregs->s4 = (compat_ulong_t) regs->s4;
+ cregs->s5 = (compat_ulong_t) regs->s5;
+ cregs->s6 = (compat_ulong_t) regs->s6;
+ cregs->s7 = (compat_ulong_t) regs->s7;
+ cregs->s8 = (compat_ulong_t) regs->s8;
+ cregs->s9 = (compat_ulong_t) regs->s9;
+ cregs->s10 = (compat_ulong_t) regs->s10;
+ cregs->s11 = (compat_ulong_t) regs->s11;
+ cregs->t3 = (compat_ulong_t) regs->t3;
+ cregs->t4 = (compat_ulong_t) regs->t4;
+ cregs->t5 = (compat_ulong_t) regs->t5;
+ cregs->t6 = (compat_ulong_t) regs->t6;
+};
+
+static inline void cregs_to_regs(struct compat_user_regs_struct *cregs,
+ struct pt_regs *regs)
+{
+ regs->epc = (unsigned long) cregs->pc;
+ regs->ra = (unsigned long) cregs->ra;
+ regs->sp = (unsigned long) cregs->sp;
+ regs->gp = (unsigned long) cregs->gp;
+ regs->tp = (unsigned long) cregs->tp;
+ regs->t0 = (unsigned long) cregs->t0;
+ regs->t1 = (unsigned long) cregs->t1;
+ regs->t2 = (unsigned long) cregs->t2;
+ regs->s0 = (unsigned long) cregs->s0;
+ regs->s1 = (unsigned long) cregs->s1;
+ regs->a0 = (unsigned long) cregs->a0;
+ regs->a1 = (unsigned long) cregs->a1;
+ regs->a2 = (unsigned long) cregs->a2;
+ regs->a3 = (unsigned long) cregs->a3;
+ regs->a4 = (unsigned long) cregs->a4;
+ regs->a5 = (unsigned long) cregs->a5;
+ regs->a6 = (unsigned long) cregs->a6;
+ regs->a7 = (unsigned long) cregs->a7;
+ regs->s2 = (unsigned long) cregs->s2;
+ regs->s3 = (unsigned long) cregs->s3;
+ regs->s4 = (unsigned long) cregs->s4;
+ regs->s5 = (unsigned long) cregs->s5;
+ regs->s6 = (unsigned long) cregs->s6;
+ regs->s7 = (unsigned long) cregs->s7;
+ regs->s8 = (unsigned long) cregs->s8;
+ regs->s9 = (unsigned long) cregs->s9;
+ regs->s10 = (unsigned long) cregs->s10;
+ regs->s11 = (unsigned long) cregs->s11;
+ regs->t3 = (unsigned long) cregs->t3;
+ regs->t4 = (unsigned long) cregs->t4;
+ regs->t5 = (unsigned long) cregs->t5;
+ regs->t6 = (unsigned long) cregs->t6;
+};
+
+#endif /* __ASM_COMPAT_H */
diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
index 60da0dcacf14..e1ad5131944b 100644
--- a/arch/riscv/include/asm/thread_info.h
+++ b/arch/riscv/include/asm/thread_info.h
@@ -91,6 +91,7 @@ struct thread_info {
#define TIF_SECCOMP 8 /* syscall secure computing */
#define TIF_NOTIFY_SIGNAL 9 /* signal notifications exist */
#define TIF_UPROBE 10 /* uprobe breakpoint or singlestep */
+#define TIF_32BIT 11 /* compat-mode 32bit process */

#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
--
2.25.1

2022-03-22 23:30:05

by Guo Ren

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

From: Christoph Hellwig <[email protected]>

The F_GETLK64/F_SETLK64/F_SETLKW64 fcntl opcodes are only implemented
for the 32-bit syscall APIs, but are also needed for compat handling
on 64-bit kernels.

Consolidate them in unistd.h instead of definining the internal compat
definitions in compat.h, which is rather error prone (e.g. parisc
gets the values wrong currently).

Note that before this change they were never visible to userspace due
to the fact that CONFIG_64BIT is only set for kernel builds.

Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Arnd Bergmann <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
---
arch/arm64/include/asm/compat.h | 4 ----
arch/mips/include/asm/compat.h | 4 ----
arch/mips/include/uapi/asm/fcntl.h | 4 ++--
arch/powerpc/include/asm/compat.h | 4 ----
arch/s390/include/asm/compat.h | 4 ----
arch/sparc/include/asm/compat.h | 4 ----
arch/x86/include/asm/compat.h | 4 ----
include/uapi/asm-generic/fcntl.h | 4 ++--
tools/include/uapi/asm-generic/fcntl.h | 2 --
9 files changed, 4 insertions(+), 30 deletions(-)

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index eaa6ca062d89..276328765408 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -73,10 +73,6 @@ struct compat_flock {
compat_pid_t l_pid;
};

-#define F_GETLK64 12 /* using 'struct flock64' */
-#define F_SETLK64 13
-#define F_SETLKW64 14
-
struct compat_flock64 {
short l_type;
short l_whence;
diff --git a/arch/mips/include/asm/compat.h b/arch/mips/include/asm/compat.h
index bbb3bc5a42fd..6a350c1f70d7 100644
--- a/arch/mips/include/asm/compat.h
+++ b/arch/mips/include/asm/compat.h
@@ -65,10 +65,6 @@ struct compat_flock {
s32 pad[4];
};

-#define F_GETLK64 33
-#define F_SETLK64 34
-#define F_SETLKW64 35
-
struct compat_flock64 {
short l_type;
short l_whence;
diff --git a/arch/mips/include/uapi/asm/fcntl.h b/arch/mips/include/uapi/asm/fcntl.h
index 9e44ac810db9..0369a38e3d4f 100644
--- a/arch/mips/include/uapi/asm/fcntl.h
+++ b/arch/mips/include/uapi/asm/fcntl.h
@@ -44,11 +44,11 @@
#define F_SETOWN 24 /* for sockets. */
#define F_GETOWN 23 /* for sockets. */

-#ifndef __mips64
+#if __BITS_PER_LONG == 32 || defined(__KERNEL__)
#define F_GETLK64 33 /* using 'struct flock64' */
#define F_SETLK64 34
#define F_SETLKW64 35
-#endif
+#endif /* __BITS_PER_LONG == 32 || defined(__KERNEL__) */

#if _MIPS_SIM != _MIPS_SIM_ABI64
#define __ARCH_FLOCK_EXTRA_SYSID long l_sysid;
diff --git a/arch/powerpc/include/asm/compat.h b/arch/powerpc/include/asm/compat.h
index 7afc96fb6524..83d8f70779cb 100644
--- a/arch/powerpc/include/asm/compat.h
+++ b/arch/powerpc/include/asm/compat.h
@@ -52,10 +52,6 @@ struct compat_flock {
compat_pid_t l_pid;
};

-#define F_GETLK64 12 /* using 'struct flock64' */
-#define F_SETLK64 13
-#define F_SETLKW64 14
-
struct compat_flock64 {
short l_type;
short l_whence;
diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index cdc7ae72529d..0f14b3188b1b 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -110,10 +110,6 @@ struct compat_flock {
compat_pid_t l_pid;
};

-#define F_GETLK64 12
-#define F_SETLK64 13
-#define F_SETLKW64 14
-
struct compat_flock64 {
short l_type;
short l_whence;
diff --git a/arch/sparc/include/asm/compat.h b/arch/sparc/include/asm/compat.h
index bd949fcf9d63..108078751bb5 100644
--- a/arch/sparc/include/asm/compat.h
+++ b/arch/sparc/include/asm/compat.h
@@ -84,10 +84,6 @@ struct compat_flock {
short __unused;
};

-#define F_GETLK64 12
-#define F_SETLK64 13
-#define F_SETLKW64 14
-
struct compat_flock64 {
short l_type;
short l_whence;
diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
index 7516e4199b3c..8d19a212f4f2 100644
--- a/arch/x86/include/asm/compat.h
+++ b/arch/x86/include/asm/compat.h
@@ -58,10 +58,6 @@ struct compat_flock {
compat_pid_t l_pid;
};

-#define F_GETLK64 12 /* using 'struct flock64' */
-#define F_SETLK64 13
-#define F_SETLKW64 14
-
/*
* IA32 uses 4 byte alignment for 64 bit quantities,
* so we need to pack this structure.
diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h
index 77aa9f2ff98d..f13d37b60775 100644
--- a/include/uapi/asm-generic/fcntl.h
+++ b/include/uapi/asm-generic/fcntl.h
@@ -116,13 +116,13 @@
#define F_GETSIG 11 /* for sockets. */
#endif

-#ifndef CONFIG_64BIT
+#if __BITS_PER_LONG == 32 || defined(__KERNEL__)
#ifndef F_GETLK64
#define F_GETLK64 12 /* using 'struct flock64' */
#define F_SETLK64 13
#define F_SETLKW64 14
#endif
-#endif
+#endif /* __BITS_PER_LONG == 32 || defined(__KERNEL__) */

#ifndef F_SETOWN_EX
#define F_SETOWN_EX 15
diff --git a/tools/include/uapi/asm-generic/fcntl.h b/tools/include/uapi/asm-generic/fcntl.h
index 99bc9b15ce2b..0197042b7dfb 100644
--- a/tools/include/uapi/asm-generic/fcntl.h
+++ b/tools/include/uapi/asm-generic/fcntl.h
@@ -115,13 +115,11 @@
#define F_GETSIG 11 /* for sockets. */
#endif

-#ifndef CONFIG_64BIT
#ifndef F_GETLK64
#define F_GETLK64 12 /* using 'struct flock64' */
#define F_SETLK64 13
#define F_SETLKW64 14
#endif
-#endif

#ifndef F_SETOWN_EX
#define F_SETOWN_EX 15
--
2.25.1

2022-03-23 01:59:53

by Guo Ren

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

From: Guo Ren <[email protected]>

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

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

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

Signed-off-by: Guo Ren <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Arnd Bergmann <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
---
arch/riscv/include/asm/pgtable.h | 13 +++++++++++--
arch/riscv/include/asm/processor.h | 6 +++++-
2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index e3549e50de95..afdc9ece2ba4 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -705,8 +705,17 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
* 63–48 all equal to bit 47, or else a page-fault exception will occur."
*/
#ifdef CONFIG_64BIT
-#define TASK_SIZE (PGDIR_SIZE * PTRS_PER_PGD / 2)
-#define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2)
+#define TASK_SIZE_64 (PGDIR_SIZE * PTRS_PER_PGD / 2)
+#define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2)
+
+#ifdef CONFIG_COMPAT
+#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE)
+#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
+ TASK_SIZE_32 : TASK_SIZE_64)
+#else
+#define TASK_SIZE TASK_SIZE_64
+#endif
+
#else
#define TASK_SIZE FIXADDR_START
#define TASK_SIZE_MIN TASK_SIZE
diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h
index 0749924d9e55..21c8072dce17 100644
--- a/arch/riscv/include/asm/processor.h
+++ b/arch/riscv/include/asm/processor.h
@@ -19,7 +19,11 @@
#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3)

#define STACK_TOP TASK_SIZE
-#define STACK_TOP_MAX STACK_TOP
+#ifdef CONFIG_64BIT
+#define STACK_TOP_MAX TASK_SIZE_64
+#else
+#define STACK_TOP_MAX TASK_SIZE
+#endif
#define STACK_ALIGN 16

#ifndef __ASSEMBLY__
--
2.25.1

2022-03-23 02:27:47

by Guo Ren

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

From: Guo Ren <[email protected]>

If the current task is in COMPAT mode, set SR_UXL_32 in status for
returning userspace. We need CONFIG _COMPAT to prevent compiling
errors with rv32 defconfig.

Signed-off-by: Guo Ren <[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/kernel/process.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 03ac3aa611f5..8c7665481a9f 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -97,6 +97,15 @@ void start_thread(struct pt_regs *regs, unsigned long pc,
}
regs->epc = pc;
regs->sp = sp;
+
+#ifdef CONFIG_64BIT
+ regs->status &= ~SR_UXL;
+
+ if (is_compat_task())
+ regs->status |= SR_UXL_32;
+ else
+ regs->status |= SR_UXL_64;
+#endif
}

void flush_thread(void)
--
2.25.1

2022-03-23 03:49:35

by Guo Ren

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

From: Guo Ren <[email protected]>

Reconstruct __setup_additional_pages() by appending vdso info
pointer argument to meet compat_vdso_info requirement. And change
vm_special_mapping *dm, *cm initialization into static.

Signed-off-by: Guo Ren <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Reviewed-by: Palmer Dabbelt <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
Cc: Arnd Bergmann <[email protected]>
---
arch/riscv/include/asm/elf.h | 5 ++
arch/riscv/include/asm/mmu.h | 1 +
arch/riscv/kernel/vdso.c | 105 +++++++++++++++++++++++------------
3 files changed, 76 insertions(+), 35 deletions(-)

diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index 754fdb8cee96..14fc7342490b 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -130,5 +130,10 @@ do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
typedef compat_ulong_t compat_elf_greg_t;
typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];

+extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
+ int uses_interp);
+#define compat_arch_setup_additional_pages \
+ compat_arch_setup_additional_pages
+
#endif /* CONFIG_COMPAT */
#endif /* _ASM_RISCV_ELF_H */
diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h
index 0099dc116168..cedcf8ea3c76 100644
--- a/arch/riscv/include/asm/mmu.h
+++ b/arch/riscv/include/asm/mmu.h
@@ -16,6 +16,7 @@ typedef struct {
atomic_long_t id;
#endif
void *vdso;
+ void *vdso_info;
#ifdef CONFIG_SMP
/* A local icache flush is needed before user execution can resume. */
cpumask_t icache_stale_mask;
diff --git a/arch/riscv/kernel/vdso.c b/arch/riscv/kernel/vdso.c
index a9436a65161a..50fe4c877603 100644
--- a/arch/riscv/kernel/vdso.c
+++ b/arch/riscv/kernel/vdso.c
@@ -23,6 +23,9 @@ struct vdso_data {
#endif

extern char vdso_start[], vdso_end[];
+#ifdef CONFIG_COMPAT
+extern char compat_vdso_start[], compat_vdso_end[];
+#endif

enum vvar_pages {
VVAR_DATA_PAGE_OFFSET,
@@ -30,6 +33,11 @@ enum vvar_pages {
VVAR_NR_PAGES,
};

+enum rv_vdso_map {
+ RV_VDSO_MAP_VVAR,
+ RV_VDSO_MAP_VDSO,
+};
+
#define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT)

/*
@@ -52,12 +60,6 @@ struct __vdso_info {
struct vm_special_mapping *cm;
};

-static struct __vdso_info vdso_info __ro_after_init = {
- .name = "vdso",
- .vdso_code_start = vdso_start,
- .vdso_code_end = vdso_end,
-};
-
static int vdso_mremap(const struct vm_special_mapping *sm,
struct vm_area_struct *new_vma)
{
@@ -66,37 +68,33 @@ static int vdso_mremap(const struct vm_special_mapping *sm,
return 0;
}

-static int __init __vdso_init(void)
+static void __init __vdso_init(struct __vdso_info *vdso_info)
{
unsigned int i;
struct page **vdso_pagelist;
unsigned long pfn;

- if (memcmp(vdso_info.vdso_code_start, "\177ELF", 4)) {
- pr_err("vDSO is not a valid ELF object!\n");
- return -EINVAL;
- }
+ if (memcmp(vdso_info->vdso_code_start, "\177ELF", 4))
+ panic("vDSO is not a valid ELF object!\n");

- vdso_info.vdso_pages = (
- vdso_info.vdso_code_end -
- vdso_info.vdso_code_start) >>
+ vdso_info->vdso_pages = (
+ vdso_info->vdso_code_end -
+ vdso_info->vdso_code_start) >>
PAGE_SHIFT;

- vdso_pagelist = kcalloc(vdso_info.vdso_pages,
+ vdso_pagelist = kcalloc(vdso_info->vdso_pages,
sizeof(struct page *),
GFP_KERNEL);
if (vdso_pagelist == NULL)
- return -ENOMEM;
+ panic("vDSO kcalloc failed!\n");

/* Grab the vDSO code pages. */
- pfn = sym_to_pfn(vdso_info.vdso_code_start);
+ pfn = sym_to_pfn(vdso_info->vdso_code_start);

- for (i = 0; i < vdso_info.vdso_pages; i++)
+ for (i = 0; i < vdso_info->vdso_pages; i++)
vdso_pagelist[i] = pfn_to_page(pfn + i);

- vdso_info.cm->pages = vdso_pagelist;
-
- return 0;
+ vdso_info->cm->pages = vdso_pagelist;
}

#ifdef CONFIG_TIME_NS
@@ -116,13 +114,14 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)
{
struct mm_struct *mm = task->mm;
struct vm_area_struct *vma;
+ struct __vdso_info *vdso_info = mm->context.vdso_info;

mmap_read_lock(mm);

for (vma = mm->mmap; vma; vma = vma->vm_next) {
unsigned long size = vma->vm_end - vma->vm_start;

- if (vma_is_special_mapping(vma, vdso_info.dm))
+ if (vma_is_special_mapping(vma, vdso_info->dm))
zap_page_range(vma, vma->vm_start, size);
}

@@ -187,11 +186,6 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
return vmf_insert_pfn(vma, vmf->address, pfn);
}

-enum rv_vdso_map {
- RV_VDSO_MAP_VVAR,
- RV_VDSO_MAP_VDSO,
-};
-
static struct vm_special_mapping rv_vdso_maps[] __ro_after_init = {
[RV_VDSO_MAP_VVAR] = {
.name = "[vvar]",
@@ -203,25 +197,46 @@ static struct vm_special_mapping rv_vdso_maps[] __ro_after_init = {
},
};

+static struct __vdso_info vdso_info __ro_after_init = {
+ .name = "vdso",
+ .vdso_code_start = vdso_start,
+ .vdso_code_end = vdso_end,
+ .dm = &rv_vdso_maps[RV_VDSO_MAP_VVAR],
+ .cm = &rv_vdso_maps[RV_VDSO_MAP_VDSO],
+};
+
+#ifdef CONFIG_COMPAT
+static struct __vdso_info compat_vdso_info __ro_after_init = {
+ .name = "compat_vdso",
+ .vdso_code_start = compat_vdso_start,
+ .vdso_code_end = compat_vdso_end,
+ .dm = &rv_vdso_maps[RV_VDSO_MAP_VVAR],
+ .cm = &rv_vdso_maps[RV_VDSO_MAP_VDSO],
+};
+#endif
+
static int __init vdso_init(void)
{
- vdso_info.dm = &rv_vdso_maps[RV_VDSO_MAP_VVAR];
- vdso_info.cm = &rv_vdso_maps[RV_VDSO_MAP_VDSO];
+ __vdso_init(&vdso_info);
+#ifdef CONFIG_COMPAT
+ __vdso_init(&compat_vdso_info);
+#endif

- return __vdso_init();
+ return 0;
}
arch_initcall(vdso_init);

static int __setup_additional_pages(struct mm_struct *mm,
struct linux_binprm *bprm,
- int uses_interp)
+ int uses_interp,
+ struct __vdso_info *vdso_info)
{
unsigned long vdso_base, vdso_text_len, vdso_mapping_len;
void *ret;

BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES);

- vdso_text_len = vdso_info.vdso_pages << PAGE_SHIFT;
+ vdso_text_len = vdso_info->vdso_pages << PAGE_SHIFT;
/* Be sure to map the data page */
vdso_mapping_len = vdso_text_len + VVAR_SIZE;

@@ -232,16 +247,18 @@ static int __setup_additional_pages(struct mm_struct *mm,
}

ret = _install_special_mapping(mm, vdso_base, VVAR_SIZE,
- (VM_READ | VM_MAYREAD | VM_PFNMAP), vdso_info.dm);
+ (VM_READ | VM_MAYREAD | VM_PFNMAP), vdso_info->dm);
if (IS_ERR(ret))
goto up_fail;

vdso_base += VVAR_SIZE;
mm->context.vdso = (void *)vdso_base;
+ mm->context.vdso_info = (void *)vdso_info;
+
ret =
_install_special_mapping(mm, vdso_base, vdso_text_len,
(VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
- vdso_info.cm);
+ vdso_info->cm);

if (IS_ERR(ret))
goto up_fail;
@@ -253,6 +270,24 @@ static int __setup_additional_pages(struct mm_struct *mm,
return PTR_ERR(ret);
}

+#ifdef CONFIG_COMPAT
+int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
+ int uses_interp)
+{
+ struct mm_struct *mm = current->mm;
+ int ret;
+
+ if (mmap_write_lock_killable(mm))
+ return -EINTR;
+
+ ret = __setup_additional_pages(mm, bprm, uses_interp,
+ &compat_vdso_info);
+ mmap_write_unlock(mm);
+
+ return ret;
+}
+#endif
+
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
{
struct mm_struct *mm = current->mm;
@@ -261,7 +296,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
if (mmap_write_lock_killable(mm))
return -EINTR;

- ret = __setup_additional_pages(mm, bprm, uses_interp);
+ ret = __setup_additional_pages(mm, bprm, uses_interp, &vdso_info);
mmap_write_unlock(mm);

return ret;
--
2.25.1

2022-03-23 04:09:18

by Guo Ren

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

From: Guo Ren <[email protected]>

The existing per-arch definitions are pretty much historic cruft.
Move SYSVIPC_COMPAT into init/Kconfig.

Signed-off-by: Guo Ren <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Acked-by: Arnd Bergmann <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
---
arch/arm64/Kconfig | 4 ----
arch/mips/Kconfig | 5 -----
arch/parisc/Kconfig | 4 ----
arch/powerpc/Kconfig | 5 -----
arch/s390/Kconfig | 3 ---
arch/sparc/Kconfig | 5 -----
arch/x86/Kconfig | 4 ----
init/Kconfig | 4 ++++
8 files changed, 4 insertions(+), 30 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index c842878f8133..03b14ac18214 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -2114,10 +2114,6 @@ config DMI

endmenu

-config SYSVIPC_COMPAT
- def_bool y
- depends on COMPAT && SYSVIPC
-
menu "Power management options"

source "kernel/power/Kconfig"
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 058446f01487..91a17ad380c9 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -3170,16 +3170,12 @@ config MIPS32_COMPAT
config COMPAT
bool

-config SYSVIPC_COMPAT
- bool
-
config MIPS32_O32
bool "Kernel support for o32 binaries"
depends on 64BIT
select ARCH_WANT_OLD_COMPAT_IPC
select COMPAT
select MIPS32_COMPAT
- select SYSVIPC_COMPAT if SYSVIPC
help
Select this option if you want to run o32 binaries. These are pure
32-bit binaries as used by the 32-bit Linux/MIPS port. Most of
@@ -3193,7 +3189,6 @@ config MIPS32_N32
select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
select COMPAT
select MIPS32_COMPAT
- select SYSVIPC_COMPAT if SYSVIPC
help
Select this option if you want to run n32 binaries. These are
64-bit binaries using 32-bit quantities for addressing and certain
diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig
index 43c1c880def6..bc56759d44a2 100644
--- a/arch/parisc/Kconfig
+++ b/arch/parisc/Kconfig
@@ -345,10 +345,6 @@ config COMPAT
def_bool y
depends on 64BIT

-config SYSVIPC_COMPAT
- def_bool y
- depends on COMPAT && SYSVIPC
-
config AUDIT_ARCH
def_bool y

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index b779603978e1..5a32b7f21af2 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -291,11 +291,6 @@ config COMPAT
select ARCH_WANT_OLD_COMPAT_IPC
select COMPAT_OLD_SIGACTION

-config SYSVIPC_COMPAT
- bool
- depends on COMPAT && SYSVIPC
- default y
-
config SCHED_OMIT_FRAME_POINTER
bool
default y
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index be9f39fd06df..80f69cafbb87 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -459,9 +459,6 @@ config COMPAT
(and some other stuff like libraries and such) is needed for
executing 31 bit applications. It is safe to say "Y".

-config SYSVIPC_COMPAT
- def_bool y if COMPAT && SYSVIPC
-
config SMP
def_bool y

diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 1cab1b284f1a..15d5725bd623 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -488,9 +488,4 @@ config COMPAT
select ARCH_WANT_OLD_COMPAT_IPC
select COMPAT_OLD_SIGACTION

-config SYSVIPC_COMPAT
- bool
- depends on COMPAT && SYSVIPC
- default y
-
source "drivers/sbus/char/Kconfig"
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 9f5bd41bf660..7d0487189f6e 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2860,10 +2860,6 @@ config COMPAT
if COMPAT
config COMPAT_FOR_U64_ALIGNMENT
def_bool y
-
-config SYSVIPC_COMPAT
- def_bool y
- depends on SYSVIPC
endif

endmenu
diff --git a/init/Kconfig b/init/Kconfig
index e9119bf54b1f..589ccec56571 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -386,6 +386,10 @@ config SYSVIPC_SYSCTL
depends on SYSCTL
default y

+config SYSVIPC_COMPAT
+ def_bool y
+ depends on COMPAT && SYSVIPC
+
config POSIX_MQUEUE
bool "POSIX Message Queues"
depends on NET
--
2.25.1

2022-03-23 08:21:08

by Guo Ren

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

From: Guo Ren <[email protected]>

Implement necessary type and macro for compat elf. See the code
comment for detail.

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]>
---
arch/riscv/include/asm/elf.h | 41 +++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index f53c40026c7a..a234656cfb5d 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -8,6 +8,8 @@
#ifndef _ASM_RISCV_ELF_H
#define _ASM_RISCV_ELF_H

+#include <uapi/linux/elf.h>
+#include <linux/compat.h>
#include <uapi/asm/elf.h>
#include <asm/auxvec.h>
#include <asm/byteorder.h>
@@ -18,11 +20,13 @@
*/
#define ELF_ARCH EM_RISCV

+#ifndef ELF_CLASS
#ifdef CONFIG_64BIT
#define ELF_CLASS ELFCLASS64
#else
#define ELF_CLASS ELFCLASS32
#endif
+#endif

#define ELF_DATA ELFDATA2LSB

@@ -31,6 +35,8 @@
*/
#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)

+#define compat_elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+
#define CORE_DUMP_USE_REGSET
#define ELF_EXEC_PAGESIZE (PAGE_SIZE)

@@ -43,8 +49,14 @@
#define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)

#ifdef CONFIG_64BIT
+#ifdef CONFIG_COMPAT
+#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
+ 0x7ff >> (PAGE_SHIFT - 12) : \
+ 0x3ffff >> (PAGE_SHIFT - 12))
+#else
#define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
#endif
+#endif
/*
* This yields a mask that user programs can use to figure out what
* instruction set this CPU supports. This could be done in user space,
@@ -60,11 +72,19 @@ extern unsigned long elf_hwcap;
*/
#define ELF_PLATFORM (NULL)

+#define COMPAT_ELF_PLATFORM (NULL)
+
#ifdef CONFIG_MMU
#define ARCH_DLINFO \
do { \
+ /* \
+ * Note that we add ulong after elf_addr_t because \
+ * casting current->mm->context.vdso triggers a cast \
+ * warning of cast from pointer to integer for \
+ * COMPAT ELFCLASS32. \
+ */ \
NEW_AUX_ENT(AT_SYSINFO_EHDR, \
- (elf_addr_t)current->mm->context.vdso); \
+ (elf_addr_t)(ulong)current->mm->context.vdso); \
NEW_AUX_ENT(AT_L1I_CACHESIZE, \
get_cache_size(1, CACHE_TYPE_INST)); \
NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \
@@ -90,4 +110,23 @@ do { \
*(struct user_regs_struct *)regs; \
} while (0);

+#ifdef CONFIG_COMPAT
+
+#define SET_PERSONALITY(ex) \
+do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
+ set_thread_flag(TIF_32BIT); \
+ else \
+ clear_thread_flag(TIF_32BIT); \
+ if (personality(current->personality) != PER_LINUX32) \
+ set_personality(PER_LINUX | \
+ (current->personality & (~PER_MASK))); \
+} while (0)
+
+#define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)
+
+/* rv32 registers */
+typedef compat_ulong_t compat_elf_greg_t;
+typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
+
+#endif /* CONFIG_COMPAT */
#endif /* _ASM_RISCV_ELF_H */
--
2.25.1

2022-03-23 12:02:45

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH V9 00/20] riscv: compat: Add COMPAT Kbuild skeletal support

On Tue, 22 Mar 2022 07:39:43 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.17-rc8, 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_v8 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 v9:
> - Fixup rv32 call rv64 segment fault
> - Ready for 5.18

Thanks. I'd also seen some arm64 autobuilder failures, not sure if
those got fixed as I don't see anything specificlly listed in here
(sorry if I just missed it).

I've gone ahead and put this on palmer/riscv-compat, I'm going to let it
sit at least overnight before putting it on for-next proper. It's a
big one and the autobuilders seem to find stuff over there, I don't want
to break any of the other ports. IIRC you were getting CC'd on the
build failures I was seeing.

If it's clean I'll merge it into for-next propely. It's passing my
staging merge tests, but I don't yet have anything specifically for
compat -- at least it's not causing any regressions, though.

>
> 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):
> kconfig: 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: Re-implement TASK_SIZE for COMPAT_32BIT
> 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 | 91 +------
> 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/configs/rv32_defconfig | 135 ----------
> 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 | 243 ++++++++++++++++++
> 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 +-
> 68 files changed, 1205 insertions(+), 698 deletions(-)
> delete mode 100644 arch/riscv/configs/rv32_defconfig
> 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

2022-03-23 14:02:45

by Guo Ren

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

From: Guo Ren <[email protected]>

Let's follow the origin patch's spirit:

The only difference between rv32_defconfig and defconfig is that
rv32_defconfig has CONFIG_ARCH_RV32I=y.

This is helpful to compare rv64-compat-rv32 v.s. rv32-linux.

Fixes: 1b937e8faa87ccfb ("RISC-V: Add separate defconfig for 32bit systems")
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/Makefile | 4 +
arch/riscv/configs/rv32_defconfig | 135 ------------------------------
2 files changed, 4 insertions(+), 135 deletions(-)
delete mode 100644 arch/riscv/configs/rv32_defconfig

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 7d81102cffd4..c6ca1b9cbf71 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -154,3 +154,7 @@ PHONY += rv64_randconfig
rv64_randconfig:
$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
-f $(srctree)/Makefile randconfig
+
+PHONY += rv32_defconfig
+rv32_defconfig:
+ $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
diff --git a/arch/riscv/configs/rv32_defconfig b/arch/riscv/configs/rv32_defconfig
deleted file mode 100644
index 8b56a7f1eb06..000000000000
--- a/arch/riscv/configs/rv32_defconfig
+++ /dev/null
@@ -1,135 +0,0 @@
-CONFIG_SYSVIPC=y
-CONFIG_POSIX_MQUEUE=y
-CONFIG_NO_HZ_IDLE=y
-CONFIG_HIGH_RES_TIMERS=y
-CONFIG_BPF_SYSCALL=y
-CONFIG_IKCONFIG=y
-CONFIG_IKCONFIG_PROC=y
-CONFIG_CGROUPS=y
-CONFIG_CGROUP_SCHED=y
-CONFIG_CFS_BANDWIDTH=y
-CONFIG_CGROUP_BPF=y
-CONFIG_NAMESPACES=y
-CONFIG_USER_NS=y
-CONFIG_CHECKPOINT_RESTORE=y
-CONFIG_BLK_DEV_INITRD=y
-CONFIG_EXPERT=y
-# CONFIG_SYSFS_SYSCALL is not set
-CONFIG_SOC_SIFIVE=y
-CONFIG_SOC_VIRT=y
-CONFIG_ARCH_RV32I=y
-CONFIG_SMP=y
-CONFIG_HOTPLUG_CPU=y
-CONFIG_VIRTUALIZATION=y
-CONFIG_KVM=m
-CONFIG_JUMP_LABEL=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-CONFIG_NET=y
-CONFIG_PACKET=y
-CONFIG_UNIX=y
-CONFIG_INET=y
-CONFIG_IP_MULTICAST=y
-CONFIG_IP_ADVANCED_ROUTER=y
-CONFIG_IP_PNP=y
-CONFIG_IP_PNP_DHCP=y
-CONFIG_IP_PNP_BOOTP=y
-CONFIG_IP_PNP_RARP=y
-CONFIG_NETLINK_DIAG=y
-CONFIG_NET_9P=y
-CONFIG_NET_9P_VIRTIO=y
-CONFIG_PCI=y
-CONFIG_PCIEPORTBUS=y
-CONFIG_PCI_HOST_GENERIC=y
-CONFIG_PCIE_XILINX=y
-CONFIG_DEVTMPFS=y
-CONFIG_DEVTMPFS_MOUNT=y
-CONFIG_BLK_DEV_LOOP=y
-CONFIG_VIRTIO_BLK=y
-CONFIG_BLK_DEV_SD=y
-CONFIG_BLK_DEV_SR=y
-CONFIG_SCSI_VIRTIO=y
-CONFIG_ATA=y
-CONFIG_SATA_AHCI=y
-CONFIG_SATA_AHCI_PLATFORM=y
-CONFIG_NETDEVICES=y
-CONFIG_VIRTIO_NET=y
-CONFIG_MACB=y
-CONFIG_E1000E=y
-CONFIG_R8169=y
-CONFIG_MICROSEMI_PHY=y
-CONFIG_INPUT_MOUSEDEV=y
-CONFIG_SERIAL_8250=y
-CONFIG_SERIAL_8250_CONSOLE=y
-CONFIG_SERIAL_OF_PLATFORM=y
-CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
-CONFIG_HVC_RISCV_SBI=y
-CONFIG_VIRTIO_CONSOLE=y
-CONFIG_HW_RANDOM=y
-CONFIG_HW_RANDOM_VIRTIO=y
-CONFIG_SPI=y
-CONFIG_SPI_SIFIVE=y
-# CONFIG_PTP_1588_CLOCK is not set
-CONFIG_DRM=y
-CONFIG_DRM_RADEON=y
-CONFIG_DRM_VIRTIO_GPU=y
-CONFIG_FB=y
-CONFIG_FRAMEBUFFER_CONSOLE=y
-CONFIG_USB=y
-CONFIG_USB_XHCI_HCD=y
-CONFIG_USB_XHCI_PLATFORM=y
-CONFIG_USB_EHCI_HCD=y
-CONFIG_USB_EHCI_HCD_PLATFORM=y
-CONFIG_USB_OHCI_HCD=y
-CONFIG_USB_OHCI_HCD_PLATFORM=y
-CONFIG_USB_STORAGE=y
-CONFIG_USB_UAS=y
-CONFIG_MMC=y
-CONFIG_MMC_SPI=y
-CONFIG_RTC_CLASS=y
-CONFIG_VIRTIO_PCI=y
-CONFIG_VIRTIO_BALLOON=y
-CONFIG_VIRTIO_INPUT=y
-CONFIG_VIRTIO_MMIO=y
-CONFIG_RPMSG_CHAR=y
-CONFIG_RPMSG_VIRTIO=y
-CONFIG_EXT4_FS=y
-CONFIG_EXT4_FS_POSIX_ACL=y
-CONFIG_AUTOFS4_FS=y
-CONFIG_MSDOS_FS=y
-CONFIG_VFAT_FS=y
-CONFIG_TMPFS=y
-CONFIG_TMPFS_POSIX_ACL=y
-CONFIG_NFS_FS=y
-CONFIG_NFS_V4=y
-CONFIG_NFS_V4_1=y
-CONFIG_NFS_V4_2=y
-CONFIG_ROOT_NFS=y
-CONFIG_9P_FS=y
-CONFIG_CRYPTO_USER_API_HASH=y
-CONFIG_CRYPTO_DEV_VIRTIO=y
-CONFIG_PRINTK_TIME=y
-CONFIG_DEBUG_FS=y
-CONFIG_DEBUG_PAGEALLOC=y
-CONFIG_SCHED_STACK_END_CHECK=y
-CONFIG_DEBUG_VM=y
-CONFIG_DEBUG_VM_PGFLAGS=y
-CONFIG_DEBUG_MEMORY_INIT=y
-CONFIG_DEBUG_PER_CPU_MAPS=y
-CONFIG_SOFTLOCKUP_DETECTOR=y
-CONFIG_WQ_WATCHDOG=y
-CONFIG_DEBUG_TIMEKEEPING=y
-CONFIG_DEBUG_RT_MUTEXES=y
-CONFIG_DEBUG_SPINLOCK=y
-CONFIG_DEBUG_MUTEXES=y
-CONFIG_DEBUG_RWSEMS=y
-CONFIG_DEBUG_ATOMIC_SLEEP=y
-CONFIG_STACKTRACE=y
-CONFIG_DEBUG_LIST=y
-CONFIG_DEBUG_PLIST=y
-CONFIG_DEBUG_SG=y
-# CONFIG_RCU_TRACE is not set
-CONFIG_RCU_EQS_DEBUG=y
-# CONFIG_FTRACE is not set
-# CONFIG_RUNTIME_TESTING_MENU is not set
-CONFIG_MEMTEST=y
--
2.25.1

2022-03-23 15:04:22

by Guo Ren

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

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]>
Cc: Palmer Dabbelt <[email protected]>
---
arch/arm64/include/asm/compat.h | 71 ++------------------
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, 168 insertions(+), 284 deletions(-)

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index e0faec1984a1..46317319738a 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -8,6 +8,13 @@
#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;
+
#include <asm-generic/compat.h>

#ifdef CONFIG_COMPAT
@@ -19,21 +26,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 +88,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

2022-03-23 22:57:03

by Guo Ren

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

From: Guo Ren <[email protected]>

Detect hardware COMPAT (32bit U-mode) capability in rv64. If not
support COMPAT mode in hw, compat_elf_check_arch would return
false by compat_binfmt_elf.c

Add CLASS to enhance (compat_)elf_check_arch to distinguish
32BIT/64BIT elf.

Signed-off-by: Guo Ren <[email protected]>
Signed-off-by: Guo Ren <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Christoph Hellwig <[email protected]>
---
arch/riscv/include/asm/elf.h | 6 ++++--
arch/riscv/kernel/process.c | 28 ++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index a234656cfb5d..754fdb8cee96 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -33,9 +33,11 @@
/*
* This is used to ensure we don't load something for the wrong architecture.
*/
-#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+#define elf_check_arch(x) (((x)->e_machine == EM_RISCV) && \
+ ((x)->e_ident[EI_CLASS] == ELF_CLASS))

-#define compat_elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
+#define compat_elf_check_arch compat_elf_check_arch

#define CORE_DUMP_USE_REGSET
#define ELF_EXEC_PAGESIZE (PAGE_SIZE)
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 8c7665481a9f..203fdaa3f9e2 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -83,6 +83,34 @@ void show_regs(struct pt_regs *regs)
dump_backtrace(regs, NULL, KERN_DEFAULT);
}

+#ifdef CONFIG_COMPAT
+static bool compat_mode_supported __read_mostly;
+
+bool compat_elf_check_arch(Elf32_Ehdr *hdr)
+{
+ return compat_mode_supported &&
+ hdr->e_machine == EM_RISCV &&
+ hdr->e_ident[EI_CLASS] == ELFCLASS32;
+}
+
+static int __init compat_mode_detect(void)
+{
+ unsigned long tmp = csr_read(CSR_STATUS);
+
+ csr_write(CSR_STATUS, (tmp & ~SR_UXL) | SR_UXL_32);
+ compat_mode_supported =
+ (csr_read(CSR_STATUS) & SR_UXL) == SR_UXL_32;
+
+ csr_write(CSR_STATUS, tmp);
+
+ pr_info("riscv: ELF compat mode %s",
+ compat_mode_supported ? "supported" : "failed");
+
+ return 0;
+}
+early_initcall(compat_mode_detect);
+#endif
+
void start_thread(struct pt_regs *regs, unsigned long pc,
unsigned long sp)
{
--
2.25.1

2022-03-25 01:31:12

by Guo Ren

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

From: Guo Ren <[email protected]>

RISC-V doesn't neeed compat_stat, so using __ARCH_WANT_COMPAT_STAT
to exclude unnecessary SYSCALL functions.

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]>
Cc: Palmer Dabbelt <[email protected]>
---
arch/arm64/include/asm/unistd.h | 1 +
arch/mips/include/asm/unistd.h | 2 ++
arch/parisc/include/asm/unistd.h | 1 +
arch/powerpc/include/asm/unistd.h | 1 +
arch/s390/include/asm/unistd.h | 1 +
arch/sparc/include/asm/unistd.h | 1 +
arch/x86/include/asm/unistd.h | 1 +
fs/stat.c | 2 +-
8 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 4e65da3445c7..037feba03a51 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -3,6 +3,7 @@
* Copyright (C) 2012 ARM Ltd.
*/
#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT
#define __ARCH_WANT_COMPAT_STAT64
#define __ARCH_WANT_SYS_GETHOSTNAME
#define __ARCH_WANT_SYS_PAUSE
diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h
index c2196b1b6604..25a5253db7f4 100644
--- a/arch/mips/include/asm/unistd.h
+++ b/arch/mips/include/asm/unistd.h
@@ -50,6 +50,8 @@
# ifdef CONFIG_32BIT
# define __ARCH_WANT_STAT64
# define __ARCH_WANT_SYS_TIME32
+# else
+# define __ARCH_WANT_COMPAT_STAT
# endif
# ifdef CONFIG_MIPS32_O32
# define __ARCH_WANT_SYS_TIME32
diff --git a/arch/parisc/include/asm/unistd.h b/arch/parisc/include/asm/unistd.h
index cd438e4150f6..14e0668184cb 100644
--- a/arch/parisc/include/asm/unistd.h
+++ b/arch/parisc/include/asm/unistd.h
@@ -168,6 +168,7 @@ type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
#define __ARCH_WANT_SYS_CLONE
#define __ARCH_WANT_SYS_CLONE3
#define __ARCH_WANT_COMPAT_SYS_SENDFILE
+#define __ARCH_WANT_COMPAT_STAT

#ifdef CONFIG_64BIT
#define __ARCH_WANT_SYS_TIME
diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h
index 5eb462af6766..b1129b4ef57d 100644
--- a/arch/powerpc/include/asm/unistd.h
+++ b/arch/powerpc/include/asm/unistd.h
@@ -44,6 +44,7 @@
#define __ARCH_WANT_SYS_TIME
#define __ARCH_WANT_SYS_UTIME
#define __ARCH_WANT_SYS_NEWFSTATAT
+#define __ARCH_WANT_COMPAT_STAT
#define __ARCH_WANT_COMPAT_SYS_SENDFILE
#endif
#define __ARCH_WANT_SYS_FORK
diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h
index 9e9f75ef046a..4260bc5ce7f8 100644
--- a/arch/s390/include/asm/unistd.h
+++ b/arch/s390/include/asm/unistd.h
@@ -28,6 +28,7 @@
#define __ARCH_WANT_SYS_SIGPENDING
#define __ARCH_WANT_SYS_SIGPROCMASK
# ifdef CONFIG_COMPAT
+# define __ARCH_WANT_COMPAT_STAT
# define __ARCH_WANT_SYS_TIME32
# define __ARCH_WANT_SYS_UTIME32
# endif
diff --git a/arch/sparc/include/asm/unistd.h b/arch/sparc/include/asm/unistd.h
index 1e66278ba4a5..d6bc76706a7a 100644
--- a/arch/sparc/include/asm/unistd.h
+++ b/arch/sparc/include/asm/unistd.h
@@ -46,6 +46,7 @@
#define __ARCH_WANT_SYS_TIME
#define __ARCH_WANT_SYS_UTIME
#define __ARCH_WANT_COMPAT_SYS_SENDFILE
+#define __ARCH_WANT_COMPAT_STAT
#endif

#ifdef __32bit_syscall_numbers__
diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h
index 80e9d5206a71..761173ccc33c 100644
--- a/arch/x86/include/asm/unistd.h
+++ b/arch/x86/include/asm/unistd.h
@@ -22,6 +22,7 @@
# include <asm/unistd_32_ia32.h>
# define __ARCH_WANT_SYS_TIME
# define __ARCH_WANT_SYS_UTIME
+# define __ARCH_WANT_COMPAT_STAT
# define __ARCH_WANT_COMPAT_SYS_PREADV64
# define __ARCH_WANT_COMPAT_SYS_PWRITEV64
# define __ARCH_WANT_COMPAT_SYS_PREADV64V2
diff --git a/fs/stat.c b/fs/stat.c
index 28d2020ba1f4..ffdeb9065d53 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -639,7 +639,7 @@ SYSCALL_DEFINE5(statx,
return do_statx(dfd, filename, flags, mask, buffer);
}

-#ifdef CONFIG_COMPAT
+#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_STAT)
static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
{
struct compat_stat tmp;
--
2.25.1

2022-03-25 02:54:50

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH V9 11/20] riscv: compat: syscall: Add compat_sys_call_table implementation

Hi Palmer & Arnd,

Fixup fadvise64_64 arguments problem.

On Tue, Mar 22, 2022 at 10:41 PM <[email protected]> wrote:
>
> From: Guo Ren <[email protected]>
>
> Implement compat sys_call_table and some system call functions:
> truncate64, ftruncate64, fallocate, pread64, pwrite64,
> sync_file_range, readahead, fadvise64_64 which need argument
> translation.
>
> Signed-off-by: Guo Ren <[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/include/asm/syscall.h | 1 +
> arch/riscv/include/asm/unistd.h | 11 +++++++
> arch/riscv/include/uapi/asm/unistd.h | 2 +-
> arch/riscv/kernel/Makefile | 1 +
> arch/riscv/kernel/compat_syscall_table.c | 19 ++++++++++++
> arch/riscv/kernel/sys_riscv.c | 6 ++--
> fs/open.c | 24 +++++++++++++++
> fs/read_write.c | 16 ++++++++++
> fs/sync.c | 9 ++++++
> include/asm-generic/compat.h | 7 +++++
> include/linux/compat.h | 37 ++++++++++++++++++++++++
> mm/fadvise.c | 11 +++++++
> mm/readahead.c | 7 +++++
> 13 files changed, 148 insertions(+), 3 deletions(-)
> create mode 100644 arch/riscv/kernel/compat_syscall_table.c
>
> diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h
> index 7ac6a0e275f2..384a63b86420 100644
> --- a/arch/riscv/include/asm/syscall.h
> +++ b/arch/riscv/include/asm/syscall.h
> @@ -16,6 +16,7 @@
>
> /* The array of function pointers for syscalls. */
> extern void * const sys_call_table[];
> +extern void * const compat_sys_call_table[];
>
> /*
> * Only the low 32 bits of orig_r0 are meaningful, so we return int.
> diff --git a/arch/riscv/include/asm/unistd.h b/arch/riscv/include/asm/unistd.h
> index 6c316093a1e5..5ddac412b578 100644
> --- a/arch/riscv/include/asm/unistd.h
> +++ b/arch/riscv/include/asm/unistd.h
> @@ -11,6 +11,17 @@
> #define __ARCH_WANT_SYS_CLONE
> #define __ARCH_WANT_MEMFD_SECRET
>
> +#ifdef CONFIG_COMPAT
> +#define __ARCH_WANT_COMPAT_TRUNCATE64
> +#define __ARCH_WANT_COMPAT_FTRUNCATE64
> +#define __ARCH_WANT_COMPAT_FALLOCATE
> +#define __ARCH_WANT_COMPAT_PREAD64
> +#define __ARCH_WANT_COMPAT_PWRITE64
> +#define __ARCH_WANT_COMPAT_SYNC_FILE_RANGE
> +#define __ARCH_WANT_COMPAT_READAHEAD
> +#define __ARCH_WANT_COMPAT_FADVISE64_64
> +#endif
> +
> #include <uapi/asm/unistd.h>
>
> #define NR_syscalls (__NR_syscalls)
> diff --git a/arch/riscv/include/uapi/asm/unistd.h b/arch/riscv/include/uapi/asm/unistd.h
> index 8062996c2dfd..c9e50eed14aa 100644
> --- a/arch/riscv/include/uapi/asm/unistd.h
> +++ b/arch/riscv/include/uapi/asm/unistd.h
> @@ -15,7 +15,7 @@
> * along with this program. If not, see <https://www.gnu.org/licenses/>.
> */
>
> -#ifdef __LP64__
> +#if defined(__LP64__) && !defined(__SYSCALL_COMPAT)
> #define __ARCH_WANT_NEW_STAT
> #define __ARCH_WANT_SET_GET_RLIMIT
> #endif /* __LP64__ */
> diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
> index ffc87e76b1dd..3b3e425aadd2 100644
> --- a/arch/riscv/kernel/Makefile
> +++ b/arch/riscv/kernel/Makefile
> @@ -68,3 +68,4 @@ obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
> obj-$(CONFIG_JUMP_LABEL) += jump_label.o
>
> obj-$(CONFIG_EFI) += efi.o
> +obj-$(CONFIG_COMPAT) += compat_syscall_table.o
> diff --git a/arch/riscv/kernel/compat_syscall_table.c b/arch/riscv/kernel/compat_syscall_table.c
> new file mode 100644
> index 000000000000..651f2b009c28
> --- /dev/null
> +++ b/arch/riscv/kernel/compat_syscall_table.c
> @@ -0,0 +1,19 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#define __SYSCALL_COMPAT
> +
> +#include <linux/compat.h>
> +#include <linux/syscalls.h>
> +#include <asm-generic/mman-common.h>
> +#include <asm-generic/syscalls.h>
> +#include <asm/syscall.h>
> +
> +#undef __SYSCALL
> +#define __SYSCALL(nr, call) [nr] = (call),
> +
> +asmlinkage long compat_sys_rt_sigreturn(void);
> +
> +void * const compat_sys_call_table[__NR_syscalls] = {
> + [0 ... __NR_syscalls - 1] = sys_ni_syscall,
> +#include <asm/unistd.h>
> +};
> diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c
> index 12f8a7fce78b..9c0194f176fc 100644
> --- a/arch/riscv/kernel/sys_riscv.c
> +++ b/arch/riscv/kernel/sys_riscv.c
> @@ -33,7 +33,9 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
> {
> return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 0);
> }
> -#else
> +#endif
> +
> +#if defined(CONFIG_32BIT) || defined(CONFIG_COMPAT)
> SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
> unsigned long, prot, unsigned long, flags,
> unsigned long, fd, off_t, offset)
> @@ -44,7 +46,7 @@ SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
> */
> return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 12);
> }
> -#endif /* !CONFIG_64BIT */
> +#endif
>
> /*
> * Allows the instruction cache to be flushed from userspace. Despite RISC-V
> diff --git a/fs/open.c b/fs/open.c
> index 9ff2f621b760..b25613f7c0a7 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -224,6 +224,21 @@ SYSCALL_DEFINE2(ftruncate64, unsigned int, fd, loff_t, length)
> }
> #endif /* BITS_PER_LONG == 32 */
>
> +#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_TRUNCATE64)
> +COMPAT_SYSCALL_DEFINE3(truncate64, const char __user *, pathname,
> + compat_arg_u64_dual(length))
> +{
> + return ksys_truncate(pathname, compat_arg_u64_glue(length));
> +}
> +#endif
> +
> +#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_FTRUNCATE64)
> +COMPAT_SYSCALL_DEFINE3(ftruncate64, unsigned int, fd,
> + compat_arg_u64_dual(length))
> +{
> + return ksys_ftruncate(fd, compat_arg_u64_glue(length));
> +}
> +#endif
>
> int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
> {
> @@ -339,6 +354,15 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
> return ksys_fallocate(fd, mode, offset, len);
> }
>
> +#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_FALLOCATE)
> +COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode, compat_arg_u64_dual(offset),
> + compat_arg_u64_dual(len))
> +{
> + return ksys_fallocate(fd, mode, compat_arg_u64_glue(offset),
> + compat_arg_u64_glue(len));
> +}
> +#endif
> +
> /*
> * access() needs to use the real uid/gid, not the effective uid/gid.
> * We do this by temporarily clearing all FS-related capabilities and
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 0074afa7ecb3..548657c462e8 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -681,6 +681,14 @@ SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
> return ksys_pread64(fd, buf, count, pos);
> }
>
> +#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_PREAD64)
> +COMPAT_SYSCALL_DEFINE5(pread64, unsigned int, fd, char __user *, buf,
> + size_t, count, compat_arg_u64_dual(pos))
> +{
> + return ksys_pread64(fd, buf, count, compat_arg_u64_glue(pos));
> +}
> +#endif
> +
> ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf,
> size_t count, loff_t pos)
> {
> @@ -707,6 +715,14 @@ SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
> return ksys_pwrite64(fd, buf, count, pos);
> }
>
> +#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_PWRITE64)
> +COMPAT_SYSCALL_DEFINE5(pwrite64, unsigned int, fd, const char __user *, buf,
> + size_t, count, compat_arg_u64_dual(pos))
> +{
> + return ksys_pwrite64(fd, buf, count, compat_arg_u64_glue(pos));
> +}
> +#endif
> +
> static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter,
> loff_t *ppos, int type, rwf_t flags)
> {
> diff --git a/fs/sync.c b/fs/sync.c
> index c7690016453e..dc725914e1ed 100644
> --- a/fs/sync.c
> +++ b/fs/sync.c
> @@ -373,6 +373,15 @@ SYSCALL_DEFINE4(sync_file_range, int, fd, loff_t, offset, loff_t, nbytes,
> return ksys_sync_file_range(fd, offset, nbytes, flags);
> }
>
> +#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_SYNC_FILE_RANGE)
> +COMPAT_SYSCALL_DEFINE6(sync_file_range, int, fd, compat_arg_u64_dual(offset),
> + compat_arg_u64_dual(nbytes), unsigned int, flags)
> +{
> + return ksys_sync_file_range(fd, compat_arg_u64_glue(offset),
> + compat_arg_u64_glue(nbytes), flags);
> +}
> +#endif
> +
> /* It would be nice if people remember that not all the world's an i386
> when they introduce new system calls */
> SYSCALL_DEFINE4(sync_file_range2, int, fd, unsigned int, flags,
> diff --git a/include/asm-generic/compat.h b/include/asm-generic/compat.h
> index 11653d6846cc..d06308a2a7a8 100644
> --- a/include/asm-generic/compat.h
> +++ b/include/asm-generic/compat.h
> @@ -14,6 +14,13 @@
> #define COMPAT_OFF_T_MAX 0x7fffffff
> #endif
>
> +#if !defined(compat_arg_u64) && !defined(CONFIG_CPU_BIG_ENDIAN)
> +#define compat_arg_u64(name) u32 name##_lo, u32 name##_hi
> +#define compat_arg_u64_dual(name) u32, name##_lo, u32, name##_hi
> +#define compat_arg_u64_glue(name) (((u64)name##_lo & 0xffffffffUL) | \
> + ((u64)name##_hi << 32))
> +#endif
> +
> /* These types are common across all compat ABIs */
> typedef u32 compat_size_t;
> typedef s32 compat_ssize_t;
> diff --git a/include/linux/compat.h b/include/linux/compat.h
> index a0481fe6c5d5..8779e283a1e9 100644
> --- a/include/linux/compat.h
> +++ b/include/linux/compat.h
> @@ -926,6 +926,43 @@ asmlinkage long compat_sys_sigaction(int sig,
> /* obsolete: net/socket.c */
> asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
>
> +#ifdef __ARCH_WANT_COMPAT_TRUNCATE64
> +asmlinkage long compat_sys_truncate64(const char __user *pathname, compat_arg_u64(len));
> +#endif
> +
> +#ifdef __ARCH_WANT_COMPAT_FTRUNCATE64
> +asmlinkage long compat_sys_ftruncate64(unsigned int fd, compat_arg_u64(len));
> +#endif
> +
> +#ifdef __ARCH_WANT_COMPAT_FALLOCATE
> +asmlinkage long compat_sys_fallocate(int fd, int mode, compat_arg_u64(offset),
> + compat_arg_u64(len));
> +#endif
> +
> +#ifdef __ARCH_WANT_COMPAT_PREAD64
> +asmlinkage long compat_sys_pread64(unsigned int fd, char __user *buf, size_t count,
> + compat_arg_u64(pos));
> +#endif
> +
> +#ifdef __ARCH_WANT_COMPAT_PWRITE64
> +asmlinkage long compat_sys_pwrite64(unsigned int fd, const char __user *buf, size_t count,
> + compat_arg_u64(pos));
> +#endif
> +
> +#ifdef __ARCH_WANT_COMPAT_SYNC_FILE_RANGE
> +asmlinkage long compat_sys_sync_file_range(int fd, compat_arg_u64(pos),
> + compat_arg_u64(nbytes), unsigned int flags);
> +#endif
> +
> +#ifdef __ARCH_WANT_COMPAT_FADVISE64_64
> +asmlinkage long compat_sys_fadvise64_64(int fd, int advice, compat_arg_u64(pos),
> + compat_arg_u64(len));
This should be:
+asmlinkage long compat_sys_fadvise64_64(int fd, compat_arg_u64(pos),
+ compat_arg_u64(len), int advice);

> +#endif
> +
> +#ifdef __ARCH_WANT_COMPAT_READAHEAD
> +asmlinkage long compat_sys_readahead(int fd, compat_arg_u64(offset), size_t count);
> +#endif
> +
> #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
>
> /**
> diff --git a/mm/fadvise.c b/mm/fadvise.c
> index d6baa4f451c5..8950f7c05d20 100644
> --- a/mm/fadvise.c
> +++ b/mm/fadvise.c
> @@ -215,5 +215,16 @@ SYSCALL_DEFINE4(fadvise64, int, fd, loff_t, offset, size_t, len, int, advice)
> return ksys_fadvise64_64(fd, offset, len, advice);
> }
>
> +#endif
> +
> +#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_FADVISE64_64)
> +
> +COMPAT_SYSCALL_DEFINE6(fadvise64_64, int, fd, int, advice, compat_arg_u64_dual(offset),
> + compat_arg_u64_dual(len))
Ditto, this should be.

+COMPAT_SYSCALL_DEFINE6(fadvise64_64, int, fd, compat_arg_u64_dual(offset),
+ compat_arg_u64_dual(len), int, advice)

> +{
> + return ksys_fadvise64_64(fd, compat_arg_u64_glue(offset),
> + compat_arg_u64_glue(len), advice);
> +}
> +
> #endif
> #endif
> diff --git a/mm/readahead.c b/mm/readahead.c
> index cf0dcf89eb69..9adf57044299 100644
> --- a/mm/readahead.c
> +++ b/mm/readahead.c
> @@ -640,6 +640,13 @@ SYSCALL_DEFINE3(readahead, int, fd, loff_t, offset, size_t, count)
> return ksys_readahead(fd, offset, count);
> }
>
> +#if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_READAHEAD)
> +COMPAT_SYSCALL_DEFINE4(readahead, int, fd, compat_arg_u64_dual(offset), size_t, count)
> +{
> + return ksys_readahead(fd, compat_arg_u64_glue(offset), count);
> +}
> +#endif
> +
> /**
> * readahead_expand - Expand a readahead request
> * @ractl: The request to be expanded
> --
> 2.25.1
>


--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

2022-04-04 21:18:12

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH V9 00/20] riscv: compat: Add COMPAT Kbuild skeletal support

I got that. I fixed up it in v10.

CC arch/arm64/kernel/asm-offsets.s
In file included from
/home/guoren/source/kernel/riscv-linux/arch/arm64/include/asm/stat.h:13,
from
/home/guoren/source/kernel/riscv-linux/include/linux/stat.h:6,
from
/home/guoren/source/kernel/riscv-linux/include/linux/sysfs.h:22,
from
/home/guoren/source/kernel/riscv-linux/include/linux/kobject.h:20,
from
/home/guoren/source/kernel/riscv-linux/include/linux/of.h:17,
from
/home/guoren/source/kernel/riscv-linux/include/linux/irqdomain.h:35,
from
/home/guoren/source/kernel/riscv-linux/include/linux/acpi.h:13,
from
/home/guoren/source/kernel/riscv-linux/include/acpi/apei.h:9,
from
/home/guoren/source/kernel/riscv-linux/include/acpi/ghes.h:5,
from
/home/guoren/source/kernel/riscv-linux/include/linux/arm_sdei.h:8,
from
/home/guoren/source/kernel/riscv-linux/arch/arm64/kernel/asm-offsets.c:10:
/home/guoren/source/kernel/riscv-linux/arch/arm64/include/asm/compat.h:69:8:
error: redefinition of ‘struct compat_statfs’
69 | struct compat_statfs {
| ^~~~~~~~~~~~~
In file included from
/home/guoren/source/kernel/riscv-linux/arch/arm64/include/asm/compat.h:18,
from
/home/guoren/source/kernel/riscv-linux/arch/arm64/include/asm/stat.h:13,
from
/home/guoren/source/kernel/riscv-linux/include/linux/stat.h:6,
from
/home/guoren/source/kernel/riscv-linux/include/linux/sysfs.h:22,
from
/home/guoren/source/kernel/riscv-linux/include/linux/kobject.h:20,
from
/home/guoren/source/kernel/riscv-linux/include/linux/of.h:17,
from
/home/guoren/source/kernel/riscv-linux/include/linux/irqdomain.h:35,
from
/home/guoren/source/kernel/riscv-linux/include/linux/acpi.h:13,
from
/home/guoren/source/kernel/riscv-linux/include/acpi/apei.h:9,
from
/home/guoren/source/kernel/riscv-linux/include/acpi/ghes.h:5,
from
/home/guoren/source/kernel/riscv-linux/include/linux/arm_sdei.h:8,
from
/home/guoren/source/kernel/riscv-linux/arch/arm64/kernel/asm-offsets.c:10:
/home/guoren/source/kernel/riscv-linux/include/asm-generic/compat.h:87:8:
note: originally defined here
87 | struct compat_statfs {
| ^~~~~~~~~~~~~
make[2]: *** [/home/guoren/source/kernel/riscv-linux/scripts/Makefile.build:121:
arch/arm64/kernel/asm-offsets.s] Error 1
make[1]: *** [/home/guoren/source/kernel/riscv-linux/Makefile:1191:
prepare0] Error 2
make[1]: Leaving directory '/home/guoren/source/kernel/build-arm64'

On Sat, Apr 2, 2022 at 8:53 PM Guo Ren <[email protected]> wrote:
>
> On Wed, Mar 23, 2022 at 5:00 AM Palmer Dabbelt <[email protected]> wrote:
> >
> > On Tue, 22 Mar 2022 07:39:43 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.17-rc8, 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_v8 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 v9:
> > > - Fixup rv32 call rv64 segment fault
> > > - Ready for 5.18
> >
> > Thanks. I'd also seen some arm64 autobuilder failures, not sure if
> > those got fixed as I don't see anything specificlly listed in here
> > (sorry if I just missed it).
> >
> > I've gone ahead and put this on palmer/riscv-compat, I'm going to let it
> > sit at least overnight before putting it on for-next proper. It's a
> > big one and the autobuilders seem to find stuff over there, I don't want
> > to break any of the other ports. IIRC you were getting CC'd on the
> > build failures I was seeing.
> I couldn't find that, could you give me a link, thank you.
>
> >
> > If it's clean I'll merge it into for-next propely. It's passing my
> > staging merge tests, but I don't yet have anything specifically for
> > compat -- at least it's not causing any regressions, though.
> >
> > >
> > > 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):
> > > kconfig: 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: Re-implement TASK_SIZE for COMPAT_32BIT
> > > 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 | 91 +------
> > > 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/configs/rv32_defconfig | 135 ----------
> > > 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 | 243 ++++++++++++++++++
> > > 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 +-
> > > 68 files changed, 1205 insertions(+), 698 deletions(-)
> > > delete mode 100644 arch/riscv/configs/rv32_defconfig
> > > 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
>
>
>
> --
> Best Regards
> Guo Ren
>
> ML: https://lore.kernel.org/linux-csky/



--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

2022-04-04 21:37:58

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH V9 00/20] riscv: compat: Add COMPAT Kbuild skeletal support

On Wed, Mar 23, 2022 at 5:00 AM Palmer Dabbelt <[email protected]> wrote:
>
> On Tue, 22 Mar 2022 07:39:43 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.17-rc8, 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_v8 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 v9:
> > - Fixup rv32 call rv64 segment fault
> > - Ready for 5.18
>
> Thanks. I'd also seen some arm64 autobuilder failures, not sure if
> those got fixed as I don't see anything specificlly listed in here
> (sorry if I just missed it).
>
> I've gone ahead and put this on palmer/riscv-compat, I'm going to let it
> sit at least overnight before putting it on for-next proper. It's a
> big one and the autobuilders seem to find stuff over there, I don't want
> to break any of the other ports. IIRC you were getting CC'd on the
> build failures I was seeing.
I couldn't find that, could you give me a link, thank you.

>
> If it's clean I'll merge it into for-next propely. It's passing my
> staging merge tests, but I don't yet have anything specifically for
> compat -- at least it's not causing any regressions, though.
>
> >
> > 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):
> > kconfig: 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: Re-implement TASK_SIZE for COMPAT_32BIT
> > 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 | 91 +------
> > 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/configs/rv32_defconfig | 135 ----------
> > 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 | 243 ++++++++++++++++++
> > 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 +-
> > 68 files changed, 1205 insertions(+), 698 deletions(-)
> > delete mode 100644 arch/riscv/configs/rv32_defconfig
> > 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



--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

2022-05-23 08:06:02

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

On Tue, Mar 22, 2022 at 10:40:03PM +0800, [email protected] wrote:
> 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]>

With this patch in linux-next, all my riscv64 emulations crash.

[ 11.600082] Run /sbin/init as init process
[ 11.628561] init[1]: unhandled signal 11 code 0x1 at 0x0000000000000000 in libc.so[ffffff8ad39000+a4000]
[ 11.629398] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
[ 11.629462] Hardware name: riscv-virtio,qemu (DT)
[ 11.629546] epc : 00ffffff8ada1100 ra : 00ffffff8ada13c8 sp : 00ffffffc58199f0
[ 11.629586] gp : 00ffffff8ad39000 tp : 00ffffff8ade0998 t0 : ffffffffffffffff
[ 11.629598] t1 : 00ffffffc5819fd0 t2 : 0000000000000000 s0 : 00ffffff8ade0cc0
[ 11.629610] s1 : 00ffffff8ade0cc0 a0 : 0000000000000000 a1 : 00ffffffc5819a00
[ 11.629622] a2 : 0000000000000001 a3 : 000000000000001e a4 : 00ffffffc5819b00
[ 11.629634] a5 : 00ffffffc5819b00 a6 : 0000000000000000 a7 : 0000000000000000
[ 11.629645] s2 : 00ffffff8ade0ac8 s3 : 00ffffff8ade0ec8 s4 : 00ffffff8ade0728
[ 11.629656] s5 : 00ffffff8ade0a90 s6 : 0000000000000000 s7 : 00ffffffc5819e40
[ 11.629667] s8 : 00ffffff8ade0ca0 s9 : 00ffffff8addba50 s10: 0000000000000000
[ 11.629678] s11: 0000000000000000 t3 : 0000000000000002 t4 : 0000000000000001
[ 11.629688] t5 : 0000000000020000 t6 : ffffffffffffffff
[ 11.629699] status: 0000000000004020 badaddr: 0000000000000000 cause: 000000000000000d
[ 11.633421] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 11.633664] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
[ 11.633784] Hardware name: riscv-virtio,qemu (DT)
[ 11.633881] Call Trace:
[ 11.633960] [<ffffffff80005e72>] dump_backtrace+0x1c/0x24
[ 11.634162] [<ffffffff809aa9ec>] show_stack+0x2c/0x38
[ 11.634274] [<ffffffff809b8482>] dump_stack_lvl+0x60/0x8e
[ 11.634386] [<ffffffff809b84c4>] dump_stack+0x14/0x1c
[ 11.634491] [<ffffffff809aaca0>] panic+0x116/0x2e2
[ 11.634596] [<ffffffff80015540>] do_exit+0x7ce/0x7d4
[ 11.634707] [<ffffffff80015666>] do_group_exit+0x24/0x7c
[ 11.634817] [<ffffffff80022294>] get_signal+0x7ee/0x830
[ 11.634924] [<ffffffff800051c0>] do_notify_resume+0x6c/0x41c
[ 11.635037] [<ffffffff80003ad4>] ret_from_exception+0x0/0x10

Guenter

---
# bad: [18ecd30af1a8402c162cca1bd58771c0e5be7815] Add linux-next specific files for 20220520
# good: [42226c989789d8da4af1de0c31070c96726d990c] Linux 5.18-rc7
git bisect start 'HEAD' 'v5.18-rc7'
# bad: [f9b63740b666dd9887eb0282d21b5f65bb0cadd0] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
git bisect bad f9b63740b666dd9887eb0282d21b5f65bb0cadd0
# bad: [7db97132097c5973ff77466d0ee681650af653de] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
git bisect bad 7db97132097c5973ff77466d0ee681650af653de
# good: [2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb] soc: document merges
git bisect good 2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb
# good: [69c9668f853fdd409bb8abbb37d615785510b29a] Merge branch 'clk-next' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git
git bisect good 69c9668f853fdd409bb8abbb37d615785510b29a
# bad: [1577f290aa0d4c5b29c03c46ef52e4952a21bfbb] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git
git bisect bad 1577f290aa0d4c5b29c03c46ef52e4952a21bfbb
# good: [34f0971f8ca73d7e5502b4cf299788a9402120f7] powerpc/powernv/flash: Check OPAL flash calls exist before using
git bisect good 34f0971f8ca73d7e5502b4cf299788a9402120f7
# good: [0349d7dfc70a26b3facd8ca97de34980d4b60954] Merge branch 'mips-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux.git
git bisect good 0349d7dfc70a26b3facd8ca97de34980d4b60954
# bad: [20bfb54d3b121699674c17a854c5ebc7a8f97d81] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git
git bisect bad 20bfb54d3b121699674c17a854c5ebc7a8f97d81
# bad: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
git bisect bad 9be8459298eadb39b9fe9974b890239e9c123107
# good: [01abdfeac81b5f56062d0a78f2cdc805db937a75] riscv: compat: Support TASK_SIZE for compat mode
git bisect good 01abdfeac81b5f56062d0a78f2cdc805db937a75
# good: [f4b395e6f1a588ed6c9a30474e58cf6b27b65783] riscv: compat: Add hw capability check for elf
git bisect good f4b395e6f1a588ed6c9a30474e58cf6b27b65783
# good: [3092eb45637573c5e435fbf5eaf9516316e5f9c6] riscv: compat: vdso: Add setup additional pages implementation
git bisect good 3092eb45637573c5e435fbf5eaf9516316e5f9c6
# good: [4608c159594fb40a5101357d4f614fdde9ce1fdb] riscv: compat: ptrace: Add compat_arch_ptrace implement
git bisect good 4608c159594fb40a5101357d4f614fdde9ce1fdb
# first bad commit: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support

2022-05-23 15:19:24

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

I tested Palmer's branch, it's okay:
8810d7feee5a (HEAD -> for-next, palmer/for-next) riscv: Don't output a
bogus mmu-type on a no MMU kernel

I also tested linux-next, it's okay:

rv64_rootfs:
# uname -a
Linux buildroot 5.18.0-next-20220523 #7 SMP Mon May 23 11:15:17 EDT
2022 riscv64 GNU/Linux
#
#
#
# ls /lib
ld-uClibc-1.0.39.so libatomic.so.1 libgcc_s.so
ld-uClibc.so.0 libatomic.so.1.2.0 libgcc_s.so.1
ld-uClibc.so.1 libc.so.0 libuClibc-1.0.39.so
libatomic.so libc.so.1 modules

rv32_rootfs:
buildroot login: root
# uname -a
Linux buildroot 5.18.0-next-20220523 #7 SMP Mon May 23 11:15:17 EDT
2022 riscv64 GNU/Linux
# ls /lib
ld-linux-riscv32-ilp32d.so.1 libm.so.6
libanl.so.1 libnss_dns.so.2
libatomic.so libnss_files.so.2
libatomic.so.1 libpthread.so.0
libatomic.so.1.2.0 libresolv.so.2
libc.so.6 librt.so.1
libcrypt.so.1 libthread_db.so.1
libdl.so.2 libutil.so.1
libgcc_s.so modules
libgcc_s.so.1

Here is my qemu version:
commit 19f13a92cef8405052e0f73d5289f9e15474dad3 (HEAD ->
riscv-to-apply.next, alistair/riscv-to-apply.next)
Author: Tsukasa OI <[email protected]>
Date: Sun May 15 11:56:11 2022 +0900

target/riscv: Move/refactor ISA extension checks

We should separate "check" and "configure" steps as possible.
This commit separates both steps except vector/Zfinx-related checks.

Signed-off-by: Tsukasa OI <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Message-Id:
<c3145fa37a529484cf3047c8cb9841e9effad4b0.1652583332.git.research_trasio@irq.a4lg.com>
Signed-off-by: Alistair Francis <[email protected]>

On Mon, May 23, 2022 at 1:45 PM Guenter Roeck <[email protected]> wrote:
>
> On Tue, Mar 22, 2022 at 10:40:03PM +0800, [email protected] wrote:
> > 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]>
>
> With this patch in linux-next, all my riscv64 emulations crash.
>
> [ 11.600082] Run /sbin/init as init process
> [ 11.628561] init[1]: unhandled signal 11 code 0x1 at 0x0000000000000000 in libc.so[ffffff8ad39000+a4000]
> [ 11.629398] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
> [ 11.629462] Hardware name: riscv-virtio,qemu (DT)
> [ 11.629546] epc : 00ffffff8ada1100 ra : 00ffffff8ada13c8 sp : 00ffffffc58199f0
> [ 11.629586] gp : 00ffffff8ad39000 tp : 00ffffff8ade0998 t0 : ffffffffffffffff
> [ 11.629598] t1 : 00ffffffc5819fd0 t2 : 0000000000000000 s0 : 00ffffff8ade0cc0
> [ 11.629610] s1 : 00ffffff8ade0cc0 a0 : 0000000000000000 a1 : 00ffffffc5819a00
> [ 11.629622] a2 : 0000000000000001 a3 : 000000000000001e a4 : 00ffffffc5819b00
> [ 11.629634] a5 : 00ffffffc5819b00 a6 : 0000000000000000 a7 : 0000000000000000
> [ 11.629645] s2 : 00ffffff8ade0ac8 s3 : 00ffffff8ade0ec8 s4 : 00ffffff8ade0728
> [ 11.629656] s5 : 00ffffff8ade0a90 s6 : 0000000000000000 s7 : 00ffffffc5819e40
> [ 11.629667] s8 : 00ffffff8ade0ca0 s9 : 00ffffff8addba50 s10: 0000000000000000
> [ 11.629678] s11: 0000000000000000 t3 : 0000000000000002 t4 : 0000000000000001
> [ 11.629688] t5 : 0000000000020000 t6 : ffffffffffffffff
> [ 11.629699] status: 0000000000004020 badaddr: 0000000000000000 cause: 000000000000000d
> [ 11.633421] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> [ 11.633664] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
> [ 11.633784] Hardware name: riscv-virtio,qemu (DT)
> [ 11.633881] Call Trace:
> [ 11.633960] [<ffffffff80005e72>] dump_backtrace+0x1c/0x24
> [ 11.634162] [<ffffffff809aa9ec>] show_stack+0x2c/0x38
> [ 11.634274] [<ffffffff809b8482>] dump_stack_lvl+0x60/0x8e
> [ 11.634386] [<ffffffff809b84c4>] dump_stack+0x14/0x1c
> [ 11.634491] [<ffffffff809aaca0>] panic+0x116/0x2e2
> [ 11.634596] [<ffffffff80015540>] do_exit+0x7ce/0x7d4
> [ 11.634707] [<ffffffff80015666>] do_group_exit+0x24/0x7c
> [ 11.634817] [<ffffffff80022294>] get_signal+0x7ee/0x830
> [ 11.634924] [<ffffffff800051c0>] do_notify_resume+0x6c/0x41c
> [ 11.635037] [<ffffffff80003ad4>] ret_from_exception+0x0/0x10
>
> Guenter
>
> ---
> # bad: [18ecd30af1a8402c162cca1bd58771c0e5be7815] Add linux-next specific files for 20220520
> # good: [42226c989789d8da4af1de0c31070c96726d990c] Linux 5.18-rc7
> git bisect start 'HEAD' 'v5.18-rc7'
> # bad: [f9b63740b666dd9887eb0282d21b5f65bb0cadd0] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
> git bisect bad f9b63740b666dd9887eb0282d21b5f65bb0cadd0
> # bad: [7db97132097c5973ff77466d0ee681650af653de] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
> git bisect bad 7db97132097c5973ff77466d0ee681650af653de
> # good: [2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb] soc: document merges
> git bisect good 2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb
> # good: [69c9668f853fdd409bb8abbb37d615785510b29a] Merge branch 'clk-next' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git
> git bisect good 69c9668f853fdd409bb8abbb37d615785510b29a
> # bad: [1577f290aa0d4c5b29c03c46ef52e4952a21bfbb] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git
> git bisect bad 1577f290aa0d4c5b29c03c46ef52e4952a21bfbb
> # good: [34f0971f8ca73d7e5502b4cf299788a9402120f7] powerpc/powernv/flash: Check OPAL flash calls exist before using
> git bisect good 34f0971f8ca73d7e5502b4cf299788a9402120f7
> # good: [0349d7dfc70a26b3facd8ca97de34980d4b60954] Merge branch 'mips-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux.git
> git bisect good 0349d7dfc70a26b3facd8ca97de34980d4b60954
> # bad: [20bfb54d3b121699674c17a854c5ebc7a8f97d81] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git
> git bisect bad 20bfb54d3b121699674c17a854c5ebc7a8f97d81
> # bad: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
> git bisect bad 9be8459298eadb39b9fe9974b890239e9c123107
> # good: [01abdfeac81b5f56062d0a78f2cdc805db937a75] riscv: compat: Support TASK_SIZE for compat mode
> git bisect good 01abdfeac81b5f56062d0a78f2cdc805db937a75
> # good: [f4b395e6f1a588ed6c9a30474e58cf6b27b65783] riscv: compat: Add hw capability check for elf
> git bisect good f4b395e6f1a588ed6c9a30474e58cf6b27b65783
> # good: [3092eb45637573c5e435fbf5eaf9516316e5f9c6] riscv: compat: vdso: Add setup additional pages implementation
> git bisect good 3092eb45637573c5e435fbf5eaf9516316e5f9c6
> # good: [4608c159594fb40a5101357d4f614fdde9ce1fdb] riscv: compat: ptrace: Add compat_arch_ptrace implement
> git bisect good 4608c159594fb40a5101357d4f614fdde9ce1fdb
> # first bad commit: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support



--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

2022-05-23 16:19:37

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

On 5/23/22 08:18, Guo Ren wrote:
> I tested Palmer's branch, it's okay:
> 8810d7feee5a (HEAD -> for-next, palmer/for-next) riscv: Don't output a
> bogus mmu-type on a no MMU kernel
>
> I also tested linux-next, it's okay:
>
> rv64_rootfs:
> # uname -a
> Linux buildroot 5.18.0-next-20220523 #7 SMP Mon May 23 11:15:17 EDT
> 2022 riscv64 GNU/Linux
> #

That is is ok with one setup doesn't mean it is ok with
all setups. It is not ok with my root file system (from
https://github.com/groeck/linux-build-test/tree/master/rootfs/riscv64),
with qemu v6.2.

> #
> #
> # ls /lib
> ld-uClibc-1.0.39.so libatomic.so.1 libgcc_s.so
> ld-uClibc.so.0 libatomic.so.1.2.0 libgcc_s.so.1
> ld-uClibc.so.1 libc.so.0 libuClibc-1.0.39.so
> libatomic.so libc.so.1 modules
>

My root file system uses musl.

Guenter

> rv32_rootfs:
> buildroot login: root
> # uname -a
> Linux buildroot 5.18.0-next-20220523 #7 SMP Mon May 23 11:15:17 EDT
> 2022 riscv64 GNU/Linux
> # ls /lib
> ld-linux-riscv32-ilp32d.so.1 libm.so.6
> libanl.so.1 libnss_dns.so.2
> libatomic.so libnss_files.so.2
> libatomic.so.1 libpthread.so.0
> libatomic.so.1.2.0 libresolv.so.2
> libc.so.6 librt.so.1
> libcrypt.so.1 libthread_db.so.1
> libdl.so.2 libutil.so.1
> libgcc_s.so modules
> libgcc_s.so.1
>
> Here is my qemu version:
> commit 19f13a92cef8405052e0f73d5289f9e15474dad3 (HEAD ->
> riscv-to-apply.next, alistair/riscv-to-apply.next)
> Author: Tsukasa OI <[email protected]>
> Date: Sun May 15 11:56:11 2022 +0900
>
> target/riscv: Move/refactor ISA extension checks
>
> We should separate "check" and "configure" steps as possible.
> This commit separates both steps except vector/Zfinx-related checks.
>
> Signed-off-by: Tsukasa OI <[email protected]>
> Reviewed-by: Alistair Francis <[email protected]>
> Message-Id:
> <c3145fa37a529484cf3047c8cb9841e9effad4b0.1652583332.git.research_trasio@irq.a4lg.com>
> Signed-off-by: Alistair Francis <[email protected]>
>
> On Mon, May 23, 2022 at 1:45 PM Guenter Roeck <[email protected]> wrote:
>>
>> On Tue, Mar 22, 2022 at 10:40:03PM +0800, [email protected] wrote:
>>> 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]>
>>
>> With this patch in linux-next, all my riscv64 emulations crash.
>>
>> [ 11.600082] Run /sbin/init as init process
>> [ 11.628561] init[1]: unhandled signal 11 code 0x1 at 0x0000000000000000 in libc.so[ffffff8ad39000+a4000]
>> [ 11.629398] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
>> [ 11.629462] Hardware name: riscv-virtio,qemu (DT)
>> [ 11.629546] epc : 00ffffff8ada1100 ra : 00ffffff8ada13c8 sp : 00ffffffc58199f0
>> [ 11.629586] gp : 00ffffff8ad39000 tp : 00ffffff8ade0998 t0 : ffffffffffffffff
>> [ 11.629598] t1 : 00ffffffc5819fd0 t2 : 0000000000000000 s0 : 00ffffff8ade0cc0
>> [ 11.629610] s1 : 00ffffff8ade0cc0 a0 : 0000000000000000 a1 : 00ffffffc5819a00
>> [ 11.629622] a2 : 0000000000000001 a3 : 000000000000001e a4 : 00ffffffc5819b00
>> [ 11.629634] a5 : 00ffffffc5819b00 a6 : 0000000000000000 a7 : 0000000000000000
>> [ 11.629645] s2 : 00ffffff8ade0ac8 s3 : 00ffffff8ade0ec8 s4 : 00ffffff8ade0728
>> [ 11.629656] s5 : 00ffffff8ade0a90 s6 : 0000000000000000 s7 : 00ffffffc5819e40
>> [ 11.629667] s8 : 00ffffff8ade0ca0 s9 : 00ffffff8addba50 s10: 0000000000000000
>> [ 11.629678] s11: 0000000000000000 t3 : 0000000000000002 t4 : 0000000000000001
>> [ 11.629688] t5 : 0000000000020000 t6 : ffffffffffffffff
>> [ 11.629699] status: 0000000000004020 badaddr: 0000000000000000 cause: 000000000000000d
>> [ 11.633421] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
>> [ 11.633664] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
>> [ 11.633784] Hardware name: riscv-virtio,qemu (DT)
>> [ 11.633881] Call Trace:
>> [ 11.633960] [<ffffffff80005e72>] dump_backtrace+0x1c/0x24
>> [ 11.634162] [<ffffffff809aa9ec>] show_stack+0x2c/0x38
>> [ 11.634274] [<ffffffff809b8482>] dump_stack_lvl+0x60/0x8e
>> [ 11.634386] [<ffffffff809b84c4>] dump_stack+0x14/0x1c
>> [ 11.634491] [<ffffffff809aaca0>] panic+0x116/0x2e2
>> [ 11.634596] [<ffffffff80015540>] do_exit+0x7ce/0x7d4
>> [ 11.634707] [<ffffffff80015666>] do_group_exit+0x24/0x7c
>> [ 11.634817] [<ffffffff80022294>] get_signal+0x7ee/0x830
>> [ 11.634924] [<ffffffff800051c0>] do_notify_resume+0x6c/0x41c
>> [ 11.635037] [<ffffffff80003ad4>] ret_from_exception+0x0/0x10
>>
>> Guenter
>>
>> ---
>> # bad: [18ecd30af1a8402c162cca1bd58771c0e5be7815] Add linux-next specific files for 20220520
>> # good: [42226c989789d8da4af1de0c31070c96726d990c] Linux 5.18-rc7
>> git bisect start 'HEAD' 'v5.18-rc7'
>> # bad: [f9b63740b666dd9887eb0282d21b5f65bb0cadd0] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
>> git bisect bad f9b63740b666dd9887eb0282d21b5f65bb0cadd0
>> # bad: [7db97132097c5973ff77466d0ee681650af653de] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
>> git bisect bad 7db97132097c5973ff77466d0ee681650af653de
>> # good: [2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb] soc: document merges
>> git bisect good 2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb
>> # good: [69c9668f853fdd409bb8abbb37d615785510b29a] Merge branch 'clk-next' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git
>> git bisect good 69c9668f853fdd409bb8abbb37d615785510b29a
>> # bad: [1577f290aa0d4c5b29c03c46ef52e4952a21bfbb] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git
>> git bisect bad 1577f290aa0d4c5b29c03c46ef52e4952a21bfbb
>> # good: [34f0971f8ca73d7e5502b4cf299788a9402120f7] powerpc/powernv/flash: Check OPAL flash calls exist before using
>> git bisect good 34f0971f8ca73d7e5502b4cf299788a9402120f7
>> # good: [0349d7dfc70a26b3facd8ca97de34980d4b60954] Merge branch 'mips-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux.git
>> git bisect good 0349d7dfc70a26b3facd8ca97de34980d4b60954
>> # bad: [20bfb54d3b121699674c17a854c5ebc7a8f97d81] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git
>> git bisect bad 20bfb54d3b121699674c17a854c5ebc7a8f97d81
>> # bad: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
>> git bisect bad 9be8459298eadb39b9fe9974b890239e9c123107
>> # good: [01abdfeac81b5f56062d0a78f2cdc805db937a75] riscv: compat: Support TASK_SIZE for compat mode
>> git bisect good 01abdfeac81b5f56062d0a78f2cdc805db937a75
>> # good: [f4b395e6f1a588ed6c9a30474e58cf6b27b65783] riscv: compat: Add hw capability check for elf
>> git bisect good f4b395e6f1a588ed6c9a30474e58cf6b27b65783
>> # good: [3092eb45637573c5e435fbf5eaf9516316e5f9c6] riscv: compat: vdso: Add setup additional pages implementation
>> git bisect good 3092eb45637573c5e435fbf5eaf9516316e5f9c6
>> # good: [4608c159594fb40a5101357d4f614fdde9ce1fdb] riscv: compat: ptrace: Add compat_arch_ptrace implement
>> git bisect good 4608c159594fb40a5101357d4f614fdde9ce1fdb
>> # first bad commit: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
>
>
>


2022-05-24 00:02:20

by Heiko Stuebner

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

Hi Guenter,

Am Montag, 23. Mai 2022, 18:18:47 CEST schrieb Guenter Roeck:
> On 5/23/22 08:18, Guo Ren wrote:
> > I tested Palmer's branch, it's okay:
> > 8810d7feee5a (HEAD -> for-next, palmer/for-next) riscv: Don't output a
> > bogus mmu-type on a no MMU kernel
> >
> > I also tested linux-next, it's okay:
> >
> > rv64_rootfs:
> > # uname -a
> > Linux buildroot 5.18.0-next-20220523 #7 SMP Mon May 23 11:15:17 EDT
> > 2022 riscv64 GNU/Linux
> > #
>
> That is is ok with one setup doesn't mean it is ok with
> all setups. It is not ok with my root file system (from
> https://github.com/groeck/linux-build-test/tree/master/rootfs/riscv64),
> with qemu v6.2.

That is very true that it shouldn't fail on any existing (qemu-)platform,
but as I remember also testing Guo's series on both riscv32 and riscv64
qemu platforms in the past, I guess it would be really helpful to get more
information about the failing platform you're experiencing so that we can
find the source of the issue.

As it looks like you both tested the same kernel source, I guess the only
differences could be in the qemu-version, kernel config and rootfs.
Is your rootfs something you can share or that can be rebuilt easily?


Heiko

> > #
> > #
> > # ls /lib
> > ld-uClibc-1.0.39.so libatomic.so.1 libgcc_s.so
> > ld-uClibc.so.0 libatomic.so.1.2.0 libgcc_s.so.1
> > ld-uClibc.so.1 libc.so.0 libuClibc-1.0.39.so
> > libatomic.so libc.so.1 modules
> >
>
> My root file system uses musl.
>
> Guenter
>
> > rv32_rootfs:
> > buildroot login: root
> > # uname -a
> > Linux buildroot 5.18.0-next-20220523 #7 SMP Mon May 23 11:15:17 EDT
> > 2022 riscv64 GNU/Linux
> > # ls /lib
> > ld-linux-riscv32-ilp32d.so.1 libm.so.6
> > libanl.so.1 libnss_dns.so.2
> > libatomic.so libnss_files.so.2
> > libatomic.so.1 libpthread.so.0
> > libatomic.so.1.2.0 libresolv.so.2
> > libc.so.6 librt.so.1
> > libcrypt.so.1 libthread_db.so.1
> > libdl.so.2 libutil.so.1
> > libgcc_s.so modules
> > libgcc_s.so.1
> >
> > Here is my qemu version:
> > commit 19f13a92cef8405052e0f73d5289f9e15474dad3 (HEAD ->
> > riscv-to-apply.next, alistair/riscv-to-apply.next)
> > Author: Tsukasa OI <[email protected]>
> > Date: Sun May 15 11:56:11 2022 +0900
> >
> > target/riscv: Move/refactor ISA extension checks
> >
> > We should separate "check" and "configure" steps as possible.
> > This commit separates both steps except vector/Zfinx-related checks.
> >
> > Signed-off-by: Tsukasa OI <[email protected]>
> > Reviewed-by: Alistair Francis <[email protected]>
> > Message-Id:
> > <c3145fa37a529484cf3047c8cb9841e9effad4b0.1652583332.git.research_trasio@irq.a4lg.com>
> > Signed-off-by: Alistair Francis <[email protected]>
> >
> > On Mon, May 23, 2022 at 1:45 PM Guenter Roeck <[email protected]> wrote:
> >>
> >> On Tue, Mar 22, 2022 at 10:40:03PM +0800, [email protected] wrote:
> >>> 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]>
> >>
> >> With this patch in linux-next, all my riscv64 emulations crash.
> >>
> >> [ 11.600082] Run /sbin/init as init process
> >> [ 11.628561] init[1]: unhandled signal 11 code 0x1 at 0x0000000000000000 in libc.so[ffffff8ad39000+a4000]
> >> [ 11.629398] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
> >> [ 11.629462] Hardware name: riscv-virtio,qemu (DT)
> >> [ 11.629546] epc : 00ffffff8ada1100 ra : 00ffffff8ada13c8 sp : 00ffffffc58199f0
> >> [ 11.629586] gp : 00ffffff8ad39000 tp : 00ffffff8ade0998 t0 : ffffffffffffffff
> >> [ 11.629598] t1 : 00ffffffc5819fd0 t2 : 0000000000000000 s0 : 00ffffff8ade0cc0
> >> [ 11.629610] s1 : 00ffffff8ade0cc0 a0 : 0000000000000000 a1 : 00ffffffc5819a00
> >> [ 11.629622] a2 : 0000000000000001 a3 : 000000000000001e a4 : 00ffffffc5819b00
> >> [ 11.629634] a5 : 00ffffffc5819b00 a6 : 0000000000000000 a7 : 0000000000000000
> >> [ 11.629645] s2 : 00ffffff8ade0ac8 s3 : 00ffffff8ade0ec8 s4 : 00ffffff8ade0728
> >> [ 11.629656] s5 : 00ffffff8ade0a90 s6 : 0000000000000000 s7 : 00ffffffc5819e40
> >> [ 11.629667] s8 : 00ffffff8ade0ca0 s9 : 00ffffff8addba50 s10: 0000000000000000
> >> [ 11.629678] s11: 0000000000000000 t3 : 0000000000000002 t4 : 0000000000000001
> >> [ 11.629688] t5 : 0000000000020000 t6 : ffffffffffffffff
> >> [ 11.629699] status: 0000000000004020 badaddr: 0000000000000000 cause: 000000000000000d
> >> [ 11.633421] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> >> [ 11.633664] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
> >> [ 11.633784] Hardware name: riscv-virtio,qemu (DT)
> >> [ 11.633881] Call Trace:
> >> [ 11.633960] [<ffffffff80005e72>] dump_backtrace+0x1c/0x24
> >> [ 11.634162] [<ffffffff809aa9ec>] show_stack+0x2c/0x38
> >> [ 11.634274] [<ffffffff809b8482>] dump_stack_lvl+0x60/0x8e
> >> [ 11.634386] [<ffffffff809b84c4>] dump_stack+0x14/0x1c
> >> [ 11.634491] [<ffffffff809aaca0>] panic+0x116/0x2e2
> >> [ 11.634596] [<ffffffff80015540>] do_exit+0x7ce/0x7d4
> >> [ 11.634707] [<ffffffff80015666>] do_group_exit+0x24/0x7c
> >> [ 11.634817] [<ffffffff80022294>] get_signal+0x7ee/0x830
> >> [ 11.634924] [<ffffffff800051c0>] do_notify_resume+0x6c/0x41c
> >> [ 11.635037] [<ffffffff80003ad4>] ret_from_exception+0x0/0x10
> >>
> >> Guenter
> >>
> >> ---
> >> # bad: [18ecd30af1a8402c162cca1bd58771c0e5be7815] Add linux-next specific files for 20220520
> >> # good: [42226c989789d8da4af1de0c31070c96726d990c] Linux 5.18-rc7
> >> git bisect start 'HEAD' 'v5.18-rc7'
> >> # bad: [f9b63740b666dd9887eb0282d21b5f65bb0cadd0] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
> >> git bisect bad f9b63740b666dd9887eb0282d21b5f65bb0cadd0
> >> # bad: [7db97132097c5973ff77466d0ee681650af653de] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
> >> git bisect bad 7db97132097c5973ff77466d0ee681650af653de
> >> # good: [2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb] soc: document merges
> >> git bisect good 2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb
> >> # good: [69c9668f853fdd409bb8abbb37d615785510b29a] Merge branch 'clk-next' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git
> >> git bisect good 69c9668f853fdd409bb8abbb37d615785510b29a
> >> # bad: [1577f290aa0d4c5b29c03c46ef52e4952a21bfbb] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git
> >> git bisect bad 1577f290aa0d4c5b29c03c46ef52e4952a21bfbb
> >> # good: [34f0971f8ca73d7e5502b4cf299788a9402120f7] powerpc/powernv/flash: Check OPAL flash calls exist before using
> >> git bisect good 34f0971f8ca73d7e5502b4cf299788a9402120f7
> >> # good: [0349d7dfc70a26b3facd8ca97de34980d4b60954] Merge branch 'mips-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux.git
> >> git bisect good 0349d7dfc70a26b3facd8ca97de34980d4b60954
> >> # bad: [20bfb54d3b121699674c17a854c5ebc7a8f97d81] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git
> >> git bisect bad 20bfb54d3b121699674c17a854c5ebc7a8f97d81
> >> # bad: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
> >> git bisect bad 9be8459298eadb39b9fe9974b890239e9c123107
> >> # good: [01abdfeac81b5f56062d0a78f2cdc805db937a75] riscv: compat: Support TASK_SIZE for compat mode
> >> git bisect good 01abdfeac81b5f56062d0a78f2cdc805db937a75
> >> # good: [f4b395e6f1a588ed6c9a30474e58cf6b27b65783] riscv: compat: Add hw capability check for elf
> >> git bisect good f4b395e6f1a588ed6c9a30474e58cf6b27b65783
> >> # good: [3092eb45637573c5e435fbf5eaf9516316e5f9c6] riscv: compat: vdso: Add setup additional pages implementation
> >> git bisect good 3092eb45637573c5e435fbf5eaf9516316e5f9c6
> >> # good: [4608c159594fb40a5101357d4f614fdde9ce1fdb] riscv: compat: ptrace: Add compat_arch_ptrace implement
> >> git bisect good 4608c159594fb40a5101357d4f614fdde9ce1fdb
> >> # first bad commit: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
> >
> >
> >
>
>





2022-05-24 00:43:19

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

On Tue, May 24, 2022 at 12:40:06AM +0200, Heiko St?bner wrote:
> Hi Guenter,
>
> Am Montag, 23. Mai 2022, 18:18:47 CEST schrieb Guenter Roeck:
> > On 5/23/22 08:18, Guo Ren wrote:
> > > I tested Palmer's branch, it's okay:
> > > 8810d7feee5a (HEAD -> for-next, palmer/for-next) riscv: Don't output a
> > > bogus mmu-type on a no MMU kernel
> > >
> > > I also tested linux-next, it's okay:
> > >
> > > rv64_rootfs:
> > > # uname -a
> > > Linux buildroot 5.18.0-next-20220523 #7 SMP Mon May 23 11:15:17 EDT
> > > 2022 riscv64 GNU/Linux
> > > #
> >
> > That is is ok with one setup doesn't mean it is ok with
> > all setups. It is not ok with my root file system (from
> > https://github.com/groeck/linux-build-test/tree/master/rootfs/riscv64),
> > with qemu v6.2.
>
> That is very true that it shouldn't fail on any existing (qemu-)platform,
> but as I remember also testing Guo's series on both riscv32 and riscv64
> qemu platforms in the past, I guess it would be really helpful to get more
> information about the failing platform you're experiencing so that we can
> find the source of the issue.
>
> As it looks like you both tested the same kernel source, I guess the only
> differences could be in the qemu-version, kernel config and rootfs.
> Is your rootfs something you can share or that can be rebuilt easily?
>
I provided a link to my root file system above. The link points to two
root file systems, for initrd (cpio archive) and for ext2.
I also mentioned above that I used qemu v6.2. And below I said

> My root file system uses musl.

I attached the buildroot configuration below. The buildroot version,
if I remember correctly, was 2021.02.

Kernel configuration is basically defconfig. However, I do see one
detail that is possibly special in my configuration.

# The latest kernel assumes SBI version 0.3, but that doesn't match qemu
# at least up to version 6.2 and results in hangup/crashes during reboot
# with sifive_u emulations.
enable_config "${defconfig}" CONFIG_RISCV_SBI_V01

Hope that helps,

Guenter

---
BR2_riscv=y
BR2_TOOLCHAIN_BUILDROOT_MUSL=y
BR2_KERNEL_HEADERS_4_19=y
BR2_BINUTILS_VERSION_2_32_X=y
BR2_TARGET_RUN_TESTSCRIPT=y
BR2_SHUTDOWN_COMMAND_POWEROFF=y
BR2_SYSTEM_DHCP="eth0"
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
BR2_PACKAGE_STRACE=y
BR2_PACKAGE_I2C_TOOLS=y
BR2_PACKAGE_PCIUTILS=y
BR2_PACKAGE_DTC=y
BR2_PACKAGE_DTC_PROGRAMS=y
BR2_PACKAGE_IPROUTE2=y
BR2_TARGET_ROOTFS_BTRFS=y
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_CPIO_GZIP=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_SIZE="16M"
BR2_TARGET_ROOTFS_EXT2_GZIP=y
BR2_TARGET_ROOTFS_ISO_GZIP=y
BR2_TARGET_ROOTFS_SQUASHFS=y
# BR2_TARGET_ROOTFS_TAR is not set


2022-05-24 20:05:31

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

On Mon, May 23, 2022 at 1:45 PM Guenter Roeck <[email protected]> wrote:
>
> On Tue, Mar 22, 2022 at 10:40:03PM +0800, [email protected] wrote:
> > 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]>
>
> With this patch in linux-next, all my riscv64 emulations crash.
>
> [ 11.600082] Run /sbin/init as init process
> [ 11.628561] init[1]: unhandled signal 11 code 0x1 at 0x0000000000000000 in libc.so[ffffff8ad39000+a4000]
> [ 11.629398] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
> [ 11.629462] Hardware name: riscv-virtio,qemu (DT)
> [ 11.629546] epc : 00ffffff8ada1100 ra : 00ffffff8ada13c8 sp : 00ffffffc58199f0
> [ 11.629586] gp : 00ffffff8ad39000 tp : 00ffffff8ade0998 t0 : ffffffffffffffff
> [ 11.629598] t1 : 00ffffffc5819fd0 t2 : 0000000000000000 s0 : 00ffffff8ade0cc0
> [ 11.629610] s1 : 00ffffff8ade0cc0 a0 : 0000000000000000 a1 : 00ffffffc5819a00
> [ 11.629622] a2 : 0000000000000001 a3 : 000000000000001e a4 : 00ffffffc5819b00
> [ 11.629634] a5 : 00ffffffc5819b00 a6 : 0000000000000000 a7 : 0000000000000000
> [ 11.629645] s2 : 00ffffff8ade0ac8 s3 : 00ffffff8ade0ec8 s4 : 00ffffff8ade0728
> [ 11.629656] s5 : 00ffffff8ade0a90 s6 : 0000000000000000 s7 : 00ffffffc5819e40
> [ 11.629667] s8 : 00ffffff8ade0ca0 s9 : 00ffffff8addba50 s10: 0000000000000000
> [ 11.629678] s11: 0000000000000000 t3 : 0000000000000002 t4 : 0000000000000001
> [ 11.629688] t5 : 0000000000020000 t6 : ffffffffffffffff
> [ 11.629699] status: 0000000000004020 badaddr: 0000000000000000 cause: 000000000000000d
> [ 11.633421] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> [ 11.633664] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
> [ 11.633784] Hardware name: riscv-virtio,qemu (DT)
> [ 11.633881] Call Trace:
> [ 11.633960] [<ffffffff80005e72>] dump_backtrace+0x1c/0x24
> [ 11.634162] [<ffffffff809aa9ec>] show_stack+0x2c/0x38
> [ 11.634274] [<ffffffff809b8482>] dump_stack_lvl+0x60/0x8e
> [ 11.634386] [<ffffffff809b84c4>] dump_stack+0x14/0x1c
> [ 11.634491] [<ffffffff809aaca0>] panic+0x116/0x2e2
> [ 11.634596] [<ffffffff80015540>] do_exit+0x7ce/0x7d4
> [ 11.634707] [<ffffffff80015666>] do_group_exit+0x24/0x7c
> [ 11.634817] [<ffffffff80022294>] get_signal+0x7ee/0x830
> [ 11.634924] [<ffffffff800051c0>] do_notify_resume+0x6c/0x41c
> [ 11.635037] [<ffffffff80003ad4>] ret_from_exception+0x0/0x10
The problem is come from "__dls3's vdso decode part in musl's
ldso/dynlink.c". The ehdr->e_phnum & ehdr->e_phentsize are wrong.

I think the root cause is from musl's implementation with the wrong
elf parser. I would fix that soon.

If you CONFIG_COMPAT=n, the bug would be bypassed.

>
> Guenter
>
> ---
> # bad: [18ecd30af1a8402c162cca1bd58771c0e5be7815] Add linux-next specific files for 20220520
> # good: [42226c989789d8da4af1de0c31070c96726d990c] Linux 5.18-rc7
> git bisect start 'HEAD' 'v5.18-rc7'
> # bad: [f9b63740b666dd9887eb0282d21b5f65bb0cadd0] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
> git bisect bad f9b63740b666dd9887eb0282d21b5f65bb0cadd0
> # bad: [7db97132097c5973ff77466d0ee681650af653de] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
> git bisect bad 7db97132097c5973ff77466d0ee681650af653de
> # good: [2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb] soc: document merges
> git bisect good 2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb
> # good: [69c9668f853fdd409bb8abbb37d615785510b29a] Merge branch 'clk-next' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git
> git bisect good 69c9668f853fdd409bb8abbb37d615785510b29a
> # bad: [1577f290aa0d4c5b29c03c46ef52e4952a21bfbb] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git
> git bisect bad 1577f290aa0d4c5b29c03c46ef52e4952a21bfbb
> # good: [34f0971f8ca73d7e5502b4cf299788a9402120f7] powerpc/powernv/flash: Check OPAL flash calls exist before using
> git bisect good 34f0971f8ca73d7e5502b4cf299788a9402120f7
> # good: [0349d7dfc70a26b3facd8ca97de34980d4b60954] Merge branch 'mips-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux.git
> git bisect good 0349d7dfc70a26b3facd8ca97de34980d4b60954
> # bad: [20bfb54d3b121699674c17a854c5ebc7a8f97d81] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git
> git bisect bad 20bfb54d3b121699674c17a854c5ebc7a8f97d81
> # bad: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
> git bisect bad 9be8459298eadb39b9fe9974b890239e9c123107
> # good: [01abdfeac81b5f56062d0a78f2cdc805db937a75] riscv: compat: Support TASK_SIZE for compat mode
> git bisect good 01abdfeac81b5f56062d0a78f2cdc805db937a75
> # good: [f4b395e6f1a588ed6c9a30474e58cf6b27b65783] riscv: compat: Add hw capability check for elf
> git bisect good f4b395e6f1a588ed6c9a30474e58cf6b27b65783
> # good: [3092eb45637573c5e435fbf5eaf9516316e5f9c6] riscv: compat: vdso: Add setup additional pages implementation
> git bisect good 3092eb45637573c5e435fbf5eaf9516316e5f9c6
> # good: [4608c159594fb40a5101357d4f614fdde9ce1fdb] riscv: compat: ptrace: Add compat_arch_ptrace implement
> git bisect good 4608c159594fb40a5101357d4f614fdde9ce1fdb
> # first bad commit: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support



--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

2022-05-25 01:08:37

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

On Wed, May 25, 2022 at 1:42 AM Guo Ren <[email protected]> wrote:
>
> On Mon, May 23, 2022 at 1:45 PM Guenter Roeck <[email protected]> wrote:
> >
> > On Tue, Mar 22, 2022 at 10:40:03PM +0800, [email protected] wrote:
> > > 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]>
> >
> > With this patch in linux-next, all my riscv64 emulations crash.
> >
> > [ 11.600082] Run /sbin/init as init process
> > [ 11.628561] init[1]: unhandled signal 11 code 0x1 at 0x0000000000000000 in libc.so[ffffff8ad39000+a4000]
> > [ 11.629398] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
> > [ 11.629462] Hardware name: riscv-virtio,qemu (DT)
> > [ 11.629546] epc : 00ffffff8ada1100 ra : 00ffffff8ada13c8 sp : 00ffffffc58199f0
> > [ 11.629586] gp : 00ffffff8ad39000 tp : 00ffffff8ade0998 t0 : ffffffffffffffff
> > [ 11.629598] t1 : 00ffffffc5819fd0 t2 : 0000000000000000 s0 : 00ffffff8ade0cc0
> > [ 11.629610] s1 : 00ffffff8ade0cc0 a0 : 0000000000000000 a1 : 00ffffffc5819a00
> > [ 11.629622] a2 : 0000000000000001 a3 : 000000000000001e a4 : 00ffffffc5819b00
> > [ 11.629634] a5 : 00ffffffc5819b00 a6 : 0000000000000000 a7 : 0000000000000000
> > [ 11.629645] s2 : 00ffffff8ade0ac8 s3 : 00ffffff8ade0ec8 s4 : 00ffffff8ade0728
> > [ 11.629656] s5 : 00ffffff8ade0a90 s6 : 0000000000000000 s7 : 00ffffffc5819e40
> > [ 11.629667] s8 : 00ffffff8ade0ca0 s9 : 00ffffff8addba50 s10: 0000000000000000
> > [ 11.629678] s11: 0000000000000000 t3 : 0000000000000002 t4 : 0000000000000001
> > [ 11.629688] t5 : 0000000000020000 t6 : ffffffffffffffff
> > [ 11.629699] status: 0000000000004020 badaddr: 0000000000000000 cause: 000000000000000d
> > [ 11.633421] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> > [ 11.633664] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-rc7-next-20220520 #1
> > [ 11.633784] Hardware name: riscv-virtio,qemu (DT)
> > [ 11.633881] Call Trace:
> > [ 11.633960] [<ffffffff80005e72>] dump_backtrace+0x1c/0x24
> > [ 11.634162] [<ffffffff809aa9ec>] show_stack+0x2c/0x38
> > [ 11.634274] [<ffffffff809b8482>] dump_stack_lvl+0x60/0x8e
> > [ 11.634386] [<ffffffff809b84c4>] dump_stack+0x14/0x1c
> > [ 11.634491] [<ffffffff809aaca0>] panic+0x116/0x2e2
> > [ 11.634596] [<ffffffff80015540>] do_exit+0x7ce/0x7d4
> > [ 11.634707] [<ffffffff80015666>] do_group_exit+0x24/0x7c
> > [ 11.634817] [<ffffffff80022294>] get_signal+0x7ee/0x830
> > [ 11.634924] [<ffffffff800051c0>] do_notify_resume+0x6c/0x41c
> > [ 11.635037] [<ffffffff80003ad4>] ret_from_exception+0x0/0x10
> The problem is come from "__dls3's vdso decode part in musl's
> ldso/dynlink.c". The ehdr->e_phnum & ehdr->e_phentsize are wrong.
>
> I think the root cause is from musl's implementation with the wrong
> elf parser. I would fix that soon.
Not elf parser, it's "aux vector just past environ[]". I think I could
solve this, but anyone who could help dig in is welcome.

>
> If you CONFIG_COMPAT=n, the bug would be bypassed.
>
> >
> > Guenter
> >
> > ---
> > # bad: [18ecd30af1a8402c162cca1bd58771c0e5be7815] Add linux-next specific files for 20220520
> > # good: [42226c989789d8da4af1de0c31070c96726d990c] Linux 5.18-rc7
> > git bisect start 'HEAD' 'v5.18-rc7'
> > # bad: [f9b63740b666dd9887eb0282d21b5f65bb0cadd0] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
> > git bisect bad f9b63740b666dd9887eb0282d21b5f65bb0cadd0
> > # bad: [7db97132097c5973ff77466d0ee681650af653de] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
> > git bisect bad 7db97132097c5973ff77466d0ee681650af653de
> > # good: [2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb] soc: document merges
> > git bisect good 2b7d17d4b7c1ff40f58b0d32be40fc0bb6c582fb
> > # good: [69c9668f853fdd409bb8abbb37d615785510b29a] Merge branch 'clk-next' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git
> > git bisect good 69c9668f853fdd409bb8abbb37d615785510b29a
> > # bad: [1577f290aa0d4c5b29c03c46ef52e4952a21bfbb] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git
> > git bisect bad 1577f290aa0d4c5b29c03c46ef52e4952a21bfbb
> > # good: [34f0971f8ca73d7e5502b4cf299788a9402120f7] powerpc/powernv/flash: Check OPAL flash calls exist before using
> > git bisect good 34f0971f8ca73d7e5502b4cf299788a9402120f7
> > # good: [0349d7dfc70a26b3facd8ca97de34980d4b60954] Merge branch 'mips-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux.git
> > git bisect good 0349d7dfc70a26b3facd8ca97de34980d4b60954
> > # bad: [20bfb54d3b121699674c17a854c5ebc7a8f97d81] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git
> > git bisect bad 20bfb54d3b121699674c17a854c5ebc7a8f97d81
> > # bad: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
> > git bisect bad 9be8459298eadb39b9fe9974b890239e9c123107
> > # good: [01abdfeac81b5f56062d0a78f2cdc805db937a75] riscv: compat: Support TASK_SIZE for compat mode
> > git bisect good 01abdfeac81b5f56062d0a78f2cdc805db937a75
> > # good: [f4b395e6f1a588ed6c9a30474e58cf6b27b65783] riscv: compat: Add hw capability check for elf
> > git bisect good f4b395e6f1a588ed6c9a30474e58cf6b27b65783
> > # good: [3092eb45637573c5e435fbf5eaf9516316e5f9c6] riscv: compat: vdso: Add setup additional pages implementation
> > git bisect good 3092eb45637573c5e435fbf5eaf9516316e5f9c6
> > # good: [4608c159594fb40a5101357d4f614fdde9ce1fdb] riscv: compat: ptrace: Add compat_arch_ptrace implement
> > git bisect good 4608c159594fb40a5101357d4f614fdde9ce1fdb
> > # first bad commit: [9be8459298eadb39b9fe9974b890239e9c123107] riscv: compat: Add COMPAT Kbuild skeletal support
>
>
>
> --
> Best Regards
> Guo Ren
>
> ML: https://lore.kernel.org/linux-csky/



--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

2022-05-25 04:41:14

by Heiko Stuebner

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

Am Dienstag, 24. Mai 2022, 01:00:39 CEST schrieb Guenter Roeck:
> On Tue, May 24, 2022 at 12:40:06AM +0200, Heiko St?bner wrote:
> > Hi Guenter,
> >
> > Am Montag, 23. Mai 2022, 18:18:47 CEST schrieb Guenter Roeck:
> > > On 5/23/22 08:18, Guo Ren wrote:
> > > > I tested Palmer's branch, it's okay:
> > > > 8810d7feee5a (HEAD -> for-next, palmer/for-next) riscv: Don't output a
> > > > bogus mmu-type on a no MMU kernel
> > > >
> > > > I also tested linux-next, it's okay:
> > > >
> > > > rv64_rootfs:
> > > > # uname -a
> > > > Linux buildroot 5.18.0-next-20220523 #7 SMP Mon May 23 11:15:17 EDT
> > > > 2022 riscv64 GNU/Linux
> > > > #
> > >
> > > That is is ok with one setup doesn't mean it is ok with
> > > all setups. It is not ok with my root file system (from
> > > https://github.com/groeck/linux-build-test/tree/master/rootfs/riscv64),
> > > with qemu v6.2.
> >
> > That is very true that it shouldn't fail on any existing (qemu-)platform,
> > but as I remember also testing Guo's series on both riscv32 and riscv64
> > qemu platforms in the past, I guess it would be really helpful to get more
> > information about the failing platform you're experiencing so that we can
> > find the source of the issue.
> >
> > As it looks like you both tested the same kernel source, I guess the only
> > differences could be in the qemu-version, kernel config and rootfs.
> > Is your rootfs something you can share or that can be rebuilt easily?
> >
> I provided a link to my root file system above. The link points to two
> root file systems, for initrd (cpio archive) and for ext2.
> I also mentioned above that I used qemu v6.2. And below I said
>
> > My root file system uses musl.
>
> I attached the buildroot configuration below. The buildroot version,
> if I remember correctly, was 2021.02.
>
> Kernel configuration is basically defconfig. However, I do see one
> detail that is possibly special in my configuration.
>
> # The latest kernel assumes SBI version 0.3, but that doesn't match qemu
> # at least up to version 6.2 and results in hangup/crashes during reboot
> # with sifive_u emulations.
> enable_config "${defconfig}" CONFIG_RISCV_SBI_V01
>
> Hope that helps,

Actually it doesn't seem rootfs-specific at all.

Merged was this v9, but the version I last tested was one of the earlier
ones, so it looks like something really broke meanwhile.

I tested both linux-next-20220524 and palmer's for-next on a very recent
qemu - master from april if I remember correctly together with a
Debian-based rootfs mounted as nfsroot inside qemu.

With CONFIG_COMPAT=y (aka using defconfig directly) I get:
[ 12.957612] VFS: Mounted root (nfs filesystem) on device 0:15.
[ 12.967260] devtmpfs: mounted
[ 13.101186] Freeing unused kernel image (initmem) memory: 2168K
[ 13.110914] Run /sbin/init as init process
[ 13.343810] Unable to handle kernel paging request at virtual address ff60007265776f78
[ 13.347271] Oops [#1]
[ 13.347749] Modules linked in:
[ 13.348689] CPU: 0 PID: 1 Comm: init Not tainted 5.18.0-next-20220524 #1
[ 13.349864] Hardware name: riscv-virtio,qemu (DT)
[ 13.350706] epc : special_mapping_fault+0x4c/0x8e
[ 13.351639] ra : __do_fault+0x28/0x11c
[ 13.352311] epc : ffffffff801210e6 ra : ffffffff8011712a sp : ff2000000060bd10
[ 13.353276] gp : ffffffff810df030 tp : ff600000012a8000 t0 : ffffffff80008acc
[ 13.354063] t1 : ffffffff80c001d8 t2 : ffffffff80c00258 s0 : ff2000000060bd20
[ 13.354886] s1 : ff2000000060bd68 a0 : ff600000013165f0 a1 : ff60000001ec2450
[ 13.355675] a2 : ff2000000060bd68 a3 : 0000000000000000 a4 : ff6000003f0337c8
[ 13.356822] a5 : ff60007265776f70 a6 : ff60000001ec2450 a7 : 0000000000000007
[ 13.357689] s2 : ff60000001ec2450 s3 : ff60000001ec2450 s4 : ff2000000060bd68
[ 13.358487] s5 : ff60000001ec2450 s6 : 0000000000000254 s7 : 000000000000000c
[ 13.359305] s8 : 000000000000000f s9 : 000000000000000d s10: ff60000001e4c080
[ 13.360102] s11: 000000000000000d t3 : 00ffffffbbeab000 t4 : 000000006ffffdff
[ 13.361557] t5 : 000000006ffffe35 t6 : 000000000000000a
[ 13.362229] status: 0000000200000120 badaddr: ff60007265776f78 cause: 000000000000000d
[ 13.363504] [<ffffffff8011712a>] __do_fault+0x28/0x11c
[ 13.364464] [<ffffffff8011b346>] __handle_mm_fault+0x71c/0x9ea
[ 13.365577] [<ffffffff8011b696>] handle_mm_fault+0x82/0x136
[ 13.366275] [<ffffffff80008bec>] do_page_fault+0x120/0x31c
[ 13.366906] [<ffffffff800032f4>] ret_from_exception+0x0/0xc
[ 13.368763] ---[ end trace 0000000000000000 ]---
[ 13.368763] ---[ end trace 0000000000000000 ]---
[ 13.369598] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 13.369933] SMP: stopping secondary CPUs


Turning CONFIG_COMPAT off, results in the system booting normally again.


Heiko


> ---
> BR2_riscv=y
> BR2_TOOLCHAIN_BUILDROOT_MUSL=y
> BR2_KERNEL_HEADERS_4_19=y
> BR2_BINUTILS_VERSION_2_32_X=y
> BR2_TARGET_RUN_TESTSCRIPT=y
> BR2_SHUTDOWN_COMMAND_POWEROFF=y
> BR2_SYSTEM_DHCP="eth0"
> BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
> BR2_PACKAGE_STRACE=y
> BR2_PACKAGE_I2C_TOOLS=y
> BR2_PACKAGE_PCIUTILS=y
> BR2_PACKAGE_DTC=y
> BR2_PACKAGE_DTC_PROGRAMS=y
> BR2_PACKAGE_IPROUTE2=y
> BR2_TARGET_ROOTFS_BTRFS=y
> BR2_TARGET_ROOTFS_CPIO=y
> BR2_TARGET_ROOTFS_CPIO_GZIP=y
> BR2_TARGET_ROOTFS_EXT2=y
> BR2_TARGET_ROOTFS_EXT2_SIZE="16M"
> BR2_TARGET_ROOTFS_EXT2_GZIP=y
> BR2_TARGET_ROOTFS_ISO_GZIP=y
> BR2_TARGET_ROOTFS_SQUASHFS=y
> # BR2_TARGET_ROOTFS_TAR is not set
>
>





2022-05-25 20:14:25

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

On Wed, May 25, 2022 at 01:46:38AM +0800, Guo Ren wrote:
[ ... ]

> > The problem is come from "__dls3's vdso decode part in musl's
> > ldso/dynlink.c". The ehdr->e_phnum & ehdr->e_phentsize are wrong.
> >
> > I think the root cause is from musl's implementation with the wrong
> > elf parser. I would fix that soon.
> Not elf parser, it's "aux vector just past environ[]". I think I could
> solve this, but anyone who could help dig in is welcome.
>

I am not sure I understand what you are saying here. Point is that my
root file system, generated with musl a year or so ago, crashes with
your patch set applied. That is a regression, even if there is a bug
in musl.

Guenter

2022-05-25 21:35:49

by Heiko Stuebner

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

Am Mittwoch, 25. Mai 2022, 12:57:30 CEST schrieb Heiko St?bner:
> Am Mittwoch, 25. Mai 2022, 00:06:46 CEST schrieb Guenter Roeck:
> > On Wed, May 25, 2022 at 01:46:38AM +0800, Guo Ren wrote:
> > [ ... ]
> >
> > > > The problem is come from "__dls3's vdso decode part in musl's
> > > > ldso/dynlink.c". The ehdr->e_phnum & ehdr->e_phentsize are wrong.
> > > >
> > > > I think the root cause is from musl's implementation with the wrong
> > > > elf parser. I would fix that soon.
> > > Not elf parser, it's "aux vector just past environ[]". I think I could
> > > solve this, but anyone who could help dig in is welcome.
> > >
> >
> > I am not sure I understand what you are saying here. Point is that my
> > root file system, generated with musl a year or so ago, crashes with
> > your patch set applied. That is a regression, even if there is a bug
> > in musl.
>
> Also as I said in the other part of the thread, the rootfs seems innocent,
> as my completely-standard Debian riscv64 rootfs is also affected.
>
> The merged version seems to be v12 [0] - not sure how we this discussion
> ended up in v9, but I just tested this revision in two variants:
>
> - v5.17 + this v9 -> works nicely

I take that back ... now going back to that build I somehow also run into
that issue here ... will investigate more.


> - v5.18-rc6 + this v9 (rebased onto it) -> breaks the boot
> The only rebase-conflict was with the introduction of restartable
> sequences and removal of the tracehook include, but turning CONFIG_RSEQ
> off doesn't seem to affect the breakage.
>
> So it looks like something changed between 5.17 and 5.18 that causes the issue.
>
>
> Heiko
>
>
> [0] https://lore.kernel.org/all/[email protected]/
>





2022-05-26 03:00:52

by Heiko Stuebner

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

Am Mittwoch, 25. Mai 2022, 18:08:22 CEST schrieb Guo Ren:
> Thx Heiko & Guenter,
>
> On Wed, May 25, 2022 at 7:10 PM Heiko St?bner <[email protected]> wrote:
> >
> > Am Mittwoch, 25. Mai 2022, 12:57:30 CEST schrieb Heiko St?bner:
> > > Am Mittwoch, 25. Mai 2022, 00:06:46 CEST schrieb Guenter Roeck:
> > > > On Wed, May 25, 2022 at 01:46:38AM +0800, Guo Ren wrote:
> > > > [ ... ]
> > > >
> > > > > > The problem is come from "__dls3's vdso decode part in musl's
> > > > > > ldso/dynlink.c". The ehdr->e_phnum & ehdr->e_phentsize are wrong.
> > > > > >
> > > > > > I think the root cause is from musl's implementation with the wrong
> > > > > > elf parser. I would fix that soon.
> > > > > Not elf parser, it's "aux vector just past environ[]". I think I could
> > > > > solve this, but anyone who could help dig in is welcome.
> > > > >
> > > >
> > > > I am not sure I understand what you are saying here. Point is that my
> > > > root file system, generated with musl a year or so ago, crashes with
> > > > your patch set applied. That is a regression, even if there is a bug
> > > > in musl.
> Thx for the report, it's a valuable regression for riscv-compat.
>
> > >
> > > Also as I said in the other part of the thread, the rootfs seems innocent,
> > > as my completely-standard Debian riscv64 rootfs is also affected.
> > >
> > > The merged version seems to be v12 [0] - not sure how we this discussion
> > > ended up in v9, but I just tested this revision in two variants:
> > >
> > > - v5.17 + this v9 -> works nicely
> >
> > I take that back ... now going back to that build I somehow also run into
> > that issue here ... will investigate more.
> Yeah, it's my fault. I've fixed up it, please have a try:
>
> https://lore.kernel.org/linux-riscv/[email protected]/T/#u

very cool that you found the issue.
I've tested your patch and it seems to fix the issue for me.

Thanks for figuring out the cause
Heiko


> > > - v5.18-rc6 + this v9 (rebased onto it) -> breaks the boot
> > > The only rebase-conflict was with the introduction of restartable
> > > sequences and removal of the tracehook include, but turning CONFIG_RSEQ
> > > off doesn't seem to affect the breakage.
> > >
> > > So it looks like something changed between 5.17 and 5.18 that causes the issue.
> > >
> > >
> > > Heiko
> > >
> > >
> > > [0] https://lore.kernel.org/all/[email protected]/
> > >
> >
> >
> >
> >
>
>
>





2022-05-26 09:22:58

by Heiko Stuebner

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

Am Mittwoch, 25. Mai 2022, 00:06:46 CEST schrieb Guenter Roeck:
> On Wed, May 25, 2022 at 01:46:38AM +0800, Guo Ren wrote:
> [ ... ]
>
> > > The problem is come from "__dls3's vdso decode part in musl's
> > > ldso/dynlink.c". The ehdr->e_phnum & ehdr->e_phentsize are wrong.
> > >
> > > I think the root cause is from musl's implementation with the wrong
> > > elf parser. I would fix that soon.
> > Not elf parser, it's "aux vector just past environ[]". I think I could
> > solve this, but anyone who could help dig in is welcome.
> >
>
> I am not sure I understand what you are saying here. Point is that my
> root file system, generated with musl a year or so ago, crashes with
> your patch set applied. That is a regression, even if there is a bug
> in musl.

Also as I said in the other part of the thread, the rootfs seems innocent,
as my completely-standard Debian riscv64 rootfs is also affected.

The merged version seems to be v12 [0] - not sure how we this discussion
ended up in v9, but I just tested this revision in two variants:

- v5.17 + this v9 -> works nicely
- v5.18-rc6 + this v9 (rebased onto it) -> breaks the boot
The only rebase-conflict was with the introduction of restartable
sequences and removal of the tracehook include, but turning CONFIG_RSEQ
off doesn't seem to affect the breakage.

So it looks like something changed between 5.17 and 5.18 that causes the issue.


Heiko


[0] https://lore.kernel.org/all/[email protected]/




2022-05-26 17:55:18

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

On Thu, May 26, 2022 at 3:37 AM Heiko Stübner <[email protected]> wrote:
>
> Am Mittwoch, 25. Mai 2022, 18:08:22 CEST schrieb Guo Ren:
> > Thx Heiko & Guenter,
> >
> > On Wed, May 25, 2022 at 7:10 PM Heiko Stübner <[email protected]> wrote:
> > >
> > > Am Mittwoch, 25. Mai 2022, 12:57:30 CEST schrieb Heiko Stübner:
> > > > Am Mittwoch, 25. Mai 2022, 00:06:46 CEST schrieb Guenter Roeck:
> > > > > On Wed, May 25, 2022 at 01:46:38AM +0800, Guo Ren wrote:
> > > > > [ ... ]
> > > > >
> > > > > > > The problem is come from "__dls3's vdso decode part in musl's
> > > > > > > ldso/dynlink.c". The ehdr->e_phnum & ehdr->e_phentsize are wrong.
> > > > > > >
> > > > > > > I think the root cause is from musl's implementation with the wrong
> > > > > > > elf parser. I would fix that soon.
> > > > > > Not elf parser, it's "aux vector just past environ[]". I think I could
> > > > > > solve this, but anyone who could help dig in is welcome.
> > > > > >
> > > > >
> > > > > I am not sure I understand what you are saying here. Point is that my
> > > > > root file system, generated with musl a year or so ago, crashes with
> > > > > your patch set applied. That is a regression, even if there is a bug
> > > > > in musl.
> > Thx for the report, it's a valuable regression for riscv-compat.
> >
> > > >
> > > > Also as I said in the other part of the thread, the rootfs seems innocent,
> > > > as my completely-standard Debian riscv64 rootfs is also affected.
> > > >
> > > > The merged version seems to be v12 [0] - not sure how we this discussion
> > > > ended up in v9, but I just tested this revision in two variants:
> > > >
> > > > - v5.17 + this v9 -> works nicely
> > >
> > > I take that back ... now going back to that build I somehow also run into
> > > that issue here ... will investigate more.
> > Yeah, it's my fault. I've fixed up it, please have a try:
> >
> > https://lore.kernel.org/linux-riscv/[email protected]/T/#u
>
> very cool that you found the issue.
> I've tested your patch and it seems to fix the issue for me.
>
> Thanks for figuring out the cause
I should thx Guenter Roeck, It just surprised me that compat_vdso
could work with quite a lot of rv64 apps.

> Heiko
>
>
> > > > - v5.18-rc6 + this v9 (rebased onto it) -> breaks the boot
> > > > The only rebase-conflict was with the introduction of restartable
> > > > sequences and removal of the tracehook include, but turning CONFIG_RSEQ
> > > > off doesn't seem to affect the breakage.
> > > >
> > > > So it looks like something changed between 5.17 and 5.18 that causes the issue.
> > > >
> > > >
> > > > Heiko
> > > >
> > > >
> > > > [0] https://lore.kernel.org/all/[email protected]/
> > > >
> > >
> > >
> > >
> > >
> >
> >
> >
>
>
>
>


--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

2022-05-26 22:11:47

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH V9 20/20] riscv: compat: Add COMPAT Kbuild skeletal support

Thx Heiko & Guenter,

On Wed, May 25, 2022 at 7:10 PM Heiko Stübner <[email protected]> wrote:
>
> Am Mittwoch, 25. Mai 2022, 12:57:30 CEST schrieb Heiko Stübner:
> > Am Mittwoch, 25. Mai 2022, 00:06:46 CEST schrieb Guenter Roeck:
> > > On Wed, May 25, 2022 at 01:46:38AM +0800, Guo Ren wrote:
> > > [ ... ]
> > >
> > > > > The problem is come from "__dls3's vdso decode part in musl's
> > > > > ldso/dynlink.c". The ehdr->e_phnum & ehdr->e_phentsize are wrong.
> > > > >
> > > > > I think the root cause is from musl's implementation with the wrong
> > > > > elf parser. I would fix that soon.
> > > > Not elf parser, it's "aux vector just past environ[]". I think I could
> > > > solve this, but anyone who could help dig in is welcome.
> > > >
> > >
> > > I am not sure I understand what you are saying here. Point is that my
> > > root file system, generated with musl a year or so ago, crashes with
> > > your patch set applied. That is a regression, even if there is a bug
> > > in musl.
Thx for the report, it's a valuable regression for riscv-compat.

> >
> > Also as I said in the other part of the thread, the rootfs seems innocent,
> > as my completely-standard Debian riscv64 rootfs is also affected.
> >
> > The merged version seems to be v12 [0] - not sure how we this discussion
> > ended up in v9, but I just tested this revision in two variants:
> >
> > - v5.17 + this v9 -> works nicely
>
> I take that back ... now going back to that build I somehow also run into
> that issue here ... will investigate more.
Yeah, it's my fault. I've fixed up it, please have a try:

https://lore.kernel.org/linux-riscv/[email protected]/T/#u

>
>
> > - v5.18-rc6 + this v9 (rebased onto it) -> breaks the boot
> > The only rebase-conflict was with the introduction of restartable
> > sequences and removal of the tracehook include, but turning CONFIG_RSEQ
> > off doesn't seem to affect the breakage.
> >
> > So it looks like something changed between 5.17 and 5.18 that causes the issue.
> >
> >
> > Heiko
> >
> >
> > [0] https://lore.kernel.org/all/[email protected]/
> >
>
>
>
>


--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/