common: memsize: fix occasionally failing alias probing
PATCH 1/1 common: memsize: fix occasionally failing alias probing
From: Emanuele Ghidoli <[email protected]>
probe_ram_size_by_alias() detects whether a probe address still aliases a lower address by writing through one address and reading through the other.
On i.MX95 this occasionally reported a false non-alias when the alias read happened immediately after the write.
A memory barrier alone, mb(), was tested but did not make the failure go away. This suggests that ordering the CPU accesses is not sufficient for this probe, likely because the issue is in the path to the memory controller rather than in the core itself.
Read the written address back before checking the alias address. This appears to force the write to become observable at the probe address before using the alias read to decide whether the tested address range exists.
If the readback does not match the written pattern, restore the saved value and continue with the next check. This keeps the probe robust for addresses that do not reliably retain the test pattern.
--- common/memsize.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
common/memsize.c +18 -2
@@ -145,6 +145,7 @@ long get_ram_size(long *base, long maxsize)long probe_ram_size_by_alias (const struct ram_alias_check *checks) {long save[2 ]; +long pat;int dcache_en =0 ;long ret =0 ;
@@ -161,12 +162,27 @@ long probe_ram_size_by_alias(const struct ram_alias_check *checks)if (dcache_en)dcache_flush_invalidate (s); - *d = ~save[0 ]; + pat = ~save[0 ]; + *d = pat;sync ();if (dcache_en)dcache_flush_invalidate (d); -if (*s != ~save[0 ]) +/* +* Make sure the test pattern is observable at the probe +* address before checking whether it is also visible through +* the alias address. +*/ +if (*d != pat) { + *d = save[1 ]; +sync (); +if (dcache_en) +dcache_flush_invalidate (d); + checks++; +continue ; + } + +if (*s != pat) ret = checks->size;/* Restore content */
Signature · 1 line
2.43.0
Quoted 23 lines · Emanuele Ghidoli
common: memsize: fix occasionally failing alias probing
probe_ram_size_by_alias()detects whether a probe address still aliases a lower address by writing through one address and reading through the other.On i.MX95 this occasionally reported a false non-alias when the alias read happened immediately after the write.
A memory barrier alone,
mb(), was tested but did not make the failure go away. This suggests that ordering the CPU accesses is not sufficient for this probe, likely because the issue is in the path to the memory controller rather than in the core itself.Read the written address back before checking the alias address. This appears to force the write to become observable at the probe address before using the alias read to decide whether the tested address range exists.
If the readback does not match the written pattern, restore the saved value and continue with the next check. This keeps the probe robust for addresses that do not reliably retain the test pattern.
Quoted 5 lines
Fixes 0977448b45e2 ("common: memsize: add RAM size probe based on alias detection")Signed-off-by Emanuele Ghidoli <[email protected]>
common/memsize.c| 20 ++++++++++++++++++--1 file changed, 18 insertions(+), 2 deletions(-)
Quoted 8 lines · Emanuele Ghidoli
probe_ram_size_by_alias()detects whether a probe address still aliases a lower address by writing through one address and reading through the other.On i.MX95 this occasionally reported a false non-alias when the alias read happened immediately after the write.
[...]
Applied to u-boot/master, thanks!
[1/1] common: memsize: fix occasionally failing alias probing
commit: 2c733e6c85576b86358885c0a9462a0337797653
Signature · 1 line
Tom