Re: [PATCH 2/4] Bug Fix drivers/pci/intel-iommu.c: secure sg_next() calling

David Woodhouse
2009-08-05T08:10:08Z

On Tue, 2009-08-04 at 15:10 -0700, Fenghua Yu wrote:
> sg_next() is called only when sg is not NULL. This solves a kernel panic on
> some platforms (e.g. ia64).

Is this still necessary after we fix the other bugs? When does it
happen? And is this fix sufficient (ignore the first hunk; it's just a
cleanup that the fix allows me to make, which is why I'd prefer to do it
this way):

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index 11b317a..c9bdb0b 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -1675,7 +1675,7 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
if (sg)
sg_res = 0;
else {
- sg_res = nr_pages + 1;
+ sg_res = nr_pages;
pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | prot;
}

@@ -1716,7 +1716,7 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
iov_pfn++;
pteval += VTD_PAGE_SIZE;
sg_res--;
- if (!sg_res)
+ if (nr_pages && !sg_res)
sg = sg_next(sg);
}
return 0;

--
David Woodhouse Open Source Technology Centre
David.Woodhouse@intel.com Intel Corporation