drm/amdgpu: use the same naming scheme for kq and uq VMID masks
Subsystems (2)
PATCH v3 1/13 drm/amdgpu: use the same naming scheme for kq and uq VMID masks
Fix the ambiguous names in amdgpu_vmid_mgr_set_vmid_mask()'s parameters so there is no confusion.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 16 ++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +8 -8
@@ -635,13 +635,13 @@ void amdgpu_vmid_reset_all(struct amdgpu_device *adev)* pools for both hubs * * @adev: amdgpu device structure -* @gfx_vmid_mask: kernel-queue VMID pool mask for GFXHUB -* @mmhub_vmid_mask: kernel-queue VMID pool mask for MMHUB +* @vmid_kq_mask_gfxhub: kernel-queue VMID pool mask for GFXHUB +* @vmid_kq_mask_mmhub: kernel-queue VMID pool mask for MMHUB * * Sets both hubs' kernel-queue VMID pools (tracked least-recently-used * via id_mgr[].ids_lru), and both hubs' KFD/MES user-queue masks. * vmid_uq_mask_gfxhub is set to the -* complement of @gfx_vmid_mask, since unlike MMHUB's it is always a +* complement of @vmid_kq_mask_gfxhub, since unlike MMHUB's it is always a * clean partition of the full VMID range; vmid_uq_mask_mmhub is the * fixed pool set here instead, since MMHUB's kq and uq pools are * allowed to overlap. A VMID dedicated to a single fixed purpose on
@@ -649,26 +649,26 @@ void amdgpu_vmid_reset_all(struct amdgpu_device *adev)* caller's responsibility to have already set npa_vmid. */ void amdgpu_vmid_mgr_set_vmid_mask (struct amdgpu_device *adev, -unsigned long gfx_vmid_mask, -unsigned long mmhub_vmid_mask) +unsigned long vmid_kq_mask_gfxhub, +unsigned long vmid_kq_mask_mmhub) {unsigned int i;BUILD_BUG_ON (AMDGPU_NUM_VMID >BITS_PER_LONG );if (adev->vm_manager.npa_vmid) - mmhub_vmid_mask &= ~BIT (adev->vm_manager.npa_vmid); + vmid_kq_mask_mmhub &= ~BIT (adev->vm_manager.npa_vmid);for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) {bool is_mmhub =AMDGPU_IS_MMHUB0 (i) ||AMDGPU_IS_MMHUB1 (i);bitmap_copy (adev->vm_manager.id_mgr[i].vmid_mask, - is_mmhub ? &mmhub_vmid_mask : &gfx_vmid_mask, + is_mmhub ? &vmid_kq_mask_mmhub : &vmid_kq_mask_gfxhub,AMDGPU_NUM_VMID ); } adev->vm_manager.vmid_uq_mask_gfxhub = -GENMASK (AMDGPU_NUM_VMID -1 ,1 ) & ~gfx_vmid_mask; +GENMASK (AMDGPU_NUM_VMID -1 ,1 ) & ~vmid_kq_mask_gfxhub; adev->vm_manager.vmid_uq_mask_mmhub =0xFF00 ;if (adev->vm_manager.npa_vmid)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +2 -2
@@ -135,7 +135,7 @@ void amdgpu_vmid_reset_all(struct amdgpu_device *adev);void amdgpu_vmid_mgr_init (struct amdgpu_device *adev);void amdgpu_vmid_mgr_fini (struct amdgpu_device *adev);void amdgpu_vmid_mgr_set_vmid_mask (struct amdgpu_device *adev, -unsigned long gfx_vmid_mask, -unsigned long mmhub_vmid_mask); +unsigned long vmid_kq_mask_gfxhub, +unsigned long vmid_kq_mask_mmhub);#endif
Signature · 1 line
2.34.1
PATCH v3 2/13 drm/amdgpu: add spm_vmid and exclude it from the MES, KFD and kq pools
The SPM (Streaming Performance Monitor) path needs a VMID that is isolated from other GPU contexts. Introduce vm_manager.spm_vmid to let a GFXHUB dedicate a VMID to SPM.
When spm_vmid is set, exclude it from both the kernel-queue pool and vmid_uq_mask_gfxhub, so neither the round-robin kernel-queue allocator nor MES/Userqueues ever maps another context onto it.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 46 ++++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 ++ 2 files changed, 31 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +29 -17
@@ -638,26 +638,45 @@ void amdgpu_vmid_reset_all(struct amdgpu_device *adev)* @vmid_kq_mask_gfxhub: kernel-queue VMID pool mask for GFXHUB * @vmid_kq_mask_mmhub: kernel-queue VMID pool mask for MMHUB * -* Sets both hubs' kernel-queue VMID pools (tracked least-recently-used -* via id_mgr[].ids_lru), and both hubs' KFD/MES user-queue masks. -* vmid_uq_mask_gfxhub is set to the -* complement of @vmid_kq_mask_gfxhub, since unlike MMHUB's it is always a -* clean partition of the full VMID range; vmid_uq_mask_mmhub is the -* fixed pool set here instead, since MMHUB's kq and uq pools are -* allowed to overlap. A VMID dedicated to a single fixed purpose on -* MMHUB (npa_vmid) is excluded from both MMHUB pools; it is the -* caller's responsibility to have already set npa_vmid. +* Sets both GFXHUB and MMHUB kernel-queue VMID pools +* via id_mgr[].ids_lru, and KFD/MES user-queue masks too. */ void amdgpu_vmid_mgr_set_vmid_mask (struct amdgpu_device *adev,unsigned long vmid_kq_mask_gfxhub,unsigned long vmid_kq_mask_mmhub) { +unsigned long uq_mask_gfxhub, uq_mask_mmhub;unsigned int i;BUILD_BUG_ON (AMDGPU_NUM_VMID >BITS_PER_LONG ); -if (adev->vm_manager.npa_vmid) +/* +* Derive the uq masks from the kq masks as given, then carve each +* hub's dedicated out-of-pool VMID out of both of that hub's pools. +*/ + uq_mask_gfxhub =GENMASK (AMDGPU_NUM_VMID -1 ,1 ) & ~vmid_kq_mask_gfxhub; + uq_mask_mmhub =0xFF00 ; + +/* +* SPM uses a dedicated vmid that is reserved from gfxhub. +* Unmask the reserved vmids from both user and kernel queues +*/ +if (adev->vm_manager.spm_vmid) { + vmid_kq_mask_gfxhub &= ~BIT (adev->vm_manager.spm_vmid); + uq_mask_gfxhub &= ~BIT (adev->vm_manager.spm_vmid); + } + +/* +* NPA uses a dedicated vmid that is reserved from mmhub. +* Unmask the reserved VMIDs from both user and kernel queues +*/ +if (adev->vm_manager.npa_vmid) { vmid_kq_mask_mmhub &= ~BIT (adev->vm_manager.npa_vmid); + uq_mask_mmhub &= ~BIT (adev->vm_manager.npa_vmid); + } + + adev->vm_manager.vmid_uq_mask_gfxhub = uq_mask_gfxhub; + adev->vm_manager.vmid_uq_mask_mmhub = uq_mask_mmhub;for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) {bool is_mmhub =AMDGPU_IS_MMHUB0 (i) ||AMDGPU_IS_MMHUB1 (i);
@@ -666,13 +685,6 @@ void amdgpu_vmid_mgr_set_vmid_mask(struct amdgpu_device *adev, is_mmhub ? &vmid_kq_mask_mmhub : &vmid_kq_mask_gfxhub, AMDGPU_NUM_VMID); } - - adev->vm_manager.vmid_uq_mask_gfxhub = -GENMASK (AMDGPU_NUM_VMID -1 ,1 ) & ~vmid_kq_mask_gfxhub; - - adev->vm_manager.vmid_uq_mask_mmhub =0xFF00 ; -if (adev->vm_manager.npa_vmid) - adev->vm_manager.vmid_uq_mask_mmhub &= ~BIT (adev->vm_manager.npa_vmid); }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -0
@@ -411,7 +411,9 @@ struct amdgpu_vm_manager {/* Global registration of recent page fault information */ struct amdgpu_vm_fault_info fault_info; +/* VMIDs dedicated to a single fixed purpose, 0 if unused */ unsigned int npa_vmid; +unsigned int spm_vmid;/* VMID masks for GFXHUB and MMHUB */ uint32_t vmid_uq_mask_gfxhub;
Signature · 1 line
2.34.1
PATCH v3 3/13 drm/amdgpu: use dedicated SPM VMID from the reserved path
In reply to Sunil KhatriUse the spm vmid which is dedicated for the SPM only and update the function paths accordingly.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 30 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +25 -5
@@ -551,9 +551,12 @@ int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm, r = -ENOENT ; goto unlock; } -/* Remove from normal round robin handling */ - id = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vmid, list); -list_del_init (&id->list); +if (!adev->vm_manager.spm_vmid) { + r = -ENOENT ; + goto unlock; + } + + id = &id_mgr->ids[adev->vm_manager.spm_vmid]; vm->reserved_vmid[vmhub] = id; id_mgr->reserved_vmid = true;mutex_unlock (&id_mgr->lock);
@@ -577,8 +580,6 @@ void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,mutex_lock (&id_mgr->lock);if (vm->reserved_vmid[vmhub]) { -list_add (&vm->reserved_vmid[vmhub]->list, - &id_mgr->ids_lru); vm->reserved_vmid[vmhub] =NULL ; id_mgr->reserved_vmid = false; }
@@ -628,6 +629,14 @@ void amdgpu_vmid_reset_all(struct amdgpu_device *adev)for_each_set_bit (j, id_mgr->vmid_mask,AMDGPU_NUM_VMID )amdgpu_vmid_reset (adev, i, j); } + +/* +* The SPM VMID is not part of the normal kernel pool, reset it +* anyway in case it is used with kernel queues. +*/ +if (adev->vm_manager.spm_vmid) +for (i =AMDGPU_GFXHUB_START ; i <AMDGPU_MMHUB0_START ; ++i) +amdgpu_vmid_reset (adev, i, adev->vm_manager.spm_vmid); }/**
@@ -712,6 +721,17 @@ void amdgpu_vmid_mgr_init(struct amdgpu_device *adev)list_add_tail (&id_mgr->ids[j].list, &id_mgr->ids_lru); } } + +/* +* The SPM VMID is not part of the normal kernel pool, create its +* sync anyway in case it is used with kernel queues. +*/ +if (adev->vm_manager.spm_vmid) { +unsigned int spm_vmid = adev->vm_manager.spm_vmid; + +for (i =AMDGPU_GFXHUB_START ; i <AMDGPU_MMHUB0_START ; ++i) +amdgpu_sync_create (&adev->vm_manager.id_mgr[i].ids[spm_vmid].active); + } }/**
Signature · 1 line
2.34.1
Re: [PATCH v3 03/13] drm/amdgpu: use dedicated SPM VMID from the reserved path
Quoted 4 lines · Sunil Khatri
Use the spm vmid which is dedicated for the SPM only and update the function paths accordingly.
Signed-off-by Sunil Khatri <[email protected]>
Quoted 66 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 30 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +25
-5@@ -551,9 +551,12 @@ int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm, r = -ENOENT ; goto unlock; } -/* Remove from normal round robin handling */ - id = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vmid, list); -list_del_init (&id->list); +if (!adev->vm_manager.spm_vmid) { + r = -ENOENT ; + goto unlock; + } + + id = &id_mgr->ids[adev->vm_manager.spm_vmid]; vm->reserved_vmid[vmhub] = id; id_mgr->reserved_vmid = true;mutex_unlock (&id_mgr->lock);@@ -577,8 +580,6 @@ void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,mutex_lock (&id_mgr->lock);if (vm->reserved_vmid[vmhub]) { -list_add (&vm->reserved_vmid[vmhub]->list, - &id_mgr->ids_lru); vm->reserved_vmid[vmhub] =NULL ; id_mgr->reserved_vmid = false; }@@ -628,6 +629,14 @@ void amdgpu_vmid_reset_all(struct amdgpu_device *adev)for_each_set_bit (j, id_mgr->vmid_mask,AMDGPU_NUM_VMID )amdgpu_vmid_reset (adev, i, j); } + +/* +* The SPM VMID is not part of the normal kernel pool, reset it +* anyway in case it is used with kernel queues. +*/ +if (adev->vm_manager.spm_vmid) +for (i =AMDGPU_GFXHUB_START ; i <AMDGPU_MMHUB0_START ; ++i) +amdgpu_vmid_reset (adev, i, adev->vm_manager.spm_vmid); }/** @@ -712,6 +721,17 @@ void amdgpu_vmid_mgr_init(struct amdgpu_device *adev)list_add_tail (&id_mgr->ids[j].list, &id_mgr->ids_lru); } } + +/* +* The SPM VMID is not part of the normal kernel pool, create its +* sync anyway in case it is used with kernel queues. +*/ +if (adev->vm_manager.spm_vmid) { +unsigned int spm_vmid = adev->vm_manager.spm_vmid; + +for (i =AMDGPU_GFXHUB_START ; i <AMDGPU_MMHUB0_START ; ++i) +amdgpu_sync_create (&adev->vm_manager.id_mgr[i].ids[spm_vmid].active); + } }/**
PATCH v3 4/13 drm/amdgpu: reserve SPM VMID on gfx7
In reply to Sunil KhatriSet vm_manager.spm_vmid to the top GFXHUB VMID so the SPM reservation path hands out a fixed, isolated VMID on gfx7 instead of borrowing one from the graphics pool.
--- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +4 -0
@@ -1008,6 +1008,10 @@ static int gmc_v7_0_sw_init(struct amdgpu_ip_block *ip_block)* amdkfd/MES user queues will use VMIDs 8-15 */ vmid_mask =GENMASK (7 ,1 ); + +/* Reserve the last VMID for SPM */ + adev->vm_manager.spm_vmid =AMDGPU_NUM_VMID -1 ; +amdgpu_vmid_mgr_set_vmid_mask (adev, vmid_mask, vmid_mask);amdgpu_vm_manager_init (adev);
Signature · 1 line
2.34.1
PATCH v3 5/13 drm/amdgpu: reserve SPM VMID on gfx8
In reply to Sunil KhatriSet vm_manager.spm_vmid to the top GFXHUB VMID so the SPM reservation path hands out a fixed, isolated VMID on gfx8 instead of borrowing one from the graphics pool.
--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +4 -0
@@ -1123,6 +1123,10 @@ static int gmc_v8_0_sw_init(struct amdgpu_ip_block *ip_block)* amdkfd/MES user queues will use VMIDs 8-15 */ vmid_mask =GENMASK (7 ,1 ); + +/* Reserve the last VMID for SPM */ + adev->vm_manager.spm_vmid =AMDGPU_NUM_VMID -1 ; +amdgpu_vmid_mgr_set_vmid_mask (adev, vmid_mask, vmid_mask);amdgpu_vm_manager_init (adev);
Signature · 1 line
2.34.1
PATCH v3 6/13 drm/amdgpu: reserve SPM VMID on gfx9
In reply to Sunil KhatriSet vm_manager.spm_vmid to the top GFXHUB VMID so the SPM reservation path hands out a fixed, isolated VMID on gfx9 instead of borrowing one from the graphics pool.
--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
@@ -2042,6 +2042,10 @@ static int gmc_v9_0_sw_init(struct amdgpu_ip_block *ip_block)7 ; vmid_mask =GENMASK (last_kq_vmid,1 ); + +/* Reserve the last VMID for SPM */ + adev->vm_manager.spm_vmid =AMDGPU_NUM_VMID -1 ; +amdgpu_vmid_mgr_set_vmid_mask (adev, vmid_mask, vmid_mask);amdgpu_vm_manager_init (adev);
Signature · 1 line
2.34.1
PATCH v3 7/13 drm/amdgpu: reserve SPM VMID on gfx10
In reply to Sunil KhatriSet vm_manager.spm_vmid to the top GFXHUB VMID so the SPM reservation path hands out a fixed, isolated VMID on gfx10 instead of borrowing one from the graphics pool.
--- drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +4 -0
@@ -869,6 +869,10 @@ static int gmc_v10_0_sw_init(struct amdgpu_ip_block *ip_block)* amdgpu graphics/compute kernel queues will use VMIDs 1-7 * amdkfd/MES user queues will use VMIDs 8-15 */ + +/* Reserve the last VMID for SPM */ + adev->vm_manager.spm_vmid =AMDGPU_NUM_VMID -1 ; +amdgpu_vmid_mgr_set_vmid_mask (adev,GENMASK (7 ,1 ),GENMASK (AMDGPU_NUM_VMID -1 ,1 ));
Signature · 1 line
2.34.1
PATCH v3 8/13 drm/amdgpu: reserve SPM VMID on gfx11
In reply to Sunil KhatriSet vm_manager.spm_vmid to the top GFXHUB VMID so the SPM reservation path hands out a fixed, isolated VMID on gfx11 instead of borrowing one from the graphics pool.
--- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +4 -0
@@ -856,6 +856,10 @@ static int gmc_v11_0_sw_init(struct amdgpu_ip_block *ip_block)* amdkfd/MES user queues will use VMIDs 8-15 */ last_kq_vmid = adev->gfx.disable_kq ?0 :7 ; + +/* Reserve the last VMID for SPM */ + adev->vm_manager.spm_vmid =AMDGPU_NUM_VMID -1 ; +amdgpu_vmid_mgr_set_vmid_mask (adev,GENMASK (last_kq_vmid,1 ),GENMASK (AMDGPU_NUM_VMID -1 ,1 ));
Signature · 1 line
2.34.1
PATCH v3 9/13 drm/amdgpu: reserve SPM VMID on gfx12
In reply to Sunil KhatriSet vm_manager.spm_vmid to the top GFXHUB VMID so the SPM reservation path hands out a fixed, isolated VMID on gfx12 instead of borrowing one from the graphics pool. This also covers gfx12.1, whose VMID setup is handled in this file.
--- drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +3 -0
@@ -1006,6 +1006,9 @@ static int gmc_v12_0_sw_init(struct amdgpu_ip_block *ip_block)if (adev->gfx.disable_kq) last_kq_vmid =0 ; +/* Reserve the last VMID for SPM */ + adev->vm_manager.spm_vmid =AMDGPU_NUM_VMID -1 ; +amdgpu_vmid_mgr_set_vmid_mask (adev,GENMASK (last_kq_vmid,1 ),GENMASK (AMDGPU_NUM_VMID -1 ,1 ));
Signature · 1 line
2.34.1
PATCH v3 10/13 drm/amdgpu: use spm_vmid for the default RLC SPM VMID
In reply to Sunil KhatriThe RLC bring-up paths programmed the RLC_SPM_VMID field to a hardcoded 0xf as the idle default. Now that the dedicated SPM VMID is tracked in vm_manager.spm_vmid, use it directly so the idle default matches the VMID the reservation path hands out.
No functional change: spm_vmid is the top VMID (0xf) on all affected generations (gfx7 through gfx12).
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +2 -2
@@ -5575,7 +5575,7 @@ static int gfx_v10_0_rlc_resume(struct amdgpu_device *adev)gfx_v10_0_init_csb (adev); -gfx_v10_0_update_spm_vmid_internal (adev,0xf ); +gfx_v10_0_update_spm_vmid_internal (adev, adev->vm_manager.spm_vmid);if (!amdgpu_sriov_vf (adev))/* enable RLC SRM */ gfx_v10_0_rlc_enable_srm (adev);
@@ -5607,7 +5607,7 @@ static int gfx_v10_0_rlc_resume(struct amdgpu_device *adev)gfx_v10_0_init_csb (adev); -gfx_v10_0_update_spm_vmid_internal (adev,0xf ); +gfx_v10_0_update_spm_vmid_internal (adev, adev->vm_manager.spm_vmid); adev->gfx.rlc.funcs->start (adev);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -1
@@ -944,7 +944,7 @@ static int gfx_v11_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL ,0xf ); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid);return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -1
@@ -773,7 +773,7 @@ static int gfx_v12_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL ,0xf ); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid);return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +1 -1
@@ -1861,7 +1861,7 @@ static int gfx_v12_1_xcc_rlc_resume(struct amdgpu_device *adev,int r;/* init spm vmid with 0xf */ -gfx_v12_1_update_spm_vmid (adev, xcc_id,NULL ,0xf ); +gfx_v12_1_update_spm_vmid (adev, xcc_id,NULL , adev->vm_manager.spm_vmid);if (adev->firmware.load_type ==AMDGPU_FW_LOAD_PSP ) {gfx_v12_1_xcc_init_csb (adev, xcc_id);
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +1 -1
@@ -3252,7 +3252,7 @@ static int gfx_v7_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL ,0xf ); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid);return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +1 -1
@@ -1274,7 +1274,7 @@ static int gfx_v8_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL ,0xf ); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid);return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
@@ -3233,7 +3233,7 @@ static int gfx_v9_0_rlc_resume(struct amdgpu_device *adev)break ; } -gfx_v9_0_update_spm_vmid_internal (adev,0xf ); +gfx_v9_0_update_spm_vmid_internal (adev, adev->vm_manager.spm_vmid); adev->gfx.rlc.funcs->start (adev);
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +1 -1
@@ -1395,7 +1395,7 @@ static int gfx_v9_4_3_rlc_init(struct amdgpu_device *adev) {/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL ,0xf ); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid);return 0 ; }
Signature · 1 line
2.34.1
PATCH v3 11/13 drm/amdgpu: remove the now-redundant runtime SPM VMID update
In reply to Sunil KhatriThe SPM reserved VMID is fixed now, so retargeting RLC_SPM_VMID to job->vmid on every submission is dead code. Remove job->spm_update_needed and the update_spm_vmid() calls in amdgpu_vm_flush() and amdgpu_ib_schedule().
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 7 +------ drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 +-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 +-- 5 files changed, 3 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +1 -6
@@ -126,7 +126,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, struct amdgpu_job *job,struct amdgpu_fence *af;struct amdgpu_fence *vm_af;bool need_ctx_switch; -bool emit_spm_needed = false;bool emit_gds_needed = false;uint64_t fence_ctx;uint32_t status =0 , alloc_size;
@@ -195,8 +194,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, struct amdgpu_job *job,/* VM sequence */ vm_af->ib_wptr = ring->wptr; -amdgpu_vm_flush (ring, job, &need_pipe_sync, &emit_spm_needed, - &emit_gds_needed); +amdgpu_vm_flush (ring, job, &need_pipe_sync, &emit_gds_needed); vm_af->ib_dw_size =amdgpu_ring_get_dw_distance (ring, vm_af->ib_wptr, ring->wptr);
@@ -211,9 +209,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, struct amdgpu_job *job,if (need_pipe_sync)amdgpu_ring_emit_pipeline_sync (ring); -if (emit_spm_needed) - adev->gfx.rlc.funcs->update_spm_vmid (adev, ring->xcc_id, ring, job->vmid); -if (emit_gds_needed) amdgpu_ring_emit_gds_switch(ring, job->vmid, job->gds_base, job->gds_size, job->gws_base,
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0 -1
@@ -372,7 +372,6 @@ static int amdgpu_vmid_grab_reserved(struct amdgpu_vm *vm,return r; job->vm_needs_flush = needs_flush; - job->spm_update_needed = true;return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +0 -1
@@ -75,7 +75,6 @@ struct amdgpu_job {uint32_t preemption_status;bool vm_needs_flush;bool gds_switch_needed; -bool spm_update_needed;uint64_t vm_pd_addr;unsigned vmid;unsigned pasid;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -14
@@ -766,14 +766,12 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,* @ring: ring to use for flush * @job: related job * @need_pipe_sync: is pipe sync needed -* @emit_spm_needed: does the caller need to emit spm * @emit_gds_needed: does the caller need to emit gds * * Emit a VM flush when it is necessary. */ void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool *need_pipe_sync,bool *emit_spm_needed, -bool *emit_gds_needed) +bool *need_pipe_sync,bool *emit_gds_needed) {struct amdgpu_device *adev = ring->adev; struct amdgpu_isolation *isolation =
@@ -782,8 +780,6 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,unsigned vmhub = ring->vm_hub;struct amdgpu_kq_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];struct amdgpu_vmid *id = &id_mgr->ids[job->vmid]; -bool spm_update_needed = adev->gfx.rlc.funcs->update_spm_vmid && - job->spm_update_needed;bool gds_switch_needed = ring->funcs->emit_gds_switch && job->gds_switch_needed;bool vm_flush_needed = job->vm_needs_flush;
@@ -797,7 +793,6 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, gds_switch_needed = true; vm_flush_needed = true; pasid_mapping_needed = true; - spm_update_needed = true; }mutex_lock (&id_mgr->lock);
@@ -807,7 +802,6 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,mutex_unlock (&id_mgr->lock); gds_switch_needed &= !!ring->funcs->emit_gds_switch; - spm_update_needed &= !!adev->gfx.rlc.funcs->update_spm_vmid; vm_flush_needed &= !!ring->funcs->emit_vm_flush && job->vm_pd_addr !=AMDGPU_BO_INVALID_OFFSET ; pasid_mapping_needed &= adev->gmc.gmc_funcs->emit_pasid_mapping &&
@@ -821,10 +815,6 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, emit_fence = vm_flush_needed || pasid_mapping_needed || cleaner_shader_needed; - *emit_spm_needed = spm_update_needed; -if (spm_update_needed && emit_fence) - *emit_spm_needed = false; - *emit_gds_needed = gds_switch_needed;if (gds_switch_needed && emit_fence) *emit_gds_needed = false;
@@ -864,9 +854,6 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (pasid_mapping_needed)amdgpu_gmc_emit_pasid_mapping (ring, job->vmid, job->pasid); -if (spm_update_needed) - adev->gfx.rlc.funcs->update_spm_vmid (adev, ring->xcc_id, ring, job->vmid); -if (gds_switch_needed) amdgpu_ring_emit_gds_switch(ring, job->vmid, job->gds_base, job->gds_size, job->gws_base,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -2
@@ -448,8 +448,7 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,int (*callback)(void *p,struct amdgpu_bo *bo), void *param);void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool *need_pipe_sync,bool *emit_spm_needed, -bool *emit_gds_needed); +bool *need_pipe_sync,bool *emit_gds_needed);int amdgpu_vm_update_pdes (struct amdgpu_device *adev,struct amdgpu_vm *vm,bool immediate); int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
Signature · 1 line
2.34.1
PATCH v3 12/13 drm/amdgpu: remove the unused ring parameter from update_spm_vmid()
In reply to Sunil KhatriEvery remaining caller of adev->gfx.rlc.funcs->update_spm_vmid() passes NULL for ring, since the only callers that ever passed a real ring were removed earlier in this series. Drop the parameter, and the dead SR-IOV one-VF ring-replay code in gfx_v11_0/gfx_v12_0/gfx_v12_1 that only ran when ring was non-NULL.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 12 ++---------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 11 +---------- drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 15 +++------------ drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 4 ++-- 9 files changed, 15 insertions(+), 41 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.h +1 -1
@@ -292,7 +292,7 @@ struct amdgpu_rlc_funcs {void (*reset)(struct amdgpu_device *adev);void (*start)(struct amdgpu_device *adev);void (*update_spm_vmid)(struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid); +unsigned int vmid);bool (*is_rlcg_access_range)(struct amdgpu_device *adev,uint32_t reg); };
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
@@ -8320,7 +8320,7 @@ static void gfx_v10_0_update_spm_vmid_internal(struct amdgpu_device *adev, }static void gfx_v10_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned int vmid) +unsigned int vmid) {amdgpu_gfx_off_ctrl (adev, false);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -10
@@ -944,7 +944,7 @@ static int gfx_v11_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }
@@ -5748,7 +5748,7 @@ static int gfx_v11_0_update_gfx_clock_gating(struct amdgpu_device *adev, }static void gfx_v11_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid) +unsigned int vmid) {u32 reg, pre_data, data;
@@ -5769,14 +5769,6 @@ static void gfx_v11_0_update_spm_vmid(struct amdgpu_device *adev, int xcc_id,WREG32_SOC15 (GC ,0 , regRLC_SPM_MC_CNTL, data); }amdgpu_gfx_off_ctrl (adev, true); - -if (ring - &&amdgpu_sriov_is_pp_one_vf (adev) - && (pre_data != data) - && ((ring->funcs->type ==AMDGPU_RING_TYPE_GFX ) - || (ring->funcs->type ==AMDGPU_RING_TYPE_COMPUTE ))) { -amdgpu_ring_emit_wreg (ring, reg, data); - } }static const struct amdgpu_rlc_funcs gfx_v11_0_rlc_funcs = {
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -10
@@ -773,7 +773,7 @@ static int gfx_v12_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }
@@ -4075,7 +4075,6 @@ static void gfx_v12_0_update_perf_clk(struct amdgpu_device *adev,static void gfx_v12_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid) {u32 reg, data;
@@ -4093,14 +4092,6 @@ static void gfx_v12_0_update_spm_vmid(struct amdgpu_device *adev,WREG32_SOC15_NO_KIQ (GC ,0 , regRLC_SPM_MC_CNTL, data); else WREG32_SOC15(GC, 0, regRLC_SPM_MC_CNTL, data); - -if (ring - &&amdgpu_sriov_is_pp_one_vf (adev) - && ((ring->funcs->type ==AMDGPU_RING_TYPE_GFX ) - || (ring->funcs->type ==AMDGPU_RING_TYPE_COMPUTE ))) { -uint32_t reg =SOC15_REG_OFFSET (GC ,0 , regRLC_SPM_MC_CNTL); -amdgpu_ring_emit_wreg (ring, reg, data); - } }static const struct amdgpu_rlc_funcs gfx_v12_0_rlc_funcs = {
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +3 -12
@@ -214,7 +214,7 @@ static int gfx_v12_1_init_cp_compute_microcode_bo(struct amdgpu_device *adev);static void gfx_v12_1_xcc_update_medium_grain_clock_gating (struct amdgpu_device *adev,bool enable,int xcc_id,bool force);static void gfx_v12_1_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid); +unsigned int vmid); static void gfx_v12_1_wait_reg_mem(struct amdgpu_ring *ring, int eng_sel, int mem_space, int opt, uint32_t addr0,
@@ -1861,7 +1861,7 @@ static int gfx_v12_1_xcc_rlc_resume(struct amdgpu_device *adev,int r;/* init spm vmid with 0xf */ -gfx_v12_1_update_spm_vmid (adev, xcc_id,NULL , adev->vm_manager.spm_vmid); +gfx_v12_1_update_spm_vmid (adev, xcc_id, adev->vm_manager.spm_vmid);if (adev->firmware.load_type ==AMDGPU_FW_LOAD_PSP ) {gfx_v12_1_xcc_init_csb (adev, xcc_id);
@@ -2918,8 +2918,7 @@ static void gfx_v12_1_update_perf_clk(struct amdgpu_device *adev,static void gfx_v12_1_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring, -unsigned vmid) +unsigned int vmid) {u32 reg, data;
@@ -2936,14 +2935,6 @@ static void gfx_v12_1_update_spm_vmid(struct amdgpu_device *adev,WREG32_SOC15_NO_KIQ (GC ,GET_INST (GC , xcc_id), regRLC_SPM_MC_CNTL, data); elseWREG32_SOC15 (GC ,GET_INST (GC ,xcc_id ),regRLC_SPM_MC_CNTL ,data ); - -if (ring - &&amdgpu_sriov_is_pp_one_vf (adev) - && ((ring->funcs->type ==AMDGPU_RING_TYPE_GFX ) - || (ring->funcs->type ==AMDGPU_RING_TYPE_COMPUTE ))) { -uint32_t reg =SOC15_REG_OFFSET (GC ,GET_INST (GC , xcc_id), regRLC_SPM_MC_CNTL); -amdgpu_ring_emit_wreg (ring, reg, data); - } }static const struct amdgpu_rlc_funcs gfx_v12_1_rlc_funcs = {
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +2 -2
@@ -3252,7 +3252,7 @@ static int gfx_v7_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }
@@ -3479,7 +3479,7 @@ static int gfx_v7_0_rlc_resume(struct amdgpu_device *adev) }static void gfx_v7_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid) +unsigned int vmid) {u32 data;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +2 -2
@@ -1274,7 +1274,7 @@ static int gfx_v8_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }
@@ -5491,7 +5491,7 @@ static void gfx_v8_0_unset_safe_mode(struct amdgpu_device *adev, int xcc_id) }static void gfx_v8_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid) +unsigned int vmid) {u32 data;
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
@@ -5225,7 +5225,7 @@ static void gfx_v9_0_update_spm_vmid_internal(struct amdgpu_device *adev, }static void gfx_v9_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned int vmid) +unsigned int vmid) {amdgpu_gfx_off_ctrl (adev, false);
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +2 -2
@@ -1395,7 +1395,7 @@ static int gfx_v9_4_3_rlc_init(struct amdgpu_device *adev) {/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }
@@ -1607,7 +1607,7 @@ static int gfx_v9_4_3_rlc_resume(struct amdgpu_device *adev) }static void gfx_v9_4_3_update_spm_vmid (struct amdgpu_device *adev, -int inst,struct amdgpu_ring *ring,unsigned int vmid) +int inst,unsigned int vmid) {u32 reg, pre_data, data;
Signature · 1 line
2.34.1
Re: [PATCH v3 12/13] drm/amdgpu: remove the unused ring parameter from update_spm_vmid()
Quoted 8 lines · Sunil Khatri
Every remaining caller of
adev->gfx.rlc.funcs->update_spm_vmid()passes NULL for ring, since the only callers that ever passed a real ring were removed earlier in this series. Drop the parameter, and the dead SR-IOV one-VF ring-replay code in gfx_v11_0/gfx_v12_0/gfx_v12_1 that only ran when ring was non-NULL.Signed-off-by Sunil Khatri <[email protected]>Suggested-by Christian König <[email protected]>
Good that we have this removed, the implementations in gfx11 and gfx12 where totally buggy and could crash if one application uses SPM immediately after another stopped using it.
Quoted 237 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 12 ++---------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 11 +---------- drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 15 +++------------ drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 4 ++-- 9 files changed, 15 insertions(+), 41 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.h +1
-1@@ -292,7 +292,7 @@ struct amdgpu_rlc_funcs {void (*reset)(struct amdgpu_device *adev);void (*start)(struct amdgpu_device *adev);void (*update_spm_vmid)(struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid); +unsigned int vmid);bool (*is_rlcg_access_range)(struct amdgpu_device *adev,uint32_t reg); };drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1
-1@@ -8320,7 +8320,7 @@ static void gfx_v10_0_update_spm_vmid_internal(struct amdgpu_device *adev, }static void gfx_v10_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned int vmid) +unsigned int vmid) {amdgpu_gfx_off_ctrl (adev, false);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-10@@ -944,7 +944,7 @@ static int gfx_v11_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }@@ -5748,7 +5748,7 @@ static int gfx_v11_0_update_gfx_clock_gating(struct amdgpu_device *adev, }static void gfx_v11_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid) +unsigned int vmid) {u32 reg, pre_data, data;@@ -5769,14 +5769,6 @@ static void gfx_v11_0_update_spm_vmid(struct amdgpu_device *adev, int xcc_id,WREG32_SOC15 (GC ,0 , regRLC_SPM_MC_CNTL, data); }amdgpu_gfx_off_ctrl (adev, true); - -if (ring - &&amdgpu_sriov_is_pp_one_vf (adev) - && (pre_data != data) - && ((ring->funcs->type ==AMDGPU_RING_TYPE_GFX ) - || (ring->funcs->type ==AMDGPU_RING_TYPE_COMPUTE ))) { -amdgpu_ring_emit_wreg (ring, reg, data); - } }static const struct amdgpu_rlc_funcs gfx_v11_0_rlc_funcs = {drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-10@@ -773,7 +773,7 @@ static int gfx_v12_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }@@ -4075,7 +4075,6 @@ static void gfx_v12_0_update_perf_clk(struct amdgpu_device *adev,static void gfx_v12_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid) {u32 reg, data;@@ -4093,14 +4092,6 @@ static void gfx_v12_0_update_spm_vmid(struct amdgpu_device *adev,WREG32_SOC15_NO_KIQ (GC ,0 , regRLC_SPM_MC_CNTL, data); else WREG32_SOC15(GC, 0, regRLC_SPM_MC_CNTL, data); - -if (ring - &&amdgpu_sriov_is_pp_one_vf (adev) - && ((ring->funcs->type ==AMDGPU_RING_TYPE_GFX ) - || (ring->funcs->type ==AMDGPU_RING_TYPE_COMPUTE ))) { -uint32_t reg =SOC15_REG_OFFSET (GC ,0 , regRLC_SPM_MC_CNTL); -amdgpu_ring_emit_wreg (ring, reg, data); - } }static const struct amdgpu_rlc_funcs gfx_v12_0_rlc_funcs = {drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +3
-12@@ -214,7 +214,7 @@ static int gfx_v12_1_init_cp_compute_microcode_bo(struct amdgpu_device *adev);static void gfx_v12_1_xcc_update_medium_grain_clock_gating (struct amdgpu_device *adev,bool enable,int xcc_id,bool force);static void gfx_v12_1_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid); +unsigned int vmid); static void gfx_v12_1_wait_reg_mem(struct amdgpu_ring *ring, int eng_sel, int mem_space, int opt, uint32_t addr0,@@ -1861,7 +1861,7 @@ static int gfx_v12_1_xcc_rlc_resume(struct amdgpu_device *adev,int r;/* init spm vmid with 0xf */ -gfx_v12_1_update_spm_vmid (adev, xcc_id,NULL , adev->vm_manager.spm_vmid); +gfx_v12_1_update_spm_vmid (adev, xcc_id, adev->vm_manager.spm_vmid);if (adev->firmware.load_type ==AMDGPU_FW_LOAD_PSP ) {gfx_v12_1_xcc_init_csb (adev, xcc_id);@@ -2918,8 +2918,7 @@ static void gfx_v12_1_update_perf_clk(struct amdgpu_device *adev,static void gfx_v12_1_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring, -unsigned vmid) +unsigned int vmid) {u32 reg, data;@@ -2936,14 +2935,6 @@ static void gfx_v12_1_update_spm_vmid(struct amdgpu_device *adev,WREG32_SOC15_NO_KIQ (GC ,GET_INST (GC , xcc_id), regRLC_SPM_MC_CNTL, data); elseWREG32_SOC15 (GC ,GET_INST (GC ,xcc_id ),regRLC_SPM_MC_CNTL ,data ); - -if (ring - &&amdgpu_sriov_is_pp_one_vf (adev) - && ((ring->funcs->type ==AMDGPU_RING_TYPE_GFX ) - || (ring->funcs->type ==AMDGPU_RING_TYPE_COMPUTE ))) { -uint32_t reg =SOC15_REG_OFFSET (GC ,GET_INST (GC , xcc_id), regRLC_SPM_MC_CNTL); -amdgpu_ring_emit_wreg (ring, reg, data); - } }static const struct amdgpu_rlc_funcs gfx_v12_1_rlc_funcs = {drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +2
-2@@ -3252,7 +3252,7 @@ static int gfx_v7_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }@@ -3479,7 +3479,7 @@ static int gfx_v7_0_rlc_resume(struct amdgpu_device *adev) }static void gfx_v7_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid) +unsigned int vmid) {u32 data;drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +2
-2@@ -1274,7 +1274,7 @@ static int gfx_v8_0_rlc_init(struct amdgpu_device *adev)/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }@@ -5491,7 +5491,7 @@ static void gfx_v8_0_unset_safe_mode(struct amdgpu_device *adev, int xcc_id) }static void gfx_v8_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned vmid) +unsigned int vmid) {u32 data;drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1@@ -5225,7 +5225,7 @@ static void gfx_v9_0_update_spm_vmid_internal(struct amdgpu_device *adev, }static void gfx_v9_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id, -struct amdgpu_ring *ring,unsigned int vmid) +unsigned int vmid) {amdgpu_gfx_off_ctrl (adev, false);drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +2
-2@@ -1395,7 +1395,7 @@ static int gfx_v9_4_3_rlc_init(struct amdgpu_device *adev) {/* init spm vmid with 0xf */ if (adev->gfx.rlc.funcs->update_spm_vmid) - adev->gfx.rlc.funcs->update_spm_vmid (adev,0 ,NULL , adev->vm_manager.spm_vmid); + adev->gfx.rlc.funcs->update_spm_vmid (adev,0 , adev->vm_manager.spm_vmid);return 0 ; }@@ -1607,7 +1607,7 @@ static int gfx_v9_4_3_rlc_resume(struct amdgpu_device *adev) }static void gfx_v9_4_3_update_spm_vmid (struct amdgpu_device *adev, -int inst,struct amdgpu_ring *ring,unsigned int vmid) +int inst,unsigned int vmid) {u32 reg, pre_data, data;
PATCH v3 13/13 drm/amdgpu: bind the SPM VMID's page table to the reserving VM
In reply to Sunil KhatriMES userqueues bypass amdgpu_vm_flush(), so a reservation granted to a userqueue never got its VMID's page table programmed. Add amdgpu_vm_spm_update(), called from amdgpu_vm_validate(), to bind the fixed SPM VMID's page-table-base to the reserving VM's root PD when that VM holds the reservation; it is a no-op for every other VM. amdgpu_vmid_free_reserved() unbinds it directly to a dummy address under the same lock that clears the reservation, so stray SPM accesses fault instead of racing a new reservation's binding.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 6 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 1 + 3 files changed, 44 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +6 -0
@@ -581,6 +581,12 @@ void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (vm->reserved_vmid[vmhub]) { vm->reserved_vmid[vmhub] =NULL ; id_mgr->reserved_vmid = false; + +if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs) { + adev->gfxhub.funcs->setup_vm_pt_regs (adev, adev->vm_manager.spm_vmid,0 ); +amdgpu_gmc_flush_gpu_tlb (adev, adev->vm_manager.spm_vmid, +AMDGPU_GFXHUB (0 ),TLB_FLUSH_LEGACY ); + } }mutex_unlock (&id_mgr->lock); }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +37 -0
@@ -568,6 +568,41 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)return result; } +/** +* amdgpu_vm_spm_update - bind the SPM VMID's page table base to @vm +* +* @adev: amdgpu device pointer +* @vm: vm to check against the SPM reservation +* +* The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base +* register must track whichever VM currently holds the reservation instead +* of being set per-job like a normal VMID. Bind it to @vm's real root PD +* address if @vm holds the reservation; otherwise do nothing, since @vm is +* not the one that could legitimately change the current binding. +*/ +void amdgpu_vm_spm_update (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct amdgpu_kq_vmid_mgr *id_mgr = + &adev->vm_manager.id_mgr[AMDGPU_GFXHUB (0 )]; +uint64_t pd_addr; + +if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs) +return ; + +mutex_lock (&id_mgr->lock); +if (vm->reserved_vmid[AMDGPU_GFXHUB (0 )] != + &id_mgr->ids[adev->vm_manager.spm_vmid] || !vm->root.bo) { +mutex_unlock (&id_mgr->lock); +return ; + } + + pd_addr =amdgpu_gmc_pd_addr (vm->root.bo); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, adev->vm_manager.spm_vmid, pd_addr); +amdgpu_gmc_flush_gpu_tlb (adev, adev->vm_manager.spm_vmid,AMDGPU_GFXHUB (0 ), +TLB_FLUSH_LEGACY ); +mutex_unlock (&id_mgr->lock); +} +/** * amdgpu_vm_validate - validate evicted BOs tracked in the VM *
@@ -630,6 +665,8 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,amdgpu_vm_bo_needs_update (bo_base); } +amdgpu_vm_spm_update (adev, vm); +if (!ticket)return 0 ;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
@@ -443,6 +443,7 @@ int amdgpu_vm_lock_individual(struct amdgpu_vm *vm, struct drm_exec *exec, unsigned int num_fences);bool amdgpu_vm_ready (struct amdgpu_vm *vm);uint64_t amdgpu_vm_generation (struct amdgpu_device *adev,struct amdgpu_vm *vm); +void amdgpu_vm_spm_update (struct amdgpu_device *adev,struct amdgpu_vm *vm); int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket, int (*callback)(void *p, struct amdgpu_bo *bo),
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH v3 13/13] drm/amdgpu: bind the SPM VMID's page table to the reserving VM
Quoted 61 lines · Sunil Khatri
MES userqueues bypass
amdgpu_vm_flush(), so a reservation granted to a userqueue never got its VMID's page table programmed. Addamdgpu_vm_spm_update(), called fromamdgpu_vm_validate(), to bind the fixed SPM VMID's page-table-base to the reserving VM's root PD when that VM holds the reservation; it is a no-op for every other VM.amdgpu_vmid_free_reserved()unbinds it directly to a dummy address under the same lock that clears the reservation, so stray SPM accesses fault instead of racing a new reservation's binding.Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 6 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 1 + 3 files changed, 44 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +6
-0@@ -581,6 +581,12 @@ void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (vm->reserved_vmid[vmhub]) { vm->reserved_vmid[vmhub] =NULL ; id_mgr->reserved_vmid = false; + +if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs) { + adev->gfxhub.funcs->setup_vm_pt_regs (adev, adev->vm_manager.spm_vmid,0 ); +amdgpu_gmc_flush_gpu_tlb (adev, adev->vm_manager.spm_vmid, +AMDGPU_GFXHUB (0 ),TLB_FLUSH_LEGACY ); + } }mutex_unlock (&id_mgr->lock); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +20
-0@@ -568,6 +568,41 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)return result; } +/** +* amdgpu_vm_spm_update - bind the SPM VMID's page table base to @vm +* +* @adev: amdgpu device pointer +* @vm: vm to check against the SPM reservation +* +* The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base +* register must track whichever VM currently holds the reservation instead +* of being set per-job like a normal VMID. Bind it to @vm's real root PD +* address if @vm holds the reservation; otherwise do nothing, since @vm is +* not the one that could legitimately change the current binding. +*/ +void amdgpu_vm_spm_update (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct amdgpu_kq_vmid_mgr *id_mgr = + &adev->vm_manager.id_mgr[AMDGPU_GFXHUB (0 )]; +uint64_t pd_addr; + +if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs) +return ;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 600
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-0+ +mutex_lock (&id_mgr->lock); +if (vm->reserved_vmid[AMDGPU_GFXHUB (0 )] != + &id_mgr->ids[adev->vm_manager.spm_vmid] || !vm->root.bo) { +mutex_unlock (&id_mgr->lock); +return ; + } + + pd_addr =amdgpu_gmc_pd_addr (vm->root.bo); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, adev->vm_manager.spm_vmid, pd_addr);
That function seriously needs a wrapper in amdgpu_gmc.c.
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+amdgpu_gmc_flush_gpu_tlb (adev, adev->vm_manager.spm_vmid,AMDGPU_GFXHUB (0 ), +TLB_FLUSH_LEGACY ); +mutex_unlock (&id_mgr->lock); +} +/** * amdgpu_vm_validate - validate evicted BOs tracked in the VM *
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 669
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -630,6 +665,8 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,amdgpu_vm_bo_needs_update (bo_base); } +amdgpu_vm_spm_update (adev, vm); +
Wrong place for that, this needs to be in the caller of amdgpu_vmid_alloc_reserved() and in amdgpu_userq_vm_validate_and_restore_queue().
And while at it please rename amdgpu_vmid_alloc_reserved() and amdgpu_vmid_free_reserved() into amdgpu_vmid_alloc_spm() and amdgpu_vmid_free_spm().
Regards,
Christian.
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0if (!ticket)return 0 ;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-0@@ -443,6 +443,7 @@ int amdgpu_vm_lock_individual(struct amdgpu_vm *vm, struct drm_exec *exec, unsigned int num_fences);bool amdgpu_vm_ready (struct amdgpu_vm *vm);uint64_t amdgpu_vm_generation (struct amdgpu_device *adev,struct amdgpu_vm *vm); +void amdgpu_vm_spm_update (struct amdgpu_device *adev,struct amdgpu_vm *vm); int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket, int (*callback)(void *p, struct amdgpu_bo *bo),
Re: [PATCH v3 13/13] drm/amdgpu: bind the SPM VMID's page table to the reserving VM
Quoted 66 lines · Christian König
Quoted 64 lines · Sunil Khatri
MES userqueues bypass
amdgpu_vm_flush(), so a reservation granted to a userqueue never got its VMID's page table programmed. Addamdgpu_vm_spm_update(), called fromamdgpu_vm_validate(), to bind the fixed SPM VMID's page-table-base to the reserving VM's root PD when that VM holds the reservation; it is a no-op for every other VM.amdgpu_vmid_free_reserved()unbinds it directly to a dummy address under the same lock that clears the reservation, so stray SPM accesses fault instead of racing a new reservation's binding.Signed-off-by Sunil Khatri<[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 6 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 1 + 3 files changed, 44 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +6
-0@@ -581,6 +581,12 @@ void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (vm->reserved_vmid[vmhub]) { vm->reserved_vmid[vmhub] =NULL ; id_mgr->reserved_vmid = false; + +if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs) { + adev->gfxhub.funcs->setup_vm_pt_regs (adev, adev->vm_manager.spm_vmid,0 ); +amdgpu_gmc_flush_gpu_tlb (adev, adev->vm_manager.spm_vmid, +AMDGPU_GFXHUB (0 ),TLB_FLUSH_LEGACY ); + } }mutex_unlock (&id_mgr->lock); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +23
-0@@ -568,6 +568,41 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)return result; } +/** +* amdgpu_vm_spm_update - bind the SPM VMID's page table base to @vm +* +* @adev: amdgpu device pointer +* @vm: vm to check against the SPM reservation +* +* The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base +* register must track whichever VM currently holds the reservation instead +* of being set per-job like a normal VMID. Bind it to @vm's real root PD +* address if @vm holds the reservation; otherwise do nothing, since @vm is +* not the one that could legitimately change the current binding. +*/ +void amdgpu_vm_spm_update (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct amdgpu_kq_vmid_mgr *id_mgr = + &adev->vm_manager.id_mgr[AMDGPU_GFXHUB (0 )]; +uint64_t pd_addr; + +if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs) +return ; + +mutex_lock (&id_mgr->lock); + if (vm->reserved_vmid[AMDGPU_GFXHUB(0)] !=
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 600
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0+ &id_mgr->ids[adev->vm_manager.spm_vmid] || !vm->root.bo) { +mutex_unlock (&id_mgr->lock); +return ; + } + + pd_addr =amdgpu_gmc_pd_addr (vm->root.bo); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, adev->vm_manager.spm_vmid, pd_addr);That function seriously needs a wrapper in
amdgpu_gmc.c.
You mean to move this function totally in the amdgpu_gmc.c or let this be here and create a wrapper in gmc layet calling this function?
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+amdgpu_gmc_flush_gpu_tlb (adev, adev->vm_manager.spm_vmid,AMDGPU_GFXHUB (0 ), +TLB_FLUSH_LEGACY ); +mutex_unlock (&id_mgr->lock); +} +/** * amdgpu_vm_validate - validate evicted BOs tracked in the VM * @@ -630,6 +665,8 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,amdgpu_vm_bo_needs_update (bo_base); }
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 669
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+amdgpu_vm_spm_update (adev, vm); +Wrong place for that, this needs to be in the caller of
amdgpu_vmid_alloc_reserved()and inamdgpu_userq_vm_validate_and_restore_queue().
If i understood it correctly, amdgpu_vm_ioctl -> amdgpu_vmid_alloc_reserved after this call returns when we should call amdgpu_vm_spm_update? For the userqueues,
amdgpu_userq_vm_validate_and_restore_queue{ ... ret = amdgpu_vm_update_pdes(adev, vm, false); if (ret) goto unlock_all; is it safe to add after this point ? amdgpu_vm_spm_update(adev, vm); }
Quoted 2 lines
And while at it please rename
amdgpu_vmid_alloc_reserved()andamdgpu_vmid_free_reserved()intoamdgpu_vmid_alloc_spm()andamdgpu_vmid_free_spm().
Noted
Regards
Sunil Khatri
Quoted 19 lines
Regards,
Christian.Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0if (!ticket)return 0 ;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-0@@ -443,6 +443,7 @@ int amdgpu_vm_lock_individual(struct amdgpu_vm *vm, struct drm_exec *exec, unsigned int num_fences);bool amdgpu_vm_ready (struct amdgpu_vm *vm);uint64_t amdgpu_vm_generation (struct amdgpu_device *adev,struct amdgpu_vm *vm); +void amdgpu_vm_spm_update (struct amdgpu_device *adev,struct amdgpu_vm *vm); int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket, int (*callback)(void *p, struct amdgpu_bo *bo),
Christian König
maintainerRe: [PATCH v3 13/13] drm/amdgpu: bind the SPM VMID's page table to the reserving VM
Quoted 75 lines · Sunil
Quoted 65 lines · Christian König
Quoted 64 lines · Sunil Khatri
MES userqueues bypass
amdgpu_vm_flush(), so a reservation granted to a userqueue never got its VMID's page table programmed. Addamdgpu_vm_spm_update(), called fromamdgpu_vm_validate(), to bind the fixed SPM VMID's page-table-base to the reserving VM's root PD when that VM holds the reservation; it is a no-op for every other VM.amdgpu_vmid_free_reserved()unbinds it directly to a dummy address under the same lock that clears the reservation, so stray SPM accesses fault instead of racing a new reservation's binding.Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 6 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 37 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 1 + 3 files changed, 44 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +6
-0@@ -581,6 +581,12 @@ void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (vm->reserved_vmid[vmhub]) { vm->reserved_vmid[vmhub] =NULL ; id_mgr->reserved_vmid = false; + +if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs) { + adev->gfxhub.funcs->setup_vm_pt_regs (adev, adev->vm_manager.spm_vmid,0 ); +amdgpu_gmc_flush_gpu_tlb (adev, adev->vm_manager.spm_vmid, +AMDGPU_GFXHUB (0 ),TLB_FLUSH_LEGACY ); + } }mutex_unlock (&id_mgr->lock); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +23
-0@@ -568,6 +568,41 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)return result; } +/** +* amdgpu_vm_spm_update - bind the SPM VMID's page table base to @vm +* +* @adev: amdgpu device pointer +* @vm: vm to check against the SPM reservation +* +* The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base +* register must track whichever VM currently holds the reservation instead +* of being set per-job like a normal VMID. Bind it to @vm's real root PD +* address if @vm holds the reservation; otherwise do nothing, since @vm is +* not the one that could legitimately change the current binding. +*/ +void amdgpu_vm_spm_update (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct amdgpu_kq_vmid_mgr *id_mgr = + &adev->vm_manager.id_mgr[AMDGPU_GFXHUB (0 )]; +uint64_t pd_addr; + +if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs) +return ; + +mutex_lock (&id_mgr->lock); + if (vm->reserved_vmid[AMDGPU_GFXHUB(0)] !=Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 600
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0+ &id_mgr->ids[adev->vm_manager.spm_vmid] || !vm->root.bo) { +mutex_unlock (&id_mgr->lock); +return ; + } + + pd_addr =amdgpu_gmc_pd_addr (vm->root.bo); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, adev->vm_manager.spm_vmid, pd_addr);That function seriously needs a wrapper in
amdgpu_gmc.c.
Quoted 1 line
You mean to move this function totally in the
amdgpu_gmc.cor let this be here and create a wrapper in gmc layet calling this function?
Create a wrapper for this in the gmc layer and call that here.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+amdgpu_gmc_flush_gpu_tlb (adev, adev->vm_manager.spm_vmid,AMDGPU_GFXHUB (0 ), +TLB_FLUSH_LEGACY ); +mutex_unlock (&id_mgr->lock); +} +/** * amdgpu_vm_validate - validate evicted BOs tracked in the VM * @@ -630,6 +665,8 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,amdgpu_vm_bo_needs_update (bo_base); }
Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 669
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+amdgpu_vm_spm_update (adev, vm); +Wrong place for that, this needs to be in the caller of
amdgpu_vmid_alloc_reserved()and inamdgpu_userq_vm_validate_and_restore_queue().If i understood it correctly,
amdgpu_vm_ioctl->amdgpu_vmid_alloc_reservedafter this call returns when we should callamdgpu_vm_spm_update?
Yes.
Quoted 4 lines
For the userqueues,
amdgpu_userq_vm_validate_and_restore_queue{ ... ret =amdgpu_vm_update_pdes(adev, vm, false); if (ret) gotounlock_all; is it safe to add after this point ?amdgpu_vm_spm_update(adev, vm); }
I think that should be before amdgpu_evf_mgr_rearm().
Regards,
Christian.
Quoted 26 lines
Quoted 2 lines
And while at it please rename
amdgpu_vmid_alloc_reserved()andamdgpu_vmid_free_reserved()intoamdgpu_vmid_alloc_spm()andamdgpu_vmid_free_spm().Noted
Regards
Sunil KhatriQuoted 18 lines
Regards,
Christian.Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0if (!ticket)return 0 ;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-0@@ -443,6 +443,7 @@ int amdgpu_vm_lock_individual(struct amdgpu_vm *vm, struct drm_exec *exec, unsigned int num_fences);bool amdgpu_vm_ready (struct amdgpu_vm *vm);uint64_t amdgpu_vm_generation (struct amdgpu_device *adev,struct amdgpu_vm *vm); +void amdgpu_vm_spm_update (struct amdgpu_device *adev,struct amdgpu_vm *vm); int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket, int (*callback)(void *p, struct amdgpu_bo *bo),