From: David Hildenbrand <david@redhat.com>
To: Alistair Popple <apopple@nvidia.com>
Cc: "Karim Manaouil" <kmanaouilinux@gmail.com>,
npiggin@gmail.com, akpm@linux-foundation.org,
mike.kravetz@oracle.com, linux-mm@kvack.org,
"Hugh Dickins" <hughd@google.com>,
"Jérôme Glisse" <jglisse@redhat.com>
Subject: Re: mm: Question: pte SMP data race in do_anomyous_page()?
Date: Wed, 31 May 2023 09:27:24 +0200 [thread overview]
Message-ID: <4f21d08c-3e79-6a16-4cd2-8f166b32d0f8@redhat.com> (raw)
In-Reply-To: <87edmxqetp.fsf@nvidia.com>
On 31.05.23 06:55, Alistair Popple wrote:
>
> David Hildenbrand <david@redhat.com> writes:
>
>> On 26.05.23 11:07, Karim Manaouil wrote:
>>> On Thu, May 25, 2023 at 02:55:30PM +0200, David Hildenbrand wrote:
>>>> On 25.05.23 12:06, Karim Manaouil wrote:
>>>>> Hi,
>>>>>
>>>>> In do_anonymous_page(), a new page is allocated and zeroed, and the
>>>>> corresponding page struct is initialised (setting flags PageUptodate,
>>>>> PageSwapBacked, etc. and initialising the various counters).
>>>>>
>>>>> Then, set_pte_at() is called directly without calling smp_wmb() to make
>>>>> the updates above visible on other CPUs.
>>>>>
>>>>> This could race with a page table walker. The walker can read the new pte
>>>>> and try to access the page struct or the page content before the changes
>>>>> above were made visible.
>>>>
>>>> Only after acquiring the page table lock (which the writer first has to
>>>> release), right?
>>> In many cases, the walkers don't take the page table locks (e.g.
>>> mm/hmm.c).
>>
>> Looks like we really should be locking the page table in
>> hmm_vma_walk_pmd() instead of only doing a pte_offset_map().
>>
>> It's all very racy without that ...
>>
>> Even the !pte_present(pte) check is racy ...
>
> hmm_range_fault() on it's own is racy, but it's supposed to be used with
> mmu interval notifiers which provide a sequence number and a driver
> mutex to synchronise against pte changes. See for example
> dmirror_range_snapshot() in lib/test_hmm.c.
>
How is this supposed to work with racing do_swap_page() that converts
!pte_present() -> pte_present() without triggering any mmu notifier AFAIKs?
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2023-05-31 7:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-25 10:06 Karim Manaouil
2023-05-25 12:55 ` David Hildenbrand
[not found] ` <ZHB2wyNtHn6qRWZB@ed.ac.uk>
2023-05-26 9:12 ` David Hildenbrand
2023-05-31 4:55 ` Alistair Popple
2023-05-31 7:27 ` David Hildenbrand [this message]
2023-05-31 12:54 ` Alistair Popple
2023-05-25 13:53 ` Matthew Wilcox
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=4f21d08c-3e79-6a16-4cd2-8f166b32d0f8@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=hughd@google.com \
--cc=jglisse@redhat.com \
--cc=kmanaouilinux@gmail.com \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=npiggin@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox