From ec22c38e40626123278471cc1d30ab113fa7f1dd Mon Sep 17 00:00:00 2001 From: Alexander Mikhalitsyn Date: Sun, 17 Nov 2024 18:32:03 +0000 Subject: [PATCH] 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; } /*