linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Possible race with page_maybe_dma_pinned?
@ 2021-09-29 19:57 Peter Xu
  2021-09-29 22:47 ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Xu @ 2021-09-29 19:57 UTC (permalink / raw)
  To: Linux MM Mailing List
  Cc: Jason Gunthorpe, Linus Torvalds, John Hubbard, Jan Kara,
	Andrew Morton, Andrea Arcangeli

Hi, all,

It seems to be racy to call page_maybe_dma_pinned() without properly taking the
mm->write_protect_seq lock, which is taken read for fast gup.

Now we have 3 callers of page_maybe_dma_pinned():

        1. page_needs_cow_for_dma
        2. pte_is_pinned
        3. shrink_page_list

The 1st one is good as it takes the seqlock for write properly.  The 2nd & 3rd
are missing, we may need to add them.

The race could trigger when the fast-gup of FOLL_PIN happened right after a
call to page_maybe_dma_pinned() which returned false.  One example for page
reclaim of above case 3:

          fast-gup thread                      page reclaim thread
          ---------------                      -------------------
                                          page_maybe_dma_pinned --> false
                                          put the page into swap cache
      fast-gup with FOLL_PIN
                                          unmap page in pgtables
                                          ...

So commit feb889fb40fa ("mm: don't put pinned pages into the swap cache",
2021-01-17) could still have a small window that will stop working.

Same thing to the pte_is_pinned for clear_refs, which is case 2nd above.

If anyone agrees, and if anyone would like to fix this, please add:

Reported-by: Andrea Arcangeli <aarcange@redhat.com>

As this is originally spotted and reported by Andrea.

Thanks,

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-30 11:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 19:57 Possible race with page_maybe_dma_pinned? Peter Xu
2021-09-29 22:47 ` Linus Torvalds
2021-09-30  1:57   ` John Hubbard
2021-09-30 11:11     ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox