From: "David Hildenbrand (Arm)" <david@kernel.org>
To: mpenttil@redhat.com, linux-mm@kvack.org
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
linux-kernel@vger.kernel.org, Jason Gunthorpe <jgg@nvidia.com>,
Leon Romanovsky <leonro@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Balbir Singh <balbirs@nvidia.com>, Zi Yan <ziy@nvidia.com>,
Matthew Brost <matthew.brost@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>
Subject: Re: [PATCH v10 2/5] mm: Add helper to convert HMM pfn to migrate pfn
Date: Tue, 12 May 2026 13:43:55 +0200 [thread overview]
Message-ID: <4a9c4170-c6b7-424c-969c-19240f07e46b@kernel.org> (raw)
In-Reply-To: <20260505184421.2324798-3-mpenttil@redhat.com>
> +
> +/**
> + * migrate_hmm_range_setup() - prepare to migrate a range of memory
> + * @range: contains pointer to struct migrate_vma to be set up.
> + *
> + * When collecting has been done with hmm_range_fault(), this
> + * should be called next, and completes range->migrate by
> + * populating migrate->src[] and migrate->dst[]
> + * using range->hmm_pfns[].
> + * Also, migrate->cpages and migrate->npages get initialized.
> + * After migrate_hmm_range_setup(), range->migrate is good
> + * for the rest of the migrate_vma_* flow.
> + */
> +void migrate_hmm_range_setup(struct hmm_range *range)
> +{
> + struct migrate_vma *migrate = range->migrate;
> +
> + if (!migrate)
> + return;
> +
> + migrate->npages = (migrate->end - migrate->start) >> PAGE_SHIFT;
> + migrate->cpages = 0;
> +
> + for (unsigned long i = 0; i < migrate->npages; i++) {
> + unsigned long pfn = range->hmm_pfns[i];
> +
> + /*
> + * We are only interested in entries to be
> + * migrated.
> + */
> + if (!(pfn & HMM_PFN_MIGRATE)) {
> + migrate->src[i] = 0;
> + migrate->dst[i] = 0;
> + continue;
> + }
> +
> + migrate->cpages++;
> +
> + /* HMM_PFN_MIGRATE without HMM_PFN_VALID denotes the special zero page */
> + if (pfn & (HMM_PFN_VALID))
No need for ()
> + migrate->src[i] = migrate_pfn(page_to_pfn(hmm_pfn_to_page(pfn)))
Is there no easier way to avoid going through a page?
I guess you really just want "migrate_pfn(pfn & ~HMM_PFN_FLAGS)".
Maybe add a hmm_pfn_to_pfn() helper that does the "pfn & ~HMM_PFN_FLAGS" ?
> + | MIGRATE_PFN_MIGRATE;
We (MM folks) usually put the | onto the previous line to then properly indent
the second line
migrate->src[i] = migrate_pfn(page_to_pfn(hmm_pfn_to_page(pfn))) |
MIGRATE_PFN_MIGRATE;
> + else
> + migrate->src[i] = MIGRATE_PFN_MIGRATE;
It might be cleaner to just set migrate->src[i] = 0; here and to unconditionally
migrate->src[i] |= MIGRATE_PFN_MIGRATE;
So you don't have the MIGRATE_PFN_MIGRATE on two paths.
> +
> + migrate->src[i] |= (pfn & HMM_PFN_WRITE) ? MIGRATE_PFN_WRITE : 0;
> + migrate->src[i] |= (pfn & HMM_PFN_COMPOUND) ? MIGRATE_PFN_COMPOUND : 0;
> + migrate->dst[i] = 0;
> + }
> +
> + if (migrate->cpages)
> + migrate_vma_unmap(migrate);
Can you remind me why we do this here, in the setup() phase? The function doc
does not really describe that.
--
Cheers,
David
next prev parent reply other threads:[~2026-05-12 11:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 18:44 [PATCH v10 0/5] Migrate on fault for device pages mpenttil
2026-05-05 18:44 ` [PATCH v10 1/5] mm/Kconfig: changes for migrate " mpenttil
2026-05-05 18:44 ` [PATCH v10 2/5] mm: Add helper to convert HMM pfn to migrate pfn mpenttil
2026-05-12 11:43 ` David Hildenbrand (Arm) [this message]
2026-05-12 12:08 ` Mika Penttilä
2026-05-12 12:44 ` David Hildenbrand (Arm)
2026-05-05 18:44 ` [PATCH v10 3/5] mm/hmm: do the plumbing for HMM to participate in migration mpenttil
2026-05-05 18:44 ` [PATCH v10 4/5] mm: setup device page migration in HMM pagewalk mpenttil
2026-05-05 18:44 ` [PATCH v10 5/5] lib/test_hmm:: add a new testcase for the migrate on fault mpenttil
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=4a9c4170-c6b7-424c-969c-19240f07e46b@kernel.org \
--to=david@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=balbirs@nvidia.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jgg@nvidia.com \
--cc=leonro@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=mpenttil@redhat.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--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