Skip to content

Commit 75f0efb

Browse files
rahjain-amdalexdeucher
authored andcommitted
drm/amdgpu: Take IOMMU remapping into account for p2p checks
when trying to enable p2p the amdgpu_device_is_peer_accessible() checks the condition where address_mask overlaps the aper_base and hence returns 0, due to which the p2p disables for this platform IOMMU should remap the BAR addresses so the device can access them. Hence check if peer_adev is remapping DMA v5: (Felix, Alex) - fixing comment as per Alex feedback - refactor code as per Felix v4: (Alex) - fix the comment and description v3: - remove iommu_remap variable v2: (Alex) - Fix as per review comments - add new function amdgpu_device_check_iommu_remap to check if iommu remap Signed-off-by: Rahul Jain <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 01bfabc commit 75f0efb

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,6 +3957,27 @@ static void amdgpu_device_check_iommu_direct_map(struct amdgpu_device *adev)
39573957
adev->ram_is_direct_mapped = true;
39583958
}
39593959

3960+
#if defined(CONFIG_HSA_AMD_P2P)
3961+
/**
3962+
* amdgpu_device_check_iommu_remap - Check if DMA remapping is enabled.
3963+
*
3964+
* @adev: amdgpu_device pointer
3965+
*
3966+
* return if IOMMU remapping bar address
3967+
*/
3968+
static bool amdgpu_device_check_iommu_remap(struct amdgpu_device *adev)
3969+
{
3970+
struct iommu_domain *domain;
3971+
3972+
domain = iommu_get_domain_for_dev(adev->dev);
3973+
if (domain && (domain->type == IOMMU_DOMAIN_DMA ||
3974+
domain->type == IOMMU_DOMAIN_DMA_FQ))
3975+
return true;
3976+
3977+
return false;
3978+
}
3979+
#endif
3980+
39603981
static const struct attribute *amdgpu_dev_attributes[] = {
39613982
&dev_attr_pcie_replay_count.attr,
39623983
NULL
@@ -6151,18 +6172,24 @@ bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
61516172
struct amdgpu_device *peer_adev)
61526173
{
61536174
#ifdef CONFIG_HSA_AMD_P2P
6154-
uint64_t address_mask = peer_adev->dev->dma_mask ?
6155-
~*peer_adev->dev->dma_mask : ~((1ULL << 32) - 1);
6156-
resource_size_t aper_limit =
6157-
adev->gmc.aper_base + adev->gmc.aper_size - 1;
61586175
bool p2p_access =
61596176
!adev->gmc.xgmi.connected_to_cpu &&
61606177
!(pci_p2pdma_distance(adev->pdev, peer_adev->dev, false) < 0);
61616178

6162-
return pcie_p2p && p2p_access && (adev->gmc.visible_vram_size &&
6163-
adev->gmc.real_vram_size == adev->gmc.visible_vram_size &&
6164-
!(adev->gmc.aper_base & address_mask ||
6165-
aper_limit & address_mask));
6179+
bool is_large_bar = adev->gmc.visible_vram_size &&
6180+
adev->gmc.real_vram_size == adev->gmc.visible_vram_size;
6181+
bool p2p_addressable = amdgpu_device_check_iommu_remap(peer_adev);
6182+
6183+
if (!p2p_addressable) {
6184+
uint64_t address_mask = peer_adev->dev->dma_mask ?
6185+
~*peer_adev->dev->dma_mask : ~((1ULL << 32) - 1);
6186+
resource_size_t aper_limit =
6187+
adev->gmc.aper_base + adev->gmc.aper_size - 1;
6188+
6189+
p2p_addressable = !(adev->gmc.aper_base & address_mask ||
6190+
aper_limit & address_mask);
6191+
}
6192+
return is_large_bar && p2p_access && p2p_addressable;
61666193
#else
61676194
return false;
61686195
#endif

0 commit comments

Comments
 (0)