From: Peter Xu <peterx@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: Alistair Popple <apopple@nvidia.com>,
linux-mm@kvack.org, akpm@linux-foundation.org,
Nadav Amit <nadav.amit@gmail.com>,
huang ying <huang.ying.caritas@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
"Sierra Guiza, Alejandro (Alex)" <alex.sierra@amd.com>,
Felix Kuehling <Felix.Kuehling@amd.com>,
Jason Gunthorpe <jgg@nvidia.com>,
John Hubbard <jhubbard@nvidia.com>,
Ralph Campbell <rcampbell@nvidia.com>,
Matthew Wilcox <willy@infradead.org>,
Karol Herbst <kherbst@redhat.com>, Lyude Paul <lyude@redhat.com>,
Ben Skeggs <bskeggs@redhat.com>,
Logan Gunthorpe <logang@deltatee.com>,
paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org,
stable@vger.kernel.org, Huang Ying <ying.huang@intel.com>
Subject: Re: [PATCH v3 2/3] mm/migrate_device.c: Copy pte dirty bit to page
Date: Fri, 26 Aug 2022 17:37:12 -0400 [thread overview]
Message-ID: <Ywk9CKIJMX3z6WIq@xz-m1.local> (raw)
In-Reply-To: <140e7688-b66d-2f6d-fed8-e39da5045420@redhat.com>
On Fri, Aug 26, 2022 at 06:46:02PM +0200, David Hildenbrand wrote:
> On 26.08.22 17:55, Peter Xu wrote:
> > On Fri, Aug 26, 2022 at 04:47:22PM +0200, David Hildenbrand wrote:
> >>> To me anon exclusive only shows this mm exclusively owns this page. I
> >>> didn't quickly figure out why that requires different handling on tlb
> >>> flushs. Did I perhaps miss something?
> >>
> >> GUP-fast is the magic bit, we have to make sure that we won't see new
> >> GUP pins, thus the TLB flush.
> >>
> >> include/linux/mm.h:gup_must_unshare() contains documentation.
> >
> > Hmm.. Shouldn't ptep_get_and_clear() (e.g., xchg() on x86_64) already
> > guarantees that no other process/thread will see this pte anymore
> > afterwards?
>
> You could have a GUP-fast thread that just looked up the PTE and is
> going to pin the page afterwards, after the ptep_get_and_clear()
> returned. You'll have to wait until that thread finished.
IIUC the early tlb flush won't protect concurrent fast-gup from happening,
but I think it's safe because fast-gup will check pte after pinning, so
either:
(1) fast-gup runs before ptep_get_and_clear(), then
page_try_share_anon_rmap() will fail properly, or,
(2) fast-gup runs during or after ptep_get_and_clear(), then fast-gup
will see that either the pte is none or changed, then it'll fail the
fast-gup itself.
>
> Another user that relies on this interaction between GUP-fast and TLB
> flushing is for example mm/ksm.c:write_protect_page()
>
> There is a comment in there explaining the interaction a bit more detailed.
>
> Maybe we'll be able to handle this differently in the future (maybe once
> this turns out to be an actual performance problem). Unfortunately,
> mm->write_protect_seq isn't easily usable because we'd need have to make
> sure we're the exclusive writer.
>
>
> For now, it's not too complicated. For PTEs:
> * try_to_migrate_one() already uses ptep_clear_flush().
> * try_to_unmap_one() already conditionally used ptep_clear_flush().
> * migrate_vma_collect_pmd() was the one case that didn't use it already
> (and I wonder why it's different than try_to_migrate_one()).
I'm not sure whether I fully get the point, but here one major difference
is all the rest handles one page, so a tlb flush alongside with the pte
clear sounds reasonable. Even if so try_to_unmap_one() was modified to use
tlb batching, but then I see that anon exclusive made that batching
conditional. I also have question there on whether we can keep using the
tlb batching even with anon exclusive pages there.
In general, I still don't see how stall tlb could affect anon exclusive
pages on racing with fast-gup, because the only side effect of a stall tlb
is unwanted page update iiuc, the problem is fast-gup doesn't even use tlb,
afaict..
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2022-08-26 21:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-24 3:03 [PATCH v3 1/3] mm/migrate_device.c: Flush TLB while holding PTL Alistair Popple
2022-08-24 3:03 ` [PATCH v3 2/3] mm/migrate_device.c: Copy pte dirty bit to page Alistair Popple
2022-08-24 15:39 ` Peter Xu
2022-08-25 22:21 ` Alistair Popple
2022-08-25 23:27 ` Peter Xu
2022-08-26 1:02 ` Alistair Popple
2022-08-26 1:14 ` Huang, Ying
2022-08-26 14:32 ` Peter Xu
2022-08-26 14:47 ` David Hildenbrand
2022-08-26 15:55 ` Peter Xu
2022-08-26 16:46 ` David Hildenbrand
2022-08-26 21:37 ` Peter Xu [this message]
2022-08-26 22:19 ` David Hildenbrand
2022-08-24 3:03 ` [PATCH v3 3/3] selftests/hmm-tests: Add test for dirty bits Alistair Popple
2022-08-24 8:21 ` [PATCH v3 1/3] mm/migrate_device.c: Flush TLB while holding PTL David Hildenbrand
2022-08-24 12:26 ` Alistair Popple
2022-08-24 12:35 ` David Hildenbrand
2022-08-25 1:36 ` Huang, Ying
2022-08-25 22:35 ` Alistair Popple
2022-08-26 0:56 ` Huang, Ying
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=Ywk9CKIJMX3z6WIq@xz-m1.local \
--to=peterx@redhat.com \
--cc=Felix.Kuehling@amd.com \
--cc=akpm@linux-foundation.org \
--cc=alex.sierra@amd.com \
--cc=apopple@nvidia.com \
--cc=bskeggs@redhat.com \
--cc=david@redhat.com \
--cc=huang.ying.caritas@gmail.com \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=kherbst@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=logang@deltatee.com \
--cc=lyude@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=paulus@ozlabs.org \
--cc=rcampbell@nvidia.com \
--cc=stable@vger.kernel.org \
--cc=willy@infradead.org \
--cc=ying.huang@intel.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