Why does CLFLUSH exist in x86?

I recently learned about a row hammer attack. To perform this attack, the programmer needs to clear the entire processor cache hierarchy for a certain number of addresses.

My question is: why is CLFLUSH necessary in x86? What are the reasons to ever use this instruction if all L * caches are transparent (i.e. no explicit caching is required)? In addition: is the CPU free to use memory access patterns and thereby ignore the instruction at all?

+8
assembly x86 caching cpu-architecture cache-invalidation
source share
1 answer

Mostly for weird things like cached MMIO areas, I think.

Skylake introduced CLFLUSHOPT's poorly ordered higher performance because it is useful for non-volatile storage connected directly to the memory hierarchy. Flushing the cache ensures that the data will be written to the actual memory and not still dirty on the CPU.

This potentially also matters for non-DMA cache devices if something else can do it in x86. (Probably not, I think all DMAs are now cached.)

I am not an expert in this, and this does not mean that this is a complete answer, covering all use cases.

+6
source share

All Articles