drm/xe: Add a function to zap page table by address range
Subsystems (2)
PATCH 1/3 drm/xe: Add a function to zap page table by address range
Add a function xe_pt_zap_range. This is similar to xe_pt_zap_ptes but is used when we don't have a vma to work with, such as zap a range mapped to scratch page where we don't have vma.
--- drivers/gpu/drm/xe/xe_pt.c | 28 ++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_pt.h | 2 ++ 2 files changed, 30 insertions(+)
drivers/gpu/drm/xe/xe_pt.c +28 -0
@@ -792,6 +792,34 @@ static const struct xe_pt_walk_ops xe_pt_zap_ptes_ops = { .pt_entry = xe_pt_zap_ptes_entry, }; +/** +* xe_pt_zap_range() - Zap (zero) gpu ptes of an virtual address range +* @tile: The tile we're zapping for. +* @vm: The vm we're zapping for. +* @start: Start of the virtual address range, inclusive. +* @end: End of the virtual address range, exclusive. +* +* This is similar to xe_pt_zap_ptes() but it's used when we don't have a +* vma to work with. This is used for example when we're clearing the scratch +* page mapping during vm_bind. +* +*/ +void xe_pt_zap_range (struct xe_tile *tile,struct xe_vm *vm,u64 start,u64 end) +{ +struct xe_pt_zap_ptes_walk xe_walk = { + .base = { + .ops = &xe_pt_zap_ptes_ops, + .shifts = xe_normal_pt_shifts, + .max_level =XE_PT_HIGHEST_LEVEL , + }, + .tile = tile, + }; +struct xe_pt *pt = vm->pt_root[tile->id]; + + (void )xe_pt_walk_shared (&pt->base, pt->level, start, + end, &xe_walk.base); +} +/** * xe_pt_zap_ptes() - Zap (zero) gpu ptes of an address range * @tile: The tile we're zapping for.
drivers/gpu/drm/xe/xe_pt.h +2 -0
@@ -43,4 +43,6 @@ void xe_pt_update_ops_abort(struct xe_tile *tile, struct xe_vma_ops *vops);bool xe_pt_zap_ptes (struct xe_tile *tile,struct xe_vma *vma); +void xe_pt_zap_range (struct xe_tile *tile,struct xe_vm *vm,u64 start,u64 end); +#endif
Signature · 1 line
2.26.3
PATCH 2/3 drm/xe: Clear scratch page before vm_bind
When a vm runs under fault mode, if scratch page is enabled, we need to clear the scratch page mapping before vm_bind for the vm_bind address range. Under fault mode, we depend on recoverable page fault to establish mapping in page table. If scratch page is not cleared, GPU access of address won't cause page fault because it always hits the existing scratch page mapping.
When vm_bind with IMMEDIATE flag, there is no need of clearing as immediate bind can overwrite the scratch page mapping.
So far only is xe2 and xe3 products are allowed to enable scratch page under fault mode. On other platform we don't allow scratch page under fault mode, so no need of such clearing.
--- drivers/gpu/drm/xe/xe_vm.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/gpu/drm/xe/xe_vm.c +32 -0
@@ -38,6 +38,7 @@#include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h" static struct drm_gem_object *xe_vm_obj (struct xe_vm *vm) {
@@ -2917,6 +2918,34 @@ static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,return 0 ; } +static bool __xe_vm_needs_clear_scratch_pages (struct xe_device *xe, +struct xe_vm *vm,u32 bind_flags) +{ +if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + +if (bind_flags &DRM_XE_VM_BIND_FLAG_IMMEDIATE ) +return false; + +if (!(IS_LUNARLAKE (xe) ||IS_BATTLEMAGE (xe) ||IS_PANTHERLAKE (xe))) +return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages (struct xe_device *xe,struct xe_vm *vm, +u64 start,u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} +int xe_vm_bind_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {struct xe_device *xe =to_xe_device (dev);
@@ -3062,6 +3091,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)u32 prefetch_region = bind_ops[i].prefetch_mem_region_instance;u16 pat_index = bind_ops[i].pat_index; +if (__xe_vm_needs_clear_scratch_pages (xe, vm, flags)) +__xe_vm_clear_scratch_pages (xe, vm, addr, addr + range); + ops[i] =vm_bind_ioctl_ops_create (vm, bos[i], obj_offset, addr, range, op, flags, prefetch_region, pat_index);
Signature · 1 line
2.26.3
RE: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
-----Original Message-----
From: Intel-xe <[email protected]> On Behalf Of Oak Zeng
Sent: Tuesday, January 28, 2025 2:22 PM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
Quoted 39 lines
When a vm runs under fault mode, if scratch page is enabled, we need to clear the scratch page mapping before
vm_bindfor thevm_bindaddress range. Under fault mode, we depend on recoverable page fault to establish mapping in page table. If scratch page is not cleared, GPU access of address won't cause page fault because it always hits the existing scratch page mapping.When
vm_bindwith IMMEDIATE flag, there is no need of clearing as immediate bind can overwrite the scratch page mapping.So far only is xe2 and xe3 products are allowed to enable scratch page under fault mode. On other platform we don't allow scratch page under fault mode, so no need of such clearing.
Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/xe/xe_vm.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)drivers/gpu/drm/xe/xe_vm.c +4
-0@@ -38,6 +38,7 @@#include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h" static struct drm_gem_object *xe_vm_obj (struct xe_vm *vm) {@@ -2917,6 +2918,34 @@ static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,return 0 ; } +static bool __xe_vm_needs_clear_scratch_pages (struct xe_device *xe, +struct xe_vm *vm,u32 bind_flags) +{
drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo, · line 2933
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +10
-0+if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + +if (bind_flags &DRM_XE_VM_BIND_FLAG_IMMEDIATE ) +return false; + +if (!(IS_LUNARLAKE (xe) ||IS_BATTLEMAGE (xe) ||IS_PANTHERLAKE (xe)))
We should probably break this platform check out into its own function or macro, especially since it's being mirrored in the next patch during xe_vm_create_ioctl. It'd also be easier to extend that way if future platforms also need this functionality.
But other than that:
-Jonathan Cavitt
Quoted 32 lines
drivers/gpu/drm/xe/xe_vm.c +18
-0+return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages (struct xe_device *xe,struct xe_vm *vm, +u64 start,u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} +int xe_vm_bind_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {struct xe_device *xe =to_xe_device (dev);@@ -3062,6 +3091,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)u32 prefetch_region = bind_ops[i].prefetch_mem_region_instance;u16 pat_index = bind_ops[i].pat_index; +if (__xe_vm_needs_clear_scratch_pages (xe, vm, flags)) +__xe_vm_clear_scratch_pages (xe, vm, addr, addr + range); + ops[i] =vm_bind_ioctl_ops_create (vm, bos[i], obj_offset, addr, range, op, flags, prefetch_region, pat_index);Signature · 1 line
2.26.3
Matthew Brost
maintainerRe: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
In reply to Oak ZengQuoted 67 lines · Oak Zeng
When a vm runs under fault mode, if scratch page is enabled, we need to clear the scratch page mapping before
vm_bindfor thevm_bindaddress range. Under fault mode, we depend on recoverable page fault to establish mapping in page table. If scratch page is not cleared, GPU access of address won't cause page fault because it always hits the existing scratch page mapping.When
vm_bindwith IMMEDIATE flag, there is no need of clearing as immediate bind can overwrite the scratch page mapping.So far only is xe2 and xe3 products are allowed to enable scratch page under fault mode. On other platform we don't allow scratch page under fault mode, so no need of such clearing.
Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/xe/xe_vm.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)drivers/gpu/drm/xe/xe_vm.c +29
-0@@ -38,6 +38,7 @@#include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h" static struct drm_gem_object *xe_vm_obj (struct xe_vm *vm) {@@ -2917,6 +2918,34 @@ static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,return 0 ; } +static bool __xe_vm_needs_clear_scratch_pages (struct xe_device *xe, +struct xe_vm *vm,u32 bind_flags) +{ +if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + +if (bind_flags &DRM_XE_VM_BIND_FLAG_IMMEDIATE ) +return false; + +if (!(IS_LUNARLAKE (xe) ||IS_BATTLEMAGE (xe) ||IS_PANTHERLAKE (xe))) +return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages (struct xe_device *xe,struct xe_vm *vm, +u64 start,u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} +int xe_vm_bind_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {struct xe_device *xe =to_xe_device (dev);
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 3095
Quoted 5 lines
drivers/gpu/drm/xe/xe_vm.c +2
-0@@ -3062,6 +3091,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)u32 prefetch_region = bind_ops[i].prefetch_mem_region_instance;u16 pat_index = bind_ops[i].pat_index; +if (__xe_vm_needs_clear_scratch_pages (xe, vm, flags)) +__xe_vm_clear_scratch_pages (xe, vm, addr, addr + range);
A few things...
- I believe this is only needed for bind user operations or internal MAP GPU VMA operations.
- I believe a TLB invalidation will be required.
- I don't think calling zap PTEs range works here, given how the scratch tables are set up (i.e., new PTEs need to be created pointing to an invalid state).
- This series appears to be untested based on the points above.
Therefore, instead of this series, I believe you will need to fully update the bind pipeline to process MAP GPU VMA operations here.
So roughly...
- Maybe include a bit in xe_vma_op_map that specifies "invalidate on bind," set in vm_bind_ioctl_ops_create, since this will need to be wired throughout the bind pipeline.
- Don't validate backing memory in this case.
- Ensure that xe_vma_ops_incr_pt_update_ops is called in this case for MAP operations, forcing entry into the xe_pt.c backend.
- Update xe_pt_stage_bind_walk with a variable that indicates clearing the PTE. Instead of calling pte_encode_vma in xe_pt_stage_bind_entry, set this variable for PT bind operations derived from MAP operations that meet the "invalidate on bind" condition.
- Ensure needs_invalidation is set in struct xe_vm_pgtable_update_ops if a MAP operation is included that meets the "invalidate on bind" condition.
- Set the VMA tile_invalidated in addition to tile_present for MAP operations that meet the "invalidate on bind" condition.
I might be missing some implementation details mentioned above, but this should provide you with some direction.
Lastly, and perhaps most importantly, please test this using an IGT and include the results in the next post.
Matt
Quoted 7 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0+ ops[i] =vm_bind_ioctl_ops_create (vm, bos[i], obj_offset, addr, range, op, flags, prefetch_region, pat_index);Signature · 1 line
2.26.3
Matthew Brost
maintainerRe: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
Quoted 89 lines · Matthew Brost
Quoted 67 lines · Oak Zeng
When a vm runs under fault mode, if scratch page is enabled, we need to clear the scratch page mapping before
vm_bindfor thevm_bindaddress range. Under fault mode, we depend on recoverable page fault to establish mapping in page table. If scratch page is not cleared, GPU access of address won't cause page fault because it always hits the existing scratch page mapping.When
vm_bindwith IMMEDIATE flag, there is no need of clearing as immediate bind can overwrite the scratch page mapping.So far only is xe2 and xe3 products are allowed to enable scratch page under fault mode. On other platform we don't allow scratch page under fault mode, so no need of such clearing.
Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/xe/xe_vm.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)drivers/gpu/drm/xe/xe_vm.c +29
-0@@ -38,6 +38,7 @@#include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h" static struct drm_gem_object *xe_vm_obj (struct xe_vm *vm) {@@ -2917,6 +2918,34 @@ static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,return 0 ; } +static bool __xe_vm_needs_clear_scratch_pages (struct xe_device *xe, +struct xe_vm *vm,u32 bind_flags) +{ +if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + +if (bind_flags &DRM_XE_VM_BIND_FLAG_IMMEDIATE ) +return false; + +if (!(IS_LUNARLAKE (xe) ||IS_BATTLEMAGE (xe) ||IS_PANTHERLAKE (xe))) +return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages (struct xe_device *xe,struct xe_vm *vm, +u64 start,u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} +int xe_vm_bind_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {struct xe_device *xe =to_xe_device (dev);drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 3095
Quoted 5 lines
drivers/gpu/drm/xe/xe_vm.c +2
-0@@ -3062,6 +3091,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)u32 prefetch_region = bind_ops[i].prefetch_mem_region_instance;u16 pat_index = bind_ops[i].pat_index; +if (__xe_vm_needs_clear_scratch_pages (xe, vm, flags)) +__xe_vm_clear_scratch_pages (xe, vm, addr, addr + range);A few things...
- I believe this is only needed for bind user operations or internal MAP GPU VMA operations.
- I believe a TLB invalidation will be required.
- I don't think calling zap PTEs range works here, given how the scratch tables are set up (i.e., new PTEs need to be created pointing to an invalid state).
- This series appears to be untested based on the points above.Therefore, instead of this series, I believe you will need to fully update the bind pipeline to process MAP GPU VMA operations here.
So roughly...
Quoted 10 lines
- Maybe include a bit in
xe_vma_op_mapthat specifies "invalidate on bind," set invm_bind_ioctl_ops_create, since this will need to be wired throughout the bind pipeline.
- Don't validate backing memory in this case.
- Ensure thatxe_vma_ops_incr_pt_update_opsis called in this case for MAP operations, forcing entry into thexe_pt.cbackend.
- Updatexe_pt_stage_bind_walkwith a variable that indicates clearing the PTE. Instead of callingpte_encode_vmainxe_pt_stage_bind_entry, set this variable for PT bind operations derived from MAP operations that meet the "invalidate on bind" condition.
Ugh, typos / nonsense here. Let me try again.
"Update xe_pt_stage_bind_walk with a variable that indicates clearing the PTE, set this for MAP ops that meet the 'invalidate on bind' condition. When this variable is set, instead of calling pte_encode_vma in xe_pt_stage_bind_entry, call a function which encodes an invalid PTE."
Matt
Quoted 21 lines
- Ensure
needs_invalidationis set in structxe_vm_pgtable_update_opsif a MAP operation is included that meets the "invalidate on bind" condition.
- Set the VMAtile_invalidatedin addition totile_presentfor MAP operations that meet the "invalidate on bind" condition.I might be missing some implementation details mentioned above, but this should provide you with some direction.
Lastly, and perhaps most importantly, please test this using an IGT and include the results in the next post.
Matt
Quoted 7 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0+ ops[i] =vm_bind_ioctl_ops_create (vm, bos[i], obj_offset, addr, range, op, flags, prefetch_region, pat_index);Signature · 1 line
2.26.3
Thomas Hellström
maintainerRe: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
Quoted 130 lines · Matthew Brost
Quoted 110 lines · Matthew Brost
Quoted 89 lines · Oak Zeng
When a vm runs under fault mode, if scratch page is enabled, we need
to clear the scratch page mapping beforevm_bindfor thevm_bindaddress range. Under fault mode, we depend on recoverable page fault
to establish mapping in page table. If scratch page is not cleared,
GPU access of address won't cause page fault because it always hits
the existing scratch page mapping.When
vm_bindwith IMMEDIATE flag, there is no need of clearing as immediate bind can overwrite the scratch page mapping.So far only is xe2 and xe3 products are allowed to enable scratch page
under fault mode. On other platform we don't allow scratch page under
fault mode, so no need of such clearing.Signed-off-by Oak Zeng <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c | 32 ++++++++++++++++++++++++++++++++1 file changed, 32 insertions(+)drivers/gpu/drm/xe/xe_vm.c +1
-0@@ -38,6 +38,7 @@ #include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h"
static structdrm_gem_object*xe_vm_obj(structxe_vm*vm) {drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2917,6 +2918,34 @@ static intxe_vm_bind_ioctl_validate_bo(struct
xe_device*xe, structxe_bo*bo,
return 0;
}
+static bool __xe_vm_needs_clear_scratch_pages(structxe_device*xe,drivers/gpu/drm/xe/xe_vm.c +1
-0+ struct xe_vm *vm,u32
bind_flags)drivers/gpu/drm/xe/xe_vm.c +11
-0+{ +if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + +if (bind_flags &DRM_XE_VM_BIND_FLAG_IMMEDIATE ) +return false; + + if (!(IS_LUNARLAKE(xe) || IS_BATTLEMAGE(xe) ||
IS_PANTHERLAKE(xe)))drivers/gpu/drm/xe/xe_vm.c +6
-0+return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages(struct xe_device *xe,struct
xe_vm*vm,drivers/gpu/drm/xe/xe_vm.c +9
-0+ u64 start, u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} +int
xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
{
structxe_device*xe =to_xe_device(dev);drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -3062,6 +3091,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)u32
prefetch_region= bind_ops[i].prefetch_mem_region_instance;
u16pat_index= bind_ops[i].pat_index;drivers/gpu/drm/xe/xe_vm.c +1
-0+ if (__xe_vm_needs_clear_scratch_pages(xe, vm,flags))
drivers/gpu/drm/xe/xe_vm.c +1
-0+ __xe_vm_clear_scratch_pages(xe, vm,Quoted 1 line
addr, addr + range);
A few things...
- I believe this is only needed for bind user operations or internal MAP
GPU VMA operations.
- I believe a TLB invalidation will be required.
- I don't think calling zap PTEs range works here, given how the scratch
tables are set up (i.e., new PTEs need to be created pointing to an
invalid state).
- This series appears to be untested based on the points above.Therefore, instead of this series, I believe you will need to fully update the bind pipeline to process MAP GPU VMA operations here.
So roughly...
Quoted 16 lines
- Maybe include a bit in
xe_vma_op_mapthat specifies "invalidate on
bind," set invm_bind_ioctl_ops_create, since this will need to be
wired throughout the bind pipeline.
- Don't validate backing memory in this case.
- Ensure thatxe_vma_ops_incr_pt_update_opsis called in this case for
MAP operations, forcing entry into thexe_pt.cbackend.
- Updatexe_pt_stage_bind_walkwith a variable that indicates clearing
the PTE. Instead of callingpte_encode_vmainxe_pt_stage_bind_entry,
set this variable for PT bind operations derived from MAP operations
that meet the "invalidate on bind" condition.Ugh, typos / nonsense here. Let me try again.
Quoted 8 lines
"Update
xe_pt_stage_bind_walkwith a variable that indicates clearing the PTE, set this for MAP ops that meet the 'invalidate on bind' condition. When this variable is set, instead of callingpte_encode_vma
inxe_pt_stage_bind_entry, call a function which encodes an invalid PTE."Matt
I agree with Matt here. This needs to look just like a regular bind, with the exception that PTEs are cleared instead of pointing towards valid pages.
/Thomas
RE: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
In reply to Matthew BrostQuoted 98 lines
-----Original Message-----
From: Brost, Matthew <[email protected]>
Sent: January 28, 2025 6:19 PM
To: Zeng, Oak <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/3] drm/xe: Clear scratch page beforevm_bindQuoted 1 line · Oak Zeng
When a vm runs under fault mode, if scratch page is enabled, we
need
Quoted 2 lines
to clear the scratch page mapping before
vm_bindfor thevm_bindaddress range. Under fault mode, we depend on recoverable pagefault
Quoted 8 lines
to establish mapping in page table. If scratch page is not cleared, GPU access of address won't cause page fault because it always hits the existing scratch page mapping.
When
vm_bindwith IMMEDIATE flag, there is no need of clearing as immediate bind can overwrite the scratch page mapping.So far only is xe2 and xe3 products are allowed to enable scratch
page
Quoted 1 line
under fault mode. On other platform we don't allow scratch page
under
Quoted 5 lines
fault mode, so no need of such clearing.
Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/xe/xe_vm.c | 32++++++++++++++++++++++++++++++++
Review
Quoted 3 lines
1 file changed, 32 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/xe/xe_vm.cdrivers/gpu/drm/xe/xe_vm.c static int
Quoted 12 lines
index
690330352d4c..196d347c6ac0100644drivers/gpu/drm/xe/xe_vm.c +1
-0@@ -38,6 +38,7 @@#include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h" static struct drm_gem_object *xe_vm_obj (struct xe_vm *vm) {@@ -2917,6 +2918,34 @@ static intxe_vm_bind_ioctl_validate_bo(struct
xe_device*xe, structxe_bo*bo,drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0return 0 ; } +static bool __xe_vm_needs_clear_scratch_pages(struct xe_device*xe,
drivers/gpu/drm/xe/xe_vm.c static int · line 2922
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +1
-0+struct xe_vm *vm, u32
bind_flags)drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 11 lines
drivers/gpu/drm/xe/xe_vm.c +11
-0+{ +if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + +if (bind_flags &DRM_XE_VM_BIND_FLAG_IMMEDIATE ) +return false; + + if (!(IS_LUNARLAKE(xe) || IS_BATTLEMAGE(xe) ||
IS_PANTHERLAKE(xe)))drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +6
-0+return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages(struct xe_device *xe,struct
xe_vm*vm,drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +9
-0+ u64 start, u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} + 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
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0{struct xe_device *xe =to_xe_device (dev);@@ -3062,6 +3091,9 @@ 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 · line 3091
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +0
-0u32 prefetch_region =bind_ops[i].prefetch_mem_region_instance;
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0u16 pat_index = bind_ops[i].pat_index; + if (__xe_vm_needs_clear_scratch_pages(xe, vm,flags))
Quoted 7 lines
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device · line 3095
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +1
-0+ __xe_vm_clear_scratch_pages(xe, vm, addr,addr + range);
A few things...
- I believe this is only needed for bind user operations or internal MAP GPU VMA operations.
Did you mean this is only needed for user bind, but not for internal map?
Quoted 1 line
- I believe a TLB invalidation will be required.
My understanding is, NULL pte won't be cached in TLB, so TLB invalidation is not needed.
Quoted 3 lines
- I don't think calling zap PTEs range works here, given how the scratch tables are set up (i.e., new PTEs need to be created pointing to an invalid state).
You are right.
I didn't realize that using xe_pt_walk_shared to walk and zap PTEs has a limitation:
For the virtual address range we want to zap, all the page tables has to be already exist. This interface doesn't create new page tables. Even though xe_pt_walk_shared takes a range parameter (addr, end), range parameter can't be arbitrary.
Today only [xe_vma_start, xe_vma_end) is used to specify the xe_pt_walk_shared Walking range. Arbitrary range won't work as you pointed out. To me this is a small Interface design issue. If you agree, I can re-parameterize xe_pt_walk_shared to take VMA vs addr/end. This way people won't make the same mistake in the future.
Anyway, I will follow the direction you give below to rework this series.
Oak
Quoted 46 lines
- This series appears to be untested based on the points above.
Therefore, instead of this series, I believe you will need to fully update the bind pipeline to process MAP GPU VMA operations here.
So roughly...
- Maybe include a bit in
xe_vma_op_mapthat specifies "invalidate on bind," set invm_bind_ioctl_ops_create, since this will need to be wired throughout the bind pipeline.
- Don't validate backing memory in this case.
- Ensure thatxe_vma_ops_incr_pt_update_opsis called in this case for
MAP operations, forcing entry into thexe_pt.cbackend.
- Updatexe_pt_stage_bind_walkwith a variable that indicates clearing
the PTE. Instead of callingpte_encode_vmainxe_pt_stage_bind_entry,
set this variable for PT bind operations derived from MAP operations that meet the "invalidate on bind" condition.
- Ensureneeds_invalidationis set in structxe_vm_pgtable_update_opsif
a MAP operation is included that meets the "invalidate on bind" condition.
- Set the VMAtile_invalidatedin addition totile_presentfor MAP operations that meet the "invalidate on bind" condition.I might be missing some implementation details mentioned above, but this
should provide you with some direction.Lastly, and perhaps most importantly, please test this using an IGT and
include the results in the next post.Matt
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device · line 3097
Quoted 2 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0+ ops[i] = vm_bind_ioctl_ops_create(vm, bos[i],
obj_offset,drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device · line 3099
Quoted 2 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0addr, range, op, flags, prefetch_region,
pat_index);Quoted 3 lines
--
2.26.3
Matthew Brost
maintainerRe: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
Quoted 101 lines · Oak
Quoted 101 lines
-----Original Message-----
From: Brost, Matthew <[email protected]>
Sent: January 28, 2025 6:19 PM
To: Zeng, Oak <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/3] drm/xe: Clear scratch page beforevm_bindQuoted 1 line · Oak Zeng
When a vm runs under fault mode, if scratch page is enabled, we
need
Quoted 2 lines
to clear the scratch page mapping before
vm_bindfor thevm_bindaddress range. Under fault mode, we depend on recoverable pagefault
Quoted 8 lines
to establish mapping in page table. If scratch page is not cleared, GPU access of address won't cause page fault because it always hits the existing scratch page mapping.
When
vm_bindwith IMMEDIATE flag, there is no need of clearing as immediate bind can overwrite the scratch page mapping.So far only is xe2 and xe3 products are allowed to enable scratch
page
Quoted 1 line
under fault mode. On other platform we don't allow scratch page
under
Quoted 5 lines
fault mode, so no need of such clearing.
Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/xe/xe_vm.c | 32++++++++++++++++++++++++++++++++
Review
Quoted 3 lines
1 file changed, 32 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/xe/xe_vm.cdrivers/gpu/drm/xe/xe_vm.c static int
Quoted 12 lines
index
690330352d4c..196d347c6ac0100644drivers/gpu/drm/xe/xe_vm.c +1
-0@@ -38,6 +38,7 @@#include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h" static struct drm_gem_object *xe_vm_obj (struct xe_vm *vm) {@@ -2917,6 +2918,34 @@ static intxe_vm_bind_ioctl_validate_bo(struct
xe_device*xe, structxe_bo*bo,drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0return 0 ; } +static bool __xe_vm_needs_clear_scratch_pages(struct xe_device*xe,
drivers/gpu/drm/xe/xe_vm.c static int · line 2922
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +1
-0+struct xe_vm *vm, u32
bind_flags)drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 11 lines
drivers/gpu/drm/xe/xe_vm.c +11
-0+{ +if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + +if (bind_flags &DRM_XE_VM_BIND_FLAG_IMMEDIATE ) +return false; + + if (!(IS_LUNARLAKE(xe) || IS_BATTLEMAGE(xe) ||
IS_PANTHERLAKE(xe)))drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +6
-0+return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages(struct xe_device *xe,struct
xe_vm*vm,drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +9
-0+ u64 start, u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} + 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
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0{struct xe_device *xe =to_xe_device (dev);@@ -3062,6 +3091,9 @@ 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 · line 3091
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +0
-0u32 prefetch_region =bind_ops[i].prefetch_mem_region_instance;
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0u16 pat_index = bind_ops[i].pat_index; + if (__xe_vm_needs_clear_scratch_pages(xe, vm,flags))
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device · line 3095
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +1
-0+ __xe_vm_clear_scratch_pages(xe, vm, addr,addr + range);
Quoted 7 lines
Quoted 4 lines
A few things...
- I believe this is only needed for bind user operations or internal MAP GPU VMA operations.
Did you mean this is only needed for user bind, but not for internal map?
Needed for user bind and also for internal MAP. With updating the bind pipeline you will only care MAP ops.
Quoted 4 lines
Quoted 1 line
- I believe a TLB invalidation will be required.
My understanding is, NULL pte won't be cached in TLB, so TLB invalidation is not needed.
I would think NULL ptes are cached but not certain either way.
Quoted 11 lines
Quoted 3 lines
- I don't think calling zap PTEs range works here, given how the scratch tables are set up (i.e., new PTEs need to be created pointing to an invalid state).
You are right.
I didn't realize that using
xe_pt_walk_sharedto walk and zap PTEs has a limitation:
For the virtual address range we want to zap, all the page tables has to be already exist. This interface doesn't create new page tables. Even thoughxe_pt_walk_sharedtakes a range parameter (addr, end), range parameter can't be arbitrary.
Quoted 5 lines
Today only [
xe_vma_start,xe_vma_end) is used to specify thexe_pt_walk_sharedWalking range. Arbitrary range won't work as you pointed out. To me this is a small Interface design issue. If you agree, I can re-parameterizexe_pt_walk_sharedto take VMA vs addr/end. This way people won't make the same mistake in the future.
Ah, no. SVM will use ranges so I think (addr, end) are the right parameters for internal PT functions.
Quoted 2 lines
Anyway, I will follow the direction you give below to rework this series.
+1
Matt
Quoted 48 lines
Oak
Quoted 46 lines
- This series appears to be untested based on the points above.
Therefore, instead of this series, I believe you will need to fully update the bind pipeline to process MAP GPU VMA operations here.
So roughly...
- Maybe include a bit in
xe_vma_op_mapthat specifies "invalidate on bind," set invm_bind_ioctl_ops_create, since this will need to be wired throughout the bind pipeline.
- Don't validate backing memory in this case.
- Ensure thatxe_vma_ops_incr_pt_update_opsis called in this case for
MAP operations, forcing entry into thexe_pt.cbackend.
- Updatexe_pt_stage_bind_walkwith a variable that indicates clearing
the PTE. Instead of callingpte_encode_vmainxe_pt_stage_bind_entry,
set this variable for PT bind operations derived from MAP operations that meet the "invalidate on bind" condition.
- Ensureneeds_invalidationis set in structxe_vm_pgtable_update_opsif
a MAP operation is included that meets the "invalidate on bind" condition.
- Set the VMAtile_invalidatedin addition totile_presentfor MAP operations that meet the "invalidate on bind" condition.I might be missing some implementation details mentioned above, but this
should provide you with some direction.Lastly, and perhaps most importantly, please test this using an IGT and
include the results in the next post.Matt
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device · line 3097
Quoted 2 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0+ ops[i] = vm_bind_ioctl_ops_create(vm, bos[i],
obj_offset,drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct drm_device · line 3099
Quoted 2 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0addr, range, op, flags, prefetch_region,
pat_index);Quoted 3 lines
--
2.26.3
Thomas Hellström
maintainerRe: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
Quoted 126 lines · Matthew Brost
Quoted 111 lines · Oak
Quoted 111 lines
-----Original Message-----
From: Brost, Matthew <[email protected]>
Sent: January 28, 2025 6:19 PM
To: Zeng, Oak <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/3] drm/xe: Clear scratch page beforevm_bindQuoted 1 line · Oak Zeng
When a vm runs under fault mode, if scratch page is enabled, we
need
Quoted 3 lines
to clear the scratch page mapping before
vm_bindfor thevm_bind
address range. Under fault mode, we depend on recoverable pagefault
Quoted 6 lines
to establish mapping in page table. If scratch page is not cleared,
GPU access of address won't cause page fault because it always hits
the existing scratch page mapping.Quoted 6 lines
When
vm_bindwith IMMEDIATE flag, there is no need of clearing as
immediate bind can overwrite the scratch page mapping.So far only is xe2 and xe3 products are allowed to enable scratch
page
Quoted 1 line
under fault mode. On other platform we don't allow scratch page
under
Quoted 5 lines
fault mode, so no need of such clearing.
Signed-off-by Oak Zeng <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c | 32++++++++++++++++++++++++++++++++
Review
Quoted 3 lines
1 file changed, 32 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/xe/xe_vm.cdrivers/gpu/drm/xe/xe_vm.c static int
Quoted 12 lines
index
690330352d4c..196d347c6ac0100644drivers/gpu/drm/xe/xe_vm.c +1
-0@@ -38,6 +38,7 @@ #include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h" static struct drm_gem_object *xe_vm_obj(struct xe_vm *vm) {@@ -2917,6 +2918,34 @@ static intxe_vm_bind_ioctl_validate_bo(struct
xe_device*xe, structxe_bo*bo,drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0return 0; } +static bool __xe_vm_needs_clear_scratch_pages(struct xe_device*xe,
drivers/gpu/drm/xe/xe_vm.c static int · line 2923
Quoted 2 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0+ struct xe_vm *vm, u32
bind_flags)drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 11 lines
drivers/gpu/drm/xe/xe_vm.c +11
-0+{ +if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + +if (bind_flags &DRM_XE_VM_BIND_FLAG_IMMEDIATE ) +return false; + + if (!(IS_LUNARLAKE(xe) || IS_BATTLEMAGE(xe) ||
IS_PANTHERLAKE(xe)))drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +6
-0+return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages(struct xe_device *xe,struct
xe_vm*vm,Quoted 11 lines
drivers/gpu/drm/xe/xe_vm.c +9
-0+ u64 start, u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} + 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
Quoted 3 lines
{
structxe_device*xe =to_xe_device(dev);drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -3062,6 +3091,9 @@ int xe_vm_bind_ioctl(struct drm_device*dev, void *data, struct
drm_file*file)Quoted 1 line
u32
prefetch_region=bind_ops[i].prefetch_mem_region_instance;
drivers/gpu/drm/xe/xe_vm.c
Quoted 3 lines
u16
pat_index= bind_ops[i].pat_index;drivers/gpu/drm/xe/xe_vm.c +1
-0+ if (__xe_vm_needs_clear_scratch_pages(xe, vm,flags))
Quoted 2 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0+ __xe_vm_clear_scratch_pages(xe, vm,addr,
addr + range);
Quoted 9 lines
Quoted 5 lines
A few things...
- I believe this is only needed for bind user operations or internal MAP
GPU VMA operations.Did you mean this is only needed for user bind, but not for internal map?
Needed for user bind and also for internal MAP. With updating the bind
pipeline you will only care MAP ops.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
- I believe a TLB invalidation will be required.
My understanding is, NULL pte won't be cached in TLB, so TLB invalidation is not needed.
I would think NULL ptes are cached but not certain either way.
Note that a NULL / scratch mapping for larger pages may point to a physical page.
/Thomas
Quoted 96 lines
Quoted 18 lines
Quoted 6 lines
- I don't think calling zap PTEs range works here, given how the scratch
tables are set up (i.e., new PTEs need to be created pointing to an
invalid state).You are right.
I didn't realize that using
xe_pt_walk_sharedto walk and zap PTEs has a limitation:
For the virtual address range we want to zap, all the page tables has to be already
exist. This interface doesn't create new page tables. Even thoughxe_pt_walk_shared
takes a range parameter (addr, end), range parameter can't be arbitrary.Quoted 9 lines
Today only [
xe_vma_start,xe_vma_end) is used to specify thexe_pt_walk_shared
Walking range. Arbitrary range won't work as you pointed out. To me this is a small
Interface design issue. If you agree, I can re-parameterizexe_pt_walk_sharedto take
VMA vs addr/end. This way people won't make the same mistake in the future.Ah, no. SVM will use ranges so I think (addr, end) are the right parameters for internal PT functions.
Quoted 3 lines
Anyway, I will follow the direction you give below to rework this series.
+1
Matt
Quoted 57 lines
Oak
Quoted 55 lines
- This series appears to be untested based on the points above.
Therefore, instead of this series, I believe you will need to fully
update the bind pipeline to process MAP GPU VMA operations here.So roughly...
- Maybe include a bit in
xe_vma_op_mapthat specifies "invalidate on
bind," set invm_bind_ioctl_ops_create, since this will need to be
wired throughout the bind pipeline.
- Don't validate backing memory in this case.
- Ensure thatxe_vma_ops_incr_pt_update_opsis called in this case
for
MAP operations, forcing entry into thexe_pt.cbackend.
- Updatexe_pt_stage_bind_walkwith a variable that indicates clearing
the PTE. Instead of callingpte_encode_vmainxe_pt_stage_bind_entry,
set this variable for PT bind operations derived from MAP operations
that meet the "invalidate on bind" condition.
- Ensureneeds_invalidationis set in structxe_vm_pgtable_update_opsif
a MAP operation is included that meets the "invalidate on bind" condition.
- Set the VMAtile_invalidatedin addition totile_presentfor MAP
operations that meet the "invalidate on bind" condition.I might be missing some implementation details mentioned above, but this
should provide you with some direction.Lastly, and perhaps most importantly, please test this using an IGT
and
include the results in the next post.Matt
Quoted 2 lines
+
ops[i] = vm_bind_ioctl_ops_create(vm, bos[i],
obj_offset,Quoted 4 lines
addr, range, op, flags,
prefetch_region,
pat_index);Quoted 3 lines
--
2.26.3
RE: [PATCH 2/3] drm/xe: Clear scratch page before vm_bind
Quoted 151 lines
-----Original Message-----
From: Thomas Hellström <[email protected]>
Sent: January 30, 2025 3:37 AM
To: Brost, Matthew <[email protected]>; Zeng, Oak <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 2/3] drm/xe: Clear scratch page beforevm_bindQuoted 13 lines · Matthew Brost
Quoted 12 lines · Oak
Quoted 12 lines
-----Original Message-----
From: Brost, Matthew <[email protected]>
Sent: January 28, 2025 6:19 PM
To: Zeng, Oak <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/3] drm/xe: Clear scratch page beforevm_bindQuoted 2 lines
Quoted 2 lines
Quoted 2 lines · Oak Zeng
Quoted 1 line
When a vm runs under fault mode, if scratch page is enabled,
we
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
need
Quoted 3 lines
to clear the scratch page mapping before
vm_bindfor thevm_bind
address range. Under fault mode, we depend on recoverablepage
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
fault
Quoted 3 lines
to establish mapping in page table. If scratch page is not cleared,
GPU access of address won't cause page fault because italways
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hits
the existing scratch page mapping.When
vm_bindwith IMMEDIATE flag, there is no need ofclearing
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
as
immediate bind can overwrite the scratch page mapping.So far only is xe2 and xe3 products are allowed to enable scratch
page
Quoted 1 line
under fault mode. On other platform we don't allow scratch
page
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
under
Quoted 5 lines
fault mode, so no need of such clearing.
Signed-off-by Oak Zeng <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c | 32++++++++++++++++++++++++++++++++
Review
Quoted 3 lines
1 file changed, 32 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/xe/xe_vm.cQuoted 9 lines
index
690330352d4c..196d347c6ac0100644drivers/gpu/drm/xe/xe_vm.c +1
-0@@ -38,6 +38,7 @@ #include "xe_trace_bo.h" #include "xe_wa.h" #include "xe_hmm.h" +#include "i915_drv.h" Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c static int
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0static struct drm_gem_object *xe_vm_obj(struct xe_vm *vm) {@@ -2917,6 +2918,34 @@ static intxe_vm_bind_ioctl_validate_bo(struct
xe_device*xe, struct
xe_boQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
*bo,
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0return 0; } +static bool __xe_vm_needs_clear_scratch_pages(struct
xe_deviceQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
*xe,
drivers/gpu/drm/xe/xe_vm.c static int · line 2923
Quoted 2 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0+ struct xe_vm *vm, u32
bind_flags)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 8 lines
drivers/gpu/drm/xe/xe_vm.c +8
-0+{ +if (!xe_vm_in_fault_mode (vm)) +return false; + +if (!xe_vm_has_scratch (vm)) +return false; + + if (bind_flags &
DRM_XE_VM_BIND_FLAG_IMMEDIATE)Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c +3
-0+return false; + + if (!(IS_LUNARLAKE(xe) || IS_BATTLEMAGE(xe) ||
IS_PANTHERLAKE(xe)))drivers/gpu/drm/xe/xe_vm.c static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +6
-0+return false; + +return true; +} + +static void __xe_vm_clear_scratch_pages(struct xe_device*xe,
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
struct
xe_vm*vm,Quoted 11 lines
drivers/gpu/drm/xe/xe_vm.c +9
-0+ u64 start, u64 end) +{ +struct xe_tile *tile; +u8 id; + +for_each_tile (tile, xe, id) +xe_pt_zap_range (tile, vm, start, end); +} + int xe_vm_bind_ioctl(struct drm_device *dev, void *data,struct
drm_file*file)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/xe/xe_vm.c int xe_vm_bind_ioctl(struct
Quoted 3 lines
{
structxe_device*xe =to_xe_device(dev);drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -3062,6 +3091,9 @@ int xe_vm_bind_ioctl(struct
drm_deviceQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
*dev, void *data, struct
drm_file*file)Quoted 1 line
u32
prefetch_region=bind_ops[i].prefetch_mem_region_instance;
drivers/gpu/drm/xe/xe_vm.c
Quoted 3 lines
u16
pat_index= bind_ops[i].pat_index;drivers/gpu/drm/xe/xe_vm.c +1
-0+ if (__xe_vm_needs_clear_scratch_pages(xe,vm,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
flags))
drivers/gpu/drm/xe/xe_vm.c
Quoted 1 line
drivers/gpu/drm/xe/xe_vm.c +1
-0+ __xe_vm_clear_scratch_pages(xe,vm,
Quoted 19 lines
Quoted 12 lines
Quoted 8 lines
Quoted 1 line
addr,
addr + range);
A few things...
- I believe this is only needed for bind user operations or internal MAP
GPU VMA operations.Did you mean this is only needed for user bind, but not for internal map?
Needed for user bind and also for internal MAP. With updating the bind
pipeline you will only care MAP ops.Quoted 2 lines
Quoted 1 line
- I believe a TLB invalidation will be required.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
My understanding is, NULL pte won't be cached in TLB, so TLB invalidation is not needed.
I would think NULL ptes are cached but not certain either way.
Note that a NULL / scratch mapping for larger pages may point to a physical page.
Thanks for pointing this out. Looking at page table definition, some high Level page table indeed doesn't support NULL entry.
So yes TLB invalidation is required.
Oak
Quoted 105 lines
/Thomas
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
- I don't think calling zap PTEs range works here, given how the scratch
tables are set up (i.e., new PTEs need to be created pointing to an
invalid state).You are right.
I didn't realize that using
xe_pt_walk_sharedto walk and zap PTEs has a limitation:
For the virtual address range we want to zap, all the page tables has to be already
exist. This interface doesn't create new page tables. Even thoughxe_pt_walk_shared
takes a range parameter (addr, end), range parameter can't be arbitrary.Quoted 3 lines
Quoted 3 lines
Today only [
xe_vma_start,xe_vma_end) is used to specify thexe_pt_walk_shared
Walking range. Arbitrary range won't work as you pointed out. Tome
Quoted 4 lines
Quoted 4 lines
this is a small
Interface design issue. If you agree, I can re-parameterizexe_pt_walk_sharedto take
VMA vs addr/end. This way people won't make the same mistakein the
Quoted 6 lines
Quoted 2 lines
future.
Ah, no. SVM will use ranges so I think (addr, end) are the right parameters for internal PT functions.
Quoted 15 lines
Quoted 3 lines
Anyway, I will follow the direction you give below to rework this series.
+1
Matt
Quoted 7 lines
Oak
Quoted 5 lines
- This series appears to be untested based on the points above.
Therefore, instead of this series, I believe you will need to fully
update the bind pipeline to process MAP GPU VMA operationshere.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
So roughly...
- Maybe include a bit in
xe_vma_op_mapthat specifies"invalidate
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
on
bind," set invm_bind_ioctl_ops_create, since this will need to be
wired throughout the bind pipeline.
- Don't validate backing memory in this case.
- Ensure thatxe_vma_ops_incr_pt_update_opsis called in this case
for
MAP operations, forcing entry into thexe_pt.cbackend.
- Updatexe_pt_stage_bind_walkwith a variable that indicates clearing
the PTE. Instead of callingpte_encode_vmainxe_pt_stage_bind_entry,
set this variable for PT bind operations derived from MAP operations
that meet the "invalidate on bind" condition.
- Ensureneeds_invalidationis set in structxe_vm_pgtable_update_opsif
a MAP operation is included that meets the "invalidate on bind" condition.
- Set the VMAtile_invalidatedin addition totile_presentfor MAP
operations that meet the "invalidate on bind" condition.Quoted 1 line
Quoted 1 line
Quoted 1 line
I might be missing some implementation details mentioned
above,
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
but this
should provide you with some direction.Lastly, and perhaps most importantly, please test this using an IGT
and
include the results in the next post.Matt
Quoted 2 lines
+
ops[i] = vm_bind_ioctl_ops_create(vm, bos[i],
obj_offset,Quoted 4 lines
addr, range, op, flags,
prefetch_region,
pat_index);Quoted 3 lines
--
2.26.3
PATCH 3/3 drm/xe: Allow scratch page under fault mode for certain platform
In reply to Oak ZengNormally scratch page is not allowed when a vm is operate under page fault mode, i.e., in the existing codes, DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE and DRM_XE_VM_CREATE_FLAG_FAULT_MODE are mutual exclusive. The reason is fault mode relies on recoverable page to work, while scratch page can mute recoverable page fault.
On xe2 and xe3, HW prefetching can cause page fault interrupt. Due to page fault interrupt overhead (i.e., need Guc and KMD involved to fix the page fault), HW prefetching can be slowed by many orders of magnitude.
Fix this problem by allowing scratch page under fault mode for xe2 and xe3. With scratch page in place, HW prefetching could always hit scratch page instead of causing interrupt.
--- drivers/gpu/drm/xe/xe_vm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +5 -4
@@ -1732,6 +1732,11 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_DBG (xe, args->extensions))return -EINVAL ; +if (XE_IOCTL_DBG (xe, args->flags &DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE && + args->flags &DRM_XE_VM_CREATE_FLAG_FAULT_MODE && + !(IS_LUNARLAKE (xe) ||IS_BATTLEMAGE (xe) ||IS_PANTHERLAKE (xe)))) +return -EINVAL ; +if (XE_WA (xe_root_mmio_gt (xe),14016763929 )) args->flags |=DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE ;
@@ -1745,10 +1750,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_FLAG_SCRATCH_PAGE && - args->flags &DRM_XE_VM_CREATE_FLAG_FAULT_MODE )) -return -EINVAL ; -if (XE_IOCTL_DBG (xe, !(args->flags &DRM_XE_VM_CREATE_FLAG_LR_MODE ) && args->flags &DRM_XE_VM_CREATE_FLAG_FAULT_MODE ))return -EINVAL ;
Signature · 1 line
2.26.3
RE: [PATCH 3/3] drm/xe: Allow scratch page under fault mode for certain platform
-----Original Message-----
From: Intel-xe <[email protected]> On Behalf Of Oak Zeng
Sent: Tuesday, January 28, 2025 2:22 PM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 3/3] drm/xe: Allow scratch page under fault mode for certain platform
Quoted 11 lines
Normally scratch page is not allowed when a vm is operate under page fault mode, i.e., in the existing codes,
DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGEandDRM_XE_VM_CREATE_FLAG_FAULT_MODEare mutual exclusive. The reason is fault mode relies on recoverable page to work, while scratch page can mute recoverable page fault.On xe2 and xe3, HW prefetching can cause page fault interrupt. Due to page fault interrupt overhead (i.e., need Guc and KMD involved to fix the page fault), HW prefetching can be slowed by many orders of magnitude.
Quoted 5 lines
Fix this problem by allowing scratch page under fault mode for xe2 and xe3. With scratch page in place, HW prefetching could always hit scratch page instead of causing interrupt.
Signed-off-by Oak Zeng <[email protected]>
LGTM, though see my comment for patch 2 regarding the added platform checks.
-Jonathan Cavitt
Quoted 35 lines
--- drivers/gpu/drm/xe/xe_vm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)drivers/gpu/drm/xe/xe_vm.c +5
-4@@ -1732,6 +1732,11 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_DBG (xe, args->extensions))return -EINVAL ; +if (XE_IOCTL_DBG (xe, args->flags &DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE && + args->flags &DRM_XE_VM_CREATE_FLAG_FAULT_MODE && + !(IS_LUNARLAKE (xe) ||IS_BATTLEMAGE (xe) ||IS_PANTHERLAKE (xe)))) +return -EINVAL ; +if (XE_WA (xe_root_mmio_gt (xe),14016763929 )) args->flags |=DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE ;@@ -1745,10 +1750,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_FLAG_SCRATCH_PAGE && - args->flags &DRM_XE_VM_CREATE_FLAG_FAULT_MODE )) -return -EINVAL ; -if (XE_IOCTL_DBG (xe, !(args->flags &DRM_XE_VM_CREATE_FLAG_LR_MODE ) && args->flags &DRM_XE_VM_CREATE_FLAG_FAULT_MODE ))return -EINVAL ;Signature · 1 line
2.26.3
Thomas Hellström
maintainerRe: [PATCH 3/3] drm/xe: Allow scratch page under fault mode for certain platform
In reply to Oak ZengQuoted 11 lines · Oak Zeng
Normally scratch page is not allowed when a vm is operate under page fault mode, i.e., in the existing codes,
DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE
andDRM_XE_VM_CREATE_FLAG_FAULT_MODEare mutual exclusive. The reason is fault mode relies on recoverable page to work, while scratch page can mute recoverable page fault.On xe2 and xe3, HW prefetching can cause page fault interrupt. Due to page fault interrupt overhead (i.e., need Guc and KMD involved to fix the page fault), HW prefetching can be slowed by many orders of magnitude.
The problem on xe2 and xe3 as I understand it is not the overhead but the fact that OOB prefetching causes pagefaults and we can't resolve those.
Quoted 27 lines
Fix this problem by allowing scratch page under fault mode for xe2 and xe3.
With scratch page in place, HW prefetching could always hit scratch page
instead of causing interrupt.Signed-off-by Oak Zeng <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c | 9 +++++----1 file changed, 5 insertions(+), 4 deletions(-)drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1732,6 +1732,11 @@ int xe_vm_create_ioctl(struct drm_device *dev,void *data, if (XE_IOCTL_DBG(xe, args->extensions)) return -EINVAL;drivers/gpu/drm/xe/xe_vm.c +1
-0+ if (XE_IOCTL_DBG(xe, args->flags &
DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE&&drivers/gpu/drm/xe/xe_vm.c +1
-0+ args->flags &
DRM_XE_VM_CREATE_FLAG_FAULT_MODE&&drivers/gpu/drm/xe/xe_vm.c +1
-0+ !(IS_LUNARLAKE(xe) || IS_BATTLEMAGE(xe) ||
IS_PANTHERLAKE(xe))))
drivers/gpu/drm/xe/xe_vm.c int xe_vm_create_ioctl(struct drm_device *dev, void *data, · line 1739
Quoted 2 lines
drivers/gpu/drm/xe/xe_vm.c +2
-0+return -EINVAL ; +
Could we perhaps add a bit in the xe->info structure?
/Thomas
Quoted 20 lines
if (
XE_WA(xe_root_mmio_gt(xe), 14016763929))args->flags|=DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1745,10 +1750,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;drivers/gpu/drm/xe/xe_vm.c +0
-1- if (XE_IOCTL_DBG(xe, args->flags &
DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE&&drivers/gpu/drm/xe/xe_vm.c +0
-1- args->flags &
DRM_XE_VM_CREATE_FLAG_FAULT_MODE))drivers/gpu/drm/xe/xe_vm.c +0
-2-return -EINVAL ; -if (XE_IOCTL_DBG(xe, !(args->flags &
DRM_XE_VM_CREATE_FLAG_LR_MODE) &&
args->flags&DRM_XE_VM_CREATE_FLAG_FAULT_MODE))
return-EINVAL;
Matthew Brost
maintainerRe: [PATCH 3/3] drm/xe: Allow scratch page under fault mode for certain platform
Quoted 40 lines · Thomas Hellström
Quoted 11 lines · Oak Zeng
Normally scratch page is not allowed when a vm is operate under page fault mode, i.e., in the existing codes,
DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE
andDRM_XE_VM_CREATE_FLAG_FAULT_MODEare mutual exclusive. The reason is fault mode relies on recoverable page to work, while scratch page can mute recoverable page fault.On xe2 and xe3, HW prefetching can cause page fault interrupt. Due to page fault interrupt overhead (i.e., need Guc and KMD involved to fix the page fault), HW prefetching can be slowed by many orders of magnitude.
The problem on xe2 and xe3 as I understand it is not the overhead but the fact that OOB prefetching causes pagefaults and we can't resolve those.
Quoted 23 lines
Fix this problem by allowing scratch page under fault mode for xe2 and xe3.
With scratch page in place, HW prefetching could always hit scratch page
instead of causing interrupt.Signed-off-by Oak Zeng <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c | 9 +++++----1 file changed, 5 insertions(+), 4 deletions(-)drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1732,6 +1732,11 @@ int xe_vm_create_ioctl(struct drm_device *dev,void *data, if (XE_IOCTL_DBG(xe, args->extensions)) return -EINVAL;drivers/gpu/drm/xe/xe_vm.c +1
-0+ if (XE_IOCTL_DBG(xe, args->flags &
DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE&&
Quoted 9 lines
drivers/gpu/drm/xe/xe_vm.c int xe_vm_create_ioctl(struct drm_device *dev, void *data, · line 1739
Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +1
-0+ args->flags &
DRM_XE_VM_CREATE_FLAG_FAULT_MODE&&drivers/gpu/drm/xe/xe_vm.c +1
-0+ !(IS_LUNARLAKE(xe) || IS_BATTLEMAGE(xe) ||
IS_PANTHERLAKE(xe))))drivers/gpu/drm/xe/xe_vm.c +2
-0+return -EINVAL ; +Could we perhaps add a bit in the
xe->infostructure?
+1. This seems like a good idea.
Matt
Quoted 24 lines
/Thomas
Quoted 20 lines
if (
XE_WA(xe_root_mmio_gt(xe), 14016763929))args->flags|=DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -1745,10 +1750,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;drivers/gpu/drm/xe/xe_vm.c +0
-1- if (XE_IOCTL_DBG(xe, args->flags &
DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE&&drivers/gpu/drm/xe/xe_vm.c +0
-1- args->flags &
DRM_XE_VM_CREATE_FLAG_FAULT_MODE))drivers/gpu/drm/xe/xe_vm.c +0
-2-return -EINVAL ; -if (XE_IOCTL_DBG(xe, !(args->flags &
DRM_XE_VM_CREATE_FLAG_LR_MODE) &&
args->flags&DRM_XE_VM_CREATE_FLAG_FAULT_MODE))
return-EINVAL;
-----Original Message-----
From: Intel-xe <[email protected]> On Behalf Of Oak Zeng
Sent: Tuesday, January 28, 2025 2:22 PM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 1/3] drm/xe: Add a function to zap page table by address range
Quoted 20 lines
Add a function
xe_pt_zap_range. This is similar toxe_pt_zap_ptesbut is used when we don't have a vma to work with, such as zap a range mapped to scratch page where we don't have vma.Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/xe/xe_pt.c | 28 ++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_pt.h | 2 ++ 2 files changed, 30 insertions(+)drivers/gpu/drm/xe/xe_pt.c +1
-0@@ -792,6 +792,34 @@ static const struct xe_pt_walk_ops xe_pt_zap_ptes_ops = { .pt_entry = xe_pt_zap_ptes_entry, }; +/**
drivers/gpu/drm/xe/xe_pt.c static const struct xe_pt_walk_ops xe_pt_zap_ptes_ops = { · line 805
Quoted 10 lines
drivers/gpu/drm/xe/xe_pt.c +10
-0+* xe_pt_zap_range() - Zap (zero) gpu ptes of an virtual address range +* @tile: The tile we're zapping for. +* @vm: The vm we're zapping for. +* @start: Start of the virtual address range, inclusive. +* @end: End of the virtual address range, exclusive. +* +* This is similar to xe_pt_zap_ptes() but it's used when we don't have a +* vma to work with. This is used for example when we're clearing the scratch +* page mapping during vm_bind. +*
NIT:
The asterisk here can be removed.
drivers/gpu/drm/xe/xe_pt.c static const struct xe_pt_walk_ops xe_pt_zap_ptes_ops = { · line 807
Quoted 2 lines
drivers/gpu/drm/xe/xe_pt.c +2
-0+*/ +void xe_pt_zap_range (struct xe_tile *tile,struct xe_vm *vm,u64 start,u64 end)
It looks like the function xe_pt_zap_ptes returns if the walk needs to be invalidated. Will that also be needed here?
Assuming not:
-Jonathan Cavitt
Quoted 33 lines
drivers/gpu/drm/xe/xe_pt.c +15
-0+{ +struct xe_pt_zap_ptes_walk xe_walk = { + .base = { + .ops = &xe_pt_zap_ptes_ops, + .shifts = xe_normal_pt_shifts, + .max_level =XE_PT_HIGHEST_LEVEL , + }, + .tile = tile, + }; +struct xe_pt *pt = vm->pt_root[tile->id]; + + (void )xe_pt_walk_shared (&pt->base, pt->level, start, + end, &xe_walk.base); +} +/** * xe_pt_zap_ptes() - Zap (zero) gpu ptes of an address range * @tile: The tile we're zapping for. drivers/gpu/drm/xe/xe_pt.h +2
-0@@ -43,4 +43,6 @@ void xe_pt_update_ops_abort(struct xe_tile *tile, struct xe_vma_ops *vops);bool xe_pt_zap_ptes (struct xe_tile *tile,struct xe_vma *vma); +void xe_pt_zap_range (struct xe_tile *tile,struct xe_vm *vm,u64 start,u64 end); +#endif Signature · 1 line
2.26.3
Patchwork
CI✓ CI.Patch_applied: success for series starting with [1/3] drm/xe: Add a function to zap page table by address range
In reply to Oak Zeng== Series Details ==
== Series Details ==
Series: series starting with [1/3] drm/xe: Add a function to zap page table by address range
URL : https://patchwork.freedesktop.org/series/144072/
State : success
== Summary ==
=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 8f3ba847175b drm-tip: 2025y-01m-28d-22h-47m-54s UTC integration manifest === git am output follows ===
Applying: drm/xe: Add a function to zap page table by address range
Applying: drm/xe: Clear scratch page before vm_bind
Applying: drm/xe: Allow scratch page under fault mode for certain platform
Patchwork
CI✓ CI.checkpatch: success for series starting with [1/3] drm/xe: Add a function to zap page table by address range
In reply to Oak Zeng== Series Details ==
== Series Details ==
Series: series starting with [1/3] drm/xe: Add a function to zap page table by address range
URL : https://patchwork.freedesktop.org/series/144072/
State : success
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 30ab6715fc09baee6cc14cb3c89ad8858688d474
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit cb0f1cdb1d31379f15c7b5e96e66a8c4d48691ee
Author: Oak Zeng <[email protected]> Date: Tue Jan 28 17:21:45 2025 -0500
drm/xe: Allow scratch page under fault mode for certain platform
Normally scratch page is not allowed when a vm is operate under page fault mode, i.e., in the existing codes, DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE and DRM_XE_VM_CREATE_FLAG_FAULT_MODE are mutual exclusive. The reason is fault mode relies on recoverable page to work, while scratch page can mute recoverable page fault.
On xe2 and xe3, HW prefetching can cause page fault interrupt. Due to page fault interrupt overhead (i.e., need Guc and KMD involved to fix the page fault), HW prefetching can be slowed by many orders of magnitude.
Fix this problem by allowing scratch page under fault mode for xe2 and xe3. With scratch page in place, HW prefetching could always hit scratch page instead of causing interrupt.
+ /mt/dim checkpatch 8f3ba847175bfd495cbfe5b51d3cdfd8d32d24db drm-intel fc3c14dbb3cb drm/xe: Add a function to zap page table by address range 108d849b4e71 drm/xe: Clear scratch page before vm_bind cb0f1cdb1d31 drm/xe: Allow scratch page under fault mode for certain platform
Patchwork
CI✗ CI.KUnit: failure for series starting with [1/3] drm/xe: Add a function to zap page table by address range
In reply to Oak Zeng== Series Details ==
== Series Details ==
Series: series starting with [1/3] drm/xe: Add a function to zap page table by address range
URL : https://patchwork.freedesktop.org/series/144072/
State : failure
== Summary ==
+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:../lib/iomap.c:156:5: warning: no previous prototype for ‘ioread64_lo_hi’ [-Wmissing-prototypes] 156 | u64 ioread64_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:163:5: warning: no previous prototype for ‘ioread64_hi_lo’ [-Wmissing-prototypes]
163 | u64 ioread64_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:170:5: warning: no previous prototype for ‘ioread64be_lo_hi’ [-Wmissing-prototypes]
170 | u64 ioread64be_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:178:5: warning: no previous prototype for ‘ioread64be_hi_lo’ [-Wmissing-prototypes]
178 | u64 ioread64be_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:264:6: warning: no previous prototype for ‘iowrite64_lo_hi’ [-Wmissing-prototypes]
264 | void iowrite64_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:272:6: warning: no previous prototype for ‘iowrite64_hi_lo’ [-Wmissing-prototypes]
272 | void iowrite64_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:280:6: warning: no previous prototype for ‘iowrite64be_lo_hi’ [-Wmissing-prototypes]
280 | void iowrite64be_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~
../lib/iomap.c:288:6: warning: no previous prototype for ‘iowrite64be_hi_lo’ [-Wmissing-prototypes]
288 | void iowrite64be_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/xe_vm.c:41:10: fatal error: i915_drv.h: No such file or directory
41 | #include "i915_drv.h"
| ^~~~~~~~~~~~compilation terminated.
make[7]: *** [../scripts/Makefile.build:194: drivers/gpu/drm/xe/xe_vm.o] Error 1 make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:440: drivers/gpu/drm/xe] Error 2 make[5]: *** [../scripts/Makefile.build:440: drivers/gpu/drm] Error 2 make[4]: *** [../scripts/Makefile.build:440: drivers/gpu] Error 2 make[3]: *** [../scripts/Makefile.build:440: drivers] Error 2 make[2]: *** [/kernel/Makefile:1989: .] Error 2
make[1]: *** [/kernel/Makefile:251: __sub-make] Error 2
make: *** [Makefile:251: __sub-make] Error 2
[23:12:39] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [23:12:43] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make all compile_commands.json ARCH=um O=.kunit --jobs=48 + cleanup ++ stat -c %u:%g /kernel + chown -R 1003:1003 /kernel
Matthew Brost
maintainerQuoted 4 lines · Oak Zeng
Add a function
xe_pt_zap_range. This is similar toxe_pt_zap_ptesbut is used when we don't have a vma to work with, such as zap a range mapped to scratch page where we don't have vma.
See my reply to the following patch. This won't work and isn't needed.
Let me explain why this won't work.
When we set up scratch PTEs on a VM, we create shell PTE structure to largest page size (1 GB), which we 1 GB entry pointing to a scratch page.
With 48 bits of address space, this is 1 level to 1 GB pages, with 57 bits this is 2 levels to 1 GB pages.
Now, let's say we perform a 4K bind from 0x0 to 0x1000 with immediate clear in fault mode.
How can we invalidate just the 4K range of memory? We can't. We need to allocate new memory for page tables so that 0x0000–0x1000 points to an invalidated PTE, while 0x1000–1 GB points to scratch. This is why, in my reply to the patch, I indicated that the entire bind pipeline needs to be updated to properly invalidate the PTEs.
I hope this explanation, along with my reply to the next patch, makes sense.
Matt
Quoted 59 lines
Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/xe/xe_pt.c | 28 ++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_pt.h | 2 ++ 2 files changed, 30 insertions(+)drivers/gpu/drm/xe/xe_pt.c +28
-0@@ -792,6 +792,34 @@ static const struct xe_pt_walk_ops xe_pt_zap_ptes_ops = { .pt_entry = xe_pt_zap_ptes_entry, }; +/** +* xe_pt_zap_range() - Zap (zero) gpu ptes of an virtual address range +* @tile: The tile we're zapping for. +* @vm: The vm we're zapping for. +* @start: Start of the virtual address range, inclusive. +* @end: End of the virtual address range, exclusive. +* +* This is similar to xe_pt_zap_ptes() but it's used when we don't have a +* vma to work with. This is used for example when we're clearing the scratch +* page mapping during vm_bind. +* +*/ +void xe_pt_zap_range (struct xe_tile *tile,struct xe_vm *vm,u64 start,u64 end) +{ +struct xe_pt_zap_ptes_walk xe_walk = { + .base = { + .ops = &xe_pt_zap_ptes_ops, + .shifts = xe_normal_pt_shifts, + .max_level =XE_PT_HIGHEST_LEVEL , + }, + .tile = tile, + }; +struct xe_pt *pt = vm->pt_root[tile->id]; + + (void )xe_pt_walk_shared (&pt->base, pt->level, start, + end, &xe_walk.base); +} +/** * xe_pt_zap_ptes() - Zap (zero) gpu ptes of an address range * @tile: The tile we're zapping for. drivers/gpu/drm/xe/xe_pt.h +2
-0@@ -43,4 +43,6 @@ void xe_pt_update_ops_abort(struct xe_tile *tile, struct xe_vma_ops *vops);bool xe_pt_zap_ptes (struct xe_tile *tile,struct xe_vma *vma); +void xe_pt_zap_range (struct xe_tile *tile,struct xe_vm *vm,u64 start,u64 end); +#endif Signature · 1 line
2.26.3
Thomas Hellström
maintainerQuoted 5 lines · Oak Zeng
Add a function
xe_pt_zap_range. This is similar toxe_pt_zap_ptesbut is used when we don't have a vma to work with, such as zap a range mapped to scratch page where we don't have vma.Signed-off-by Oak Zeng <[email protected]>
As I think also Matt mentions, The zap functionality works only when it exactly matches a pre-bound range (like in this case a vma) and there is something cleaning up the zapped ptes afterwards. Typically that's a rebind or an unbind.
Thanks,
Thomas
Quoted 62 lines
---
drivers/gpu/drm/xe/xe_pt.c | 28 ++++++++++++++++++++++++++++drivers/gpu/drm/xe/xe_pt.h| 2 ++2 files changed, 30 insertions(+)drivers/gpu/drm/xe/xe_pt.c +0
-0@@ -792,6 +792,34 @@ static const struct xe_pt_walk_ops xe_pt_zap_ptes_ops = { .pt_entry = xe_pt_zap_ptes_entry, };
+/**
+ *xe_pt_zap_range()- Zap (zero) gpu ptes of an virtual address range
+ * @tile: The tile we're zapping for.
+ * @vm: The vm we're zapping for.
+ * @start: Start of the virtual address range, inclusive.
+ * @end: End of the virtual address range, exclusive.
+ *
+ * This is similar toxe_pt_zap_ptes()but it's used when we don't have a
+ * vma to work with. This is used for example when we're clearing the scratch
+ * page mapping duringvm_bind.
+ *
+ */
+voidxe_pt_zap_range(struct xe_tile *tile, struct xe_vm *vm, u64 start, u64 end)drivers/gpu/drm/xe/xe_pt.c +15
-0+{ +struct xe_pt_zap_ptes_walk xe_walk = { + .base = { + .ops = &xe_pt_zap_ptes_ops, + .shifts = xe_normal_pt_shifts, + .max_level =XE_PT_HIGHEST_LEVEL , + }, + .tile = tile, + }; +struct xe_pt *pt = vm->pt_root[tile->id]; + + (void )xe_pt_walk_shared (&pt->base, pt->level, start, + end, &xe_walk.base); +} +/**
*xe_pt_zap_ptes()- Zap (zero) gpu ptes of an address range
* @tile: The tile we're zapping for.drivers/gpu/drm/xe/xe_pt.h +0
-0@@ -43,4 +43,6 @@ void xe_pt_update_ops_abort(struct xe_tile *tile, struct xe_vma_ops *vops);
boolxe_pt_zap_ptes(struct xe_tile *tile, struct xe_vma *vma);
+voidxe_pt_zap_range(struct xe_tile *tile, struct xe_vm *vm, u64 start, u64 end);
+
#endif