From: Nick Hu <nickhu@andestech.com> To: <alankao@andestech.com>, <paul.walmsley@sifive.com>, <palmer@sifive.com>, <aou@eecs.berkeley.edu>, <green.hu@gmail.com>, <deanbo422@gmail.com>, <tglx@linutronix.de>, <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>, <aryabinin@virtuozzo.com>, <glider@google.com>, <dvyukov@google.com>, <Anup.Patel@wdc.com>, <gregkh@linuxfoundation.org>, <alexios.zavras@intel.com>, <atish.patra@wdc.com>, <zong@andestech.com>, <kasan-dev@googlegroups.com> Cc: Nick Hu <nickhu@andestech.com> Subject: [PATCH 1/2] riscv: Add memmove string operation. Date: Wed, 7 Aug 2019 15:19:14 +0800 [thread overview] Message-ID: <a6c24ce01dc40da10d58fdd30bc3e1316035c832.1565161957.git.nickhu@andestech.com> (raw) In-Reply-To: <cover.1565161957.git.nickhu@andestech.com> There are some features which need this string operation for compilation, like KASAN. So the purpose of this porting is for the features like KASAN which cannot be compiled without it. KASAN's string operations would replace the original string operations and call for the architecture defined string operations. Since we don't have this in current kernel, this patch provides the implementation. This porting refers to the 'arch/nds32/lib/memmove.S'. Signed-off-by: Nick Hu <nickhu@andestech.com> --- arch/riscv/include/asm/string.h | 3 ++ arch/riscv/kernel/riscv_ksyms.c | 1 + arch/riscv/lib/Makefile | 1 + arch/riscv/lib/memmove.S | 63 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 0 deletions(-) create mode 100644 arch/riscv/lib/memmove.S diff --git a/arch/riscv/include/asm/string.h b/arch/riscv/include/asm/string.h index 1b5d445..11210f1 100644 --- a/arch/riscv/include/asm/string.h +++ b/arch/riscv/include/asm/string.h @@ -15,4 +15,7 @@ #define __HAVE_ARCH_MEMCPY extern asmlinkage void *memcpy(void *, const void *, size_t); +#define __HAVE_ARCH_MEMMOVE +extern asmlinkage void *memmove(void *, const void *, size_t); + #endif /* _ASM_RISCV_STRING_H */ diff --git a/arch/riscv/kernel/riscv_ksyms.c b/arch/riscv/kernel/riscv_ksyms.c index 4800cf7..ffabaf1 100644 --- a/arch/riscv/kernel/riscv_ksyms.c +++ b/arch/riscv/kernel/riscv_ksyms.c @@ -14,3 +14,4 @@ EXPORT_SYMBOL(__asm_copy_from_user); EXPORT_SYMBOL(memset); EXPORT_SYMBOL(memcpy); +EXPORT_SYMBOL(memmove); diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index 8e364eb..9a4d5b3 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -2,6 +2,7 @@ lib-y += delay.o lib-y += memcpy.o lib-y += memset.o +lib-y += memmove.o lib-y += uaccess.o lib-$(CONFIG_64BIT) += tishift.o diff --git a/arch/riscv/lib/memmove.S b/arch/riscv/lib/memmove.S new file mode 100644 index 0000000..3657a06 --- /dev/null +++ b/arch/riscv/lib/memmove.S @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/linkage.h> +#include <asm/asm.h> + +ENTRY(memmove) + move t0, a0 + move t1, a1 + + beq a0, a1, exit_memcpy + beqz a2, exit_memcpy + srli t2, a2, 0x2 + + slt t3, a0, a1 + beqz t3, do_reverse + + andi a2, a2, 0x3 + li t4, 1 + beqz t2, byte_copy + +word_copy: + lw t3, 0(a1) + addi t2, t2, -1 + addi a1, a1, 4 + sw t3, 0(a0) + addi a0, a0, 4 + bnez t2, word_copy + beqz a2, exit_memcpy + j byte_copy + +do_reverse: + add a0, a0, a2 + add a1, a1, a2 + andi a2, a2, 0x3 + li t4, -1 + beqz t2, reverse_byte_copy + +reverse_word_copy: + addi a1, a1, -4 + addi t2, t2, -1 + lw t3, 0(a1) + addi a0, a0, -4 + sw t3, 0(a0) + bnez t2, reverse_word_copy + beqz a2, exit_memcpy + +reverse_byte_copy: + addi a0, a0, -1 + addi a1, a1, -1 +byte_copy: + lb t3, 0(a1) + addi a2, a2, -1 + sb t3, 0(a0) + add a1, a1, t4 + add a0, a0, t4 + bnez a2, byte_copy + +exit_memcpy: + move a0, t0 + move a1, t1 + ret + +END(memmove) -- 1.7.1
WARNING: multiple messages have this Message-ID (diff)
From: Nick Hu <nickhu@andestech.com> To: <alankao@andestech.com>, <paul.walmsley@sifive.com>, <palmer@sifive.com>, <aou@eecs.berkeley.edu>, <green.hu@gmail.com>, <deanbo422@gmail.com>, <tglx@linutronix.de>, <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>, <aryabinin@virtuozzo.com>, <glider@google.com>, <dvyukov@google.com>, <Anup.Patel@wdc.com>, <gregkh@linuxfoundation.org>, <alexios.zavras@intel.com>, <atish.patra@wdc.com>, <zong@andestech.com>, <kasan-dev@googlegroups.com> Cc: Nick Hu <nickhu@andestech.com> Subject: [PATCH 1/2] riscv: Add memmove string operation. Date: Wed, 7 Aug 2019 15:19:14 +0800 [thread overview] Message-ID: <a6c24ce01dc40da10d58fdd30bc3e1316035c832.1565161957.git.nickhu@andestech.com> (raw) In-Reply-To: <cover.1565161957.git.nickhu@andestech.com> There are some features which need this string operation for compilation, like KASAN. So the purpose of this porting is for the features like KASAN which cannot be compiled without it. KASAN's string operations would replace the original string operations and call for the architecture defined string operations. Since we don't have this in current kernel, this patch provides the implementation. This porting refers to the 'arch/nds32/lib/memmove.S'. Signed-off-by: Nick Hu <nickhu@andestech.com> --- arch/riscv/include/asm/string.h | 3 ++ arch/riscv/kernel/riscv_ksyms.c | 1 + arch/riscv/lib/Makefile | 1 + arch/riscv/lib/memmove.S | 63 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 0 deletions(-) create mode 100644 arch/riscv/lib/memmove.S diff --git a/arch/riscv/include/asm/string.h b/arch/riscv/include/asm/string.h index 1b5d445..11210f1 100644 --- a/arch/riscv/include/asm/string.h +++ b/arch/riscv/include/asm/string.h @@ -15,4 +15,7 @@ #define __HAVE_ARCH_MEMCPY extern asmlinkage void *memcpy(void *, const void *, size_t); +#define __HAVE_ARCH_MEMMOVE +extern asmlinkage void *memmove(void *, const void *, size_t); + #endif /* _ASM_RISCV_STRING_H */ diff --git a/arch/riscv/kernel/riscv_ksyms.c b/arch/riscv/kernel/riscv_ksyms.c index 4800cf7..ffabaf1 100644 --- a/arch/riscv/kernel/riscv_ksyms.c +++ b/arch/riscv/kernel/riscv_ksyms.c @@ -14,3 +14,4 @@ EXPORT_SYMBOL(__asm_copy_from_user); EXPORT_SYMBOL(memset); EXPORT_SYMBOL(memcpy); +EXPORT_SYMBOL(memmove); diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index 8e364eb..9a4d5b3 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -2,6 +2,7 @@ lib-y += delay.o lib-y += memcpy.o lib-y += memset.o +lib-y += memmove.o lib-y += uaccess.o lib-$(CONFIG_64BIT) += tishift.o diff --git a/arch/riscv/lib/memmove.S b/arch/riscv/lib/memmove.S new file mode 100644 index 0000000..3657a06 --- /dev/null +++ b/arch/riscv/lib/memmove.S @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/linkage.h> +#include <asm/asm.h> + +ENTRY(memmove) + move t0, a0 + move t1, a1 + + beq a0, a1, exit_memcpy + beqz a2, exit_memcpy + srli t2, a2, 0x2 + + slt t3, a0, a1 + beqz t3, do_reverse + + andi a2, a2, 0x3 + li t4, 1 + beqz t2, byte_copy + +word_copy: + lw t3, 0(a1) + addi t2, t2, -1 + addi a1, a1, 4 + sw t3, 0(a0) + addi a0, a0, 4 + bnez t2, word_copy + beqz a2, exit_memcpy + j byte_copy + +do_reverse: + add a0, a0, a2 + add a1, a1, a2 + andi a2, a2, 0x3 + li t4, -1 + beqz t2, reverse_byte_copy + +reverse_word_copy: + addi a1, a1, -4 + addi t2, t2, -1 + lw t3, 0(a1) + addi a0, a0, -4 + sw t3, 0(a0) + bnez t2, reverse_word_copy + beqz a2, exit_memcpy + +reverse_byte_copy: + addi a0, a0, -1 + addi a1, a1, -1 +byte_copy: + lb t3, 0(a1) + addi a2, a2, -1 + sb t3, 0(a0) + add a1, a1, t4 + add a0, a0, t4 + bnez a2, byte_copy + +exit_memcpy: + move a0, t0 + move a1, t1 + ret + +END(memmove) -- 1.7.1 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2019-08-07 7:49 UTC|newest] Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-07 7:19 [PATCH 0/2] KASAN support for RISC-V Nick Hu 2019-08-07 7:19 ` Nick Hu 2019-08-07 7:19 ` Nick Hu [this message] 2019-08-07 7:19 ` [PATCH 1/2] riscv: Add memmove string operation Nick Hu 2019-08-12 15:04 ` Christoph Hellwig 2019-08-12 15:04 ` Christoph Hellwig 2019-08-13 23:50 ` Palmer Dabbelt 2019-08-13 23:50 ` Palmer Dabbelt 2019-08-14 2:22 ` Paul Walmsley 2019-08-14 2:22 ` Paul Walmsley 2019-08-14 3:27 ` Nick Hu 2019-08-14 3:27 ` Nick Hu 2019-08-14 17:03 ` Paul Walmsley 2019-08-15 3:12 ` Nick Hu 2019-08-15 3:12 ` Nick Hu 2019-08-15 18:27 ` Paul Walmsley 2019-08-19 6:29 ` Nick Hu 2019-08-19 6:29 ` Nick Hu 2019-08-14 18:33 ` Palmer Dabbelt 2019-08-14 18:33 ` Palmer Dabbelt 2019-08-22 15:59 ` Andrey Ryabinin 2019-08-22 15:59 ` Andrey Ryabinin 2019-08-27 9:07 ` Nick Hu 2019-08-27 9:07 ` Nick Hu 2019-08-27 9:33 ` Andrey Ryabinin 2019-08-27 9:33 ` Andrey Ryabinin 2019-08-28 3:06 ` Nick Hu 2019-08-28 3:06 ` Nick Hu 2019-08-07 7:19 ` [PATCH 2/2] riscv: Add KASAN support Nick Hu 2019-08-07 7:19 ` Nick Hu 2019-08-12 15:10 ` Christoph Hellwig 2019-08-12 15:10 ` Christoph Hellwig 2019-08-14 7:44 ` Nick Hu 2019-08-14 7:44 ` Nick Hu 2019-08-22 17:08 ` Andrey Ryabinin 2019-08-22 17:08 ` Andrey Ryabinin 2019-09-03 15:08 ` Daniel Axtens 2019-09-03 15:08 ` Daniel Axtens 2019-09-04 2:24 ` Nick Hu 2019-09-04 2:24 ` Nick Hu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=a6c24ce01dc40da10d58fdd30bc3e1316035c832.1565161957.git.nickhu@andestech.com \ --to=nickhu@andestech.com \ --cc=Anup.Patel@wdc.com \ --cc=alankao@andestech.com \ --cc=alexios.zavras@intel.com \ --cc=aou@eecs.berkeley.edu \ --cc=aryabinin@virtuozzo.com \ --cc=atish.patra@wdc.com \ --cc=deanbo422@gmail.com \ --cc=dvyukov@google.com \ --cc=glider@google.com \ --cc=green.hu@gmail.com \ --cc=gregkh@linuxfoundation.org \ --cc=kasan-dev@googlegroups.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-riscv@lists.infradead.org \ --cc=palmer@sifive.com \ --cc=paul.walmsley@sifive.com \ --cc=tglx@linutronix.de \ --cc=zong@andestech.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.