From: Matthew Auld <matthew.auld@intel.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: Re: [PATCH 1/7] drm/gpusvm: fix hmm_pfn_to_map_order() usage
Date: Fri, 21 Mar 2025 11:42:45 +0000 [thread overview]
Message-ID: <cdb53bdc-bab5-4c85-9b95-4abbd40641c4@intel.com> (raw)
In-Reply-To: <Z9x9RSvaoexRjj90@lstrano-desk.jf.intel.com>
On 20/03/2025 20:40, Matthew Brost wrote:
> On Thu, Mar 20, 2025 at 05:29:58PM +0000, Matthew Auld wrote:
>> Handle the case where the hmm range partially covers a huge page (like
>> 2M), otherwise we can potentially end up doing something nasty like
>> mapping memory which potentially is outside the range, and maybe not
>> even mapped by the mm. Fix is based on the xe userptr code, which in a
>> future patch will directly use gpusvm, so needs alignment here.
>>
>> Reported-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
>> Cc: Matthew Brost <matthew.brost@intel.com>
>> ---
>> drivers/gpu/drm/drm_gpusvm.c | 25 +++++++++++++++++++++++--
>> 1 file changed, 23 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
>> index 2451c816edd5..48993cef4a74 100644
>> --- a/drivers/gpu/drm/drm_gpusvm.c
>> +++ b/drivers/gpu/drm/drm_gpusvm.c
>> @@ -817,6 +817,27 @@ drm_gpusvm_range_alloc(struct drm_gpusvm *gpusvm,
>> return range;
>> }
>>
>> +/*
>> + * To allow skipping PFNs with the same flags (like when they belong to
>> + * the same huge PTE) when looping over the pfn array, take a given a hmm_pfn,
>> + * and return the largest order that will fit inside the PTE, but also crucially
>> + * accounting for the original hmm range boundaries.
>> + */
>
> I'd make this proper kernel doc given all of drm_gpusvm.c has proper kernel doc.
Ok, typically we don't add kernel-doc for static declarations so didn't
bother. Will make this consistent. Thanks.
>
> Otherwise LGTM.
>
> Matt
>
>> +static unsigned int drm_gpusvm_hmm_pfn_to_order(unsigned long hmm_pfn,
>> + unsigned long hmm_pfn_index,
>> + unsigned long npages)
>> +{
>> + unsigned long size;
>> +
>> + size = 1UL << hmm_pfn_to_map_order(hmm_pfn);
>> + size -= (hmm_pfn & ~HMM_PFN_FLAGS) & (size - 1);
>> + hmm_pfn_index += size;
>> + if (hmm_pfn_index > npages)
>> + size -= (hmm_pfn_index - npages);
>> +
>> + return fls(size) - 1;
>> +}
>> +
>> /**
>> * drm_gpusvm_check_pages() - Check pages
>> * @gpusvm: Pointer to the GPU SVM structure
>> @@ -875,7 +896,7 @@ static bool drm_gpusvm_check_pages(struct drm_gpusvm *gpusvm,
>> err = -EFAULT;
>> goto err_free;
>> }
>> - i += 0x1 << hmm_pfn_to_map_order(pfns[i]);
>> + i += 0x1 << drm_gpusvm_hmm_pfn_to_order(pfns[i], i, npages);
>> }
>>
>> err_free:
>> @@ -1408,7 +1429,7 @@ int drm_gpusvm_range_get_pages(struct drm_gpusvm *gpusvm,
>> for (i = 0, j = 0; i < npages; ++j) {
>> struct page *page = hmm_pfn_to_page(pfns[i]);
>>
>> - order = hmm_pfn_to_map_order(pfns[i]);
>> + order = drm_gpusvm_hmm_pfn_to_order(pfns[i], i, npages);
>> if (is_device_private_page(page) ||
>> is_device_coherent_page(page)) {
>> if (zdd != page->zone_device_data && i > 0) {
>> --
>> 2.48.1
>>
next prev parent reply other threads:[~2025-03-21 11:42 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-20 17:29 [PATCH 0/7] Replace xe_hmm with gpusvm Matthew Auld
2025-03-20 17:29 ` [PATCH 1/7] drm/gpusvm: fix hmm_pfn_to_map_order() usage Matthew Auld
2025-03-20 19:52 ` Thomas Hellström
2025-03-20 20:40 ` Matthew Brost
2025-03-21 11:42 ` Matthew Auld [this message]
2025-03-20 17:29 ` [PATCH 2/7] drm/gpusvm: use more selective dma dir in get_pages() Matthew Auld
2025-03-20 19:31 ` Thomas Hellström
2025-03-20 19:37 ` Matthew Brost
2025-03-20 17:30 ` [PATCH 3/7] drm/gpusvm: mark pages as dirty Matthew Auld
2025-03-20 19:29 ` Thomas Hellström
2025-03-20 19:33 ` Matthew Brost
2025-03-21 11:37 ` Matthew Auld
2025-03-20 17:30 ` [PATCH 4/7] drm/gpusvm: pull out drm_gpusvm_pages substructure Matthew Auld
2025-03-20 20:43 ` Matthew Brost
2025-03-21 11:53 ` Matthew Auld
2025-03-20 17:30 ` [PATCH 5/7] drm/gpusvm: lower get/unmap pages Matthew Auld
2025-03-20 20:59 ` Matthew Brost
2025-03-20 17:30 ` [PATCH 6/7] drm/gpusvm: support basic_range Matthew Auld
2025-03-20 21:04 ` Matthew Brost
2025-03-20 17:30 ` [PATCH 7/7] drm/xe/userptr: replace xe_hmm with gpusvm Matthew Auld
2025-03-20 20:52 ` Matthew Brost
2025-03-25 9:50 ` Ghimiray, Himal Prasad
2025-03-20 17:37 ` ✓ CI.Patch_applied: success for Replace " Patchwork
2025-03-20 17:37 ` ✗ CI.checkpatch: warning " Patchwork
2025-03-20 17:38 ` ✗ CI.KUnit: failure " Patchwork
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=cdb53bdc-bab5-4c85-9b95-4abbd40641c4@intel.com \
--to=matthew.auld@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=thomas.hellstrom@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.