For example, suppose I have a PageTable value and register its physical address with CR3 register.
#![no_std]
use {
spinning_top::{const_spinlock, Spinlock},
x86_64::structures::paging::PageTable,
};
// The physical address of `PML4` is registered with CR3 register.
static PML4: Spinlock<PageTable> = const_spinlock(PageTable::new());
The processor changes the Accessed bit of an entry of PML4 if a page is accessed. I'm afraid that the optimized code may use a cached value stored in one of the CPU registers or the stack instead of the actual value on memory, causing the use of the old value of the bit.
In this case, the impact should be small, and I don't care the Accessed bit. But, in general, is it safe to have a value that the processor may change unexpectedly (like MMIO and DMA buffer) or a reference to such a value? Or should I do a read-modify-write cycle every time through a raw pointer with read_volatile and write_volatile?