[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <dad71615-0eba-4a8d-abfc-979fb815511c@redhat.com>
Date: Thu, 24 Jul 2025 08:46:11 +0300
From: Mika Penttilä <mpenttil@...hat.com>
To: Matthew Brost <matthew.brost@...el.com>
Cc: Francois Dugast <francois.dugast@...el.com>, airlied@...il.com,
akpm@...ux-foundation.org, apopple@...dia.com, baohua@...nel.org,
baolin.wang@...ux.alibaba.com, dakr@...nel.org, david@...hat.com,
donettom@...ux.ibm.com, jane.chu@...cle.com, jglisse@...hat.com,
kherbst@...hat.com, linux-kernel@...r.kernel.org, linux-mm@...ck.org,
lyude@...hat.com, peterx@...hat.com, ryan.roberts@....com, shuah@...nel.org,
simona@...ll.ch, wangkefeng.wang@...wei.com, willy@...radead.org,
ziy@...dia.com, Balbir Singh <balbirs@...dia.com>, jgg@...dia.com,
Leon Romanovsky <leonro@...dia.com>
Subject: Re: [PATCH] mm/hmm: Do not fault in device private pages owned by the
caller
On 7/24/25 08:02, Matthew Brost wrote:
> On Thu, Jul 24, 2025 at 10:25:11AM +1000, Balbir Singh wrote:
>> On 7/23/25 05:34, Francois Dugast wrote:
>>> When the PMD swap entry is device private and owned by the caller,
>>> skip the range faulting and instead just set the correct HMM PFNs.
>>> This is similar to the logic for PTEs in hmm_vma_handle_pte().
>>>
>>> For now, each hmm_pfns[i] entry is populated as it is currently done
>>> in hmm_vma_handle_pmd() but this might not be necessary. A follow-up
>>> optimization could be to make use of the order and skip populating
>>> subsequent PFNs.
>> I think we should test and remove these now
>>
> +Jason, Leon – perhaps either of you can provide insight into why
> hmm_vma_handle_pmd fully populates the HMM PFNs when a higher-order page
> is found.
>
> If we can be assured that changing this won’t break other parts of the
> kernel, I agree it should be removed. A snippet of documentation should
> also be added indicating that when higher-order PFNs are found,
> subsequent PFNs within the range will remain unpopulated. I can verify
> that GPU SVM works just fine without these PFNs being populated.
afaics the device can consume the range as smaller pages also, and some
hmm users depend on that.
> Matt
--Mika
>
>>> Signed-off-by: Francois Dugast <francois.dugast@...el.com>
>>> ---
>>> mm/hmm.c | 25 +++++++++++++++++++++++++
>>> 1 file changed, 25 insertions(+)
>>>
>>> diff --git a/mm/hmm.c b/mm/hmm.c
>>> index f2415b4b2cdd..63ec1b18a656 100644
>>> --- a/mm/hmm.c
>>> +++ b/mm/hmm.c
>>> @@ -355,6 +355,31 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp,
>>> }
>>>
>>> if (!pmd_present(pmd)) {
>>> + swp_entry_t entry = pmd_to_swp_entry(pmd);
>>> +
>>> + /*
>>> + * Don't fault in device private pages owned by the caller,
>>> + * just report the PFNs.
>>> + */
>>> + if (is_device_private_entry(entry) &&
>>> + pfn_swap_entry_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 = swp_offset_pfn(entry);
>>> + unsigned long i;
>>> +
>>> + if (is_writable_device_private_entry(entry))
>>> + cpu_flags |= HMM_PFN_WRITE;
>>> +
>>> + for (i = 0; addr < end; addr += PAGE_SIZE, i++, pfn++) {
>>> + hmm_pfns[i] &= HMM_PFN_INOUT_FLAGS;
>>> + hmm_pfns[i] |= pfn | cpu_flags;
>>> + }
>>> +
>> As discussed, can we remove these.
>>
>>> + return 0;
>>> + }
>> All of this be under CONFIG_ARCH_ENABLE_THP_MIGRATION
>>
>>> +
>>> if (hmm_range_need_fault(hmm_vma_walk, hmm_pfns, npages, 0))
>>> return -EFAULT;
>>> return hmm_pfns_fill(start, end, range, HMM_PFN_ERROR);
>>
>>
>> Balbir Singh
Powered by blists - more mailing lists