Skip to contentSkip to conversation

memcpy regression

DISCUSSION Michal Sojka 4 participants 16 messages Sep 4, 2015 – Sep 8, 2015 PowerPC

lore
Share & tools
lore
#0 lore raw

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the problem to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 = v4.2-6663-g807249d), my system boots again.

commit 0b05e2d671c40cfb57e66e4e402320d6e056b2f8

Author: LEROY Christophe <[email protected]>
Date:   Tue May 19 12:07:55 2015 +0200

powerpc/32: cacheable_memcpy becomes memcpy

cacheable_memcpy uses dcbz instruction and is more efficient than memcpy when the destination is in RAM. If the destination is in an io area, memcpy_toio() is normally used, not memcpy

This patch renames memcpy as generic_memcpy, and renames cacheable_memcpy as memcpy

On MPC885, we get approximatly 7% increase of the transfer rate on an FTP reception

Best regards,
-Michal Sojka

#1 lore raw
Quoted 8 lines · Michal Sojka

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the problem to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 = v4.2-6663-g807249d), my system boots again.

Do you use mainline code only, or do you have home-made code ?

memcpy() is not supposed to be used on non-cacheable memory. memcpy_toio() is the function to use when copying to non-cacheble area.

When I submitted the patch, I looked for erroneous use of memcpy() and memset().
I found one wrong use of memset() that I changed to memset_io() but I didn't find any misuse of memcpy(). But I may have missed one.

Christophe

#2 lore raw
Quoted 11 lines · Christophe LEROY
Quoted 8 lines · Michal Sojka

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the problem to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 = v4.2-6663-g807249d), my system boots again.

Do you use mainline code only, or do you have home-made code ?

I use mainline only sources with non-mainline device-tree.

Quoted 8 lines

memcpy() is not supposed to be used on non-cacheable memory. memcpy_toio() is the function to use when copying to non-cacheble area.

When I submitted the patch, I looked for erroneous use of memcpy() and memset().
I found one wrong use of memset() that I changed to memset_io() but I didn't find any misuse of memcpy().
But I may have missed one.

I attach my .config, if it helps. I have there

CONFIG_PPC_MPC52xx=y
CONFIG_PPC_MPC5200_SIMPLE=y

so arch/powerpc/platforms/52xx is probably the directory to look. Do you see any mempcy misuse there?

Thanks,
-Michal

#3 lore raw
Quoted 21 lines · Michal Sojka
Quoted 10 lines · Christophe LEROY
Quoted 8 lines · Michal Sojka

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the problem to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 = v4.2-6663-g807249d), my system boots again.

Do you use mainline code only, or do you have home-made code ?

I use mainline only sources with non-mainline device-tree.

Quoted 8 lines

memcpy() is not supposed to be used on non-cacheable memory. memcpy_toio() is the function to use when copying to non-cacheble area.

When I submitted the patch, I looked for erroneous use of memcpy() and memset().
I found one wrong use of memset() that I changed to memset_io() but I didn't find any misuse of memcpy().
But I may have missed one.

Quoted 7 lines

I attach my .config, if it helps. I have there

CONFIG_PPC_MPC52xx=y
CONFIG_PPC_MPC5200_SIMPLE=y

so arch/powerpc/platforms/52xx is probably the directory to look. Do you see any mempcy misuse there?

I only found one suspect use of memcpy() in arch/powerpc/platforms/52xx/ It is in mpc52xx_pm.c but it's linked to CONFIG_PM which is not selected by your .config I'll check in the drivers selected by your .config

In parallele, are you able to try with CONFIG_PPC_EARLY_DEBUG in order to try and locate the blocking point ?

Christophe

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

#4 lore raw
Quoted 29 lines · christophe leroy
Quoted 26 lines · Michal Sojka
Quoted 10 lines · Christophe LEROY
Quoted 8 lines · Michal Sojka

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the problem to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 = v4.2-6663-g807249d), my system boots again.

Do you use mainline code only, or do you have home-made code ?

I use mainline only sources with non-mainline device-tree.

Quoted 8 lines

memcpy() is not supposed to be used on non-cacheable memory. memcpy_toio() is the function to use when copying to non-cacheble area.

When I submitted the patch, I looked for erroneous use of memcpy() and memset().
I found one wrong use of memset() that I changed to memset_io() but I didn't find any misuse of memcpy().
But I may have missed one.

I attach my .config, if it helps. I have there

CONFIG_PPC_MPC52xx=y
CONFIG_PPC_MPC5200_SIMPLE=y

Quoted 7 lines
Quoted 2 lines

so arch/powerpc/platforms/52xx is probably the directory to look. Do you see any mempcy misuse there?

I only found one suspect use of memcpy() in arch/powerpc/platforms/52xx/ It is in mpc52xx_pm.c but it's linked to CONFIG_PM which is not selected by your .config I'll check in the drivers selected by your .config

In parallele, are you able to try with CONFIG_PPC_EARLY_DEBUG in order to try and locate the blocking point ?

I don't get any output from the system even with CONFIG_PPC_EARLY_DEBUG.

-Michal

#5 lore raw
Quoted 30 lines · Michal Sojka
Quoted 29 lines · christophe leroy
Quoted 26 lines · Michal Sojka
Quoted 10 lines · Christophe LEROY
Quoted 8 lines · Michal Sojka

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the problem to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 = v4.2-6663-g807249d), my system boots again.

Do you use mainline code only, or do you have home-made code ?

I use mainline only sources with non-mainline device-tree.

Quoted 8 lines

memcpy() is not supposed to be used on non-cacheable memory. memcpy_toio() is the function to use when copying to non-cacheble area.

When I submitted the patch, I looked for erroneous use of memcpy() and memset().
I found one wrong use of memset() that I changed to memset_io() but I didn't find any misuse of memcpy().
But I may have missed one.

I attach my .config, if it helps. I have there

CONFIG_PPC_MPC52xx=y
CONFIG_PPC_MPC5200_SIMPLE=y

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

so arch/powerpc/platforms/52xx is probably the directory to look. Do you see any mempcy misuse there?

I only found one suspect use of memcpy() in arch/powerpc/platforms/52xx/ It is in mpc52xx_pm.c but it's linked to CONFIG_PM which is not selected by your .config I'll check in the drivers selected by your .config

In parallele, are you able to try with CONFIG_PPC_EARLY_DEBUG in order to try and locate the blocking point ?

I don't get any output from the system even with CONFIG_PPC_EARLY_DEBUG.

Hmm, there is no udbg console for MPC5200. I hacked something up and the earliest place I was able to initialize it is after early_init_devtree() in setup_32.c. Even with this console, I got no output when the problematic patch was applied. So the problem is somewhere earlier.

-Michal

#6 lore raw
Quoted 33 lines · Michal Sojka
Quoted 32 lines · Michal Sojka
Quoted 31 lines · christophe leroy
Quoted 28 lines · Michal Sojka
Quoted 10 lines · Christophe LEROY
Quoted 8 lines · Michal Sojka

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the problem to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 = v4.2-6663-g807249d), my system boots again.

Do you use mainline code only, or do you have home-made code ?

I use mainline only sources with non-mainline device-tree.

Quoted 8 lines

memcpy() is not supposed to be used on non-cacheable memory. memcpy_toio() is the function to use when copying to non-cacheble area.

When I submitted the patch, I looked for erroneous use of memcpy() and memset().
I found one wrong use of memset() that I changed to memset_io() but I didn't find any misuse of memcpy().
But I may have missed one.

I attach my .config, if it helps. I have there

CONFIG_PPC_MPC52xx=y
CONFIG_PPC_MPC5200_SIMPLE=y

so arch/powerpc/platforms/52xx is probably the directory to look. Do you see any mempcy misuse there?

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

I only found one suspect use of memcpy() in arch/powerpc/platforms/52xx/ It is in mpc52xx_pm.c but it's linked to CONFIG_PM which is not selected by your .config I'll check in the drivers selected by your .config

In parallele, are you able to try with CONFIG_PPC_EARLY_DEBUG in order to try and locate the blocking point ?

I don't get any output from the system even with CONFIG_PPC_EARLY_DEBUG.

Hmm, there is no udbg console for MPC5200. I hacked something up and the earliest place I was able to initialize it is after early_init_devtree() in setup_32.c. Even with this console, I got no output when the problematic patch was applied. So the problem is somewhere earlier.

In early_init() in setup_32.c, there is the following comment:
/* First zero the BSS -- use memset_io, some platforms don't have caches on yet */

In that case, when does cache get activated ?

In move_device_tree(), called from early_init_devtree(), there is a call to memcpy(). Can you try replacing it by memcpy_io() ?

Christophe

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

#7 lore raw
Quoted 55 lines · christophe leroy

Le 05/09/2015 02:08, Michal Sojka a =C3=A9crit :

Quoted 45 lines · Michal Sojka
Quoted 44 lines · christophe leroy
Quoted 43 lines

Le 04/09/2015 16:35, Michal Sojka a =C3=A9crit :

Quoted 24 lines · Christophe LEROY
Quoted 11 lines

Le 04/09/2015 15:33, Michal Sojka a =C3=A9crit :

Quoted 9 lines

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the=20 problem
to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 =3D v4.2-6663-g807249d), my system boots again.

Do you use mainline code only, or do you have home-made code ?

I use mainline only sources with non-mainline device-tree.

Quoted 10 lines

memcpy() is not supposed to be used on non-cacheable memory. memcpy_toio() is the function to use when copying to non-cacheble=20 area.

When I submitted the patch, I looked for erroneous use of memcpy()=20 and
memset().
I found one wrong use of memset() that I changed to memset_io() but I didn't find any misuse of memcpy().
But I may have missed one.

Quoted 8 lines

I attach my .config, if it helps. I have there

CONFIG_PPC_MPC52xx=3Dy
CONFIG_PPC_MPC5200_SIMPLE=3Dy

so arch/powerpc/platforms/52xx is probably the directory to look.=20 Do you
see any mempcy misuse there?

I only found one suspect use of memcpy() in=20 arch/powerpc/platforms/52xx/
It is in mpc52xx_pm.c but it's linked to CONFIG_PM which is not=20 selected by your .config
I'll check in the drivers selected by your .config

In parallele, are you able to try with CONFIG_PPC_EARLY_DEBUG in=20 order to try and locate the blocking point ?

Quoted 8 lines
Quoted 1 line

I don't get any output from the system even with CONFIG_PPC_EARLY_DEBUG.

Hmm, there is no udbg console for MPC5200. I hacked something up and=20 the earliest place I was able to initialize it is after=20 early_init_devtree() in setup_32.c. Even with this console, I got no=20 output when the problematic patch was applied. So the problem is=20 somewhere earlier.

Quoted 2 lines

In early_init() in setup_32.c, there is the following comment:
/* First zero the BSS -- use memset_io, some platforms don't have caches=

=20

Quoted 5 lines

on yet */

In that case, when does cache get activated ?

In move_device_tree(), called from early_init_devtree(), there is a call=

=20

Quoted 2 lines

to memcpy().
Can you try replacing it by memcpy_io() ?

I tried replacing it by memcpy_toio(), memcpy_fromio() and by generic_memcpy(). Nothing helped :(

-Michal

#8 lore raw
Quoted 7 lines · Michal Sojka
Quoted 6 lines · christophe leroy

Le 05/09/2015 02:08, Michal Sojka a =C3=A9crit :

Quoted 5 lines · Michal Sojka
Quoted 4 lines · christophe leroy
Quoted 3 lines

Le 04/09/2015 16:35, Michal Sojka a =C3=A9crit :

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Christophe LEROY
Quoted 7 lines

Le 04/09/2015 15:33, Michal Sojka a =C3=A9crit :

Quoted 6 lines

Dear Christophe,

my MPC5200-based system stopped booting recently. I bisected the=20 problem
to your commit below. If I revert that commit (on top of 807249d3ada1ff28a47c4054ca4edd479421b671 =3D v4.2-6663-g807249d), =

my

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 3 lines

system boots again.

Do you use mainline code only, or do you have home-made code ?

I use mainline only sources with non-mainline device-tree.

Quoted 5 lines

memcpy() is not supposed to be used on non-cacheable memory. memcpy_toio() is the function to use when copying to non-cacheble=20 area.

When I submitted the patch, I looked for erroneous use of memcpy()=

=20

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and
memset().
I found one wrong use of memset() that I changed to memset_io() but=

I

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 10 lines
Quoted 2 lines

didn't find any misuse of memcpy().
But I may have missed one.

I attach my .config, if it helps. I have there

CONFIG_PPC_MPC52xx=3Dy
CONFIG_PPC_MPC5200_SIMPLE=3Dy

so arch/powerpc/platforms/52xx is probably the directory to look.=20 Do you
see any mempcy misuse there?

I only found one suspect use of memcpy() in=20 arch/powerpc/platforms/52xx/
It is in mpc52xx_pm.c but it's linked to CONFIG_PM which is not=20 selected by your .config
I'll check in the drivers selected by your .config

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

In parallele, are you able to try with CONFIG_PPC_EARLY_DEBUG in=20 order to try and locate the blocking point ?

I don't get any output from the system even with CONFIG_PPC_EARLY_DEBU=

G.

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines

Hmm, there is no udbg console for MPC5200. I hacked something up and=20 the earliest place I was able to initialize it is after=20 early_init_devtree() in setup_32.c. Even with this console, I got no=20 output when the problematic patch was applied. So the problem is=20 somewhere earlier.

In early_init() in setup_32.c, there is the following comment:
/* First zero the BSS -- use memset_io, some platforms don't have caches=

=20

Quoted 5 lines
Quoted 5 lines

on yet */

In that case, when does cache get activated ?

In move_device_tree(), called from early_init_devtree(), there is a call=

=20

Quoted 5 lines
Quoted 2 lines

to memcpy().
Can you try replacing it by memcpy_io() ?

I tried replacing it by memcpy_toio(), memcpy_fromio() and by generic_memcpy(). Nothing helped :(

I found the problem. The compiler replaces an assignment with a call to memcpy. The following patch fixes the problem for me. However, I'm not sure whether this is the real solution. I guess the compiler is free to generate a call to memcpy wherever it wants so other compilers or other optimization levels may need fixes at other places. What do others think?

-Michal

---------------8<----------------------
From: Michal Sojka <[email protected]>
Date: Sun, 6 Sep 2015 22:44:55 +0200
Subject: [PATCH] powerpc: Fix unbootable system after memcpy optimization

This fixes the problem caused by commit 0b05e2d671c40cfb57e66e4e402320d6e056b2f8. On MPC5200, when using the following version of GCC:

    powerpc-603e-linux-gnu-gcc (OSELAS.Toolchain-2012.12.1) 4.7.2

the system was ubootable.

---
 arch/powerpc/kernel/cputable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/cputable.c +0 -0
index 7d80bfd..c2f1fba 100644
@@ -2121,7 +2121,7 @@ static struct cpu_spec * __init setup_cpu_spec(unsign=

ed long offset,
old =3D *t;
=20
/* Copy everything, then do fixups */
- *t =3D *s;
+ memcpy_toio(t, s, sizeof(struct cpu_spec));
=20
/*
* If we are overriding a previous value derived from the real
--=20
2.5.0

#9 lore raw

Hi Michal,

Thanks for finding the problem.

Quoted 7 lines · Michal Sojka

I found the problem. The compiler replaces an assignment with a call to memcpy. The following patch fixes the problem for me. However, I'm not sure whether this is the real solution. I guess the compiler is free to generate a call to memcpy wherever it wants so other compilers or other optimization levels may need fixes at other places. What do others think?

I think you're right that it's not a good solution, the compiler could generate other calls to memcpy depending on various factors, and people will add new code that causes memcpy to get called and it will break your platform.

Christophe, am I right that the problem here is that your new memcpy() doesn't work until later in boot when caches are enabled?

cheers

#10 lore raw

Hi Michael

Quoted 11 lines · Michael Ellerman

Hi Michal,

Thanks for finding the problem.

Quoted 6 lines · Michal Sojka

I found the problem. The compiler replaces an assignment with a call to memcpy. The following patch fixes the problem for me. However, I'm not sure whether this is the real solution. I guess the compiler is free to generate a call to memcpy wherever it wants so other compilers or other optimization levels may need fixes at other places. What do others think?

Quoted 8 lines

I think you're right that it's not a good solution, the compiler could generate other calls to memcpy depending on various factors, and people will add new code that causes memcpy to get called and it will break your platform.

Christophe, am I right that the problem here is that your new memcpy() doesn't work until later in boot when caches are enabled?

That's right, memset() and memcpy() are for setting/copying data into cacheable RAM.
They are using dczb instruction in order to avoid wasting time loading the cacheline with data that will be overwritten.

memset_io() and memcpy_toio() are the functions to use when using not cacheable memory.

The issue identified by Michal is in function setup_cpu_spec() which is called by identify_cpu(). identify_cpu() is called from early_init(). In the begining of early_init(), there is (code from Paul in 2005)

	/* First zero the BSS -- use memset_io, some platforms don't have
	 * caches on yet */
	memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
			__bss_stop - __bss_start);

It shows that it is already expected that the cache is not active yet and standard memset() shall not be used yet. That's the same with memcpy().

I think GCC uses memcpy() in well known situations like initialising structures or copying structures. Shouldn't we just avoid this kind of actions in the very few early init functions ?

Christophe

#11 lore raw
Quoted 29 lines · Christophe LEROY

Hi Michael

Quoted 7 lines · Michael Ellerman
Quoted 6 lines · Michal Sojka

I found the problem. The compiler replaces an assignment with a call to memcpy. The following patch fixes the problem for me. However, I'm not sure whether this is the real solution. I guess the compiler is free to generate a call to memcpy wherever it wants so other compilers or other optimization levels may need fixes at other places. What do others think?

Quoted 6 lines

I think you're right that it's not a good solution, the compiler could generate other calls to memcpy depending on various factors, and people will add new code that causes memcpy to get called and it will break your platform.

Christophe, am I right that the problem here is that your new memcpy() doesn't work until later in boot when caches are enabled?

That's right, memset() and memcpy() are for setting/copying data into cacheable RAM.
They are using dczb instruction in order to avoid wasting time loading the cacheline with data that will be overwritten.

memset_io() and memcpy_toio() are the functions to use when using not cacheable memory.

The issue identified by Michal is in function setup_cpu_spec() which is called by identify_cpu(). identify_cpu() is called from early_init(). In the begining of early_init(), there is (code from Paul in 2005)

Quoted 7 lines
	/* First zero the BSS -- use memset_io, some platforms don't have
	 * caches on yet */
	memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
			__bss_stop - __bss_start);

It shows that it is already expected that the cache is not active yet and standard memset() shall not be used yet. That's the same with memcpy().

Thanks for the explanation.

Quoted 4 lines

I think GCC uses memcpy() in well known situations like initialising structures or copying structures.
Shouldn't we just avoid this kind of actions in the very few early init functions ?

Which are the "very few" early init functions? Can you make a list, for 32-bit and 64-bit? And can we keep it updated over time and not introduce regressions?

cheers

#12 lore raw
Quoted 36 lines · Michael Ellerman
Quoted 28 lines · Christophe LEROY

Hi Michael

Quoted 7 lines · Michael Ellerman
Quoted 6 lines · Michal Sojka

I found the problem. The compiler replaces an assignment with a call to memcpy. The following patch fixes the problem for me. However, I'm not sure whether this is the real solution. I guess the compiler is free to generate a call to memcpy wherever it wants so other compilers or other optimization levels may need fixes at other places. What do others think?

Quoted 6 lines

I think you're right that it's not a good solution, the compiler could generate other calls to memcpy depending on various factors, and people will add new code that causes memcpy to get called and it will break your platform.

Christophe, am I right that the problem here is that your new memcpy() doesn't work until later in boot when caches are enabled?

That's right, memset() and memcpy() are for setting/copying data into cacheable RAM.
They are using dczb instruction in order to avoid wasting time loading the cacheline with data that will be overwritten.

memset_io() and memcpy_toio() are the functions to use when using not cacheable memory.

The issue identified by Michal is in function setup_cpu_spec() which is called by identify_cpu(). identify_cpu() is called from early_init(). In the begining of early_init(), there is (code from Paul in 2005)

Quoted 7 lines
	/* First zero the BSS -- use memset_io, some platforms don't have
	 * caches on yet */
	memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
			__bss_stop - __bss_start);

It shows that it is already expected that the cache is not active yet and standard memset() shall not be used yet. That's the same with memcpy().

Quoted 9 lines

Thanks for the explanation.

Quoted 4 lines

I think GCC uses memcpy() in well known situations like initialising structures or copying structures.
Shouldn't we just avoid this kind of actions in the very few early init functions ?

Which are the "very few" early init functions? Can you make a list, for 32-bit and 64-bit? And can we keep it updated over time and not introduce regressions?

If the code that runs without caches is concentrated in few files, we may either modify the buildsystem to check whether there is a call to memcpy from these files (e.g. by using nm) or these files can be "prelinked" with special version of memcpy that doesn't require caches. Would any of these be acceptable?

-Michal

#13 lore raw

RnJvbTogTWljaGFsIFNvamthDQo+ID4+IEkgdGhpbmsgR0NDIHVzZXMgbWVtY3B5KCkgaW4gd2Vs bCBrbm93biBzaXR1YXRpb25zIGxpa2UgaW5pdGlhbGlzaW5nDQo+ID4+IHN0cnVjdHVyZXMgb3Ig Y29weWluZyBzdHJ1Y3R1cmVzLg0KPiA+PiBTaG91bGRuJ3Qgd2UganVzdCBhdm9pZCB0aGlzIGtp bmQgb2YgYWN0aW9ucyBpbiB0aGUgdmVyeSBmZXcgZWFybHkgaW5pdA0KPiA+PiBmdW5jdGlvbnMg Pw0KPiA+IFdoaWNoIGFyZSB0aGUgInZlcnkgZmV3IiBlYXJseSBpbml0IGZ1bmN0aW9ucz8gQ2Fu IHlvdSBtYWtlIGEgbGlzdCwgZm9yIDMyLWJpdA0KPiA+IGFuZCA2NC1iaXQ/IEFuZCBjYW4gd2Ug a2VlcCBpdCB1cGRhdGVkIG92ZXIgdGltZSBhbmQgbm90IGludHJvZHVjZSByZWdyZXNzaW9ucz8N Cj4gPg0KPiBJZiB0aGUgY29kZSB0aGF0IHJ1bnMgd2l0aG91dCBjYWNoZXMgaXMgY29uY2VudHJh dGVkIGluIGZldyBmaWxlcywgd2UNCj4gbWF5IGVpdGhlciBtb2RpZnkgdGhlIGJ1aWxkc3lzdGVt IHRvIGNoZWNrIHdoZXRoZXIgdGhlcmUgaXMgYSBjYWxsIHRvDQo+IG1lbWNweSBmcm9tIHRoZXNl IGZpbGVzIChlLmcuIGJ5IHVzaW5nIG5tKSBvciB0aGVzZSBmaWxlcyBjYW4gYmUNCj4gInByZWxp bmtlZCIgd2l0aCBzcGVjaWFsIHZlcnNpb24gb2YgbWVtY3B5IHRoYXQgZG9lc24ndCByZXF1aXJl IGNhY2hlcy4NCj4gV291bGQgYW55IG9mIHRoZXNlIGJlIGFjY2VwdGFibGU/DQoNCldoYXQgYWJv dXQgcnVuLXRpbWUgcGF0Y2hpbmcgbWVtY3B5KCkgYWZ0ZXIgdGhlIGNhY2hlcyBhcmUgaW5pdGlh bGlzZWQ/DQoNCglEYXZpZA0KDQo=

#14 lore raw
Quoted 8 lines · David Laight

From: Michal Sojka

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

I think GCC uses memcpy() in well known situations like initialising structures or copying structures.
Shouldn't we just avoid this kind of actions in the very few early init functions ?

Which are the "very few" early init functions? Can you make a list, for 32-bit and 64-bit? And can we keep it updated over time and not introduce regressions?

Quoted 7 lines
Quoted 5 lines

If the code that runs without caches is concentrated in few files, we may either modify the buildsystem to check whether there is a call to memcpy from these files (e.g. by using nm) or these files can be "prelinked" with special version of memcpy that doesn't require caches. Would any of these be acceptable?

What about run-time patching memcpy() after the caches are initialised?

Yeah, that's the solution we use on 64-bit.

It also means you can have cpu specific optimisations, which can be patched in or out using the cpu feature patching.

cheers

#15 lore raw

PiA+IFdoYXQgYWJvdXQgcnVuLXRpbWUgcGF0Y2hpbmcgbWVtY3B5KCkgYWZ0ZXIgdGhlIGNhY2hl cyBhcmUgaW5pdGlhbGlzZWQ/DQo+IA0KPiBZZWFoLCB0aGF0J3MgdGhlIHNvbHV0aW9uIHdlIHVz ZSBvbiA2NC1iaXQuDQo+IA0KPiBJdCBhbHNvIG1lYW5zIHlvdSBjYW4gaGF2ZSBjcHUgc3BlY2lm aWMgb3B0aW1pc2F0aW9ucywgd2hpY2ggY2FuIGJlIHBhdGNoZWQgaW4NCj4gb3Igb3V0IHVzaW5n IHRoZSBjcHUgZmVhdHVyZSBwYXRjaGluZy4NCg0KSSd2ZSBub3RpY2VkIHg4NiBkb2luZyB0aGF0 Lg0KRm9yIG5ld2VyIEludGVsIHBhcnRzIGl0IHBhdGNoZXMgaW4gJ3JlcCBtb3ZzYicgYnV0IHVu Zm9ydHVuYXRlbHkNCm1lbWNweV9pbyBpcyBhbHdheXMgI2RlZmluZWQgdG8gbWVtY3B5Lg0KDQpG b3IgdW5jYWNoZWQgdGFyZ2V0cyB0aGUgaGFyZHdhcmUgY2FuJ3Qgb3B0aW1pc2UgcmVwIG1vdnNi IC0gc28geW91DQplbmQgdXAgd2l0aCBieXRlIGFjY2Vzc2VzLg0KVGhlc2Ugd29yayBjYW4gYmUg cmF0aGVyIHNsb3dlciB0aGFuIGV4cGVjdGVkLg0KDQpUaGlzIGFsc28gYWZmZWN0cyB1c2Vyc3Bh Y2UgY29waWVzIHRvIG1tYXAoKWVkIFBDSWUgc3BhY2UuDQoNCglEYXZpZA0K