From 8f0f265e6cf5b6d99a5a5d01b36985bc1131183e Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 25 Feb 2022 14:55:34 +0100 Subject: microblaze: Use simple memset implementation from lib/string.c On microblaze systems which are not using OPT_LIB_FUNCTION only simple memset is used. This function is already implemented in lib/string.c that's why it should be used instead. This change is done in respect of issue fixed by commit 33d0f96ffd73 ("lib/string.c: Use freestanding environment") where gcc-10.x moved -ftree-loop-distribute-patterns optimization is to O2 optimization level. This optimization causes GCC to convert the while loop in memset.c into a call to memset. So This optimization is transforming a loop in a memset/memcpy into a call to the function itself. This makes the memset implementation as recursive. Based on fix above -ffreestanding was used and it needs to be used on Microblaze too but the patch is not adding this flag it removes simple implementation to cause that generic implementation is used where this flag is already setup. Signed-off-by: Michal Simek Signed-off-by: Mahesh Bodapati Link: https://lore.kernel.org/r/4a143e7654f72ee893dcea9769946e17d3570b16.1645797329.git.michal.simek@xilinx.com --- arch/microblaze/include/asm/string.h | 2 ++ arch/microblaze/lib/memset.c | 20 ++------------------ 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/arch/microblaze/include/asm/string.h b/arch/microblaze/include/asm/string.h index 34071a848b6a..dbdb9eb4a733 100644 --- a/arch/microblaze/include/asm/string.h +++ b/arch/microblaze/include/asm/string.h @@ -8,7 +8,9 @@ #ifdef __KERNEL__ +#ifdef CONFIG_OPT_LIB_FUNCTION #define __HAVE_ARCH_MEMSET +#endif #define __HAVE_ARCH_MEMCPY #define __HAVE_ARCH_MEMMOVE diff --git a/arch/microblaze/lib/memset.c b/arch/microblaze/lib/memset.c index eb6c8988af02..615a2f8f53cb 100644 --- a/arch/microblaze/lib/memset.c +++ b/arch/microblaze/lib/memset.c @@ -30,22 +30,7 @@ #include #include -#ifdef __HAVE_ARCH_MEMSET -#ifndef CONFIG_OPT_LIB_FUNCTION -void *memset(void *v_src, int c, __kernel_size_t n) -{ - char *src = v_src; - - /* Truncate c to 8 bits */ - c = (c & 0xFF); - - /* Simple, byte oriented memset or the rest of count. */ - while (n--) - *src++ = c; - - return v_src; -} -#else /* CONFIG_OPT_LIB_FUNCTION */ +#ifdef CONFIG_OPT_LIB_FUNCTION void *memset(void *v_src, int c, __kernel_size_t n) { char *src = v_src; @@ -94,6 +79,5 @@ void *memset(void *v_src, int c, __kernel_size_t n) return v_src; } -#endif /* CONFIG_OPT_LIB_FUNCTION */ EXPORT_SYMBOL(memset); -#endif /* __HAVE_ARCH_MEMSET */ +#endif /* CONFIG_OPT_LIB_FUNCTION */ -- cgit v1.2.3 From 95fee37be45f443a8a322ee7f6f78167b73f2abc Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 25 Feb 2022 14:55:35 +0100 Subject: microblaze: Do loop unrolling for optimized memset implementation Align implementation with memcpy and memmove where also remaining bytes are copied via final switch case instead of using simple implementations which loop. But this alignment has much stronger reason and definitely aligning implementation is not the key point here. It is just good to have in mind that the same technique is used already there. In GCC 10, now -ftree-loop-distribute-patterns optimization is on at O2. This optimization causes GCC to convert the while loop in memset.c into a call to memset. So this optimization is transforming a loop in a memset/memcpy into a call to the function itself. This makes the memset implementation as recursive. "-freestanding" option will disable the built-in library function but it has been added in generic library implementation. In default microblaze kernel defconfig we have CONFIG_OPT_LIB_FUNCTION enabled so it will always pick optimized version of memset which is target specific so we are replacing the while() loop with switch case to avoid recursive memset call. Issue with freestanding was already discussed in connection to commit 33d0f96ffd73 ("lib/string.c: Use freestanding environment") and also this is topic in glibc and gcc. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 http://patchwork.ozlabs.org/project/glibc/patch/20191121021040.14554-1-sandra@codesourcery.com/ Signed-off-by: Michal Simek Signed-off-by: Mahesh Bodapati Link: https://lore.kernel.org/r/10a432e269a6d3349cf458e4f5792522779cba0d.1645797329.git.michal.simek@xilinx.com --- arch/microblaze/lib/memset.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/microblaze/lib/memset.c b/arch/microblaze/lib/memset.c index 615a2f8f53cb..7c2352d56bb0 100644 --- a/arch/microblaze/lib/memset.c +++ b/arch/microblaze/lib/memset.c @@ -74,8 +74,19 @@ void *memset(void *v_src, int c, __kernel_size_t n) } /* Simple, byte oriented memset or the rest of count. */ - while (n--) + switch (n) { + case 3: *src++ = c; + fallthrough; + case 2: + *src++ = c; + fallthrough; + case 1: + *src++ = c; + break; + default: + break; + } return v_src; } -- cgit v1.2.3 From 61a4e653cabd7d9e4a9e940d0786532725e73c0d Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 25 Feb 2022 14:55:36 +0100 Subject: microblaze: Use simple memmove/memcpy implementation from lib/string.c This is based on previous commit ("microblaze: Use simple memset implementation from lib/string.c") where generic memset implementation is used when OPT_LIB_FUNCTION is not defined. The same change can be done for memset/memcpy implementation where doesn't make sense to have generic implementation in architecture code. Signed-off-by: Michal Simek Link: https://lore.kernel.org/r/1f5cfc026a8a458f3e3134ab80f65bd4ac7e3e8e.1645797329.git.michal.simek@xilinx.com --- arch/microblaze/include/asm/string.h | 2 +- arch/microblaze/lib/memcpy.c | 18 ++---------------- arch/microblaze/lib/memmove.c | 29 ++--------------------------- 3 files changed, 5 insertions(+), 44 deletions(-) diff --git a/arch/microblaze/include/asm/string.h b/arch/microblaze/include/asm/string.h index dbdb9eb4a733..8798ad2c132a 100644 --- a/arch/microblaze/include/asm/string.h +++ b/arch/microblaze/include/asm/string.h @@ -10,13 +10,13 @@ #ifdef CONFIG_OPT_LIB_FUNCTION #define __HAVE_ARCH_MEMSET -#endif #define __HAVE_ARCH_MEMCPY #define __HAVE_ARCH_MEMMOVE extern void *memset(void *, int, __kernel_size_t); extern void *memcpy(void *, const void *, __kernel_size_t); extern void *memmove(void *, const void *, __kernel_size_t); +#endif #endif /* __KERNEL__ */ diff --git a/arch/microblaze/lib/memcpy.c b/arch/microblaze/lib/memcpy.c index 63041fdf916d..9966dce55619 100644 --- a/arch/microblaze/lib/memcpy.c +++ b/arch/microblaze/lib/memcpy.c @@ -31,20 +31,7 @@ #include -#ifdef __HAVE_ARCH_MEMCPY -#ifndef CONFIG_OPT_LIB_FUNCTION -void *memcpy(void *v_dst, const void *v_src, __kernel_size_t c) -{ - const char *src = v_src; - char *dst = v_dst; - - /* Simple, byte oriented memcpy. */ - while (c--) - *dst++ = *src++; - - return v_dst; -} -#else /* CONFIG_OPT_LIB_FUNCTION */ +#ifdef CONFIG_OPT_LIB_FUNCTION void *memcpy(void *v_dst, const void *v_src, __kernel_size_t c) { const char *src = v_src; @@ -188,6 +175,5 @@ void *memcpy(void *v_dst, const void *v_src, __kernel_size_t c) return v_dst; } -#endif /* CONFIG_OPT_LIB_FUNCTION */ EXPORT_SYMBOL(memcpy); -#endif /* __HAVE_ARCH_MEMCPY */ +#endif /* CONFIG_OPT_LIB_FUNCTION */ diff --git a/arch/microblaze/lib/memmove.c b/arch/microblaze/lib/memmove.c index 9862f6b1e59d..2e49d0ef1e07 100644 --- a/arch/microblaze/lib/memmove.c +++ b/arch/microblaze/lib/memmove.c @@ -30,31 +30,7 @@ #include #include -#ifdef __HAVE_ARCH_MEMMOVE -#ifndef CONFIG_OPT_LIB_FUNCTION -void *memmove(void *v_dst, const void *v_src, __kernel_size_t c) -{ - const char *src = v_src; - char *dst = v_dst; - - if (!c) - return v_dst; - - /* Use memcpy when source is higher than dest */ - if (v_dst <= v_src) - return memcpy(v_dst, v_src, c); - - /* copy backwards, from end to beginning */ - src += c; - dst += c; - - /* Simple, byte oriented memmove. */ - while (c--) - *--dst = *--src; - - return v_dst; -} -#else /* CONFIG_OPT_LIB_FUNCTION */ +#ifdef CONFIG_OPT_LIB_FUNCTION void *memmove(void *v_dst, const void *v_src, __kernel_size_t c) { const char *src = v_src; @@ -215,6 +191,5 @@ void *memmove(void *v_dst, const void *v_src, __kernel_size_t c) } return v_dst; } -#endif /* CONFIG_OPT_LIB_FUNCTION */ EXPORT_SYMBOL(memmove); -#endif /* __HAVE_ARCH_MEMMOVE */ +#endif /* CONFIG_OPT_LIB_FUNCTION */ -- cgit v1.2.3 From e4c70fc695667d115e050470375b315685ab069c Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 25 Feb 2022 14:17:30 +0100 Subject: microblaze: Wire memblock_dump_all() Wire memblock_dump_all() to be able to see the whole memblock allocation. Dumps are enabled by passing memblock=debug via kernel command line. Signed-off-by: Michal Simek Link: https://lore.kernel.org/r/6f480b6010068872f429df69c8894cc3f1f38f46.1645795048.git.michal.simek@xilinx.com --- arch/microblaze/mm/init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c index 952f35b335b2..de0d8b03af21 100644 --- a/arch/microblaze/mm/init.c +++ b/arch/microblaze/mm/init.c @@ -263,6 +263,8 @@ asmlinkage void __init mmu_init(void) /* CMA initialization */ dma_contiguous_reserve(memory_start + lowmem_size - 1); + + memblock_dump_all(); } void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask) -- cgit v1.2.3 From 68cbfae83a7208d960034813c4744bf9651a725d Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 25 Feb 2022 14:17:31 +0100 Subject: microblaze: Add support for reserved memory defined by DT In DT reserved memory nodes can be added as is described by Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt but Microblaze didn't have a support for it. The similar change was done for ARC by commit 1b10cb21d888 ("ARC: add support for reserved memory defined by device tree"). It is pretty much enough to call early_init_fdt_scan_reserved_mem(). Microblaze is not using initial_boot_params that's why there is no need to call early_init_fdt_reserve_self(). Signed-off-by: Michal Simek Link: https://lore.kernel.org/r/da4395776bf0de7207767abcc8a5df05bf411816.1645795048.git.michal.simek@xilinx.com --- arch/microblaze/mm/init.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c index de0d8b03af21..f4e503461d24 100644 --- a/arch/microblaze/mm/init.c +++ b/arch/microblaze/mm/init.c @@ -13,6 +13,7 @@ #include #include /* mem_init */ #include +#include #include #include #include @@ -261,6 +262,8 @@ asmlinkage void __init mmu_init(void) parse_early_param(); + early_init_fdt_scan_reserved_mem(); + /* CMA initialization */ dma_contiguous_reserve(memory_start + lowmem_size - 1); -- cgit v1.2.3 From 78b5f52ab6f6074a6fe2f27122e2165f32d6a143 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sat, 30 Apr 2022 21:11:15 +0200 Subject: microblaze: fix typos in comments Various spelling mistakes in comments. Detected with the help of Coccinelle. Signed-off-by: Julia Lawall Link: https://lore.kernel.org/r/20220430191122.8667-1-Julia.Lawall@inria.fr Signed-off-by: Michal Simek --- arch/microblaze/kernel/kgdb.c | 2 +- arch/microblaze/lib/memmove.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/microblaze/kernel/kgdb.c b/arch/microblaze/kernel/kgdb.c index 130cd0f064ce..df4b9d0112e5 100644 --- a/arch/microblaze/kernel/kgdb.c +++ b/arch/microblaze/kernel/kgdb.c @@ -31,7 +31,7 @@ #define GDB_RTLBLO 55 #define GDB_RTLBHI 56 -/* keep pvr separately because it is unchangeble */ +/* keep pvr separately because it is unchangeable */ static struct pvr_s pvr; void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) diff --git a/arch/microblaze/lib/memmove.c b/arch/microblaze/lib/memmove.c index 2e49d0ef1e07..c1f08c484e20 100644 --- a/arch/microblaze/lib/memmove.c +++ b/arch/microblaze/lib/memmove.c @@ -78,7 +78,7 @@ void *memmove(void *v_dst, const void *v_src, __kernel_size_t c) i_dst = (void *)dst; /* Choose a copy scheme based on the source */ - /* alignment relative to dstination. */ + /* alignment relative to destination. */ switch ((unsigned long)src & 3) { case 0x0: /* Both byte offsets are aligned */ -- cgit v1.2.3