Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Kefeng Wang <wangkefeng.wang@huawei.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alistair Popple <apopple@nvidia.com>,
	Gregory Price <gourry@gourry.net>
Cc: Pedro Falcato <pfalcato@suse.de>, Zi Yan <ziy@nvidia.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	linux-mm@kvack.org
Subject: Re: [PATCH v2 1/4] mm: mincore: use walk_page_range_vma() in do_mincore()
Date: Fri, 26 Jun 2026 17:58:25 +0200	[thread overview]
Message-ID: <e759c145-f55a-4b23-8aa7-ae0342a7cebb@kernel.org> (raw)
In-Reply-To: <1b34ac03-edf7-4219-a334-1e7b7292129b@huawei.com>

On 6/26/26 17:21, Kefeng Wang wrote:
> 
> 
> On 6/25/2026 10:38 AM, Andrew Morton wrote:
>> On Mon, 22 Jun 2026 11:23:11 +0800 Kefeng Wang <wangkefeng.wang@huawei.com>
>> wrote:
>>
>>>
>>> Hope Andrew can fix the comments when pickup patches.
>>
>> I added this:
>>
>> --- a/mm/mincore.c~mm-mincore-use-walk_page_range_vma-in-do_mincore-fix
>> +++ a/mm/mincore.c
>> @@ -261,12 +261,7 @@ static long do_mincore(unsigned long add
>>       }
>>         /*
>> -     * walk_page_range_vma() does not call walk_page_test(), which
>> -     * handles VM_PFNMAP VMA by invoking ->pte_hole() to skip the
>> -     * page table walk. Without this check, PFNMAP PTEs would be
>> -     * treated as present by mincore_pte_range(), changing the returned
>> -     * residency status from the historical "not resident" to "resident".
>> -     * Handle VM_PFNMAP explicitly to preserve the original behavior.
>> +     * mincore historically reports PFNMAP mappings as non-resident.
>>        */
>>       if (vma->vm_flags & VM_PFNMAP) {
>>           __mincore_unmapped_range(addr, end, vma, vec);
>> _
>>
> 
> Thanks.
> 
>>
>> Sashiko is OK with your patchset, but it might have found four(!)
>> pre-existing issues:
>>
>>     https://sashiko.dev/#/patchset/20260618092845.3905740-1-
>> wangkefeng.wang@huawei.com
>>
> 
> Sorry for the late, this is pre-existing issue, I am not familiar with
> zone devices, so just focus on my changes and the subsequent
> changes related to mincore.. After a quick review, most of them are not
> issues based on my understanding.
> 
> + CC Alistair and Gregroy for migrate_device.c, also Zi could you help
> to check it?
> 
> 1. mlock.c, ACTION_AGAIN
> 2. migrate_device.c, goto again array overrun / double counting
> 3. migrate_device.c, softleaf_to_folio VM_WARN
> 4. migrate_device.c, pte_pfn / pte_dirty on non-present PTE
> 
> I think issue 4 is real issue, a quick fix is
> 
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 554754eb26ff..3ccc4fc1015c 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -401,7 +401,8 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
>                         bool anon_exclusive;
>                         pte_t swp_pte;
> 
> -                       flush_cache_page(vma, addr, pte_pfn(pte));
> +                       if (pte_present(pte))
> +                               flush_cache_page(vma, addr, pte_pfn(pte));
>                         anon_exclusive = folio_test_anon(folio) &&
>                                           PageAnonExclusive(page);

That looks reasonable.

>                         if (anon_exclusive) {
> @@ -422,8 +423,12 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
>                         migrate->cpages++;
> 
>                         /* Set the dirty flag on the folio now the pte is gone. */
> -                       if (pte_dirty(pte))
> +                       if (pte_present(pte)) {
> +                               if (pte_dirty(pte))
> +                                       folio_mark_dirty(folio);
> +                       } else if (softleaf_is_device_private_write(entry)) {
>                                 folio_mark_dirty(folio);
> +                       }

The pte_presnt() check looks reasonable. But dirty handling is really
responsibility of the device side user.

So likely just

if (pte_present(pte) && pte_dirty(pte))
	folio_mark_dirty(folio);

-- 
Cheers,

David


  reply	other threads:[~2026-06-26 15:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18  9:28 [PATCH v2 0/4] mm: convert to walk_page_range_vma() to eliminate find_vma() Kefeng Wang
2026-06-18  9:28 ` [PATCH v2 1/4] mm: mincore: use walk_page_range_vma() in do_mincore() Kefeng Wang
2026-06-18 11:34   ` David Hildenbrand (Arm)
2026-06-18 11:49   ` Pedro Falcato
2026-06-18 12:58     ` David Hildenbrand (Arm)
2026-06-18 13:01     ` Kefeng Wang
2026-06-18 15:02       ` Pedro Falcato
2026-06-22  3:23         ` Kefeng Wang
2026-06-25  2:38           ` Andrew Morton
2026-06-26 15:21             ` Kefeng Wang
2026-06-26 15:58               ` David Hildenbrand (Arm) [this message]
2026-06-27  2:02                 ` Kefeng Wang
2026-06-18  9:28 ` [PATCH v2 2/4] mm: mprotect: use walk_page_range_vma() in mprotect_fixup() Kefeng Wang
2026-06-18 11:52   ` Pedro Falcato
2026-06-18  9:28 ` [PATCH v2 3/4] mm: mlock: use walk_page_range_vma() in mlock_vma_pages_range() Kefeng Wang
2026-06-18 11:53   ` Pedro Falcato
2026-06-18  9:28 ` [PATCH v2 4/4] mm: migrate_device: use walk_page_range_vma() in migrate_vma_collect() Kefeng Wang
2026-06-18 11:53   ` Pedro Falcato

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=e759c145-f55a-4b23-8aa7-ae0342a7cebb@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=gourry@gourry.net \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=pfalcato@suse.de \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=wangkefeng.wang@huawei.com \
    --cc=ziy@nvidia.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