linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 v2 07/76] ARC: [optim] uaccess __{get,put}_user() optimised
Date: Fri, 18 Jan 2013 17:54:21 +0530	[thread overview]
Message-ID: <1358511930-7424-8-git-send-email-vgupta@synopsys.com> (raw)
In-Reply-To: <1358511930-7424-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>
---
 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


  parent reply	other threads:[~2013-01-18 12:26 UTC|newest]

Thread overview: 148+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-18 12:24 [PATCH v2 00/76] Synopsys ARC Linux kernel Port Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 01/76] ARC: Generic Headers Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 02/76] ARC: irqflags - Interrupt enabling/disabling at in-core intc Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 03/76] ARC: Atomic/bitops/cmpxchg/barriers Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 04/76] asm-generic headers: uaccess.h to conditionally define segment_eq() Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 05/76] ARC: uaccess friends Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 06/76] asm-generic: uaccess: Allow arches to over-ride __{get,put}_user_fn() Vineet Gupta
2013-01-18 12:24 ` Vineet Gupta [this message]
2013-01-18 14:30   ` [PATCH v2 07/76] ARC: [optim] uaccess __{get,put}_user() optimised Arnd Bergmann
2013-01-18 12:24 ` [PATCH v2 08/76] asm-generic headers: Allow yet more arch overrides in checksum.h Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 09/76] ARC: Checksum/byteorder/swab routines Vineet Gupta
2013-01-18 14:21   ` Arnd Bergmann
2013-01-18 14:26     ` Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 10/76] ARC: Fundamental ARCH data-types/defines Vineet Gupta
2013-01-18 14:15   ` Arnd Bergmann
2013-01-19  3:25   ` Al Viro
2013-01-19 13:11     ` Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 11/76] ARC: Spinlock/rwlock/mutex primitives Vineet Gupta
2013-01-18 13:59   ` Arnd Bergmann
2013-01-18 12:24 ` [PATCH v2 12/76] ARC: String library Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 13/76] ARC: Low level IRQ/Trap/Exception Handling Vineet Gupta
2013-01-19  3:31   ` Al Viro
2013-01-19 13:48     ` Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 14/76] ARC: Interrupt Handling Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 15/76] ARC: Non-MMU Exception Handling Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 16/76] ARC: Syscall support (no-legacy-syscall ABI) Vineet Gupta
2013-01-18 13:58   ` Arnd Bergmann
2013-01-19  3:09   ` Al Viro
2013-01-19 12:56     ` Vineet Gupta
2013-01-21  6:55     ` Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 17/76] ARC: Process-creation/scheduling/idle-loop Vineet Gupta
2013-01-18 14:35   ` Arnd Bergmann
2013-01-21 11:19     ` Vineet Gupta
2013-01-21 14:21       ` Arnd Bergmann
2013-01-18 12:24 ` [PATCH v2 18/76] ARC: Timers/counters/delay management Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 19/76] ARC: Signal handling Vineet Gupta
2013-01-19  3:23   ` Al Viro
2013-01-19  3:34     ` Al Viro
2013-01-19 14:10     ` Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 20/76] ARC: [Review] Preparing to fix incorrect syscall restarts due to signals Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 21/76] ARC: [Review] Prevent incorrect syscall restarts Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 22/76] ARC: Cache Flush Management Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 23/76] ARC: Page Table Management Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 24/76] ARC: MMU Context Management Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 25/76] ARC: MMU Exception Handling Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 26/76] ARC: TLB flush Handling Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 27/76] ARC: Page Fault handling Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 28/76] ARC: I/O and DMA Mappings Vineet Gupta
2013-01-18 15:55   ` Arnd Bergmann
2013-01-18 16:01     ` Paul Mundt
2013-01-18 16:18       ` Arnd Bergmann
2013-01-21 12:38     ` Vineet Gupta
2013-01-21 14:26       ` Arnd Bergmann
2013-01-18 12:24 ` [PATCH v2 29/76] ARC: Boot #1: low-level, setup_arch(), /proc/cpuinfo, mem init Vineet Gupta
2013-01-18 14:45   ` Arnd Bergmann
2013-01-22  7:49     ` Vineet Gupta
2013-01-22  8:23       ` Arnd Bergmann
2013-01-22  8:31         ` Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 30/76] ARC: [plat-arcfpga] Static platform device for CONFIG_SERIAL_ARC Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 31/76] ARC: Build system: Makefiles, Kconfig, Linker script Vineet Gupta
2013-01-18 19:04   ` Sam Ravnborg
2013-01-18 19:25     ` Arnd Bergmann
2013-01-19 12:23     ` Vineet Gupta
2013-01-18 19:08   ` Sam Ravnborg
2013-01-19 12:26     ` Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 32/76] ARC: [DeviceTree] Basic support Vineet Gupta
2013-01-18 15:53   ` Rob Herring
2013-01-21 10:14     ` Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 33/76] ARC: [DeviceTree] Convert some Kconfig items to runtime values Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 34/76] ARC: [plat-arcfpga]: Enabling DeviceTree for Angel4 board Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 35/76] ARC: Last bits (stubs) to get to a running kernel with UART Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 36/76] ARC: Switch to generic kernel_thread() - split ret_from_fork Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 37/76] ARC: Switch to generic kernel_execve() and sys_execve() Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 38/76] ARC: Switch to saner kernel_execve() semantics #1 Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 39/76] ARC: Switch to saner kernel_execve() semantics #2 Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 40/76] ARC: Switch to generic sys_clone, fork, vfork Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 41/76] ARC: [3.8 tracking] altstack consolidation, trace_clock, cacheflush.h Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 42/76] ARC: [plat-arcfpga] defconfig Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 43/76] ARC: [optim] Cache "current" in Register r25 Vineet Gupta
2013-01-18 12:24 ` [PATCH v2 44/76] ARC: ptrace support Vineet Gupta
2013-01-18 14:48   ` Arnd Bergmann
2013-01-18 12:24 ` [PATCH v2 45/76] ARC: Futex support Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 46/76] ARC: OProfile support Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 47/76] ARC: Support for high priority interrupts in the in-core intc Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 48/76] ARC: Module support Vineet Gupta
2013-01-18 14:50   ` Arnd Bergmann
2013-01-19 11:56     ` Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 49/76] ARC: Diagnostics: show_regs() etc Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 50/76] ARC: SMP support Vineet Gupta
2013-01-18 14:53   ` Arnd Bergmann
2013-01-22  8:57     ` Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 51/76] ARC: DWARF2 .debug_frame based stack unwinder Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 52/76] ARC: stacktracing APIs based on dw2 unwinder Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 53/76] ARC: disassembly (needed by kprobes/kgdb/unaligned-access-emul) Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 54/76] ARC: kprobes support Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 55/76] sysctl: Enable PARISC "unaligned-trap" to be used cross-arch Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 56/76] ARC: Unaligned access emulation Vineet Gupta
2013-01-18 14:54   ` Arnd Bergmann
2013-01-18 12:25 ` [PATCH v2 57/76] ARC: kgdb support Vineet Gupta
2013-01-18 13:15   ` Jason Wessel
2013-01-18 13:31     ` Vineet Gupta
2013-01-18 14:25       ` Jason Wessel
2013-01-18 12:25 ` [PATCH v2 58/76] ARC: Boot #2: Verbose Boot reporting / feature verification Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 59/76] ARC: [plat-arfpga] BVCI Latency Unit setup Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 60/76] perf, ARC: Enable building perf tools for ARC Vineet Gupta
2013-01-23 11:31   ` Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 61/76] ARC: perf support (software counters only) Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 62/76] ARC: Support for single cycle Close Coupled Mem (CCM) Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 63/76] ARC: Hostlink Pseudo-Driver for Metaware Debugger Vineet Gupta
2013-01-18 14:58   ` Arnd Bergmann
2013-01-21 13:51     ` Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 64/76] ARC: Add self to MAINTAINERS Vineet Gupta
2013-01-22 13:21   ` James Hogan
2013-01-22 13:27     ` Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 65/76] ARC: UAPI Disintegrate arch/arc/include/asm Vineet Gupta
2013-01-23 11:34   ` Vineet Gupta
2013-01-23 12:50   ` David Howells
2013-01-23 13:03     ` Vineet Gupta
2013-01-24  5:46     ` Vineet Gupta
2013-01-24  9:54       ` James Hogan
2013-01-24 13:28       ` David Howells
2013-01-18 12:25 ` [PATCH v2 66/76] ARC: Add support for ioremap_prot API Vineet Gupta
2013-01-18 12:25 ` [PATCH v2 67/76] ARC: [Review] Multi-platform image #1: Kconfig enablement Vineet Gupta
2013-01-18 14:59   ` Arnd Bergmann
2013-01-18 12:25 ` [PATCH v2 68/76] ARC: Fold boards sub-menu into platform/SoC menu Vineet Gupta
2013-01-18 14:59   ` Arnd Bergmann
2013-01-18 12:25 ` [PATCH v2 69/76] ARC: [Review] Multi-platform image #2: Board callback Infrastructure Vineet Gupta
2013-01-18 15:05   ` Arnd Bergmann
2013-01-21 14:10     ` Vineet Gupta
2013-01-21 14:29       ` Arnd Bergmann
2013-01-18 12:25 ` [PATCH v2 70/76] ARC: [Review] Multi-platform image #3: switch to board callback Vineet Gupta
2013-01-18 15:05   ` Arnd Bergmann
2013-01-18 12:25 ` [PATCH v2 71/76] ARC: [Review] Multi-platform image #4: Isolate platform headers Vineet Gupta
2013-01-18 15:06   ` Arnd Bergmann
2013-01-18 12:40 ` [PATCH v2 72/76] ARC: [Review] Multi-platform image #5: NR_IRQS defined by ARC core Vineet Gupta
2013-01-18 12:40   ` [PATCH v2 73/76] ARC: [Review] Multi-platform image #6: cpu-to-dma-addr optional Vineet Gupta
2013-01-18 15:07     ` Arnd Bergmann
2013-01-18 12:40   ` [PATCH v2 74/76] ARC: [Review] Multi-platform image #7: SMP common code to use callbacks Vineet Gupta
2013-01-18 15:08     ` Arnd Bergmann
2013-01-18 12:40   ` [PATCH v2 75/76] ARC: [Review] Multi-platform image #8: platform registers SMP callbacks Vineet Gupta
2013-01-18 12:40   ` [PATCH v2 76/76] ARC: [plat-arcfpga] defconfig for fully loaded ARC Linux Vineet Gupta
2013-01-18 15:12 ` [PATCH v2 00/76] Synopsys ARC Linux kernel Port Arnd Bergmann
2013-01-24  8:54   ` Vineet Gupta
2013-01-24  9:52     ` James Hogan
2013-01-24 10:11       ` Vineet Gupta
2013-01-24 12:00         ` James Hogan
2013-01-20  6:15 ` H. Peter Anvin
2013-01-21  5:50   ` 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=1358511930-7424-8-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).