drm/xe: Enable scratch page when page fault is enabled
Subsystems (2)
PATCH 1/1 drm/xe: Enable scratch page when page fault is enabled
This is just a proposal and not fully tested yet. Once it is got agreenment, more efforts needed to make it fully working, including igt test changes.
i915 can use scratch page even when page fault is enabled, this patch is trying to port this feature over.
The current i915 solution changes page table directly which may be hard to make to upstream, so a more complex solution is needed to apply to the current Xe framework if following the existing i915 solution.
This patch is trying to make the minimum impact to the existing driver, but still enable the scratch page support.
So, the idea is to bind a scratch vma if the page fault is from an invalid access. This patch is taking advantage of null pte at this point, we may introduce a special vma for scratch vma if needed. After the bind, the user app can continue to run without causing a fatal failure or reset and stop.
In case the app will bind this scratch vma to a valid address, it will fail the bind, this patch will handle the failre and unbind the scrach vma[s], so that the user binding will be retried to the valid address.
This patch only kicks in when there is a failure for both page fault and bind, so it should has no impact to the exiating code path. On another hand, it uses actual page tables instead of special scratch page tables, so it enables potential not to invalidate TLBs when doing unbind if all upper layer page tables are still being used.
--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 8 +++-- drivers/gpu/drm/xe/xe_vm.c | 52 ++++++++++++++++++++++++---- drivers/gpu/drm/xe/xe_vm.h | 2 ++ 3 files changed, 53 insertions(+), 9 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +6 -2
@@ -138,8 +138,12 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf) write_locked = true; vma =lookup_vma (vm, pf->page_addr);if (!vma) { - ret = -EINVAL ; - goto unlock_vm; +if (vm->flags &XE_VM_FLAG_SCRATCH_PAGE ) + ret =xe_bind_scratch_vma (vm, pf->page_addr,SZ_64K ); +else + ret = -EINVAL ; +if (ret) + goto unlock_vm; }if (!xe_vma_is_userptr (vma) || !xe_vma_userptr_check_repin (vma)) {
drivers/gpu/drm/xe/xe_vm.c +45 -7
78 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +2 -0
@@ -140,6 +140,8 @@ static inline void xe_vm_queue_rebind_worker(struct xe_vm *vm)queue_work (vm->xe->ordered_wq, &vm->preempt.rebind_work); } +int xe_bind_scratch_vma (struct xe_vm *vm,u64 addr,u64 size); +/* * XE_ONSTACK_TV is used to size the tv_onstack array that is input * to xe_vm_lock_dma_resv() and xe_vm_unlock_dma_resv().
Signature · 1 line
2.25.1
Patchwork
CI[Intel-xe] ✗ CI.Patch_applied: failure for drm/xe: Enable scratch page when page fault is enabled
== Series Details ==
== Series Details ==
Series: drm/xe: Enable scratch page when page fault is enabled
URL : https://patchwork.freedesktop.org/series/120480/
State : failure
== Summary ==
=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: d39e49e2a drm/xe: Port Xe to GPUVA
=== git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_vm.c:2603
error: drivers/gpu/drm/xe/xe_vm.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Applying: drm/xe: Enable scratch page when page fault is enabled Patch failed at 0001 drm/xe: Enable scratch page when page fault is enabled When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
Hi Bruce,
Why do we want to enable scratch page on xe driver? Mapping whole process address space to scratch page or mapping invalid (aka out of bound) GPU virtual address to scratch page can hide application programming bug. It can even hide kmd or GPU HW bug. My philosophy is, when there is a bug, fail the application immediately and let user know the problem immediately. Hiding issues fails us for long run.
On I915, this feature has caused us a lot of troubles. Once it is enabled, application can depend on it so it is very hard to remove. As you know our plan is to disable scratch page on i915. So I don't understand why we want enable this "feature" in the first place.
Thanks,
Oak
Quoted 181 lines
-----Original Message-----
From: Chang, Yu bruce <[email protected]>
Sent: July 10, 2023 6:07 PM
To: [email protected]
Cc: Chang, Yu bruce <[email protected]>; Zeng, Oak <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Summers, Stuart <[email protected]>; Brost, Matthew <[email protected]>
Subject: [PATCH] drm/xe: Enable scratch page when page fault is enabledThis is just a proposal and not fully tested yet. Once it is got agreenment, more efforts needed to make it fully working, including igt test changes.
i915 can use scratch page even when page fault is enabled, this patch is trying to port this feature over.
The current i915 solution changes page table directly which may be hard to make to upstream, so a more complex solution is needed to apply to the current Xe framework if following the existing i915 solution.
This patch is trying to make the minimum impact to the existing driver, but still enable the scratch page support.
So, the idea is to bind a scratch vma if the page fault is from an invalid access. This patch is taking advantage of null pte at this point, we may introduce a special vma for scratch vma if needed. After the bind, the user app can continue to run without causing a fatal failure or reset and stop.
In case the app will bind this scratch vma to a valid address, it will fail the bind, this patch will handle the failre and unbind the scrach vma[s], so that the user binding will be retried to the valid address.
This patch only kicks in when there is a failure for both page fault and bind, so it should has no impact to the exiating code path. On another hand, it uses actual page tables instead of special scratch page tables, so it enables potential not to invalidate TLBs when doing unbind if all upper layer page tables are still being used.
Cc Oak Zeng <[email protected]>Cc Brian Welty <[email protected]>Cc Niranjana Vishwanathapura <[email protected]>Cc Stuart Summers <[email protected]>Cc Matthew Brost <[email protected]>Signed-off-by Bruce Chang <[email protected]>--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 8 +++-- drivers/gpu/drm/xe/xe_vm.c | 52 ++++++++++++++++++++++++---- drivers/gpu/drm/xe/xe_vm.h | 2 ++ 3 files changed, 53 insertions(+), 9 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +6
-2@@ -138,8 +138,12 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf) write_locked = true; vma =lookup_vma (vm, pf->page_addr);if (!vma) { - ret = -EINVAL ; - goto unlock_vm; +if (vm->flags &XE_VM_FLAG_SCRATCH_PAGE ) + ret =xe_bind_scratch_vma (vm, pf->page_addr,SZ_64K ); +else + ret = -EINVAL ; +if (ret) + goto unlock_vm; }drivers/gpu/drm/xe/xe_gt_pagefault.c +0
-0if (!xe_vma_is_userptr (vma) || !xe_vma_userptr_check_repin (vma)) {drivers/gpu/drm/xe/xe_vm.c +2
-1@@ -1241,7 +1241,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags) } } -if (flags &XE_VM_FLAG_SCRATCH_PAGE ) { +if (flags &XE_VM_FLAG_SCRATCH_PAGE && + (!(flags &XE_VM_FLAG_FAULT_MODE ))) {for_each_tile (tile, xe, id) {if (!vm->pt_root[id])drivers/gpu/drm/xe/xe_vm.c +0
-1continue ;@@ -1931,10 +1932,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data, if (XE_IOCTL_ERR(xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS)) return -EINVAL; - if (XE_IOCTL_ERR(xe, args->flags &
DRM_XE_VM_CREATE_SCRATCH_PAGE&&drivers/gpu/drm/xe/xe_vm.c +0
-3- args->flags & DRM_XE_VM_CREATE_FAULT_MODE)) -return -EINVAL ; - if (XE_IOCTL_ERR(xe, args->flags &
DRM_XE_VM_CREATE_COMPUTE_MODE&&drivers/gpu/drm/xe/xe_vm.c +38
-0args->flags & DRM_XE_VM_CREATE_FAULT_MODE))return -EINVAL ;@@ -2603,6 +2600,44 @@ static int prep_replacement_vma(struct xe_vm *vm, struct xe_vma *vma)return 0 ; } +int xe_bind_scratch_vma (struct xe_vm *vm,u64 addr,u64 size) +{ +struct xe_vma *vma; + +if (!vm->size) +return -ENOMEM ; + + vma =xe_vma_create (vm,NULL ,0 , addr, addr + size -1 , false, true,0 ); +if (!vma) +return -ENOMEM ; +xe_vm_insert_vma (vm, vma); + +/* +* fault will handle the bind +*/ + +return 0 ; +} + +int xe_unbind_scratch_vma (struct xe_vm *vm,u64 addr,u64 range) +{ +struct xe_vma *vma, lookup; + + lookup.start = addr; + lookup.end = addr + range -1 ; + + vma =xe_vm_find_overlapping_vma (vm, &lookup); +if (!vma) +return -ENXIO ; + +if (xe_vma_is_null (vma)) { +prep_vma_destroy (vm, vma); +xe_vm_unbind (vm, vma,NULL ,NULL ,0 ,NULL ); + } + +return 0 ; +} +/* * Find all overlapping VMAs in lookup range and add to a list in the returned * VMA, all of VMAs found will be unbound. Also possibly add 2 new VMAs that
drivers/gpu/drm/xe/xe_vm.c +5
-2@@ -3220,10 +3255,13 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)u64 range = bind_ops[i].range;u64 addr = bind_ops[i].addr;u32 op = bind_ops[i].op; - +retry: err =__vm_bind_ioctl_lookup_vma (vm, bos[i], addr, range, op); -if (err) +if (err) { +if (!xe_unbind_scratch_vma (vm, addr, range)) + goto retry; goto release_vm_lock; + } }drivers/gpu/drm/xe/xe_vm.c +0
-0for (i =0 ; i < args->num_binds; ++i) {drivers/gpu/drm/xe/xe_vm.h +2
-0@@ -140,6 +140,8 @@ static inline void xe_vm_queue_rebind_worker(struct xe_vm *vm) queue_work(vm->xe->ordered_wq, &vm->preempt.rebind_work); } +int xe_bind_scratch_vma (struct xe_vm *vm,u64 addr,u64 size); +/* * XE_ONSTACK_TV is used to size the tv_onstack array that is input * to
xe_vm_lock_dma_resv()andxe_vm_unlock_dma_resv().
--
2.25.1