I have read the document about the CLFLUSH instruction of Intel x86 machine.
I understand that CLFLUSH m8
means flush the cache line containing linear address m8 if I run the instruction inside a Linux module on the bare metal.
However, what if I want to run the instruction inside a VM in virtualization environment? What the parameter of CLFLUSH
is?
To be specific, suppose I want to flush a cache line that hold the content for virtual address va
of a program in a VM. The virtual address va
is mapped to physical address pa
in the VM, and pa
will be mapped to the machine address ma
in the VMM/hypervisor. Which address should I use for the CLFLUSH
instruction, va
, pa
or ma
?
Thank you very much!
clflush
is not a privileged instruction. User processes can run it, just like they can run load, store, prefetch, and movnt
(store with cache eviction) instructions which also affect the cache.
I expect it virtualizes just fine, without any hypervisor support, since it uses addresses the same way other memory references do.
Since hardware virtualization allows the CPU to do a full translation from guest virtual addresses to hardware physical addresses, the desired behaviour (cache line synced to physical memory) should happen without hypervisor intervention.