Skip to contentSkip to conversation

Revert "drm/amdgpu: mark A+A VF VRAM mappings as system memory"

PATCH In review Zhigang Luo 2 participants 8 messages Nov 11 – Nov 13

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

PATCH 1/4 Revert "drm/amdgpu: mark A+A VF VRAM mappings as system memory"

This reverts commit 521bedfc94cc.

The patch sets AMDGPU_PTE_SYSTEM in amdgpu_ttm_tt_pde_flags() and converts the VRAM address with amdgpu_gmc_vram_mc2pa() inside amdgpu_gmc_get_pde_for_bo(). gmc_v12_1_get_vm_pde() already converts an MC address to a physical address and skips that conversion when the SYSTEM bit is set, so setting the bit first bypasses the translation.

The bit belongs in the GFX 12.1 helpers, after that translation. PDB0 is written directly and does not go through get_vm_pde(), and NPA still requires PTE.S=0, so those two pieces come back in the following patch.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c    |  9 ---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 14 +++-----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c |  1 -
 drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c     |  1 -
 4 files changed, 3 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -9
index 4204c3c750a8..659e89e5e78f 100644
@@ -122,11 +122,6 @@ void amdgpu_gmc_get_pde_for_bo(struct amdgpu_bo *bo, int level,
 		break;
 	case TTM_PL_VRAM:
 		*addr = amdgpu_bo_gpu_offset(bo);
-		/* For SPM-backed VRAM, convert the MC address to a physical
-		 * address for system memory path access.
-		 */
-		if (amdgpu_virt_vram_is_spm(adev))
-			*addr = amdgpu_gmc_vram_mc2pa(adev, *addr);
 		break;
 	default:
 		*addr = 0;
@@ -1286,8 +1281,6 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
 	flags |= AMDGPU_PTE_VALID | AMDGPU_PTE_READABLE;
 	flags |= AMDGPU_PTE_WRITEABLE;
 	flags |= AMDGPU_PTE_SNOOPED;
-	if (amdgpu_virt_vram_is_spm(adev))
-		flags |= AMDGPU_PTE_SYSTEM;
 	flags |= AMDGPU_PTE_FRAG((adev->gmc.vmid0_page_table_block_size + 9*1));
 	flags |= AMDGPU_PDE_PTE_FLAG(adev);
 
@@ -1307,8 +1300,6 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
 	 * pointing to a 4K system page
 	 */
 	flags = AMDGPU_PTE_VALID;
-	if (amdgpu_virt_vram_is_spm(adev))
-		flags |= AMDGPU_PTE_SYSTEM;
 	flags |= AMDGPU_PTE_SNOOPED | AMDGPU_PDE_BFS_FLAG(adev, 0);
 	/* Requires gart_ptb_gpu_pa to be 4K aligned */
 	amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, gart_ptb_gpu_pa, flags);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -11
index 212d86adffd8..37f7f421b470 100644
@@ -1461,17 +1461,9 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_resource *mem)
 			flags |= AMDGPU_PTE_SNOOPED;
 	}
 
-	if (mem && mem->mem_type == TTM_PL_VRAM) {
-		if (mem->bo) {
-			struct amdgpu_device *adev = amdgpu_ttm_adev(mem->bo->bdev);
-
-			if (amdgpu_virt_vram_is_spm(adev))
-				flags |= AMDGPU_PTE_SYSTEM;
-		}
-
-		if (mem->bus.caching == ttm_cached)
-			flags |= AMDGPU_PTE_SNOOPED;
-	}
+	if (mem && mem->mem_type == TTM_PL_VRAM &&
+			mem->bus.caching == ttm_cached)
+		flags |= AMDGPU_PTE_SNOOPED;
 
 	return flags;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c +0 -1
index 11f022c56667..3bb426b33af9 100644
@@ -6171,7 +6171,6 @@ static int amdgpu_ualink_peer_remote_init(struct amdgpu_device *adev)
 	flags = amdgpu_ttm_tt_pte_flags(adev, bo->tbo.ttm, bo->tbo.resource);
 	flags |= AMDGPU_PTE_SNOOPED | AMDGPU_PTE_PRT_GFX12 | AMDGPU_PTE_BUS_ATOMICS;
 	flags &= ~AMDGPU_PTE_VALID;
-	flags &= ~AMDGPU_PTE_SYSTEM;
 	/* PTE.X=0 turn off RPC checks for RBs, wptr and doorbell NPA address */
 	flags &= ~AMDGPU_PTE_EXECUTABLE;
 
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +0 -1
index b67683012002..76391fca6c62 100644
@@ -616,7 +616,6 @@ static void gmc_v12_1_get_npa_flags(struct amdgpu_device *adev,
 	*flags |= AMDGPU_PTE_SNOOPED | AMDGPU_PTE_PRT_GFX12 |
 		   AMDGPU_PTE_BUS_ATOMICS;
 	*flags &= ~AMDGPU_PTE_VALID;
-	*flags &= ~AMDGPU_PTE_SYSTEM;
 	*flags &= ~AMDGPU_PTE_EXECUTABLE;
 }
 
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/4 Revert "drm/amdkfd: mark A+A VF VRAM PTEs as system memory"

This reverts commit daf19be40e04.

SVM VRAM ranges leave AMDGPU_PTE_SYSTEM clear and then call amdgpu_gmc_get_vm_pte() with a NULL buffer object. The GFX 12.1 PTE helper sets the bit for an A+A VF, so the special case in svm_range_get_pte_flags() is the wrong place.

---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -7
index 876476046926..a5aed7853775 100644
@@ -1398,13 +1398,7 @@ svm_range_get_pte_flags(struct kfd_node *node, struct amdgpu_vm *vm,
 		mapping_flags |= AMDGPU_VM_PAGE_EXECUTABLE;
 
 	pte_flags = AMDGPU_PTE_VALID;
-	/* SPM-backed VRAM is accessed through the system memory path and
-	 * requires the SYSTEM bit.
-	 */
-	if (amdgpu_virt_vram_is_spm(node->adev))
-		pte_flags |= AMDGPU_PTE_SYSTEM;
-	else
-		pte_flags |= (domain == SVM_RANGE_VRAM_DOMAIN) ? 0 : AMDGPU_PTE_SYSTEM;
+	pte_flags |= (domain == SVM_RANGE_VRAM_DOMAIN) ? 0 : AMDGPU_PTE_SYSTEM;
 	pte_flags |= snoop ? AMDGPU_PTE_SNOOPED : 0;
 	if (gc_ip_version >= IP_VERSION(12, 0, 0))
 		pte_flags |= AMDGPU_PTE_IS_PTE;
Signature · 1 line
2.43.0
#2 lore raw

PATCH 3/4 drm/amdgpu: set the A+A VF SYSTEM bit in the GFX 12.1 helpers

In reply to Zhigang Luo

gmc_v12_1_get_vm_pde() converts a VRAM MC address to a physical address and skips that conversion when AMDGPU_PTE_SYSTEM is already set. Set the bit after the translation so the address stays physical.

PDB0 is filled through amdgpu_gmc_get_vm_pde() so those entries take the same path. The VRAM entries are PDE_PTEs and already hold a physical address, so the translation is skipped. The GART PDE is given the GART BO's MC address and translated once.

gmc_v12_1_get_vm_pte() sets the bit only for VRAM. SVM VRAM ranges call it with a NULL buffer object and leave the bit clear. NPA mappings are left unchanged.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 22 ++++++++++++++++------
 drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c  | 12 +++++++++++-
 2 files changed, 27 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +16 -6
index 659e89e5e78f..04cf02dd22ac 100644
@@ -1272,7 +1272,7 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
 	u64 vram_size = adev->gmc.xgmi.node_segment_size * adev->gmc.xgmi.num_physical_nodes;
 	u64 pde0_page_size = (1ULL<<adev->gmc.vmid0_page_table_block_size)<<21;
 	u64 vram_addr, vram_end;
-	u64 gart_ptb_gpu_pa = amdgpu_gmc_vram_pa(adev, adev->gart.bo);
+	u64 pde_addr, pde_flags;
 	int idx;
 
 	if (!drm_dev_enter(adev_to_drm(adev), &idx))
@@ -1290,10 +1290,16 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
 	vram_end = vram_addr + vram_size;
 
 	/* The first n PDE0 entries are used as PTE,
-	 * pointing to vram
+	 * pointing to vram. PDE_PTE already holds a physical address, so
+	 * get_vm_pde() skips translation and sets S for SPM.
 	 */
-	for (i = 0; vram_addr < vram_end; i++, vram_addr += pde0_page_size)
-		amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, vram_addr, flags);
+	for (i = 0; vram_addr < vram_end; i++, vram_addr += pde0_page_size) {
+		pde_addr = vram_addr;
+		pde_flags = flags;
+		amdgpu_gmc_get_vm_pde(adev, AMDGPU_VM_PDB0, &pde_addr, &pde_flags);
+		amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, pde_addr,
+				       pde_flags);
+	}
 
 	/* The n+1'th PDE0 entry points to a huge
 	 * PTB who has more than 512 entries each
@@ -1301,8 +1307,12 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
 	 */
 	flags = AMDGPU_PTE_VALID;
 	flags |= AMDGPU_PTE_SNOOPED | AMDGPU_PDE_BFS_FLAG(adev, 0);
-	/* Requires gart_ptb_gpu_pa to be 4K aligned */
-	amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, gart_ptb_gpu_pa, flags);
+	/* MC address. get_vm_pde() translates it once and sets S for SPM.
+	 * Requires the GART PT to be 4K aligned.
+	 */
+	pde_addr = amdgpu_bo_gpu_offset(adev->gart.bo);
+	amdgpu_gmc_get_vm_pde(adev, AMDGPU_VM_PDB0, &pde_addr, &flags);
+	amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, pde_addr, flags);
 	drm_dev_exit(idx);
 }
 
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +11 -1
index 76391fca6c62..0fbf4525947a 100644
@@ -586,6 +586,12 @@ static void gmc_v12_1_get_vm_pde(struct amdgpu_device *adev, int level,
 		*addr = adev->vm_manager.vram_base_offset + *addr -
 			adev->gmc.vram_start;
 
+	/* SPM VRAM is reached at a system physical address. Set S after the
+	 * translation above so that translation is not skipped.
+	 */
+	if (amdgpu_virt_vram_is_spm(adev))
+		*flags |= AMDGPU_PTE_SYSTEM;
+
 	if (*addr & ~adev->gmc.pte_addr_mask) {
 		dev_err(adev->dev, "Invalid PDE address: %llx\n", *addr);
 		*addr = 0;
@@ -756,8 +762,12 @@ static void gmc_v12_1_get_vm_pte(struct amdgpu_device *adev,
 		break;
 	}
 
+	mem = bo ? bo->tbo.resource : NULL;
+	if (amdgpu_virt_vram_is_spm(adev) &&
+	    (!mem || mem->mem_type == TTM_PL_VRAM))
+		*flags |= AMDGPU_PTE_SYSTEM;
+
 	if (bo) {
-		mem = bo->tbo.resource;
 		if (mem && mem->mem_type == AMDGPU_PL_NPA) {
 			dev_dbg(adev->dev,
 				"Setting PTE for NPA BO, mem->type: %d, mem->start: %lx, mem->size: %u, cur_flags: %llx\n",
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH 3/4] drm/amdgpu: set the A+A VF SYSTEM bit in the GFX 12.1 helpers

Quoted 39 lines · Zhigang Luo

gmc_v12_1_get_vm_pde() converts a VRAM MC address to a physical address and skips that conversion when AMDGPU_PTE_SYSTEM is already set. Set the bit after the translation so the address stays physical.

PDB0 is filled through amdgpu_gmc_get_vm_pde() so those entries take the same path. The VRAM entries are PDE_PTEs and already hold a physical address, so the translation is skipped. The GART PDE is given the GART BO's MC address and translated once.

gmc_v12_1_get_vm_pte() sets the bit only for VRAM. SVM VRAM ranges call it with a NULL buffer object and leave the bit clear. NPA mappings are left unchanged.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 22 ++++++++++++++++------
 drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c  | 12 +++++++++++-
 2 files changed, 27 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -2
index 659e89e5e78f..04cf02dd22ac 100644
@@ -1272,7 +1272,7 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
 	u64 vram_size = adev->gmc.xgmi.node_segment_size * adev->gmc.xgmi.num_physical_nodes;
 	u64 pde0_page_size = (1ULL<<adev->gmc.vmid0_page_table_block_size)<<21;
 	u64 vram_addr, vram_end;
-	u64 gart_ptb_gpu_pa = amdgpu_gmc_vram_pa(adev, adev->gart.bo);
+	u64 pde_addr, pde_flags;
 	int idx;
 
 	if (!drm_dev_enter(adev_to_drm(adev), &idx))
@@ -1290,10 +1290,16 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
 	vram_end = vram_addr + vram_size;
 
 	/* The first n PDE0 entries are used as PTE,
-	 * pointing to vram
+	 * pointing to vram. PDE_PTE already holds a physical address, so
+	 * get_vm_pde() skips translation and sets S for SPM.

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev) · line 1302

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +7 -2
 	 */
-	for (i = 0; vram_addr < vram_end; i++, vram_addr += pde0_page_size)
-		amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, vram_addr, flags);
+	for (i = 0; vram_addr < vram_end; i++, vram_addr += pde0_page_size) {
+		pde_addr = vram_addr;
+		pde_flags = flags;
+		amdgpu_gmc_get_vm_pde(adev, AMDGPU_VM_PDB0, &pde_addr, &pde_flags);
+		amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, pde_addr,
+				       pde_flags);
+	}

That is still a little bit hacky but certainly better than before.

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
 	/* The n+1'th PDE0 entry points to a huge
 	 * PTB who has more than 512 entries each
@@ -1301,8 +1307,12 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
 	 */

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev) · line 1315

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +6 -2
 	flags = AMDGPU_PTE_VALID;
 	flags |= AMDGPU_PTE_SNOOPED | AMDGPU_PDE_BFS_FLAG(adev, 0);
-	/* Requires gart_ptb_gpu_pa to be 4K aligned */
-	amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, gart_ptb_gpu_pa, flags);
+	/* MC address. get_vm_pde() translates it once and sets S for SPM.
+	 * Requires the GART PT to be 4K aligned.
+	 */
+	pde_addr = amdgpu_bo_gpu_offset(adev->gart.bo);
+	amdgpu_gmc_get_vm_pde(adev, AMDGPU_VM_PDB0, &pde_addr, &flags);
+	amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, pde_addr, flags);

Please move those two changes into a separate patch.

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
 	drm_dev_exit(idx);
 }
 
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +6 -0
index 76391fca6c62..0fbf4525947a 100644
@@ -586,6 +586,12 @@ static void gmc_v12_1_get_vm_pde(struct amdgpu_device *adev, int level,
 		*addr = adev->vm_manager.vram_base_offset + *addr -
 			adev->gmc.vram_start;
 
+	/* SPM VRAM is reached at a system physical address. Set S after the
+	 * translation above so that translation is not skipped.
+	 */
+	if (amdgpu_virt_vram_is_spm(adev))
+		*flags |= AMDGPU_PTE_SYSTEM;
+
 	if (*addr & ~adev->gmc.pte_addr_mask) {
 		dev_err(adev->dev, "Invalid PDE address: %llx\n", *addr);
 		*addr = 0;

drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c static void gmc_v12_1_get_vm_pte(struct amdgpu_device *adev, · line 760

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +5 -1
@@ -756,8 +762,12 @@ static void gmc_v12_1_get_vm_pte(struct amdgpu_device *adev,
 		break;
 	}
 
+	mem = bo ? bo->tbo.resource : NULL;
+	if (amdgpu_virt_vram_is_spm(adev) &&
+	    (!mem || mem->mem_type == TTM_PL_VRAM))
+		*flags |= AMDGPU_PTE_SYSTEM;
+
 	if (bo) {
-		mem = bo->tbo.resource;

Move the check here, this way you don't need to check if there is a BO any more and already have mem.

Apart from those minor comments that looks good to me now.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +0 -0
 		if (mem && mem->mem_type == AMDGPU_PL_NPA) {
 			dev_dbg(adev->dev,
 				"Setting PTE for NPA BO, mem->type: %d, mem->start: %lx, mem->size: %u, cur_flags: %llx\n",
#4 lore raw

RE: [PATCH 3/4] drm/amdgpu: set the A+A VF SYSTEM bit in the GFX 12.1 helpers

AMD General

Hi Christian,

Thanks for the review again. I made these changes in the new revision.

PDB0 moved out. Both PDB0 hunks (the VRAM loop and the GART PDE) are now in their own patch, "drm/amdgpu: fill the A+A VF PDB0 through get_vm_pde". The helper patch only changes the GFX 12.1 get_vm_pde/get_vm_pte helpers.

SYSTEM bit check. I did not move the check above if (bo). Doing that would break SVM. The SVM VRAM path calls amdgpu_gmc_get_vm_pte() with a NULL buffer object, and svm_range_get_pte_flags() in kfd_svm.c only sets AMDGPU_PTE_SYSTEM for system memory. The PTE address for SVM VRAM is the HBM SPA from dma_addr, not a framebuffer address. Without the S bit, the GFX 12.1 walker reads it as a framebuffer address. So the code is:

if (bo) {
        mem = bo->tbo.resource;
        if (amdgpu_virt_vram_is_spm(adev) &&
            mem && mem->mem_type == TTM_PL_VRAM)
                *flags |= AMDGPU_PTE_SYSTEM;
        ...
} else if (amdgpu_virt_vram_is_spm(adev)) {
        /* SVM has no BO. System memory already has S. VRAM does not. */
        *flags |= AMDGPU_PTE_SYSTEM;
}

The if (bo) branch covers ordinary VRAM BOs, and the else covers the SVM NULL-BO case. The commit message now explains this.

Other. The revert of the earlier VRAM SYSTEM-bit commits is in front of the series, and the NPA path is unchanged.

Let me know if you want the else branch handled another way.

Thanks,
Zhigang

Quoted 142 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, November 12, 2026 7:33 AM
To: Luo, Zhigang <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>
Subject: Re: [PATCH 3/4] drm/amdgpu: set the A+A VF SYSTEM bit in the GFX 12.1 helpers

Quoted 9 lines · Zhigang Luo

gmc_v12_1_get_vm_pde() converts a VRAM MC address to a physical address and skips that conversion when AMDGPU_PTE_SYSTEM is already set. Set the bit after the translation so the address stays physical.

PDB0 is filled through amdgpu_gmc_get_vm_pde() so those entries take the same path. The VRAM entries are PDE_PTEs and already hold a physical address, so the translation is skipped. The GART PDE is given the GART BO's MC address and translated once.

Quoted 7 lines

gmc_v12_1_get_vm_pte() sets the bit only for VRAM. SVM VRAM ranges call it with a NULL buffer object and leave the bit clear. NPA mappings are left unchanged.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 22 ++++++++++++++++----

--

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct

Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c | 12 +++++++++++-

 2 files changed, 27 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
index 659e89e5e78f..04cf02dd22ac 100644
@@ -1272,7 +1272,7 @@ void amdgpu_gmc_init_pdb0(struct

amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
    u64 vram_size = adev->gmc.xgmi.node_segment_size * adev-
 gmc.xgmi.num_physical_nodes;
    u64 pde0_page_size = (1ULL<<adev-
 gmc.vmid0_page_table_block_size)<<21;
    u64 vram_addr, vram_end;
-   u64 gart_ptb_gpu_pa = amdgpu_gmc_vram_pa(adev, adev->gart.bo);
+   u64 pde_addr, pde_flags;
    int idx;
    if (!drm_dev_enter(adev_to_drm(adev), &idx)) @@ -1290,10 +1290,16

@@

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)

Quoted 10 lines

void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)

    vram_end = vram_addr + vram_size;

    /* The first n PDE0 entries are used as PTE,
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -3
-    * pointing to vram
+    * pointing to vram. PDE_PTE already holds a physical address, so
+    * get_vm_pde() skips translation and sets S for SPM.
     */
-   for (i = 0; vram_addr < vram_end; i++, vram_addr += pde0_page_size)
-           amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i,

vram_addr, flags);

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4 -0
+   for (i = 0; vram_addr < vram_end; i++, vram_addr += pde0_page_size) {
+           pde_addr = vram_addr;
+           pde_flags = flags;
+           amdgpu_gmc_get_vm_pde(adev, AMDGPU_VM_PDB0,

&pde_addr, &pde_flags);

Quoted 1 line

+ amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i,

pde_addr,

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev) · line 1302

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -0
+                                  pde_flags);
+   }

That is still a little bit hacky but certainly better than before.

Quoted 3 lines

/* The n+1'th PDE0 entry points to a huge
* PTB who has more than 512 entries each @@ -1301,8 +1307,12

@@

Quoted 4 lines

void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)

     */
    flags = AMDGPU_PTE_VALID;
    flags |= AMDGPU_PTE_SNOOPED | AMDGPU_PDE_BFS_FLAG(adev,

0);

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

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -2
-   /* Requires gart_ptb_gpu_pa to be 4K aligned */
-   amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i,

gart_ptb_gpu_pa, flags);

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +5 -0
+   /* MC address. get_vm_pde() translates it once and sets S for SPM.
+    * Requires the GART PT to be 4K aligned.
+    */
+   pde_addr = amdgpu_bo_gpu_offset(adev->gart.bo);
+   amdgpu_gmc_get_vm_pde(adev, AMDGPU_VM_PDB0, &pde_addr,

&flags);

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

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -0
+   amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, pde_addr,
+flags);

Please move those two changes into a separate patch.

drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c static void gmc_v12_1_get_vm_pde(struct

Quoted 9 lines
    drm_dev_exit(idx);

}

drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +0 -0
index 76391fca6c62..0fbf4525947a 100644
@@ -586,6 +586,12 @@ static void gmc_v12_1_get_vm_pde(struct

amdgpu_device *adev, int level,

drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c static void gmc_v12_1_get_vm_pte(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +6 -0
            *addr = adev->vm_manager.vram_base_offset + *addr -
                    adev->gmc.vram_start;
 
+   /* SPM VRAM is reached at a system physical address. Set S after the
+    * translation above so that translation is not skipped.
+    */
+   if (amdgpu_virt_vram_is_spm(adev))
+           *flags |= AMDGPU_PTE_SYSTEM;
+
    if (*addr & ~adev->gmc.pte_addr_mask) {
            dev_err(adev->dev, "Invalid PDE address: %llx\n", *addr);
            *addr = 0;
@@ -756,8 +762,12 @@ static void gmc_v12_1_get_vm_pte(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c static void gmc_v12_1_get_vm_pte(struct amdgpu_device *adev, · line 760

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +5 -1
            break;
    }
 
+   mem = bo ? bo->tbo.resource : NULL;
+   if (amdgpu_virt_vram_is_spm(adev) &&
+       (!mem || mem->mem_type == TTM_PL_VRAM))
+           *flags |= AMDGPU_PTE_SYSTEM;
+
    if (bo) {
-           mem = bo->tbo.resource;

Move the check here, this way you don't need to check if there is a BO any more and already have mem.

Apart from those minor comments that looks good to me now.

Regards,
Christian.

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +0 -0
            if (mem && mem->mem_type == AMDGPU_PL_NPA) {
                    dev_dbg(adev->dev,
                            "Setting PTE for NPA BO, mem->type: %d, mem-

start: %lx,
mem->size: %u, cur_flags: %llx\n",

#5 lore raw

PATCH 4/4 drm/amdgpu: keep the A+A VF VRAM base at the SRAT address

In reply to Zhigang Luo

On the A+A VF the hypervisor reports each VF's VRAM address in the ACPI SRAT table, and that address is stored in aper_base. The XGMI LFB region and segment registers describe the physical GPU, not the VF, so physical_node_id * node_segment_size is not a valid VRAM starting address.

Report the VF as a single XGMI node from mmhub_v4_2_0_get_xgmi_info():
one physical node, node id 0, and a segment covering the SRAT aperture. The existing node offset math then adds nothing, and node_segment_size * num_physical_nodes is the VF's local VRAM, so PDB0 is sized correctly without a special case.

Return aper_base from the GFX 12.1 gfxhub and mmhub get_mc_fb_offset() callbacks, the same way an APU uses the FB offset for aper_base, so vram_base_offset is computed by the common path.

Align GART to 8GB. That alignment is one PDB0 entry when vmid0_page_table_block_size is 12, and it applies to every PDB0 placement.

v2:
- Explain that the SRAT address is already the VF VRAM base and must not be adjusted by the XGMI node segment.

v3:
- Report the VF as XGMI node 0 of 1 instead of special-casing the node offset and the PDB0 size.
- Return the SRAT address from get_mc_fb_offset() instead of special-casing amdgpu_virt_resume().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c   |  6 ++++--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c |  4 ++++
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c    | 13 ++-----------
 drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c | 20 ++++++++++++++++----
 4 files changed, 26 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4 -2
index 04cf02dd22ac..ac2664e1eb8a 100644
@@ -42,6 +42,8 @@
 #include <drm/ttm/ttm_tt.h>
 
 static const u64 four_gb = 0x100000000ULL;
+/* PDB0 block size 12 covers one 8GB entry. */
+static const u64 eight_gb = 0x200000000ULL;
 
 bool amdgpu_gmc_is_pdb0_enabled(struct amdgpu_device *adev)
 {
@@ -261,8 +263,8 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc
 	u64 hive_vram_end = mc->xgmi.node_segment_size * mc->xgmi.num_physical_nodes - 1;
 	mc->vram_start = mc->xgmi.node_segment_size * mc->xgmi.physical_node_id;
 	mc->vram_end = mc->vram_start + mc->xgmi.node_segment_size - 1;
-	/* node_segment_size may not 4GB aligned on SRIOV, align up is needed. */
-	mc->gart_start = ALIGN(hive_vram_end + 1, four_gb);
+	/* Round up to a PDB0 entry so GART starts on the page-table PDE. */
+	mc->gart_start = ALIGN(hive_vram_end + 1, eight_gb);
 	mc->gart_end = mc->gart_start + mc->gart_size - 1;
 	if (amdgpu_virt_xgmi_migrate_enabled(adev)) {
 		/* set mc->vram_start to 0 to switch the returned GPU address of
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +4 -0
index b13967a1c8fb..13e29752e435 100644
@@ -53,6 +53,10 @@ static u64 gfxhub_v12_1_get_fb_location(struct amdgpu_device *adev)
 
 static u64 gfxhub_v12_1_get_mc_fb_offset(struct amdgpu_device *adev)
 {
+	/* SPM VRAM starts at the system physical address from SRAT. */
+	if (amdgpu_virt_vram_is_spm(adev))
+		return adev->gmc.aper_base;
+
 	return (u64)(RREG32_SOC15(GC, GET_INST(GC, 0),
 				  regGCMC_VM_FB_OFFSET) << 24);
 }
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +2 -11
index cd276a138e10..1c7f3f0496cc 100644
@@ -720,19 +720,10 @@ static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev,
 			amdgpu_gmc_agp_location(adev, mc);
 	}
 	/* base offset of vram pages */
-	if (amdgpu_virt_vram_is_spm(adev)) {
-		/*
-		 * For SPM-backed VRAM, PDB0 entries use PTE_SYSTEM, so the
-		 * address is a system physical address. vram_base_offset must
-		 * be aper_base so PDB0 maps GPU address 0 onto the HBM system
-		 * physical address.
-		 */
-		adev->vm_manager.vram_base_offset = adev->gmc.aper_base;
-	} else if (amdgpu_sriov_vf(adev)) {
+	if (amdgpu_sriov_vf(adev) && !amdgpu_virt_vram_is_spm(adev))
 		adev->vm_manager.vram_base_offset = 0;
-	} else {
+	else
 		adev->vm_manager.vram_base_offset = adev->mmhub.funcs->get_mc_fb_offset(adev);
-	}
 
 	adev->vm_manager.vram_base_offset +=
 		adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size;
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +16 -4
index 4c0a2d671cfc..409d57a9045e 100644
@@ -132,6 +132,17 @@ static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev)
 	if (!adev->gmc.xgmi.connected_to_cpu)
 		return 0;
 
+	/* The SRAT entry is the VF's whole VRAM. PF_LFB_REGION and the LFB
+	 * segment describe the physical GPU, not the VF, so report a single
+	 * node covering the SRAT aperture.
+	 */
+	if (amdgpu_virt_vram_is_spm(adev)) {
+		adev->gmc.xgmi.num_physical_nodes = 1;
+		adev->gmc.xgmi.physical_node_id = 0;
+		adev->gmc.xgmi.node_segment_size = adev->gmc.aper_size;
+		return 0;
+	}
+
 	xgmi_lfb_cntl = RREG32_SOC15(MMHUB, GET_INST(MMHUB, 0),
 				     regMMMC_VM_XGMI_LFB_CNTL);
 	seg_size = REG_GET_FIELD(
@@ -154,10 +165,7 @@ static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev)
 	if (adev->gmc.xgmi.physical_node_id > max_physical_node_id)
 		return -EINVAL;
 
-	if (amdgpu_virt_vram_is_spm(adev) && adev->gmc.aper_size)
-		adev->gmc.xgmi.node_segment_size = adev->gmc.aper_size;
-	else
-		adev->gmc.xgmi.node_segment_size = seg_size;
+	adev->gmc.xgmi.node_segment_size = seg_size;
 
 	return 0;
 }
@@ -180,6 +188,10 @@ static u64 mmhub_v4_2_0_get_fb_location(struct amdgpu_device *adev)
 
 static u64 mmhub_v4_2_0_get_mc_fb_offset(struct amdgpu_device *adev)
 {
+	/* SPM VRAM starts at the system physical address from SRAT. */
+	if (amdgpu_virt_vram_is_spm(adev))
+		return adev->gmc.aper_base;
+
 	return (u64)RREG32_SOC15(MMHUB, GET_INST(MMHUB, 0),
 			         regMMMC_VM_FB_OFFSET) << 24;
 }
Signature · 1 line
2.43.0
maintainer
#6 lore raw

Re: [PATCH 4/4] drm/amdgpu: keep the A+A VF VRAM base at the SRAT address

Quoted 43 lines · Zhigang Luo

On the A+A VF the hypervisor reports each VF's VRAM address in the ACPI SRAT table, and that address is stored in aper_base. The XGMI LFB region and segment registers describe the physical GPU, not the VF, so physical_node_id * node_segment_size is not a valid VRAM starting address.

Report the VF as a single XGMI node from mmhub_v4_2_0_get_xgmi_info():
one physical node, node id 0, and a segment covering the SRAT aperture. The existing node offset math then adds nothing, and node_segment_size * num_physical_nodes is the VF's local VRAM, so PDB0 is sized correctly without a special case.

Return aper_base from the GFX 12.1 gfxhub and mmhub get_mc_fb_offset() callbacks, the same way an APU uses the FB offset for aper_base, so vram_base_offset is computed by the common path.

Align GART to 8GB. That alignment is one PDB0 entry when vmid0_page_table_block_size is 12, and it applies to every PDB0 placement.

v2:
- Explain that the SRAT address is already the VF VRAM base and must not be adjusted by the XGMI node segment.

v3:
- Report the VF as XGMI node 0 of 1 instead of special-casing the node offset and the PDB0 size.
- Return the SRAT address from get_mc_fb_offset() instead of special-casing amdgpu_virt_resume().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c   |  6 ++++--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c |  4 ++++
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c    | 13 ++-----------
 drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c | 20 ++++++++++++++++----
 4 files changed, 26 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
index 04cf02dd22ac..ac2664e1eb8a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c line 45

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -0
@@ -42,6 +42,8 @@
 #include <drm/ttm/ttm_tt.h>
 
 static const u64 four_gb = 0x100000000ULL;
+/* PDB0 block size 12 covers one 8GB entry. */

That comment doesn't belong here.

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c line 46

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -0
+static const u64 eight_gb = 0x200000000ULL;

Linux already had SZ_8G and SZ_4G as defines, so those here are actually completely superflous.

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc · line 267

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -2
 bool amdgpu_gmc_is_pdb0_enabled(struct amdgpu_device *adev)
 {
@@ -261,8 +263,8 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc
 	u64 hive_vram_end = mc->xgmi.node_segment_size * mc->xgmi.num_physical_nodes - 1;
 	mc->vram_start = mc->xgmi.node_segment_size * mc->xgmi.physical_node_id;
 	mc->vram_end = mc->vram_start + mc->xgmi.node_segment_size - 1;
-	/* node_segment_size may not 4GB aligned on SRIOV, align up is needed. */
-	mc->gart_start = ALIGN(hive_vram_end + 1, four_gb);
+	/* Round up to a PDB0 entry so GART starts on the page-table PDE. */
+	mc->gart_start = ALIGN(hive_vram_end + 1, eight_gb);

Good catch, but that needs to be a separate patch and should most likely be backported as well.

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
 	mc->gart_end = mc->gart_start + mc->gart_size - 1;
 	if (amdgpu_virt_xgmi_migrate_enabled(adev)) {
 		/* set mc->vram_start to 0 to switch the returned GPU address of
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +0 -0
index b13967a1c8fb..13e29752e435 100644

drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c static u64 gfxhub_v12_1_get_fb_location(struct amdgpu_device *adev) · line 58

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +3 -0
@@ -53,6 +53,10 @@ static u64 gfxhub_v12_1_get_fb_location(struct amdgpu_device *adev)
 
 static u64 gfxhub_v12_1_get_mc_fb_offset(struct amdgpu_device *adev)
 {
+	/* SPM VRAM starts at the system physical address from SRAT. */
+	if (amdgpu_virt_vram_is_spm(adev))
+		return adev->gmc.aper_base;

This is still upside down. Don't use aper_base for the fb_offset, instead use it the other way around

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +1 -0
+
 	return (u64)(RREG32_SOC15(GC, GET_INST(GC, 0),
 				  regGCMC_VM_FB_OFFSET) << 24);
 }
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
index cd276a138e10..1c7f3f0496cc 100644
@@ -720,19 +720,10 @@ static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev,
 			amdgpu_gmc_agp_location(adev, mc);

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev, · line 730

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -8
 	}
 	/* base offset of vram pages */
-	if (amdgpu_virt_vram_is_spm(adev)) {
-		/*
-		 * For SPM-backed VRAM, PDB0 entries use PTE_SYSTEM, so the
-		 * address is a system physical address. vram_base_offset must
-		 * be aper_base so PDB0 maps GPU address 0 onto the HBM system
-		 * physical address.
-		 */
-		adev->vm_manager.vram_base_offset = adev->gmc.aper_base;

That stuff should have been reverted.

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +2 -3
-	} else if (amdgpu_sriov_vf(adev)) {
+	if (amdgpu_sriov_vf(adev) && !amdgpu_virt_vram_is_spm(adev))
 		adev->vm_manager.vram_base_offset = 0;
-	} else {
+	else
 		adev->vm_manager.vram_base_offset = adev->mmhub.funcs->get_mc_fb_offset(adev);
-	}
 
 	adev->vm_manager.vram_base_offset +=
 		adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size;
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +0 -0
index 4c0a2d671cfc..409d57a9045e 100644
@@ -132,6 +132,17 @@ static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev)
 	if (!adev->gmc.xgmi.connected_to_cpu)

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev) · line 142

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +8 -0
 		return 0;
 
+	/* The SRAT entry is the VF's whole VRAM. PF_LFB_REGION and the LFB
+	 * segment describe the physical GPU, not the VF, so report a single
+	 * node covering the SRAT aperture.
+	 */
+	if (amdgpu_virt_vram_is_spm(adev)) {
+		adev->gmc.xgmi.num_physical_nodes = 1;
+		adev->gmc.xgmi.physical_node_id = 0;
+		adev->gmc.xgmi.node_segment_size = adev->gmc.aper_size;

Again, don't use aper_size here.

What you can do is to initialize aper_base and aper_size from fb_offset/size but not the other way around.

Apart from that having one XGMI node which covers everything sounds like a good idea to me.

We just need to document the multi use on the XGMI member decleration.

Regards,
Christian.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +3 -0
+		return 0;
+	}
+
 	xgmi_lfb_cntl = RREG32_SOC15(MMHUB, GET_INST(MMHUB, 0),
 				     regMMMC_VM_XGMI_LFB_CNTL);
 	seg_size = REG_GET_FIELD(

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev) · line 160

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +0 -4
@@ -154,10 +165,7 @@ static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev)
 	if (adev->gmc.xgmi.physical_node_id > max_physical_node_id)
 		return -EINVAL;
 
-	if (amdgpu_virt_vram_is_spm(adev) && adev->gmc.aper_size)
-		adev->gmc.xgmi.node_segment_size = adev->gmc.aper_size;
-	else
-		adev->gmc.xgmi.node_segment_size = seg_size;

That should also be reverted before this patch set.

Regards,
Christian.

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +5 -0
+	adev->gmc.xgmi.node_segment_size = seg_size;
 
 	return 0;
 }
@@ -180,6 +188,10 @@ static u64 mmhub_v4_2_0_get_fb_location(struct amdgpu_device *adev)
 
 static u64 mmhub_v4_2_0_get_mc_fb_offset(struct amdgpu_device *adev)
 {
+	/* SPM VRAM starts at the system physical address from SRAT. */
+	if (amdgpu_virt_vram_is_spm(adev))
+		return adev->gmc.aper_base;
+
 	return (u64)RREG32_SOC15(MMHUB, GET_INST(MMHUB, 0),
 			         regMMMC_VM_FB_OFFSET) << 24;
 }
#7 lore raw

RE: [PATCH 4/4] drm/amdgpu: keep the A+A VF VRAM base at the SRAT address

AMD General

Hi Christian,

Thanks for the review again. I split the patch and addressed each point.

Split into three commits:

Revert "drm/amdgpu: take the A+A VF GMC aperture from SRAT". This removes the early_init SRAT read, the vram_base_offset = aper_base copy, the node_segment_size = aper_size ternary, and the !spm guard in mc_init. You were right that those copies were upside down, and they came in with ea7147d613a0. After this revert, mc_init is back to the connected_to_cpu path.

drm/amdgpu: align the sysvm GART start to 8GB. This is separate so it can be backported. four_gb and eight_gb are gone. The code uses SZ_4G and SZ_8G, and the PDB0-entry comment sits at the ALIGN() call, not beside a constant. The commit does not mention SPM.

drm/amdgpu: keep the A+A VF VRAM base at the SRAT address. The SRAT read moved into mmhub_v4_2_0_get_xgmi_info(). For an SPM VF it reports one node at id 0, and the segment is the SRAT length, not aper_size. The SRAT address is saved in a new adev->gmc.fb_offset. get_mc_fb_offset() in mmhub and gfxhub returns that address for SPM. aper_base and aper_size are filled from the FB offset and the segment size in mc_init, not written from SRAT.

Other points:

The one-node XGMI model stays, and the XGMI member comments now say that on an SPM VF the segment is the SRAT length and the node is id 0. The mc_init aperture block has no SPM special case. The SPM VF goes through the same offset-plus-node path as native A+A.

Thanks,
Zhigang

Quoted 220 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, November 12, 2026 7:46 AM
To: Luo, Zhigang <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>
Subject: Re: [PATCH 4/4] drm/amdgpu: keep the A+A VF VRAM base at the SRAT address

Quoted 30 lines · Zhigang Luo

On the A+A VF the hypervisor reports each VF's VRAM address in the ACPI SRAT table, and that address is stored in aper_base. The XGMI LFB region and segment registers describe the physical GPU, not the VF, so physical_node_id * node_segment_size is not a valid VRAM starting address.

Report the VF as a single XGMI node from mmhub_v4_2_0_get_xgmi_info():
one physical node, node id 0, and a segment covering the SRAT aperture. The existing node offset math then adds nothing, and node_segment_size * num_physical_nodes is the VF's local VRAM, so PDB0 is sized correctly without a special case.

Return aper_base from the GFX 12.1 gfxhub and mmhub get_mc_fb_offset() callbacks, the same way an APU uses the FB offset for aper_base, so vram_base_offset is computed by the common path.

Align GART to 8GB. That alignment is one PDB0 entry when vmid0_page_table_block_size is 12, and it applies to every PDB0 placement.

v2:
- Explain that the SRAT address is already the VF VRAM base and must not be adjusted by the XGMI node segment.

v3:
- Report the VF as XGMI node 0 of 1 instead of special-casing the node offset and the PDB0 size.
- Return the SRAT address from get_mc_fb_offset() instead of special-casing amdgpu_virt_resume().

Quoted 6 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c   |  6 ++++--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c |  4 ++++
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c    | 13 ++-----------
 drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c | 20 ++++++++++++++++-

---

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c line 45

Quoted 12 lines
 4 files changed, 26 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -0
index 04cf02dd22ac..ac2664e1eb8a 100644
@@ -42,6 +42,8 @@
 #include <drm/ttm/ttm_tt.h>
 
 static const u64 four_gb = 0x100000000ULL;
+/* PDB0 block size 12 covers one 8GB entry. */

That comment doesn't belong here.

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c line 46

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -0
+static const u64 eight_gb = 0x200000000ULL;

Linux already had SZ_8G and SZ_4G as defines, so those here are actually completely superflous.

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c line 46

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -1
 bool amdgpu_gmc_is_pdb0_enabled(struct amdgpu_device *adev)  { @@
-261,8 +263,8 @@ void amdgpu_gmc_sysvm_location(struct

amdgpu_device *adev, struct amdgpu_gmc *mc

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
    u64 hive_vram_end = mc->xgmi.node_segment_size * mc-
xgmi.num_physical_nodes - 1;
    mc->vram_start = mc->xgmi.node_segment_size * mc-
xgmi.physical_node_id;
    mc->vram_end = mc->vram_start + mc->xgmi.node_segment_size -

1;

Quoted 1 line

- /* node_segment_size may not 4GB aligned on SRIOV, align up is

needed. */

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc · line 267

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -1
-   mc->gart_start = ALIGN(hive_vram_end + 1, four_gb);
+   /* Round up to a PDB0 entry so GART starts on the page-table PDE. */
+   mc->gart_start = ALIGN(hive_vram_end + 1, eight_gb);

Good catch, but that needs to be a separate patch and should most likely be backported as well.

Quoted 3 lines
    mc->gart_end = mc->gart_start + mc->gart_size - 1;
    if (amdgpu_virt_xgmi_migrate_enabled(adev)) {
            /* set mc->vram_start to 0 to switch the returned GPU address

of

drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c static u64 gfxhub_v12_1_get_fb_location(struct · line 59

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +3 -0
index b13967a1c8fb..13e29752e435 100644
@@ -53,6 +53,10 @@ static u64 gfxhub_v12_1_get_fb_location(struct
 amdgpu_device *adev)
 
 static u64 gfxhub_v12_1_get_mc_fb_offset(struct amdgpu_device *adev)
 {
+   /* SPM VRAM starts at the system physical address from SRAT. */
+   if (amdgpu_virt_vram_is_spm(adev))
+           return adev->gmc.aper_base;

This is still upside down. Don't use aper_base for the fb_offset, instead use it the other way around

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_vram_gtt_location(struct

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +1 -0
+
    return (u64)(RREG32_SOC15(GC, GET_INST(GC, 0),
                              regGCMC_VM_FB_OFFSET) << 24);

}

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
index cd276a138e10..1c7f3f0496cc 100644
@@ -720,19 +720,10 @@ static void gmc_v12_0_vram_gtt_location(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -3
                    amdgpu_gmc_agp_location(adev, mc);
    }
    /* base offset of vram pages */
-   if (amdgpu_virt_vram_is_spm(adev)) {
-           /*
-            * For SPM-backed VRAM, PDB0 entries use PTE_SYSTEM, so

the

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_vram_gtt_location(struct · line 726

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -1
-            * address is a system physical address. vram_base_offset

must

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_vram_gtt_location(struct · line 727

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -1
-            * be aper_base so PDB0 maps GPU address 0 onto the HBM

system

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -3
-            * physical address.
-            */
-           adev->vm_manager.vram_base_offset = adev-
 gmc.aper_base;

That stuff should have been reverted.

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c static int mmhub_v4_2_0_get_xgmi_info(struct

Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +2 -3
-   } else if (amdgpu_sriov_vf(adev)) {
+   if (amdgpu_sriov_vf(adev) && !amdgpu_virt_vram_is_spm(adev))
            adev->vm_manager.vram_base_offset = 0;
-   } else {
+   else
            adev->vm_manager.vram_base_offset = adev->mmhub.funcs-
 get_mc_fb_offset(adev);
-   }
 
    adev->vm_manager.vram_base_offset +=
            adev->gmc.xgmi.physical_node_id * adev-

gmc.xgmi.node_segment_size;

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +0 -0
index 4c0a2d671cfc..409d57a9045e 100644
@@ -132,6 +132,17 @@ static int mmhub_v4_2_0_get_xgmi_info(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +1 -0
    if (!adev->gmc.xgmi.connected_to_cpu)
            return 0;
 
+   /* The SRAT entry is the VF's whole VRAM. PF_LFB_REGION and the

LFB

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev) · line 142

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +7 -0
+    * segment describe the physical GPU, not the VF, so report a single
+    * node covering the SRAT aperture.
+    */
+   if (amdgpu_virt_vram_is_spm(adev)) {
+           adev->gmc.xgmi.num_physical_nodes = 1;
+           adev->gmc.xgmi.physical_node_id = 0;
+           adev->gmc.xgmi.node_segment_size = adev->gmc.aper_size;

Again, don't use aper_size here.

What you can do is to initialize aper_base and aper_size from fb_offset/size but not the other way around.

Apart from that having one XGMI node which covers everything sounds like a good idea to me.

We just need to document the multi use on the XGMI member decleration.

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c static int mmhub_v4_2_0_get_xgmi_info(struct

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +3 -0
+           return 0;
+   }
+
    xgmi_lfb_cntl = RREG32_SOC15(MMHUB, GET_INST(MMHUB, 0),
                                 regMMMC_VM_XGMI_LFB_CNTL);
    seg_size = REG_GET_FIELD(
@@ -154,10 +165,7 @@ static int mmhub_v4_2_0_get_xgmi_info(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev) · line 160

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +0 -4
    if (adev->gmc.xgmi.physical_node_id > max_physical_node_id)
            return -EINVAL;
 
-   if (amdgpu_virt_vram_is_spm(adev) && adev->gmc.aper_size)
-           adev->gmc.xgmi.node_segment_size = adev->gmc.aper_size;
-   else
-           adev->gmc.xgmi.node_segment_size = seg_size;

That should also be reverted before this patch set.

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c static u64 mmhub_v4_2_0_get_fb_location(struct · line 190

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +1 -0
+   adev->gmc.xgmi.node_segment_size = seg_size;
 
    return 0;
 }
@@ -180,6 +188,10 @@ static u64 mmhub_v4_2_0_get_fb_location(struct
 amdgpu_device *adev)
 
 static u64 mmhub_v4_2_0_get_mc_fb_offset(struct amdgpu_device

*adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +4 -0
 {
+   /* SPM VRAM starts at the system physical address from SRAT. */
+   if (amdgpu_virt_vram_is_spm(adev))
+           return adev->gmc.aper_base;
+
    return (u64)RREG32_SOC15(MMHUB, GET_INST(MMHUB, 0),
                             regMMMC_VM_FB_OFFSET) << 24;  }