aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
diff options
context:
space:
mode:
authorTom St Denis <tom.stdenis@amd.com>2017-09-19 11:29:04 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-09-26 15:14:15 -0400
commit10cfafd62af4295abc73cbf4531654d4f335ff15 (patch)
treede5d4777f67f6db74315f686c44134fb73faf054 /drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
parenta49ccdbd1d70005049647ac1f8e8989c54b41e63 (diff)
drm/amd/amdgpu: Partial revert of iova debugfs
We discovered that on some devices even with iommu enabled you can access all of system memory through the iommu translation. Therefore, we revert the read method to the translation only service and drop the write method completely. Signed-off-by: Tom St Denis <tom.stdenis@amd.com> Reviewed-by: Christan König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c90
1 files changed, 13 insertions, 77 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 0e5f78f3a97e..ce435dbbb398 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1784,98 +1784,34 @@ static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
1784 size_t size, loff_t *pos) 1784 size_t size, loff_t *pos)
1785{ 1785{
1786 struct amdgpu_device *adev = file_inode(f)->i_private; 1786 struct amdgpu_device *adev = file_inode(f)->i_private;
1787 ssize_t result, n;
1788 int r; 1787 int r;
1789 uint64_t phys; 1788 uint64_t phys;
1790 void *ptr;
1791 struct iommu_domain *dom; 1789 struct iommu_domain *dom;
1792 1790
1793 dom = iommu_get_domain_for_dev(adev->dev); 1791 // always return 8 bytes
1794 if (!dom) 1792 if (size != 8)
1795 return -EFAULT; 1793 return -EINVAL;
1796
1797 result = 0;
1798 while (size) {
1799 // get physical address and map
1800 phys = iommu_iova_to_phys(dom, *pos);
1801
1802 // copy upto one page
1803 if (size > PAGE_SIZE)
1804 n = PAGE_SIZE;
1805 else
1806 n = size;
1807
1808 // to end of the page
1809 if (((*pos & (PAGE_SIZE - 1)) + n) >= PAGE_SIZE)
1810 n = PAGE_SIZE - (*pos & (PAGE_SIZE - 1));
1811
1812 ptr = kmap(pfn_to_page(PFN_DOWN(phys)));
1813 if (!ptr)
1814 return -EFAULT;
1815
1816 r = copy_to_user(buf, ptr, n);
1817 kunmap(pfn_to_page(PFN_DOWN(phys)));
1818 if (r)
1819 return -EFAULT;
1820
1821 *pos += n;
1822 size -= n;
1823 result += n;
1824 }
1825
1826 return result;
1827}
1828 1794
1829static ssize_t amdgpu_iova_to_phys_write(struct file *f, const char __user *buf, 1795 // only accept page addresses
1830 size_t size, loff_t *pos) 1796 if (*pos & 0xFFF)
1831{ 1797 return -EINVAL;
1832 struct amdgpu_device *adev = file_inode(f)->i_private;
1833 ssize_t result, n;
1834 int r;
1835 uint64_t phys;
1836 void *ptr;
1837 struct iommu_domain *dom;
1838 1798
1839 dom = iommu_get_domain_for_dev(adev->dev); 1799 dom = iommu_get_domain_for_dev(adev->dev);
1840 if (!dom) 1800 if (dom)
1841 return -EFAULT;
1842
1843 result = 0;
1844 while (size) {
1845 // get physical address and map
1846 phys = iommu_iova_to_phys(dom, *pos); 1801 phys = iommu_iova_to_phys(dom, *pos);
1802 else
1803 phys = *pos;
1847 1804
1848 // copy upto one page 1805 r = copy_to_user(buf, &phys, 8);
1849 if (size > PAGE_SIZE) 1806 if (r)
1850 n = PAGE_SIZE; 1807 return -EFAULT;
1851 else
1852 n = size;
1853
1854 // to end of the page
1855 if (((*pos & (PAGE_SIZE - 1)) + n) >= PAGE_SIZE)
1856 n = PAGE_SIZE - (*pos & (PAGE_SIZE - 1));
1857
1858 ptr = kmap(pfn_to_page(PFN_DOWN(phys)));
1859 if (!ptr)
1860 return -EFAULT;
1861
1862 r = copy_from_user(ptr, buf, n);
1863 kunmap(pfn_to_page(PFN_DOWN(phys)));
1864 if (r)
1865 return -EFAULT;
1866
1867 *pos += n;
1868 size -= n;
1869 result += n;
1870 }
1871 1808
1872 return result; 1809 return 8;
1873} 1810}
1874 1811
1875static const struct file_operations amdgpu_ttm_iova_fops = { 1812static const struct file_operations amdgpu_ttm_iova_fops = {
1876 .owner = THIS_MODULE, 1813 .owner = THIS_MODULE,
1877 .read = amdgpu_iova_to_phys_read, 1814 .read = amdgpu_iova_to_phys_read,
1878 .write = amdgpu_iova_to_phys_write,
1879 .llseek = default_llseek 1815 .llseek = default_llseek
1880}; 1816};
1881 1817