diff options
author | Jiang Liu <jiang.liu@linux.intel.com> | 2014-11-25 20:42:10 -0500 |
---|---|---|
committer | Joerg Roedel <jroedel@suse.de> | 2014-12-02 07:03:09 -0500 |
commit | cc4f14aa170d895c9a43bdb56f62070c8a6da908 (patch) | |
tree | aa8e7d2d6634e0713a9773a77659759f16d967cd | |
parent | 864b94adfcba752aa902ee34497bbe58b97aa8d3 (diff) |
iommu/vt-d: Fix an off-by-one bug in __domain_mapping()
There's an off-by-one bug in function __domain_mapping(), which may
trigger the BUG_ON(nr_pages < lvl_pages) when
(nr_pages + 1) & superpage_mask == 0
The issue was introduced by commit 9051aa0268dc "intel-iommu: Combine
domain_pfn_mapping() and domain_sg_mapping()", which sets sg_res to
"nr_pages + 1" to avoid some of the 'sg_res==0' code paths.
It's safe to remove extra "+1" because sg_res is only used to calculate
page size now.
Reported-And-Tested-by: Sudeep Dutt <sudeep.dutt@intel.com>
Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Cc: <stable@vger.kernel.org> # >= 3.0
Acked-By: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
-rw-r--r-- | drivers/iommu/intel-iommu.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 99bf651234a6..fe6830af6cfa 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c | |||
@@ -1986,7 +1986,7 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, | |||
1986 | { | 1986 | { |
1987 | struct dma_pte *first_pte = NULL, *pte = NULL; | 1987 | struct dma_pte *first_pte = NULL, *pte = NULL; |
1988 | phys_addr_t uninitialized_var(pteval); | 1988 | phys_addr_t uninitialized_var(pteval); |
1989 | unsigned long sg_res; | 1989 | unsigned long sg_res = 0; |
1990 | unsigned int largepage_lvl = 0; | 1990 | unsigned int largepage_lvl = 0; |
1991 | unsigned long lvl_pages = 0; | 1991 | unsigned long lvl_pages = 0; |
1992 | 1992 | ||
@@ -1997,10 +1997,8 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, | |||
1997 | 1997 | ||
1998 | prot &= DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP; | 1998 | prot &= DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP; |
1999 | 1999 | ||
2000 | if (sg) | 2000 | if (!sg) { |
2001 | sg_res = 0; | 2001 | sg_res = nr_pages; |
2002 | else { | ||
2003 | sg_res = nr_pages + 1; | ||
2004 | pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | prot; | 2002 | pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | prot; |
2005 | } | 2003 | } |
2006 | 2004 | ||