On Sat, Jun 15, 2019 at 01:41:31AM +0300, Kirill A. Shutemov wrote: > On Fri, Jun 14, 2019 at 03:43:35PM +0200, Peter Zijlstra wrote:
> > Not really, it all 'works' because clflush_cache_range() includes mb() > > and page_address() has an address dependency on the store, and there are > > no other sites that will ever change 'keyid', which is all kind of > > fragile. > > Hm. I don't follow how the mb() in clflush_cache_range() relevant... > > Any following access of page's memory by kernel will go through > page_keyid() and therefore I believe there's always address dependency on > the store. > > Am I missing something? The dependency doesn't help with prior calls; consider: addr = page_address(page); *addr = foo; page->key_id = bar; addr2 = page_address(page); Without a barrier() between '*addr = foo' and 'page->key_id = bar', the compiler is allowed to reorder these stores. Now, the clflush stuff we do, that already hard orders things -- we need to be done writing before we start flushing -- so we can/do rely on that, but we should explicitly mention that. Now, for the second part, addr2 must observe bar, because of the address dependency, the compiler is not allowed mess that up, but again, that is something we should put in a comment.