Skip to contentSkip to conversation

fix initrd memcpy

PATCH William Lee Irwin III 2 participants 6 messages Dec 21, 2004

lore
Share & tools
lore

William Lee Irwin III

author Acked-by Acked-by Dave Miller
#0 lore raw

The latter hunk of the forwarded patch has already been applied, so please apply the patch as it appears in the un-forwarded part. I've taken some liberties in adding the Acked/Signed-off lines in what I hope is an agreeable way.

Quoted 4 lines · Jurij Smakov

As a followup: I have tried fiddling more with the memcpy() routine. Insight from Rob Radez and comments in arch/sparc/lib/blockops.S suggest, that __copy_1page assumes that the memory regions copied are aligned on a double-word boundary. I have checked, that in the cramfs case it wasn't

Quoted 8 lines

true, the destination was not aligned on the double-word boundary. So, I have implemented a simple workaround (see patch below), which together with Bob Breuer's iommu.c fix [0] made 2.6.8 kernel to boot on my machine (SS10 with Ross Hypersparc CPU)! I also confirm, that adding the suggested fix to the srmmu.c also [1] breaks sunlance on my machine. With that "fix" the line 'eth0: Memory error, status 88c3, addr 3713ba' is displayed continuously during boot, when it comes to configuring network interfaces. The successful patch for me is:

Index: sparc32-2.6.10-rc3/include/asm-sparc/string.h
=================================--- sparc32-2.6.10-rc3.orig/include/asm-sparc/string.h 2004-06-15 22:18:38.000000000 -0700
+++ sparc32-2.6.10-rc3/include/asm-sparc/string.h 2004-12-20 20:53:00.585527010 -0800
@@ -40,6 +40,9 @@

if(n <= 32) {
__builtin_memcpy(to, from, n);
+ } else if (((unsigned int) to & 7) != 0) {
+ /* Destination is not aligned on the double-word boundary */
+ __memcpy(to, from, n);
} else {
switch(n) {
case PAGE_SIZE:

#1 lore raw
Quoted 4 lines · On Mon, 20 Dec 2004 20:56:27 -0800 William Lee Irwin III <[email protected]>…

The latter hunk of the forwarded patch has already been applied, so please apply the patch as it appears in the un-forwarded part. I've taken some liberties in adding the Acked/Signed-off lines in what I hope is an agreeable way.

For this one it may be advisable to kill this silly attempt to optimize constant count memcpy()'s. GCC knows very well when to do a __builtin_memcpy() expansion vs. a real memcpy call.

All the memcpy --> __memcpy is doing is making it so that the memcpy assembler doesn't need to retain and return the original destination pointer argument.

Sparc64 was doing silly stuff like this too, and it simplified things a lot to just kill all of these macroized optimizations. I did that as follows:

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/07/27 12:55:12-07:00 [email protected]
# [SPARC64]: Kill all this silly inline memcpy handling.
#
# GCC does this well enough.
#
# Signed-off-by: David S. Miller <[email protected]>
#

# include/asm-sparc64/string.h
#   2004/07/27 12:54:49-07:00 [email protected] +1 -25
#   [SPARC64]: Kill all this silly inline memcpy handling.
#   
#   GCC does this well enough.
#   
#   Signed-off-by: David S. Miller <[email protected]>
# 
# include/asm-sparc64/page.h
#   2004/07/27 12:54:49-07:00 [email protected] +1 -1
#   [SPARC64]: Kill all this silly inline memcpy handling.
#   
#   GCC does this well enough.
#   
#   Signed-off-by: David S. Miller <[email protected]>
# 
# arch/sparc64/lib/VIScopy.S
#   2004/07/27 12:54:49-07:00 [email protected] +0 -4
#   [SPARC64]: Kill all this silly inline memcpy handling.
#   
#   GCC does this well enough.
#   
#   Signed-off-by: David S. Miller <[email protected]>
# 
# arch/sparc64/kernel/sparc64_ksyms.c
#   2004/07/27 12:54:49-07:00 [email protected] +0 -1
#   [SPARC64]: Kill all this silly inline memcpy handling.
#   
#   GCC does this well enough.
#   
#   Signed-off-by: David S. Miller <[email protected]>
# 
diff -Nru a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c
--- a/arch/sparc64/kernel/sparc64_ksyms.c	2004-12-20 22:06:27 -08:00
+++ b/arch/sparc64/kernel/sparc64_ksyms.c	2004-12-20 22:06:27 -08:00
@@ -334,7 +334,6 @@
 #endif

/* Special internal versions of library functions. */
-EXPORT_SYMBOL(__memcpy);
EXPORT_SYMBOL(__memset); EXPORT_SYMBOL(_clear_page); EXPORT_SYMBOL(clear_user_page);

arch/sparc64/lib/VIScopy.S +0 -4
diff -Nru a/arch/sparc64/lib/VIScopy.S b/arch/sparc64/lib/VIScopy.S
@@ -306,11 +306,7 @@
 		.globl			__memcpy_begin
 __memcpy_begin:
 
-		.globl			__memcpy
-		.type			__memcpy,@function
-
 memcpy_private:
-__memcpy:
 memcpy:		mov		ASI_P, asi_src			! IEU0	Group
 		brnz,pt		%o2, __memcpy_entry		! CTI
 		 mov		ASI_P, asi_dest			! IEU1
include/asm-sparc64/page.h +1 -1
diff -Nru a/include/asm-sparc64/page.h b/include/asm-sparc64/page.h
@@ -18,7 +18,7 @@
 #define clear_page(X)	_clear_page((void *)(X))
 struct page;
 extern void clear_user_page(void *addr, unsigned long vaddr, struct page *page);
-#define copy_page(X,Y)	__memcpy((void *)(X), (void *)(Y), PAGE_SIZE)
+#define copy_page(X,Y)	memcpy((void *)(X), (void *)(Y), PAGE_SIZE)
 extern void copy_user_page(void *to, void *from, unsigned long vaddr, struct page *topage);
 
 /* GROSS, defining this makes gcc pass these types as aggregates,
include/asm-sparc64/string.h +1 -25
diff -Nru a/include/asm-sparc64/string.h b/include/asm-sparc64/string.h
@@ -16,9 +16,7 @@
 #include <asm/asi.h>
 
 extern void __memmove(void *,const void *,__kernel_size_t);
-extern __kernel_size_t __memcpy(void *,const void *,__kernel_size_t);
 extern void *__memset(void *,int,__kernel_size_t);
-extern void *__builtin_memcpy(void *,const void *,__kernel_size_t);
 extern void *__builtin_memset(void *,int,__kernel_size_t);
 
 #ifndef EXPORT_SYMTAB_STROPS
@@ -37,29 +35,7 @@
 
 #define __HAVE_ARCH_MEMCPY
 
-static inline void *__constant_memcpy(void *to, const void *from, __kernel_size_t n)
-{
-	if(n) {
-		if(n <= 32) {
-			__builtin_memcpy(to, from, n);
-		} else {
-			__memcpy(to, from, n);
-		}
-	}
-	return to;
-}
-
-static inline void *__nonconstant_memcpy(void *to, const void *from, __kernel_size_t n)
-{
-	__memcpy(to, from, n);
-	return to;
-}
-
-#undef memcpy
-#define memcpy(t, f, n) \
-(__builtin_constant_p(n) ? \
- __constant_memcpy((t),(f),(n)) : \
- __nonconstant_memcpy((t),(f),(n)))
+extern void * memcpy(void *,const void *,__kernel_size_t);
 
 #define __HAVE_ARCH_MEMSET
 
#2 lore raw
In reply to William Lee Irwin III
Quoted 5 lines · On Mon, 20 Dec 2004 20:56:27 -0800 William Lee Irwin III wrote:
Quoted 4 lines

The latter hunk of the forwarded patch has already been applied, so please apply the patch as it appears in the un-forwarded part. I've taken some liberties in adding the Acked/Signed-off lines in what I hope is an agreeable way.

Quoted 10 lines · David S. Miller

For this one it may be advisable to kill this silly attempt to optimize constant count memcpy()'s. GCC knows very well when to do a __builtin_memcpy() expansion vs. a real memcpy call.
All the memcpy --> __memcpy is doing is making it so that the memcpy assembler doesn't need to retain and return the original destination pointer argument.
Sparc64 was doing silly stuff like this too, and it simplified things a lot to just kill all of these macroized optimizations. I did that as follows:

This looks tremendously cleaner. I'll look for an ack to see if there are actively participating users lingering about with toolchains that do something unintelligible out of paranoia and then send an analogue of this upstream.

-- wli

author Acked-by
#3 lore raw
In reply to William Lee Irwin III
Quoted 4 lines · William Lee Irwin III

This looks tremendously cleaner. I'll look for an ack to see if there are actively participating users lingering about with toolchains that do something unintelligible out of paranoia and then send an analogue of this upstream.

tentative sparc32 analogue (not booted it yet):

Index: sparc32-2.6.10-rc3/include/asm-sparc/string.h
=================================--- sparc32-2.6.10-rc3.orig/include/asm-sparc/string.h 2004-06-15 22:18:38.000000000 -0700
+++ sparc32-2.6.10-rc3/include/asm-sparc/string.h 2004-12-20 22:50:52.891373098 -0800
@@ -16,7 +16,7 @@
#ifdef __KERNEL__

extern void __memmove(void *,const void *,__kernel_size_t);
-extern __kernel_size_t __memcpy(void *,const void *,__kernel_size_t); +void *memcpy(void *,const void *,__kernel_size_t);
extern __kernel_size_t __memset(void *,int,__kernel_size_t);

#ifndef EXPORT_SYMTAB_STROPS
@@ -33,38 +33,6 @@
})

#define __HAVE_ARCH_MEMCPY
-
-static inline void *__constant_memcpy(void *to, const void *from, __kernel_size_t n) -{
- extern void __copy_1page(void *, const void *);
-
- if(n <= 32) {
- __builtin_memcpy(to, from, n);
- } else {
- switch(n) {
- case PAGE_SIZE:
- __copy_1page(to, from);
- break;
- default:
- __memcpy(to, from, n);
- break;
- }
- }
- return to;
-}
-
-static inline void *__nonconstant_memcpy(void *to, const void *from, __kernel_size_t n) -{
- __memcpy(to, from, n);
- return to;
-}
-
-#undef memcpy
-#define memcpy(t, f, n) \
-(__builtin_constant_p(n) ? \
- __constant_memcpy((t),(f),(n)) : \
- __nonconstant_memcpy((t),(f),(n)))
-
#define __HAVE_ARCH_MEMSET

static inline void *__constant_c_and_count_memset(void *s, char c, __kernel_size_t count)
Index: sparc32-2.6.10-rc3/arch/sparc/lib/checksum.S
=================================--- sparc32-2.6.10-rc3.orig/arch/sparc/lib/checksum.S 2004-06-15 22:19:36.000000000 -0700
+++ sparc32-2.6.10-rc3/arch/sparc/lib/checksum.S 2004-12-20 22:40:19.814615394 -0800
@@ -560,7 +560,7 @@
mov %i0, %o1
mov %i1, %o0
5:
- call __memcpy
+ call memcpy
mov %i2, %o2
tst %o0
bne,a 2f
Index: sparc32-2.6.10-rc3/arch/sparc/kernel/sparc_ksyms.c
=================================--- sparc32-2.6.10-rc3.orig/arch/sparc/kernel/sparc_ksyms.c 2004-11-17 02:25:41.000000000 -0800
+++ sparc32-2.6.10-rc3/arch/sparc/kernel/sparc_ksyms.c 2004-12-20 22:44:37.788397418 -0800
@@ -280,7 +280,6 @@

/* Special internal versions of library functions. */ EXPORT_SYMBOL(__copy_1page);
-EXPORT_SYMBOL(__memcpy);
EXPORT_SYMBOL(__memset); EXPORT_SYMBOL(bzero_1page); EXPORT_SYMBOL(__bzero);
Index: sparc32-2.6.10-rc3/arch/sparc/lib/memcpy.S
=================================--- sparc32-2.6.10-rc3.orig/arch/sparc/lib/memcpy.S 2004-10-07 04:01:27.000000000 -0700
+++ sparc32-2.6.10-rc3/arch/sparc/lib/memcpy.S 2004-12-20 22:40:46.813510938 -0800
@@ -550,9 +550,6 @@
b 3f
add %o0, 2, %o0

-#ifdef __KERNEL__
-FUNC(__memcpy)
-#endif
FUNC(memcpy) /* %o0=dst %o1=src %o2=len */

sub %o0, %o1, %o4

#4 lore raw
In reply to William Lee Irwin III
Quoted 7 lines · On Mon, 20 Dec 2004 23:00:25 -0800 William Lee Irwin III <[email protected]>…
Quoted 4 lines · William Lee Irwin III

This looks tremendously cleaner. I'll look for an ack to see if there are actively participating users lingering about with toolchains that do something unintelligible out of paranoia and then send an analogue of this upstream.

tentative sparc32 analogue (not booted it yet):

Won't work, you have to fixup the memcpy.S code to return the original destination pointer.

And you can't use the SETUP_RETL et al. stuff already there since %g6 is used for the current thread pointer.

#5 lore raw
In reply to William Lee Irwin III
Quoted 1 line · On Mon, 20 Dec 2004 23:00:25 -0800 William Lee Irwin III wrote:
Quoted 1 line

tentative sparc32 analogue (not booted it yet):

Quoted 4 lines · David S. Miller

Won't work, you have to fixup the memcpy.S code to return

And you can't use the SETUP_RETL et al. stuff already there since %g6 is used for the current thread pointer.

Amazingly, the kernel runs anyway, but I'll do that.

-- wli