linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: "Sierra Guiza, Alejandro (Alex)" <Alex.Sierra@amd.com>
Cc: "jgg@nvidia.com" <jgg@nvidia.com>,
	"rcampbell@nvidia.com" <rcampbell@nvidia.com>,
	"willy@infradead.org" <willy@infradead.org>,
	"david@redhat.com" <david@redhat.com>,
	"Kuehling, Felix" <Felix.Kuehling@amd.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"linux-xfs@vger.kernel.org" <linux-xfs@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"jglisse@redhat.com" <jglisse@redhat.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>,
	"hch@lst.de" <hch@lst.de>
Subject: Re: [PATCH v1 04/15] mm: add device coherent checker to remove migration pte
Date: Thu, 12 May 2022 12:39:16 +1000	[thread overview]
Message-ID: <87fslfqwyo.fsf@nvdebian.thelocal> (raw)
In-Reply-To: <SN6PR12MB27173F2F37294D6DDBC3457CFDC29@SN6PR12MB2717.namprd12.prod.outlook.com>


"Sierra Guiza, Alejandro (Alex)" <Alex.Sierra@amd.com> writes:

> @apopple@nvidia.com Could you please check this patch? It's somehow related to migrate_device_page() for long term device coherent pages.
>
> Regards,
> Alex Sierra
>> -----Original Message-----
>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Alex
>> Sierra
>> Sent: Thursday, May 5, 2022 4:34 PM
>> To: jgg@nvidia.com
>> Cc: rcampbell@nvidia.com; willy@infradead.org; david@redhat.com;
>> Kuehling, Felix <Felix.Kuehling@amd.com>; apopple@nvidia.com; amd-
>> gfx@lists.freedesktop.org; linux-xfs@vger.kernel.org; linux-mm@kvack.org;
>> jglisse@redhat.com; dri-devel@lists.freedesktop.org; akpm@linux-
>> foundation.org; linux-ext4@vger.kernel.org; hch@lst.de
>> Subject: [PATCH v1 04/15] mm: add device coherent checker to remove
>> migration pte
>>
>> During remove_migration_pte(), entries for device coherent type pages that
>> were not created through special migration ptes, ignore _PAGE_RW flag. This
>> path can be found at migrate_device_page(), where valid vma is not
>> required. In this case, migrate_vma_collect_pmd() is not called and special
>> migration ptes are not set.

It's true that we don't call migrate_vma_collect_pmd() for
migrate_device_page(), but this doesn't imply migration entries are not
created. We still call migrate_vma_unmap() which calls try_to_migrate()
to install migration entries.

When we have a vma migrate_vma_collect_pmd() is a fast path for the
common case a page is only mapped once. So migrate_vma_collect_pmd()
should fairly closely match try_to_migrate_one(). I did experiment
locally with removing the fast path to simplify the code, but it does
provide a meaningful performance improvement so I abandoned it.

I think you're running into the problem addressed by
https://lkml.kernel.org/r/20211018045247.3128058-1-apopple@nvidia.com
but for DEVICE_COHERENT pages.

Based on that I think the approach below is wrong. You should update
try_to_migrate_one() to deal with DEVICE_COHERENT pages. It would make
sense to do that as part of patch 1 in this series.

The problem is that try_to_migrate_one() assumes folio_is_zone_device()
implies it is a DEVICE_PRIVATE page due to the check in
try_to_migrate().

>> Signed-off-by: Alex Sierra <alex.sierra@amd.com>
>> ---
>>  mm/migrate.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/migrate.c b/mm/migrate.c index
>> 6c31ee1e1c9b..e18ddee56f37 100644
>> --- a/mm/migrate.c
>> +++ b/mm/migrate.c
>> @@ -206,7 +206,8 @@ static bool remove_migration_pte(struct folio *folio,
>>  		 * Recheck VMA as permissions can change since migration
>> started
>>  		 */
>>  		entry = pte_to_swp_entry(*pvmw.pte);
>> -		if (is_writable_migration_entry(entry))
>> +		if (is_writable_migration_entry(entry) ||
>> +		    is_device_coherent_page(pfn_to_page(pvmw.pfn)))
>>  			pte = maybe_mkwrite(pte, vma);
>>  		else if (pte_swp_uffd_wp(*pvmw.pte))
>>  			pte = pte_mkuffd_wp(pte);
>> --
>> 2.32.0

  parent reply	other threads:[~2022-05-12  2:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05 21:34 [PATCH v1 00/15] Add MEMORY_DEVICE_COHERENT for coherent device memory mapping Alex Sierra
2022-05-05 21:34 ` [PATCH v1 01/15] mm: add zone device coherent type memory support Alex Sierra
2022-05-12  2:58   ` Alistair Popple
2022-05-12 18:45     ` Sierra Guiza, Alejandro (Alex)
2022-05-05 21:34 ` [PATCH v1 02/15] mm: add device coherent vma selection for memory migration Alex Sierra
2022-05-05 21:34 ` [PATCH v1 03/15] mm: remove the vma check in migrate_vma_setup() Alex Sierra
2022-05-05 21:34 ` [PATCH v1 04/15] mm: add device coherent checker to remove migration pte Alex Sierra
2022-05-05 21:38   ` Sierra Guiza, Alejandro (Alex)
2022-05-05 22:48     ` Alistair Popple
2022-05-12  2:39     ` Alistair Popple [this message]
2022-05-05 21:34 ` [PATCH v1 05/15] mm/gup: migrate device coherent pages when pinning instead of failing Alex Sierra
2022-05-05 21:34 ` [PATCH v1 06/15] drm/amdkfd: add SPM support for SVM Alex Sierra
2022-05-05 21:34 ` [PATCH v1 07/15] drm/amdkfd: coherent type as sys mem on migration to ram Alex Sierra
2022-05-05 21:34 ` [PATCH v1 08/15] lib: test_hmm add ioctl to get zone device type Alex Sierra
2022-05-05 21:34 ` [PATCH v1 09/15] lib: test_hmm add module param for " Alex Sierra
2022-05-05 21:34 ` [PATCH v1 10/15] lib: add support for device coherent type in test_hmm Alex Sierra
2022-05-05 21:34 ` [PATCH v1 11/15] tools: update hmm-test to support device coherent type Alex Sierra
2022-05-05 21:34 ` [PATCH v1 12/15] tools: update test_hmm script to support SP config Alex Sierra
2022-05-05 21:34 ` [PATCH v1 13/15] mm: handling Non-LRU pages returned by vm_normal_pages Alex Sierra
2022-05-11 18:50   ` Jason Gunthorpe
2022-05-12 22:33     ` Sierra Guiza, Alejandro (Alex)
2022-05-13 11:45       ` Jason Gunthorpe
2022-05-05 21:34 ` [PATCH v1 14/15] tools: add hmm gup tests for device coherent type Alex Sierra
2022-05-16  8:02   ` Alistair Popple
2022-05-05 21:34 ` [PATCH v1 15/15] tools: add selftests to hmm for COW in device memory Alex Sierra

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=87fslfqwyo.fsf@nvdebian.thelocal \
    --to=apopple@nvidia.com \
    --cc=Alex.Sierra@amd.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=david@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hch@lst.de \
    --cc=jgg@nvidia.com \
    --cc=jglisse@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=rcampbell@nvidia.com \
    --cc=willy@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).