iommu/amd: Call free_iova_fast with pfn in map_sg

This change “iommu/amd: Call free_iova_fast with pfn in map_sg” in Linux kernel is authored by Jerry Snitselaar <jsnitsel [at]> on Thu Jan 17 12:29:02 2019 -0700.

iommu/amd: Call free_iova_fast with pfn in map_sg

In the error path of map_sg, free_iova_fast is being called with
address instead of the pfn. This results in a bad value getting into
the rcache, and can result in hitting a BUG_ON when
iova_magazine_free_pfns is called.

Cc: Joerg Roedel <>
Cc: Suravee Suthikulpanit <>
Signed-off-by: Jerry Snitselaar <>
Fixes: 80187fd39dcb ("iommu/amd: Optimize map_sg and unmap_sg")
Signed-off-by: Joerg Roedel <>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 51d8838.

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/iommu/amd_iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 87ba23a..418df8f 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2623,7 +2623,7 @@ static int map_sg(struct device *dev, struct scatterlist *sglist,
-	free_iova_fast(&dma_dom->iovad, address, npages);
+	free_iova_fast(&dma_dom->iovad, address >> PAGE_SHIFT, npages);
 	return 0;

The commit for this change in Linux stable tree is 51d8838 (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *