From ae7eb091fefc5b9c3868efb035f4de101f2e4438 Mon Sep 17 00:00:00 2001 From: Gu Zitao Date: Tue, 11 Nov 2025 16:58:00 +0800 Subject: [PATCH 1/4] sw64: fix random mmap base range Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IDDHEO -------------------------------- The original random mmap base range was incorrect, it should be 0~256M, but it was set to 0~1024G. So, fix it. Signed-off-by: Gu Zitao Reviewed-by: He Sheng --- arch/sw_64/mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sw_64/mm/mmap.c b/arch/sw_64/mm/mmap.c index 4eedb6d66633..095c55dab308 100644 --- a/arch/sw_64/mm/mmap.c +++ b/arch/sw_64/mm/mmap.c @@ -113,7 +113,7 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, unsigned long arch_mmap_rnd(void) { - unsigned long rnd = get_random_long() & 0x7fffffful; + unsigned long rnd = get_random_long() & 0x7ffful; return rnd << PAGE_SHIFT; } -- Gitee From 8fca3255e3a9685edab95a5d3eaa56bff14186a6 Mon Sep 17 00:00:00 2001 From: Mao Minkai Date: Mon, 17 Nov 2025 16:19:38 +0800 Subject: [PATCH 2/4] sw64: fix simd version of copy/clear_page() Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IDDHEO -------------------------------- Make the following changes to these two functions: - Use cache store instructions for new cpus. - Add a memb after NC store to ensure correct memory ordering. - Adjust function and instruction alignment. - Use macro PAGE_SIZE for page size. Fixes: cee00bee96ca ("sw64: optimize simd version of copy/clear_page()") Signed-off-by: Mao Minkai Reviewed-by: He Sheng Signed-off-by: Gu Zitao --- arch/sw_64/lib/clear_page_simd.S | 16 ++++++++++++---- arch/sw_64/lib/copy_page_simd.S | 15 +++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/sw_64/lib/clear_page_simd.S b/arch/sw_64/lib/clear_page_simd.S index e02d703b0bc2..d4abbb5578a9 100644 --- a/arch/sw_64/lib/clear_page_simd.S +++ b/arch/sw_64/lib/clear_page_simd.S @@ -4,21 +4,22 @@ */ #include #include +#include #ifndef CONFIG_SUBARCH_C3B -# define VSTD_CPU vstd_nc -#else # define VSTD_CPU vstd +#else +# define VSTD_CPU vstd_nc #endif .text - .align 4 + .align 5 .global clear_page .ent clear_page clear_page: .prologue 0 - ldi $1, 0x2000($16) + ldi $1, PAGE_SIZE($16) 1: VSTD_CPU $f31, 0($16) @@ -26,9 +27,16 @@ clear_page: VSTD_CPU $f31, 64($16) VSTD_CPU $f31, 96($16) addl $16, 128, $16 + .align 3 cmpeq $16, $1, $2 beq $2, 1b +#ifdef CONFIG_SUBARCH_C3B + memb +#endif + + .align 4 + nop ret .end clear_page diff --git a/arch/sw_64/lib/copy_page_simd.S b/arch/sw_64/lib/copy_page_simd.S index 36763127504a..a89cdae4f1d9 100644 --- a/arch/sw_64/lib/copy_page_simd.S +++ b/arch/sw_64/lib/copy_page_simd.S @@ -6,21 +6,22 @@ */ #include #include +#include #ifndef CONFIG_SUBARCH_C3B -# define VSTD_CPU vstd_nc -#else # define VSTD_CPU vstd +#else +# define VSTD_CPU vstd_nc #endif .text - .align 4 + .align 5 .global copy_page .ent copy_page copy_page: .prologue 0 - ldi $1, 0x2000($16) + ldi $1, PAGE_SIZE($16) subl $sp, 64, $sp bic $sp, 0x1f, $3 @@ -46,16 +47,22 @@ copy_page: addl $16, 128, $16 addl $17, 128, $17 + .align 3 cmpeq $16, $1, $2 beq $2, 1b #ifdef CONFIG_SUBARCH_C4 csrw $4, CSR_WR_FREGS #endif +#ifdef CONFIG_SUBARCH_C3B + memb +#endif vldd $f10, 0($3) addl $sp, 64, $sp + .align 4 + nop ret .end copy_page -- Gitee From e2b70f8685b9a0ecfe56c3a54c0b1db4b5548b98 Mon Sep 17 00:00:00 2001 From: Gu Yuchen Date: Thu, 20 Nov 2025 11:04:04 +0800 Subject: [PATCH 3/4] sw64: set execute permission for virtual machine's hmcode text section Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IDDHEO -------------------------------- The execute permission for the virtual machine's hmcode section is incorrectly set to non-executable before. This commit updates its permission to read and execute. Signed-off-by: Gu Yuchen Reviewed-by: He Sheng Signed-off-by: Gu Zitao --- arch/sw_64/mm/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sw_64/mm/init.c b/arch/sw_64/mm/init.c index f9055604a484..d59ab7279080 100644 --- a/arch/sw_64/mm/init.c +++ b/arch/sw_64/mm/init.c @@ -531,7 +531,7 @@ void __init paging_init(void) PAGE_KERNEL_NOEXEC, pgtable_alloc_fixmap); if (is_in_guest()) create_pgd_mapping(pgdir, sw64_guest_reset_start, __pa(sw64_guest_reset_start), sw64_guest_reset_size, - PAGE_KERNEL_NOEXEC, pgtable_alloc_fixmap); + PAGE_KERNEL_READONLY_EXEC, pgtable_alloc_fixmap); memblock_mark_nomap(__pa(sw64_reserve_start), __pa((unsigned long)_end - sw64_reserve_start)); -- Gitee From c54cc3fb7a703512b4fccb2efc2d87a38cfe6b44 Mon Sep 17 00:00:00 2001 From: Gu Yuchen Date: Wed, 26 Nov 2025 10:22:46 +0800 Subject: [PATCH 4/4] sw64: set PTBR_SYS before accessing vmalloc area Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IDDHEO -------------------------------- In commit 43c3eb78b165 ("sw64: use ioremap to map IO address in functions like __get_cpu_nums()"), some IO addresses are mapped to vmalloc area via ioremap() before being accessed. Move update_ptbr_sys() to the beginning of smp_callin() to make sure PTBR_SYS is set before accessing vmalloc area. Signed-off-by: Gu Yuchen Reviewed-by: He Sheng Signed-off-by: Gu Zitao --- arch/sw_64/kernel/smp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/sw_64/kernel/smp.c b/arch/sw_64/kernel/smp.c index eb041c38889b..cb77f4c3559c 100644 --- a/arch/sw_64/kernel/smp.c +++ b/arch/sw_64/kernel/smp.c @@ -164,6 +164,8 @@ void smp_callin(void) unsigned long __maybe_unused nmi_stack; save_ktp(); + /* update csr:ptbr */ + update_ptbr_sys(virt_to_phys(init_mm.pgd)); upshift_freq(); cpuid = smp_processor_id(); WARN_ON_ONCE(!irqs_disabled()); @@ -185,8 +187,6 @@ void smp_callin(void) /* All kernel threads share the same mm context. */ mmgrab(&init_mm); current->active_mm = &init_mm; - /* update csr:ptbr */ - update_ptbr_sys(virt_to_phys(init_mm.pgd)); #ifdef CONFIG_SUBARCH_C4 update_ptbr_usr(__pa_symbol(empty_zero_page)); #endif -- Gitee