iommu/vt-d: Fix infinite loop in free_all_cpu_cached_iovas
PATCH 1/1 iommu/vt-d: Fix infinite loop in free_all_cpu_cached_iovas
Per VT-d spec Section 10.4.2 ("Capability Register"), the maximum number of possible domains is 64K; indeed this is the maximum value that the cap_ndoms() macro will expand to. Since the value 65536 will not fix in a u16, the 'did' variable must be promoted to an int, otherwise the test for < 65536 will always be true and the loop will never end.
The symptom, in my case, was a hung machine during suspend.
--- drivers/iommu/intel-iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel-iommu.c +2 -2
@@ -4602,13 +4602,13 @@ static void free_all_cpu_cached_iovas(unsigned int cpu)for (i =0 ; i < g_num_of_iommus; i++) {struct intel_iommu *iommu = g_iommus[i];struct dmar_domain *domain; -u16 did; +int did;if (!iommu)continue ;for (did =0 ; did <cap_ndoms (iommu->cap); did++) { - domain =get_iommu_domain (iommu, did); + domain =get_iommu_domain (iommu, (u16 )did);if (!domain)continue ;
Signature · 1 line
2.7.4
A message that is not in the archive (sent off-list or not yet received): 1467505404-3561-1-git-send-email-aaron-J6AcJDG0ZEwdnm+yROfE0A@public.gmane.org
Quoted 3 lines · Aaron Campbell
Per VT-d spec Section 10.4.2 ("Capability Register"), the maximum number of possible domains is 64K; indeed this is the maximum value that the
cap_ndoms()macro will expand to.
Good catch. Before 3bd4f9112f87, the loop ended at the fixed value 0xffff. I didn't notice that cap_ndoms() could not only be lower than that, like on my notebook, but could also be greater. Therefore I didn't even look at the type of 'did'.
So, strictly speaking, the original code would not only overflow for small values of cap_ndoms, but would miss the entry at 0xffff in case cap_ndoms was 0x10000. My patch unfortunately changed that to an endless loop, instead.
Jan
Joerg Roedel
AppliedQuoted 8 lines · Aaron Campbell
Per VT-d spec Section 10.4.2 ("Capability Register"), the maximum number of possible domains is 64K; indeed this is the maximum value that the
cap_ndoms()macro will expand to. Since the value 65536 will not fix in a u16, the 'did' variable must be promoted to an int, otherwise the test for < 65536 will always be true and the loop will never end.The symptom, in my case, was a hung machine during suspend.
Applied, thanks.