llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

__clear_cache for AArch64 might work incorrectly on Cortex-A53

Open miyuki opened this issue 7 years ago • 1 comments

Bugzilla Link 42483
Version unspecified
OS Linux
CC @kevin-brodsky-arm,@smithp35

Extended Description

According to Arm erratum 824069 (http://infocenter.arm.com/help/topic/com.arm.doc.epm048406/Cortex_A53_MPCore_Software_Developers_Errata_Notice_v20.pdf, page 28) on some releases Cortex-A53 the "dc cvau" instruction (which is used in clear_cache.c:__clear_cache) might not clear the cache line correctly in certain circumstances. As a workaround, it is recommended to use the "dc civac" instruction instead.

miyuki avatar Jul 02 '19 10:07 miyuki

The linux kernel has some support for trapping dc cvau and emulating it. See https://github.com/torvalds/linux/blob/master/arch/arm64/Kconfig#L304 config ARM64_ERRATUM_826319 and config ARM64_ERRATUM_827319 which both default to on. As I understand it the patching is only enabled on the CPU and AMBA versions that are affected.

This would prevent the problem from being seen on Android or Linux. Windows and Apple use an OS routine. From the look of clear_cache.c it is possible that the routine could be called in a bare-metal context or from another OS using compiler-rt such as one of the BSDs.

I'm reluctant to recommend using the less efficient dc civac for everyone in 2019 the last affected bit of hardware Cortex-A53 r0p2 was released in 2013, although it may have made it into more recent bits of hardware

I think we could do one of: 1.) use dc cvau only when linux or ANDROID is defined, dc civac otherwise 2.) put a comment in the code about dc cvau potentially causing problems in old A53 revisions, if you are not using linux. 3.) do nothing as the likelihood of someone using clear_cache outside a linux environment on an affected device is small.

Any other thoughts?

For reference dc cvau: data cache clean by virtual address to point of unification dc civac: data cache clean invalidate by virtual address to point of coherency

An approximation of point of unification is instruction cache, data cache and tlb walks all see the same value. An approximation of point of coherency is all observers of the address, all cores, dma engines etc.

smithp35 avatar Jul 02 '19 13:07 smithp35