1 From 7e9af733a0be196ed305ec367ea18c13525feb81 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Mon, 28 Nov 2016 16:50:04 +0000
4 Subject: [PATCH 061/454] Improve __copy_to_user and __copy_from_user
7 Provide a __copy_from_user that uses memcpy. On BCM2708, use
8 optimised memcpy/memmove/memcmp/memset implementations.
10 arch/arm: Add mmiocpy/set aliases for memcpy/set
12 See: https://github.com/raspberrypi/linux/issues/1082
14 copy_from_user: CPU_SW_DOMAIN_PAN compatibility
16 The downstream copy_from_user acceleration must also play nice with
17 CONFIG_CPU_SW_DOMAIN_PAN.
19 See: https://github.com/raspberrypi/linux/issues/1381
21 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
23 arch/arm/include/asm/string.h | 5 +
24 arch/arm/include/asm/uaccess.h | 3 +
25 arch/arm/lib/Makefile | 15 +-
26 arch/arm/lib/arm-mem.h | 159 +++++++++
27 arch/arm/lib/copy_from_user.S | 4 +-
28 arch/arm/lib/exports_rpi.c | 37 +++
29 arch/arm/lib/memcmp_rpi.S | 285 ++++++++++++++++
30 arch/arm/lib/memcpy_rpi.S | 61 ++++
31 arch/arm/lib/memcpymove.h | 506 +++++++++++++++++++++++++++++
32 arch/arm/lib/memmove_rpi.S | 61 ++++
33 arch/arm/lib/memset_rpi.S | 128 ++++++++
34 arch/arm/lib/uaccess_with_memcpy.c | 120 ++++++-
35 arch/arm/mach-bcm/Kconfig | 7 +
36 13 files changed, 1385 insertions(+), 6 deletions(-)
37 create mode 100644 arch/arm/lib/arm-mem.h
38 create mode 100644 arch/arm/lib/exports_rpi.c
39 create mode 100644 arch/arm/lib/memcmp_rpi.S
40 create mode 100644 arch/arm/lib/memcpy_rpi.S
41 create mode 100644 arch/arm/lib/memcpymove.h
42 create mode 100644 arch/arm/lib/memmove_rpi.S
43 create mode 100644 arch/arm/lib/memset_rpi.S
45 --- a/arch/arm/include/asm/string.h
46 +++ b/arch/arm/include/asm/string.h
47 @@ -39,6 +39,11 @@ static inline void *memset64(uint64_t *p
48 return __memset64(p, v, n * 8, v >> 32);
51 +#ifdef CONFIG_BCM2835_FAST_MEMCPY
52 +#define __HAVE_ARCH_MEMCMP
53 +extern int memcmp(const void *, const void *, size_t);
56 extern void __memzero(void *ptr, __kernel_size_t n);
58 #define memset(p,v,n) \
59 --- a/arch/arm/include/asm/uaccess.h
60 +++ b/arch/arm/include/asm/uaccess.h
61 @@ -514,6 +514,9 @@ do { \
62 extern unsigned long __must_check
63 arm_copy_from_user(void *to, const void __user *from, unsigned long n);
65 +extern unsigned long __must_check
66 +__copy_from_user_std(void *to, const void __user *from, unsigned long n);
68 static inline unsigned long __must_check
69 raw_copy_from_user(void *to, const void __user *from, unsigned long n)
71 --- a/arch/arm/lib/Makefile
72 +++ b/arch/arm/lib/Makefile
75 lib-y := backtrace.o changebit.o csumipv6.o csumpartial.o \
76 csumpartialcopy.o csumpartialcopyuser.o clearbit.o \
77 - delay.o delay-loop.o findbit.o memchr.o memcpy.o \
78 - memmove.o memset.o memzero.o setbit.o \
79 - strchr.o strrchr.o \
80 + delay.o delay-loop.o findbit.o memchr.o memzero.o \
81 + setbit.o strchr.o strrchr.o \
82 testchangebit.o testclearbit.o testsetbit.o \
83 ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \
84 ucmpdi2.o lib1funcs.o div64.o \
85 @@ -19,6 +18,16 @@ lib-y := backtrace.o changebit.o csumip
86 mmu-y := clear_user.o copy_page.o getuser.o putuser.o \
87 copy_from_user.o copy_to_user.o
89 +# Choose optimised implementations for Raspberry Pi
90 +ifeq ($(CONFIG_BCM2835_FAST_MEMCPY),y)
91 + CFLAGS_uaccess_with_memcpy.o += -DCOPY_FROM_USER_THRESHOLD=1600
92 + CFLAGS_uaccess_with_memcpy.o += -DCOPY_TO_USER_THRESHOLD=672
93 + obj-$(CONFIG_MODULES) += exports_rpi.o
94 + lib-y += memcpy_rpi.o memmove_rpi.o memset_rpi.o memcmp_rpi.o
96 + lib-y += memcpy.o memmove.o memset.o
99 # using lib_ here won't override already available weak symbols
100 obj-$(CONFIG_UACCESS_WITH_MEMCPY) += uaccess_with_memcpy.o
103 +++ b/arch/arm/lib/arm-mem.h
106 +Copyright (c) 2013, Raspberry Pi Foundation
107 +Copyright (c) 2013, RISC OS Open Ltd
108 +All rights reserved.
110 +Redistribution and use in source and binary forms, with or without
111 +modification, are permitted provided that the following conditions are met:
112 + * Redistributions of source code must retain the above copyright
113 + notice, this list of conditions and the following disclaimer.
114 + * Redistributions in binary form must reproduce the above copyright
115 + notice, this list of conditions and the following disclaimer in the
116 + documentation and/or other materials provided with the distribution.
117 + * Neither the name of the copyright holder nor the
118 + names of its contributors may be used to endorse or promote products
119 + derived from this software without specific prior written permission.
121 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
122 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
123 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
124 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
125 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
126 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
127 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
128 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
129 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
130 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139 +.macro preload_leading_step1 backwards, ptr, base
140 +/* If the destination is already 16-byte aligned, then we need to preload
141 + * between 0 and prefetch_distance (inclusive) cache lines ahead so there
142 + * are no gaps when the inner loop starts.
151 + .rept prefetch_distance+1
154 + .set OFFSET, OFFSET-32
156 + .set OFFSET, OFFSET+32
161 +.macro preload_leading_step2 backwards, ptr, base, leading_bytes, tmp
162 +/* However, if the destination is not 16-byte aligned, we may need to
163 + * preload one more cache line than that. The question we need to ask is:
164 + * are the leading bytes more than the amount by which the source
165 + * pointer will be rounded down for preloading, and if so, by how many
169 +/* Here we compare against how many bytes we are into the
170 + * cache line, counting down from the highest such address.
171 + * Effectively, we want to calculate
172 + * leading_bytes = dst&15
173 + * cacheline_offset = 31-((src-leading_bytes-1)&31)
174 + * extra_needed = leading_bytes - cacheline_offset
175 + * and test if extra_needed is <= 0, or rearranging:
176 + * leading_bytes + (src-leading_bytes-1)&31 <= 31
178 + mov tmp, base, lsl #32-5
179 + sbc tmp, tmp, leading_bytes, lsl #32-5
180 + adds tmp, tmp, leading_bytes, lsl #32-5
182 + pld [ptr, #-32*(prefetch_distance+1)]
184 +/* Effectively, we want to calculate
185 + * leading_bytes = (-dst)&15
186 + * cacheline_offset = (src+leading_bytes)&31
187 + * extra_needed = leading_bytes - cacheline_offset
188 + * and test if extra_needed is <= 0.
190 + mov tmp, base, lsl #32-5
191 + add tmp, tmp, leading_bytes, lsl #32-5
192 + rsbs tmp, tmp, leading_bytes, lsl #32-5
194 + pld [ptr, #32*(prefetch_distance+1)]
199 +.macro preload_trailing backwards, base, remain, tmp
200 + /* We need either 0, 1 or 2 extra preloads */
203 + mov tmp, tmp, lsl #32-5
205 + mov tmp, base, lsl #32-5
207 + adds tmp, tmp, remain, lsl #32-5
208 + adceqs tmp, tmp, #0
209 + /* The instruction above has two effects: ensures Z is only
210 + * set if C was clear (so Z indicates that both shifted quantities
211 + * were 0), and clears C if Z was set (so C indicates that the sum
212 + * of the shifted quantities was greater and not equal to 32) */
222 + pld [tmp, #-32*(prefetch_distance+1)]
224 + pld [tmp, #-32*prefetch_distance]
226 + pld [tmp, #32*(prefetch_distance+2)]
228 + pld [tmp, #32*(prefetch_distance+1)]
233 +.macro preload_all backwards, narrow_case, shift, base, remain, tmp0, tmp1
236 + bic tmp0, tmp0, #31
238 + sub tmp1, base, remain, lsl #shift
240 + bic tmp0, base, #31
242 + add tmp1, base, remain, lsl #shift
245 + bic tmp1, tmp1, #31
249 + /* In this case, all the data fits in either 1 or 2 cache lines */
254 + sub tmp0, tmp0, #32
256 + add tmp0, tmp0, #32
264 --- a/arch/arm/lib/copy_from_user.S
265 +++ b/arch/arm/lib/copy_from_user.S
270 -ENTRY(arm_copy_from_user)
271 +ENTRY(__copy_from_user_std)
272 +WEAK(arm_copy_from_user)
273 #ifdef CONFIG_CPU_SPECTRE
275 ldr r3, [r3, #TI_ADDR_LIMIT]
276 @@ -99,6 +100,7 @@ ENTRY(arm_copy_from_user)
277 #include "copy_template.S"
279 ENDPROC(arm_copy_from_user)
280 +ENDPROC(__copy_from_user_std)
282 .pushsection .fixup,"ax"
285 +++ b/arch/arm/lib/exports_rpi.c
288 + * Copyright (c) 2014, Raspberry Pi (Trading) Ltd.
290 + * Redistribution and use in source and binary forms, with or without
291 + * modification, are permitted provided that the following conditions
293 + * 1. Redistributions of source code must retain the above copyright
294 + * notice, this list of conditions, and the following disclaimer,
295 + * without modification.
296 + * 2. Redistributions in binary form must reproduce the above copyright
297 + * notice, this list of conditions and the following disclaimer in the
298 + * documentation and/or other materials provided with the distribution.
299 + * 3. The names of the above-listed copyright holders may not be used
300 + * to endorse or promote products derived from this software without
301 + * specific prior written permission.
303 + * ALTERNATIVELY, this software may be distributed under the terms of the
304 + * GNU General Public License ("GPL") version 2, as published by the Free
305 + * Software Foundation.
307 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
308 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
309 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
310 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
311 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
312 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
313 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
314 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
315 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
316 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
317 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
320 +#include <linux/kernel.h>
321 +#include <linux/module.h>
323 +EXPORT_SYMBOL(memcmp);
325 +++ b/arch/arm/lib/memcmp_rpi.S
328 +Copyright (c) 2013, Raspberry Pi Foundation
329 +Copyright (c) 2013, RISC OS Open Ltd
330 +All rights reserved.
332 +Redistribution and use in source and binary forms, with or without
333 +modification, are permitted provided that the following conditions are met:
334 + * Redistributions of source code must retain the above copyright
335 + notice, this list of conditions and the following disclaimer.
336 + * Redistributions in binary form must reproduce the above copyright
337 + notice, this list of conditions and the following disclaimer in the
338 + documentation and/or other materials provided with the distribution.
339 + * Neither the name of the copyright holder nor the
340 + names of its contributors may be used to endorse or promote products
341 + derived from this software without specific prior written permission.
343 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
344 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
345 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
346 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
347 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
348 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
349 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
350 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
351 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
352 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
355 +#include <linux/linkage.h>
356 +#include "arm-mem.h"
358 +/* Prevent the stack from becoming executable */
359 +#if defined(__linux__) && defined(__ELF__)
360 +.section .note.GNU-stack,"",%progbits
370 +.macro memcmp_process_head unaligned
372 + ldr DAT0, [S_1], #4
373 + ldr DAT1, [S_1], #4
374 + ldr DAT2, [S_1], #4
375 + ldr DAT3, [S_1], #4
377 + ldmia S_1!, {DAT0, DAT1, DAT2, DAT3}
379 + ldmia S_2!, {DAT4, DAT5, DAT6, DAT7}
382 +.macro memcmp_process_tail
390 +.macro memcmp_leading_31bytes
391 + movs DAT0, OFF, lsl #31
392 + ldrmib DAT0, [S_1], #1
393 + ldrcsh DAT1, [S_1], #2
394 + ldrmib DAT4, [S_2], #1
395 + ldrcsh DAT5, [S_2], #2
405 + movs DAT0, OFF, lsl #29
406 + ldrmi DAT0, [S_1], #4
407 + ldrcs DAT1, [S_1], #4
408 + ldrcs DAT2, [S_1], #4
409 + ldrmi DAT4, [S_2], #4
410 + ldmcsia S_2!, {DAT5, DAT6}
425 + memcmp_process_head 1
427 + memcmp_process_tail
431 +.macro memcmp_trailing_15bytes unaligned
434 + ldrcs DAT0, [S_1], #4
435 + ldrcs DAT1, [S_1], #4
437 + ldmcsia S_1!, {DAT0, DAT1}
439 + ldrmi DAT2, [S_1], #4
440 + ldmcsia S_2!, {DAT4, DAT5}
441 + ldrmi DAT6, [S_2], #4
453 + ldrcsh DAT0, [S_1], #2
455 + ldrcsh DAT4, [S_2], #2
466 +.macro memcmp_long_inner_loop unaligned
468 + memcmp_process_head unaligned
469 + pld [S_2, #prefetch_distance*32 + 16]
470 + memcmp_process_tail
471 + memcmp_process_head unaligned
473 + memcmp_process_tail
476 + /* Just before the final (prefetch_distance+1) 32-byte blocks,
477 + * deal with final preloads */
478 + preload_trailing 0, S_1, N, DAT0
479 + preload_trailing 0, S_2, N, DAT0
480 + add N, N, #(prefetch_distance+2)*32 - 16
482 + memcmp_process_head unaligned
483 + memcmp_process_tail
486 + /* Trailing words and bytes */
489 + memcmp_trailing_15bytes unaligned
490 +199: /* Reached end without detecting a difference */
493 + pop {DAT1-DAT6, pc}
496 +.macro memcmp_short_inner_loop unaligned
497 + subs N, N, #16 /* simplifies inner loop termination */
500 + memcmp_process_head unaligned
501 + memcmp_process_tail
504 +122: /* Trailing words and bytes */
507 + memcmp_trailing_15bytes unaligned
508 +199: /* Reached end without detecting a difference */
511 + pop {DAT1-DAT6, pc}
515 + * int memcmp(const void *s1, const void *s2, size_t n);
517 + * a1 = pointer to buffer 1
518 + * a2 = pointer to buffer 2
519 + * a3 = number of bytes to compare (as unsigned chars)
521 + * a1 = >0/=0/<0 if s1 >/=/< s2
524 +.set prefetch_distance, 2
540 + push {DAT1-DAT6, lr}
541 + setend be /* lowest-addressed bytes are most significant */
543 + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
544 + cmp N, #(prefetch_distance+3)*32 - 1
548 + /* Adjust N so that the decrement instruction can also test for
549 + * inner loop termination. We want it to stop when there are
550 + * (prefetch_distance+1) complete blocks to go. */
551 + sub N, N, #(prefetch_distance+2)*32
552 + preload_leading_step1 0, DAT0, S_1
553 + preload_leading_step1 0, DAT1, S_2
556 + rsb OFF, S_2, #0 /* no need to AND with 15 here */
557 + preload_leading_step2 0, DAT0, S_1, OFF, DAT2
558 + preload_leading_step2 0, DAT1, S_2, OFF, DAT2
559 + memcmp_leading_31bytes
560 +154: /* Second source now cacheline (32-byte) aligned; we have at
561 + * least one prefetch to go. */
562 + /* Prefetch offset is best selected such that it lies in the
563 + * first 8 of each 32 bytes - but it's just as easy to aim for
566 + rsb OFF, OFF, #32*prefetch_distance
569 + memcmp_long_inner_loop 0
570 +140: memcmp_long_inner_loop 1
572 +170: /* Short case */
575 + preload_all 0, 0, 0, S_1, N, DAT0, DAT1
576 + preload_all 0, 0, 0, S_2, N, DAT0, DAT1
581 + ldrb DAT0, [S_1], #1
582 + ldrb DAT4, [S_2], #1
587 +174: /* Second source now 4-byte aligned; we have 0 or more bytes to go */
590 + memcmp_short_inner_loop 0
591 +140: memcmp_short_inner_loop 1
593 +200: /* Difference found: determine sign. */
597 + pop {DAT1-DAT6, pc}
613 +++ b/arch/arm/lib/memcpy_rpi.S
616 +Copyright (c) 2013, Raspberry Pi Foundation
617 +Copyright (c) 2013, RISC OS Open Ltd
618 +All rights reserved.
620 +Redistribution and use in source and binary forms, with or without
621 +modification, are permitted provided that the following conditions are met:
622 + * Redistributions of source code must retain the above copyright
623 + notice, this list of conditions and the following disclaimer.
624 + * Redistributions in binary form must reproduce the above copyright
625 + notice, this list of conditions and the following disclaimer in the
626 + documentation and/or other materials provided with the distribution.
627 + * Neither the name of the copyright holder nor the
628 + names of its contributors may be used to endorse or promote products
629 + derived from this software without specific prior written permission.
631 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
632 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
633 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
634 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
635 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
636 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
637 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
638 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
639 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
640 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
643 +#include <linux/linkage.h>
644 +#include "arm-mem.h"
645 +#include "memcpymove.h"
647 +/* Prevent the stack from becoming executable */
648 +#if defined(__linux__) && defined(__ELF__)
649 +.section .note.GNU-stack,"",%progbits
660 + * void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
662 + * a1 = pointer to destination
663 + * a2 = pointer to source
664 + * a3 = number of bytes to copy
669 +.set prefetch_distance, 3
677 +++ b/arch/arm/lib/memcpymove.h
680 +Copyright (c) 2013, Raspberry Pi Foundation
681 +Copyright (c) 2013, RISC OS Open Ltd
682 +All rights reserved.
684 +Redistribution and use in source and binary forms, with or without
685 +modification, are permitted provided that the following conditions are met:
686 + * Redistributions of source code must retain the above copyright
687 + notice, this list of conditions and the following disclaimer.
688 + * Redistributions in binary form must reproduce the above copyright
689 + notice, this list of conditions and the following disclaimer in the
690 + documentation and/or other materials provided with the distribution.
691 + * Neither the name of the copyright holder nor the
692 + names of its contributors may be used to endorse or promote products
693 + derived from this software without specific prior written permission.
695 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
696 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
697 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
698 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
699 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
700 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
701 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
702 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
703 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
704 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
707 +.macro unaligned_words backwards, align, use_pld, words, r0, r1, r2, r3, r4, r5, r6, r7, r8
710 + mov r1, r0, lsl #32-align*8
712 + orr r1, r1, r0, lsr #align*8
715 + mov r0, r1, lsr #align*8
717 + orr r0, r0, r1, lsl #32-align*8
723 + mov r2, r0, lsl #32-align*8
725 + orr r2, r2, r1, lsr #align*8
726 + mov r1, r1, lsl #32-align*8
727 + orr r1, r1, r0, lsr #align*8
731 + mov r0, r2, lsr #align*8
733 + orr r0, r0, r1, lsl #32-align*8
734 + mov r1, r1, lsr #align*8
735 + orr r1, r1, r2, lsl #32-align*8
741 + mov r4, r0, lsl #32-align*8
743 + orr r4, r4, r3, lsr #align*8
744 + mov r3, r3, lsl #32-align*8
745 + orr r3, r3, r2, lsr #align*8
746 + mov r2, r2, lsl #32-align*8
747 + orr r2, r2, r1, lsr #align*8
748 + mov r1, r1, lsl #32-align*8
749 + orr r1, r1, r0, lsr #align*8
750 + stmdb D!, {r1, r2, r3, r4}
753 + mov r0, r4, lsr #align*8
755 + orr r0, r0, r1, lsl #32-align*8
756 + mov r1, r1, lsr #align*8
757 + orr r1, r1, r2, lsl #32-align*8
758 + mov r2, r2, lsr #align*8
759 + orr r2, r2, r3, lsl #32-align*8
760 + mov r3, r3, lsr #align*8
761 + orr r3, r3, r4, lsl #32-align*8
762 + stmia D!, {r0, r1, r2, r3}
766 + ldmdb S!, {r4, r5, r6, r7}
767 + mov r8, r0, lsl #32-align*8
768 + ldmdb S!, {r0, r1, r2, r3}
772 + orr r8, r8, r7, lsr #align*8
773 + mov r7, r7, lsl #32-align*8
774 + orr r7, r7, r6, lsr #align*8
775 + mov r6, r6, lsl #32-align*8
776 + orr r6, r6, r5, lsr #align*8
777 + mov r5, r5, lsl #32-align*8
778 + orr r5, r5, r4, lsr #align*8
779 + mov r4, r4, lsl #32-align*8
780 + orr r4, r4, r3, lsr #align*8
781 + mov r3, r3, lsl #32-align*8
782 + orr r3, r3, r2, lsr #align*8
783 + mov r2, r2, lsl #32-align*8
784 + orr r2, r2, r1, lsr #align*8
785 + mov r1, r1, lsl #32-align*8
786 + orr r1, r1, r0, lsr #align*8
787 + stmdb D!, {r5, r6, r7, r8}
788 + stmdb D!, {r1, r2, r3, r4}
790 + ldmib S!, {r1, r2, r3, r4}
791 + mov r0, r8, lsr #align*8
792 + ldmib S!, {r5, r6, r7, r8}
796 + orr r0, r0, r1, lsl #32-align*8
797 + mov r1, r1, lsr #align*8
798 + orr r1, r1, r2, lsl #32-align*8
799 + mov r2, r2, lsr #align*8
800 + orr r2, r2, r3, lsl #32-align*8
801 + mov r3, r3, lsr #align*8
802 + orr r3, r3, r4, lsl #32-align*8
803 + mov r4, r4, lsr #align*8
804 + orr r4, r4, r5, lsl #32-align*8
805 + mov r5, r5, lsr #align*8
806 + orr r5, r5, r6, lsl #32-align*8
807 + mov r6, r6, lsr #align*8
808 + orr r6, r6, r7, lsl #32-align*8
809 + mov r7, r7, lsr #align*8
810 + orr r7, r7, r8, lsl #32-align*8
811 + stmia D!, {r0, r1, r2, r3}
812 + stmia D!, {r4, r5, r6, r7}
817 +.macro memcpy_leading_15bytes backwards, align
818 + movs DAT1, DAT2, lsl #31
821 + ldrmib DAT0, [S, #-1]!
822 + ldrcsh DAT1, [S, #-2]!
823 + strmib DAT0, [D, #-1]!
824 + strcsh DAT1, [D, #-2]!
826 + ldrmib DAT0, [S], #1
827 + ldrcsh DAT1, [S], #2
828 + strmib DAT0, [D], #1
829 + strcsh DAT1, [D], #2
831 + movs DAT1, DAT2, lsl #29
833 + ldrmi DAT0, [S, #-4]!
835 + ldmcsdb S!, {DAT1, DAT2}
837 + ldrcs DAT2, [S, #-4]!
838 + ldrcs DAT1, [S, #-4]!
840 + strmi DAT0, [D, #-4]!
841 + stmcsdb D!, {DAT1, DAT2}
843 + ldrmi DAT0, [S], #4
845 + ldmcsia S!, {DAT1, DAT2}
847 + ldrcs DAT1, [S], #4
848 + ldrcs DAT2, [S], #4
850 + strmi DAT0, [D], #4
851 + stmcsia D!, {DAT1, DAT2}
855 +.macro memcpy_trailing_15bytes backwards, align
859 + ldmcsdb S!, {DAT0, DAT1}
861 + ldrcs DAT1, [S, #-4]!
862 + ldrcs DAT0, [S, #-4]!
864 + ldrmi DAT2, [S, #-4]!
865 + stmcsdb D!, {DAT0, DAT1}
866 + strmi DAT2, [D, #-4]!
869 + ldmcsia S!, {DAT0, DAT1}
871 + ldrcs DAT0, [S], #4
872 + ldrcs DAT1, [S], #4
874 + ldrmi DAT2, [S], #4
875 + stmcsia D!, {DAT0, DAT1}
876 + strmi DAT2, [D], #4
880 + ldrcsh DAT0, [S, #-2]!
881 + ldrmib DAT1, [S, #-1]
882 + strcsh DAT0, [D, #-2]!
883 + strmib DAT1, [D, #-1]
885 + ldrcsh DAT0, [S], #2
887 + strcsh DAT0, [D], #2
892 +.macro memcpy_long_inner_loop backwards, align
895 + ldr DAT0, [S, #-align]!
897 + ldr LAST, [S, #-align]!
903 + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
905 + stmdb D!, {DAT4, DAT5, DAT6, LAST}
906 + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
908 + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
910 + stmia D!, {DAT0, DAT1, DAT2, DAT3}
911 + stmia D!, {DAT4, DAT5, DAT6, LAST}
914 + unaligned_words backwards, align, 1, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
918 + /* Just before the final (prefetch_distance+1) 32-byte blocks, deal with final preloads */
919 + preload_trailing backwards, S, N, OFF
920 + add N, N, #(prefetch_distance+2)*32 - 32
924 + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
925 + stmdb D!, {DAT4, DAT5, DAT6, LAST}
926 + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
928 + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
929 + stmia D!, {DAT0, DAT1, DAT2, DAT3}
930 + stmia D!, {DAT4, DAT5, DAT6, LAST}
933 + unaligned_words backwards, align, 0, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
940 + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
941 + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
943 + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
944 + stmneia D!, {DAT0, DAT1, DAT2, LAST}
948 + unaligned_words backwards, align, 0, 4, DAT0, DAT1, DAT2, DAT3, LAST
951 + /* Trailing words and bytes */
957 + memcpy_trailing_15bytes backwards, align
959 + pop {DAT3, DAT4, DAT5, DAT6, DAT7}
960 + pop {D, DAT1, DAT2, pc}
963 +.macro memcpy_medium_inner_loop backwards, align
967 + ldmdb S!, {DAT0, DAT1, DAT2, LAST}
969 + ldr LAST, [S, #-4]!
970 + ldr DAT2, [S, #-4]!
971 + ldr DAT1, [S, #-4]!
972 + ldr DAT0, [S, #-4]!
974 + stmdb D!, {DAT0, DAT1, DAT2, LAST}
977 + ldmia S!, {DAT0, DAT1, DAT2, LAST}
984 + stmia D!, {DAT0, DAT1, DAT2, LAST}
988 + /* Trailing words and bytes */
991 + memcpy_trailing_15bytes backwards, align
993 + pop {D, DAT1, DAT2, pc}
996 +.macro memcpy_short_inner_loop backwards, align
1000 + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
1002 + ldrne LAST, [S, #-4]!
1003 + ldrne DAT2, [S, #-4]!
1004 + ldrne DAT1, [S, #-4]!
1005 + ldrne DAT0, [S, #-4]!
1007 + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
1010 + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
1012 + ldrne DAT0, [S], #4
1013 + ldrne DAT1, [S], #4
1014 + ldrne DAT2, [S], #4
1015 + ldrne LAST, [S], #4
1017 + stmneia D!, {DAT0, DAT1, DAT2, LAST}
1019 + memcpy_trailing_15bytes backwards, align
1021 + pop {D, DAT1, DAT2, pc}
1024 +.macro memcpy backwards
1041 + push {D, DAT1, DAT2, lr}
1043 + .cfi_def_cfa_offset 16
1044 + .cfi_rel_offset D, 0
1047 + .cfi_undefined DAT0
1048 + .cfi_rel_offset DAT1, 4
1049 + .cfi_rel_offset DAT2, 8
1050 + .cfi_undefined LAST
1051 + .cfi_rel_offset lr, 12
1058 + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
1061 + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
1062 + cmp N, #(prefetch_distance+3)*32 - 1
1066 + push {DAT3, DAT4, DAT5, DAT6, DAT7}
1068 + .cfi_def_cfa_offset 36
1069 + .cfi_rel_offset D, 20
1070 + .cfi_rel_offset DAT1, 24
1071 + .cfi_rel_offset DAT2, 28
1072 + .cfi_rel_offset DAT3, 0
1073 + .cfi_rel_offset DAT4, 4
1074 + .cfi_rel_offset DAT5, 8
1075 + .cfi_rel_offset DAT6, 12
1076 + .cfi_rel_offset DAT7, 16
1077 + .cfi_rel_offset lr, 32
1079 + /* Adjust N so that the decrement instruction can also test for
1080 + * inner loop termination. We want it to stop when there are
1081 + * (prefetch_distance+1) complete blocks to go. */
1082 + sub N, N, #(prefetch_distance+2)*32
1083 + preload_leading_step1 backwards, DAT0, S
1085 + /* Bug in GAS: it accepts, but mis-assembles the instruction
1086 + * ands DAT2, D, #60, 2
1087 + * which sets DAT2 to the number of leading bytes until destination is aligned and also clears C (sets borrow)
1094 + rsb DAT2, DAT2, #16 /* number of leading bytes until destination aligned */
1096 + preload_leading_step2 backwards, DAT0, S, DAT2, OFF
1097 + memcpy_leading_15bytes backwards, 1
1098 +154: /* Destination now 16-byte aligned; we have at least one prefetch as well as at least one 16-byte output block */
1099 + /* Prefetch offset is best selected such that it lies in the first 8 of each 32 bytes - but it's just as easy to aim for the first one */
1103 + sub OFF, OFF, #32*(prefetch_distance+1)
1106 + rsb OFF, OFF, #32*prefetch_distance
1108 + movs DAT0, S, lsl #31
1112 + memcpy_long_inner_loop backwards, 0
1113 +155: memcpy_long_inner_loop backwards, 1
1114 +156: memcpy_long_inner_loop backwards, 2
1115 +157: memcpy_long_inner_loop backwards, 3
1117 + .cfi_def_cfa_offset 16
1118 + .cfi_rel_offset D, 0
1119 + .cfi_rel_offset DAT1, 4
1120 + .cfi_rel_offset DAT2, 8
1121 + .cfi_same_value DAT3
1122 + .cfi_same_value DAT4
1123 + .cfi_same_value DAT5
1124 + .cfi_same_value DAT6
1125 + .cfi_same_value DAT7
1126 + .cfi_rel_offset lr, 12
1128 +160: /* Medium case */
1129 + preload_all backwards, 0, 0, S, N, DAT2, OFF
1130 + sub N, N, #16 /* simplifies inner loop termination */
1137 + rsb DAT2, DAT2, #16
1139 + memcpy_leading_15bytes backwards, align
1140 +164: /* Destination now 16-byte aligned; we have at least one 16-byte output block */
1143 + memcpy_medium_inner_loop backwards, 0
1144 +140: memcpy_medium_inner_loop backwards, 1
1146 +170: /* Short case, less than 31 bytes, so no guarantee of at least one 16-byte block */
1149 + preload_all backwards, 1, 0, S, N, DAT2, LAST
1155 + ldrb DAT0, [S, #-1]!
1156 + strb DAT0, [D, #-1]!
1158 + ldrb DAT0, [S], #1
1159 + strb DAT0, [D], #1
1163 +174: /* Destination now 4-byte aligned; we have 0 or more output bytes to go */
1166 + memcpy_short_inner_loop backwards, 0
1167 +140: memcpy_short_inner_loop backwards, 1
1186 +++ b/arch/arm/lib/memmove_rpi.S
1189 +Copyright (c) 2013, Raspberry Pi Foundation
1190 +Copyright (c) 2013, RISC OS Open Ltd
1191 +All rights reserved.
1193 +Redistribution and use in source and binary forms, with or without
1194 +modification, are permitted provided that the following conditions are met:
1195 + * Redistributions of source code must retain the above copyright
1196 + notice, this list of conditions and the following disclaimer.
1197 + * Redistributions in binary form must reproduce the above copyright
1198 + notice, this list of conditions and the following disclaimer in the
1199 + documentation and/or other materials provided with the distribution.
1200 + * Neither the name of the copyright holder nor the
1201 + names of its contributors may be used to endorse or promote products
1202 + derived from this software without specific prior written permission.
1204 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1205 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1206 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1207 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
1208 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1209 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1210 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1211 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1212 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1213 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1216 +#include <linux/linkage.h>
1217 +#include "arm-mem.h"
1218 +#include "memcpymove.h"
1220 +/* Prevent the stack from becoming executable */
1221 +#if defined(__linux__) && defined(__ELF__)
1222 +.section .note.GNU-stack,"",%progbits
1227 + .object_arch armv4
1233 + * void *memmove(void *s1, const void *s2, size_t n);
1235 + * a1 = pointer to destination
1236 + * a2 = pointer to source
1237 + * a3 = number of bytes to copy
1242 +.set prefetch_distance, 3
1246 + bpl memcpy /* pl works even over -1 - 0 and 0x7fffffff - 0x80000000 boundaries */
1250 +++ b/arch/arm/lib/memset_rpi.S
1253 +Copyright (c) 2013, Raspberry Pi Foundation
1254 +Copyright (c) 2013, RISC OS Open Ltd
1255 +All rights reserved.
1257 +Redistribution and use in source and binary forms, with or without
1258 +modification, are permitted provided that the following conditions are met:
1259 + * Redistributions of source code must retain the above copyright
1260 + notice, this list of conditions and the following disclaimer.
1261 + * Redistributions in binary form must reproduce the above copyright
1262 + notice, this list of conditions and the following disclaimer in the
1263 + documentation and/or other materials provided with the distribution.
1264 + * Neither the name of the copyright holder nor the
1265 + names of its contributors may be used to endorse or promote products
1266 + derived from this software without specific prior written permission.
1268 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1269 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1270 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1271 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
1272 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1273 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1274 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1275 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1276 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1277 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1280 +#include <linux/linkage.h>
1281 +#include "arm-mem.h"
1283 +/* Prevent the stack from becoming executable */
1284 +#if defined(__linux__) && defined(__ELF__)
1285 +.section .note.GNU-stack,"",%progbits
1290 + .object_arch armv4
1296 + * void *memset(void *s, int c, size_t n);
1298 + * a1 = pointer to buffer to fill
1299 + * a2 = byte pattern to fill with (caller-narrowed)
1300 + * a3 = number of bytes to fill
1316 + orr DAT0, DAT0, lsl #8
1318 + orr DAT0, DAT0, lsl #16
1321 + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
1325 +161: sub N, N, #16 /* simplifies inner loop termination */
1326 + /* Leading words and bytes */
1329 + rsb DAT3, S, #0 /* bits 0-3 = number of leading bytes until aligned */
1330 + movs DAT2, DAT3, lsl #31
1332 + strmib DAT0, [S], #1
1334 + strcsh DAT0, [S], #2
1335 + movs DAT2, DAT3, lsl #29
1337 + strmi DAT0, [S], #4
1339 + stmcsia S!, {DAT0, DAT1}
1340 +164: /* Delayed set up of DAT2 and DAT3 so we could use them as scratch registers above */
1343 + /* Now the inner loop of 16-byte stores */
1344 +165: stmia S!, {DAT0, DAT1, DAT2, DAT3}
1347 +166: /* Trailing words and bytes */
1348 + movs N, N, lsl #29
1349 + stmcsia S!, {DAT0, DAT1}
1350 + strmi DAT0, [S], #4
1352 + strcsh DAT0, [S], #2
1356 +170: /* Short case */
1363 + strb DAT0, [S], #1
1367 + stmneia S!, {DAT0, DAT1, DAT2, DAT3}
1376 +ENDPROC(__memset64)
1377 +ENDPROC(__memset32)
1380 --- a/arch/arm/lib/uaccess_with_memcpy.c
1381 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1383 #include <asm/current.h>
1384 #include <asm/page.h>
1386 +#ifndef COPY_FROM_USER_THRESHOLD
1387 +#define COPY_FROM_USER_THRESHOLD 64
1390 +#ifndef COPY_TO_USER_THRESHOLD
1391 +#define COPY_TO_USER_THRESHOLD 64
1395 pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
1397 @@ -84,7 +92,44 @@ pin_page_for_write(const void __user *_a
1401 -static unsigned long noinline
1403 +pin_page_for_read(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
1405 + unsigned long addr = (unsigned long)_addr;
1412 + pgd = pgd_offset(current->mm, addr);
1413 + if (unlikely(pgd_none(*pgd) || pgd_bad(*pgd)))
1417 + pud = pud_offset(pgd, addr);
1418 + if (unlikely(pud_none(*pud) || pud_bad(*pud)))
1423 + pmd = pmd_offset(pud, addr);
1424 + if (unlikely(pmd_none(*pmd) || pmd_bad(*pmd)))
1427 + pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl);
1428 + if (unlikely(!pte_present(*pte) || !pte_young(*pte))) {
1429 + pte_unmap_unlock(pte, ptl);
1439 +unsigned long noinline
1440 __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
1442 unsigned long ua_flags;
1443 @@ -137,6 +182,57 @@ out:
1447 +unsigned long noinline
1448 +__copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
1450 + unsigned long ua_flags;
1453 + if (unlikely(segment_eq(get_fs(), KERNEL_DS))) {
1454 + memcpy(to, (const void *)from, n);
1458 + /* the mmap semaphore is taken only if not in an atomic context */
1459 + atomic = in_atomic();
1462 + down_read(¤t->mm->mmap_sem);
1468 + while (!pin_page_for_read(from, &pte, &ptl)) {
1471 + up_read(¤t->mm->mmap_sem);
1472 + if (__get_user(temp, (char __user *)from))
1475 + down_read(¤t->mm->mmap_sem);
1478 + tocopy = (~(unsigned long)from & ~PAGE_MASK) + 1;
1482 + ua_flags = uaccess_save_and_enable();
1483 + memcpy(to, (const void *)from, tocopy);
1484 + uaccess_restore(ua_flags);
1489 + pte_unmap_unlock(pte, ptl);
1492 + up_read(¤t->mm->mmap_sem);
1499 arm_copy_to_user(void __user *to, const void *from, unsigned long n)
1501 @@ -147,7 +243,7 @@ arm_copy_to_user(void __user *to, const
1502 * With frame pointer disabled, tail call optimization kicks in
1503 * as well making this test almost invisible.
1506 + if (n < COPY_TO_USER_THRESHOLD) {
1507 unsigned long ua_flags = uaccess_save_and_enable();
1508 n = __copy_to_user_std(to, from, n);
1509 uaccess_restore(ua_flags);
1510 @@ -157,6 +253,26 @@ arm_copy_to_user(void __user *to, const
1515 +unsigned long __must_check
1516 +arm_copy_from_user(void *to, const void __user *from, unsigned long n)
1519 + * This test is stubbed out of the main function above to keep
1520 + * the overhead for small copies low by avoiding a large
1521 + * register dump on the stack just to reload them right away.
1522 + * With frame pointer disabled, tail call optimization kicks in
1523 + * as well making this test almost invisible.
1525 + if (n < COPY_TO_USER_THRESHOLD) {
1526 + unsigned long ua_flags = uaccess_save_and_enable();
1527 + n = __copy_from_user_std(to, from, n);
1528 + uaccess_restore(ua_flags);
1530 + n = __copy_from_user_memcpy(to, from, n);
1535 static unsigned long noinline
1536 __clear_user_memset(void __user *addr, unsigned long n)
1537 --- a/arch/arm/mach-bcm/Kconfig
1538 +++ b/arch/arm/mach-bcm/Kconfig
1539 @@ -177,6 +177,13 @@ config ARCH_BCM_53573
1540 The base chip is BCM53573 and there are some packaging modifications
1541 like BCM47189 and BCM47452.
1543 +config BCM2835_FAST_MEMCPY
1544 + bool "Enable optimized __copy_to_user and __copy_from_user"
1545 + depends on ARCH_BCM2835 && ARCH_MULTI_V6
1548 + Optimized versions of __copy_to_user and __copy_from_user for Pi1.
1550 config ARCH_BCM_63XX
1551 bool "Broadcom BCM63xx DSL SoC"
1552 depends on ARCH_MULTI_V7