Skip to content

Commit 0f18ac7

Browse files
mbrost05lucasdemarchi
authored andcommitted
drm/xe: Use helper for ASID -> VM in GPU faults and access counters
Normalize both code paths with a helper. Fixes a possible leak access counter path too. Suggested-by: Matthew Auld <[email protected]> Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Matthew Auld <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit dc0dce6) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent d1ef967 commit 0f18ac7

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

drivers/gpu/drm/xe/xe_gt_pagefault.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,21 @@ static int handle_vma_pagefault(struct xe_tile *tile, struct pagefault *pf,
185185
return err;
186186
}
187187

188+
static struct xe_vm *asid_to_vm(struct xe_device *xe, u32 asid)
189+
{
190+
struct xe_vm *vm;
191+
192+
down_read(&xe->usm.lock);
193+
vm = xa_load(&xe->usm.asid_to_vm, asid);
194+
if (vm && xe_vm_in_fault_mode(vm))
195+
xe_vm_get(vm);
196+
else
197+
vm = ERR_PTR(-EINVAL);
198+
up_read(&xe->usm.lock);
199+
200+
return vm;
201+
}
202+
188203
static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
189204
{
190205
struct xe_device *xe = gt_to_xe(gt);
@@ -197,16 +212,9 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
197212
if (pf->trva_fault)
198213
return -EFAULT;
199214

200-
/* ASID to VM */
201-
down_read(&xe->usm.lock);
202-
vm = xa_load(&xe->usm.asid_to_vm, pf->asid);
203-
if (vm && xe_vm_in_fault_mode(vm))
204-
xe_vm_get(vm);
205-
else
206-
vm = NULL;
207-
up_read(&xe->usm.lock);
208-
if (!vm)
209-
return -EINVAL;
215+
vm = asid_to_vm(xe, pf->asid);
216+
if (IS_ERR(vm))
217+
return PTR_ERR(vm);
210218

211219
/*
212220
* TODO: Change to read lock? Using write lock for simplicity.
@@ -548,14 +556,9 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
548556
if (acc->access_type != ACC_TRIGGER)
549557
return -EINVAL;
550558

551-
/* ASID to VM */
552-
down_read(&xe->usm.lock);
553-
vm = xa_load(&xe->usm.asid_to_vm, acc->asid);
554-
if (vm)
555-
xe_vm_get(vm);
556-
up_read(&xe->usm.lock);
557-
if (!vm || !xe_vm_in_fault_mode(vm))
558-
return -EINVAL;
559+
vm = asid_to_vm(xe, acc->asid);
560+
if (IS_ERR(vm))
561+
return PTR_ERR(vm);
559562

560563
down_read(&vm->lock);
561564

0 commit comments

Comments
 (0)