• Kirill A. Shutemov's avatar
    mm: make compound_head() robust · 1d798ca3
    Kirill A. Shutemov authored
    Hugh has pointed that compound_head() call can be unsafe in some
    context. There's one example:
    
    	CPU0					CPU1
    
    isolate_migratepages_block()
      page_count()
        compound_head()
          !!PageTail() == true
    					put_page()
    					  tail->first_page = NULL
          head = tail->first_page
    					alloc_pages(__GFP_COMP)
    					   prep_compound_page()
    					     tail->first_page = head
    					     __SetPageTail(p);
          !!PageTail() == true
        <head == NULL dereferencing>
    
    The race is pure theoretical. I don't it's possible to trigger it in
    practice. But who knows.
    
    We can fix the race by changing how encode PageTail() and compound_head()
    within struct page to be able to update them in one shot.
    
    The patch introduces page->compound_head into third double word block in
    front of compound_dtor and compound_order. Bit 0 encodes PageTail() and
    the rest bits are pointer to head page if bit zero is set.
    
    The patch moves page->pmd_huge_pte out of word, just in case if an
    architecture defines pgtabl...
    1d798ca3
Kconfig 22.3 KB