Skip to contentSkip to conversation

drm/amdgpu: use the same naming scheme for kq and uq VMID masks

PATCH In review Sunil Khatri 3 participants 16 messages Oct 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/14 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
index 1c5bce0500ac9..392a18b1f2b4b 100644
@@ -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
index 4dfcec76afed7..105272ee2dce6 100644
@@ -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
#1 lore raw

PATCH v3 2/14 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.

Assisted-by Claude:claude-sonnet-5
---
 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
index 392a18b1f2b4b..ed1efde29a9a5 100644
@@ -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
index d99e42ca308ef..ddcdc7256ef07 100644
@@ -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
#2 lore raw

PATCH v3 3/14 drm/amdgpu: use dedicated SPM VMID from the reserved path

In reply to Sunil Khatri

Use 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
index ed1efde29a9a5..0eac7695f5587 100644
@@ -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
#3 lore raw

PATCH v3 4/14 drm/amdgpu: reserve SPM VMID on gfx7

In reply to Sunil Khatri

Set 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
index 4199300eab177..c09f5153679ea 100644
@@ -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
#4 lore raw

PATCH v3 5/14 drm/amdgpu: reserve SPM VMID on gfx8

In reply to Sunil Khatri

Set 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
index 3f9ec7427319d..15592027e7c0c 100644
@@ -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
#5 lore raw

PATCH v3 6/14 drm/amdgpu: reserve SPM VMID on gfx9

In reply to Sunil Khatri

Set 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
index 3a8dc15ef95b9..c058a00bf2fbb 100644
@@ -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
#6 lore raw

PATCH v3 7/14 drm/amdgpu: reserve SPM VMID on gfx10

In reply to Sunil Khatri

Set 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
index 55d286275466d..49f593fe2a876 100644
@@ -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
#7 lore raw

PATCH v3 8/14 drm/amdgpu: reserve SPM VMID on gfx11

In reply to Sunil Khatri

Set 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
index 301ffb89c9672..709c3d1b99980 100644
@@ -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
#8 lore raw

PATCH v3 9/14 drm/amdgpu: reserve SPM VMID on gfx12

In reply to Sunil Khatri

Set 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
index e4a74cd6574f4..cd276a138e101 100644
@@ -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
#9 lore raw

PATCH v3 10/14 drm/amdgpu: use spm_vmid for the default RLC SPM VMID

In reply to Sunil Khatri

The 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
index e791bf86ad571..fce651d9bc613 100644
@@ -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
index 1caecf26c4589..1f2ad47adb9fe 100644
@@ -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
index a5151e15e1011..72ceb113689e8 100644
@@ -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
index 4ceb3c0aa3322..b44f5ec68714d 100644
@@ -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
index 2eaea0e4864dd..91ce21425126f 100644
@@ -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
index 696558f6f30d3..479480e39fe47 100644
@@ -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
index 3fb51417ebee5..8afcdb54a0f56 100644
@@ -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
index 3572eb9b5758a..1d1973fd8f677 100644
@@ -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
#10 lore raw

PATCH v3 11/14 drm/amdgpu: remove the now-redundant runtime SPM VMID update

In reply to Sunil Khatri

The 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
index 0f8b097001e3c..f98a7c6797b3c 100644
@@ -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
index 0eac7695f5587..992f7cb3a3102 100644
@@ -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
index ae569b4497f6a..f6577f82e6b93 100644
@@ -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
index 7d3659ef11e53..de992405ed718 100644
@@ -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
index ddcdc7256ef07..b8aa45db1d844 100644
@@ -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
#11 lore raw

PATCH v3 12/14 drm/amdgpu: remove the unused ring parameter from update_spm_vmid()

In reply to 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.

---
 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
index 2ae2c1d0f702b..e38a8ea02c520 100644
@@ -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
index fce651d9bc613..b6f61f4a08e5a 100644
@@ -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
index 1f2ad47adb9fe..315dfd806d56f 100644
@@ -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
index 72ceb113689e8..d82e7f115b7ef 100644
@@ -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
index b44f5ec68714d..147bed75261c1 100644
@@ -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);
 	else
 		WREG32_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
index 91ce21425126f..dd00be109d7cc 100644
@@ -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
index 479480e39fe47..c9268cc5715b9 100644
@@ -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
index 8afcdb54a0f56..75d1bbdb421ff 100644
@@ -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
index 1d1973fd8f677..0ffdef21df0ae 100644
@@ -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
#12 lore raw

PATCH v3 13/14 drm/amdgpu: bind the SPM VMID's page table to the reserving VM

In reply to Sunil Khatri

MES 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() 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. It is called right after a successful AMDGPU_VM_OP_RESERVE_VMID (amdgpu_vm_ioctl()) and from amdgpu_userq_vm_validate_and_restore_queue(), the two paths that can actually change the binding. 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.

Both binds go through the new amdgpu_gmc_bind_vmid() helper, which pairs setup_vm_pt_regs() with the matching TLB flush for a VMID bound outside the normal per-job VM flush path.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c   | 24 +++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h   |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c   |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c |  7 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    | 43 +++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h    |  1 +
 6 files changed, 79 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +24 -0
index 5d4276cd0f7d3..4204c3c750a8d 100644
@@ -787,6 +787,30 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	dev_err(adev->dev, "Error flushing GPU TLB using the SDMA (%d)!\n", r);
 }
 
+/**
+ * amdgpu_gmc_bind_vmid - bind a VMID's page table base and flush its TLB
+ *
+ * @adev: amdgpu device pointer
+ * @vmhub: vmhub the VMID belongs to
+ * @vmid: VMID to bind
+ * @pd_addr: new page directory address, 0 to unbind to a faulting address
+ *
+ * For VMIDs that are bound directly to a VM's page table outside the
+ * normal per-job VM flush path, e.g. a dedicated out-of-pool VMID.
+ */
+void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
+			  unsigned int vmid, uint64_t pd_addr)
+{
+	bool is_mmhub = AMDGPU_IS_MMHUB0(vmhub) || AMDGPU_IS_MMHUB1(vmhub);
+
+	if (is_mmhub)
+		adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+	else
+		adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+
+	amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, TLB_FLUSH_LEGACY);
+}
+
 static void amdgpu_gmc_flush_pasid_regs(struct amdgpu_device *adev, u16 pasid,
 					u32 flush_type, bool all_hub,
 					u32 inst)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -0
index 76e6f1f96913c..d17055d4c50a9 100644
@@ -444,6 +444,8 @@ int amdgpu_gmc_ras_sw_init(struct amdgpu_device *adev);
 int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev);
 void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 			      uint32_t vmhub, uint32_t flush_type);
+void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
+			  unsigned int vmid, uint64_t pd_addr);
 int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, u16 pasid,
 				   u32 flush_type, bool all_hub, u32 inst);
 int amdgpu_gmc_flush_gpu_tlb_pasid_xccs(struct amdgpu_device *adev, u16 pasid,
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +4 -0
index 992f7cb3a3102..8e60e5fdd210d 100644
@@ -581,6 +581,10 @@ 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)
+			amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0),
+					     adev->vm_manager.spm_vmid, 0);
 	}
 	mutex_unlock(&id_mgr->lock);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +7 -0
index e29823ae8672e..d45357e092bb5 100644
@@ -1075,6 +1075,13 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
 		if (unlikely(ret))
 			goto unlock_all;
 
+		/*
+		 * Userqueues never go through amdgpu_vm_flush(), so this is
+		 * the only place that can rebind the SPM VMID's page table
+		 * for a userqueue-held reservation.
+		 */
+		amdgpu_vm_spm_update(adev, vm);
+
 		/* This locks and validates the remaining evicted BOs */
 		ret = amdgpu_userq_bo_validate(adev, &exec, vm);
 		drm_exec_retry_on_contention(&exec);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +41 -2

56 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
index b8aa45db1d844..2a2a2ccbaa2cc 100644
@@ -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
maintainer
#13 lore raw

Re: [PATCH v3 13/14] drm/amdgpu: bind the SPM VMID's page table to the reserving VM

Quoted 79 lines · Sunil Khatri

MES 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() 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. It is called right after a successful AMDGPU_VM_OP_RESERVE_VMID (amdgpu_vm_ioctl()) and from amdgpu_userq_vm_validate_and_restore_queue(), the two paths that can actually change the binding. 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.

Both binds go through the new amdgpu_gmc_bind_vmid() helper, which pairs setup_vm_pt_regs() with the matching TLB flush for a VMID bound outside the normal per-job VM flush path.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c   | 24 +++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h   |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c   |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c |  7 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    | 43 +++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h    |  1 +
 6 files changed, 79 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +24 -0
index 5d4276cd0f7d3..4204c3c750a8d 100644
@@ -787,6 +787,30 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	dev_err(adev->dev, "Error flushing GPU TLB using the SDMA (%d)!\n", r);
 }
 
+/**
+ * amdgpu_gmc_bind_vmid - bind a VMID's page table base and flush its TLB
+ *
+ * @adev: amdgpu device pointer
+ * @vmhub: vmhub the VMID belongs to
+ * @vmid: VMID to bind
+ * @pd_addr: new page directory address, 0 to unbind to a faulting address
+ *
+ * For VMIDs that are bound directly to a VM's page table outside the
+ * normal per-job VM flush path, e.g. a dedicated out-of-pool VMID.
+ */
+void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
+			  unsigned int vmid, uint64_t pd_addr)
+{
+	bool is_mmhub = AMDGPU_IS_MMHUB0(vmhub) || AMDGPU_IS_MMHUB1(vmhub);
+
+	if (is_mmhub)
+		adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+	else
+		adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+
+	amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, TLB_FLUSH_LEGACY);
+}
+
 static void amdgpu_gmc_flush_pasid_regs(struct amdgpu_device *adev, u16 pasid,
 					u32 flush_type, bool all_hub,
 					u32 inst)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -0
index 76e6f1f96913c..d17055d4c50a9 100644
@@ -444,6 +444,8 @@ int amdgpu_gmc_ras_sw_init(struct amdgpu_device *adev);
 int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev);
 void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 			      uint32_t vmhub, uint32_t flush_type);
+void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
+			  unsigned int vmid, uint64_t pd_addr);
 int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, u16 pasid,
 				   u32 flush_type, bool all_hub, u32 inst);
 int amdgpu_gmc_flush_gpu_tlb_pasid_xccs(struct amdgpu_device *adev, u16 pasid,
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0 -0
index 992f7cb3a3102..8e60e5fdd210d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 587

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +4 -0
@@ -581,6 +581,10 @@ 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)
+			amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0),
+					     adev->vm_manager.spm_vmid, 0);

Yeah that will break the uAPI and is not something we can do. The problem is that we need to wait for the VM to be idle.

Is the VM locked when that is called? If yes we can just wait for it to be idle before calling this.

Quoted 43 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0 -0
 	}
 	mutex_unlock(&id_mgr->lock);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +7 -0
index e29823ae8672e..d45357e092bb5 100644
@@ -1075,6 +1075,13 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
 		if (unlikely(ret))
 			goto unlock_all;
 
+		/*
+		 * Userqueues never go through amdgpu_vm_flush(), so this is
+		 * the only place that can rebind the SPM VMID's page table
+		 * for a userqueue-held reservation.
+		 */
+		amdgpu_vm_spm_update(adev, vm);
+
 		/* This locks and validates the remaining evicted BOs */
 		ret = amdgpu_userq_bo_validate(adev, &exec, vm);
 		drm_exec_retry_on_contention(&exec);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -0
index de992405ed718..05358e7d81cb8 100644
@@ -568,6 +568,39 @@ 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)
+{

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 594

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -0
+	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) {

Drop checking vm->root.bo, that makes no sense.

Rather call amdgpu_vm_ready() to check if the VM is actually useable.

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 599

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -0
+		mutex_unlock(&id_mgr->lock);
+		return;
+	}
+
+	pd_addr = amdgpu_gmc_pd_addr(vm->root.bo);

This will probably cause lockdep to warn that the VM isn't locked, but I'm not 100% sure.

Please double check if the VM is locked here.

Regards,
Christian.

Quoted 37 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +12 -2
+	amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), adev->vm_manager.spm_vmid, pd_addr);
+	mutex_unlock(&id_mgr->lock);
+}
+
 /**
  * amdgpu_vm_validate - validate evicted BOs tracked in the VM
  *
@@ -2958,9 +2991,15 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		return -EINVAL;
 
 	switch (args->in.op) {
-	case AMDGPU_VM_OP_RESERVE_VMID:
+	case AMDGPU_VM_OP_RESERVE_VMID: {
+		int r;
+
 		/* We only have requirement to reserve vmid from gfxhub */
-		return amdgpu_vmid_alloc_reserved(adev, vm, AMDGPU_GFXHUB(0));
+		r = amdgpu_vmid_alloc_reserved(adev, vm, AMDGPU_GFXHUB(0));
+		if (!r)
+			amdgpu_vm_spm_update(adev, vm);
+		return r;
+	}
 	case AMDGPU_VM_OP_UNRESERVE_VMID:
 		amdgpu_vmid_free_reserved(adev, vm, AMDGPU_GFXHUB(0));
 		break;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
index b8aa45db1d844..2a2a2ccbaa2cc 100644
@@ -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),
#14 lore raw

Re: [PATCH v3 13/14] drm/amdgpu: bind the SPM VMID's page table to the reserving VM

Quoted 89 lines · Christian König
Quoted 79 lines · Sunil Khatri

MES 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() 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. It is called right after a successful AMDGPU_VM_OP_RESERVE_VMID (amdgpu_vm_ioctl()) and from amdgpu_userq_vm_validate_and_restore_queue(), the two paths that can actually change the binding. 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.

Both binds go through the new amdgpu_gmc_bind_vmid() helper, which pairs setup_vm_pt_regs() with the matching TLB flush for a VMID bound outside the normal per-job VM flush path.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c   | 24 +++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h   |  2 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c   |  4 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c |  7 ++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    | 43 +++++++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h    |  1 +
  6 files changed, 79 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +24 -0
index 5d4276cd0f7d3..4204c3c750a8d 100644
@@ -787,6 +787,30 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
  	dev_err(adev->dev, "Error flushing GPU TLB using the SDMA (%d)!\n", r);
  }
 
+/**
+ * amdgpu_gmc_bind_vmid - bind a VMID's page table base and flush its TLB
+ *
+ * @adev: amdgpu device pointer
+ * @vmhub: vmhub the VMID belongs to
+ * @vmid: VMID to bind
+ * @pd_addr: new page directory address, 0 to unbind to a faulting address
+ *
+ * For VMIDs that are bound directly to a VM's page table outside the
+ * normal per-job VM flush path, e.g. a dedicated out-of-pool VMID.
+ */
+void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
+			  unsigned int vmid, uint64_t pd_addr)
+{
+	bool is_mmhub = AMDGPU_IS_MMHUB0(vmhub) || AMDGPU_IS_MMHUB1(vmhub);
+
+	if (is_mmhub)
+		adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+	else
+		adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+
+	amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, TLB_FLUSH_LEGACY);
+}
+
  static void amdgpu_gmc_flush_pasid_regs(struct amdgpu_device *adev, u16 pasid,
  					u32 flush_type, bool all_hub,
  					u32 inst)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -0
index 76e6f1f96913c..d17055d4c50a9 100644
@@ -444,6 +444,8 @@ int amdgpu_gmc_ras_sw_init(struct amdgpu_device *adev);
  int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev);
  void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
  			      uint32_t vmhub, uint32_t flush_type);
+void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
+			  unsigned int vmid, uint64_t pd_addr);
  int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, u16 pasid,
  				   u32 flush_type, bool all_hub, u32 inst);
  int amdgpu_gmc_flush_gpu_tlb_pasid_xccs(struct amdgpu_device *adev, u16 pasid,
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0 -0
index 992f7cb3a3102..8e60e5fdd210d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 587

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +4 -0
@@ -581,6 +581,10 @@ 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)
+			amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0),
+					     adev->vm_manager.spm_vmid, 0);

Yeah that will break the uAPI and is not something we can do. The problem is that we need to wait for the VM to be idle.

Quoted 1 line

Is the VM locked when that is called? If yes we can just wait for it to be idle before calling this.

Sure i will add the wait for vm to be idle here there is amdgpu_sync_wait which make sure that this vmid all jobs are done and the next step is just setting pt to 0 and flush which doesnt depend upong the root pd here.

Quoted 56 lines
Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0 -0
  	}
  	mutex_unlock(&id_mgr->lock);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +7 -0
index e29823ae8672e..d45357e092bb5 100644
@@ -1075,6 +1075,13 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
  		if (unlikely(ret))
  			goto unlock_all;
 
+		/*
+		 * Userqueues never go through amdgpu_vm_flush(), so this is
+		 * the only place that can rebind the SPM VMID's page table
+		 * for a userqueue-held reservation.
+		 */
+		amdgpu_vm_spm_update(adev, vm);
+
  		/* This locks and validates the remaining evicted BOs */
  		ret = amdgpu_userq_bo_validate(adev, &exec, vm);
  		drm_exec_retry_on_contention(&exec);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -0
index de992405ed718..05358e7d81cb8 100644
@@ -568,6 +568,39 @@ 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)
+{

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 594

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -0
+	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) {

Drop checking vm->root.bo, that makes no sense.

Quoted 1 line

Rather call amdgpu_vm_ready() to check if the VM is actually useable.

Noted

Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 599

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -0
+		mutex_unlock(&id_mgr->lock);
+		return;
+	}
+
+	pd_addr = amdgpu_gmc_pd_addr(vm->root.bo);

This will probably cause lockdep to warn that the VM isn't locked, but I'm not 100% sure.

VM is locked in this loop here in exec manager before making this call.

Quoted 43 lines

Please double check if the VM is locked here.

Regards,
Christian.

Quoted 37 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +12 -2
+	amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), adev->vm_manager.spm_vmid, pd_addr);
+	mutex_unlock(&id_mgr->lock);
+}
+
  /**
   * amdgpu_vm_validate - validate evicted BOs tracked in the VM
   *
@@ -2958,9 +2991,15 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
  		return -EINVAL;
 
  	switch (args->in.op) {
-	case AMDGPU_VM_OP_RESERVE_VMID:
+	case AMDGPU_VM_OP_RESERVE_VMID: {
+		int r;
+
  		/* We only have requirement to reserve vmid from gfxhub */
-		return amdgpu_vmid_alloc_reserved(adev, vm, AMDGPU_GFXHUB(0));
+		r = amdgpu_vmid_alloc_reserved(adev, vm, AMDGPU_GFXHUB(0));
+		if (!r)
+			amdgpu_vm_spm_update(adev, vm);
+		return r;
+	}
  	case AMDGPU_VM_OP_UNRESERVE_VMID:
  		amdgpu_vmid_free_reserved(adev, vm, AMDGPU_GFXHUB(0));
  		break;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
index b8aa45db1d844..2a2a2ccbaa2cc 100644
@@ -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),
#15 lore raw

PATCH v3 14/14 drm/amdgpu: rename amdgpu_vmid_alloc/free_reserved to _spm

In reply to Sunil Khatri

These functions only ever hand out the dedicated SPM VMID now, not a generic reserved VMID. Rename them to amdgpu_vmid_alloc_spm() and amdgpu_vmid_free_spm() to say so. Pure rename, no functional change.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 8 ++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +4 -4
index 8e60e5fdd210d..a3293b32ea58a 100644
@@ -527,7 +527,7 @@ bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub)
 }
 
 /*
- * amdgpu_vmid_alloc_reserved - reserve a specific VMID for this vm
+ * amdgpu_vmid_alloc_spm - reserve a specific VMID for this vm
  * @adev: amdgpu device structure
  * @vm: the VM to reserve an ID for
  * @vmhub: the VMHUB which should be used
@@ -536,7 +536,7 @@ bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub)
  *
  * Returns: 0 for success, -ENOENT if an ID is already reserved.
  */
-int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
+int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			       unsigned vmhub)
 {
 	struct amdgpu_kq_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
@@ -567,12 +567,12 @@ int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 }
 
 /*
- * amdgpu_vmid_free_reserved - free up a reserved VMID again
+ * amdgpu_vmid_free_spm - free up a reserved VMID again
  * @adev: amdgpu device structure
  * @vm: the VM with the reserved ID
  * @vmhub: the VMHUB which should be used
  */
-void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
+void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			       unsigned vmhub)
 {
 	struct amdgpu_kq_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +2 -2
index 105272ee2dce6..e2aa16b0898cb 100644
@@ -122,9 +122,9 @@ void amdgpu_pasid_mgr_cleanup(void);
 bool amdgpu_vmid_had_gpu_reset(struct amdgpu_device *adev,
 			       struct amdgpu_vmid *id);
 bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub);
-int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
+int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			       unsigned vmhub);
-void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
+void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			       unsigned vmhub);
 int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
 		     struct amdgpu_job *job, struct dma_fence **fence);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
index 05358e7d81cb8..15fe597b7515e 100644
@@ -2892,7 +2892,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 	dma_fence_put(vm->last_update);
 
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
-		amdgpu_vmid_free_reserved(adev, vm, i);
+		amdgpu_vmid_free_spm(adev, vm, i);
 	}
 
 	ttm_lru_bulk_move_fini(&adev->mman.bdev, &vm->lru_bulk_move);
@@ -2995,13 +2995,13 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		int r;
 
 		/* We only have requirement to reserve vmid from gfxhub */
-		r = amdgpu_vmid_alloc_reserved(adev, vm, AMDGPU_GFXHUB(0));
+		r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(0));
 		if (!r)
 			amdgpu_vm_spm_update(adev, vm);
 		return r;
 	}
 	case AMDGPU_VM_OP_UNRESERVE_VMID:
-		amdgpu_vmid_free_reserved(adev, vm, AMDGPU_GFXHUB(0));
+		amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(0));
 		break;
 	default:
 		return -EINVAL;
Signature · 1 line
2.34.1