Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrew Morton" <akpm@linux-foundation.org>,
	"Mika Penttilä" <mpenttil@redhat.com>
Cc: linux-mm@kvack.org, "Aveline Noir" <jm5905938@gmail.com>,
	"Ralph Campbell" <rcampbell@nvidia.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Shuah Khan" <shuah@kernel.org>,
	"David Hildenbrand" <david@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Michal Hocko" <mhocko@suse.com>
Subject: Re: [PATCH] lib/test_hmm: invalidate all mirrors on device-private migration
Date: Thu, 26 Nov 2026 06:53:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-234914@kernel.org> (raw)
In-Reply-To: <bae41f6fc4114357a8a74c8b958f2bdc.1@linux-foundation.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] lib/test_hmm: dmirror_migrate_to_device() fails on resident
  device pages
- [Medium] lib/test_hmm: dmirror_do_fault() maps subpage 0 on PMD
  device-private fault
--

commit fd992ab990d0dc726b0adb39191efdbd1d7b171d
Author: Andrew Morton <akpm@linux-foundation.org>

lib/test_hmm: invalidate all mirrors on device-private migration

This commit stores the RAM backing subpage instead of the device-private
page in mirror page tables on fault, and removes the same-owner
MMU_NOTIFY_MIGRATE bypass in dmirror_interval_invalidate() so all
mirrors are invalidated on migration.

Link: https://lore.kernel.org/r/20261122015246.d8b6b98ff5a8157168156339@linux-foundation.org
Link: https://lore.kernel.org/r/179535872126.34.4789080961796247940.b4-reply@b4

> diff --git a/lib/test_hmm.c b/lib/test_hmm.c
> index a09a766b15b05..ad68e2636f313 100644
> --- a/lib/test_hmm.c
> +++ b/lib/test_hmm.c
> @@ -290,6 +290,12 @@ static int dmirror_do_fault(struct dmirror *dmirror, struct hmm_range *range)
>  		page = hmm_pfn_to_page(*pfns);
>  		WARN_ON(!page);
>  
> +		if (is_device_private_page(page)) {
> +			struct folio *folio = page_folio(page);
> +			struct page *backing = BACKING_PAGE(&folio->page);
> +
> +			page = backing + folio_page_idx(folio, page);
> +		}
>  		entry = page;
>  		if (*pfns & HMM_PFN_WRITE)
>  			entry = xa_tag_pointer(entry, DPT_XA_TAG_WRITE);

[Severity: Medium]
Does folio_page_idx(folio, page) always evaluate to 0 when faulting a
non-PMD-aligned subpage of a PMD-mapped device-private folio?

When hmm_range_fault() walks a PMD device-private entry starting at a
non-zero offset within the PMD, hmm_vma_handle_absent_pmd() initializes
pfn to the folio's head PFN without adding the within-PMD page offset
((addr & ~PMD_MASK) >> PAGE_SHIFT):

mm/hmm.c:hmm_vma_handle_absent_pmd() {
    ...
	if (softleaf_is_device_private(entry) &&
	    softleaf_to_folio(entry)->pgmap->owner ==
	    range->dev_private_owner) {
		unsigned long cpu_flags = HMM_PFN_VALID |
			hmm_pfn_flags_order(PMD_SHIFT - PAGE_SHIFT);
		unsigned long pfn = softleaf_to_pfn(entry);
		unsigned long i;
    ...
		for (i = 0; addr < end; addr += PAGE_SIZE, i++, pfn++) {
			hmm_pfns[i] &= HMM_PFN_INOUT_FLAGS;
			hmm_pfns[i] |= pfn | cpu_flags;
		}
    ...
}

As a result, hmm_pfn_to_page(*pfns) is &folio->page rather than the
requested tail subpage, so dmirror_do_fault() maps backing subpage 0 into
dmirror->pt.  The new subpage read check in TEST_F(hmm,
migrate_anon_huge_fault) reads subpage 0 instead of subpage npages - 1
and fails its assertion.

> @@ -325,14 +331,6 @@ static bool dmirror_interval_invalidate(struct mmu_interval_notifier *mni,
>  {
>  	struct dmirror *dmirror = container_of(mni, struct dmirror, notifier);
>  
> -	/*
> -	 * Ignore invalidation callbacks for device private pages since
> -	 * the invalidation is handled as part of the migration process.
> -	 */
> -	if (range->event == MMU_NOTIFY_MIGRATE &&
> -	    range->owner == dmirror->mdevice)
> -		return true;
> -
>  	if (mmu_notifier_range_blockable(range))
>  		mutex_lock(&dmirror->mutex);
>  	else if (!mutex_trylock(&dmirror->mutex))

[Severity: Medium]
Does removing this check cause a regression in dmirror_migrate_to_device()
when part of the requested range is already resident in device memory on
the same mirror?

During dmirror_migrate_to_device(), migrate_vma_setup() runs with
MIGRATE_VMA_SELECT_SYSTEM and fires MMU_NOTIFY_MIGRATE across
[args.start, args.end).  Without the same-owner check,
dmirror_interval_invalidate() calls dmirror_do_update() on the migrating
dmirror instance and erases all of its dmirror->pt entries in that range,
including pages already residing on the device (plus the entry at
end >> PAGE_SHIFT because xa_for_each_range() takes an inclusive upper
bound).  Because those already-resident device pages do not have
MIGRATE_PFN_MIGRATE set, dmirror_migrate_finalize_and_map() skips them
and leaves them unmapped in dmirror->pt, causing the verification
dmirror_do_read() at the end of dmirror_migrate_to_device() to fail with
-ENOENT (which breaks TEST_F(hmm, migrate_fault) in hmm-tests).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/bae41f6fc4114357a8a74c8b958f2bdc.1@linux-foundation.org?part=1


      parent reply	other threads:[~2026-11-26  6:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:53 [PATCH] lib/test_hmm: invalidate all mirrors on device-private migration Andrew Morton
2026-11-25 14:15 ` Alexandru Elisei
2026-11-25 14:25   ` Aveline Noir
2026-11-25 15:06     ` Alexandru Elisei
2026-11-25 16:40       ` Mika Penttilä
2026-11-26  1:58         ` Aveline Noir
2026-11-26 12:23         ` Alexandru Elisei
2026-11-25 15:06   ` Mika Penttilä
2026-11-25 15:35 ` Aveline Noir
2026-11-26  6:53 ` sashiko-bot [this message]

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=sashiko-outbox-234914@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=jm5905938@gmail.com \
    --cc=leon@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=mpenttil@redhat.com \
    --cc=rcampbell@nvidia.com \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=vbabka@kernel.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