On 11/11/26 20:23, Zhigang Luo wrote:
> 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().
> 
> Signed-off-by: Zhigang Luo <[email protected]>
> ---
>  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(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> index 04cf02dd22ac..ac2664e1eb8a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> @@ -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.

> +static const u64 eight_gb = 0x200000000ULL;

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

>  
>  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.



>       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
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c 
> b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
> index b13967a1c8fb..13e29752e435 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
> @@ -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

> +
>       return (u64)(RREG32_SOC15(GC, GET_INST(GC, 0),
>                                 regGCMC_VM_FB_OFFSET) << 24);
>  }
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
> index cd276a138e10..1c7f3f0496cc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
> @@ -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;

That stuff should have been reverted.

> -     } 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;
> diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c 
> b/drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c
> index 4c0a2d671cfc..409d57a9045e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c
> @@ -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;

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.

> +             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;

That should also be reverted before this patch set.

Regards,
Christian.

> +     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;
>  }

Reply via email to