Skip to content

Commit 80e709e

Browse files
Chong Lialexdeucher
authored andcommitted
drm/amdgpu: add option params to enforce process isolation between graphics and compute
enforce process isolation between graphics and compute via using the same reserved vmid. v2: remove params "struct amdgpu_vm *vm" from amdgpu_vmid_alloc_reserved and amdgpu_vmid_free_reserved. Signed-off-by: Chong Li <chongli2@amd.com> Reviewed-by: Christian Koenig <Christian.Koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 4e70da9 commit 80e709e

5 files changed

Lines changed: 36 additions & 23 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ extern int amdgpu_force_asic_type;
214214
extern int amdgpu_smartshift_bias;
215215
extern int amdgpu_use_xgmi_p2p;
216216
extern int amdgpu_mtype_local;
217+
extern bool enforce_isolation;
217218
#ifdef CONFIG_HSA_AMD
218219
extern int sched_policy;
219220
extern bool debug_evictions;

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ uint amdgpu_pg_mask = 0xffffffff;
153153
uint amdgpu_sdma_phase_quantum = 32;
154154
char *amdgpu_disable_cu;
155155
char *amdgpu_virtual_display;
156-
156+
bool enforce_isolation;
157157
/*
158158
* OverDrive(bit 14) disabled by default
159159
* GFX DCS(bit 19) disabled by default
@@ -973,6 +973,14 @@ MODULE_PARM_DESC(
973973
4 = AMDGPU_CPX_PARTITION_MODE)");
974974
module_param_named(user_partt_mode, amdgpu_user_partt_mode, uint, 0444);
975975

976+
977+
/**
978+
* DOC: enforce_isolation (bool)
979+
* enforce process isolation between graphics and compute via using the same reserved vmid.
980+
*/
981+
module_param(enforce_isolation, bool, 0444);
982+
MODULE_PARM_DESC(enforce_isolation, "enforce process isolation between graphics and compute . enforce_isolation = on");
983+
976984
/* These devices are not supported by amdgpu.
977985
* They are supported by the mach64, r128, radeon drivers
978986
*/

drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
409409
if (r || !idle)
410410
goto error;
411411

412-
if (vm->reserved_vmid[vmhub]) {
412+
if (vm->reserved_vmid[vmhub] || (enforce_isolation && (vmhub == AMDGPU_GFXHUB(0)))) {
413413
r = amdgpu_vmid_grab_reserved(vm, ring, job, &id, fence);
414414
if (r || !id)
415415
goto error;
@@ -460,14 +460,11 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
460460
}
461461

462462
int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev,
463-
struct amdgpu_vm *vm,
464463
unsigned vmhub)
465464
{
466465
struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
467466

468467
mutex_lock(&id_mgr->lock);
469-
if (vm->reserved_vmid[vmhub])
470-
goto unlock;
471468

472469
++id_mgr->reserved_use_count;
473470
if (!id_mgr->reserved) {
@@ -479,27 +476,23 @@ int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev,
479476
list_del_init(&id->list);
480477
id_mgr->reserved = id;
481478
}
482-
vm->reserved_vmid[vmhub] = true;
483479

484-
unlock:
485480
mutex_unlock(&id_mgr->lock);
486481
return 0;
487482
}
488483

489484
void amdgpu_vmid_free_reserved(struct amdgpu_device *adev,
490-
struct amdgpu_vm *vm,
491485
unsigned vmhub)
492486
{
493487
struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
494488

495489
mutex_lock(&id_mgr->lock);
496-
if (vm->reserved_vmid[vmhub] &&
497-
!--id_mgr->reserved_use_count) {
490+
if (!--id_mgr->reserved_use_count) {
498491
/* give the reserved ID back to normal round robin */
499492
list_add(&id_mgr->reserved->list, &id_mgr->ids_lru);
500493
id_mgr->reserved = NULL;
501494
}
502-
vm->reserved_vmid[vmhub] = false;
495+
503496
mutex_unlock(&id_mgr->lock);
504497
}
505498

@@ -578,6 +571,10 @@ void amdgpu_vmid_mgr_init(struct amdgpu_device *adev)
578571
list_add_tail(&id_mgr->ids[j].list, &id_mgr->ids_lru);
579572
}
580573
}
574+
/* alloc a default reserved vmid to enforce isolation */
575+
if (enforce_isolation)
576+
amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(0));
577+
581578
}
582579

583580
/**

drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,
7979
bool amdgpu_vmid_had_gpu_reset(struct amdgpu_device *adev,
8080
struct amdgpu_vmid *id);
8181
int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev,
82-
struct amdgpu_vm *vm,
83-
unsigned vmhub);
82+
unsigned vmhub);
8483
void amdgpu_vmid_free_reserved(struct amdgpu_device *adev,
85-
struct amdgpu_vm *vm,
86-
unsigned vmhub);
84+
unsigned vmhub);
8785
int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
8886
struct amdgpu_job *job, struct dma_fence **fence);
8987
void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,8 +2284,14 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
22842284
}
22852285

22862286
dma_fence_put(vm->last_update);
2287-
for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
2288-
amdgpu_vmid_free_reserved(adev, vm, i);
2287+
2288+
for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
2289+
if (vm->reserved_vmid[i]) {
2290+
amdgpu_vmid_free_reserved(adev, i);
2291+
vm->reserved_vmid[i] = false;
2292+
}
2293+
}
2294+
22892295
}
22902296

22912297
/**
@@ -2368,7 +2374,6 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
23682374
union drm_amdgpu_vm *args = data;
23692375
struct amdgpu_device *adev = drm_to_adev(dev);
23702376
struct amdgpu_fpriv *fpriv = filp->driver_priv;
2371-
int r;
23722377

23732378
/* No valid flags defined yet */
23742379
if (args->in.flags)
@@ -2377,13 +2382,17 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
23772382
switch (args->in.op) {
23782383
case AMDGPU_VM_OP_RESERVE_VMID:
23792384
/* We only have requirement to reserve vmid from gfxhub */
2380-
r = amdgpu_vmid_alloc_reserved(adev, &fpriv->vm,
2381-
AMDGPU_GFXHUB(0));
2382-
if (r)
2383-
return r;
2385+
if (!fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)]) {
2386+
amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(0));
2387+
fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)] = true;
2388+
}
2389+
23842390
break;
23852391
case AMDGPU_VM_OP_UNRESERVE_VMID:
2386-
amdgpu_vmid_free_reserved(adev, &fpriv->vm, AMDGPU_GFXHUB(0));
2392+
if (fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)]) {
2393+
amdgpu_vmid_free_reserved(adev, AMDGPU_GFXHUB(0));
2394+
fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)] = false;
2395+
}
23872396
break;
23882397
default:
23892398
return -EINVAL;

0 commit comments

Comments
 (0)