drm/amdgpu: keep SPM VF VRAM at GPU address 0
Subsystems (2)
PATCH 1/1 drm/amdgpu: keep SPM VF VRAM at GPU address 0
- bug 'amdgpu_virt_resume': resume added the xGMI node segment on top of the MMHUB FB offset for SPM VRAM; use aper_base and skip the node offset
- bug 'gmc_v12_0_vram_gtt_location': the initial load path added the same node segment after aper_base; skip it when VRAM is SPM
- bug 'amdgpu_gmc_sysvm_location': SPM used the hive window and a 4GB GART alignment; zero the VRAM GPU window and place GART after local VRAM on an 8GB PDB0 boundary
- bug 'amdgpu_gmc_pdb0_alloc': PDB0 covered the hive; size SPM coverage from mc_vram_size
- bug 'amdgpu_gmc_init_pdb0': SPM subtracted the node segment from aper_base; keep the system physical base
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 22 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 6 ++++-- 3 files changed, 29 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -3
@@ -4677,9 +4677,15 @@ static inline int amdgpu_virt_resume(struct amdgpu_device *adev)dev_info (adev->dev,"xgmi node, old id %d, new id %d\n" , prev_physical_node_id, adev->gmc.xgmi.physical_node_id); - adev->vm_manager.vram_base_offset = adev->gfxhub.funcs->get_mc_fb_offset (adev); - adev->vm_manager.vram_base_offset += - adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size; +if (amdgpu_virt_vram_is_spm (adev)) { + adev->vm_manager.vram_base_offset = adev->gmc.aper_base; + }else { + adev->vm_manager.vram_base_offset = + adev->gfxhub.funcs->get_mc_fb_offset (adev); + adev->vm_manager.vram_base_offset += + adev->gmc.xgmi.physical_node_id * + adev->gmc.xgmi.node_segment_size; + }return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +16 -6
@@ -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) {
@@ -60,7 +62,8 @@ int amdgpu_gmc_pdb0_alloc(struct amdgpu_device *adev) {int r;struct amdgpu_bo_param bp; -u64 vram_size = adev->gmc.xgmi.node_segment_size * adev->gmc.xgmi.num_physical_nodes; +u64 vram_size =amdgpu_virt_vram_is_spm (adev) ? adev->gmc.mc_vram_size : + adev->gmc.xgmi.node_segment_size * adev->gmc.xgmi.num_physical_nodes;uint32_t pde0_page_shift = adev->gmc.vmid0_page_table_block_size +21 ;uint32_t npdes = (vram_size + (1ULL << pde0_page_shift) -1 ) >> pde0_page_shift;
@@ -266,16 +269,21 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mcu64 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)) { +if (amdgpu_virt_xgmi_migrate_enabled (adev) || +amdgpu_virt_vram_is_spm (adev)) {/* set mc->vram_start to 0 to switch the returned GPU address of * amdgpu_bo_create_reserved() from FB aperture to GART aperture. */ mc->vram_start =0 ; mc->vram_end = mc->vram_start + mc->mc_vram_size -1 ; mc->visible_vram_size =min (mc->visible_vram_size, mc->real_vram_size); +if (amdgpu_virt_vram_is_spm (adev)) { + mc->gart_start =ALIGN (mc->vram_end +1 , eight_gb); + mc->gart_end = mc->gart_start + mc->gart_size -1 ; + } }else { mc->fb_start = hive_vram_start; mc->fb_end = hive_vram_end;
@@ -1274,7 +1282,8 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)uint64_t flags = adev->gart.gart_pte_flags;//TODO it is UC. explore NC/RW? /* Each PDE0 (used as PTE) covers (2^vmid0_page_table_block_size)*2M */ -u64 vram_size = adev->gmc.xgmi.node_segment_size * adev->gmc.xgmi.num_physical_nodes; +u64 vram_size =amdgpu_virt_vram_is_spm (adev) ? adev->gmc.mc_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);
@@ -1292,7 +1301,8 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev) flags |=AMDGPU_PDE_PTE_FLAG (adev); vram_addr = adev->vm_manager.vram_base_offset; -if (!amdgpu_virt_xgmi_migrate_enabled (adev)) +if (!amdgpu_virt_xgmi_migrate_enabled (adev) && + !amdgpu_virt_vram_is_spm (adev)) vram_addr -= adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size; vram_end = vram_addr + vram_size;
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +4 -2
@@ -734,8 +734,10 @@ static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev, 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; +if (!amdgpu_virt_vram_is_spm (adev)) + adev->vm_manager.vram_base_offset += + adev->gmc.xgmi.physical_node_id * + adev->gmc.xgmi.node_segment_size; }/**
Signature · 1 line
2.43.0
Christian König
maintainerQuoted 4 lines · Zhigang Luo
- bug '
amdgpu_virt_resume': resume added the xGMI node segment on top of the MMHUB FB offset for SPM VRAM; useaper_baseand skip the node offset
- bug 'gmc_v12_0_vram_gtt_location': the initial load path added the
Quoted 8 lines
same node segment after
aper_base; skip it when VRAM is SPM
- bug 'amdgpu_gmc_sysvm_location': SPM used the hive window and a 4GB GART alignment; zero the VRAM GPU window and place GART after local VRAM on an 8GB PDB0 boundary
- bug 'amdgpu_gmc_pdb0_alloc': PDB0 covered the hive; size SPM coverage frommc_vram_size
- bug 'amdgpu_gmc_init_pdb0': SPM subtracted the node segment fromaper_base; keep the system physical base
First of all please write a proper commit message. That here is clearly inacceptable.
Quoted 13 lines
Signed-off-by Zhigang Luo <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 22 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 6 ++++-- 3 files changed, 29 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static inline int amdgpu_virt_resume(struct amdgpu_device *adev) · line 4681
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-3@@ -4677,9 +4677,15 @@ static inline int amdgpu_virt_resume(struct amdgpu_device *adev)dev_info (adev->dev,"xgmi node, old id %d, new id %d\n" , prev_physical_node_id, adev->gmc.xgmi.physical_node_id); - adev->vm_manager.vram_base_offset = adev->gfxhub.funcs->get_mc_fb_offset (adev); - adev->vm_manager.vram_base_offset += - adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size; +if (amdgpu_virt_vram_is_spm (adev)) { + adev->vm_manager.vram_base_offset = adev->gmc.aper_base;
Well that is totally nonsense as far as I can see.
The vram_base_offset and the PCI aperture are two completely different things.
Please explain what you try to do here?
Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0+ }else { + adev->vm_manager.vram_base_offset = + adev->gfxhub.funcs->get_mc_fb_offset (adev); + adev->vm_manager.vram_base_offset += + adev->gmc.xgmi.physical_node_id * + adev->gmc.xgmi.node_segment_size; + }return 0 ; }drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-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. */ +static const u64 eight_gb =0x200000000ULL ;bool amdgpu_gmc_is_pdb0_enabled (struct amdgpu_device *adev) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_pdb0_alloc(struct amdgpu_device *adev) · line 66
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-1@@ -60,7 +62,8 @@ int amdgpu_gmc_pdb0_alloc(struct amdgpu_device *adev) {int r;struct amdgpu_bo_param bp; -u64 vram_size = adev->gmc.xgmi.node_segment_size * adev->gmc.xgmi.num_physical_nodes; +u64 vram_size =amdgpu_virt_vram_is_spm (adev) ? adev->gmc.mc_vram_size : + adev->gmc.xgmi.node_segment_size * adev->gmc.xgmi.num_physical_nodes;
Clear NAK from my side for such hacks.
Please describe the requirements and proper integarte that into the handling.
Regards,
Christian.
Quoted 65 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +12
-5uint32_t pde0_page_shift = adev->gmc.vmid0_page_table_block_size +21 ;uint32_t npdes = (vram_size + (1ULL << pde0_page_shift) -1 ) >> pde0_page_shift;@@ -266,16 +269,21 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mcu64 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)) { +if (amdgpu_virt_xgmi_migrate_enabled (adev) || +amdgpu_virt_vram_is_spm (adev)) {/* set mc->vram_start to 0 to switch the returned GPU address of * amdgpu_bo_create_reserved() from FB aperture to GART aperture. */ mc->vram_start =0 ; mc->vram_end = mc->vram_start + mc->mc_vram_size -1 ; mc->visible_vram_size =min (mc->visible_vram_size, mc->real_vram_size); +if (amdgpu_virt_vram_is_spm (adev)) { + mc->gart_start =ALIGN (mc->vram_end +1 , eight_gb); + mc->gart_end = mc->gart_start + mc->gart_size -1 ; + } }else { mc->fb_start = hive_vram_start; mc->fb_end = hive_vram_end;@@ -1274,7 +1282,8 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)uint64_t flags = adev->gart.gart_pte_flags;//TODO it is UC. explore NC/RW? /* Each PDE0 (used as PTE) covers (2^vmid0_page_table_block_size)*2M */ -u64 vram_size = adev->gmc.xgmi.node_segment_size * adev->gmc.xgmi.num_physical_nodes; +u64 vram_size =amdgpu_virt_vram_is_spm (adev) ? adev->gmc.mc_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);@@ -1292,7 +1301,8 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev) flags |=AMDGPU_PDE_PTE_FLAG (adev); vram_addr = adev->vm_manager.vram_base_offset; -if (!amdgpu_virt_xgmi_migrate_enabled (adev)) +if (!amdgpu_virt_xgmi_migrate_enabled (adev) && + !amdgpu_virt_vram_is_spm (adev)) vram_addr -= adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size; vram_end = vram_addr + vram_size;drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +4
-2@@ -734,8 +734,10 @@ static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev, 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; +if (!amdgpu_virt_vram_is_spm (adev)) + adev->vm_manager.vram_base_offset += + adev->gmc.xgmi.physical_node_id * + adev->gmc.xgmi.node_segment_size; }/**
AMD General
Quoted 19 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, November 5, 2026 6:30 AM
To: Luo, Zhigang <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: keep SPM VF VRAM at GPU address 0Quoted 6 lines · Zhigang Luo
- bug '
amdgpu_virt_resume': resume added the xGMI node segment on top of the MMHUB FB offset for SPM VRAM; useaper_baseand skip the node offset
- bug 'gmc_v12_0_vram_gtt_location': the initial load path added the same node segment afteraper_base; skip it when VRAM is SPM
- bug 'amdgpu_gmc_sysvm_location': SPM used the hive window and a4GB
Quoted 3 lines
GART alignment; zero the VRAM GPU window and place GART after local VRAM on an 8GB PDB0 boundary
- bug 'amdgpu_gmc_pdb0_alloc': PDB0 covered the hive; size SPM
Quoted 8 lines
coverage
Quoted 3 lines
from
mc_vram_size
- bug 'amdgpu_gmc_init_pdb0': SPM subtracted the node segment fromaper_base; keep the system physical baseFirst of all please write a proper commit message. That here is clearly inacceptable.
Will rewrite a commit message.
Quoted 30 lines
Quoted 7 lines
Signed-off-by Zhigang Luo <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 22 ++++++++++++++++------
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static inline int amdgpu_virt_resume(struct
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 6 ++++-- 3 files changed, 29 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4677,9 +4677,15 @@ static inline int amdgpu_virt_resume(struct
amdgpu_device*adev)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static inline int amdgpu_virt_resume(struct · line 4684
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-3dev_info (adev->dev,"xgmi node, old id %d, new id %d\n" , prev_physical_node_id, adev->gmc.xgmi.physical_node_id); - adev->vm_manager.vram_base_offset = adev->gfxhub.funcs-get_mc_fb_offset (adev); - adev->vm_manager.vram_base_offset += - adev->gmc.xgmi.physical_node_id * adev- gmc.xgmi.node_segment_size; +if (amdgpu_virt_vram_is_spm (adev)) { + adev->vm_manager.vram_base_offset = adev- gmc.aper_base;
Quoted 6 lines
Well that is totally nonsense as far as I can see.
The
vram_base_offsetand the PCI aperture are two completely different things.Please explain what you try to do here?
For the AMDGPU_VIRT_VRAM_IS_SPM case, the VF has no framebuffer BAR and its VRAM is exposed as SPM. Since there is no PCI BAR address to record, gmc.aper_base is reused to hold the VF VRAM system physical address obtained from the ACPI SRAT table. This is consistent with the existing bare-metal gmc.xgmi.connected_to_cpu case, where aper_base is also not a PCI BAR address; it is populated from get_mc_fb_offset(). In both cases, aper_base represents the system physical base of VRAM rather than a PCI framebuffer aperture.
Quoted 36 lines
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0+ }else { + adev->vm_manager.vram_base_offset = + adev->gfxhub.funcs->get_mc_fb_offset (adev); + adev->vm_manager.vram_base_offset += + adev->gmc.xgmi.physical_node_id * + adev->gmc.xgmi.node_segment_size; + }return 0;}
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c line 47
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-1@@ -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) { @@ -60,7 +62,8 @@ int amdgpu_gmc_pdb0_alloc(struct amdgpu_device*adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
Quoted 9 lines
{ int r; struct amdgpu_bo_param bp;- u64
vram_size=adev->gmc.xgmi.node_segment_size* adev-
gmc.xgmi.num_physical_nodes;
+ u64vram_size=amdgpu_virt_vram_is_spm(adev)? adev-
gmc.mc_vram_size :drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-0+ adev->gmc.xgmi.node_segment_size * +adev->gmc.xgmi.num_physical_nodes;
Quoted 8 lines
Clear NAK from my side for such hacks.
Please describe the requirements and proper integarte that into the handling.
Regards,
Christian.
On AMDGPU_VIRT_VRAM_IS_SPM case, the hypervisor reports each VF's VRAM address in the ACPI SRAT table. So, driver can use the address directly, there is no need to use xgmi.node_segment_size to calculate the VF's VRAM starting address(the xGMI node segment size is not valid for the VF).
Thanks,
Zhigang
Quoted 89 lines
Quoted 1 line
uint32_t pde0_page_shift = adev->gmc.vmid0_page_table_block_size+ 21;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct
Quoted 4 lines
uint32_t npdes = (vram_size + (1ULL << pde0_page_shift) - 1) >>
pde0_page_shift;drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0@@ -266,16 +269,21 @@ void amdgpu_gmc_sysvm_location(struct
amdgpu_device*adev, structamdgpu_gmc*mcdrivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct · line 273
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0u64 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;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct · line 271
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-1-/* 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
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4
-2- 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)) { +if (amdgpu_virt_xgmi_migrate_enabled (adev) || +amdgpu_virt_vram_is_spm (adev)) {/* set mc->vram_start to 0 to switch the returned GPU address of
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct · line 280
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0* amdgpu_bo_create_reserved() from FB aperture to GART aperture.
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4
-0*/ mc->vram_start =0 ; mc->vram_end = mc->vram_start + mc->mc_vram_size -1 ; mc->visible_vram_size =min (mc->visible_vram_size, mc->real_vram_size); +if (amdgpu_virt_vram_is_spm (adev)) { + mc->gart_start =ALIGN (mc->vram_end +1 , eight_gb); + mc->gart_end = mc->gart_start + mc->gart_size -1 ; + }} else { mc->fb_start = hive_vram_start; mc->fb_end = hive_vram_end;drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0@@ -1274,7 +1282,8 @@ void amdgpu_gmc_init_pdb0(struct
amdgpu_device*adev)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct · line 1282
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0uint64_t flags = adev->gart.gart_pte_flags;//TODO it is UC. explore NC/RW?
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct · line 1283
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0/* Each PDE0 (used as PTE) covers (2^vmid0_page_table_block_size)*2M
Quoted 11 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 vram_size = amdgpu_virt_vram_is_spm(adev) ? adev-gmc.mc_vram_size :
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-0+ 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);@@
Quoted 1 line
-1292,7 +1301,8 @@ void amdgpu_gmc_init_pdb0(struct
amdgpu_device*adev)
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_vram_gtt_location(struct
Quoted 16 lines
flags |= AMDGPU_PDE_PTE_FLAG(adev); vram_addr = adev->vm_manager.vram_base_offset;drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-1-if (!amdgpu_virt_xgmi_migrate_enabled (adev)) +if (!amdgpu_virt_xgmi_migrate_enabled (adev) && + !amdgpu_virt_vram_is_spm (adev)) vram_addr -= adev->gmc.xgmi.physical_node_id * adev-gmc.xgmi.node_segment_size; vram_end = vram_addr + vram_size;drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0
-0@@ -734,8 +734,10 @@ static void gmc_v12_0_vram_gtt_location(struct
amdgpu_device*adev,Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +4
-2adev->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; +if (!amdgpu_virt_vram_is_spm (adev)) + adev->vm_manager.vram_base_offset += + adev->gmc.xgmi.physical_node_id * + adev->gmc.xgmi.node_segment_size; }/**
Christian König
maintainerQuoted 62 lines · Zhigang
AMD General
Quoted 19 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, November 5, 2026 6:30 AM
To: Luo, Zhigang <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: keep SPM VF VRAM at GPU address 0Quoted 6 lines · Zhigang Luo
- bug '
amdgpu_virt_resume': resume added the xGMI node segment on top of the MMHUB FB offset for SPM VRAM; useaper_baseand skip the node offset
- bug 'gmc_v12_0_vram_gtt_location': the initial load path added the same node segment afteraper_base; skip it when VRAM is SPM
- bug 'amdgpu_gmc_sysvm_location': SPM used the hive window and a4GB
Quoted 3 lines
GART alignment; zero the VRAM GPU window and place GART after local VRAM on an 8GB PDB0 boundary
- bug 'amdgpu_gmc_pdb0_alloc': PDB0 covered the hive; size SPMQuoted 8 lines
coverage
Quoted 3 lines
from
mc_vram_size
- bug 'amdgpu_gmc_init_pdb0': SPM subtracted the node segment fromaper_base; keep the system physical baseFirst of all please write a proper commit message. That here is clearly inacceptable.
Will rewrite a commit message.
Quoted 30 lines
Quoted 7 lines
Signed-off-by Zhigang Luo <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 22 ++++++++++++++++------
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static inline int amdgpu_virt_resume(struct
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 6 ++++-- 3 files changed, 29 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4677,9 +4677,15 @@ static inline int amdgpu_virt_resume(struct
amdgpu_device*adev)Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-3dev_info (adev->dev,"xgmi node, old id %d, new id %d\n" , prev_physical_node_id, adev->gmc.xgmi.physical_node_id); - adev->vm_manager.vram_base_offset = adev->gfxhub.funcs-get_mc_fb_offset (adev); - adev->vm_manager.vram_base_offset += - adev->gmc.xgmi.physical_node_id * adev- gmc.xgmi.node_segment_size; +if (amdgpu_virt_vram_is_spm (adev)) { + adev->vm_manager.vram_base_offset = adev- gmc.aper_base;
Quoted 8 lines
Quoted 6 lines
Well that is totally nonsense as far as I can see.
The
vram_base_offsetand the PCI aperture are two completely different things.Please explain what you try to do here?
For the
AMDGPU_VIRT_VRAM_IS_SPMcase, the VF has no framebuffer BAR and its VRAM is exposed as SPM.
Yeah that's what I already know about.
Quoted 1 line
Since there is no PCI BAR address to record, gmc.aper_base is reused to hold the VF VRAM system physical address obtained from the ACPI SRAT table.
Clear NAK to that approach, please come up with something clean.
Quoted 1 line
This is consistent with the existing bare-metal gmc.xgmi.connected_to_cpu case, where
aper_baseis also not a PCI BAR address;
No it isn't. Exposing VRAM through SPM/SRAT is something completely different.
Quoted 1 line
it is populated from
get_mc_fb_offset(). In both cases,aper_baserepresents the system physical base of VRAM rather than a PCI framebuffer aperture.
No, that is completely nonsense! aper_base is configuring the CPU access path for the io remap.
It is true that on APUs and when we have an XGMI connection to the CPU it points directly to the local memory associated with the device, but abusing that for the vram_base_offset calculation is an absolutely clear NAK from my side.
Quoted 38 lines
Quoted 38 lines
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0+ }else { + adev->vm_manager.vram_base_offset = + adev->gfxhub.funcs->get_mc_fb_offset (adev); + adev->vm_manager.vram_base_offset += + adev->gmc.xgmi.physical_node_id * + adev->gmc.xgmi.node_segment_size; + }return 0;}
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c line 47
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-1@@ -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) { @@ -60,7 +62,8 @@ int amdgpu_gmc_pdb0_alloc(struct amdgpu_device*adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
Quoted 9 lines
{ int r; struct amdgpu_bo_param bp;- u64
vram_size=adev->gmc.xgmi.node_segment_size* adev-
gmc.xgmi.num_physical_nodes;
+ u64vram_size=amdgpu_virt_vram_is_spm(adev)? adev-
gmc.mc_vram_size :drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-0+ adev->gmc.xgmi.node_segment_size * +adev->gmc.xgmi.num_physical_nodes;Clear NAK from my side for such hacks.
Quoted 8 lines
Quoted 6 lines
Please describe the requirements and proper integarte that into the handling.
Regards,
Christian.On
AMDGPU_VIRT_VRAM_IS_SPMcase, the hypervisor reports each VF's VRAM address in the ACPI SRAT table. So, driver can use the address directly, there is no need to use xgmi.node_segment_size to calculate the VF's VRAM starting address(the xGMI node segment size is not valid for the VF).
Yeah but that looks completely stitched together without any knowledge about what variable is used for what.
Two possibilities here, either write something reasonable or give us the requirements and my is implementing this.
This code quality you came up with here is absolutely horrible.
Regards,
Christian.
Quoted 94 lines
Thanks,
ZhigangQuoted 89 lines
Quoted 1 line
uint32_t pde0_page_shift = adev->gmc.vmid0_page_table_block_size+ 21;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct
Quoted 4 lines
uint32_t npdes = (vram_size + (1ULL << pde0_page_shift) - 1) >>
pde0_page_shift;drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0@@ -266,16 +269,21 @@ void amdgpu_gmc_sysvm_location(struct
amdgpu_device*adev, structamdgpu_gmc*mcdrivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct · line 273
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0u64 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;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct · line 271
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-1-/* 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
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4
-2- 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)) { +if (amdgpu_virt_xgmi_migrate_enabled (adev) || +amdgpu_virt_vram_is_spm (adev)) {/* set mc->vram_start to 0 to switch the returned GPU address of
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct · line 280
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0* amdgpu_bo_create_reserved() from FB aperture to GART aperture.
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4
-0*/ mc->vram_start =0 ; mc->vram_end = mc->vram_start + mc->mc_vram_size -1 ; mc->visible_vram_size =min (mc->visible_vram_size, mc->real_vram_size); +if (amdgpu_virt_vram_is_spm (adev)) { + mc->gart_start =ALIGN (mc->vram_end +1 , eight_gb); + mc->gart_end = mc->gart_start + mc->gart_size -1 ; + }} else { mc->fb_start = hive_vram_start; mc->fb_end = hive_vram_end;drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0@@ -1274,7 +1282,8 @@ void amdgpu_gmc_init_pdb0(struct
amdgpu_device*adev)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct · line 1282
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0uint64_t flags = adev->gart.gart_pte_flags;//TODO it is UC. explore NC/RW?
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct · line 1283
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0/* Each PDE0 (used as PTE) covers (2^vmid0_page_table_block_size)*2M
Quoted 11 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 vram_size = amdgpu_virt_vram_is_spm(adev) ? adev-gmc.mc_vram_size :
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-0+ 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);@@
Quoted 1 line
-1292,7 +1301,8 @@ void amdgpu_gmc_init_pdb0(struct
amdgpu_device*adev)
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_vram_gtt_location(struct
Quoted 16 lines
flags |= AMDGPU_PDE_PTE_FLAG(adev); vram_addr = adev->vm_manager.vram_base_offset;drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-1-if (!amdgpu_virt_xgmi_migrate_enabled (adev)) +if (!amdgpu_virt_xgmi_migrate_enabled (adev) && + !amdgpu_virt_vram_is_spm (adev)) vram_addr -= adev->gmc.xgmi.physical_node_id * adev-gmc.xgmi.node_segment_size; vram_end = vram_addr + vram_size;drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0
-0@@ -734,8 +734,10 @@ static void gmc_v12_0_vram_gtt_location(struct
amdgpu_device*adev,Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +4
-2adev->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; +if (!amdgpu_virt_vram_is_spm (adev)) + adev->vm_manager.vram_base_offset += + adev->gmc.xgmi.physical_node_id * + adev->gmc.xgmi.node_segment_size; }/**