Bug 77571 - __clear_cache is broken on arm64 for big.little where the cache line sizes are different between cores
Summary: __clear_cache is broken on arm64 for big.little where the cache line sizes ar...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-12 20:52 UTC by Bernhard Urban
Modified: 2016-09-19 14:44 UTC (History)
1 user (show)

See Also:
Host:
Target: aarch64*-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-09-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Urban 2016-09-12 20:52:44 UTC
This patch introduces a problem: https://gcc.gnu.org/ml/gcc-patches/2012-09/msg00076.html and should be at least reverted.

See https://github.com/mono/mono/pull/3549 and http://www.mono-project.com/news/2016/09/12/arm64-icache/

There is also some work going on to fix this on kernel level: https://gcc.gnu.org/ml/gcc-patches/2012-09/msg00076.html
Comment 1 Andrew Pinski 2016-09-12 20:57:28 UTC
Confirmed.
Comment 2 Andrew Pinski 2016-09-12 21:01:01 UTC
really there needs to be no caching at all because the code could migrate between the cores.
Comment 3 Andrew Pinski 2016-09-12 21:03:41 UTC
That is even reverting the patch can still cause issues.  Really this code should just hard code 4 as the smallest size.
Or change the loop to get the sizes through the whole loop.
Comment 4 James Greenhalgh 2016-09-13 15:25:13 UTC
(In reply to Bernhard Urban from comment #0)
> This patch introduces a problem:
> https://gcc.gnu.org/ml/gcc-patches/2012-09/msg00076.html and should be at
> least reverted.
> 
> See https://github.com/mono/mono/pull/3549 and
> http://www.mono-project.com/news/2016/09/12/arm64-icache/
> 
> There is also some work going on to fix this on kernel level:
> https://gcc.gnu.org/ml/gcc-patches/2012-09/msg00076.html

Neither reverting the patch, nor any of the other suggestions in this report (other than hardcoding the size to 4) would remove the potential race condition between reading the size of the cache line and being migrated to a CPU with a smaller cache line size.

The proposed Linux kernel workaround ( http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1227904.html ) will remove the need for a change to GCC in a Linux environment - the value will read as the minimum required for the system. The Kernel is also best placed to enable the workaround only for those systems which require it.

Handling this in user-space is extremely fragile, and will penalize a large number of systems. Such a workaround would require serious thought as to how it was designed and implemented, and which subtargets it was enabled for.

To my mind, the only appropriate place to implement a workaround is the kernel.
Comment 5 Richard Earnshaw 2016-09-19 14:44:47 UTC
This is something the kernel has to address.  If the system has processors with differently sized cache line lengths, then the OS needs to virtualize the relevant system registers to report an appropriate (safe) line length.  Any other approach will likely have race conditions.