1 From 30f1537d9b4df93cc77f255109794e25f35dc1b4 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 0103/1085] 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 | 65 ++++
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, 1398 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
721 +++ b/arch/arm/lib/memcpymove.h
724 +Copyright (c) 2013, Raspberry Pi Foundation
725 +Copyright (c) 2013, RISC OS Open Ltd
726 +All rights reserved.
728 +Redistribution and use in source and binary forms, with or without
729 +modification, are permitted provided that the following conditions are met:
730 + * Redistributions of source code must retain the above copyright
731 + notice, this list of conditions and the following disclaimer.
732 + * Redistributions in binary form must reproduce the above copyright
733 + notice, this list of conditions and the following disclaimer in the
734 + documentation and/or other materials provided with the distribution.
735 + * Neither the name of the copyright holder nor the
736 + names of its contributors may be used to endorse or promote products
737 + derived from this software without specific prior written permission.
739 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
740 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
741 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
742 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
743 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
744 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
745 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
746 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
747 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
748 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
751 +.macro unaligned_words backwards, align, use_pld, words, r0, r1, r2, r3, r4, r5, r6, r7, r8
754 + mov r1, r0, lsl #32-align*8
756 + orr r1, r1, r0, lsr #align*8
759 + mov r0, r1, lsr #align*8
761 + orr r0, r0, r1, lsl #32-align*8
767 + mov r2, r0, lsl #32-align*8
769 + orr r2, r2, r1, lsr #align*8
770 + mov r1, r1, lsl #32-align*8
771 + orr r1, r1, r0, lsr #align*8
775 + mov r0, r2, lsr #align*8
777 + orr r0, r0, r1, lsl #32-align*8
778 + mov r1, r1, lsr #align*8
779 + orr r1, r1, r2, lsl #32-align*8
785 + mov r4, r0, lsl #32-align*8
787 + orr r4, r4, r3, lsr #align*8
788 + mov r3, r3, lsl #32-align*8
789 + orr r3, r3, r2, lsr #align*8
790 + mov r2, r2, lsl #32-align*8
791 + orr r2, r2, r1, lsr #align*8
792 + mov r1, r1, lsl #32-align*8
793 + orr r1, r1, r0, lsr #align*8
794 + stmdb D!, {r1, r2, r3, r4}
797 + mov r0, r4, lsr #align*8
799 + orr r0, r0, r1, lsl #32-align*8
800 + mov r1, r1, lsr #align*8
801 + orr r1, r1, r2, lsl #32-align*8
802 + mov r2, r2, lsr #align*8
803 + orr r2, r2, r3, lsl #32-align*8
804 + mov r3, r3, lsr #align*8
805 + orr r3, r3, r4, lsl #32-align*8
806 + stmia D!, {r0, r1, r2, r3}
810 + ldmdb S!, {r4, r5, r6, r7}
811 + mov r8, r0, lsl #32-align*8
812 + ldmdb S!, {r0, r1, r2, r3}
816 + orr r8, r8, r7, lsr #align*8
817 + mov r7, r7, lsl #32-align*8
818 + orr r7, r7, r6, lsr #align*8
819 + mov r6, r6, lsl #32-align*8
820 + orr r6, r6, r5, lsr #align*8
821 + mov r5, r5, lsl #32-align*8
822 + orr r5, r5, r4, lsr #align*8
823 + mov r4, r4, lsl #32-align*8
824 + orr r4, r4, r3, lsr #align*8
825 + mov r3, r3, lsl #32-align*8
826 + orr r3, r3, r2, lsr #align*8
827 + mov r2, r2, lsl #32-align*8
828 + orr r2, r2, r1, lsr #align*8
829 + mov r1, r1, lsl #32-align*8
830 + orr r1, r1, r0, lsr #align*8
831 + stmdb D!, {r5, r6, r7, r8}
832 + stmdb D!, {r1, r2, r3, r4}
834 + ldmib S!, {r1, r2, r3, r4}
835 + mov r0, r8, lsr #align*8
836 + ldmib S!, {r5, r6, r7, r8}
840 + orr r0, r0, r1, lsl #32-align*8
841 + mov r1, r1, lsr #align*8
842 + orr r1, r1, r2, lsl #32-align*8
843 + mov r2, r2, lsr #align*8
844 + orr r2, r2, r3, lsl #32-align*8
845 + mov r3, r3, lsr #align*8
846 + orr r3, r3, r4, lsl #32-align*8
847 + mov r4, r4, lsr #align*8
848 + orr r4, r4, r5, lsl #32-align*8
849 + mov r5, r5, lsr #align*8
850 + orr r5, r5, r6, lsl #32-align*8
851 + mov r6, r6, lsr #align*8
852 + orr r6, r6, r7, lsl #32-align*8
853 + mov r7, r7, lsr #align*8
854 + orr r7, r7, r8, lsl #32-align*8
855 + stmia D!, {r0, r1, r2, r3}
856 + stmia D!, {r4, r5, r6, r7}
861 +.macro memcpy_leading_15bytes backwards, align
862 + movs DAT1, DAT2, lsl #31
865 + ldrmib DAT0, [S, #-1]!
866 + ldrcsh DAT1, [S, #-2]!
867 + strmib DAT0, [D, #-1]!
868 + strcsh DAT1, [D, #-2]!
870 + ldrmib DAT0, [S], #1
871 + ldrcsh DAT1, [S], #2
872 + strmib DAT0, [D], #1
873 + strcsh DAT1, [D], #2
875 + movs DAT1, DAT2, lsl #29
877 + ldrmi DAT0, [S, #-4]!
879 + ldmcsdb S!, {DAT1, DAT2}
881 + ldrcs DAT2, [S, #-4]!
882 + ldrcs DAT1, [S, #-4]!
884 + strmi DAT0, [D, #-4]!
885 + stmcsdb D!, {DAT1, DAT2}
887 + ldrmi DAT0, [S], #4
889 + ldmcsia S!, {DAT1, DAT2}
891 + ldrcs DAT1, [S], #4
892 + ldrcs DAT2, [S], #4
894 + strmi DAT0, [D], #4
895 + stmcsia D!, {DAT1, DAT2}
899 +.macro memcpy_trailing_15bytes backwards, align
903 + ldmcsdb S!, {DAT0, DAT1}
905 + ldrcs DAT1, [S, #-4]!
906 + ldrcs DAT0, [S, #-4]!
908 + ldrmi DAT2, [S, #-4]!
909 + stmcsdb D!, {DAT0, DAT1}
910 + strmi DAT2, [D, #-4]!
913 + ldmcsia S!, {DAT0, DAT1}
915 + ldrcs DAT0, [S], #4
916 + ldrcs DAT1, [S], #4
918 + ldrmi DAT2, [S], #4
919 + stmcsia D!, {DAT0, DAT1}
920 + strmi DAT2, [D], #4
924 + ldrcsh DAT0, [S, #-2]!
925 + ldrmib DAT1, [S, #-1]
926 + strcsh DAT0, [D, #-2]!
927 + strmib DAT1, [D, #-1]
929 + ldrcsh DAT0, [S], #2
931 + strcsh DAT0, [D], #2
936 +.macro memcpy_long_inner_loop backwards, align
939 + ldr DAT0, [S, #-align]!
941 + ldr LAST, [S, #-align]!
947 + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
949 + stmdb D!, {DAT4, DAT5, DAT6, LAST}
950 + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
952 + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
954 + stmia D!, {DAT0, DAT1, DAT2, DAT3}
955 + stmia D!, {DAT4, DAT5, DAT6, LAST}
958 + unaligned_words backwards, align, 1, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
962 + /* Just before the final (prefetch_distance+1) 32-byte blocks, deal with final preloads */
963 + preload_trailing backwards, S, N, OFF
964 + add N, N, #(prefetch_distance+2)*32 - 32
968 + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
969 + stmdb D!, {DAT4, DAT5, DAT6, LAST}
970 + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
972 + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
973 + stmia D!, {DAT0, DAT1, DAT2, DAT3}
974 + stmia D!, {DAT4, DAT5, DAT6, LAST}
977 + unaligned_words backwards, align, 0, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
984 + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
985 + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
987 + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
988 + stmneia D!, {DAT0, DAT1, DAT2, LAST}
992 + unaligned_words backwards, align, 0, 4, DAT0, DAT1, DAT2, DAT3, LAST
995 + /* Trailing words and bytes */
1001 + memcpy_trailing_15bytes backwards, align
1003 + pop {DAT3, DAT4, DAT5, DAT6, DAT7}
1004 + pop {D, DAT1, DAT2, pc}
1007 +.macro memcpy_medium_inner_loop backwards, align
1011 + ldmdb S!, {DAT0, DAT1, DAT2, LAST}
1013 + ldr LAST, [S, #-4]!
1014 + ldr DAT2, [S, #-4]!
1015 + ldr DAT1, [S, #-4]!
1016 + ldr DAT0, [S, #-4]!
1018 + stmdb D!, {DAT0, DAT1, DAT2, LAST}
1021 + ldmia S!, {DAT0, DAT1, DAT2, LAST}
1028 + stmia D!, {DAT0, DAT1, DAT2, LAST}
1032 + /* Trailing words and bytes */
1035 + memcpy_trailing_15bytes backwards, align
1037 + pop {D, DAT1, DAT2, pc}
1040 +.macro memcpy_short_inner_loop backwards, align
1044 + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
1046 + ldrne LAST, [S, #-4]!
1047 + ldrne DAT2, [S, #-4]!
1048 + ldrne DAT1, [S, #-4]!
1049 + ldrne DAT0, [S, #-4]!
1051 + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
1054 + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
1056 + ldrne DAT0, [S], #4
1057 + ldrne DAT1, [S], #4
1058 + ldrne DAT2, [S], #4
1059 + ldrne LAST, [S], #4
1061 + stmneia D!, {DAT0, DAT1, DAT2, LAST}
1063 + memcpy_trailing_15bytes backwards, align
1065 + pop {D, DAT1, DAT2, pc}
1068 +.macro memcpy backwards
1083 + UNWIND( .fnstart )
1085 + push {D, DAT1, DAT2, lr}
1088 + UNWIND( .fnstart )
1089 + UNWIND( .save {D, DAT1, DAT2, lr} )
1096 + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
1099 + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
1100 + cmp N, #(prefetch_distance+3)*32 - 1
1104 + push {DAT3, DAT4, DAT5, DAT6, DAT7}
1107 + UNWIND( .fnstart )
1108 + UNWIND( .save {D, DAT1, DAT2, lr} )
1109 + UNWIND( .save {DAT3, DAT4, DAT5, DAT6, DAT7} )
1111 + /* Adjust N so that the decrement instruction can also test for
1112 + * inner loop termination. We want it to stop when there are
1113 + * (prefetch_distance+1) complete blocks to go. */
1114 + sub N, N, #(prefetch_distance+2)*32
1115 + preload_leading_step1 backwards, DAT0, S
1117 + /* Bug in GAS: it accepts, but mis-assembles the instruction
1118 + * ands DAT2, D, #60, 2
1119 + * which sets DAT2 to the number of leading bytes until destination is aligned and also clears C (sets borrow)
1126 + rsb DAT2, DAT2, #16 /* number of leading bytes until destination aligned */
1128 + preload_leading_step2 backwards, DAT0, S, DAT2, OFF
1129 + memcpy_leading_15bytes backwards, 1
1130 +154: /* Destination now 16-byte aligned; we have at least one prefetch as well as at least one 16-byte output block */
1131 + /* 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 */
1135 + sub OFF, OFF, #32*(prefetch_distance+1)
1138 + rsb OFF, OFF, #32*prefetch_distance
1140 + movs DAT0, S, lsl #31
1144 + memcpy_long_inner_loop backwards, 0
1145 +155: memcpy_long_inner_loop backwards, 1
1146 +156: memcpy_long_inner_loop backwards, 2
1147 +157: memcpy_long_inner_loop backwards, 3
1151 + UNWIND( .fnstart )
1152 + UNWIND( .save {D, DAT1, DAT2, lr} )
1154 +160: /* Medium case */
1155 + preload_all backwards, 0, 0, S, N, DAT2, OFF
1156 + sub N, N, #16 /* simplifies inner loop termination */
1163 + rsb DAT2, DAT2, #16
1165 + memcpy_leading_15bytes backwards, align
1166 +164: /* Destination now 16-byte aligned; we have at least one 16-byte output block */
1169 + memcpy_medium_inner_loop backwards, 0
1170 +140: memcpy_medium_inner_loop backwards, 1
1172 +170: /* Short case, less than 31 bytes, so no guarantee of at least one 16-byte block */
1175 + preload_all backwards, 1, 0, S, N, DAT2, LAST
1181 + ldrb DAT0, [S, #-1]!
1182 + strb DAT0, [D, #-1]!
1184 + ldrb DAT0, [S], #1
1185 + strb DAT0, [D], #1
1189 +174: /* Destination now 4-byte aligned; we have 0 or more output bytes to go */
1192 + memcpy_short_inner_loop backwards, 0
1193 +140: memcpy_short_inner_loop backwards, 1
1212 +++ b/arch/arm/lib/memmove_rpi.S
1215 +Copyright (c) 2013, Raspberry Pi Foundation
1216 +Copyright (c) 2013, RISC OS Open Ltd
1217 +All rights reserved.
1219 +Redistribution and use in source and binary forms, with or without
1220 +modification, are permitted provided that the following conditions are met:
1221 + * Redistributions of source code must retain the above copyright
1222 + notice, this list of conditions and the following disclaimer.
1223 + * Redistributions in binary form must reproduce the above copyright
1224 + notice, this list of conditions and the following disclaimer in the
1225 + documentation and/or other materials provided with the distribution.
1226 + * Neither the name of the copyright holder nor the
1227 + names of its contributors may be used to endorse or promote products
1228 + derived from this software without specific prior written permission.
1230 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1231 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1232 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1233 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
1234 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1235 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1236 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1237 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1238 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1239 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1242 +#include <linux/linkage.h>
1243 +#include <asm/assembler.h>
1244 +#include <asm/unwind.h>
1245 +#include "arm-mem.h"
1246 +#include "memcpymove.h"
1248 +/* Prevent the stack from becoming executable */
1249 +#if defined(__linux__) && defined(__ELF__)
1250 +.section .note.GNU-stack,"",%progbits
1255 + .object_arch armv4
1261 + * void *memmove(void *s1, const void *s2, size_t n);
1263 + * a1 = pointer to destination
1264 + * a2 = pointer to source
1265 + * a3 = number of bytes to copy
1270 +.set prefetch_distance, 3
1274 + bpl memcpy /* pl works even over -1 - 0 and 0x7fffffff - 0x80000000 boundaries */
1278 +++ b/arch/arm/lib/memset_rpi.S
1281 +Copyright (c) 2013, Raspberry Pi Foundation
1282 +Copyright (c) 2013, RISC OS Open Ltd
1283 +All rights reserved.
1285 +Redistribution and use in source and binary forms, with or without
1286 +modification, are permitted provided that the following conditions are met:
1287 + * Redistributions of source code must retain the above copyright
1288 + notice, this list of conditions and the following disclaimer.
1289 + * Redistributions in binary form must reproduce the above copyright
1290 + notice, this list of conditions and the following disclaimer in the
1291 + documentation and/or other materials provided with the distribution.
1292 + * Neither the name of the copyright holder nor the
1293 + names of its contributors may be used to endorse or promote products
1294 + derived from this software without specific prior written permission.
1296 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1297 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1298 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1299 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
1300 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1301 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1302 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1303 +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1304 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1305 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1308 +#include <linux/linkage.h>
1309 +#include "arm-mem.h"
1311 +/* Prevent the stack from becoming executable */
1312 +#if defined(__linux__) && defined(__ELF__)
1313 +.section .note.GNU-stack,"",%progbits
1318 + .object_arch armv4
1324 + * void *memset(void *s, int c, size_t n);
1326 + * a1 = pointer to buffer to fill
1327 + * a2 = byte pattern to fill with (caller-narrowed)
1328 + * a3 = number of bytes to fill
1343 + orr DAT0, DAT0, DAT0, lsl #8
1344 + orr DAT0, DAT0, DAT0, lsl #16
1352 + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
1356 +161: sub N, N, #16 /* simplifies inner loop termination */
1357 + /* Leading words and bytes */
1360 + rsb DAT3, S, #0 /* bits 0-3 = number of leading bytes until aligned */
1361 + movs DAT2, DAT3, lsl #31
1363 + strmib DAT0, [S], #1
1365 + strcsh DAT0, [S], #2
1366 + movs DAT2, DAT3, lsl #29
1368 + strmi DAT0, [S], #4
1370 + stmcsia S!, {DAT0, DAT1}
1371 +164: /* Delayed set up of DAT2 and DAT3 so we could use them as scratch registers above */
1374 + /* Now the inner loop of 16-byte stores */
1375 +165: stmia S!, {DAT0, DAT1, DAT2, DAT3}
1378 +166: /* Trailing words and bytes */
1379 + movs N, N, lsl #29
1380 + stmcsia S!, {DAT0, DAT1}
1381 + strmi DAT0, [S], #4
1383 + strcsh DAT0, [S], #2
1387 +170: /* Short case */
1394 + strb DAT0, [S], #1
1398 + stmneia S!, {DAT0, DAT1, DAT2, DAT3}
1407 +ENDPROC(__memset64)
1408 +ENDPROC(__memset32)
1412 --- a/arch/arm/lib/uaccess_with_memcpy.c
1413 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1415 #include <asm/current.h>
1416 #include <asm/page.h>
1418 +#ifndef COPY_FROM_USER_THRESHOLD
1419 +#define COPY_FROM_USER_THRESHOLD 64
1422 +#ifndef COPY_TO_USER_THRESHOLD
1423 +#define COPY_TO_USER_THRESHOLD 64
1427 pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
1429 @@ -43,7 +51,7 @@ pin_page_for_write(const void __user *_a
1432 pmd = pmd_offset(pud, addr);
1433 - if (unlikely(pmd_none(*pmd)))
1434 + if (unlikely(pmd_none(*pmd) || pmd_bad(*pmd)))
1438 @@ -89,7 +97,46 @@ pin_page_for_write(const void __user *_a
1442 -static unsigned long noinline
1444 +pin_page_for_read(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
1446 + unsigned long addr = (unsigned long)_addr;
1454 + pgd = pgd_offset(current->mm, addr);
1455 + if (unlikely(pgd_none(*pgd) || pgd_bad(*pgd)))
1458 + p4d = p4d_offset(pgd, addr);
1459 + if (unlikely(p4d_none(*p4d) || p4d_bad(*p4d)))
1462 + pud = pud_offset(p4d, addr);
1463 + if (unlikely(pud_none(*pud) || pud_bad(*pud)))
1466 + pmd = pmd_offset(pud, addr);
1467 + if (unlikely(pmd_none(*pmd) || pmd_bad(*pmd)))
1470 + pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl);
1471 + if (unlikely(!pte_present(*pte) || !pte_young(*pte))) {
1472 + pte_unmap_unlock(pte, ptl);
1482 +unsigned long noinline
1483 __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
1485 unsigned long ua_flags;
1486 @@ -137,6 +184,52 @@ out:
1490 +unsigned long noinline
1491 +__copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
1493 + unsigned long ua_flags;
1496 + /* the mmap semaphore is taken only if not in an atomic context */
1497 + atomic = in_atomic();
1500 + mmap_read_lock(current->mm);
1506 + while (!pin_page_for_read(from, &pte, &ptl)) {
1509 + mmap_read_unlock(current->mm);
1510 + if (__get_user(temp, (char __user *)from))
1513 + mmap_read_lock(current->mm);
1516 + tocopy = (~(unsigned long)from & ~PAGE_MASK) + 1;
1520 + ua_flags = uaccess_save_and_enable();
1521 + memcpy(to, (const void *)from, tocopy);
1522 + uaccess_restore(ua_flags);
1527 + pte_unmap_unlock(pte, ptl);
1530 + mmap_read_unlock(current->mm);
1537 arm_copy_to_user(void __user *to, const void *from, unsigned long n)
1539 @@ -147,7 +240,7 @@ arm_copy_to_user(void __user *to, const
1540 * With frame pointer disabled, tail call optimization kicks in
1541 * as well making this test almost invisible.
1544 + if (n < COPY_TO_USER_THRESHOLD) {
1545 unsigned long ua_flags = uaccess_save_and_enable();
1546 n = __copy_to_user_std(to, from, n);
1547 uaccess_restore(ua_flags);
1548 @@ -157,6 +250,32 @@ arm_copy_to_user(void __user *to, const
1553 +unsigned long __must_check
1554 +arm_copy_from_user(void *to, const void __user *from, unsigned long n)
1556 +#ifdef CONFIG_BCM2835_FAST_MEMCPY
1558 + * This test is stubbed out of the main function above to keep
1559 + * the overhead for small copies low by avoiding a large
1560 + * register dump on the stack just to reload them right away.
1561 + * With frame pointer disabled, tail call optimization kicks in
1562 + * as well making this test almost invisible.
1564 + if (n < COPY_TO_USER_THRESHOLD) {
1565 + unsigned long ua_flags = uaccess_save_and_enable();
1566 + n = __copy_from_user_std(to, from, n);
1567 + uaccess_restore(ua_flags);
1569 + n = __copy_from_user_memcpy(to, from, n);
1572 + unsigned long ua_flags = uaccess_save_and_enable();
1573 + n = __copy_from_user_std(to, from, n);
1574 + uaccess_restore(ua_flags);
1579 static unsigned long noinline
1580 __clear_user_memset(void __user *addr, unsigned long n)
1581 --- a/arch/arm/mach-bcm/Kconfig
1582 +++ b/arch/arm/mach-bcm/Kconfig
1583 @@ -182,6 +182,30 @@ config ARCH_BCM_53573
1584 The base chip is BCM53573 and there are some packaging modifications
1585 like BCM47189 and BCM47452.
1587 +config ARCH_BCM_63XX
1588 + bool "Broadcom BCM63xx DSL SoC"
1589 + depends on ARCH_MULTI_V7
1590 + select ARCH_HAS_RESET_CONTROLLER
1591 + select ARM_ERRATA_754322
1592 + select ARM_ERRATA_764369 if SMP
1594 + select ARM_GLOBAL_TIMER
1596 + select HAVE_ARM_ARCH_TIMER
1597 + select HAVE_ARM_TWD if SMP
1598 + select HAVE_ARM_SCU if SMP
1600 + This enables support for systems based on Broadcom DSL SoCs.
1601 + It currently supports the 'BCM63XX' ARM-based family, which includes
1602 + the BCM63138 variant.
1604 +config BCM2835_FAST_MEMCPY
1605 + bool "Enable optimized __copy_to_user and __copy_from_user"
1606 + depends on ARCH_BCM2835 && ARCH_MULTI_V6
1609 + Optimized versions of __copy_to_user and __copy_from_user for Pi1.
1612 bool "Broadcom BCM7XXX based boards"
1613 depends on ARCH_MULTI_V7