aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-26 20:47:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-26 20:47:46 -0400
commit9f86262dcc573ca195488de9ec6e4d6d74288ad3 (patch)
treed320244d8c559597ead3108bf2bbfb135ab7fec0 /drivers/iommu
parent85f2901bdf4bdc0d034e1bbe8629e269ec200389 (diff)
parent03ecc32c5274962b9b1904d7a730e71c95bac05f (diff)
Merge git://git.infradead.org/intel-iommu
Pull intel iommu updates from David Woodhouse: "This lays a little of the groundwork for upcoming Shared Virtual Memory support — fixing some bogus #defines for capability bits and adding the new ones, and starting to use the new wider page tables where we can, in anticipation of actually filling in the new fields therein. It also allows graphics devices to be assigned to VM guests again. This got broken in 3.17 by disallowing assignment of RMRR-afflicted devices. Like USB, we do understand why there's an RMRR for graphics devices — and unlike USB, it's actually sane. So we can make an exception for graphics devices, just as we do USB controllers. Finally, tone down the warning about the X2APIC_OPT_OUT bit, due to persistent requests. X2APIC_OPT_OUT was added to the spec as a nasty hack to allow broken BIOSes to forbid us from using X2APIC when they do stupid and invasive things and would break if we did. Someone noticed that since Windows doesn't have full IOMMU support for DMA protection, setting the X2APIC_OPT_OUT bit made Windows avoid initialising the IOMMU on the graphics unit altogether. This means that it would be available for use in "driver mode", where the IOMMU registers are made available through a BAR of the graphics device and the graphics driver can do SVM all for itself. So they started setting the X2APIC_OPT_OUT bit on *all* platforms with SVM capabilities. And even the platforms which *might*, if the planets had been aligned correctly, possibly have had SVM capability but which in practice actually don't" * git://git.infradead.org/intel-iommu: iommu/vt-d: support extended root and context entries iommu/vt-d: Add new extended capabilities from v2.3 VT-d specification iommu/vt-d: Allow RMRR on graphics devices too iommu/vt-d: Print x2apic opt out info instead of printing a warning iommu/vt-d: kill bogus ecap_niotlb_iunits()
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/intel-iommu.c142
-rw-r--r--drivers/iommu/intel_irq_remapping.c5
2 files changed, 67 insertions, 80 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a35927cd42e5..68d43beccb7e 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -50,6 +50,7 @@
50#define CONTEXT_SIZE VTD_PAGE_SIZE 50#define CONTEXT_SIZE VTD_PAGE_SIZE
51 51
52#define IS_GFX_DEVICE(pdev) ((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY) 52#define IS_GFX_DEVICE(pdev) ((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY)
53#define IS_USB_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_SERIAL_USB)
53#define IS_ISA_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA) 54#define IS_ISA_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA)
54#define IS_AZALIA(pdev) ((pdev)->vendor == 0x8086 && (pdev)->device == 0x3a3e) 55#define IS_AZALIA(pdev) ((pdev)->vendor == 0x8086 && (pdev)->device == 0x3a3e)
55 56
@@ -184,32 +185,11 @@ static int force_on = 0;
184 * 64-127: Reserved 185 * 64-127: Reserved
185 */ 186 */
186struct root_entry { 187struct root_entry {
187 u64 val; 188 u64 lo;
188 u64 rsvd1; 189 u64 hi;
189}; 190};
190#define ROOT_ENTRY_NR (VTD_PAGE_SIZE/sizeof(struct root_entry)) 191#define ROOT_ENTRY_NR (VTD_PAGE_SIZE/sizeof(struct root_entry))
191static inline bool root_present(struct root_entry *root)
192{
193 return (root->val & 1);
194}
195static inline void set_root_present(struct root_entry *root)
196{
197 root->val |= 1;
198}
199static inline void set_root_value(struct root_entry *root, unsigned long value)
200{
201 root->val &= ~VTD_PAGE_MASK;
202 root->val |= value & VTD_PAGE_MASK;
203}
204 192
205static inline struct context_entry *
206get_context_addr_from_root(struct root_entry *root)
207{
208 return (struct context_entry *)
209 (root_present(root)?phys_to_virt(
210 root->val & VTD_PAGE_MASK) :
211 NULL);
212}
213 193
214/* 194/*
215 * low 64 bits: 195 * low 64 bits:
@@ -682,6 +662,40 @@ static void domain_update_iommu_cap(struct dmar_domain *domain)
682 domain->iommu_superpage = domain_update_iommu_superpage(NULL); 662 domain->iommu_superpage = domain_update_iommu_superpage(NULL);
683} 663}
684 664
665static inline struct context_entry *iommu_context_addr(struct intel_iommu *iommu,
666 u8 bus, u8 devfn, int alloc)
667{
668 struct root_entry *root = &iommu->root_entry[bus];
669 struct context_entry *context;
670 u64 *entry;
671
672 if (ecap_ecs(iommu->ecap)) {
673 if (devfn >= 0x80) {
674 devfn -= 0x80;
675 entry = &root->hi;
676 }
677 devfn *= 2;
678 }
679 entry = &root->lo;
680 if (*entry & 1)
681 context = phys_to_virt(*entry & VTD_PAGE_MASK);
682 else {
683 unsigned long phy_addr;
684 if (!alloc)
685 return NULL;
686
687 context = alloc_pgtable_page(iommu->node);
688 if (!context)
689 return NULL;
690
691 __iommu_flush_cache(iommu, (void *)context, CONTEXT_SIZE);
692 phy_addr = virt_to_phys((void *)context);
693 *entry = phy_addr | 1;
694 __iommu_flush_cache(iommu, entry, sizeof(*entry));
695 }
696 return &context[devfn];
697}
698
685static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn) 699static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn)
686{ 700{
687 struct dmar_drhd_unit *drhd = NULL; 701 struct dmar_drhd_unit *drhd = NULL;
@@ -741,75 +755,36 @@ static void domain_flush_cache(struct dmar_domain *domain,
741 clflush_cache_range(addr, size); 755 clflush_cache_range(addr, size);
742} 756}
743 757
744/* Gets context entry for a given bus and devfn */
745static struct context_entry * device_to_context_entry(struct intel_iommu *iommu,
746 u8 bus, u8 devfn)
747{
748 struct root_entry *root;
749 struct context_entry *context;
750 unsigned long phy_addr;
751 unsigned long flags;
752
753 spin_lock_irqsave(&iommu->lock, flags);
754 root = &iommu->root_entry[bus];
755 context = get_context_addr_from_root(root);
756 if (!context) {
757 context = (struct context_entry *)
758 alloc_pgtable_page(iommu->node);
759 if (!context) {
760 spin_unlock_irqrestore(&iommu->lock, flags);
761 return NULL;
762 }
763 __iommu_flush_cache(iommu, (void *)context, CONTEXT_SIZE);
764 phy_addr = virt_to_phys((void *)context);
765 set_root_value(root, phy_addr);
766 set_root_present(root);
767 __iommu_flush_cache(iommu, root, sizeof(*root));
768 }
769 spin_unlock_irqrestore(&iommu->lock, flags);
770 return &context[devfn];
771}
772
773static int device_context_mapped(struct intel_iommu *iommu, u8 bus, u8 devfn) 758static int device_context_mapped(struct intel_iommu *iommu, u8 bus, u8 devfn)
774{ 759{
775 struct root_entry *root;
776 struct context_entry *context; 760 struct context_entry *context;
777 int ret; 761 int ret = 0;
778 unsigned long flags; 762 unsigned long flags;
779 763
780 spin_lock_irqsave(&iommu->lock, flags); 764 spin_lock_irqsave(&iommu->lock, flags);
781 root = &iommu->root_entry[bus]; 765 context = iommu_context_addr(iommu, bus, devfn, 0);
782 context = get_context_addr_from_root(root); 766 if (context)
783 if (!context) { 767 ret = context_present(context);
784 ret = 0;
785 goto out;
786 }
787 ret = context_present(&context[devfn]);
788out:
789 spin_unlock_irqrestore(&iommu->lock, flags); 768 spin_unlock_irqrestore(&iommu->lock, flags);
790 return ret; 769 return ret;
791} 770}
792 771
793static void clear_context_table(struct intel_iommu *iommu, u8 bus, u8 devfn) 772static void clear_context_table(struct intel_iommu *iommu, u8 bus, u8 devfn)
794{ 773{
795 struct root_entry *root;
796 struct context_entry *context; 774 struct context_entry *context;
797 unsigned long flags; 775 unsigned long flags;
798 776
799 spin_lock_irqsave(&iommu->lock, flags); 777 spin_lock_irqsave(&iommu->lock, flags);
800 root = &iommu->root_entry[bus]; 778 context = iommu_context_addr(iommu, bus, devfn, 0);
801 context = get_context_addr_from_root(root);
802 if (context) { 779 if (context) {
803 context_clear_entry(&context[devfn]); 780 context_clear_entry(context);
804 __iommu_flush_cache(iommu, &context[devfn], \ 781 __iommu_flush_cache(iommu, context, sizeof(*context));
805 sizeof(*context));
806 } 782 }
807 spin_unlock_irqrestore(&iommu->lock, flags); 783 spin_unlock_irqrestore(&iommu->lock, flags);
808} 784}
809 785
810static void free_context_table(struct intel_iommu *iommu) 786static void free_context_table(struct intel_iommu *iommu)
811{ 787{
812 struct root_entry *root;
813 int i; 788 int i;
814 unsigned long flags; 789 unsigned long flags;
815 struct context_entry *context; 790 struct context_entry *context;
@@ -819,10 +794,17 @@ static void free_context_table(struct intel_iommu *iommu)
819 goto out; 794 goto out;
820 } 795 }
821 for (i = 0; i < ROOT_ENTRY_NR; i++) { 796 for (i = 0; i < ROOT_ENTRY_NR; i++) {
822 root = &iommu->root_entry[i]; 797 context = iommu_context_addr(iommu, i, 0, 0);
823 context = get_context_addr_from_root(root); 798 if (context)
799 free_pgtable_page(context);
800
801 if (!ecap_ecs(iommu->ecap))
802 continue;
803
804 context = iommu_context_addr(iommu, i, 0x80, 0);
824 if (context) 805 if (context)
825 free_pgtable_page(context); 806 free_pgtable_page(context);
807
826 } 808 }
827 free_pgtable_page(iommu->root_entry); 809 free_pgtable_page(iommu->root_entry);
828 iommu->root_entry = NULL; 810 iommu->root_entry = NULL;
@@ -1146,14 +1128,16 @@ static int iommu_alloc_root_entry(struct intel_iommu *iommu)
1146 1128
1147static void iommu_set_root_entry(struct intel_iommu *iommu) 1129static void iommu_set_root_entry(struct intel_iommu *iommu)
1148{ 1130{
1149 void *addr; 1131 u64 addr;
1150 u32 sts; 1132 u32 sts;
1151 unsigned long flag; 1133 unsigned long flag;
1152 1134
1153 addr = iommu->root_entry; 1135 addr = virt_to_phys(iommu->root_entry);
1136 if (ecap_ecs(iommu->ecap))
1137 addr |= DMA_RTADDR_RTT;
1154 1138
1155 raw_spin_lock_irqsave(&iommu->register_lock, flag); 1139 raw_spin_lock_irqsave(&iommu->register_lock, flag);
1156 dmar_writeq(iommu->reg + DMAR_RTADDR_REG, virt_to_phys(addr)); 1140 dmar_writeq(iommu->reg + DMAR_RTADDR_REG, addr);
1157 1141
1158 writel(iommu->gcmd | DMA_GCMD_SRTP, iommu->reg + DMAR_GCMD_REG); 1142 writel(iommu->gcmd | DMA_GCMD_SRTP, iommu->reg + DMAR_GCMD_REG);
1159 1143
@@ -1800,7 +1784,9 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
1800 BUG_ON(translation != CONTEXT_TT_PASS_THROUGH && 1784 BUG_ON(translation != CONTEXT_TT_PASS_THROUGH &&
1801 translation != CONTEXT_TT_MULTI_LEVEL); 1785 translation != CONTEXT_TT_MULTI_LEVEL);
1802 1786
1803 context = device_to_context_entry(iommu, bus, devfn); 1787 spin_lock_irqsave(&iommu->lock, flags);
1788 context = iommu_context_addr(iommu, bus, devfn, 1);
1789 spin_unlock_irqrestore(&iommu->lock, flags);
1804 if (!context) 1790 if (!context)
1805 return -ENOMEM; 1791 return -ENOMEM;
1806 spin_lock_irqsave(&iommu->lock, flags); 1792 spin_lock_irqsave(&iommu->lock, flags);
@@ -2564,6 +2550,10 @@ static bool device_has_rmrr(struct device *dev)
2564 * In both cases we assume that PCI USB devices with RMRRs have them largely 2550 * In both cases we assume that PCI USB devices with RMRRs have them largely
2565 * for historical reasons and that the RMRR space is not actively used post 2551 * for historical reasons and that the RMRR space is not actively used post
2566 * boot. This exclusion may change if vendors begin to abuse it. 2552 * boot. This exclusion may change if vendors begin to abuse it.
2553 *
2554 * The same exception is made for graphics devices, with the requirement that
2555 * any use of the RMRR regions will be torn down before assigning the device
2556 * to a guest.
2567 */ 2557 */
2568static bool device_is_rmrr_locked(struct device *dev) 2558static bool device_is_rmrr_locked(struct device *dev)
2569{ 2559{
@@ -2573,7 +2563,7 @@ static bool device_is_rmrr_locked(struct device *dev)
2573 if (dev_is_pci(dev)) { 2563 if (dev_is_pci(dev)) {
2574 struct pci_dev *pdev = to_pci_dev(dev); 2564 struct pci_dev *pdev = to_pci_dev(dev);
2575 2565
2576 if ((pdev->class >> 8) == PCI_CLASS_SERIAL_USB) 2566 if (IS_USB_DEVICE(pdev) || IS_GFX_DEVICE(pdev))
2577 return false; 2567 return false;
2578 } 2568 }
2579 2569
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index 6c25b3c5b729..5709ae9c3e77 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -637,10 +637,7 @@ static int __init intel_enable_irq_remapping(void)
637 if (x2apic_supported()) { 637 if (x2apic_supported()) {
638 eim = !dmar_x2apic_optout(); 638 eim = !dmar_x2apic_optout();
639 if (!eim) 639 if (!eim)
640 printk(KERN_WARNING 640 pr_info("x2apic is disabled because BIOS sets x2apic opt out bit. You can use 'intremap=no_x2apic_optout' to override the BIOS setting.\n");
641 "Your BIOS is broken and requested that x2apic be disabled.\n"
642 "This will slightly decrease performance.\n"
643 "Use 'intremap=no_x2apic_optout' to override BIOS request.\n");
644 } 641 }
645 642
646 for_each_iommu(iommu, drhd) { 643 for_each_iommu(iommu, drhd) {