From 1a0e0c10f985a99aeaa1f2c08312c2590ed4e007 Mon Sep 17 00:00:00 2001 From: Alexander Mikhalitsyn Date: Sun, 17 Nov 2024 16:10:20 +0000 Subject: [PATCH 1/2] compel: fix gitignore and remove autogenerated code We don't need to have compel/arch/riscv64/plugins/std/syscalls/syscalls.S tracked in git. It is autogenerated. We also need to update our .gitignore to ignore autogenerated files with syscall tables. Signed-off-by: Alexander Mikhalitsyn --- compel/.gitignore | 3 + .../riscv64/plugins/std/syscalls/syscalls.S | 112 ------------------ 2 files changed, 3 insertions(+), 112 deletions(-) delete mode 100644 compel/arch/riscv64/plugins/std/syscalls/syscalls.S diff --git a/compel/.gitignore b/compel/.gitignore index eab3337d6b..5e770a86c7 100644 --- a/compel/.gitignore +++ b/compel/.gitignore @@ -4,6 +4,9 @@ arch/arm/plugins/std/syscalls/syscalls.S arch/aarch64/plugins/std/syscalls/syscalls.S arch/s390/plugins/std/syscalls/syscalls.S arch/ppc64/plugins/std/syscalls/syscalls.S +arch/mips/plugins/std/syscalls/syscalls-64.S +arch/loongarch64/plugins/std/syscalls/syscalls-64.S +arch/riscv64/plugins/std/syscalls/syscalls.S include/version.h plugins/include/uapi/std/asm/syscall-types.h plugins/include/uapi/std/syscall-64.h diff --git a/compel/arch/riscv64/plugins/std/syscalls/syscalls.S b/compel/arch/riscv64/plugins/std/syscalls/syscalls.S deleted file mode 100644 index 715da46122..0000000000 --- a/compel/arch/riscv64/plugins/std/syscalls/syscalls.S +++ /dev/null @@ -1,112 +0,0 @@ -/* Autogenerated, don't edit */ -#include -#include "std/syscalls/syscall-common.S" -syscall sys_read, __NR_read -syscall sys_write, __NR_write -syscall sys_close, __NR_close -syscall sys_lseek, __NR_lseek -syscall sys_mmap, __NR_mmap -syscall sys_mprotect, __NR_mprotect -syscall sys_munmap, __NR_munmap -syscall sys_brk, __NR_brk -syscall sys_sigaction, __NR_rt_sigaction -syscall sys_sigprocmask, __NR_rt_sigprocmask -syscall sys_rt_sigreturn, __NR_rt_sigreturn -syscall sys_ioctl, __NR_ioctl -syscall sys_pread64, __NR_pread64 -syscall sys_ptrace, __NR_ptrace -syscall sys_mremap, __NR_mremap -syscall sys_mincore, __NR_mincore -syscall sys_madvise, __NR_madvise -syscall sys_shmat, __NR_shmat -syscall sys_pause, __NR_pause -syscall sys_nanosleep, __NR_nanosleep -syscall sys_getitimer, __NR_getitimer -syscall sys_setitimer, __NR_setitimer -syscall sys_getpid, __NR_getpid -syscall sys_socket, __NR_socket -syscall sys_connect, __NR_connect -syscall sys_sendto, __NR_sendto -syscall sys_recvfrom, __NR_recvfrom -syscall sys_sendmsg, __NR_sendmsg -syscall sys_recvmsg, __NR_recvmsg -syscall sys_shutdown, __NR_shutdown -syscall sys_bind, __NR_bind -syscall sys_setsockopt, __NR_setsockopt -syscall sys_getsockopt, __NR_getsockopt -syscall sys_clone, __NR_clone -syscall sys_exit, __NR_exit -syscall sys_wait4, __NR_wait4 -syscall sys_waitid, __NR_waitid -syscall sys_kill, __NR_kill -syscall sys_fcntl, __NR_fcntl -syscall sys_flock, __NR_flock -syscall sys_readlinkat, __NR_readlinkat -syscall sys_umask, __NR_umask -syscall sys_getgroups, __NR_getgroups -syscall sys_setgroups, __NR_setgroups -syscall sys_setresuid, __NR_setresuid -syscall sys_getresuid, __NR_getresuid -syscall sys_setresgid, __NR_setresgid -syscall sys_getresgid, __NR_getresgid -syscall sys_getpgid, __NR_getpgid -syscall sys_setfsuid, __NR_setfsuid -syscall sys_setfsgid, __NR_setfsgid -syscall sys_getsid, __NR_getsid -syscall sys_capget, __NR_capget -syscall sys_capset, __NR_capset -syscall sys_rt_sigqueueinfo, __NR_rt_sigqueueinfo -syscall sys_setpriority, __NR_setpriority -syscall sys_sched_setscheduler, __NR_sched_setscheduler -syscall sys_sigaltstack, __NR_sigaltstack -syscall sys_personality, __NR_personality -syscall sys_prctl, __NR_prctl -syscall sys_setrlimit, __NR_setrlimit -syscall sys_mount, __NR_mount -syscall sys_umount2, __NR_umount2 -syscall sys_gettid, __NR_gettid -syscall sys_futex, __NR_futex -syscall sys_set_tid_address, __NR_set_tid_address -syscall sys_restart_syscall, __NR_restart_syscall -syscall sys_timer_create, __NR_timer_create -syscall sys_timer_settime, __NR_timer_settime -syscall sys_timer_gettime, __NR_timer_gettime -syscall sys_timer_getoverrun, __NR_timer_getoverrun -syscall sys_timer_delete, __NR_timer_delete -syscall sys_clock_gettime, __NR_clock_gettime -syscall sys_exit_group, __NR_exit_group -syscall sys_set_robust_list, __NR_set_robust_list -syscall sys_get_robust_list, __NR_get_robust_list -syscall sys_signalfd4, __NR_signalfd4 -syscall sys_rt_tgsigqueueinfo, __NR_rt_tgsigqueueinfo -syscall sys_vmsplice, __NR_vmsplice -syscall sys_timerfd_settime, __NR_timerfd_settime -syscall sys_fanotify_init, __NR_fanotify_init -syscall sys_fanotify_mark, __NR_fanotify_mark -syscall sys_open_by_handle_at, __NR_open_by_handle_at -syscall sys_setns, __NR_setns -syscall sys_kcmp, __NR_kcmp -syscall sys_openat, __NR_openat -syscall sys_mkdirat, __NR_mkdirat -syscall sys_unlinkat, __NR_unlinkat -syscall sys_memfd_create, __NR_memfd_create -syscall sys_io_setup, __NR_io_setup -syscall sys_io_submit, __NR_io_submit -syscall sys_io_getevents, __NR_io_getevents -syscall sys_seccomp, __NR_seccomp -syscall sys_gettimeofday, __NR_gettimeofday -syscall sys_preadv_raw, __NR_preadv_raw -syscall sys_userfaultfd, __NR_userfaultfd -syscall sys_fallocate, __NR_fallocate -syscall sys_ppoll, __NR_ppoll -syscall sys_fsopen, __NR_fsopen -syscall sys_fsconfig, __NR_fsconfig -syscall sys_fsmount, __NR_fsmount -syscall sys_clone3, __NR_clone3 -syscall sys_pidfd_open, __NR_pidfd_open -syscall sys_pidfd_getfd, __NR_pidfd_getfd -syscall sys_rseq, __NR_rseq -syscall sys_move_mount, __NR_move_mount -syscall sys_open_tree, __NR_open_tree -syscall sys_openat2, __NR_openat2 -#include From ec22c38e40626123278471cc1d30ab113fa7f1dd Mon Sep 17 00:00:00 2001 From: Alexander Mikhalitsyn Date: Sun, 17 Nov 2024 18:32:03 +0000 Subject: [PATCH 2/2] compel/arch/riscv64: properly implement compel_task_size() We need to dynamically calculate TASK_SIZE depending on the MMU on RISC-V system. [We are using analogical approach on aarch64/ppc64le.] This change was tested on physical machine: StarFive VisionFive 2 isa : rv64imafdc_zicntr_zicsr_zifencei_zihpm_zca_zcd_zba_zbb mmu : sv39 uarch : sifive,u74-mc mvendorid : 0x489 marchid : 0x8000000000000007 mimpid : 0x4210427 hart isa : rv64imafdc_zicntr_zicsr_zifencei_zihpm_zca_zcd_zba_zbb Signed-off-by: Alexander Mikhalitsyn --- compel/arch/riscv64/src/lib/infect.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/compel/arch/riscv64/src/lib/infect.c b/compel/arch/riscv64/src/lib/infect.c index 01395a205a..861fe3b2f2 100644 --- a/compel/arch/riscv64/src/lib/infect.c +++ b/compel/arch/riscv64/src/lib/infect.c @@ -181,20 +181,22 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) * Task size is the maximum virtual address space size that a process can occupy in the memory * Refer to linux kernel arch/riscv/include/asm/pgtable.h, * task size is: - * - 0x9fc00000 (~2.5GB) for RV32. - * - 0x4000000000 ( 256GB) for RV64 using SV39 mmu - * - 0x800000000000 ( 128TB) for RV64 using SV48 mmu - * - * Note that PGDIR_SIZE must evenly divide TASK_SIZE since "RISC-V - * Instruction Set Manual Volume II: Privileged Architecture" states that - * "load and store effective addresses, which are 64bits, must have bits - * 63–48 all equal to bit 47, or else a page-fault exception will occur." -*/ -#define TASK_SIZE 0x800000000000UL // hardcoded for SV48 MMU + * - 0x9fc00000 (~2.5GB) for RV32. + * - 0x4000000000 ( 256GB) for RV64 using SV39 mmu + * - 0x800000000000 ( 128TB) for RV64 using SV48 mmu + * - 0x100000000000000 ( 64PB) for RV64 using SV57 mmu + */ +#define TASK_SIZE_MIN (1UL << 38) +#define TASK_SIZE_MAX (1UL << 56) unsigned long compel_task_size(void) { - return TASK_SIZE; + unsigned long task_size; + + for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size <<= 1) + if (munmap((void *)task_size, page_size())) + break; + return task_size; } /*