Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.infradead.org/iommu-2.6

* git://git.infradead.org/iommu-2.6:
intel-iommu: Set a more specific taint flag for invalid BIOS DMAR tables
intel-iommu: Combine the BIOS DMAR table warning messages
panic: Add taint flag TAINT_FIRMWARE_WORKAROUND ('I')
panic: Allow warnings to set different taint flags
intel-iommu: intel_iommu_map_range failed at very end of address space
intel-iommu: errors with smaller iommu widths
intel-iommu: Fix boot inside 64bit virtualbox with io-apic disabled
intel-iommu: use physfn to search drhd for VF
intel-iommu: Print out iommu seq_id
intel-iommu: Don't complain that ACPI_DMAR_SCOPE_TYPE_IOAPIC is not supported
intel-iommu: Avoid global flushes with caching mode.
intel-iommu: Use correct domain ID when caching mode is enabled
intel-iommu mistakenly uses offset_pfn when caching mode is enabled
intel-iommu: use for_each_set_bit()
intel-iommu: Fix section mismatch dmar_ir_support() uses dmar_tbl.

+181 -137
+4
Documentation/oops-tracing.txt
··· 256 256 9: 'A' if the ACPI table has been overridden. 257 257 258 258 10: 'W' if a warning has previously been issued by the kernel. 259 + (Though some warnings may set more specific taint flags.) 259 260 260 261 11: 'C' if a staging driver has been loaded. 262 + 263 + 12: 'I' if the kernel is working around a severe bug in the platform 264 + firmware (BIOS or similar). 261 265 262 266 The primary reason for the 'Tainted: ' string is to tell kernel 263 267 debuggers if this is a clean kernel or if anything unusual has
+4 -4
arch/parisc/include/asm/bug.h
··· 44 44 #endif 45 45 46 46 #ifdef CONFIG_DEBUG_BUGVERBOSE 47 - #define __WARN() \ 47 + #define __WARN_TAINT(taint) \ 48 48 do { \ 49 49 asm volatile("\n" \ 50 50 "1:\t" PARISC_BUG_BREAK_ASM "\n" \ ··· 54 54 "\t.org 2b+%c3\n" \ 55 55 "\t.popsection" \ 56 56 : : "i" (__FILE__), "i" (__LINE__), \ 57 - "i" (BUGFLAG_WARNING), \ 57 + "i" (BUGFLAG_TAINT(taint)), \ 58 58 "i" (sizeof(struct bug_entry)) ); \ 59 59 } while(0) 60 60 #else 61 - #define __WARN() \ 61 + #define __WARN_TAINT(taint) \ 62 62 do { \ 63 63 asm volatile("\n" \ 64 64 "1:\t" PARISC_BUG_BREAK_ASM "\n" \ ··· 67 67 "\t.short %c0\n" \ 68 68 "\t.org 2b+%c1\n" \ 69 69 "\t.popsection" \ 70 - : : "i" (BUGFLAG_WARNING), \ 70 + : : "i" (BUGFLAG_TAINT(taint)), \ 71 71 "i" (sizeof(struct bug_entry)) ); \ 72 72 } while(0) 73 73 #endif
+3 -3
arch/powerpc/include/asm/bug.h
··· 85 85 } \ 86 86 } while (0) 87 87 88 - #define __WARN() do { \ 88 + #define __WARN_TAINT(taint) do { \ 89 89 __asm__ __volatile__( \ 90 90 "1: twi 31,0,0\n" \ 91 91 _EMIT_BUG_ENTRY \ 92 92 : : "i" (__FILE__), "i" (__LINE__), \ 93 - "i" (BUGFLAG_WARNING), \ 93 + "i" (BUGFLAG_TAINT(taint)), \ 94 94 "i" (sizeof(struct bug_entry))); \ 95 95 } while (0) 96 96 ··· 104 104 "1: "PPC_TLNEI" %4,0\n" \ 105 105 _EMIT_BUG_ENTRY \ 106 106 : : "i" (__FILE__), "i" (__LINE__), \ 107 - "i" (BUGFLAG_WARNING), \ 107 + "i" (BUGFLAG_TAINT(TAINT_WARN)), \ 108 108 "i" (sizeof(struct bug_entry)), \ 109 109 "r" (__ret_warn_on)); \ 110 110 } \
+4 -4
arch/s390/include/asm/bug.h
··· 46 46 unreachable(); \ 47 47 } while (0) 48 48 49 - #define __WARN() do { \ 50 - __EMIT_BUG(BUGFLAG_WARNING); \ 49 + #define __WARN_TAINT(taint) do { \ 50 + __EMIT_BUG(BUGFLAG_TAINT(taint)); \ 51 51 } while (0) 52 52 53 53 #define WARN_ON(x) ({ \ 54 54 int __ret_warn_on = !!(x); \ 55 55 if (__builtin_constant_p(__ret_warn_on)) { \ 56 56 if (__ret_warn_on) \ 57 - __EMIT_BUG(BUGFLAG_WARNING); \ 57 + __WARN(); \ 58 58 } else { \ 59 59 if (unlikely(__ret_warn_on)) \ 60 - __EMIT_BUG(BUGFLAG_WARNING); \ 60 + __WARN(); \ 61 61 } \ 62 62 unlikely(__ret_warn_on); \ 63 63 })
+2 -2
arch/sh/include/asm/bug.h
··· 48 48 "i" (sizeof(struct bug_entry))); \ 49 49 } while (0) 50 50 51 - #define __WARN() \ 51 + #define __WARN_TAINT(taint) \ 52 52 do { \ 53 53 __asm__ __volatile__ ( \ 54 54 "1:\t.short %O0\n" \ ··· 57 57 : "n" (TRAPA_BUG_OPCODE), \ 58 58 "i" (__FILE__), \ 59 59 "i" (__LINE__), \ 60 - "i" (BUGFLAG_WARNING), \ 60 + "i" (BUGFLAG_TAINT(taint)), \ 61 61 "i" (sizeof(struct bug_entry))); \ 62 62 } while (0) 63 63
+37 -45
drivers/pci/dmar.c
··· 131 131 if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT || 132 132 scope->entry_type == ACPI_DMAR_SCOPE_TYPE_BRIDGE) 133 133 (*cnt)++; 134 - else 134 + else if (scope->entry_type != ACPI_DMAR_SCOPE_TYPE_IOAPIC) { 135 135 printk(KERN_WARNING PREFIX 136 - "Unsupported device scope\n"); 136 + "Unsupported device scope\n"); 137 + } 137 138 start += scope->length; 138 139 } 139 140 if (*cnt == 0) ··· 310 309 struct acpi_dmar_atsr *atsr; 311 310 struct dmar_atsr_unit *atsru; 312 311 312 + dev = pci_physfn(dev); 313 + 313 314 list_for_each_entry(atsru, &dmar_atsr_units, list) { 314 315 atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header); 315 316 if (atsr->segment == pci_domain_nr(dev->bus)) ··· 361 358 return 0; 362 359 } 363 360 } 364 - WARN(1, "Your BIOS is broken; RHSA refers to non-existent DMAR unit at %llx\n" 365 - "BIOS vendor: %s; Ver: %s; Product Version: %s\n", 366 - drhd->reg_base_addr, 367 - dmi_get_system_info(DMI_BIOS_VENDOR), 368 - dmi_get_system_info(DMI_BIOS_VERSION), 369 - dmi_get_system_info(DMI_PRODUCT_VERSION)); 361 + WARN_TAINT( 362 + 1, TAINT_FIRMWARE_WORKAROUND, 363 + "Your BIOS is broken; RHSA refers to non-existent DMAR unit at %llx\n" 364 + "BIOS vendor: %s; Ver: %s; Product Version: %s\n", 365 + drhd->reg_base_addr, 366 + dmi_get_system_info(DMI_BIOS_VENDOR), 367 + dmi_get_system_info(DMI_BIOS_VERSION), 368 + dmi_get_system_info(DMI_PRODUCT_VERSION)); 370 369 371 370 return 0; 372 371 } ··· 512 507 return ret; 513 508 } 514 509 515 - int dmar_pci_device_match(struct pci_dev *devices[], int cnt, 510 + static int dmar_pci_device_match(struct pci_dev *devices[], int cnt, 516 511 struct pci_dev *dev) 517 512 { 518 513 int index; ··· 534 529 { 535 530 struct dmar_drhd_unit *dmaru = NULL; 536 531 struct acpi_dmar_hardware_unit *drhd; 532 + 533 + dev = pci_physfn(dev); 537 534 538 535 list_for_each_entry(dmaru, &dmar_drhd_units, list) { 539 536 drhd = container_of(dmaru->hdr, ··· 621 614 return 0; 622 615 } 623 616 624 - static int bios_warned; 617 + static void warn_invalid_dmar(u64 addr, const char *message) 618 + { 619 + WARN_TAINT_ONCE( 620 + 1, TAINT_FIRMWARE_WORKAROUND, 621 + "Your BIOS is broken; DMAR reported at address %llx%s!\n" 622 + "BIOS vendor: %s; Ver: %s; Product Version: %s\n", 623 + addr, message, 624 + dmi_get_system_info(DMI_BIOS_VENDOR), 625 + dmi_get_system_info(DMI_BIOS_VERSION), 626 + dmi_get_system_info(DMI_PRODUCT_VERSION)); 627 + } 625 628 626 629 int __init check_zero_address(void) 627 630 { ··· 657 640 658 641 drhd = (void *)entry_header; 659 642 if (!drhd->address) { 660 - /* Promote an attitude of violence to a BIOS engineer today */ 661 - WARN(1, "Your BIOS is broken; DMAR reported at address zero!\n" 662 - "BIOS vendor: %s; Ver: %s; Product Version: %s\n", 663 - dmi_get_system_info(DMI_BIOS_VENDOR), 664 - dmi_get_system_info(DMI_BIOS_VERSION), 665 - dmi_get_system_info(DMI_PRODUCT_VERSION)); 666 - bios_warned = 1; 643 + warn_invalid_dmar(0, ""); 667 644 goto failed; 668 645 } 669 646 ··· 670 659 ecap = dmar_readq(addr + DMAR_ECAP_REG); 671 660 early_iounmap(addr, VTD_PAGE_SIZE); 672 661 if (cap == (uint64_t)-1 && ecap == (uint64_t)-1) { 673 - /* Promote an attitude of violence to a BIOS engineer today */ 674 - WARN(1, "Your BIOS is broken; DMAR reported at address %llx returns all ones!\n" 675 - "BIOS vendor: %s; Ver: %s; Product Version: %s\n", 676 - drhd->address, 677 - dmi_get_system_info(DMI_BIOS_VENDOR), 678 - dmi_get_system_info(DMI_BIOS_VERSION), 679 - dmi_get_system_info(DMI_PRODUCT_VERSION)); 680 - bios_warned = 1; 662 + warn_invalid_dmar(drhd->address, 663 + " returns all ones"); 681 664 goto failed; 682 665 } 683 666 } ··· 736 731 int msagaw = 0; 737 732 738 733 if (!drhd->reg_base_addr) { 739 - if (!bios_warned) { 740 - WARN(1, "Your BIOS is broken; DMAR reported at address zero!\n" 741 - "BIOS vendor: %s; Ver: %s; Product Version: %s\n", 742 - dmi_get_system_info(DMI_BIOS_VENDOR), 743 - dmi_get_system_info(DMI_BIOS_VERSION), 744 - dmi_get_system_info(DMI_PRODUCT_VERSION)); 745 - bios_warned = 1; 746 - } 734 + warn_invalid_dmar(0, ""); 747 735 return -EINVAL; 748 736 } 749 737 ··· 756 758 iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG); 757 759 758 760 if (iommu->cap == (uint64_t)-1 && iommu->ecap == (uint64_t)-1) { 759 - if (!bios_warned) { 760 - /* Promote an attitude of violence to a BIOS engineer today */ 761 - WARN(1, "Your BIOS is broken; DMAR reported at address %llx returns all ones!\n" 762 - "BIOS vendor: %s; Ver: %s; Product Version: %s\n", 763 - drhd->reg_base_addr, 764 - dmi_get_system_info(DMI_BIOS_VENDOR), 765 - dmi_get_system_info(DMI_BIOS_VERSION), 766 - dmi_get_system_info(DMI_PRODUCT_VERSION)); 767 - bios_warned = 1; 768 - } 761 + warn_invalid_dmar(drhd->reg_base_addr, " returns all ones"); 769 762 goto err_unmap; 770 763 } 771 764 ··· 795 806 } 796 807 797 808 ver = readl(iommu->reg + DMAR_VER_REG); 798 - pr_info("IOMMU %llx: ver %d:%d cap %llx ecap %llx\n", 809 + pr_info("IOMMU %d: reg_base_addr %llx ver %d:%d cap %llx ecap %llx\n", 810 + iommu->seq_id, 799 811 (unsigned long long)drhd->reg_base_addr, 800 812 DMAR_VER_MAJOR(ver), DMAR_VER_MINOR(ver), 801 813 (unsigned long long)iommu->cap, ··· 1447 1457 /* 1448 1458 * Check interrupt remapping support in DMAR table description. 1449 1459 */ 1450 - int dmar_ir_support(void) 1460 + int __init dmar_ir_support(void) 1451 1461 { 1452 1462 struct acpi_table_dmar *dmar; 1453 1463 dmar = (struct acpi_table_dmar *)dmar_tbl; 1464 + if (!dmar) 1465 + return 0; 1454 1466 return dmar->flags & 0x1; 1455 1467 }
+58 -69
drivers/pci/intel-iommu.c
··· 491 491 492 492 domain->iommu_coherency = 1; 493 493 494 - i = find_first_bit(&domain->iommu_bmp, g_num_of_iommus); 495 - for (; i < g_num_of_iommus; ) { 494 + for_each_set_bit(i, &domain->iommu_bmp, g_num_of_iommus) { 496 495 if (!ecap_coherent(g_iommus[i]->ecap)) { 497 496 domain->iommu_coherency = 0; 498 497 break; 499 498 } 500 - i = find_next_bit(&domain->iommu_bmp, g_num_of_iommus, i+1); 501 499 } 502 500 } 503 501 ··· 505 507 506 508 domain->iommu_snooping = 1; 507 509 508 - i = find_first_bit(&domain->iommu_bmp, g_num_of_iommus); 509 - for (; i < g_num_of_iommus; ) { 510 + for_each_set_bit(i, &domain->iommu_bmp, g_num_of_iommus) { 510 511 if (!ecap_sc_support(g_iommus[i]->ecap)) { 511 512 domain->iommu_snooping = 0; 512 513 break; 513 514 } 514 - i = find_next_bit(&domain->iommu_bmp, g_num_of_iommus, i+1); 515 515 } 516 516 } 517 517 ··· 1064 1068 } 1065 1069 1066 1070 static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, u16 did, 1067 - unsigned long pfn, unsigned int pages) 1071 + unsigned long pfn, unsigned int pages, int map) 1068 1072 { 1069 1073 unsigned int mask = ilog2(__roundup_pow_of_two(pages)); 1070 1074 uint64_t addr = (uint64_t)pfn << VTD_PAGE_SHIFT; ··· 1085 1089 DMA_TLB_PSI_FLUSH); 1086 1090 1087 1091 /* 1088 - * In caching mode, domain ID 0 is reserved for non-present to present 1089 - * mapping flush. Device IOTLB doesn't need to be flushed in this case. 1092 + * In caching mode, changes of pages from non-present to present require 1093 + * flush. However, device IOTLB doesn't need to be flushed in this case. 1090 1094 */ 1091 - if (!cap_caching_mode(iommu->cap) || did) 1095 + if (!cap_caching_mode(iommu->cap) || !map) 1092 1096 iommu_flush_dev_iotlb(iommu->domains[did], addr, mask); 1093 1097 } 1094 1098 ··· 1150 1154 unsigned long nlongs; 1151 1155 1152 1156 ndomains = cap_ndoms(iommu->cap); 1153 - pr_debug("Number of Domains supportd <%ld>\n", ndomains); 1157 + pr_debug("IOMMU %d: Number of Domains supportd <%ld>\n", iommu->seq_id, 1158 + ndomains); 1154 1159 nlongs = BITS_TO_LONGS(ndomains); 1155 1160 1156 1161 spin_lock_init(&iommu->lock); ··· 1191 1194 unsigned long flags; 1192 1195 1193 1196 if ((iommu->domains) && (iommu->domain_ids)) { 1194 - i = find_first_bit(iommu->domain_ids, cap_ndoms(iommu->cap)); 1195 - for (; i < cap_ndoms(iommu->cap); ) { 1197 + for_each_set_bit(i, iommu->domain_ids, cap_ndoms(iommu->cap)) { 1196 1198 domain = iommu->domains[i]; 1197 1199 clear_bit(i, iommu->domain_ids); 1198 1200 ··· 1203 1207 domain_exit(domain); 1204 1208 } 1205 1209 spin_unlock_irqrestore(&domain->iommu_lock, flags); 1206 - 1207 - i = find_next_bit(iommu->domain_ids, 1208 - cap_ndoms(iommu->cap), i+1); 1209 1210 } 1210 1211 } 1211 1212 ··· 1285 1292 1286 1293 spin_lock_irqsave(&iommu->lock, flags); 1287 1294 ndomains = cap_ndoms(iommu->cap); 1288 - num = find_first_bit(iommu->domain_ids, ndomains); 1289 - for (; num < ndomains; ) { 1295 + for_each_set_bit(num, iommu->domain_ids, ndomains) { 1290 1296 if (iommu->domains[num] == domain) { 1291 1297 found = 1; 1292 1298 break; 1293 1299 } 1294 - num = find_next_bit(iommu->domain_ids, 1295 - cap_ndoms(iommu->cap), num+1); 1296 1300 } 1297 1301 1298 1302 if (found) { ··· 1475 1485 1476 1486 /* find an available domain id for this device in iommu */ 1477 1487 ndomains = cap_ndoms(iommu->cap); 1478 - num = find_first_bit(iommu->domain_ids, ndomains); 1479 - for (; num < ndomains; ) { 1488 + for_each_set_bit(num, iommu->domain_ids, ndomains) { 1480 1489 if (iommu->domains[num] == domain) { 1481 1490 id = num; 1482 1491 found = 1; 1483 1492 break; 1484 1493 } 1485 - num = find_next_bit(iommu->domain_ids, 1486 - cap_ndoms(iommu->cap), num+1); 1487 1494 } 1488 1495 1489 1496 if (found == 0) { ··· 1545 1558 (((u16)bus) << 8) | devfn, 1546 1559 DMA_CCMD_MASK_NOBIT, 1547 1560 DMA_CCMD_DEVICE_INVL); 1548 - iommu->flush.flush_iotlb(iommu, 0, 0, 0, DMA_TLB_DSI_FLUSH); 1561 + iommu->flush.flush_iotlb(iommu, domain->id, 0, 0, DMA_TLB_DSI_FLUSH); 1549 1562 } else { 1550 1563 iommu_flush_write_buffer(iommu); 1551 1564 } ··· 2320 2333 */ 2321 2334 iommu->flush.flush_context = __iommu_flush_context; 2322 2335 iommu->flush.flush_iotlb = __iommu_flush_iotlb; 2323 - printk(KERN_INFO "IOMMU 0x%Lx: using Register based " 2336 + printk(KERN_INFO "IOMMU %d 0x%Lx: using Register based " 2324 2337 "invalidation\n", 2338 + iommu->seq_id, 2325 2339 (unsigned long long)drhd->reg_base_addr); 2326 2340 } else { 2327 2341 iommu->flush.flush_context = qi_flush_context; 2328 2342 iommu->flush.flush_iotlb = qi_flush_iotlb; 2329 - printk(KERN_INFO "IOMMU 0x%Lx: using Queued " 2343 + printk(KERN_INFO "IOMMU %d 0x%Lx: using Queued " 2330 2344 "invalidation\n", 2345 + iommu->seq_id, 2331 2346 (unsigned long long)drhd->reg_base_addr); 2332 2347 } 2333 2348 } ··· 2610 2621 2611 2622 /* it's a non-present to present mapping. Only flush if caching mode */ 2612 2623 if (cap_caching_mode(iommu->cap)) 2613 - iommu_flush_iotlb_psi(iommu, 0, mm_to_dma_pfn(iova->pfn_lo), size); 2624 + iommu_flush_iotlb_psi(iommu, domain->id, mm_to_dma_pfn(iova->pfn_lo), size, 1); 2614 2625 else 2615 2626 iommu_flush_write_buffer(iommu); 2616 2627 ··· 2650 2661 if (!deferred_flush[i].next) 2651 2662 continue; 2652 2663 2653 - iommu->flush.flush_iotlb(iommu, 0, 0, 0, 2664 + /* In caching mode, global flushes turn emulation expensive */ 2665 + if (!cap_caching_mode(iommu->cap)) 2666 + iommu->flush.flush_iotlb(iommu, 0, 0, 0, 2654 2667 DMA_TLB_GLOBAL_FLUSH); 2655 2668 for (j = 0; j < deferred_flush[i].next; j++) { 2656 2669 unsigned long mask; 2657 2670 struct iova *iova = deferred_flush[i].iova[j]; 2671 + struct dmar_domain *domain = deferred_flush[i].domain[j]; 2658 2672 2659 - mask = ilog2(mm_to_dma_pfn(iova->pfn_hi - iova->pfn_lo + 1)); 2660 - iommu_flush_dev_iotlb(deferred_flush[i].domain[j], 2661 - (uint64_t)iova->pfn_lo << PAGE_SHIFT, mask); 2673 + /* On real hardware multiple invalidations are expensive */ 2674 + if (cap_caching_mode(iommu->cap)) 2675 + iommu_flush_iotlb_psi(iommu, domain->id, 2676 + iova->pfn_lo, iova->pfn_hi - iova->pfn_lo + 1, 0); 2677 + else { 2678 + mask = ilog2(mm_to_dma_pfn(iova->pfn_hi - iova->pfn_lo + 1)); 2679 + iommu_flush_dev_iotlb(deferred_flush[i].domain[j], 2680 + (uint64_t)iova->pfn_lo << PAGE_SHIFT, mask); 2681 + } 2662 2682 __free_iova(&deferred_flush[i].domain[j]->iovad, iova); 2663 2683 } 2664 2684 deferred_flush[i].next = 0; ··· 2748 2750 2749 2751 if (intel_iommu_strict) { 2750 2752 iommu_flush_iotlb_psi(iommu, domain->id, start_pfn, 2751 - last_pfn - start_pfn + 1); 2753 + last_pfn - start_pfn + 1, 0); 2752 2754 /* free iova */ 2753 2755 __free_iova(&domain->iovad, iova); 2754 2756 } else { ··· 2838 2840 2839 2841 if (intel_iommu_strict) { 2840 2842 iommu_flush_iotlb_psi(iommu, domain->id, start_pfn, 2841 - last_pfn - start_pfn + 1); 2843 + last_pfn - start_pfn + 1, 0); 2842 2844 /* free iova */ 2843 2845 __free_iova(&domain->iovad, iova); 2844 2846 } else { ··· 2872 2874 struct dmar_domain *domain; 2873 2875 size_t size = 0; 2874 2876 int prot = 0; 2875 - size_t offset_pfn = 0; 2876 2877 struct iova *iova = NULL; 2877 2878 int ret; 2878 2879 struct scatterlist *sg; ··· 2925 2928 2926 2929 /* it's a non-present to present mapping. Only flush if caching mode */ 2927 2930 if (cap_caching_mode(iommu->cap)) 2928 - iommu_flush_iotlb_psi(iommu, 0, start_vpfn, offset_pfn); 2931 + iommu_flush_iotlb_psi(iommu, domain->id, start_vpfn, size, 1); 2929 2932 else 2930 2933 iommu_flush_write_buffer(iommu); 2931 2934 ··· 3433 3436 /* domain id for virtual machine, it won't be set in context */ 3434 3437 static unsigned long vm_domid; 3435 3438 3436 - static int vm_domain_min_agaw(struct dmar_domain *domain) 3437 - { 3438 - int i; 3439 - int min_agaw = domain->agaw; 3440 - 3441 - i = find_first_bit(&domain->iommu_bmp, g_num_of_iommus); 3442 - for (; i < g_num_of_iommus; ) { 3443 - if (min_agaw > g_iommus[i]->agaw) 3444 - min_agaw = g_iommus[i]->agaw; 3445 - 3446 - i = find_next_bit(&domain->iommu_bmp, g_num_of_iommus, i+1); 3447 - } 3448 - 3449 - return min_agaw; 3450 - } 3451 - 3452 3439 static struct dmar_domain *iommu_alloc_vm_domain(void) 3453 3440 { 3454 3441 struct dmar_domain *domain; ··· 3493 3512 iommu = drhd->iommu; 3494 3513 3495 3514 ndomains = cap_ndoms(iommu->cap); 3496 - i = find_first_bit(iommu->domain_ids, ndomains); 3497 - for (; i < ndomains; ) { 3515 + for_each_set_bit(i, iommu->domain_ids, ndomains) { 3498 3516 if (iommu->domains[i] == domain) { 3499 3517 spin_lock_irqsave(&iommu->lock, flags); 3500 3518 clear_bit(i, iommu->domain_ids); ··· 3501 3521 spin_unlock_irqrestore(&iommu->lock, flags); 3502 3522 break; 3503 3523 } 3504 - i = find_next_bit(iommu->domain_ids, ndomains, i+1); 3505 3524 } 3506 3525 } 3507 3526 } ··· 3561 3582 struct pci_dev *pdev = to_pci_dev(dev); 3562 3583 struct intel_iommu *iommu; 3563 3584 int addr_width; 3564 - u64 end; 3565 3585 3566 3586 /* normally pdev is not mapped */ 3567 3587 if (unlikely(domain_context_mapped(pdev))) { ··· 3583 3605 3584 3606 /* check if this iommu agaw is sufficient for max mapped address */ 3585 3607 addr_width = agaw_to_width(iommu->agaw); 3586 - end = DOMAIN_MAX_ADDR(addr_width); 3587 - end = end & VTD_PAGE_MASK; 3588 - if (end < dmar_domain->max_addr) { 3589 - printk(KERN_ERR "%s: iommu agaw (%d) is not " 3608 + if (addr_width > cap_mgaw(iommu->cap)) 3609 + addr_width = cap_mgaw(iommu->cap); 3610 + 3611 + if (dmar_domain->max_addr > (1LL << addr_width)) { 3612 + printk(KERN_ERR "%s: iommu width (%d) is not " 3590 3613 "sufficient for the mapped address (%llx)\n", 3591 - __func__, iommu->agaw, dmar_domain->max_addr); 3614 + __func__, addr_width, dmar_domain->max_addr); 3592 3615 return -EFAULT; 3616 + } 3617 + dmar_domain->gaw = addr_width; 3618 + 3619 + /* 3620 + * Knock out extra levels of page tables if necessary 3621 + */ 3622 + while (iommu->agaw < dmar_domain->agaw) { 3623 + struct dma_pte *pte; 3624 + 3625 + pte = dmar_domain->pgd; 3626 + if (dma_pte_present(pte)) { 3627 + free_pgtable_page(dmar_domain->pgd); 3628 + dmar_domain->pgd = (struct dma_pte *)dma_pte_addr(pte); 3629 + } 3630 + dmar_domain->agaw--; 3593 3631 } 3594 3632 3595 3633 return domain_add_dev_info(dmar_domain, pdev, CONTEXT_TT_MULTI_LEVEL); ··· 3626 3632 { 3627 3633 struct dmar_domain *dmar_domain = domain->priv; 3628 3634 u64 max_addr; 3629 - int addr_width; 3630 3635 int prot = 0; 3631 3636 size_t size; 3632 3637 int ret; ··· 3640 3647 size = PAGE_SIZE << gfp_order; 3641 3648 max_addr = iova + size; 3642 3649 if (dmar_domain->max_addr < max_addr) { 3643 - int min_agaw; 3644 3650 u64 end; 3645 3651 3646 3652 /* check if minimum agaw is sufficient for mapped address */ 3647 - min_agaw = vm_domain_min_agaw(dmar_domain); 3648 - addr_width = agaw_to_width(min_agaw); 3649 - end = DOMAIN_MAX_ADDR(addr_width); 3650 - end = end & VTD_PAGE_MASK; 3653 + end = __DOMAIN_MAX_ADDR(dmar_domain->gaw) + 1; 3651 3654 if (end < max_addr) { 3652 - printk(KERN_ERR "%s: iommu agaw (%d) is not " 3655 + printk(KERN_ERR "%s: iommu width (%d) is not " 3653 3656 "sufficient for the mapped address (%llx)\n", 3654 - __func__, min_agaw, max_addr); 3657 + __func__, dmar_domain->gaw, max_addr); 3655 3658 return -EFAULT; 3656 3659 } 3657 3660 dmar_domain->max_addr = max_addr;
+3 -3
drivers/pci/intr_remapping.c
··· 832 832 return -1; 833 833 } 834 834 835 - printk(KERN_INFO "IOAPIC id %d under DRHD base" 836 - " 0x%Lx\n", scope->enumeration_id, 837 - drhd->address); 835 + printk(KERN_INFO "IOAPIC id %d under DRHD base " 836 + " 0x%Lx IOMMU %d\n", scope->enumeration_id, 837 + drhd->address, iommu->seq_id); 838 838 839 839 ir_parse_one_ioapic_scope(scope, iommu); 840 840 } else if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_HPET) {
+32 -2
include/asm-generic/bug.h
··· 25 25 }; 26 26 #endif /* __ASSEMBLY__ */ 27 27 28 - #define BUGFLAG_WARNING (1<<0) 28 + #define BUGFLAG_WARNING (1 << 0) 29 + #define BUGFLAG_TAINT(taint) (BUGFLAG_WARNING | ((taint) << 8)) 30 + #define BUG_GET_TAINT(bug) ((bug)->flags >> 8) 31 + 29 32 #endif /* CONFIG_GENERIC_BUG */ 30 33 31 34 /* ··· 59 56 * appear at runtime. Use the versions with printk format strings 60 57 * to provide better diagnostics. 61 58 */ 62 - #ifndef __WARN 59 + #ifndef __WARN_TAINT 63 60 #ifndef __ASSEMBLY__ 64 61 extern void warn_slowpath_fmt(const char *file, const int line, 65 62 const char *fmt, ...) __attribute__((format(printf, 3, 4))); 63 + extern void warn_slowpath_fmt_taint(const char *file, const int line, 64 + unsigned taint, const char *fmt, ...) 65 + __attribute__((format(printf, 4, 5))); 66 66 extern void warn_slowpath_null(const char *file, const int line); 67 67 #define WANT_WARN_ON_SLOWPATH 68 68 #endif 69 69 #define __WARN() warn_slowpath_null(__FILE__, __LINE__) 70 70 #define __WARN_printf(arg...) warn_slowpath_fmt(__FILE__, __LINE__, arg) 71 + #define __WARN_printf_taint(taint, arg...) \ 72 + warn_slowpath_fmt_taint(__FILE__, __LINE__, taint, arg) 71 73 #else 74 + #define __WARN() __WARN_TAINT(TAINT_WARN) 72 75 #define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0) 76 + #define __WARN_printf_taint(taint, arg...) \ 77 + do { printk(arg); __WARN_TAINT(taint); } while (0) 73 78 #endif 74 79 75 80 #ifndef WARN_ON ··· 97 86 unlikely(__ret_warn_on); \ 98 87 }) 99 88 #endif 89 + 90 + #define WARN_TAINT(condition, taint, format...) ({ \ 91 + int __ret_warn_on = !!(condition); \ 92 + if (unlikely(__ret_warn_on)) \ 93 + __WARN_printf_taint(taint, format); \ 94 + unlikely(__ret_warn_on); \ 95 + }) 100 96 101 97 #else /* !CONFIG_BUG */ 102 98 #ifndef HAVE_ARCH_BUG ··· 128 110 }) 129 111 #endif 130 112 113 + #define WARN_TAINT(condition, taint, format...) WARN_ON(condition) 114 + 131 115 #endif 132 116 133 117 #define WARN_ON_ONCE(condition) ({ \ ··· 148 128 \ 149 129 if (unlikely(__ret_warn_once)) \ 150 130 if (WARN(!__warned, format)) \ 131 + __warned = true; \ 132 + unlikely(__ret_warn_once); \ 133 + }) 134 + 135 + #define WARN_TAINT_ONCE(condition, taint, format...) ({ \ 136 + static bool __warned; \ 137 + int __ret_warn_once = !!(condition); \ 138 + \ 139 + if (unlikely(__ret_warn_once)) \ 140 + if (WARN_TAINT(!__warned, taint, format)) \ 151 141 __warned = true; \ 152 142 unlikely(__ret_warn_once); \ 153 143 })
+1
include/linux/kernel.h
··· 346 346 #define TAINT_OVERRIDDEN_ACPI_TABLE 8 347 347 #define TAINT_WARN 9 348 348 #define TAINT_CRAP 10 349 + #define TAINT_FIRMWARE_WORKAROUND 11 349 350 350 351 extern void dump_stack(void) __cold; 351 352
+10
include/linux/pci.h
··· 334 334 #endif 335 335 }; 336 336 337 + static inline struct pci_dev *pci_physfn(struct pci_dev *dev) 338 + { 339 + #ifdef CONFIG_PCI_IOV 340 + if (dev->is_virtfn) 341 + dev = dev->physfn; 342 + #endif 343 + 344 + return dev; 345 + } 346 + 337 347 extern struct pci_dev *alloc_pci_dev(void); 338 348 339 349 #define pci_dev_b(n) list_entry(n, struct pci_dev, bus_list)
+22 -4
kernel/panic.c
··· 178 178 { TAINT_OVERRIDDEN_ACPI_TABLE, 'A', ' ' }, 179 179 { TAINT_WARN, 'W', ' ' }, 180 180 { TAINT_CRAP, 'C', ' ' }, 181 + { TAINT_FIRMWARE_WORKAROUND, 'I', ' ' }, 181 182 }; 182 183 183 184 /** ··· 195 194 * 'A' - ACPI table overridden. 196 195 * 'W' - Taint on warning. 197 196 * 'C' - modules from drivers/staging are loaded. 197 + * 'I' - Working around severe firmware bug. 198 198 * 199 199 * The string is overwritten by the next call to print_tainted(). 200 200 */ ··· 367 365 va_list args; 368 366 }; 369 367 370 - static void warn_slowpath_common(const char *file, int line, void *caller, struct slowpath_args *args) 368 + static void warn_slowpath_common(const char *file, int line, void *caller, 369 + unsigned taint, struct slowpath_args *args) 371 370 { 372 371 const char *board; 373 372 ··· 384 381 print_modules(); 385 382 dump_stack(); 386 383 print_oops_end_marker(); 387 - add_taint(TAINT_WARN); 384 + add_taint(taint); 388 385 } 389 386 390 387 void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...) ··· 393 390 394 391 args.fmt = fmt; 395 392 va_start(args.args, fmt); 396 - warn_slowpath_common(file, line, __builtin_return_address(0), &args); 393 + warn_slowpath_common(file, line, __builtin_return_address(0), 394 + TAINT_WARN, &args); 397 395 va_end(args.args); 398 396 } 399 397 EXPORT_SYMBOL(warn_slowpath_fmt); 400 398 399 + void warn_slowpath_fmt_taint(const char *file, int line, 400 + unsigned taint, const char *fmt, ...) 401 + { 402 + struct slowpath_args args; 403 + 404 + args.fmt = fmt; 405 + va_start(args.args, fmt); 406 + warn_slowpath_common(file, line, __builtin_return_address(0), 407 + taint, &args); 408 + va_end(args.args); 409 + } 410 + EXPORT_SYMBOL(warn_slowpath_fmt_taint); 411 + 401 412 void warn_slowpath_null(const char *file, int line) 402 413 { 403 - warn_slowpath_common(file, line, __builtin_return_address(0), NULL); 414 + warn_slowpath_common(file, line, __builtin_return_address(0), 415 + TAINT_WARN, NULL); 404 416 } 405 417 EXPORT_SYMBOL(warn_slowpath_null); 406 418 #endif
+1 -1
lib/bug.c
··· 165 165 (void *)bugaddr); 166 166 167 167 show_regs(regs); 168 - add_taint(TAINT_WARN); 168 + add_taint(BUG_GET_TAINT(bug)); 169 169 return BUG_TRAP_TYPE_WARN; 170 170 } 171 171