From: Vineet Gupta <Vineet.Gupta1@synopsys.com>
To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: arnd@arndb.de, Vineet Gupta <Vineet.Gupta1@synopsys.com>
Subject: [PATCH v3 08/71] ARC: [optim] uaccess __{get,put}_user() optimised
Date: Thu, 24 Jan 2013 16:35:49 +0530 [thread overview]
Message-ID: <1359025589-22277-6-git-send-email-vgupta@synopsys.com> (raw)
In-Reply-To: <1359025589-22277-1-git-send-email-vgupta@synopsys.com>
Override asm-generic implementations. We basically gain on 2 fronts
* checks for alignment no longer needed as we are only doing "unit"
sized copies.
(Careful observer could argue that While the kernel buffers are aligned,
the user buffer in theory might not be - however in that case the
user space is already broken when it tries to deref a hword/word
straddling word boundary - so we are not making it any worse).
* __copy_{to,from}_user( ) returns bytes that couldn't be copied,
whereas get_user() returns 0 for success or -EFAULT (not size). Thus
the code to do leftover bytes calculation can be avoided as well.
The savings were significant: ~17k of code.
bloat-o-meter vmlinux_uaccess_pre vmlinux_uaccess_post
add/remove: 0/4 grow/shrink: 8/118 up/down: 1262/-18758 (-17496)
^^^^^^^^^
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
---
arch/arc/include/asm/uaccess.h | 105 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 105 insertions(+), 0 deletions(-)
diff --git a/arch/arc/include/asm/uaccess.h b/arch/arc/include/asm/uaccess.h
index f13bca4..3242082 100644
--- a/arch/arc/include/asm/uaccess.h
+++ b/arch/arc/include/asm/uaccess.h
@@ -57,6 +57,111 @@
#define __access_ok(addr, sz) (unlikely(__kernel_ok) || \
likely(__user_ok((addr), (sz))))
+/*********** Single byte/hword/word copies ******************/
+
+#define __get_user_fn(sz, u, k) \
+({ \
+ long __ret = 0; /* success by default */ \
+ switch (sz) { \
+ case 1: __arc_get_user_one(*(k), u, "ldb", __ret); break; \
+ case 2: __arc_get_user_one(*(k), u, "ldw", __ret); break; \
+ case 4: __arc_get_user_one(*(k), u, "ld", __ret); break; \
+ case 8: __arc_get_user_one_64(*(k), u, __ret); break; \
+ } \
+ __ret; \
+})
+
+/*
+ * Returns 0 on success, -EFAULT if not.
+ * @ret already contains 0 - given that errors will be less likely
+ * (hence +r asm constraint below).
+ * In case of error, fixup code will make it -EFAULT
+ */
+#define __arc_get_user_one(dst, src, op, ret) \
+ __asm__ __volatile__( \
+ "1: "op" %1,[%2]\n" \
+ "2: ;nop\n" \
+ " .section .fixup, \"ax\"\n" \
+ " .align 4\n" \
+ "3: mov %0, %3\n" \
+ " j 2b\n" \
+ " .previous\n" \
+ " .section __ex_table, \"a\"\n" \
+ " .align 4\n" \
+ " .word 1b,3b\n" \
+ " .previous\n" \
+ \
+ : "+r" (ret), "=r" (dst) \
+ : "r" (src), "ir" (-EFAULT))
+
+#define __arc_get_user_one_64(dst, src, ret) \
+ __asm__ __volatile__( \
+ "1: ld %1,[%2]\n" \
+ "4: ld %R1,[%2, 4]\n" \
+ "2: ;nop\n" \
+ " .section .fixup, \"ax\"\n" \
+ " .align 4\n" \
+ "3: mov %0, %3\n" \
+ " j 2b\n" \
+ " .previous\n" \
+ " .section __ex_table, \"a\"\n" \
+ " .align 4\n" \
+ " .word 1b,3b\n" \
+ " .word 4b,3b\n" \
+ " .previous\n" \
+ \
+ : "+r" (ret), "=r" (dst) \
+ : "r" (src), "ir" (-EFAULT))
+
+#define __put_user_fn(sz, u, k) \
+({ \
+ long __ret = 0; /* success by default */ \
+ switch (sz) { \
+ case 1: __arc_put_user_one(*(k), u, "stb", __ret); break; \
+ case 2: __arc_put_user_one(*(k), u, "stw", __ret); break; \
+ case 4: __arc_put_user_one(*(k), u, "st", __ret); break; \
+ case 8: __arc_put_user_one_64(*(k), u, __ret); break; \
+ } \
+ __ret; \
+})
+
+#define __arc_put_user_one(src, dst, op, ret) \
+ __asm__ __volatile__( \
+ "1: "op" %1,[%2]\n" \
+ "2: ;nop\n" \
+ " .section .fixup, \"ax\"\n" \
+ " .align 4\n" \
+ "3: mov %0, %3\n" \
+ " j 2b\n" \
+ " .previous\n" \
+ " .section __ex_table, \"a\"\n" \
+ " .align 4\n" \
+ " .word 1b,3b\n" \
+ " .previous\n" \
+ \
+ : "+r" (ret) \
+ : "r" (src), "r" (dst), "ir" (-EFAULT))
+
+#define __arc_put_user_one_64(src, dst, ret) \
+ __asm__ __volatile__( \
+ "1: st %1,[%2]\n" \
+ "4: st %R1,[%2, 4]\n" \
+ "2: ;nop\n" \
+ " .section .fixup, \"ax\"\n" \
+ " .align 4\n" \
+ "3: mov %0, %3\n" \
+ " j 2b\n" \
+ " .previous\n" \
+ " .section __ex_table, \"a\"\n" \
+ " .align 4\n" \
+ " .word 1b,3b\n" \
+ " .word 4b,3b\n" \
+ " .previous\n" \
+ \
+ : "+r" (ret) \
+ : "r" (src), "r" (dst), "ir" (-EFAULT))
+
+
static inline unsigned long
__arc_copy_from_user(void *to, const void __user *from, unsigned long n)
{
--
1.7.4.1
next prev parent reply other threads:[~2013-01-24 11:05 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-24 11:05 [PATCH v3 00/71] Synopsys ARC Linux kernel Port (Part #2) Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 03/71] ARC: irqflags - Interrupt enabling/disabling at in-core intc Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 04/71] ARC: Atomic/bitops/cmpxchg/barriers Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 05/71] asm-generic headers: uaccess.h to conditionally define segment_eq() Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 07/71] asm-generic: uaccess: Allow arches to over-ride __{get,put}_user_fn() Vineet Gupta
2013-01-24 11:05 ` Vineet Gupta [this message]
2013-01-24 11:05 ` [PATCH v3 08/71] ARC: [optim] uaccess __{get,put}_user() optimised Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 09/71] asm-generic headers: Allow yet more arch overrides in checksum.h Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 10/71] ARC: Checksum/byteorder/swab routines Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 12/71] ARC: Spinlock/rwlock/mutex primitives Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 13/71] ARC: String library Vineet Gupta
2013-01-24 11:05 ` Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 14/71] ARC: Low level IRQ/Trap/Exception Handling Vineet Gupta
2013-01-28 7:44 ` Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 15/71] ARC: Interrupt Handling Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 16/71] ARC: Non-MMU Exception Handling Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 24/71] ARC: Page Table Management Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 25/71] ARC: MMU Context Management Vineet Gupta
2013-01-24 11:05 ` Vineet Gupta
2013-01-24 11:05 ` [PATCH v3 26/71] ARC: MMU Exception Handling Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 27/71] ARC: TLB flush Handling Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 28/71] ARC: Page Fault handling Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 31/71] ARC: [plat-arcfpga] Static platform device for CONFIG_SERIAL_ARC Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 35/71] ARC: Last bits (stubs) to get to a running kernel with UART Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 36/71] ARC: [plat-arcfpga] defconfig Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 37/71] ARC: [optim] Cache "current" in Register r25 Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 38/71] ARC: ptrace support Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 39/71] ARC: Futex support Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 40/71] ARC: OProfile support Vineet Gupta
2013-01-29 17:05 ` James Hogan
2013-01-30 6:34 ` Vineet Gupta
2013-01-30 10:54 ` James Hogan
2013-01-30 11:46 ` Vineet Gupta
2013-01-30 11:46 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 41/71] ARC: Support for high priority interrupts in the in-core intc Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 43/71] ARC: Diagnostics: show_regs() etc Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 46/71] ARC: stacktracing APIs based on dw2 unwinder Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 47/71] ARC: disassembly (needed by kprobes/kgdb/unaligned-access-emul) Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 49/71] sysctl: Enable PARISC "unaligned-trap" to be used cross-arch Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 50/71] ARC: Unaligned access emulation Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 51/71] ARC: kgdb support Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 52/71] ARC: Boot #2: Verbose Boot reporting / feature verification Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 53/71] ARC: [plat-arfpga] BVCI Latency Unit setup Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 54/71] perf, ARC: Enable building perf tools for ARC Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 55/71] ARC: perf support (software counters only) Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 56/71] ARC: Support for single cycle Close Coupled Mem (CCM) Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 60/71] ARC: [Review] Multi-platform image #1: Kconfig enablement Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 61/71] ARC: Fold boards sub-menu into platform/SoC menu Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 63/71] ARC: [Review] Multi-platform image #3: switch to board callback Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 64/71] ARC: [Review] Multi-platform image #4: Isolate platform headers Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 65/71] ARC: [Review] Multi-platform image #5: NR_IRQS defined by ARC core Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 66/71] ARC: [Review] Multi-platform image #6: cpu-to-dma-addr optional Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 67/71] ARC: [Review] Multi-platform image #7: SMP common code to use callbacks Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 68/71] ARC: [Review] Multi-platform image #8: platform registers SMP callbacks Vineet Gupta
2013-01-24 11:06 ` Vineet Gupta
2013-01-24 11:06 ` [PATCH v3 71/71] ARC: Add self to MAINTAINERS Vineet Gupta
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=1359025589-22277-6-git-send-email-vgupta@synopsys.com \
--to=vineet.gupta1@synopsys.com \
--cc=arnd@arndb.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).