xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] IOMMU: don't disable bus mastering on faults for devices used by Xen or Dom0
@ 2012-11-05 16:53 Jan Beulich
  2012-11-05 17:15 ` Keir Fraser
  2012-11-30  9:42 ` [PATCH] IOMMU: don't disable bus mastering on faults for devices used by Xen or Dom0 Keir Fraser
  0 siblings, 2 replies; 26+ messages in thread
From: Jan Beulich @ 2012-11-05 16:53 UTC (permalink / raw)
  To: wei.huang2, weiwang.dd, xiantao.zhang
  Cc: Tim Deegan, Dario Faggioli, xen-devel

[-- Attachment #1: Type: text/plain, Size: 3336 bytes --]

Under the assumption that in these cases recurring faults aren't a
security issue and it can be expected that the drivers there are going
to try to take care of the problem.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/drivers/passthrough/amd/iommu_init.c
+++ b/xen/drivers/passthrough/amd/iommu_init.c
@@ -625,6 +625,18 @@ static void parse_event_log_entry(struct
         for ( bdf = 0; bdf < ivrs_bdf_entries; bdf++ )
             if ( get_dma_requestor_id(iommu->seg, bdf) == device_id )
             {
+                const struct pci_dev *pdev;
+
+                spin_lock(&pcidevs_lock);
+                pdev = pci_get_pdev(iommu->seg, PCI_BUS(bdf), PCI_DEVFN2(bdf));
+                if ( pdev && pdev->domain != dom_xen &&
+                     (!pdev->domain || !IS_PRIV(pdev->domain)) )
+                    pdev = NULL;
+                spin_unlock(&pcidevs_lock);
+
+                if ( pdev )
+                    continue;
+
                 cword = pci_conf_read16(iommu->seg, PCI_BUS(bdf),
                                         PCI_SLOT(bdf), PCI_FUNC(bdf),
                                         PCI_COMMAND);
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -916,7 +916,8 @@ static void __do_iommu_page_fault(struct
     reg = cap_fault_reg_offset(iommu->cap);
     while (1)
     {
-        u8 fault_reason;
+        const struct pci_dev *pdev;
+        u8 fault_reason, bus;
         u16 source_id, cword;
         u32 data;
         u64 guest_addr;
@@ -950,14 +951,27 @@ static void __do_iommu_page_fault(struct
         iommu_page_fault_do_one(iommu, type, fault_reason,
                                 source_id, guest_addr);
 
-        /* Tell the device to stop DMAing; we can't rely on the guest to
-         * control it for us. */
-        cword = pci_conf_read16(iommu->intel->drhd->segment,
-                                PCI_BUS(source_id), PCI_SLOT(source_id),
-                                PCI_FUNC(source_id), PCI_COMMAND);
-        pci_conf_write16(iommu->intel->drhd->segment, PCI_BUS(source_id),
-                         PCI_SLOT(source_id), PCI_FUNC(source_id),
-                         PCI_COMMAND, cword & ~PCI_COMMAND_MASTER);
+        bus = PCI_BUS(source_id);
+
+        spin_lock(&pcidevs_lock);
+        pdev = pci_get_pdev(iommu->intel->drhd->segment, bus,
+                            PCI_DEVFN2(source_id));
+        if ( pdev && pdev->domain != dom_xen &&
+             (!pdev->domain || !IS_PRIV(pdev->domain)) )
+            pdev = NULL;
+        spin_unlock(&pcidevs_lock);
+
+        if ( !pdev )
+        {
+            /* Tell the device to stop DMAing; we can't rely on the guest to
+             * control it for us. */
+            cword = pci_conf_read16(iommu->intel->drhd->segment, bus,
+                                    PCI_SLOT(source_id), PCI_FUNC(source_id),
+                                    PCI_COMMAND);
+            pci_conf_write16(iommu->intel->drhd->segment, bus,
+                             PCI_SLOT(source_id), PCI_FUNC(source_id),
+                             PCI_COMMAND, cword & ~PCI_COMMAND_MASTER);
+        }
 
         fault_index++;
         if ( fault_index > cap_num_fault_regs(iommu->cap) )




[-- Attachment #2: IOMMU-disable-BM-not-dom0.patch --]
[-- Type: text/plain, Size: 3410 bytes --]

IOMMU: don't disable bus mastering on faults for devices used by Xen or Dom0

Under the assumption that in these cases recurring faults aren't a
security issue and it can be expected that the drivers there are going
to try to take care of the problem.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/drivers/passthrough/amd/iommu_init.c
+++ b/xen/drivers/passthrough/amd/iommu_init.c
@@ -625,6 +625,18 @@ static void parse_event_log_entry(struct
         for ( bdf = 0; bdf < ivrs_bdf_entries; bdf++ )
             if ( get_dma_requestor_id(iommu->seg, bdf) == device_id )
             {
+                const struct pci_dev *pdev;
+
+                spin_lock(&pcidevs_lock);
+                pdev = pci_get_pdev(iommu->seg, PCI_BUS(bdf), PCI_DEVFN2(bdf));
+                if ( pdev && pdev->domain != dom_xen &&
+                     (!pdev->domain || !IS_PRIV(pdev->domain)) )
+                    pdev = NULL;
+                spin_unlock(&pcidevs_lock);
+
+                if ( pdev )
+                    continue;
+
                 cword = pci_conf_read16(iommu->seg, PCI_BUS(bdf),
                                         PCI_SLOT(bdf), PCI_FUNC(bdf),
                                         PCI_COMMAND);
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -916,7 +916,8 @@ static void __do_iommu_page_fault(struct
     reg = cap_fault_reg_offset(iommu->cap);
     while (1)
     {
-        u8 fault_reason;
+        const struct pci_dev *pdev;
+        u8 fault_reason, bus;
         u16 source_id, cword;
         u32 data;
         u64 guest_addr;
@@ -950,14 +951,27 @@ static void __do_iommu_page_fault(struct
         iommu_page_fault_do_one(iommu, type, fault_reason,
                                 source_id, guest_addr);
 
-        /* Tell the device to stop DMAing; we can't rely on the guest to
-         * control it for us. */
-        cword = pci_conf_read16(iommu->intel->drhd->segment,
-                                PCI_BUS(source_id), PCI_SLOT(source_id),
-                                PCI_FUNC(source_id), PCI_COMMAND);
-        pci_conf_write16(iommu->intel->drhd->segment, PCI_BUS(source_id),
-                         PCI_SLOT(source_id), PCI_FUNC(source_id),
-                         PCI_COMMAND, cword & ~PCI_COMMAND_MASTER);
+        bus = PCI_BUS(source_id);
+
+        spin_lock(&pcidevs_lock);
+        pdev = pci_get_pdev(iommu->intel->drhd->segment, bus,
+                            PCI_DEVFN2(source_id));
+        if ( pdev && pdev->domain != dom_xen &&
+             (!pdev->domain || !IS_PRIV(pdev->domain)) )
+            pdev = NULL;
+        spin_unlock(&pcidevs_lock);
+
+        if ( !pdev )
+        {
+            /* Tell the device to stop DMAing; we can't rely on the guest to
+             * control it for us. */
+            cword = pci_conf_read16(iommu->intel->drhd->segment, bus,
+                                    PCI_SLOT(source_id), PCI_FUNC(source_id),
+                                    PCI_COMMAND);
+            pci_conf_write16(iommu->intel->drhd->segment, bus,
+                             PCI_SLOT(source_id), PCI_FUNC(source_id),
+                             PCI_COMMAND, cword & ~PCI_COMMAND_MASTER);
+        }
 
         fault_index++;
         if ( fault_index > cap_num_fault_regs(iommu->cap) )

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2012-12-04  8:19 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-05 16:53 [PATCH] IOMMU: don't disable bus mastering on faults for devices used by Xen or Dom0 Jan Beulich
2012-11-05 17:15 ` Keir Fraser
2012-11-06  9:08   ` Jan Beulich
2012-11-06  9:44     ` Tim Deegan
2012-11-06 10:19       ` Jan Beulich
2012-11-06 12:08         ` Dario Faggioli
2012-11-06 12:38           ` Jan Beulich
2012-11-06 12:06       ` Dario Faggioli
2012-11-06 12:51         ` Jan Beulich
2012-11-06 13:58           ` Tim Deegan
2012-11-06 14:16             ` Dario Faggioli
2012-11-06 14:17             ` Jan Beulich
2012-11-06 14:29               ` Dario Faggioli
2012-11-08 12:42                 ` Tim Deegan
2012-11-06 14:24           ` Dario Faggioli
2012-11-07 16:05       ` [PATCH, v2] IOMMU: don't immediately disable bus mastering on faults Jan Beulich
2012-11-08 12:46         ` Tim Deegan
2012-11-08 13:46           ` Jan Beulich
2012-11-08 14:23             ` Tim Deegan
2012-11-08 18:07         ` Dario Faggioli
2012-11-30  9:42 ` [PATCH] IOMMU: don't disable bus mastering on faults for devices used by Xen or Dom0 Keir Fraser
2012-11-30  9:50   ` Jan Beulich
2012-12-03  6:08     ` Zhang, Xiantao
2012-12-03  7:36       ` Jan Beulich
2012-12-04  0:55         ` Zhang, Xiantao
2012-12-04  8:19           ` Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).