Race between flush_cache_page and flush_tlb_page

Karim Manaouil k.manaouil at gmail.com
Thu May 4 06:30:41 EDT 2023


Hi,

In try_to_unmap_one(), flush_cache_page() [1] is called before
flush_tlb_page() [2].

The following scenario can happen:

cpu0:                                            cpu1:
flush_cache_page()
                                                     User writes to page
ptep_clear_flush()

Since the two operations on cpu0 are not atomic, a write from the user
can happen
right after flush_cache_page() is called, but before flushing the tlb.
Thus there is a risk
the last updates from the user on cpu1 won't be flushed to memory.

I understand that not all CPUs need flush_cache_page, but for those
that require it,
how is correctness guaranteed in this case?

[1] https://elixir.bootlin.com/linux/latest/source/mm/rmap.c#L1572
[2] https://elixir.bootlin.com/linux/latest/source/mm/rmap.c#L1587

Cheers
Karim



More information about the Kernelnewbies mailing list