Re: [RFC 07/15] drm/xe: Move ASID to FAULT VM lookup to xe_device

Ghimiray, Himal Prasad
2026-04-07T06:41:47Z

On 03-04-2026 03:20, Matthew Brost wrote:
> On Wed, Mar 18, 2026 at 01:14:48PM +0530, Himal Prasad Ghimiray wrote:
>> Move xe_pagefault_asid_to_vm() to xe_device.c as
>> xe_device_asid_to_fault_vm() for reuse in access counter handling.
>>
>> Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
>> ---
>> drivers/gpu/drm/xe/xe_device.c | 25 +++++++++++++++++++++++++
>> drivers/gpu/drm/xe/xe_device.h | 1 +
>> drivers/gpu/drm/xe/xe_pagefault.c | 16 +---------------
>> 3 files changed, 27 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
>> index 8773c2d2f69a..ba2f0e345257 100644
>> --- a/drivers/gpu/drm/xe/xe_device.c
>> +++ b/drivers/gpu/drm/xe/xe_device.c
>> @@ -1399,3 +1399,28 @@ struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid)
>>
>> return vm;
>> }
>> +
>> +/**
>> + * xe_device_asid_to_fault_vm() - Find FAULT VM from ASID
>> + * @xe: the &xe_device
>> + * @asid: Address space ID
>> + *
>> + * Find a FAULTING VM from ASID and take a reference to VM which
>> + * caller must drop. Reclaim safe.
>> + *
>> + * Return: VM on success, ERR_PTR on failure
>> + */
>> +struct xe_vm *xe_device_asid_to_fault_vm(struct xe_device *xe, u32 asid)
>
> I think the recently merged xe_pagefault_save_to_vm() function can reuse
> this function now too.

For xe_pagefault_save_to_vm we need to use existing function
xe_device_asid_to_vm instead of xe_device_asid_to_fault_vm(). Will
submit patch for same too.

Thanks.

>
> Patch LGTM to though.
>
> Matt
>
>> +{
>> + struct xe_vm *vm;
>> +
>> + down_read(&xe->usm.lock);
>> + vm = xa_load(&xe->usm.asid_to_vm, asid);
>> + if (vm && xe_vm_in_fault_mode(vm))
>> + xe_vm_get(vm);
>> + else
>> + vm = ERR_PTR(-EINVAL);
>> + up_read(&xe->usm.lock);
>> +
>> + return vm;
>> +}
>> diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h
>> index c4d267002661..e746f5c7cce0 100644
>> --- a/drivers/gpu/drm/xe/xe_device.h
>> +++ b/drivers/gpu/drm/xe/xe_device.h
>> @@ -209,6 +209,7 @@ int xe_is_injection_active(void);
>> bool xe_is_xe_file(const struct file *file);
>>
>> struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid);
>> +struct xe_vm *xe_device_asid_to_fault_vm(struct xe_device *xe, u32 asid);
>>
>> /*
>> * Occasionally it is seen that the G2H worker starts running after a delay of more than
>> diff --git a/drivers/gpu/drm/xe/xe_pagefault.c b/drivers/gpu/drm/xe/xe_pagefault.c
>> index 8c159e3512ee..a4ee9393e4af 100644
>> --- a/drivers/gpu/drm/xe/xe_pagefault.c
>> +++ b/drivers/gpu/drm/xe/xe_pagefault.c
>> @@ -121,20 +121,6 @@ xe_pagefault_access_is_atomic(enum xe_pagefault_access_type access_type)
>> return (access_type & XE_PAGEFAULT_ACCESS_TYPE_MASK) == XE_PAGEFAULT_ACCESS_TYPE_ATOMIC;
>> }
>>
>> -static struct xe_vm *xe_pagefault_asid_to_vm(struct xe_device *xe, u32 asid)
>> -{
>> - struct xe_vm *vm;
>> -
>> - down_read(&xe->usm.lock);
>> - vm = xa_load(&xe->usm.asid_to_vm, asid);
>> - if (vm && xe_vm_in_fault_mode(vm))
>> - xe_vm_get(vm);
>> - else
>> - vm = ERR_PTR(-EINVAL);
>> - up_read(&xe->usm.lock);
>> -
>> - return vm;
>> -}
>>
>> static int xe_pagefault_service(struct xe_pagefault *pf)
>> {
>> @@ -149,7 +135,7 @@ static int xe_pagefault_service(struct xe_pagefault *pf)
>> if (pf->consumer.fault_type_level == XE_PAGEFAULT_TYPE_LEVEL_NACK)
>> return -EFAULT;
>>
>> - vm = xe_pagefault_asid_to_vm(xe, pf->consumer.asid);
>> + vm = xe_device_asid_to_fault_vm(xe, pf->consumer.asid);
>> if (IS_ERR(vm))
>> return PTR_ERR(vm);
>>
>> --
>> 2.34.1
>>