• Linus Torvalds's avatar
    mremap: properly flush TLB before releasing the page · 0f1490a7
    Linus Torvalds authored
    Commit eb66ae03 upstream.
    
    This is a backport to stable 3.18.y, based on Will Deacon's 4.4.y
    backport.
    
    Jann Horn points out that our TLB flushing was subtly wrong for the
    mremap() case.  What makes mremap() special is that we don't follow the
    usual "add page to list of pages to be freed, then flush tlb, and then
    free pages".  No, mremap() obviously just _moves_ the page from one page
    table location to another.
    
    That matters, because mremap() thus doesn't directly control the
    lifetime of the moved page with a freelist: instead, the lifetime of the
    page is controlled by the page table locking, that serializes access to
    the entry.
    
    As a result, we need to flush the TLB not just before releasing the lock
    for the source location (to avoid any concurrent accesses to the entry),
    but also before we release the destination page table lock (to avoid the
    TLB being flushed after somebody else has already done something to that
    page)...
    0f1490a7
mremap.c 15.4 KB