Re: [PATCH v7 12/12] drm/xe/madvise: Accept canonical GPU addresses in xe_vm_madvise_ioctl

Matthew Brost
2026-03-24T03:35:40Z

On Mon, Mar 23, 2026 at 03:01:01PM +0530, Arvind Yadav wrote:
> Userspace passes canonical (sign-extended) GPU addresses where bits 63:48
> mirror bit 47. The internal GPUVM uses non-canonical form (upper bits
> zeroed), so passing raw canonical addresses into GPUVM lookups causes
> mismatches for addresses above 128TiB.
>
> Strip the sign extension with xe_device_uncanonicalize_addr() at the
> top of xe_vm_madvise_ioctl(). Non-canonical addresses are unaffected.
>
> Fixes: ada7486c5668 ("drm/xe: Implement madvise ioctl for xe")
>
> Suggested-by: Matthew Brost <matthew.brost@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>

Reviewed-by: Matthew Brost <matthew.brost@intel.com>

> Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
> ---
> drivers/gpu/drm/xe/xe_vm_madvise.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_vm_madvise.c b/drivers/gpu/drm/xe/xe_vm_madvise.c
> index 4a19da5e86d4..2d03676ee595 100644
> --- a/drivers/gpu/drm/xe/xe_vm_madvise.c
> +++ b/drivers/gpu/drm/xe/xe_vm_madvise.c
> @@ -673,8 +673,15 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data, struct drm_file *fil
> struct xe_device *xe = to_xe_device(dev);
> struct xe_file *xef = to_xe_file(file);
> struct drm_xe_madvise *args = data;
> - struct xe_vmas_in_madvise_range madvise_range = {.addr = args->start,
> - .range = args->range, };
> + struct xe_vmas_in_madvise_range madvise_range = {
> + /*
> + * Userspace may pass canonical (sign-extended) addresses.
> + * Strip the sign extension to get the internal non-canonical
> + * form used by the GPUVM, matching xe_vm_bind_ioctl() behavior.
> + */
> + .addr = xe_device_uncanonicalize_addr(xe, args->start),
> + .range = args->range,
> + };
> struct xe_madvise_details details;
> struct xe_vm *vm;
> struct drm_exec exec;
> @@ -724,7 +731,7 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data, struct drm_file *fil
> if (err)
> goto unlock_vm;
>
> - err = xe_vm_alloc_madvise_vma(vm, args->start, args->range);
> + err = xe_vm_alloc_madvise_vma(vm, madvise_range.addr, args->range);
> if (err)
> goto madv_fini;
>
> @@ -774,7 +781,8 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data, struct drm_file *fil
> madvise_funcs[attr_type](xe, vm, madvise_range.vmas, madvise_range.num_vmas, args,
> &details);
>
> - err = xe_vm_invalidate_madvise_range(vm, args->start, args->start + args->range);
> + err = xe_vm_invalidate_madvise_range(vm, madvise_range.addr,
> + madvise_range.addr + args->range);
>
> if (madvise_range.has_svm_userptr_vmas)
> xe_svm_notifier_unlock(vm);
> --
> 2.43.0
>