Skip to content

Commit 074e40d

Browse files
committed
drm/xe: Nuke VM's mapping upon close
Clear root PT entry and invalidate entire VM's address space when closing the VM. Will prevent the GPU from accessing any of the VM's memory after closing. v2: - s/vma/vm in kernel doc (CI) - Don't nuke migration VM as this occur at driver unload (CI) v3: - Rebase and pull into SVM series (Thomas) - Wait for pending binds (Thomas) v5: - Remove xe_gt_tlb_invalidation_fence_fini in error case (Matt Auld) - Drop local migration bool (Thomas) v7: - Add drm_dev_enter/exit protecting invalidation (CI, Matt Auld) Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 85d4653 commit 074e40d

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,28 @@ int xe_gt_tlb_invalidation_range(struct xe_gt *gt,
410410
return send_tlb_invalidation(&gt->uc.guc, fence, action, len);
411411
}
412412

413+
/**
414+
* xe_gt_tlb_invalidation_vm - Issue a TLB invalidation on this GT for a VM
415+
* @gt: graphics tile
416+
* @vm: VM to invalidate
417+
*
418+
* Invalidate entire VM's address space
419+
*/
420+
void xe_gt_tlb_invalidation_vm(struct xe_gt *gt, struct xe_vm *vm)
421+
{
422+
struct xe_gt_tlb_invalidation_fence fence;
423+
u64 range = 1ull << vm->xe->info.va_bits;
424+
int ret;
425+
426+
xe_gt_tlb_invalidation_fence_init(gt, &fence, true);
427+
428+
ret = xe_gt_tlb_invalidation_range(gt, &fence, 0, range, vm->usm.asid);
429+
if (ret < 0)
430+
return;
431+
432+
xe_gt_tlb_invalidation_fence_wait(&fence);
433+
}
434+
413435
/**
414436
* xe_gt_tlb_invalidation_vma - Issue a TLB invalidation on this GT for a VMA
415437
* @gt: GT structure

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
struct xe_gt;
1414
struct xe_guc;
15+
struct xe_vm;
1516
struct xe_vma;
1617

1718
int xe_gt_tlb_invalidation_init_early(struct xe_gt *gt);
@@ -21,6 +22,7 @@ int xe_gt_tlb_invalidation_ggtt(struct xe_gt *gt);
2122
int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,
2223
struct xe_gt_tlb_invalidation_fence *fence,
2324
struct xe_vma *vma);
25+
void xe_gt_tlb_invalidation_vm(struct xe_gt *gt, struct xe_vm *vm);
2426
int xe_gt_tlb_invalidation_range(struct xe_gt *gt,
2527
struct xe_gt_tlb_invalidation_fence *fence,
2628
u64 start, u64 end, u32 asid);

drivers/gpu/drm/xe/xe_pt.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ void xe_pt_destroy(struct xe_pt *pt, u32 flags, struct llist_head *deferred)
218218
xe_pt_free(pt);
219219
}
220220

221+
/**
222+
* xe_pt_clear() - Clear a page-table.
223+
* @xe: xe device.
224+
* @pt: The page-table.
225+
*
226+
* Clears page-table by setting to zero.
227+
*/
228+
void xe_pt_clear(struct xe_device *xe, struct xe_pt *pt)
229+
{
230+
struct iosys_map *map = &pt->bo->vmap;
231+
232+
xe_map_memset(xe, map, 0, 0, SZ_4K);
233+
}
234+
221235
/**
222236
* DOC: Pagetable building
223237
*

drivers/gpu/drm/xe/xe_pt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct dma_fence;
1313
struct xe_bo;
1414
struct xe_device;
1515
struct xe_exec_queue;
16+
struct xe_svm_range;
1617
struct xe_sync_entry;
1718
struct xe_tile;
1819
struct xe_vm;
@@ -35,6 +36,8 @@ void xe_pt_populate_empty(struct xe_tile *tile, struct xe_vm *vm,
3536

3637
void xe_pt_destroy(struct xe_pt *pt, u32 flags, struct llist_head *deferred);
3738

39+
void xe_pt_clear(struct xe_device *xe, struct xe_pt *pt);
40+
3841
int xe_pt_update_ops_prepare(struct xe_tile *tile, struct xe_vma_ops *vops);
3942
struct dma_fence *xe_pt_update_ops_run(struct xe_tile *tile,
4043
struct xe_vma_ops *vops);

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/dma-fence-array.h>
99
#include <linux/nospec.h>
1010

11+
#include <drm/drm_drv.h>
1112
#include <drm/drm_exec.h>
1213
#include <drm/drm_print.h>
1314
#include <drm/ttm/ttm_tt.h>
@@ -1615,9 +1616,40 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
16151616

16161617
static void xe_vm_close(struct xe_vm *vm)
16171618
{
1619+
struct xe_device *xe = vm->xe;
1620+
bool bound;
1621+
int idx;
1622+
1623+
bound = drm_dev_enter(&xe->drm, &idx);
1624+
16181625
down_write(&vm->lock);
1626+
16191627
vm->size = 0;
1628+
1629+
if (!((vm->flags & XE_VM_FLAG_MIGRATION))) {
1630+
struct xe_tile *tile;
1631+
struct xe_gt *gt;
1632+
u8 id;
1633+
1634+
/* Wait for pending binds */
1635+
dma_resv_wait_timeout(xe_vm_resv(vm),
1636+
DMA_RESV_USAGE_BOOKKEEP,
1637+
false, MAX_SCHEDULE_TIMEOUT);
1638+
1639+
if (bound) {
1640+
for_each_tile(tile, xe, id)
1641+
if (vm->pt_root[id])
1642+
xe_pt_clear(xe, vm->pt_root[id]);
1643+
1644+
for_each_gt(gt, xe, id)
1645+
xe_gt_tlb_invalidation_vm(gt, vm);
1646+
}
1647+
}
1648+
16201649
up_write(&vm->lock);
1650+
1651+
if (bound)
1652+
drm_dev_exit(idx);
16211653
}
16221654

16231655
void xe_vm_close_and_put(struct xe_vm *vm)

0 commit comments

Comments
 (0)