Commit 60d0ca3c authored by Alex Williamson's avatar Alex Williamson Committed by Joerg Roedel

iommu/amd: Only unmap large pages from the first pte

If we use a large mapping, the expectation is that only unmaps from
the first pte in the superpage are supported.  Unmaps from offsets
into the superpage should fail (ie. return zero sized unmap).  In the
current code, unmapping from an offset clears the size of the full
mapping starting from an offset.  For instance, if we map a 16k
physically contiguous range at IOVA 0x0 with a large page, then
attempt to unmap 4k at offset 12k, 4 ptes are cleared (12k - 28k) and
the unmap returns 16k unmapped.  This potentially incorrectly clears
valid mappings and confuses drivers like VFIO that use the unmap size
to release pinned pages.

Fix by refusing to unmap from offsets into the page.
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJoerg Roedel <joro@8bytes.org>
parent 5c34c403
...@@ -1484,6 +1484,10 @@ static unsigned long iommu_unmap_page(struct protection_domain *dom, ...@@ -1484,6 +1484,10 @@ static unsigned long iommu_unmap_page(struct protection_domain *dom,
/* Large PTE found which maps this address */ /* Large PTE found which maps this address */
unmap_size = PTE_PAGE_SIZE(*pte); unmap_size = PTE_PAGE_SIZE(*pte);
/* Only unmap from the first pte in the page */
if ((unmap_size - 1) & bus_addr)
break;
count = PAGE_SIZE_PTE_COUNT(unmap_size); count = PAGE_SIZE_PTE_COUNT(unmap_size);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
pte[i] = 0ULL; pte[i] = 0ULL;
...@@ -1493,7 +1497,7 @@ static unsigned long iommu_unmap_page(struct protection_domain *dom, ...@@ -1493,7 +1497,7 @@ static unsigned long iommu_unmap_page(struct protection_domain *dom,
unmapped += unmap_size; unmapped += unmap_size;
} }
BUG_ON(!is_power_of_2(unmapped)); BUG_ON(unmapped && !is_power_of_2(unmapped));
return unmapped; return unmapped;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment