From fbba62aff7a727723aa75715e1d1838b484ba842 Mon Sep 17 00:00:00 2001 From: Stefan Date: Sun, 1 Aug 2021 20:58:20 +0200 Subject: [PATCH] _pi_ patches for rvc * use MEMOP extension for faster memcpy (disabled atm) * don't poison init kernel area, we don't care about security * print more messages about initramfs loading, since otherwise it just looks like it got stuck Signed-off-by: Stefan --- arch/riscv/lib/memcpy.S | 13 +++++++++++++ include/linux/mm.h | 2 +- init/initramfs.c | 19 +++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/arch/riscv/lib/memcpy.S b/arch/riscv/lib/memcpy.S index 51ab716253fa..67636579413d 100644 --- a/arch/riscv/lib/memcpy.S +++ b/arch/riscv/lib/memcpy.S @@ -41,6 +41,18 @@ WEAK(memcpy) beqz a4, 4f add a3, a1, a4 3: + #lla t0, 10f + #li t2, 1025 + #bltu a2, t2, 11f + + #csrw 0x0b1, a1 # src + #csrw 0x0b2, t6 # dst + #csrw 0x0b3, a2 # n + #li t2, 0x1 + #csrw 0x0b0, t2 # memcpy + #j 10f + +11: REG_L a4, 0(a1) REG_L a5, SZREG(a1) REG_L a6, 2*SZREG(a1) @@ -76,6 +88,7 @@ WEAK(memcpy) REG_S t1, 15*SZREG(t6) addi t6, t6, 16*SZREG bltu a1, a3, 3b +10: andi a2, a2, (16*SZREG)-1 /* Update count */ 4: diff --git a/include/linux/mm.h b/include/linux/mm.h index 9afb8998e7e5..881f1c1cf7ea 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2420,7 +2420,7 @@ static inline unsigned long free_initmem_default(int poison) extern char __init_begin[], __init_end[]; return free_reserved_area(&__init_begin, &__init_end, - poison, "unused kernel"); + 0x1ff, "unused kernel"); } static inline unsigned long get_num_physpages(void) diff --git a/init/initramfs.c b/init/initramfs.c index af27abc59643..1124f0cf6c8f 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -43,8 +43,10 @@ static ssize_t __init xwrite(struct file *file, const char *p, size_t count, static __initdata char *message; static void __init error(char *x) { - if (!message) + if (!message) { message = x; + pr_err("[_pi_] initramfs error: %s\n", x); + } } static void panic_show_mem(const char *fmt, ...) @@ -467,6 +469,9 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) const char *compress_name; static __initdata char msg_buf[64]; + unsigned long len_orig = len; + unsigned long len_percent = 0, len_percent_tmp; + header_buf = kmalloc(110, GFP_KERNEL); symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL); name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL); @@ -474,11 +479,20 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) if (!header_buf || !symlink_buf || !name_buf) panic_show_mem("can't allocate buffers"); + pr_info("[_pi_] loading initramfs now, this may take a while...\n"); + state = Start; this_header = 0; message = NULL; while (!message && len) { loff_t saved_offset = this_header; + + len_percent_tmp = (len * 10) / len_orig; + if (len_percent_tmp != len_percent) { + len_percent = len_percent_tmp; + pr_info("[_pi_] initramfs: %lu0%% done\n", 10 - len_percent); + } + if (*buf == '0' && !(this_header & 3)) { state = Start; written = write_buffer(buf, len); @@ -494,7 +508,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) } this_header = 0; decompress = decompress_method(buf, len, &compress_name); - pr_debug("Detected %s compressed data\n", compress_name); + pr_info("Detected %s compressed data\n", compress_name); if (decompress) { int res = decompress(buf, len, NULL, flush_buffer, NULL, &my_inptr, error); @@ -519,6 +533,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) kfree(name_buf); kfree(symlink_buf); kfree(header_buf); + pr_info("[_pi_] unpack_to_rootfs retval: %s\n", (message && *message) ? message : ""); return message; } -- 2.32.0