Harden option parsing in IOMMU code Prevent crashes when there is a option with a number after iommu= and better checking for bad values. Also allow [GMK] prefixes for IOMMU size. Index: linux/arch/x86_64/kernel/pci-gart.c =================================================================== --- linux.orig/arch/x86_64/kernel/pci-gart.c +++ linux/arch/x86_64/kernel/pci-gart.c @@ -677,14 +677,16 @@ static __init unsigned long check_iommu_ if (!no_agp) iommu_size /= 2; } - - a = aper + iommu_size; - iommu_size -= round_up(a, LARGE_PAGE_SIZE) - a; - + if (iommu_size > aper_size) + iommu_size = aper_size; + a = aper + (aper_size - iommu_size); + a = round_up(a, LARGE_PAGE_SIZE); + if (a >= aper + aper_size) + iommu_size = aper_size; /* RED-PEN lame fallback */ + iommu_size = aper + aper_size - a; if (iommu_size < 64*1024*1024) printk(KERN_WARNING "PCI-DMA: Warning: Small IOMMU %luMB. Consider increasing the AGP aperture in BIOS\n",iommu_size>>20); - return iommu_size; } @@ -889,7 +891,7 @@ fs_initcall(pci_iommu_init); /* iommu=[size][,noagp][,off][,force][,noforce][,leak][,memaper[=order]][,merge] [,forcesac][,fullflush][,nomerge][,biomerge] - size set size of iommu (in bytes) + size set size of iommu (in bytes), K,M,G prefixes allowed. Max 2GB. noagp don't initialize the AGP driver and use full aperture. off don't use the IOMMU leak turn on simple iommu leak tracing (only when CONFIG_IOMMU_LEAK is on) @@ -912,7 +914,7 @@ __init int iommu_setup(char *p) { int arg; - while (*p) { + while (*p && *p != ' ') { if (!strncmp(p,"noagp",5)) no_agp = 1; if (!strncmp(p,"off",3)) @@ -970,9 +972,15 @@ __init int iommu_setup(char *p) iommu_leak_pages = arg; } else #endif - if (isdigit(*p) && get_option(&p, &arg)) - iommu_size = arg; - p += strcspn(p, ","); + if (isdigit(*p)) { + char *newp; + unsigned long num = memparse(p, &newp); + if (newp > p) { + p = newp; + iommu_size = num; + } + } + p += strcspn(p, ", "); if (*p == ',') ++p; } Index: linux/Documentation/x86_64/boot-options.txt =================================================================== --- linux.orig/Documentation/x86_64/boot-options.txt +++ linux/Documentation/x86_64/boot-options.txt @@ -148,7 +148,7 @@ IOMMU iommu=[size][,noagp][,off][,force][,noforce][,leak][,memaper[=order]][,merge] [,forcesac][,fullflush][,nomerge][,noaperture] - size set size of iommu (in bytes) + size set size of iommu (in bytes). K,M,G postfixes allowed. Max 2GB. noagp don't initialize the AGP driver and use full aperture. off don't use the IOMMU leak turn on simple iommu leak tracing (only when CONFIG_IOMMU_LEAK is on)