Skip to contentSkip to conversation

drm/amdgpu: return early on error while setting bar0 memtype

PATCH In review Nirmoy Das 4 participants 8 messages Oct 29, 2021 – Nov 2, 2021

Subsystems (2)
lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH 1/1 drm/amdgpu: return early on error while setting bar0 memtype

We set WC memtype for aper_base but don't check return value of arch_io_reserve_memtype_wc(). Be more defensive and return early on error.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -1
index 073ba2af0b9c..6b25982a9077 100644
@@ -1032,9 +1032,14 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
 	/* On A+A platform, VRAM can be mapped as WB */
 	if (!adev->gmc.xgmi.connected_to_cpu) {
 		/* reserve PAT memory space to WC for VRAM */
-		arch_io_reserve_memtype_wc(adev->gmc.aper_base,
+		int r = arch_io_reserve_memtype_wc(adev->gmc.aper_base,
 				adev->gmc.aper_size);
 
+		if (r) {
+			DRM_ERROR("Unable to set WC memtype for the aperture base\n");
+			return r;
+		}
+
 		/* Add an MTRR for the VRAM */
 		adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,
 				adev->gmc.aper_size);
Signature · 1 line
2.33.1
#1 lore raw

Am 29.10.21 um 17:09 schrieb Nirmoy Das:

Quoted 14 lines

We set WC memtype for aper_base but don't check return value of arch_io_reserve_memtype_wc(). Be more defensive and return early on error.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 073ba2af0b9c..6b25982a9077 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_init(struct amdgpu_device *adev) · line 1039

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -1
@@ -1032,9 +1032,14 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
  	/* On A+A platform, VRAM can be mapped as WB */
  	if (!adev->gmc.xgmi.connected_to_cpu) {
  		/* reserve PAT memory space to WC for VRAM */
-		arch_io_reserve_memtype_wc(adev->gmc.aper_base,
+		int r = arch_io_reserve_memtype_wc(adev->gmc.aper_base,
  				adev->gmc.aper_size);
 
+		if (r) {
+			DRM_ERROR("Unable to set WC memtype for the aperture base\n");

Drop the word "base" and rather write "VRAM aperture".

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

Regards,
Christian.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -0
+			return r;
+		}
+
  		/* Add an MTRR for the VRAM */
  		adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,
  				adev->gmc.aper_size);
#2 lore raw
In reply to Nirmoy Das
Quoted 14 lines · Nirmoy Das

We set WC memtype for aper_base but don't check return value of arch_io_reserve_memtype_wc(). Be more defensive and return early on error.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 073ba2af0b9c..6b25982a9077 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_init(struct amdgpu_device *adev) · line 1036

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
@@ -1032,9 +1032,14 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
  	/* On A+A platform, VRAM can be mapped as WB */
  	if (!adev->gmc.xgmi.connected_to_cpu) {
  		/* reserve PAT memory space to WC for VRAM */
-		arch_io_reserve_memtype_wc(adev->gmc.aper_base,
+		int r = arch_io_reserve_memtype_wc(adev->gmc.aper_base,
  				adev->gmc.aper_size);

BTW, isn't it more appropriate to use visible vram size? There are cases where pci resize rounds aperture to the next higher size > size of actual VRAM.

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5 -0
+		if (r) {
+			DRM_ERROR("Unable to set WC memtype for the aperture base\n");
+			return r;
+		}
+
  		/* Add an MTRR for the VRAM */
  		adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,
  				adev->gmc.aper_size);
 
#3 lore raw
Quoted 12 lines · Lijo
Quoted 9 lines · Nirmoy Das

We set WC memtype for aper_base but don't check return value of arch_io_reserve_memtype_wc(). Be more defensive and return early on error.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-

  1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_init(struct amdgpu_device *adev) · line 1036

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index 073ba2af0b9c..6b25982a9077 100644
@@ -1032,9 +1032,14 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
       /* On A+A platform, VRAM can be mapped as WB */
       if (!adev->gmc.xgmi.connected_to_cpu) {
           /* reserve PAT memory space to WC for VRAM */
-        arch_io_reserve_memtype_wc(adev->gmc.aper_base,
+        int r = arch_io_reserve_memtype_wc(adev->gmc.aper_base,
                   adev->gmc.aper_size);

BTW, isn't it more appropriate to use visible vram size? There are cases where pci resize rounds aperture to the next higher size > size of actual VRAM.

Good point, I will update this one and send again.

Regards,

Nirmoy

Quoted 13 lines

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
   +        if (r) {
+            DRM_ERROR("Unable to set WC memtype for the aperture 
 base\n");
+            return r;
+        }
+
           /* Add an MTRR for the VRAM */
           adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,

                  adev->gmc.aper_size);

#4 lore raw

Am 02.11.21 um 11:11 schrieb Das, Nirmoy:

Quoted 29 lines · Lijo
Quoted 12 lines · Nirmoy Das
Quoted 9 lines

We set WC memtype for aper_base but don't check return value of arch_io_reserve_memtype_wc(). Be more defensive and return early on error.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-

  1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_init(struct amdgpu_device *adev) · line 1036

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index 073ba2af0b9c..6b25982a9077 100644
@@ -1032,9 +1032,14 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
       /* On A+A platform, VRAM can be mapped as WB */
       if (!adev->gmc.xgmi.connected_to_cpu) {
           /* reserve PAT memory space to WC for VRAM */
-        arch_io_reserve_memtype_wc(adev->gmc.aper_base,
+        int r = arch_io_reserve_memtype_wc(adev->gmc.aper_base,
                   adev->gmc.aper_size);

BTW, isn't it more appropriate to use visible vram size? There are cases where pci resize rounds aperture to the next higher size > size of actual VRAM.

Quoted 1 line

Good point, I will update this one and send again.

Not a good idea at all.

The aperture size is rounded up to the next power of two and that's exactly what we should stick to if we don't want to get an error code in return.

Regards,
Christian.

Quoted 20 lines

Regards,

Nirmoy

Quoted 13 lines

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
   +        if (r) {
+            DRM_ERROR("Unable to set WC memtype for the aperture 
 base\n");
+            return r;
+        }
+
           /* Add an MTRR for the VRAM */
           adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,

                  adev->gmc.aper_size);

#5 lore raw
Quoted 30 lines · Christian König

Am 02.11.21 um 11:11 schrieb Das, Nirmoy:

Quoted 29 lines · Lijo
Quoted 25 lines · Nirmoy Das
Quoted 14 lines

We set WC memtype for aper_base but don't check return value of arch_io_reserve_memtype_wc(). Be more defensive and return early on error.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-

  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 073ba2af0b9c..6b25982a9077 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_init(struct amdgpu_device *adev) · line 1036

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
@@ -1032,9 +1032,14 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
       /* On A+A platform, VRAM can be mapped as WB */
       if (!adev->gmc.xgmi.connected_to_cpu) {
           /* reserve PAT memory space to WC for VRAM */
-        arch_io_reserve_memtype_wc(adev->gmc.aper_base,
+        int r = arch_io_reserve_memtype_wc(adev->gmc.aper_base,
                   adev->gmc.aper_size);

BTW, isn't it more appropriate to use visible vram size? There are cases where pci resize rounds aperture to the next higher size > size of actual VRAM.

Quoted 6 lines
Quoted 1 line

Good point, I will update this one and send again.

Not a good idea at all.

The aperture size is rounded up to the next power of two and that's exactly what we should stick to if we don't want to get an error code in return.

PCI rebar sizes have its restrictions. It jumps from 4G to 8G to 16G and so on. Why we need to map 16G for a card with 12G VRAM? BTW, how it increases the failure chance - this mapping happens in page sizes, right?

Thanks,
Lijo

Quoted 24 lines

Regards,
Christian.

Quoted 20 lines

Regards,

Nirmoy

Quoted 13 lines

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
   +        if (r) {
+            DRM_ERROR("Unable to set WC memtype for the aperture 
 base\n");
+            return r;
+        }
+
           /* Add an MTRR for the VRAM */
           adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,

                  adev->gmc.aper_size);

maintainer
#6 lore raw

Am 02.11.21 um 12:18 schrieb Lazar, Lijo:

Quoted 33 lines · Christian König
Quoted 30 lines

Am 02.11.21 um 11:11 schrieb Das, Nirmoy:

Quoted 29 lines · Lijo
Quoted 25 lines · Nirmoy Das
Quoted 14 lines

We set WC memtype for aper_base but don't check return value of arch_io_reserve_memtype_wc(). Be more defensive and return early on error.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-

  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 073ba2af0b9c..6b25982a9077 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_init(struct amdgpu_device *adev) · line 1036

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
@@ -1032,9 +1032,14 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
       /* On A+A platform, VRAM can be mapped as WB */
       if (!adev->gmc.xgmi.connected_to_cpu) {
           /* reserve PAT memory space to WC for VRAM */
- arch_io_reserve_memtype_wc(adev->gmc.aper_base,
+        int r = arch_io_reserve_memtype_wc(adev->gmc.aper_base,
                   adev->gmc.aper_size);

BTW, isn't it more appropriate to use visible vram size? There are cases where pci resize rounds aperture to the next higher size > size of actual VRAM.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Good point, I will update this one and send again.

Not a good idea at all.

The aperture size is rounded up to the next power of two and that's exactly what we should stick to if we don't want to get an error code in return.

PCI rebar sizes have its restrictions. It jumps from 4G to 8G to 16G and so on. Why we need to map 16G for a card with 12G VRAM? BTW, how it increases the failure chance - this mapping happens in page sizes, right?

Exactly that's the point. This mapping usually happens in power of two in the same way as the PCI BAR sizes. So we should use 16GiB even for a 12GiB card here.

Only some architectures work with page size mappings (e.g. x86 with PAT enabled). Then we can indeed use the real VRAM size, but that is absolutely not guaranteed as far as I know.

Regards,
Christian.

Quoted 27 lines

Thanks,
Lijo

Quoted 24 lines

Regards,
Christian.

Quoted 20 lines

Regards,

Nirmoy

Quoted 13 lines

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
   +        if (r) {
+            DRM_ERROR("Unable to set WC memtype for the aperture 
 base\n");
+            return r;
+        }
+
           /* Add an MTRR for the VRAM */
           adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,

                  adev->gmc.aper_size);

#7 lore raw
Quoted 39 lines · Christian König

Am 02.11.21 um 12:18 schrieb Lazar, Lijo:

Quoted 38 lines · Christian König
Quoted 35 lines

Am 02.11.21 um 11:11 schrieb Das, Nirmoy:

Quoted 30 lines · Lijo
Quoted 12 lines · Nirmoy Das
Quoted 9 lines

We set WC memtype for aper_base but don't check return value of arch_io_reserve_memtype_wc(). Be more defensive and return early on error.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-

  1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_init(struct amdgpu_device · line 1037

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index 073ba2af0b9c..6b25982a9077 100644
@@ -1032,9 +1032,14 @@ int amdgpu_bo_init(struct amdgpu_device 
 *adev)
       /* On A+A platform, VRAM can be mapped as WB */
       if (!adev->gmc.xgmi.connected_to_cpu) {
           /* reserve PAT memory space to WC for VRAM */
- arch_io_reserve_memtype_wc(adev->gmc.aper_base,
+        int r = arch_io_reserve_memtype_wc(adev->gmc.aper_base,
                   adev->gmc.aper_size);

BTW, isn't it more appropriate to use visible vram size? There are cases where pci resize rounds aperture to the next higher size > size of actual VRAM.

Quoted 1 line

Good point, I will update this one and send again.

Not a good idea at all.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

The aperture size is rounded up to the next power of two and that's exactly what we should stick to if we don't want to get an error code in return.

PCI rebar sizes have its restrictions. It jumps from 4G to 8G to 16G and so on. Why we need to map 16G for a card with 12G VRAM? BTW, how it increases the failure chance - this mapping happens in page sizes, right?

Exactly that's the point. This mapping usually happens in power of two in the same way as the PCI BAR sizes. So we should use 16GiB even for a 12GiB card here.

Only some architectures work with page size mappings (e.g. x86 with PAT enabled). Then we can indeed use the real VRAM size, but that is absolutely not guaranteed as far as I know.

Thanks for clarifying this. I will push the patch with your suggested changes.

Regards,

Nirmoy

Quoted 32 lines

Regards,
Christian.

Quoted 27 lines

Thanks,
Lijo

Quoted 24 lines

Regards,
Christian.

Quoted 20 lines

Regards,

Nirmoy

Quoted 13 lines

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
   +        if (r) {
+            DRM_ERROR("Unable to set WC memtype for the aperture 
 base\n");
+            return r;
+        }
+
           /* Add an MTRR for the VRAM */

          adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base, adev->gmc.aper_size);