From: Peter Xu <peterx@redhat.com>
To: Linux MM Mailing List <linux-mm@kvack.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
John Hubbard <jhubbard@nvidia.com>, Jan Kara <jack@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
Andrea Arcangeli <aarcange@redhat.com>
Subject: Possible race with page_maybe_dma_pinned?
Date: Wed, 29 Sep 2021 15:57:04 -0400 [thread overview]
Message-ID: <YVTFEAwHEZfUrSCT@t490s> (raw)
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
next reply other threads:[~2021-09-29 19:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-29 19:57 Peter Xu [this message]
2021-09-29 22:47 ` Possible race with page_maybe_dma_pinned? Linus Torvalds
2021-09-30 1:57 ` John Hubbard
2021-09-30 11:11 ` Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YVTFEAwHEZfUrSCT@t490s \
--to=peterx@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=jack@suse.cz \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=linux-mm@kvack.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.