Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Hellstrom, Thomas" <thomas.hellstrom@intel.com>
To: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
	"Auld,  Matthew" <matthew.auld@intel.com>
Cc: "Brost, Matthew" <matthew.brost@intel.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v2] drm/xe/userptr: properly setup pfn_flags_mask
Date: Wed, 26 Feb 2025 19:34:59 +0000	[thread overview]
Message-ID: <597b3cc1928493edcb6538f5f56bf67d0c7894ea.camel@intel.com> (raw)
In-Reply-To: <20250226174748.294285-2-matthew.auld@intel.com>

On Wed, 2025-02-26 at 17:47 +0000, Matthew Auld wrote:
> Currently we just leave it uninitialised, which at first looks
> harmless,
> however we also don't zero out the pfn array, and with pfn_flags_mask
> the idea is to be able set individual flags for a given range of pfn
> or
> completely ignore them, outside of default_flags. So here we end up
> with
> pfn[i] & pfn_flags_mask, and if both are uninitialised we might get
> back
> an unexpected flags value, like asking for read only with
> default_flags,
> but getting back write on top, leading to potentially bogus
> behaviour.
> 
> To fix this ensure we zero the pfn_flags_mask, such that hmm only
> considers the default_flags and not also the initial pfn[i] value.
> 
> v2 (Thomas):
>  - Prefer proper initializer.
> 
> Fixes: 81e058a3e7fd ("drm/xe: Introduce helper to populate userptr")
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@intel.com>
> Cc: <stable@vger.kernel.org> # v6.10+
> ---
>  drivers/gpu/drm/xe/xe_hmm.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_hmm.c
> b/drivers/gpu/drm/xe/xe_hmm.c
> index 089834467880..2e4ae61567d8 100644
> --- a/drivers/gpu/drm/xe/xe_hmm.c
> +++ b/drivers/gpu/drm/xe/xe_hmm.c
> @@ -166,13 +166,20 @@ int xe_hmm_userptr_populate_range(struct
> xe_userptr_vma *uvma,
>  {
>  	unsigned long timeout =
>  		jiffies +
> msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
> -	unsigned long *pfns, flags = HMM_PFN_REQ_FAULT;
> +	unsigned long *pfns;
>  	struct xe_userptr *userptr;
>  	struct xe_vma *vma = &uvma->vma;
>  	u64 userptr_start = xe_vma_userptr(vma);
>  	u64 userptr_end = userptr_start + xe_vma_size(vma);
>  	struct xe_vm *vm = xe_vma_vm(vma);
> -	struct hmm_range hmm_range;
> +	struct hmm_range hmm_range = {
> +		.pfn_flags_mask = 0, /* ignore pfns */
> +		.default_flags = HMM_PFN_REQ_FAULT,
> +		.start = userptr_start,
> +		.end = userptr_end,
> +		.notifier = &uvma->userptr.notifier,
> +		.dev_private_owner = vm->xe,
> +	};
>  	bool write = !xe_vma_read_only(vma);
>  	unsigned long notifier_seq;
>  	u64 npages;
> @@ -199,19 +206,14 @@ int xe_hmm_userptr_populate_range(struct
> xe_userptr_vma *uvma,
>  		return -ENOMEM;
>  
>  	if (write)
> -		flags |= HMM_PFN_REQ_WRITE;
> +		hmm_range.default_flags |= HMM_PFN_REQ_WRITE;
>  
>  	if (!mmget_not_zero(userptr->notifier.mm)) {
>  		ret = -EFAULT;
>  		goto free_pfns;
>  	}
>  
> -	hmm_range.default_flags = flags;
>  	hmm_range.hmm_pfns = pfns;
> -	hmm_range.notifier = &userptr->notifier;
> -	hmm_range.start = userptr_start;
> -	hmm_range.end = userptr_end;
> -	hmm_range.dev_private_owner = vm->xe;
>  
>  	while (true) {
>  		hmm_range.notifier_seq =
> mmu_interval_read_begin(&userptr->notifier);

Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>



  reply	other threads:[~2025-02-26 19:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26 17:47 [PATCH v2] drm/xe/userptr: properly setup pfn_flags_mask Matthew Auld
2025-02-26 19:34 ` Hellstrom, Thomas [this message]
2025-02-26 20:13 ` ✓ CI.Patch_applied: success for drm/xe/userptr: properly setup pfn_flags_mask (rev2) Patchwork
2025-02-26 20:13 ` ✓ CI.checkpatch: " Patchwork
2025-02-26 20:14 ` ✓ CI.KUnit: " Patchwork
2025-02-26 20:31 ` ✓ CI.Build: " Patchwork
2025-02-26 20:33 ` ✓ CI.Hooks: " Patchwork
2025-02-26 20:35 ` ✓ CI.checksparse: " Patchwork
2025-02-26 20:55 ` ✓ Xe.CI.BAT: " Patchwork
2025-02-26 21:57 ` ✗ Xe.CI.Full: 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=597b3cc1928493edcb6538f5f56bf67d0c7894ea.camel@intel.com \
    --to=thomas.hellstrom@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=stable@vger.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