From 21f655f3d917c473b99b938c6c508de1a9932088 Mon Sep 17 00:00:00 2001 From: Gu Zitao Date: Tue, 11 Nov 2025 16:58:00 +0800 Subject: [PATCH 1/4] anolis: sw64: fix random mmap base range ANBZ: #4688 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 2c4fc9eb073e294400fb7021018f50ac1b77fc9a Mon Sep 17 00:00:00 2001 From: Mao Minkai Date: Mon, 17 Nov 2025 16:19:38 +0800 Subject: [PATCH 2/4] anolis: sw64: fix simd version of copy/clear_page() ANBZ: #4688 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: 3d5b403dc70d ("anolis: 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 b6977ce7fd27ff692791a0a3c17c805b4db98ba4 Mon Sep 17 00:00:00 2001 From: Gu Yuchen Date: Thu, 20 Nov 2025 11:04:04 +0800 Subject: [PATCH 3/4] anolis: sw64: set execute permission for virtual machine's hmcode text section ANBZ: #4688 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 d484d1138481..f7a525d42fb3 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 05cc5379bbaf8258670fdcf4f25a67acb021cbe1 Mon Sep 17 00:00:00 2001 From: Gu Yuchen Date: Wed, 26 Nov 2025 10:22:46 +0800 Subject: [PATCH 4/4] anolis: sw64: set PTBR_SYS before accessing vmalloc area ANBZ: #4688 In commit 8a32d9f2c881 ("anolis: 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