Skip to contentSkip to conversation

drm/amdgpu: ensure no PCIe peer access for CPU XGMI iolinks

PATCH In review Alex Sierra 4 participants 5 messages Aug 26, 2022 – Aug 29, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: ensure no PCIe peer access for CPU XGMI iolinks

[Why] Devices with CPU XGMI iolink do not support PCIe peer access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -1
index ce7d117efdb5..1ff66718639d 100644
@@ -5538,7 +5538,8 @@ bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
 	return pcie_p2p && p2p_access && (adev->gmc.visible_vram_size &&
 		adev->gmc.real_vram_size == adev->gmc.visible_vram_size &&
 		!(adev->gmc.aper_base & address_mask ||
-		  aper_limit & address_mask));
+		  aper_limit & address_mask) &&
+		!adev->gmc.xgmi.connected_to_cpu);
 #else
 	return false;
 #endif
Signature · 1 line
2.32.0
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Alex Sierra

[Why] Devices with CPU XGMI iolink do not support PCIe peer access.

Quoted 21 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
index ce7d117efdb5..1ff66718639d 100644
@@ -5538,7 +5538,8 @@ bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
        return pcie_p2p && p2p_access && (adev->gmc.visible_vram_size &&
                adev->gmc.real_vram_size == adev->gmc.visible_vram_size &&
                !(adev->gmc.aper_base & address_mask ||
-                 aper_limit & address_mask));
+                 aper_limit & address_mask) &&
+               !adev->gmc.xgmi.connected_to_cpu);
 #else
        return false;
 #endif
--

2.32.0

#2 lore raw
In reply to Alex Sierra
Quoted 12 lines · Alex Sierra

[Why] Devices with CPU XGMI iolink do not support PCIe peer access.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index ce7d117efdb5..1ff66718639d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev, · line 5542

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -1
@@ -5538,7 +5538,8 @@ bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
  	return pcie_p2p && p2p_access && (adev->gmc.visible_vram_size &&
  		adev->gmc.real_vram_size == adev->gmc.visible_vram_size &&
  		!(adev->gmc.aper_base & address_mask ||
-		  aper_limit & address_mask));
+		  aper_limit & address_mask) &&
+		!adev->gmc.xgmi.connected_to_cpu);

Maybe it would be more readable if you added this to the initialization of p2p_access. In that case you can also save yourself the call to pci_p2pdma_distance_many and all the aperture checks. Like this:

	bool p2p_access = !adev->gmc.xgmi.connected_to_cpu &&
		!(pci_p2pdma_distance_many(adev->pdev, &peer_adev->dev, 1, true) < 0);

Regards,
  Felix

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  #else
  	return false;
  #endif
#3 lore raw

Am 26.08.22 um 23:49 schrieb Felix Kuehling:

Quoted 23 lines · Alex Sierra
Quoted 13 lines

[Why] Devices with CPU XGMI iolink do not support PCIe peer access.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index ce7d117efdb5..1ff66718639d 100644
@@ -5538,7 +5538,8 @@ bool amdgpu_device_is_peer_accessible(struct 
 amdgpu_device *adev,
Quoted 6 lines

      return pcie_p2p && p2p_access && (adev->gmc.visible_vram_size && adev->gmc.real_vram_size == adev->gmc.visible_vram_size && !(adev->gmc.aper_base & address_mask ||
-          aper_limit & address_mask));
+          aper_limit & address_mask) &&
+        !adev->gmc.xgmi.connected_to_cpu);

Maybe it would be more readable if you added this to the initialization of p2p_access. In that case you can also save yourself the call to pci_p2pdma_distance_many and all the aperture checks. Like this:

Quoted 2 lines

    bool p2p_access = !adev->gmc.xgmi.connected_to_cpu && !(pci_p2pdma_distance_many(adev->pdev, &peer_adev->dev, 1, true) < 0);

Yeah, agree. Static checks should come first.

But another question: When we have an XGMI link to the CPU all local memory is directly accessible, isn't it?

So the PCIe root complex should be able to allow PCIe device to access our local memory, even with snooping.

Or do I miss something here?

Regards,
Christian.

Quoted 8 lines

Regards,
  Felix

Quoted 3 lines

  #else
      return false;
  #endif

#4 lore raw

Am 2022-08-28 um 11:28 schrieb Christian König:

Quoted 27 lines

Am 26.08.22 um 23:49 schrieb Felix Kuehling:

Quoted 23 lines · Alex Sierra
Quoted 13 lines

[Why] Devices with CPU XGMI iolink do not support PCIe peer access.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index ce7d117efdb5..1ff66718639d 100644
@@ -5538,7 +5538,8 @@ bool amdgpu_device_is_peer_accessible(struct 
 amdgpu_device *adev,
Quoted 6 lines

      return pcie_p2p && p2p_access && (adev->gmc.visible_vram_size && adev->gmc.real_vram_size == adev->gmc.visible_vram_size && !(adev->gmc.aper_base & address_mask ||
-          aper_limit & address_mask));
+          aper_limit & address_mask) &&
+        !adev->gmc.xgmi.connected_to_cpu);

Maybe it would be more readable if you added this to the initialization of p2p_access. In that case you can also save yourself the call to pci_p2pdma_distance_many and all the aperture checks. Like this:

Quoted 2 lines

    bool p2p_access = !adev->gmc.xgmi.connected_to_cpu && !(pci_p2pdma_distance_many(adev->pdev, &peer_adev->dev, 1, true) < 0);

Quoted 7 lines

Yeah, agree. Static checks should come first.

But another question: When we have an XGMI link to the CPU all local memory is directly accessible, isn't it?

So the PCIe root complex should be able to allow PCIe device to access our local memory, even with snooping.

Or do I miss something here?

This patch is meant for the case that the module parameter amdgpu_use_xgmi_p2p=0. With XGMI disabled, I don't think PCIe P2P would work on this platform. This patch will ensure that we don't report PCIe P2P links in the KFD topology, and don't attempt to create PCIe P2P mappings and potentially DMA mappings in the page tables.

Regards,
  Felix

Quoted 13 lines

Regards,
Christian.

Quoted 8 lines

Regards,
  Felix

Quoted 3 lines

  #else
      return false;
  #endif