1 From 9a10ffd029c81a694db6666c1dedfa687396093b 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] 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 Fix copy_from_user if BCM2835_FAST_MEMCPY=n
25 The change which introduced CONFIG_BCM2835_FAST_MEMCPY unconditionally
26 changed the behaviour of arm_copy_from_user. The page pinning code
27 is not safe on ARMv7 if LPAE & high memory is enabled and causes
28 crashes which look like PTE corruption.
30 Make __copy_from_user_memcpy conditional on CONFIG_2835_FAST_MEMCPY=y
31 which is really an ARMv6 / Pi1 optimization and not necessary on newer
34 arm: fix mmap unlocks in uaccess_with_memcpy.c
36 This is a regression that was added with the commit 192a4e923ef092924dd013e7326f2ec520ee4783 as of rpi-5.8.y, since that is when the move to the mmap locking API was introduced - d8ed45c5dcd455fc5848d47f86883a1b872ac0d0
38 The issue is that when the patch to improve performance for the __copy_to_user and __copy_from_user functions were added for the Raspberry Pi, some of the mmaps were incorrectly mapped to write instead of read. This would cause a verity of issues, and in my case, prevent the booting of a squashfs filesystem on rpi-5.8-y and above. An example of the panic you would see from this can be seen at https://pastebin.com/raw/jBz5xCzL
40 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
41 Signed-off-by: Christopher Blake <chrisrblake93@gmail.com>
43 arch/arm: Add __memset alias to memset_rpi.S
45 memset_rpi.S is an optimised memset implementation, but doesn't define
46 __memset (which was just added to memset.S). As a result, building
47 for the BCM2835 platform causes a link failure.
49 Add __memset as yet another alias to our common implementation.
51 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
53 arm: Fix custom rpi __memset32 and __memset64
55 See: https://github.com/raspberrypi/linux/issues/4798
57 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
59 arm: Fix annoying .eh_frame section warnings
61 Replace the cfi directives with the UNWIND equivalents. This prevents
62 the .eh_frame section from being created, eliminating the warnings.
64 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
66 arch/arm/include/asm/string.h | 5 +
67 arch/arm/include/asm/uaccess.h | 3 +
68 arch/arm/lib/Makefile | 14 +-
69 arch/arm/lib/arm-mem.h | 159 ++++++++++
70 arch/arm/lib/copy_from_user.S | 4 +-
71 arch/arm/lib/exports_rpi.c | 37 +++
72 arch/arm/lib/memcmp_rpi.S | 285 +++++++++++++++++
73 arch/arm/lib/memcpy_rpi.S | 63 ++++
74 arch/arm/lib/memcpymove.h | 488 +++++++++++++++++++++++++++++
75 arch/arm/lib/memmove_rpi.S | 63 ++++
76 arch/arm/lib/memset_rpi.S | 132 ++++++++
77 arch/arm/lib/uaccess_with_memcpy.c | 125 +++++++-
78 arch/arm/mach-bcm/Kconfig | 24 ++
79 13 files changed, 1396 insertions(+), 6 deletions(-)
80 create mode 100644 arch/arm/lib/arm-mem.h
81 create mode 100644 arch/arm/lib/exports_rpi.c
82 create mode 100644 arch/arm/lib/memcmp_rpi.S
83 create mode 100644 arch/arm/lib/memcpy_rpi.S
84 create mode 100644 arch/arm/lib/memcpymove.h
85 create mode 100644 arch/arm/lib/memmove_rpi.S
86 create mode 100644 arch/arm/lib/memset_rpi.S
88 --- a/arch/arm/include/asm/string.h
89 +++ b/arch/arm/include/asm/string.h
90 @@ -65,4 +65,9 @@ static inline void *memset64(uint64_t *p
94 +#ifdef CONFIG_BCM2835_FAST_MEMCPY
95 +#define __HAVE_ARCH_MEMCMP
96 +extern int memcmp(const void *, const void *, size_t);
100 --- a/arch/arm/include/asm/uaccess.h
101 +++ b/arch/arm/include/asm/uaccess.h
102 @@ -509,6 +509,9 @@ do { \
103 extern unsigned long __must_check
104 arm_copy_from_user(void *to, const void __user *from, unsigned long n);
106 +extern unsigned long __must_check
107 +__copy_from_user_std(void *to, const void __user *from, unsigned long n);
109 static inline unsigned long __must_check
110 raw_copy_from_user(void *to, const void __user *from, unsigned long n)
112 --- a/arch/arm/lib/Makefile
113 +++ b/arch/arm/lib/Makefile
116 lib-y := changebit.o csumipv6.o csumpartial.o \
117 csumpartialcopy.o csumpartialcopyuser.o clearbit.o \
118 - delay.o delay-loop.o findbit.o memchr.o memcpy.o \
119 - memmove.o memset.o setbit.o \
120 + delay.o delay-loop.o findbit.o memchr.o \
123 testchangebit.o testclearbit.o testsetbit.o \
124 ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \
125 @@ -25,6 +25,16 @@ else
129 +# Choose optimised implementations for Raspberry Pi
130 +ifeq ($(CONFIG_BCM2835_FAST_MEMCPY),y)
131 + CFLAGS_uaccess_with_memcpy.o += -DCOPY_FROM_USER_THRESHOLD=1600
132 + CFLAGS_uaccess_with_memcpy.o += -DCOPY_TO_USER_THRESHOLD=672
133 + obj-$(CONFIG_MODULES) += exports_rpi.o
134 + lib-y += memcpy_rpi.o memmove_rpi.o memset_rpi.o memcmp_rpi.o
136 + lib-y += memcpy.o memmove.o memset.o
139 # using lib_ here won't override already available weak symbols
140 obj-$(CONFIG_UACCESS_WITH_MEMCPY) += uaccess_with_memcpy.o
143 +++ b/arch/arm/lib/arm-mem.h
146 +Copyright (c) 2013, Raspberry Pi Foundation
147 +Copyright (c) 2013, RISC OS Open Ltd
148 +All rights reserved.
150 +Redistribution and use in source and binary forms, with or without
151 +modification, are permitted provided that the following conditions are met:
152 + * Redistributions of source code must retain the above copyright
153 + notice, this list of conditions and the following disclaimer.
154 + * Redistributions in binary form must reproduce the above copyright
155 + notice, this list of conditions and the following disclaimer in the
156 + documentation and/or other materials provided with the distribution.
157 + * Neither the name of the copyright holder nor the
158 + names of its contributors may be used to endorse or promote products
159 + derived from this software without specific prior written permission.
161 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
162 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
163 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
164 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
165 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
166 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
167 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
168 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
169 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
170 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
179 +.macro preload_leading_step1 backwards, ptr, base
180 +/* If the destination is already 16-byte aligned, then we need to preload
181 + * between 0 and prefetch_distance (inclusive) cache lines ahead so there
182 + * are no gaps when the inner loop starts.
191 + .rept prefetch_distance+1
194 + .set OFFSET, OFFSET-32
196 + .set OFFSET, OFFSET+32
201 +.macro preload_leading_step2 backwards, ptr, base, leading_bytes, tmp
202 +/* However, if the destination is not 16-byte aligned, we may need to
203 + * preload one more cache line than that. The question we need to ask is:
204 + * are the leading bytes more than the amount by which the source
205 + * pointer will be rounded down for preloading, and if so, by how many
209 +/* Here we compare against how many bytes we are into the
210 + * cache line, counting down from the highest such address.
211 + * Effectively, we want to calculate
212 + * leading_bytes = dst&15
213 + * cacheline_offset = 31-((src-leading_bytes-1)&31)
214 + * extra_needed = leading_bytes - cacheline_offset
215 + * and test if extra_needed is <= 0, or rearranging:
216 + * leading_bytes + (src-leading_bytes-1)&31 <= 31
218 + mov tmp, base, lsl #32-5
219 + sbc tmp, tmp, leading_bytes, lsl #32-5
220 + adds tmp, tmp, leading_bytes, lsl #32-5
222 + pld [ptr, #-32*(prefetch_distance+1)]
224 +/* Effectively, we want to calculate
225 + * leading_bytes = (-dst)&15
226 + * cacheline_offset = (src+leading_bytes)&31
227 + * extra_needed = leading_bytes - cacheline_offset
228 + * and test if extra_needed is <= 0.
230 + mov tmp, base, lsl #32-5
231 + add tmp, tmp, leading_bytes, lsl #32-5
232 + rsbs tmp, tmp, leading_bytes, lsl #32-5
234 + pld [ptr, #32*(prefetch_distance+1)]
239 +.macro preload_trailing backwards, base, remain, tmp
240 + /* We need either 0, 1 or 2 extra preloads */
243 + mov tmp, tmp, lsl #32-5
245 + mov tmp, base, lsl #32-5
247 + adds tmp, tmp, remain, lsl #32-5
248 + adceqs tmp, tmp, #0
249 + /* The instruction above has two effects: ensures Z is only
250 + * set if C was clear (so Z indicates that both shifted quantities
251 + * were 0), and clears C if Z was set (so C indicates that the sum
252 + * of the shifted quantities was greater and not equal to 32) */
262 + pld [tmp, #-32*(prefetch_distance+1)]
264 + pld [tmp, #-32*prefetch_distance]
266 + pld [tmp, #32*(prefetch_distance+2)]
268 + pld [tmp, #32*(prefetch_distance+1)]
273 +.macro preload_all backwards, narrow_case, shift, base, remain, tmp0, tmp1
276 + bic tmp0, tmp0, #31
278 + sub tmp1, base, remain, lsl #shift
280 + bic tmp0, base, #31
282 + add tmp1, base, remain, lsl #shift
285 + bic tmp1, tmp1, #31
289 + /* In this case, all the data fits in either 1 or 2 cache lines */
294 + sub tmp0, tmp0, #32
296 + add tmp0, tmp0, #32
304 --- a/arch/arm/lib/copy_from_user.S
305 +++ b/arch/arm/lib/copy_from_user.S
306 @@ -104,7 +104,8 @@ UNWIND( .save {r0, r2, r3, \regs} )
310 -ENTRY(arm_copy_from_user)
311 +ENTRY(__copy_from_user_std)
312 +WEAK(arm_copy_from_user)
313 #ifdef CONFIG_CPU_SPECTRE
315 uaccess_mask_range_ptr r1, r2, r3, ip
316 @@ -113,6 +114,7 @@ ENTRY(arm_copy_from_user)
317 #include "copy_template.S"
319 ENDPROC(arm_copy_from_user)
320 +ENDPROC(__copy_from_user_std)
322 .pushsection .text.fixup,"ax"
325 +++ b/arch/arm/lib/exports_rpi.c
328 + * Copyright (c) 2014, Raspberry Pi (Trading) Ltd.
330 + * Redistribution and use in source and binary forms, with or without
331 + * modification, are permitted provided that the following conditions
333 + * 1. Redistributions of source code must retain the above copyright
334 + * notice, this list of conditions, and the following disclaimer,
335 + * without modification.
336 + * 2. 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 + * 3. The names of the above-listed copyright holders may not be used
340 + * to endorse or promote products derived from this software without
341 + * specific prior written permission.
343 + * ALTERNATIVELY, this software may be distributed under the terms of the
344 + * GNU General Public License ("GPL") version 2, as published by the Free
345 + * Software Foundation.
347 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
348 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
349 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
350 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
351 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
352 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
353 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
354 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
355 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
356 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
357 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
360 +#include <linux/kernel.h>
361 +#include <linux/module.h>
363 +EXPORT_SYMBOL(memcmp);
365 +++ b/arch/arm/lib/memcmp_rpi.S
368 +Copyright (c) 2013, Raspberry Pi Foundation
369 +Copyright (c) 2013, RISC OS Open Ltd
370 +All rights reserved.
372 +Redistribution and use in source and binary forms, with or without
373 +modification, are permitted provided that the following conditions are met:
374 + * Redistributions of source code must retain the above copyright
375 + notice, this list of conditions and the following disclaimer.
376 + * Redistributions in binary form must reproduce the above copyright
377 + notice, this list of conditions and the following disclaimer in the
378 + documentation and/or other materials provided with the distribution.
379 + * Neither the name of the copyright holder nor the
380 + names of its contributors may be used to endorse or promote products
381 + derived from this software without specific prior written permission.
383 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
384 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
385 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
386 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
387 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
388 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
389 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
390 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
391 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
392 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
395 +#include <linux/linkage.h>
396 +#include "arm-mem.h"
398 +/* Prevent the stack from becoming executable */
399 +#if defined(__linux__) && defined(__ELF__)
400 +.section .note.GNU-stack,"",%progbits
410 +.macro memcmp_process_head unaligned
412 + ldr DAT0, [S_1], #4
413 + ldr DAT1, [S_1], #4
414 + ldr DAT2, [S_1], #4
415 + ldr DAT3, [S_1], #4
417 + ldmia S_1!, {DAT0, DAT1, DAT2, DAT3}
419 + ldmia S_2!, {DAT4, DAT5, DAT6, DAT7}
422 +.macro memcmp_process_tail
430 +.macro memcmp_leading_31bytes
431 + movs DAT0, OFF, lsl #31
432 + ldrmib DAT0, [S_1], #1
433 + ldrcsh DAT1, [S_1], #2
434 + ldrmib DAT4, [S_2], #1
435 + ldrcsh DAT5, [S_2], #2
445 + movs DAT0, OFF, lsl #29
446 + ldrmi DAT0, [S_1], #4
447 + ldrcs DAT1, [S_1], #4
448 + ldrcs DAT2, [S_1], #4
449 + ldrmi DAT4, [S_2], #4
450 + ldmcsia S_2!, {DAT5, DAT6}
465 + memcmp_process_head 1
467 + memcmp_process_tail
471 +.macro memcmp_trailing_15bytes unaligned
474 + ldrcs DAT0, [S_1], #4
475 + ldrcs DAT1, [S_1], #4
477 + ldmcsia S_1!, {DAT0, DAT1}
479 + ldrmi DAT2, [S_1], #4
480 + ldmcsia S_2!, {DAT4, DAT5}
481 + ldrmi DAT6, [S_2], #4
493 + ldrcsh DAT0, [S_1], #2
495 + ldrcsh DAT4, [S_2], #2
506 +.macro memcmp_long_inner_loop unaligned
508 + memcmp_process_head unaligned
509 + pld [S_2, #prefetch_distance*32 + 16]
510 + memcmp_process_tail
511 + memcmp_process_head unaligned
513 + memcmp_process_tail
516 + /* Just before the final (prefetch_distance+1) 32-byte blocks,
517 + * deal with final preloads */
518 + preload_trailing 0, S_1, N, DAT0
519 + preload_trailing 0, S_2, N, DAT0
520 + add N, N, #(prefetch_distance+2)*32 - 16
522 + memcmp_process_head unaligned
523 + memcmp_process_tail
526 + /* Trailing words and bytes */
529 + memcmp_trailing_15bytes unaligned
530 +199: /* Reached end without detecting a difference */
533 + pop {DAT1-DAT6, pc}
536 +.macro memcmp_short_inner_loop unaligned
537 + subs N, N, #16 /* simplifies inner loop termination */
540 + memcmp_process_head unaligned
541 + memcmp_process_tail
544 +122: /* Trailing words and bytes */
547 + memcmp_trailing_15bytes unaligned
548 +199: /* Reached end without detecting a difference */
551 + pop {DAT1-DAT6, pc}
555 + * int memcmp(const void *s1, const void *s2, size_t n);
557 + * a1 = pointer to buffer 1
558 + * a2 = pointer to buffer 2
559 + * a3 = number of bytes to compare (as unsigned chars)
561 + * a1 = >0/=0/<0 if s1 >/=/< s2
564 +.set prefetch_distance, 2
580 + push {DAT1-DAT6, lr}
581 + setend be /* lowest-addressed bytes are most significant */
583 + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
584 + cmp N, #(prefetch_distance+3)*32 - 1
588 + /* Adjust N so that the decrement instruction can also test for
589 + * inner loop termination. We want it to stop when there are
590 + * (prefetch_distance+1) complete blocks to go. */
591 + sub N, N, #(prefetch_distance+2)*32
592 + preload_leading_step1 0, DAT0, S_1
593 + preload_leading_step1 0, DAT1, S_2
596 + rsb OFF, S_2, #0 /* no need to AND with 15 here */
597 + preload_leading_step2 0, DAT0, S_1, OFF, DAT2
598 + preload_leading_step2 0, DAT1, S_2, OFF, DAT2
599 + memcmp_leading_31bytes
600 +154: /* Second source now cacheline (32-byte) aligned; we have at
601 + * least one prefetch to go. */
602 + /* Prefetch offset is best selected such that it lies in the
603 + * first 8 of each 32 bytes - but it's just as easy to aim for
606 + rsb OFF, OFF, #32*prefetch_distance
609 + memcmp_long_inner_loop 0
610 +140: memcmp_long_inner_loop 1
612 +170: /* Short case */
615 + preload_all 0, 0, 0, S_1, N, DAT0, DAT1
616 + preload_all 0, 0, 0, S_2, N, DAT0, DAT1
621 + ldrb DAT0, [S_1], #1
622 + ldrb DAT4, [S_2], #1
627 +174: /* Second source now 4-byte aligned; we have 0 or more bytes to go */
630 + memcmp_short_inner_loop 0
631 +140: memcmp_short_inner_loop 1
633 +200: /* Difference found: determine sign. */
637 + pop {DAT1-DAT6, pc}
653 +++ b/arch/arm/lib/memcpy_rpi.S
656 +Copyright (c) 2013, Raspberry Pi Foundation
657 +Copyright (c) 2013, RISC OS Open Ltd
658 +All rights reserved.
660 +Redistribution and use in source and binary forms, with or without
661 +modification, are permitted provided that the following conditions are met:
662 + * Redistributions of source code must retain the above copyright
663 + notice, this list of conditions and the following disclaimer.
664 + * Redistributions in binary form must reproduce the above copyright
665 + notice, this list of conditions and the following disclaimer in the
666 + documentation and/or other materials provided with the distribution.
667 + * Neither the name of the copyright holder nor the
668 + names of its contributors may be used to endorse or promote products
669 + derived from this software without specific prior written permission.
671 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
672 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
673 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
674 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
675 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
676 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
677 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
678 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
679 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
680 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
683 +#include <linux/linkage.h>
684 +#include <asm/assembler.h>
685 +#include <asm/unwind.h>
686 +#include "arm-mem.h"
687 +#include "memcpymove.h"
689 +/* Prevent the stack from becoming executable */
690 +#if defined(__linux__) && defined(__ELF__)
691 +.section .note.GNU-stack,"",%progbits
702 + * void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
704 + * a1 = pointer to destination
705 + * a2 = pointer to source
706 + * a3 = number of bytes to copy
711 +.set prefetch_distance, 3
719 +++ b/arch/arm/lib/memcpymove.h
722 +Copyright (c) 2013, Raspberry Pi Foundation
723 +Copyright (c) 2013, RISC OS Open Ltd
724 +All rights reserved.
726 +Redistribution and use in source and binary forms, with or without
727 +modification, are permitted provided that the following conditions are met:
728 + * Redistributions of source code must retain the above copyright
729 + notice, this list of conditions and the following disclaimer.
730 + * Redistributions in binary form must reproduce the above copyright
731 + notice, this list of conditions and the following disclaimer in the
732 + documentation and/or other materials provided with the distribution.
733 + * Neither the name of the copyright holder nor the
734 + names of its contributors may be used to endorse or promote products
735 + derived from this software without specific prior written permission.
737 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
738 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
739 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
740 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
741 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
742 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
743 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
744 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
745 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
746 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
749 +.macro unaligned_words backwards, align, use_pld, words, r0, r1, r2, r3, r4, r5, r6, r7, r8
752 + mov r1, r0, lsl #32-align*8
754 + orr r1, r1, r0, lsr #align*8
757 + mov r0, r1, lsr #align*8
759 + orr r0, r0, r1, lsl #32-align*8
765 + mov r2, r0, lsl #32-align*8
767 + orr r2, r2, r1, lsr #align*8
768 + mov r1, r1, lsl #32-align*8
769 + orr r1, r1, r0, lsr #align*8
773 + mov r0, r2, lsr #align*8
775 + orr r0, r0, r1, lsl #32-align*8
776 + mov r1, r1, lsr #align*8
777 + orr r1, r1, r2, lsl #32-align*8
783 + mov r4, r0, lsl #32-align*8
785 + orr r4, r4, r3, lsr #align*8
786 + mov r3, r3, lsl #32-align*8
787 + orr r3, r3, r2, lsr #align*8
788 + mov r2, r2, lsl #32-align*8
789 + orr r2, r2, r1, lsr #align*8
790 + mov r1, r1, lsl #32-align*8
791 + orr r1, r1, r0, lsr #align*8
792 + stmdb D!, {r1, r2, r3, r4}
795 + mov r0, r4, lsr #align*8
797 + orr r0, r0, r1, lsl #32-align*8
798 + mov r1, r1, lsr #align*8
799 + orr r1, r1, r2, lsl #32-align*8
800 + mov r2, r2, lsr #align*8
801 + orr r2, r2, r3, lsl #32-align*8
802 + mov r3, r3, lsr #align*8
803 + orr r3, r3, r4, lsl #32-align*8
804 + stmia D!, {r0, r1, r2, r3}
808 + ldmdb S!, {r4, r5, r6, r7}
809 + mov r8, r0, lsl #32-align*8
810 + ldmdb S!, {r0, r1, r2, r3}
814 + orr r8, r8, r7, lsr #align*8
815 + mov r7, r7, lsl #32-align*8
816 + orr r7, r7, r6, lsr #align*8
817 + mov r6, r6, lsl #32-align*8
818 + orr r6, r6, r5, lsr #align*8
819 + mov r5, r5, lsl #32-align*8
820 + orr r5, r5, r4, lsr #align*8
821 + mov r4, r4, lsl #32-align*8
822 + orr r4, r4, r3, lsr #align*8
823 + mov r3, r3, lsl #32-align*8
824 + orr r3, r3, r2, lsr #align*8
825 + mov r2, r2, lsl #32-align*8
826 + orr r2, r2, r1, lsr #align*8
827 + mov r1, r1, lsl #32-align*8
828 + orr r1, r1, r0, lsr #align*8
829 + stmdb D!, {r5, r6, r7, r8}
830 + stmdb D!, {r1, r2, r3, r4}
832 + ldmib S!, {r1, r2, r3, r4}
833 + mov r0, r8, lsr #align*8
834 + ldmib S!, {r5, r6, r7, r8}
838 + orr r0, r0, r1, lsl #32-align*8
839 + mov r1, r1, lsr #align*8
840 + orr r1, r1, r2, lsl #32-align*8
841 + mov r2, r2, lsr #align*8
842 + orr r2, r2, r3, lsl #32-align*8
843 + mov r3, r3, lsr #align*8
844 + orr r3, r3, r4, lsl #32-align*8
845 + mov r4, r4, lsr #align*8
846 + orr r4, r4, r5, lsl #32-align*8
847 + mov r5, r5, lsr #align*8
848 + orr r5, r5, r6, lsl #32-align*8
849 + mov r6, r6, lsr #align*8
850 + orr r6, r6, r7, lsl #32-align*8
851 + mov r7, r7, lsr #align*8
852 + orr r7, r7, r8, lsl #32-align*8
853 + stmia D!, {r0, r1, r2, r3}
854 + stmia D!, {r4, r5, r6, r7}
859 +.macro memcpy_leading_15bytes backwards, align
860 + movs DAT1, DAT2, lsl #31
863 + ldrmib DAT0, [S, #-1]!
864 + ldrcsh DAT1, [S, #-2]!
865 + strmib DAT0, [D, #-1]!
866 + strcsh DAT1, [D, #-2]!
868 + ldrmib DAT0, [S], #1
869 + ldrcsh DAT1, [S], #2
870 + strmib DAT0, [D], #1
871 + strcsh DAT1, [D], #2
873 + movs DAT1, DAT2, lsl #29
875 + ldrmi DAT0, [S, #-4]!
877 + ldmcsdb S!, {DAT1, DAT2}
879 + ldrcs DAT2, [S, #-4]!
880 + ldrcs DAT1, [S, #-4]!
882 + strmi DAT0, [D, #-4]!
883 + stmcsdb D!, {DAT1, DAT2}
885 + ldrmi DAT0, [S], #4
887 + ldmcsia S!, {DAT1, DAT2}
889 + ldrcs DAT1, [S], #4
890 + ldrcs DAT2, [S], #4
892 + strmi DAT0, [D], #4
893 + stmcsia D!, {DAT1, DAT2}
897 +.macro memcpy_trailing_15bytes backwards, align
901 + ldmcsdb S!, {DAT0, DAT1}
903 + ldrcs DAT1, [S, #-4]!
904 + ldrcs DAT0, [S, #-4]!
906 + ldrmi DAT2, [S, #-4]!
907 + stmcsdb D!, {DAT0, DAT1}
908 + strmi DAT2, [D, #-4]!
911 + ldmcsia S!, {DAT0, DAT1}
913 + ldrcs DAT0, [S], #4
914 + ldrcs DAT1, [S], #4
916 + ldrmi DAT2, [S], #4
917 + stmcsia D!, {DAT0, DAT1}
918 + strmi DAT2, [D], #4
922 + ldrcsh DAT0, [S, #-2]!
923 + ldrmib DAT1, [S, #-1]
924 + strcsh DAT0, [D, #-2]!
925 + strmib DAT1, [D, #-1]
927 + ldrcsh DAT0, [S], #2
929 + strcsh DAT0, [D], #2
934 +.macro memcpy_long_inner_loop backwards, align
937 + ldr DAT0, [S, #-align]!
939 + ldr LAST, [S, #-align]!
945 + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
947 + stmdb D!, {DAT4, DAT5, DAT6, LAST}
948 + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
950 + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
952 + stmia D!, {DAT0, DAT1, DAT2, DAT3}
953 + stmia D!, {DAT4, DAT5, DAT6, LAST}
956 + unaligned_words backwards, align, 1, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
960 + /* Just before the final (prefetch_distance+1) 32-byte blocks, deal with final preloads */
961 + preload_trailing backwards, S, N, OFF
962 + add N, N, #(prefetch_distance+2)*32 - 32
966 + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
967 + stmdb D!, {DAT4, DAT5, DAT6, LAST}
968 + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
970 + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
971 + stmia D!, {DAT0, DAT1, DAT2, DAT3}
972 + stmia D!, {DAT4, DAT5, DAT6, LAST}
975 + unaligned_words backwards, align, 0, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
982 + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
983 + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
985 + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
986 + stmneia D!, {DAT0, DAT1, DAT2, LAST}
990 + unaligned_words backwards, align, 0, 4, DAT0, DAT1, DAT2, DAT3, LAST
993 + /* Trailing words and bytes */
999 + memcpy_trailing_15bytes backwards, align
1001 + pop {DAT3, DAT4, DAT5, DAT6, DAT7}
1002 + pop {D, DAT1, DAT2, pc}
1005 +.macro memcpy_medium_inner_loop backwards, align
1009 + ldmdb S!, {DAT0, DAT1, DAT2, LAST}
1011 + ldr LAST, [S, #-4]!
1012 + ldr DAT2, [S, #-4]!
1013 + ldr DAT1, [S, #-4]!
1014 + ldr DAT0, [S, #-4]!
1016 + stmdb D!, {DAT0, DAT1, DAT2, LAST}
1019 + ldmia S!, {DAT0, DAT1, DAT2, LAST}
1026 + stmia D!, {DAT0, DAT1, DAT2, LAST}
1030 + /* Trailing words and bytes */
1033 + memcpy_trailing_15bytes backwards, align
1035 + pop {D, DAT1, DAT2, pc}
1038 +.macro memcpy_short_inner_loop backwards, align
1042 + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
1044 + ldrne LAST, [S, #-4]!
1045 + ldrne DAT2, [S, #-4]!
1046 + ldrne DAT1, [S, #-4]!
1047 + ldrne DAT0, [S, #-4]!
1049 + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
1052 + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
1054 + ldrne DAT0, [S], #4
1055 + ldrne DAT1, [S], #4
1056 + ldrne DAT2, [S], #4
1057 + ldrne LAST, [S], #4
1059 + stmneia D!, {DAT0, DAT1, DAT2, LAST}
1061 + memcpy_trailing_15bytes backwards, align
1063 + pop {D, DAT1, DAT2, pc}
1066 +.macro memcpy backwards
1081 + UNWIND( .fnstart )
1083 + push {D, DAT1, DAT2, lr}
1086 + UNWIND( .fnstart )
1087 + UNWIND( .save {D, DAT1, DAT2, lr} )
1094 + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
1097 + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
1098 + cmp N, #(prefetch_distance+3)*32 - 1
1102 + push {DAT3, DAT4, DAT5, DAT6, DAT7}
1105 + UNWIND( .fnstart )
1106 + UNWIND( .save {D, DAT1, DAT2, lr} )
1107 + UNWIND( .save {DAT3, DAT4, DAT5, DAT6, DAT7} )
1109 + /* Adjust N so that the decrement instruction can also test for
1110 + * inner loop termination. We want it to stop when there are
1111 + * (prefetch_distance+1) complete blocks to go. */
1112 + sub N, N, #(prefetch_distance+2)*32
1113 + preload_leading_step1 backwards, DAT0, S
1115 + /* Bug in GAS: it accepts, but mis-assembles the instruction
1116 + * ands DAT2, D, #60, 2
1117 + * which sets DAT2 to the number of leading bytes until destination is aligned and also clears C (sets borrow)
1124 + rsb DAT2, DAT2, #16 /* number of leading bytes until destination aligned */
1126 + preload_leading_step2 backwards, DAT0, S, DAT2, OFF
1127 + memcpy_leading_15bytes backwards, 1
1128 +154: /* Destination now 16-byte aligned; we have at least one prefetch as well as at least one 16-byte output block */
1129 + /* 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 */
1133 + sub OFF, OFF, #32*(prefetch_distance+1)
1136 + rsb OFF, OFF, #32*prefetch_distance
1138 + movs DAT0, S, lsl #31
1142 + memcpy_long_inner_loop backwards, 0
1143 +155: memcpy_long_inner_loop backwards, 1
1144 +156: memcpy_long_inner_loop backwards, 2
1145 +157: memcpy_long_inner_loop backwards, 3
1149 + UNWIND( .fnstart )
1150 + UNWIND( .save {D, DAT1, DAT2, lr} )
1152 +160: /* Medium case */
1153 + preload_all backwards, 0, 0, S, N, DAT2, OFF
1154 + sub N, N, #16 /* simplifies inner loop termination */
1161 + rsb DAT2, DAT2, #16
1163 + memcpy_leading_15bytes backwards, align
1164 +164: /* Destination now 16-byte aligned; we have at least one 16-byte output block */
1167 + memcpy_medium_inner_loop backwards, 0
1168 +140: memcpy_medium_inner_loop backwards, 1
1170 +170: /* Short case, less than 31 bytes, so no guarantee of at least one 16-byte block */
1173 + preload_all backwards, 1, 0, S, N, DAT2, LAST
1179 + ldrb DAT0, [S, #-1]!
1180 + strb DAT0, [D, #-1]!
1182 + ldrb DAT0, [S], #1
1183 + strb DAT0, [D], #1
1187 +174: /* Destination now 4-byte aligned; we have 0 or more output bytes to go */
1190 + memcpy_short_inner_loop backwards, 0
1191 +140: memcpy_short_inner_loop backwards, 1
1210 +++ b/arch/arm/lib/memmove_rpi.S
1213 +Copyright (c) 2013, Raspberry Pi Foundation
1214 +Copyright (c) 2013, RISC OS Open Ltd
1215 +All rights reserved.
1217 +Redistribution and use in source and binary forms, with or without
1218 +modification, are permitted provided that the following conditions are met:
1219 + * Redistributions of source code must retain the above copyright
1220 + notice, this list of conditions and the following disclaimer.
1221 + * Redistributions in binary form must reproduce the above copyright
1222 + notice, this list of conditions and the following disclaimer in the
1223 + documentation and/or other materials provided with the distribution.
1224 + * Neither the name of the copyright holder nor the
1225 + names of its contributors may be used to endorse or promote products
1226 + derived from this software without specific prior written permission.
1228 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1229 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1230 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1231 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
1232 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1233 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1234 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1235 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1236 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1237 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1240 +#include <linux/linkage.h>
1241 +#include <asm/assembler.h>
1242 +#include <asm/unwind.h>
1243 +#include "arm-mem.h"
1244 +#include "memcpymove.h"
1246 +/* Prevent the stack from becoming executable */
1247 +#if defined(__linux__) && defined(__ELF__)
1248 +.section .note.GNU-stack,"",%progbits
1253 + .object_arch armv4
1259 + * void *memmove(void *s1, const void *s2, size_t n);
1261 + * a1 = pointer to destination
1262 + * a2 = pointer to source
1263 + * a3 = number of bytes to copy
1268 +.set prefetch_distance, 3
1272 + bpl memcpy /* pl works even over -1 - 0 and 0x7fffffff - 0x80000000 boundaries */
1276 +++ b/arch/arm/lib/memset_rpi.S
1279 +Copyright (c) 2013, Raspberry Pi Foundation
1280 +Copyright (c) 2013, RISC OS Open Ltd
1281 +All rights reserved.
1283 +Redistribution and use in source and binary forms, with or without
1284 +modification, are permitted provided that the following conditions are met:
1285 + * Redistributions of source code must retain the above copyright
1286 + notice, this list of conditions and the following disclaimer.
1287 + * Redistributions in binary form must reproduce the above copyright
1288 + notice, this list of conditions and the following disclaimer in the
1289 + documentation and/or other materials provided with the distribution.
1290 + * Neither the name of the copyright holder nor the
1291 + names of its contributors may be used to endorse or promote products
1292 + derived from this software without specific prior written permission.
1294 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1295 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1296 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1297 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
1298 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1299 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1300 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1301 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1302 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1303 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1306 +#include <linux/linkage.h>
1307 +#include "arm-mem.h"
1309 +/* Prevent the stack from becoming executable */
1310 +#if defined(__linux__) && defined(__ELF__)
1311 +.section .note.GNU-stack,"",%progbits
1316 + .object_arch armv4
1322 + * void *memset(void *s, int c, size_t n);
1324 + * a1 = pointer to buffer to fill
1325 + * a2 = byte pattern to fill with (caller-narrowed)
1326 + * a3 = number of bytes to fill
1341 + orr DAT0, DAT0, DAT0, lsl #8
1342 + orr DAT0, DAT0, DAT0, lsl #16
1350 + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
1354 +161: sub N, N, #16 /* simplifies inner loop termination */
1355 + /* Leading words and bytes */
1358 + rsb DAT3, S, #0 /* bits 0-3 = number of leading bytes until aligned */
1359 + movs DAT2, DAT3, lsl #31
1361 + strmib DAT0, [S], #1
1363 + strcsh DAT0, [S], #2
1364 + movs DAT2, DAT3, lsl #29
1366 + strmi DAT0, [S], #4
1368 + stmcsia S!, {DAT0, DAT1}
1369 +164: /* Delayed set up of DAT2 and DAT3 so we could use them as scratch registers above */
1372 + /* Now the inner loop of 16-byte stores */
1373 +165: stmia S!, {DAT0, DAT1, DAT2, DAT3}
1376 +166: /* Trailing words and bytes */
1377 + movs N, N, lsl #29
1378 + stmcsia S!, {DAT0, DAT1}
1379 + strmi DAT0, [S], #4
1381 + strcsh DAT0, [S], #2
1385 +170: /* Short case */
1392 + strb DAT0, [S], #1
1396 + stmneia S!, {DAT0, DAT1, DAT2, DAT3}
1405 +ENDPROC(__memset64)
1406 +ENDPROC(__memset32)
1410 --- a/arch/arm/lib/uaccess_with_memcpy.c
1411 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1413 #include <asm/current.h>
1414 #include <asm/page.h>
1416 +#ifndef COPY_FROM_USER_THRESHOLD
1417 +#define COPY_FROM_USER_THRESHOLD 64
1420 +#ifndef COPY_TO_USER_THRESHOLD
1421 +#define COPY_TO_USER_THRESHOLD 64
1425 pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
1427 @@ -43,7 +51,7 @@ pin_page_for_write(const void __user *_a
1430 pmd = pmd_offset(pud, addr);
1431 - if (unlikely(pmd_none(*pmd)))
1432 + if (unlikely(pmd_none(*pmd) || pmd_bad(*pmd)))
1436 @@ -86,7 +94,46 @@ pin_page_for_write(const void __user *_a
1440 -static unsigned long noinline
1442 +pin_page_for_read(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
1444 + unsigned long addr = (unsigned long)_addr;
1452 + pgd = pgd_offset(current->mm, addr);
1453 + if (unlikely(pgd_none(*pgd) || pgd_bad(*pgd)))
1456 + p4d = p4d_offset(pgd, addr);
1457 + if (unlikely(p4d_none(*p4d) || p4d_bad(*p4d)))
1460 + pud = pud_offset(p4d, addr);
1461 + if (unlikely(pud_none(*pud) || pud_bad(*pud)))
1464 + pmd = pmd_offset(pud, addr);
1465 + if (unlikely(pmd_none(*pmd) || pmd_bad(*pmd)))
1468 + pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl);
1469 + if (unlikely(!pte_present(*pte) || !pte_young(*pte))) {
1470 + pte_unmap_unlock(pte, ptl);
1480 +unsigned long noinline
1481 __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
1483 unsigned long ua_flags;
1484 @@ -134,6 +181,52 @@ out:
1488 +unsigned long noinline
1489 +__copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
1491 + unsigned long ua_flags;
1494 + /* the mmap semaphore is taken only if not in an atomic context */
1495 + atomic = in_atomic();
1498 + mmap_read_lock(current->mm);
1504 + while (!pin_page_for_read(from, &pte, &ptl)) {
1507 + mmap_read_unlock(current->mm);
1508 + if (__get_user(temp, (char __user *)from))
1511 + mmap_read_lock(current->mm);
1514 + tocopy = (~(unsigned long)from & ~PAGE_MASK) + 1;
1518 + ua_flags = uaccess_save_and_enable();
1519 + memcpy(to, (const void *)from, tocopy);
1520 + uaccess_restore(ua_flags);
1525 + pte_unmap_unlock(pte, ptl);
1528 + mmap_read_unlock(current->mm);
1535 arm_copy_to_user(void __user *to, const void *from, unsigned long n)
1537 @@ -144,7 +237,7 @@ arm_copy_to_user(void __user *to, const
1538 * With frame pointer disabled, tail call optimization kicks in
1539 * as well making this test almost invisible.
1542 + if (n < COPY_TO_USER_THRESHOLD) {
1543 unsigned long ua_flags = uaccess_save_and_enable();
1544 n = __copy_to_user_std(to, from, n);
1545 uaccess_restore(ua_flags);
1546 @@ -154,6 +247,32 @@ arm_copy_to_user(void __user *to, const
1551 +unsigned long __must_check
1552 +arm_copy_from_user(void *to, const void __user *from, unsigned long n)
1554 +#ifdef CONFIG_BCM2835_FAST_MEMCPY
1556 + * This test is stubbed out of the main function above to keep
1557 + * the overhead for small copies low by avoiding a large
1558 + * register dump on the stack just to reload them right away.
1559 + * With frame pointer disabled, tail call optimization kicks in
1560 + * as well making this test almost invisible.
1562 + if (n < COPY_TO_USER_THRESHOLD) {
1563 + unsigned long ua_flags = uaccess_save_and_enable();
1564 + n = __copy_from_user_std(to, from, n);
1565 + uaccess_restore(ua_flags);
1567 + n = __copy_from_user_memcpy(to, from, n);
1570 + unsigned long ua_flags = uaccess_save_and_enable();
1571 + n = __copy_from_user_std(to, from, n);
1572 + uaccess_restore(ua_flags);
1577 static unsigned long noinline
1578 __clear_user_memset(void __user *addr, unsigned long n)
1579 --- a/arch/arm/mach-bcm/Kconfig
1580 +++ b/arch/arm/mach-bcm/Kconfig
1581 @@ -182,6 +182,30 @@ config ARCH_BCM_53573
1582 The base chip is BCM53573 and there are some packaging modifications
1583 like BCM47189 and BCM47452.
1585 +config ARCH_BCM_63XX
1586 + bool "Broadcom BCM63xx DSL SoC"
1587 + depends on ARCH_MULTI_V7
1588 + select ARCH_HAS_RESET_CONTROLLER
1589 + select ARM_ERRATA_754322
1590 + select ARM_ERRATA_764369 if SMP
1592 + select ARM_GLOBAL_TIMER
1594 + select HAVE_ARM_ARCH_TIMER
1595 + select HAVE_ARM_TWD if SMP
1596 + select HAVE_ARM_SCU if SMP
1598 + This enables support for systems based on Broadcom DSL SoCs.
1599 + It currently supports the 'BCM63XX' ARM-based family, which includes
1600 + the BCM63138 variant.
1602 +config BCM2835_FAST_MEMCPY
1603 + bool "Enable optimized __copy_to_user and __copy_from_user"
1604 + depends on ARCH_BCM2835 && ARCH_MULTI_V6
1607 + Optimized versions of __copy_to_user and __copy_from_user for Pi1.
1610 bool "Broadcom BCM7XXX based boards"
1611 depends on ARCH_MULTI_V7