On 11/13/26 15:56, Zhigang Luo wrote:
> 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.
> 
> gmc_v12_1_get_vm_pte() sets the bit for a VRAM buffer object. SVM
> calls it with a NULL buffer object, and svm_range_get_pte_flags()
> sets the bit only for system memory, so the NULL case sets it for
> SPM VRAM. NPA mappings are left unchanged.
> 
> v2:
> - Set the bit for a VRAM BO inside if (bo), and for the SVM NULL BO
>   in the else.
> 
> Signed-off-by: Zhigang Luo <[email protected]>
> ---
>  drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
> index 76391fca6c62..7ac0d9c6f280 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
> @@ -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;
> @@ -758,6 +764,10 @@ static void gmc_v12_1_get_vm_pte(struct amdgpu_device 
> *adev,
>  
>       if (bo) {
>               mem = bo->tbo.resource;
> +             if (amdgpu_virt_vram_is_spm(adev) &&
> +                 mem && mem->mem_type == TTM_PL_VRAM)
> +                     *flags |= AMDGPU_PTE_SYSTEM;
> +
>               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",
> @@ -766,6 +776,9 @@ static void gmc_v12_1_get_vm_pte(struct amdgpu_device 
> *adev,
>               } else if (*flags & AMDGPU_PTE_VALID) {
>                       gmc_v12_1_get_coherence_flags(adev, bo, flags);
>               }
> +     } else if (amdgpu_virt_vram_is_spm(adev)) {
> +             /* SVM has no BO. System memory already has S. VRAM does not. */
> +             *flags |= AMDGPU_PTE_SYSTEM;

Both SVM and PRT doesn't use a BO, so could be that this causes problems with 
PRT.

Please double check the VM programming guide that this is ok, if not change the 
code so that PRT is excluded.

With that done Reviewed-by: Christian König <[email protected]>

Regards,
Christian.

>       }
>  }
>  

Reply via email to