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
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.
tested on new scratch igt tests which will be sent out for review.
--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++-- drivers/gpu/drm/xe/xe_vm.c | 48 +++++++++++++++++++++++----- drivers/gpu/drm/xe/xe_vm.h | 2 ++ 3 files changed, 49 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +7 -2
@@ -137,8 +137,13 @@ 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 ) + vma =xe_bind_scratch_vma (vm, pf->page_addr,SZ_64K ); + +if (!vma) { + ret = -EINVAL ; + goto unlock_vm; + } }if (!xe_vma_is_userptr (vma) || !xe_vma_userptr_check_repin (vma)) {
drivers/gpu/drm/xe/xe_vm.c +40 -8
80 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +2 -0
@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma);int xe_vma_userptr_check_repin (struct xe_vma *vma); +struct xe_vma *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 (rev2)
== Series Details ==
== Series Details ==
Series: drm/xe: Enable scratch page when page fault is enabled (rev2)
URL : https://patchwork.freedesktop.org/series/120480/
State : failure
== Summary ==
=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: b9c9020fc drm/xe/pvc: Use fast copy engines as migrate engine on PVC === git am output follows ===
Applying: drm/xe: Enable scratch page when page fault is enabled
Quoted 2 lines · Bruce
i915 can use scratch page even when page fault is enabled, this patch is trying to port this feature over.
But why? From a debug perspective maybe this is interesting, but ideally the failed page fault should give the app everything they need to recover. Why not give the onus to the application to fix the addressing problems?
Quoted 7 lines
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.
Quoted 7 lines
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.
So basically we want to avoid a cat fault because the cat fault doesn't give enough information about the bad address? Or is there something else?
Thanks,
Stuart
Quoted 170 lines
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.tested on new scratch igt tests which will be sent out for review.
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]>---
drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++-- drivers/gpu/drm/xe/xe_vm.c | 48 +++++++++++++++++++++++--- --
drivers/gpu/drm/xe/xe_vm.h | 2 ++3 files changed, 49 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +7
-2@@ -137,8 +137,13 @@ 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) + vma = xe_bind_scratch_vma(vm, pf->page_addr,SZ_64K ); + + if (!vma) { + ret = -EINVAL; + goto unlock_vm; + } }
if (!xe_vma_is_userptr(vma) ||
!xe_vma_userptr_check_repin(vma)) {drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1262,7 +1262,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])
continue;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1998,10 +1999,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,if (
XE_IOCTL_DBG(xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS))
return-EINVAL;
- if (XE_IOCTL_DBG(xe,args->flags&DRM_XE_VM_CREATE_SCRATCH_PAGE&&
-args->flags&DRM_XE_VM_CREATE_FAULT_MODE)) - return-EINVAL;
-
if (XE_IOCTL_DBG(xe,args->flags&DRM_XE_VM_CREATE_COMPUTE_MODE&&
args->flags&DRM_XE_VM_CREATE_FAULT_MODE)) return-EINVAL;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2783,6 +2780,39 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, return err; }
+structxe_vma*xe_bind_scratch_vma(structxe_vm*vm, u64 addr, u64 size)drivers/gpu/drm/xe/xe_vm.c +7
-0+{ + struct xe_vma *vma = 0; + + if (!vm->size) + return 0; + + vma = xe_vma_create(vm, NULL, 0, addr, addr + size - 1,false, true, 0);
+ if (!vma)
+ return 0;
+ xe_vm_insert_vma(vm, vma);drivers/gpu/drm/xe/xe_vm.c +17
-0+ + /* fault will handle the bind */ + + return vma; +} + +int xe_unbind_scratch_vma (struct xe_vm *vm,u64 addr,u64 range) +{ + struct xe_vma *vma; + + vma = xe_vm_find_overlapping_vma(vm, addr, range); + if (!vma) + return -ENXIO; + + if (xe_vma_is_null(vma)) { + prep_vma_destroy(vm, vma, true); + xe_vm_unbind(vm, vma, NULL, NULL, 0, NULL, true,false);
+ }drivers/gpu/drm/xe/xe_vm.c +4
-0+ + return 0; +} +static int
xe_vma_op_execute(struct xe_vm *vm, struct xe_vma_op *op){
int ret = 0;drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -3205,7 +3235,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) err = vm_bind_ioctl_check_args(xe, args, &bind_ops, &async); if (err) return err; - if (args->exec_queue_id) { q = xe_exec_queue_lookup(xef, args->exec_queue_id);if (
XE_IOCTL_DBG(xe, !q)) {drivers/gpu/drm/xe/xe_vm.c +5
-2@@ -3352,10 +3381,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 free_syncs; + } }
for (i = 0; i <args->num_binds; ++i) {drivers/gpu/drm/xe/xe_vm.h +0
-0@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma);
intxe_vma_userptr_check_repin(struct xe_vma *vma);
+structxe_vma*xe_bind_scratch_vma(structxe_vm*vm, u64 addr, u64 size);
+
/*
*XE_ONSTACK_TVis used to size thetv_onstackarray that is input
* toxe_vm_lock_dma_resv()andxe_vm_unlock_dma_resv().
Quoted 12 lines
-----Original Message-----
From: Summers, Stuart <[email protected]>
Sent: Monday, August 28, 2023 10:56 AM
To: [email protected]; Chang, Yu bruce <[email protected]>
Cc: Brost, Matthew <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Zeng, Oak <[email protected]>
Subject: Re: [PATCH] drm/xe: Enable scratch page when page fault is enabled
Quoted 8 lines
Quoted 2 lines · Bruce
i915 can use scratch page even when page fault is enabled, this patch is trying to port this feature over.
But why? From a debug perspective maybe this is interesting, but ideally the failed page fault should give the app everything they need to recover. Why not give the onus to the application to fix the addressing problems?
You are correct that this feature was originally designed to help application to run even they had invalid VA accesses. Now this should not be a goal anymore.
The main ask is for EU debug support, and also can be potential WA if there Is any prefetch related issue, such as L1.
Quoted 13 lines
Quoted 6 lines
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.
Quoted 6 lines
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.
Quoted 6 lines
So basically we want to avoid a cat fault because the cat fault doesn't give enough information about the bad address? Or is there something else?
Thanks,
Stuart
As mentioned above, mainly for EU debugger support and any potential prefetch WA.
The issue you mentioned should be fixed with a GuC change along with corresponding driver change. It is coming, but separately.
Thanks,
Bruce
Quoted 166 lines
drivers/gpu/drm/xe/xe_vm.c struct xe_vm *xe_vm_create(struct xe_device
Quoted 56 lines
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.
tested on new scratch igt tests which will be sent out for review.
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]>---
drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++-- drivers/gpu/drm/xe/xe_vm.c | 48 +++++++++++++++++++++++--- --
drivers/gpu/drm/xe/xe_vm.h | 2 ++3 files changed, 49 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +7
-2@@ -137,8 +137,13 @@ 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) + vma = xe_bind_scratch_vma(vm, pf->page_addr,SZ_64K ); + + if (!vma) { + ret = -EINVAL; + goto unlock_vm; + } }if (!xe_vma_is_userptr(vma) ||
!xe_vma_userptr_check_repin(vma)) {drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1262,7 +1262,8 @@ struct xe_vm *xe_vm_create(struct xe_device*xe,
drivers/gpu/drm/xe/xe_vm.h int xe_vma_userptr_pin_pages(struct xe_vma
Quoted 99 lines
drivers/gpu/drm/xe/xe_vm.c +2
-1u32 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])continue; @@ -1998,10 +1999,6 @@ int xe_vm_create_ioctl(struct
drm_device*dev, void *data,
if (XE_IOCTL_DBG(xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS))
return-EINVAL;- if (XE_IOCTL_DBG(xe,
args->flags&DRM_XE_VM_CREATE_SCRATCH_PAGE&&
-args->flags&DRM_XE_VM_CREATE_FAULT_MODE)) - return-EINVAL;
-
if (XE_IOCTL_DBG(xe,args->flags&DRM_XE_VM_CREATE_COMPUTE_MODE&&
args->flags&DRM_XE_VM_CREATE_FAULT_MODE)) return-EINVAL;drivers/gpu/drm/xe/xe_vm.c +27
-0@@ -2783,6 +2780,39 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, return err; } +struct xe_vma *xe_bind_scratch_vma (struct xe_vm *vm,u64 addr,u64 size) +{ + struct xe_vma *vma = 0; + + if (!vm->size) + return 0; + + vma = xe_vma_create(vm, NULL, 0, addr, addr + size - 1, false, true,0 ); + if (!vma) + return 0; + xe_vm_insert_vma(vm, vma); + + /* fault will handle the bind */ + + return vma; +} + +int xe_unbind_scratch_vma (struct xe_vm *vm,u64 addr,u64 range) { + struct xe_vma *vma; + + vma = xe_vm_find_overlapping_vma(vm, addr, range); + if (!vma) + return -ENXIO; + + if (xe_vma_is_null(vma)) { + prep_vma_destroy(vm, vma, true); + xe_vm_unbind(vm, vma, NULL, NULL, 0, NULL, true,false);
+ }drivers/gpu/drm/xe/xe_vm.c +4
-0+ + return 0; +} +static int
xe_vma_op_execute(struct xe_vm *vm, struct xe_vma_op *op){
int ret = 0;drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -3205,7 +3235,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) err = vm_bind_ioctl_check_args(xe, args, &bind_ops, &async); if (err) return err; - if (args->exec_queue_id) { q = xe_exec_queue_lookup(xef, args->exec_queue_id);if (
XE_IOCTL_DBG(xe, !q)) { @@ -3352,10 +3381,13 @@ intxe_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;drivers/gpu/drm/xe/xe_vm.c +1
-1- +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;
gotofree_syncs;
+ }
}for (i = 0; i <
args->num_binds; ++i) { diff --gita/drivers/gpu/drm/xe/xe_vm.hb/drivers/gpu/drm/xe/xe_vm.hindex6de6e3edb24a..6447bed427b1100644drivers/gpu/drm/xe/xe_vm.h +0
-0@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(struct xe_vma*vma);
Quoted 9 lines
drivers/gpu/drm/xe/xe_vm.h +2
-0int xe_vma_userptr_check_repin(struct xe_vma *vma); +struct xe_vma *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().
Quoted 25 lines · Yu bruce
Quoted 19 lines
-----Original Message-----
From: Summers, Stuart <[email protected]>
Sent: Monday, August 28, 2023 10:56 AM
To: [email protected]; Chang, Yu bruce <[email protected]>
Cc: Brost, Matthew <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Zeng, Oak <[email protected]>
Subject: Re: [PATCH] drm/xe: Enable scratch page when page fault is enabledQuoted 3 lines · Bruce
i915 can use scratch page even when page fault is enabled, this patch
is trying to port this feature over.Quoted 6 lines
But why? From a debug perspective maybe this is interesting, but ideally the
failed page fault should give the app everything they need to recover. Why not
give the onus to the application to fix the addressing problems?
Quoted 8 lines
You are correct that this feature was originally designed to help application
to run even they had invalid VA accesses. Now this should not be a goal anymore.The main ask is for EU debug support, and also can be potential WA if there
Is any prefetch related issue, such as L1.
I agree with what Matt B. had said. It would be nice to know why EU debug needs this. Is there an alternate solution? If not, can we enable this only if EU debug is active?
We also don't necessarily want a bunch of workarounds added for potential issues we don't yet know about. That's adding undue burden on the driver.
Thanks,
Stuart
Quoted 229 lines
Quoted 17 lines
Quoted 8 lines
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.Quoted 8 lines
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.Quoted 8 lines
So basically we want to avoid a cat fault because the cat fault doesn't give
enough information about the bad address? Or is there something else?Thanks,
StuartAs mentioned above, mainly for EU debugger support and any potential prefetch WA.
The issue you mentioned should be fixed with a GuC change along with corresponding driver change. It is coming, but separately.
Thanks,
BruceQuoted 194 lines
drivers/gpu/drm/xe/xe_vm.c struct xe_vm *xe_vm_create(struct xe_device
Quoted 70 lines
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.tested on new scratch igt tests which will be sent out for review.
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]>
---
drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++--
drivers/gpu/drm/xe/xe_vm.c | 48
+++++++++++++++++++++++---
--
drivers/gpu/drm/xe/xe_vm.h | 2 ++3 files changed, 49 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +2
-2@@ -137,8 +137,13 @@ 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) + vma = xe_bind_scratch_vma(vm, pf- >page_addr,
SZ_64K);
+
+ if (!vma) {
+ ret =-EINVAL;
+ gotounlock_vm;
+ }
}if (!xe_vma_is_userptr(vma) ||
!xe_vma_userptr_check_repin(vma)) {drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1262,7 +1262,8 @@ struct xe_vm *xe_vm_create(struct xe_device*xe,
drivers/gpu/drm/xe/xe_vm.h int xe_vma_userptr_pin_pages(struct xe_vma
Quoted 111 lines
drivers/gpu/drm/xe/xe_vm.c +2
-1u32 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])continue; @@ -1998,10 +1999,6 @@ int
xe_vm_create_ioctl(structdrm_device*dev, void *data, if (XE_IOCTL_DBG(xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS))
return-EINVAL;- if (XE_IOCTL_DBG(xe,
args->flags&DRM_XE_VM_CREATE_SCRATCH_PAGE&&
-args->flags&DRM_XE_VM_CREATE_FAULT_MODE))
- return-EINVAL;
-
if (XE_IOCTL_DBG(xe,args->flags&DRM_XE_VM_CREATE_COMPUTE_MODE&&
args->flags&DRM_XE_VM_CREATE_FAULT_MODE))
return-EINVAL;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2783,6 +2780,39 @@ static int __xe_vma_op_execute(struct
xe_vm
*vm, structxe_vma*vma,
return err;
}+struct
xe_vma*xe_bind_scratch_vma(structxe_vm*vm, u64 addr, u64
size)drivers/gpu/drm/xe/xe_vm.c +7
-0+{ + struct xe_vma *vma = 0; + + if (!vm->size) + return 0; + + vma = xe_vma_create(vm, NULL, 0, addr, addr + size - 1,false, true, 0);
+ if (!vma)
+ return 0;
+ xe_vm_insert_vma(vm, vma);drivers/gpu/drm/xe/xe_vm.c +7
-0+ + /* fault will handle the bind */ + + return vma; +} + +int xe_unbind_scratch_vma (struct xe_vm *vm,u64 addr,u64 range){
+ structxe_vma*vma;drivers/gpu/drm/xe/xe_vm.c +8
-0+ + vma = xe_vm_find_overlapping_vma(vm, addr, range); + if (!vma) + return -ENXIO; + + if (xe_vma_is_null(vma)) { + prep_vma_destroy(vm, vma, true); + xe_vm_unbind(vm, vma, NULL, NULL, 0, NULL, true,false);
+ }drivers/gpu/drm/xe/xe_vm.c +4
-0+ + return 0; +} +static int
xe_vma_op_execute(struct xe_vm *vm, struct xe_vma_op *op)
{
int ret = 0;drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -3205,7 +3235,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) err = vm_bind_ioctl_check_args(xe, args, &bind_ops, &async); if (err) return err; -if (
args->exec_queue_id) {
q = xe_exec_queue_lookup(xef, args-Quoted 1 line
exec_queue_id);if (
XE_IOCTL_DBG(xe, !q)) { @@ -3352,10 +3381,13 @@
intxe_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;drivers/gpu/drm/xe/xe_vm.c +1
-1- +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;
gotofree_syncs;
+ }
}for (i = 0; i <
args->num_binds; ++i) { diff --gita/drivers/gpu/drm/xe/xe_vm.hb/drivers/gpu/drm/xe/xe_vm.hindex6de6e3edb24a..6447bed427b1100644drivers/gpu/drm/xe/xe_vm.h +0
-0@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(struct xe_vma*vma);
Quoted 11 lines
drivers/gpu/drm/xe/xe_vm.h +1
-0int xe_vma_userptr_check_repin(struct xe_vma *vma); +struct xe_vma *xe_bind_scratch_vma(struct xe_vm *vm, u64 addr,u64
size);
+
/*
*XE_ONSTACK_TVis used to size thetv_onstackarray that is input
* toxe_vm_lock_dma_resv()andxe_vm_unlock_dma_resv().
Quoted 46 lines
-----Original Message-----
From: Summers, Stuart <[email protected]>
Sent: Monday, August 28, 2023 3:26 PM
To: [email protected]; Chang, Yu bruce <[email protected]>
Cc: Brost, Matthew <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Zeng, Oak <[email protected]>
Subject: Re: [PATCH] drm/xe: Enable scratch page when page fault is enabledQuoted 23 lines · Yu bruce
Quoted 14 lines
-----Original Message-----
From: Summers, Stuart <[email protected]>
Sent: Monday, August 28, 2023 10:56 AM
To: [email protected]; Chang, Yu bruce <[email protected]>
Cc: Brost, Matthew <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Zeng, Oak <[email protected]>
Subject: Re: [PATCH] drm/xe: Enable scratch page when page fault is enabledQuoted 9 lines
Quoted 2 lines · Bruce
i915 can use scratch page even when page fault is enabled, this patch is trying to port this feature over.
But why? From a debug perspective maybe this is interesting, but ideally the failed page fault should give the app everything they need to recover. Why not give the onus to the application to fix the addressing problems?
Quoted 6 lines
You are correct that this feature was originally designed to help application to run even they had invalid VA accesses. Now this should not be a goal anymore.
The main ask is for EU debug support, and also can be potential WA if there Is any prefetch related issue, such as L1.
I agree with what Matt B. had said. It would be nice to know why EU debug needs this. Is there an alternate solution? If not, can we enable this only if EU debug is active?
Quoted 6 lines
We also don't necessarily want a bunch of workarounds added for potential issues we don't yet know about. That's adding undue burden on the driver.
Thanks,
Stuart
The PVC HW has a limitation that the page fault due to invalid accessing will halt the EUs accessing it, and the default behavior is CAT fault. So, in order to activate the debugger, kmd needs to setup the scratch pages to unhalt the EUs.
this feature can only be enabled if scratch flag is set. So, once EU debugger is running, the debugger umd will set the scratch flag, otherwise, this flag should not be set. So, in regular run, this feature should not be activated.
Will add this details into commit comment to make things more clear.
Thanks,
Bruce
Quoted 214 lines
Quoted 214 lines
Quoted 14 lines
Quoted 7 lines
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.
Quoted 6 lines
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.
Quoted 7 lines
So basically we want to avoid a cat fault because the cat fault doesn't give enough information about the bad address? Or is there something else?
Thanks,
StuartAs mentioned above, mainly for EU debugger support and any potential prefetch WA.
The issue you mentioned should be fixed with a GuC change along with corresponding driver change. It is coming, but separately.
Thanks,
BruceQuoted 183 lines
drivers/gpu/drm/xe/xe_vm.c struct xe_vm *xe_vm_create(struct xe_device
Quoted 63 lines
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.tested on new scratch igt tests which will be sent out for review.
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]>
---
drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++--
drivers/gpu/drm/xe/xe_vm.c | 48
+++++++++++++++++++++++---
--
drivers/gpu/drm/xe/xe_vm.h | 2 ++3 files changed, 49 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +7
-2@@ -137,8 +137,13 @@ 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) + vma = xe_bind_scratch_vma(vm, pf- >page_addr,SZ_64K ); + + if (!vma) { + ret = -EINVAL; + goto unlock_vm; + }}
if (!xe_vma_is_userptr(vma) || !xe_vma_userptr_check_repin(vma)) { diff --git
a/drivers/gpu/drm/xe/xe_vm.cb/drivers/gpu/drm/xe/xe_vm.cindex389ac5ba8ddf..4c3d5d781b58100644drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1262,7 +1262,8 @@ struct xe_vm *xe_vm_create(struct xe_device*xe,
drivers/gpu/drm/xe/xe_vm.h int xe_vma_userptr_pin_pages(struct xe_vma
Quoted 107 lines
drivers/gpu/drm/xe/xe_vm.c +2
-1u32 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])continue; @@ -1998,10 +1999,6 @@ int xe_vm_create_ioctl(struct
drm_device*dev, void *data, if (XE_IOCTL_DBG(xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS))
return-EINVAL;- if (XE_IOCTL_DBG(xe,
args->flags&DRM_XE_VM_CREATE_SCRATCH_PAGE&&
-args->flags&DRM_XE_VM_CREATE_FAULT_MODE))
- return-EINVAL;
-
if (XE_IOCTL_DBG(xe,args->flags&DRM_XE_VM_CREATE_COMPUTE_MODE&&
args->flags&DRM_XE_VM_CREATE_FAULT_MODE))
return-EINVAL;drivers/gpu/drm/xe/xe_vm.c +1
-0@@ -2783,6 +2780,39 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, return err; } +struct xe_vma *xe_bind_scratch_vma(struct xe_vm *vm, u64 addr,u64
size)drivers/gpu/drm/xe/xe_vm.c +7
-0+{ + struct xe_vma *vma = 0; + + if (!vm->size) + return 0; + + vma = xe_vma_create(vm, NULL, 0, addr, addr + size - 1,false, true, 0);
+ if (!vma)
+ return 0;
+ xe_vm_insert_vma(vm, vma);drivers/gpu/drm/xe/xe_vm.c +7
-0+ + /* fault will handle the bind */ + + return vma; +} + +int xe_unbind_scratch_vma (struct xe_vm *vm,u64 addr,u64 range){
+ structxe_vma*vma;drivers/gpu/drm/xe/xe_vm.c +8
-0+ + vma = xe_vm_find_overlapping_vma(vm, addr, range); + if (!vma) + return -ENXIO; + + if (xe_vma_is_null(vma)) { + prep_vma_destroy(vm, vma, true); + xe_vm_unbind(vm, vma, NULL, NULL, 0, NULL, true,false);
+ }drivers/gpu/drm/xe/xe_vm.c +4
-0+ + return 0; +} +static int
xe_vma_op_execute(struct xe_vm *vm, struct xe_vma_op *op)
{
int ret = 0;drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -3205,7 +3235,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) err = vm_bind_ioctl_check_args(xe, args, &bind_ops, &async); if (err) return err; - if (args->exec_queue_id) {q = xe_exec_queue_lookup(xef, args-
Quoted 1 line
exec_queue_id);if (
XE_IOCTL_DBG(xe, !q)) { @@ -3352,10 +3381,13 @@ intxe_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;drivers/gpu/drm/xe/xe_vm.c +1
-1- +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;
gotofree_syncs;
+ }
}for (i = 0; i <
args->num_binds; ++i) { diff --gita/drivers/gpu/drm/xe/xe_vm.hb/drivers/gpu/drm/xe/xe_vm.hindex6de6e3edb24a..6447bed427b1100644drivers/gpu/drm/xe/xe_vm.h +0
-0@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(struct xe_vma*vma);
Quoted 11 lines
drivers/gpu/drm/xe/xe_vm.h +1
-0int xe_vma_userptr_check_repin(struct xe_vma *vma); +struct xe_vma *xe_bind_scratch_vma(struct xe_vm *vm, u64 addr,u64
size);
+
/*
*XE_ONSTACK_TVis used to size thetv_onstackarray that is input
* toxe_vm_lock_dma_resv()andxe_vm_unlock_dma_resv().
Quoted 63 lines · Yu bruce
Quoted 63 lines
-----Original Message-----
From: Summers, Stuart <[email protected]>
Sent: Monday, August 28, 2023 3:26 PM
To: [email protected]; Chang, Yu bruce <[email protected]>
Cc: Brost, Matthew <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Zeng, Oak <[email protected]>
Subject: Re: [PATCH] drm/xe: Enable scratch page when page fault is enabledQuoted 28 lines · Yu bruce
Quoted 20 lines
-----Original Message-----
From: Summers, Stuart <[email protected]>
Sent: Monday, August 28, 2023 10:56 AM
To: [email protected]; Chang, Yu bruce <[email protected]>
Cc: Brost, Matthew <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Zeng, Oak <[email protected]>
Subject: Re: [PATCH] drm/xe: Enable scratch page when page fault is
enabledQuoted 3 lines · Bruce
i915 can use scratch page even when page fault is enabled, this
patch is trying to port this feature over.Quoted 8 lines
But why? From a debug perspective maybe this is interesting, but
ideally the failed page fault should give the app everything they
need to recover. Why not give the onus to the application to fix the
addressing problems?Quoted 8 lines
You are correct that this feature was originally designed to help application to run even they had invalid VA accesses. Now this should
not be a goal anymore.The main ask is for EU debug support, and also can be potential WA if
there Is any prefetch related issue, such as L1.I agree with what Matt B. had said. It would be nice to know why EU debug needs
this. Is there an alternate solution? If not, can we enable this only if EU debug is
active?We also don't necessarily want a bunch of workarounds added for potential
issues we don't yet know about. That's adding undue burden on the driver.
Quoted 8 lines
Quoted 3 lines
Thanks,
StuartThe PVC HW has a limitation that the page fault due to invalid accessing will halt
the EUs accessing it, and the default behavior is CAT fault. So, in order to activate
the debugger, kmd needs to setup the scratch pages to unhalt the EUs.
We should add this as an explicit workaround for PVC then, not a general feature. Also IMO it's better to hold off merging this until EU debug is ready to consume it. We shouldn't have dead code sitting here untested.
Do you have a link to the EU debug series adding this support?
Thanks,
Stuart
Quoted 264 lines
this feature can only be enabled if scratch flag is set. So, once EU debugger is running,
the debugger umd will set the scratch flag, otherwise, this flag should not be set.
So, in regular run, this feature should not be activated.Will add this details into commit comment to make things more clear.
Thanks,
BruceQuoted 251 lines
Quoted 251 lines
Quoted 21 lines
Quoted 14 lines
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.Quoted 6 lines
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.Quoted 8 lines
So basically we want to avoid a cat fault because the cat fault doesn't give enough information about the bad address? Or is there
something else?Thanks,
StuartAs mentioned above, mainly for EU debugger support and any potential
prefetch WA.The issue you mentioned should be fixed with a GuC change along with
corresponding driver change. It is coming, but separately.Thanks,
BruceQuoted 210 lines
Quoted 74 lines
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.tested on new scratch igt tests which will be sent out for review.
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]>
---
drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++--
drivers/gpu/drm/xe/xe_vm.c | 48
+++++++++++++++++++++++---
--
drivers/gpu/drm/xe/xe_vm.h | 2 ++3 files changed, 49 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +2
-2@@ -137,8 +137,13 @@ 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) + vma = xe_bind_scratch_vma(vm, pf- > page_addr,
SZ_64K);
+
+ if (!vma) {
+ ret =-EINVAL;
+ gotounlock_vm;
+ }
}if (!xe_vma_is_userptr(vma) || !xe_vma_userptr_check_repin(vma)) { diff --git
a/drivers/gpu/drm/xe/xe_vm.cb/drivers/gpu/drm/xe/xe_vm.cindex389ac5ba8ddf..4c3d5d781b58100644drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1262,7 +1262,8 @@ struct xe_vm *xe_vm_create(structQuoted 1 line
xe_device*xe,
Quoted 119 lines
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]) continue; @@ -1998,10 +1999,6 @@
int xe_vm_create_ioctl(structdrm_device*dev, void *data, if (XE_IOCTL_DBG(xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS))
return-EINVAL;- if (XE_IOCTL_DBG(xe,
args->flags&DRM_XE_VM_CREATE_SCRATCH_PAGE&&
-args->flags&DRM_XE_VM_CREATE_FAULT_MODE))
- return-EINVAL;
-
if (XE_IOCTL_DBG(xe,args->flags&DRM_XE_VM_CREATE_COMPUTE_MODE&&
args->flags&DRM_XE_VM_CREATE_FAULT_MODE))
return-EINVAL;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2783,6 +2780,39 @@ static int __xe_vma_op_execute(struct
xe_vm
*vm, structxe_vma*vma,
return err;
}+struct
xe_vma*xe_bind_scratch_vma(structxe_vm*vm, u64 addr,
u64
size)drivers/gpu/drm/xe/xe_vm.c +7
-0+{ + struct xe_vma *vma = 0; + + if (!vm->size) + return 0; + + vma = xe_vma_create(vm, NULL, 0, addr, addr + size -1,
false, true, 0);
+ if (!vma)
+ return 0;
+ xe_vm_insert_vma(vm, vma);drivers/gpu/drm/xe/xe_vm.c +7
-0+ + /* fault will handle the bind */ + + return vma; +} + +int xe_unbind_scratch_vma(struct xe_vm *vm, u64 addr, u64range)
{
+ structxe_vma*vma;drivers/gpu/drm/xe/xe_vm.c +8
-0+ + vma = xe_vm_find_overlapping_vma(vm, addr, range); + if (!vma) + return -ENXIO; + + if (xe_vma_is_null(vma)) { + prep_vma_destroy(vm, vma, true); + xe_vm_unbind(vm, vma, NULL, NULL, 0, NULL,true,
false);
+ }drivers/gpu/drm/xe/xe_vm.c +4
-0+ + return 0; +} +static int xe_vma_op_execute(struct
xe_vm*vm, structxe_vma_op
*op)
{
int ret = 0;drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -3205,7 +3235,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) err = vm_bind_ioctl_check_args(xe, args, &bind_ops, &async); if (err) return err; -if (
args->exec_queue_id) {
q = xe_exec_queue_lookup(xef, args-Quoted 1 line
exec_queue_id);if (
XE_IOCTL_DBG(xe, !q)) { @@ -3352,10 +3381,13
@@ int xe_vm_bind_ioctl(structdrm_device*dev, void *data, structdrm_file*file)
u64 range = bind_ops[i].range;
u64 addr = bind_ops[i].addr;
u32 op = bind_ops[i].op;drivers/gpu/drm/xe/xe_vm.c +1
-1- +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;
gotofree_syncs;
+ }
}for (i = 0; i <
args->num_binds; ++i) { diff --gita/drivers/gpu/drm/xe/xe_vm.hb/drivers/gpu/drm/xe/xe_vm.hindex6de6e3edb24a..6447bed427b1100644drivers/gpu/drm/xe/xe_vm.h +0
-0@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(structQuoted 1 line
xe_vma*vma);
Quoted 13 lines
int
xe_vma_userptr_check_repin(struct xe_vma *vma);+struct
xe_vma*xe_bind_scratch_vma(structxe_vm*vm, u64 addr,
u64
size);
+
/*
*XE_ONSTACK_TVis used to size thetv_onstackarray that is
input
* toxe_vm_lock_dma_resv()andxe_vm_unlock_dma_resv().
Matthew Brost
maintainerQuoted 3 lines · Bruce
i915 can use scratch page even when page fault is enabled, this patch is trying to port this feature over.
I think we need to ask why do we support this before merging this. Because the i915 does this is not a valid answer. Please explain why a UMD needs this feature.
Quoted 41 lines
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.
tested on new scratch igt tests which will be sent out for review.
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]>--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++-- drivers/gpu/drm/xe/xe_vm.c | 48 +++++++++++++++++++++++----- drivers/gpu/drm/xe/xe_vm.h | 2 ++ 3 files changed, 49 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +0
-0
drivers/gpu/drm/xe/xe_gt_pagefault.c static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf) · line 141
Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_pagefault.c +2
-2@@ -137,8 +137,13 @@ 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 ) + vma =xe_bind_scratch_vma (vm, pf->page_addr,SZ_64K );
I think this would be better.
s/xe_bind_scratch_vma/xe_vm_create_scratch_vma
Quoted 34 lines
drivers/gpu/drm/xe/xe_gt_pagefault.c +5
-0+ +if (!vma) { + ret = -EINVAL ; + goto unlock_vm; + } }if (!xe_vma_is_userptr (vma) || !xe_vma_userptr_check_repin (vma)) {drivers/gpu/drm/xe/xe_vm.c +2
-5@@ -1262,7 +1262,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])continue ;@@ -1998,10 +1999,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_DBG (xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS ))return -EINVAL ; -if (XE_IOCTL_DBG (xe, args->flags &DRM_XE_VM_CREATE_SCRATCH_PAGE && - args->flags &DRM_XE_VM_CREATE_FAULT_MODE )) -return -EINVAL ; -if (XE_IOCTL_DBG (xe, args->flags &DRM_XE_VM_CREATE_COMPUTE_MODE && args->flags &DRM_XE_VM_CREATE_FAULT_MODE ))return -EINVAL ;
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, · line 2784
Quoted 5 lines
drivers/gpu/drm/xe/xe_vm.c +2
-0@@ -2783,6 +2780,39 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,return err; } +struct xe_vma *xe_bind_scratch_vma (struct xe_vm *vm,u64 addr,u64 size) +{
Nit, the size argument really isn't needed.
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, · line 2787
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +3
-0+struct xe_vma *vma =0 ; + +if (!vm->size)
xe_vm_is_closed_or_banned rather than vm->size check.
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, · line 2788
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +1
-0+return 0 ;
Probably a ERR_PTR with correct return codes.
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, · line 2794
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +6
-0+ + vma =xe_vma_create (vm,NULL ,0 , addr, addr + size -1 , false, true,0 ); +if (!vma) +return 0 ; +xe_vm_insert_vma (vm, vma); +
Need to check the return of xe_vm_insert_vma, also probably WARN on this as it shouldn't ever fail.
Quoted 25 lines
drivers/gpu/drm/xe/xe_vm.c +21
-0+/* fault will handle the bind */ + +return vma; +} + +int xe_unbind_scratch_vma (struct xe_vm *vm,u64 addr,u64 range) +{ +struct xe_vma *vma; + + vma =xe_vm_find_overlapping_vma (vm, addr, range); +if (!vma) +return -ENXIO ; + +if (xe_vma_is_null (vma)) { +prep_vma_destroy (vm, vma, true); +xe_vm_unbind (vm, vma,NULL ,NULL ,0 ,NULL , true, false); + } + +return 0 ; +} +static int xe_vma_op_execute (struct xe_vm *vm,struct xe_vma_op *op) {int ret =0 ;
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 3208
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -3205,7 +3235,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) err =vm_bind_ioctl_check_args (xe, args, &bind_ops, &async);if (err)return err; -
Not related.
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0if (args->exec_queue_id) { q =xe_exec_queue_lookup (xef, args->exec_queue_id);if (XE_IOCTL_DBG (xe, !q)) {@@ -3352,10 +3381,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;
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 3390
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +5
-2u32 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 free_syncs; + }
You don't need this change, GPUVA handles all of this (e.g. it will create ops to unbind the old VMA, bind the new one).
Matt
Quoted 19 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0}for (i =0 ; i < args->num_binds; ++i) {drivers/gpu/drm/xe/xe_vm.h +2
-0@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma);int xe_vma_userptr_check_repin (struct xe_vma *vma); +struct xe_vma *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
Quoted 12 lines
-----Original Message-----
From: Brost, Matthew <[email protected]>
Sent: Monday, August 28, 2023 12:22 PM
To: Chang, Yu bruce <[email protected]>
Cc: [email protected]; Zeng, Oak <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Summers, Stuart <[email protected]>
Subject: Re: [PATCH] drm/xe: Enable scratch page when page fault is enabled
Quoted 9 lines
Quoted 3 lines · Bruce
i915 can use scratch page even when page fault is enabled, this patch is trying to port this feature over.
I think we need to ask why do we support this before merging this. Because the i915 does this is not a valid answer. Please explain why a UMD needs this feature.
Sure, mainly for EU debugger support and any potential prefetch WA.
Will add this in the commit comment.
Quoted 52 lines
drivers/gpu/drm/xe/xe_gt_pagefault.c static int handle_pagefault(struct xe_gt *gt, struct
Quoted 42 lines
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.
tested on new scratch igt tests which will be sent out for review.
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]>--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++-- drivers/gpu/drm/xe/xe_vm.c | 48 +++++++++++++++++++++++----- drivers/gpu/drm/xe/xe_vm.h | 2 ++ 3 files changed, 49 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +0
-0@@ -137,8 +137,13 @@ static int handle_pagefault(struct xe_gt *gt, structpagefault *pf)
drivers/gpu/drm/xe/xe_gt_pagefault.c static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_pagefault.c +2
-2write_locked = true; vma =lookup_vma (vm, pf->page_addr);if (!vma) { - ret = -EINVAL ; - goto unlock_vm; +if (vm->flags &XE_VM_FLAG_SCRATCH_PAGE ) + vma = xe_bind_scratch_vma(vm, pf->page_addr,
SZ_64K);
Quoted 4 lines
I think this would be better.
s/xe_bind_scratch_vma/xe_vm_create_scratch_vma
Will make the change.
Quoted 40 lines
drivers/gpu/drm/xe/xe_vm.c struct xe_vm *xe_vm_create(struct xe_device *xe,
Quoted 14 lines
drivers/gpu/drm/xe/xe_gt_pagefault.c +5
-0+ +if (!vma) { + ret = -EINVAL ; + goto unlock_vm; + } }if (!xe_vma_is_userptr (vma) || !xe_vma_userptr_check_repin (vma)) {drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1262,7 +1262,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe,u32 flags)
drivers/gpu/drm/xe/xe_vm.c int xe_vm_create_ioctl(struct drm_device *dev,
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +2
-1} } -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])continue ;@@ -1998,10 +1999,6 @@ int xe_vm_create_ioctl(struct drm_device *dev,void *data,
drivers/gpu/drm/xe/xe_vm.c int xe_vm_create_ioctl(struct drm_device *dev, void *data,
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-1if (XE_IOCTL_DBG (xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS ))return -EINVAL ; - if (XE_IOCTL_DBG(xe, args->flags &
DRM_XE_VM_CREATE_SCRATCH_PAGE&&drivers/gpu/drm/xe/xe_vm.c int xe_vm_create_ioctl(struct drm_device *dev, void *data,
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-3- args->flags & DRM_XE_VM_CREATE_FAULT_MODE)) -return -EINVAL ; - if (XE_IOCTL_DBG(xe, args->flags &
DRM_XE_VM_CREATE_COMPUTE_MODE&&drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm,
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0args->flags & DRM_XE_VM_CREATE_FAULT_MODE))return -EINVAL ;@@ -2783,6 +2780,39 @@ static int __xe_vma_op_execute(struct xe_vm *vm,struct
xe_vma*vma,
Quoted 8 lines
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,
Quoted 5 lines
drivers/gpu/drm/xe/xe_vm.c +2
-0return err; } +struct xe_vma *xe_bind_scratch_vma (struct xe_vm *vm,u64 addr,u64 +size) {Nit, the size argument really isn't needed.
Sure, can hard code it.
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, · line 2787
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +3
-0+struct xe_vma *vma =0 ; + +if (!vm->size)
xe_vm_is_closed_or_bannedrather thanvm->sizecheck.drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, · line 2788
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +1
-0+return 0 ;Probably a
ERR_PTRwith correct return codes.
Will add this error check.
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, · line 2794
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +6
-0+ + vma =xe_vma_create (vm,NULL ,0 , addr, addr + size -1 , false, true,0 ); +if (!vma) +return 0 ; +xe_vm_insert_vma (vm, vma); +Need to check the return of
xe_vm_insert_vma, also probably WARN on this as it shouldn't ever fail.
Will change it
Quoted 53 lines
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void
Quoted 24 lines
drivers/gpu/drm/xe/xe_vm.c +20
-0+/* fault will handle the bind */ + +return vma; +} + +int xe_unbind_scratch_vma (struct xe_vm *vm,u64 addr,u64 range) { +struct xe_vma *vma; + + vma =xe_vm_find_overlapping_vma (vm, addr, range); +if (!vma) +return -ENXIO ; + +if (xe_vma_is_null (vma)) { +prep_vma_destroy (vm, vma, true); +xe_vm_unbind (vm, vma,NULL ,NULL ,0 ,NULL , true, false); + } + +return 0 ; +} +static int xe_vma_op_execute (struct xe_vm *vm,struct xe_vma_op *op) {int ret =0 ;@@ -3205,7 +3235,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void*data, struct
drm_file*file)drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 3208
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-1err =vm_bind_ioctl_check_args (xe, args, &bind_ops, &async);if (err)return err; -Not related.
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0if (args->exec_queue_id) { q =xe_exec_queue_lookup (xef, args->exec_queue_id);if (XE_IOCTL_DBG (xe, !q)) {@@ -3352,10 +3381,13 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void*data, struct
drm_file*file)drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 3390
Quoted 12 lines
drivers/gpu/drm/xe/xe_vm.c +5
-2u64 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 free_syncs; + }You don't need this change, GPUVA handles all of this (e.g. it will create ops to unbind the old VMA, bind the new one).
Quoted 2 lines
Matt
I was also concerned about this change. Good to know GPUVA can help here! Then the change will be a lot more cleaner.
Thanks!
Bruce
Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0} for (i = 0; i < args->num_binds; ++i) { diff --git
a/drivers/gpu/drm/xe/xe_vm.hb/drivers/gpu/drm/xe/xe_vm.hindex6de6e3edb24a..6447bed427b1100644drivers/gpu/drm/xe/xe_vm.h +3
-1@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma);int xe_vma_userptr_check_repin (struct xe_vma *vma); +struct xe_vma *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(). -- 2.25.1
Quoted 229 lines
-----Original Message-----
From: Intel-xe <[email protected]> On Behalf Of Chang, Yu bruce
Sent: Monday, August 28, 2023 3:35 PM
To: Brost, Matthew <[email protected]>
Cc: Summers, Stuart <[email protected]>; intel- [email protected]
Subject: Re: [Intel-xe] [PATCH] drm/xe: Enable scratch page when page fault is enabledQuoted 11 lines
-----Original Message-----
From: Brost, Matthew <[email protected]>
Sent: Monday, August 28, 2023 12:22 PM
To: Chang, Yu bruce <[email protected]>
Cc: [email protected]; Zeng, Oak <[email protected]>; Welty, Brian <[email protected]>; Vishwanathapura, Niranjana <[email protected]>; Summers, Stuart <[email protected]>
Subject: Re: [PATCH] drm/xe: Enable scratch page when page fault is enabledQuoted 9 lines
Quoted 3 lines · Bruce
i915 can use scratch page even when page fault is enabled, this patch is trying to port this feature over.
I think we need to ask why do we support this before merging this. Because the i915 does this is not a valid answer. Please explain why a UMD needs this feature.
Sure, mainly for EU debugger support and any potential prefetch WA.
Will add this in the commit comment.
Quoted 53 lines
Quoted 42 lines
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.
tested on new scratch igt tests which will be sent out for review.
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]>--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 9 ++++-- drivers/gpu/drm/xe/xe_vm.c | 48 +++++++++++++++++++++++----- drivers/gpu/drm/xe/xe_vm.h | 2 ++ 3 files changed, 49 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_gt_pagefault.c +0
-0@@ -137,8 +137,13 @@ static int handle_pagefault(struct xe_gt *gt,Quoted 1 line
struct
pagefault *pf)
drivers/gpu/drm/xe/xe_gt_pagefault.c static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_pagefault.c +2
-2write_locked = true; vma =lookup_vma (vm, pf->page_addr);if (!vma) { - ret = -EINVAL ; - goto unlock_vm; +if (vm->flags &XE_VM_FLAG_SCRATCH_PAGE ) + vma = xe_bind_scratch_vma(vm, pf->page_addr,
SZ_64K);Quoted 4 lines
I think this would be better.
s/xe_bind_scratch_vma/xe_vm_create_scratch_vma
Will make the change.
Quoted 43 lines
Quoted 14 lines
drivers/gpu/drm/xe/xe_gt_pagefault.c +5
-0+ +if (!vma) { + ret = -EINVAL ; + goto unlock_vm; + } }if (!xe_vma_is_userptr (vma) || !xe_vma_userptr_check_repin (vma)) {drivers/gpu/drm/xe/xe_vm.c +0
-0drivers/gpu/drm/xe/xe_vm.c struct xe_vm *xe_vm_create(struct xe_device · line 1262
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1262,7 +1262,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe,u32 flags)
drivers/gpu/drm/xe/xe_vm.c int xe_vm_create_ioctl(struct drm_device · line 1999
Quoted 11 lines
drivers/gpu/drm/xe/xe_vm.c +2
-1} } -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
-0continue ;@@ -1998,10 +1999,6 @@ int xe_vm_create_ioctl(struct drm_device *dev,void *data,
drivers/gpu/drm/xe/xe_vm.c int xe_vm_create_ioctl(struct drm_device *dev, void *data,
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-1if (XE_IOCTL_DBG (xe, args->flags & ~ALL_DRM_XE_VM_CREATE_FLAGS ))return -EINVAL ; - if (XE_IOCTL_DBG(xe, args->flags &
DRM_XE_VM_CREATE_SCRATCH_PAGE&&drivers/gpu/drm/xe/xe_vm.c int xe_vm_create_ioctl(struct drm_device *dev, void *data,
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-3- args->flags & DRM_XE_VM_CREATE_FAULT_MODE)) -return -EINVAL ; - if (XE_IOCTL_DBG(xe, args->flags &
DRM_XE_VM_CREATE_COMPUTE_MODE&&drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm · line 2780
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0args->flags & DRM_XE_VM_CREATE_FAULT_MODE))drivers/gpu/drm/xe/xe_vm.c +0
-0return -EINVAL ;@@ -2783,6 +2780,39 @@ static int __xe_vma_op_execute(struct xe_vm *vm,struct
xe_vma*vma,Quoted 8 lines
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,
Quoted 5 lines
drivers/gpu/drm/xe/xe_vm.c +2
-0return err; } +struct xe_vma *xe_bind_scratch_vma (struct xe_vm *vm,u64 addr,u64 +size) {Nit, the size argument really isn't needed.
Sure, can hard code it.
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, · line 2787
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +3
-0+struct xe_vma *vma =0 ; + +if (!vm->size)
xe_vm_is_closed_or_bannedrather thanvm->sizecheck.drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm · line 2789
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +1
-0+return 0 ;Probably a
ERR_PTRwith correct return codes.Will add this error check.
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma, · line 2794
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +6
-0+ + vma =xe_vma_create (vm,NULL ,0 , addr, addr + size -1 , false, true,0 ); +if (!vma) +return 0 ; +xe_vm_insert_vma (vm, vma); +Need to check the return of
xe_vm_insert_vma, also probably WARN on this as it shouldn't ever fail.Will change it
Quoted 55 lines
Quoted 24 lines
drivers/gpu/drm/xe/xe_vm.c +20
-0+/* fault will handle the bind */ + +return vma; +} + +int xe_unbind_scratch_vma (struct xe_vm *vm,u64 addr,u64 range) { +struct xe_vma *vma; + + vma =xe_vm_find_overlapping_vma (vm, addr, range); +if (!vma) +return -ENXIO ; + +if (xe_vma_is_null (vma)) { +prep_vma_destroy (vm, vma, true); +xe_vm_unbind (vm, vma,NULL ,NULL ,0 ,NULL , true, false); + } + +return 0 ; +} +static int xe_vma_op_execute (struct xe_vm *vm,struct xe_vma_op *op) {int ret =0 ;@@ -3205,7 +3235,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev,Quoted 1 line
void
*data, struct
drm_file*file)drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 3208
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +0
-1err =vm_bind_ioctl_check_args (xe, args, &bind_ops, &async);if (err)return err; -Not related.
Quoted 5 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0if (args->exec_queue_id) { q =xe_exec_queue_lookup (xef, args->exec_queue_id);if (XE_IOCTL_DBG (xe, !q)) {@@ -3352,10 +3381,13 @@ int xe_vm_bind_ioctl(struct drm_device *dev,void
*data, struct
drm_file*file)drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 3390
Quoted 12 lines
drivers/gpu/drm/xe/xe_vm.c +5
-2u64 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 free_syncs; + }You don't need this change, GPUVA handles all of this (e.g. it will create ops to unbind the old VMA, bind the new one).
Quoted 9 lines
Quoted 2 lines
Matt
I was also concerned about this change. Good to know GPUVA can help here! Then the change will be a lot more cleaner.
Thanks!
Bruce
It seems
err = vm_bind_ioctl_lookup_vma(vm, bos[i], addr, range, op);
will prevent GPUVA as it will error out firstly. If I remove it, it seems working.
-Bruce
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0} for (i = 0; i < args->num_binds; ++i) { diff --git
a/drivers/gpu/drm/xe/xe_vm.hb/drivers/gpu/drm/xe/xe_vm.hindex6de6e3edb24a..6447bed427b1100644drivers/gpu/drm/xe/xe_vm.h +3
-1@@ -212,6 +212,8 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma);int xe_vma_userptr_check_repin (struct xe_vma *vma); +struct xe_vma *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(). -- 2.25.1