Skip to contentSkip to conversation

drm/amdgpu/gmc: use PCI BARs for APUs in passthrough

PATCH In review Alex Deucher 3 participants 3 messages Mar 15, 2022 – Mar 16, 2022

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu/gmc: use PCI BARs for APUs in passthrough

If the GPU is passed through to a guest VM, use the PCI BAR for CPU FB access rather than the physical address of carve out. The physical address is not valid in a guest.

v2: Fix HDP handing as suggested by Michel

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c     | 2 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c      | 5 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      | 2 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c      | 2 +-
 5 files changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
index 1b313a95c7e5..eb902654f35d 100644
@@ -5733,7 +5733,7 @@ void amdgpu_device_flush_hdp(struct amdgpu_device *adev,
 		struct amdgpu_ring *ring)
 {
 #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU)
+	if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev))
 		return;
 #endif
 	if (adev->gmc.xgmi.connected_to_cpu)
@@ -5749,7 +5749,7 @@ void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev,
 		struct amdgpu_ring *ring)
 {
 #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU)
+	if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev))
 		return;
 #endif
 	if (adev->gmc.xgmi.connected_to_cpu)
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -1
index f60b7bd4dbf5..9887a60e8eae 100644
@@ -814,7 +814,7 @@ static int gmc_v10_0_mc_init(struct amdgpu_device *adev)
 	adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
 
 #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU) {
+	if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev)) {
 		adev->gmc.aper_base = adev->gfxhub.funcs->get_mc_fb_offset(adev);
 		adev->gmc.aper_size = adev->gmc.real_vram_size;
 	}
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -2
index 344d819b4c1b..979da6f510e8 100644
@@ -381,8 +381,9 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)
 	adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
 
 #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU &&
-	    adev->gmc.real_vram_size > adev->gmc.aper_size) {
+	if ((adev->flags & AMD_IS_APU) &&
+	    adev->gmc.real_vram_size > adev->gmc.aper_size &&
+	    !amdgpu_passthrough(adev)) {
 		adev->gmc.aper_base = ((u64)RREG32(mmMC_VM_FB_OFFSET)) << 22;
 		adev->gmc.aper_size = adev->gmc.real_vram_size;
 	}
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -1
index ca9841d5669f..1932a3e4af7e 100644
@@ -581,7 +581,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
 	adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
 
 #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU) {
+	if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev)) {
 		adev->gmc.aper_base = ((u64)RREG32(mmMC_VM_FB_OFFSET)) << 22;
 		adev->gmc.aper_size = adev->gmc.real_vram_size;
 	}
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
index 431742eb7811..5fa613d41799 100644
@@ -1456,7 +1456,7 @@ static int gmc_v9_0_mc_init(struct amdgpu_device *adev)
 	 */
 
 	/* check whether both host-gpu and gpu-gpu xgmi links exist */
-	if ((adev->flags & AMD_IS_APU) ||
+	if (((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev)) ||
 	    (adev->gmc.xgmi.supported &&
 	     adev->gmc.xgmi.connected_to_cpu)) {
 		adev->gmc.aper_base =
Signature · 1 line
2.35.1
#1 lore raw

Am 15.03.22 um 19:13 schrieb Alex Deucher:

Quoted 7 lines

If the GPU is passed through to a guest VM, use the PCI BAR for CPU FB access rather than the physical address of carve out. The physical address is not valid in a guest.

v2: Fix HDP handing as suggested by Michel

Might be a good idea to have a function or macro to figure out if we should use the BAR or not on APUs.

Anyway patch is Reviewed-by: Christian König <[email protected]>.

Quoted 85 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++--
  drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c     | 2 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c      | 5 +++--
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      | 2 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c      | 2 +-
  5 files changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
index 1b313a95c7e5..eb902654f35d 100644
@@ -5733,7 +5733,7 @@ void amdgpu_device_flush_hdp(struct amdgpu_device *adev,
  		struct amdgpu_ring *ring)
  {
  #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU)
+	if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev))
  		return;
  #endif
  	if (adev->gmc.xgmi.connected_to_cpu)
@@ -5749,7 +5749,7 @@ void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev,
  		struct amdgpu_ring *ring)
  {
  #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU)
+	if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev))
  		return;
  #endif
  	if (adev->gmc.xgmi.connected_to_cpu)
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -1
index f60b7bd4dbf5..9887a60e8eae 100644
@@ -814,7 +814,7 @@ static int gmc_v10_0_mc_init(struct amdgpu_device *adev)
  	adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
 
  #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU) {
+	if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev)) {
  		adev->gmc.aper_base = adev->gfxhub.funcs->get_mc_fb_offset(adev);
  		adev->gmc.aper_size = adev->gmc.real_vram_size;
  	}
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -2
index 344d819b4c1b..979da6f510e8 100644
@@ -381,8 +381,9 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)
  	adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
 
  #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU &&
-	    adev->gmc.real_vram_size > adev->gmc.aper_size) {
+	if ((adev->flags & AMD_IS_APU) &&
+	    adev->gmc.real_vram_size > adev->gmc.aper_size &&
+	    !amdgpu_passthrough(adev)) {
  		adev->gmc.aper_base = ((u64)RREG32(mmMC_VM_FB_OFFSET)) << 22;
  		adev->gmc.aper_size = adev->gmc.real_vram_size;
  	}
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -1
index ca9841d5669f..1932a3e4af7e 100644
@@ -581,7 +581,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
  	adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
 
  #ifdef CONFIG_X86_64
-	if (adev->flags & AMD_IS_APU) {
+	if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev)) {
  		adev->gmc.aper_base = ((u64)RREG32(mmMC_VM_FB_OFFSET)) << 22;
  		adev->gmc.aper_size = adev->gmc.real_vram_size;
  	}
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
index 431742eb7811..5fa613d41799 100644
@@ -1456,7 +1456,7 @@ static int gmc_v9_0_mc_init(struct amdgpu_device *adev)
  	 */
 
  	/* check whether both host-gpu and gpu-gpu xgmi links exist */
-	if ((adev->flags & AMD_IS_APU) ||
+	if (((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev)) ||
  	    (adev->gmc.xgmi.supported &&
  	     adev->gmc.xgmi.connected_to_cpu)) {
  		adev->gmc.aper_base =
Reviewed-by
#2 lore raw
Quoted 5 lines · Christian König

Am 15.03.22 um 19:13 schrieb Alex Deucher:

Quoted 4 lines

If the GPU is passed through to a guest VM, use the PCI BAR for CPU FB access rather than the physical address of carve out.  The physical address is not valid in a guest.

Quoted 7 lines
Quoted 3 lines

v2: Fix HDP handing as suggested by Michel

Might be a good idea to have a function or macro to figure out if we should use the BAR or not on APUs.

Anyway patch is Reviewed-by: Christian König <[email protected]>.

And

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer