Skip to contentSkip to conversation

IOMMU faults

DISCUSSION Tim Deegan 5 participants 12 messages Jun 16, 2011 – Jun 30, 2011

lore
Share & tools
lore

Tim Deegan

author
#0 lore raw

Hi, IOMMU maintainers,

What should Xen do when an IOMMU fault happens? As far as I can see both the AMD and Intel code clears the error in the IOMMU and carries on, but I suspect some more vigorous action is appropriate. I've seen traces from an Intel machine that seemed to be livelocked on IOMMU faults from a passed-through VGA card, until it was killed by the watchdog. I think I can see two things that contribute to that:

- The Intel IOMMU fault handler prints quite a lot of info in interrupt context, making it easier to livelock. Still I think the general problem applies on AMD too.
- Domain destruction re-assigns passed though cards to dom0, but the cards don't seem to get reset. So there's nothing to stop a card battering away at DMA in the meantime. That seems like a problem independent of livelock, actually.

In any case, it seems like it would be a good idea to stop a broken/malicious/deassigned card from flooding Xen with IOMMU faults.

I was considering just writing 0 to the faulting card's PCI command register, but I'm told that's not always enough to properly deactivate a card, and it might be a little over-zealous to do it on the first offence.

Ideas?

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#1 lore raw
Quoted 20 lines · Tim Deegan

Hi, IOMMU maintainers,

What should Xen do when an IOMMU fault happens? As far as I can see both the AMD and Intel code clears the error in the IOMMU and carries on, but I suspect some more vigorous action is appropriate. I've seen traces from an Intel machine that seemed to be livelocked on IOMMU faults from a passed-through VGA card, until it was killed by the watchdog. I think I can see two things that contribute to that:

- The Intel IOMMU fault handler prints quite a lot of info in interrupt context, making it easier to livelock. Still I think the general problem applies on AMD too.
- Domain destruction re-assigns passed though cards to dom0, but the cards don't seem to get reset. So there's nothing to stop a card battering away at DMA in the meantime. That seems like a problem independent of livelock, actually.

In any case, it seems like it would be a good idea to stop a broken/malicious/deassigned card from flooding Xen with IOMMU faults.

Quoted 7 lines

I was considering just writing 0 to the faulting card's PCI command register, but I'm told that's not always enough to properly deactivate a card, and it might be a little over-zealous to do it on the first offence.

Ideas?

Hi Tim,

We have seed such behavior when we were testing GPU assignement especially the Intel GPU. The problem is that domain destruction in Xen is assynchronous and right now the pci device reset is done in dom0 with some help of the toolstack.

In the Intel GPU case we need to make sure that the guest memory and the IOMMU are still in place while we perform to reset otherwise the device drift into an unstable state.

There is probably other ways to do that in a cleaner way but we decided to move the pci reset code into Xen, so we are sure we perform the reset while the device is in a known state (functionning state).

Attached is the patch we have in XenClient that move the pci reset into Xen. The modifications we have made to the VT-d code should go in the IOMMU generic section. I appologise but this patch is based on Xen 3.4, if we think this is the right way to do it, I can submit a proper patch against unstable and 4.1.

Regards,
Jean

xen/arch/x86/domain.c +0 -2
index feda3ba..2f5a69a 100644
@@ -510,8 +510,6 @@ void arch_domain_destroy(struct domain *d)
 
     pci_release_devices(d);
     free_domain_pirqs(d);
-    if ( !is_idle_domain(d) )
-        iommu_domain_destroy(d);
 
     paging_final_teardown(d);
 
xen/common/domain.c +1 -0
index 32f1d48..a7b0207 100644
@@ -385,6 +385,7 @@ int domain_kill(struct domain *d)
 	v4v_destroy(d);
         evtchn_destroy(d);
         gnttab_release_mappings(d);
+        iommu_domain_destroy(d);
         /* fallthrough */
     case DOMDYING_dying:
         rc = domain_relinquish_resources(d);
xen/drivers/passthrough/pci.c +75 -0

81 lines not on this page · raw message

xen/drivers/passthrough/vtd/Makefile +1 -0
index 0e6f163..00ba797 100644
@@ -6,3 +6,4 @@ obj-y += dmar.o
 obj-y += utils.o
 obj-y += qinval.o
 obj-y += intremap.o
+obj-y += pci_reset.o
xen/drivers/passthrough/vtd/iommu.c +15 -1
index 687f3fd..df88dc7 100644
@@ -21,7 +21,6 @@
 
 #include <xen/irq.h>
 #include <xen/sched.h>
-#include <xen/xmalloc.h>
 #include <xen/mm.h>
 #include <xen/paging.h>
 #include <xen/domain_page.h>
@@ -32,11 +31,13 @@
 #include <xen/pci.h>
 #include <xen/pci_regs.h>
 #include <xen/keyhandler.h>
+#include <xen/xmalloc.h>
 #include <asm/msi.h>
 #include "iommu.h"
 #include "dmar.h"
 #include "extern.h"
 #include "vtd.h"
+#include "pci_reset.h"
 
 #define domain_iommu_domid(d) ((d)->arch.hvm_domain.hvm_iommu.iommu_domid)
 
@@ -1503,6 +1504,15 @@ static int reassign_device_ownership(
 
     if ( (drhd = acpi_find_matched_drhd_unit(pdev)) == NULL )
         return -ENODEV;
+
+    /* Only do the reset here if target isn't dom0.
+    ** For the reassign to dom0 it's done in the iommu_domain_teardown
+    ** function because reassign_device_ownership happen too late in
+    ** the process.
+    */
+    if (target->domain_id != 0)
+        pci_reset_device(bus, devfn);
+
     pdev_iommu = drhd->iommu;
     domain_context_unmap(source, bus, devfn);
 
@@ -1534,10 +1544,14 @@ static int reassign_device_ownership(
 void iommu_domain_teardown(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    struct pci_dev *pdev = NULL;
 
     if ( list_empty(&acpi_drhd_units) )
         return;
 
+    if ((pdev = pci_get_gfx(d)))
+        pci_reset_device(pdev->bus, pdev->devfn);
+
     spin_lock(&hd->mapping_lock);
     iommu_free_pagetable(hd->pgd_maddr, agaw_to_level(hd->agaw));
     hd->pgd_maddr = 0;
xen/include/xen/pci.h +3 -0
index 6827e0d..9ed6f60 100644
@@ -77,6 +77,9 @@ int pci_remove_device(u8 bus, u8 devfn);
 int pci_add_device_ext(u8 bus, u8 devfn, struct pci_dev_info *info);
 struct pci_dev *pci_get_pdev(int bus, int devfn);
 struct pci_dev *pci_get_pdev_by_domain(struct domain *d, int bus, int devfn);
+struct pci_dev *pci_match_pdev(int (*match)(struct pci_dev *));
+struct pci_dev *pci_get_bridge(u8 secondary);
+struct pci_dev *pci_get_gfx(struct domain *d);
 
 uint8_t pci_conf_read8(
     unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg);
xen/include/xen/pci_regs.h +12 -0
index 361554c..20b00e8 100644
@@ -210,6 +210,7 @@
 #define  PCI_CAP_ID_AGP3	0x0E	/* AGP Target PCI-PCI bridge */
 #define  PCI_CAP_ID_EXP 	0x10	/* PCI Express */
 #define  PCI_CAP_ID_MSIX	0x11	/* MSI-X */
+#define  PCI_CAP_ID_AF          0x13    /* PCI Advanced Features */
 #define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
 #define PCI_CAP_FLAGS		2	/* Capability defined flags (16 bits) */
 #define PCI_CAP_SIZEOF		4
@@ -315,6 +316,17 @@
 #define  PCI_CHSWP_EXT		0x40	/* ENUM# status - extraction */
 #define  PCI_CHSWP_INS		0x80	/* ENUM# status - insertion */
 
+/* PCI Advanced Feature registers */
+
+#define PCI_AF_LENGTH		2
+#define PCI_AF_CAP		3
+#define  PCI_AF_CAP_TP		0x01
+#define  PCI_AF_CAP_FLR		0x02
+#define PCI_AF_CTRL		4
+#define  PCI_AF_CTRL_FLR	0x01
+#define PCI_AF_STATUS		5
+#define  PCI_AF_STATUS_TP	0x01
+
 /* PCI-X registers */
 
 #define PCI_X_CMD		2	/* Modes & Features */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#2 lore raw

Hi Jean,

Quoted 8 lines · Jean Guyader

We have seed such behavior when we were testing GPU assignement especially the Intel GPU. The problem is that domain destruction in Xen is assynchronous and right now the pci device reset is done in dom0 with some help of the toolstack.

In the Intel GPU case we need to make sure that the guest memory and the IOMMU are still in place while we perform to reset otherwise the device drift into an unstable state.

Quoted 5 lines

There is probably other ways to do that in a cleaner way but we decided to move the pci reset code into Xen, so we are sure we perform the reset while the device is in a known state (functionning state).

Attached is the patch we have in XenClient that move the pci reset into Xen.

Thanks, Jean. This sounds like a good idea to me, though I'd like to hear Wei and Allen's opinions.

The patch is incomplete (missing the new pci_reset.[ch] files) but I get the general idea. A few questions:

- Why the special handling for one graphics device on each domain? (And if one, why not all?)
- Why not reset when the target is dom0? It seems like it can do no harm and should protect dom0 from assigning itself an active PCI card.

Of course, even with this patch, my original question still stands:
should Xen do something more assertive in the IOMMU fault handler?

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#3 lore raw
Quoted 2 lines · Tim Deegan

Hi Jean,

Reply below,

Quoted 13 lines
Quoted 12 lines · Jean Guyader

We have seed such behavior when we were testing GPU assignement especially the Intel GPU. The problem is that domain destruction in Xen is assynchronous and right now the pci device reset is done in dom0 with some help of the toolstack.

In the Intel GPU case we need to make sure that the guest memory and the IOMMU are still in place while we perform to reset otherwise the device drift into an unstable state.

There is probably other ways to do that in a cleaner way but we decided to move the pci reset code into Xen, so we are sure we perform the reset while the device is in a known state (functionning state).

Quoted 7 lines
Quoted 1 line

Attached is the patch we have in XenClient that move the pci reset into Xen.

Thanks, Jean. This sounds like a good idea to me, though I'd like to hear Wei and Allen's opinions.

The patch is incomplete (missing the new pci_reset.[ch] files) but I get the general idea. A few questions:

Reattach the full patch.

Quoted 3 lines

- Why the special handling for one graphics device on each domain? (And if one, why not all?)

No good reason really just a limitation of the patch, we can trivially get ride of the limitation.

Quoted 3 lines

- Why not reset when the target is dom0? It seems like it can do no harm and should protect dom0 from assigning itself an active PCI card.

Reset could be quiet expensive (couple of seconds sometimes). We did that to avoid a double reset on domain reboot. I agree that we should remove that, or extend the IOMMU API so we can reassign from domU to domU without going through dom0.

Quoted 4 lines

Of course, even with this patch, my original question still stands:
should Xen do something more assertive in the IOMMU fault handler?

What we really want to achive here is to stop DMA on this device. One way of doing it is to perform a proper PCI reset (FLR, secondary bus reset, ...) when that happens.

Jean

xen/arch/x86/domain.c +0 -2
index feda3ba..2f5a69a 100644
@@ -510,8 +510,6 @@ void arch_domain_destroy(struct domain *d)
 
     pci_release_devices(d);
     free_domain_pirqs(d);
-    if ( !is_idle_domain(d) )
-        iommu_domain_destroy(d);
 
     paging_final_teardown(d);
 
xen/common/domain.c +1 -0
index 32f1d48..a7b0207 100644
@@ -385,6 +385,7 @@ int domain_kill(struct domain *d)
 	v4v_destroy(d);
         evtchn_destroy(d);
         gnttab_release_mappings(d);
+        iommu_domain_destroy(d);
         /* fallthrough */
     case DOMDYING_dying:
         rc = domain_relinquish_resources(d);
xen/drivers/passthrough/pci.c +75 -0

81 lines not on this page · raw message

xen/drivers/passthrough/vtd/Makefile +1 -0
index 0e6f163..00ba797 100644
@@ -6,3 +6,4 @@ obj-y += dmar.o
 obj-y += utils.o
 obj-y += qinval.o
 obj-y += intremap.o
+obj-y += pci_reset.o
xen/drivers/passthrough/vtd/iommu.c +15 -1
index 687f3fd..df88dc7 100644
@@ -21,7 +21,6 @@
 
 #include <xen/irq.h>
 #include <xen/sched.h>
-#include <xen/xmalloc.h>
 #include <xen/mm.h>
 #include <xen/paging.h>
 #include <xen/domain_page.h>
@@ -32,11 +31,13 @@
 #include <xen/pci.h>
 #include <xen/pci_regs.h>
 #include <xen/keyhandler.h>
+#include <xen/xmalloc.h>
 #include <asm/msi.h>
 #include "iommu.h"
 #include "dmar.h"
 #include "extern.h"
 #include "vtd.h"
+#include "pci_reset.h"
 
 #define domain_iommu_domid(d) ((d)->arch.hvm_domain.hvm_iommu.iommu_domid)
 
@@ -1503,6 +1504,15 @@ static int reassign_device_ownership(
 
     if ( (drhd = acpi_find_matched_drhd_unit(pdev)) == NULL )
         return -ENODEV;
+
+    /* Only do the reset here if target isn't dom0.
+    ** For the reassign to dom0 it's done in the iommu_domain_teardown
+    ** function because reassign_device_ownership happen too late in
+    ** the process.
+    */
+    if (target->domain_id != 0)
+        pci_reset_device(bus, devfn);
+
     pdev_iommu = drhd->iommu;
     domain_context_unmap(source, bus, devfn);
 
@@ -1534,10 +1544,14 @@ static int reassign_device_ownership(
 void iommu_domain_teardown(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    struct pci_dev *pdev = NULL;
 
     if ( list_empty(&acpi_drhd_units) )
         return;
 
+    if ((pdev = pci_get_gfx(d)))
+        pci_reset_device(pdev->bus, pdev->devfn);
+
     spin_lock(&hd->mapping_lock);
     iommu_free_pagetable(hd->pgd_maddr, agaw_to_level(hd->agaw));
     hd->pgd_maddr = 0;
xen/drivers/passthrough/vtd/pci_reset.c new file +389 -0

389 lines not on this page · raw message

xen/drivers/passthrough/vtd/pci_reset.h new file +27 -0
new file mode 100644
index 0000000..dfd0872
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2011, Citrix Systems. 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Copyright (C) Julian Pidancet <[email protected]>
+ * Copyright (C) Jean Guyader <[email protected]>
+ */
+
+
+#ifndef PCI_RESET_H_
+# define PCI_RESET_H_
+
+void pci_reset_device(u8 bus, u8 devfn);
+
+#endif /* PCI_RESET_H_ */
xen/include/xen/pci.h +3 -0
index 6827e0d..9ed6f60 100644
@@ -77,6 +77,9 @@ int pci_remove_device(u8 bus, u8 devfn);
 int pci_add_device_ext(u8 bus, u8 devfn, struct pci_dev_info *info);
 struct pci_dev *pci_get_pdev(int bus, int devfn);
 struct pci_dev *pci_get_pdev_by_domain(struct domain *d, int bus, int devfn);
+struct pci_dev *pci_match_pdev(int (*match)(struct pci_dev *));
+struct pci_dev *pci_get_bridge(u8 secondary);
+struct pci_dev *pci_get_gfx(struct domain *d);
 
 uint8_t pci_conf_read8(
     unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg);
xen/include/xen/pci_regs.h +12 -0
index 361554c..20b00e8 100644
@@ -210,6 +210,7 @@
 #define  PCI_CAP_ID_AGP3	0x0E	/* AGP Target PCI-PCI bridge */
 #define  PCI_CAP_ID_EXP 	0x10	/* PCI Express */
 #define  PCI_CAP_ID_MSIX	0x11	/* MSI-X */
+#define  PCI_CAP_ID_AF          0x13    /* PCI Advanced Features */
 #define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
 #define PCI_CAP_FLAGS		2	/* Capability defined flags (16 bits) */
 #define PCI_CAP_SIZEOF		4
@@ -315,6 +316,17 @@
 #define  PCI_CHSWP_EXT		0x40	/* ENUM# status - extraction */
 #define  PCI_CHSWP_INS		0x80	/* ENUM# status - insertion */
 
+/* PCI Advanced Feature registers */
+
+#define PCI_AF_LENGTH		2
+#define PCI_AF_CAP		3
+#define  PCI_AF_CAP_TP		0x01
+#define  PCI_AF_CAP_FLR		0x02
+#define PCI_AF_CTRL		4
+#define  PCI_AF_CTRL_FLR	0x01
+#define PCI_AF_STATUS		5
+#define  PCI_AF_STATUS_TP	0x01
+
 /* PCI-X registers */
 
 #define PCI_X_CMD		2	/* Modes & Features */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#4 lore raw

Hi,

Quoted 6 lines · Jean Guyader
Quoted 2 lines

Of course, even with this patch, my original question still stands:
should Xen do something more assertive in the IOMMU fault handler?

What we really want to achive here is to stop DMA on this device. One way of doing it is to perform a proper PCI reset (FLR, secondary bus reset, ...) when that happens.

I think that's more or less a consensus then, that we should try to stop the device from the IOMMU fault handler.

Looking at your patch in a bit more detail, I see two things that worry me. The first is that the new pci_reset_device() function does nothing at all if the device isn't one of the particular graphics cards it know about!

The second is this comment:

xen/drivers/passthrough/vtd/pci_reset.c line 254

Quoted 2 lines
xen/drivers/passthrough/vtd/pci_reset.c new file +2 -0
+    /* Leave CMD MEMORY set otherwise the platform can crashe during FLR */
+    pci_conf_write16(bus, d, f, PCI_COMMAND, 2);

which implies that my current approach of just disabling the card might have pretty bad conequences. Can you expand on that? Would it be better just to mask out PCI_COMMAND_MASTER? And if I do that do I need to try and issue a reset as well (i.e. are there cards that are known to ignore this bit?)

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
author
#5 lore raw
Quoted 18 lines · Tim Deegan
Quoted 6 lines · Jean Guyader
Quoted 2 lines

Of course, even with this patch, my original question still stands:
should Xen do something more assertive in the IOMMU fault handler?

What we really want to achive here is to stop DMA on this device. One way of doing it is to perform a proper PCI reset (FLR, secondary bus reset, ...) when that happens.

I think that's more or less a consensus then, that we should try to stop the device from the IOMMU fault handler.

Looking at your patch in a bit more detail, I see two things that worry me. The first is that the new pci_reset_device() function does nothing at all if the device isn't one of the particular graphics cards it know about!

The second is this comment:

Quoted 8 lines

xen/drivers/passthrough/vtd/pci_reset.c line 254

Quoted 2 lines
xen/drivers/passthrough/vtd/pci_reset.c new file +2 -0
+    /* Leave CMD MEMORY set otherwise the platform can crashe during FLR */
+    pci_conf_write16(bus, d, f, PCI_COMMAND, 2);

which implies that my current approach of just disabling the card might have pretty bad conequences. Can you expand on that? Would it be better just to mask out PCI_COMMAND_MASTER? And if I do that do I need to try and issue a reset as well (i.e. are there cards that are known to ignore this bit?)

Ping?

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#6 lore raw
Quoted 9 lines · Tim Deegan
Quoted 8 lines · Tim Deegan
Quoted 6 lines · Jean Guyader
Quoted 2 lines

Of course, even with this patch, my original question still stands:
should Xen do something more assertive in the IOMMU fault handler?

What we really want to achive here is to stop DMA on this device. One way of doing it is to perform a proper PCI reset (FLR, secondary bus reset, ...) when that happens.

Quoted 8 lines
Quoted 8 lines

I think that's more or less a consensus then, that we should try to stop the device from the IOMMU fault handler.

Looking at your patch in a bit more detail, I see two things that worry me. The first is that the new pci_reset_device() function does nothing at all if the device isn't one of the particular graphics cards it know about!

In our case the reset of other devices is done using the classic Xen toolstack way in dom0. But the code could be easily changed to do a proper reset on all the type of devices.

Quoted 10 lines
Quoted 10 lines

The second is this comment:

xen/drivers/passthrough/vtd/pci_reset.c line 254

Quoted 2 lines
xen/drivers/passthrough/vtd/pci_reset.c new file +2 -0
+    /* Leave CMD MEMORY set otherwise the platform can crashe during FLR */
+    pci_conf_write16(bus, d, f, PCI_COMMAND, 2);

which implies that my current approach of just disabling the card might have pretty bad conequences. Can you expand on that? Would it be better just to mask out PCI_COMMAND_MASTER? And if I do that do I need to try and issue a reset as well (i.e. are there cards that are known to ignore this bit?)

Agreed, masking out PCI_COMMAND_MASTER should be enough, Linux only do that.

Jean

#7 lore raw
In reply to Tim Deegan
Quoted 9 lines · Alberto BozzoOn Thursday 16 June 2011 11:25:09 Tim Deegan wrote:

Hi, IOMMU maintainers,

What should Xen do when an IOMMU fault happens? As far as I can see both the AMD and Intel code clears the error in the IOMMU and carries on, but I suspect some more vigorous action is appropriate. I've seen traces from an Intel machine that seemed to be livelocked on IOMMU faults from a passed-through VGA card, until it was killed by the watchdog. I think I can see two things that contribute to that:

Quoted 3 lines

- The Intel IOMMU fault handler prints quite a lot of info in interrupt context, making it easier to livelock. Still I think the general problem applies on AMD too.

This info could still be useful for debugging, but we should only enable this for debug build.

Quoted 4 lines

- Domain destruction re-assigns passed though cards to dom0, but the cards don't seem to get reset. So there's nothing to stop a card battering away at DMA in the meantime. That seems like a problem independent of livelock, actually.

There should be some FLR codes in tools (both xm and xl). But this might not work well with some devices...

Quoted 2 lines

In any case, it seems like it would be a good idea to stop a broken/malicious/deassigned card from flooding Xen with IOMMU faults.

Yes, agree that. Actually I saw a lot could be improved in the fault handler. When iommu faults come from dma error, we should either stop the device from doing dma or inject errors to guest if the guest driver is able to handle io page fault.

Quoted 5 lines

I was considering just writing 0 to the faulting card's PCI command register, but I'm told that's not always enough to properly deactivate a card, and it might be a little over-zealous to do it on the first offence.
Ideas?

It seems difficult to find a generic approach to stop a device without knowing more device specific details...

Thanks,
Wei

Quoted 1 line

Tim.

#8 lore raw
Quoted 7 lines
Quoted 5 lines

I was considering just writing 0 to the faulting card's PCI command register, but I'm told that's not always enough to properly deactivate a card, and it might be a little over-zealous to do it on the first offence.
Ideas?

It seems difficult to find a generic approach to stop a device without knowing more device specific details...

Perhaps make something similar to the MCE fault interrupts? As in when the error happens, the Dom0 is notified of the offending BDF and persuses whatever action it thinks are neccessary. The action would be to tell the device driver to turn itself off. But how it would interact with the driver.. Well how does Linux deal with this today? Is there an extension to the device driver API (similar to the power) to notify the driver that it has done bad things and to shut itself off?

Perhaps similar to the PCIe AER handling?

author
#9 lore raw
Quoted 8 lines · Konrad Rzeszutek Wilk

Perhaps make something similar to the MCE fault interrupts? As in when the error happens, the Dom0 is notified of the offending BDF and persuses whatever action it thinks are neccessary. The action would be to tell the device driver to turn itself off. But how it would interact with the driver.. Well how does Linux deal with this today? Is there an extension to the device driver API (similar to the power) to notify the driver that it has done bad things and to shut itself off?

That sort of interface might be nice too, but I was worried more about badly-behaved guests or devices. In the livelock case the guest might never get to run so can't do anything, and a malicious guest would just ignore the message anyway.

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#10 lore raw
In reply to Tim Deegan
Quoted 3 lines

- The Intel IOMMU fault handler prints quite a lot of info in interrupt context, making it easier to livelock. Still I think the general problem applies on AMD too.

Someone at Intel looked into implementing measured rate printing in vt-d fault handler. He encountered some complications. I remember it had to do with measured rate printing not enabled by default (?). For now, I think having it print out only for debug case sounds simple enough. I will submit a patch for it.

Quoted 6 lines

- Domain destruction re-assigns passed though cards to dom0, but the cards don't seem to get reset. So there's nothing to stop a card battering away at DMA in the meantime. That seems like a problem independent of livelock, actually.

From reading the code in libxl, it seems libxl__device_pci_reset() is called by both libxl__device_pci_add() and do_pci_remove(). Isn't do_pci_remove() called when the pass through device is reassigned to dom0 during a domain teardown?

Allen

-----Original Message-----
From: Tim Deegan [mailto:[email protected]]
Sent: Thursday, June 16, 2011 2:25 AM
To: Kay, Allen M; Wei Wang
Cc: [email protected]; Jean Guyader
Subject: IOMMU faults

Hi, IOMMU maintainers,

What should Xen do when an IOMMU fault happens? As far as I can see both the AMD and Intel code clears the error in the IOMMU and carries on, but I suspect some more vigorous action is appropriate. I've seen traces from an Intel machine that seemed to be livelocked on IOMMU faults from a passed-through VGA card, until it was killed by the watchdog. I think I can see two things that contribute to that:

- The Intel IOMMU fault handler prints quite a lot of info in interrupt context, making it easier to livelock. Still I think the general problem applies on AMD too.
- Domain destruction re-assigns passed though cards to dom0, but the cards don't seem to get reset. So there's nothing to stop a card battering away at DMA in the meantime. That seems like a problem independent of livelock, actually.

In any case, it seems like it would be a good idea to stop a broken/malicious/deassigned card from flooding Xen with IOMMU faults.

I was considering just writing 0 to the faulting card's PCI command register, but I'm told that's not always enough to properly deactivate a card, and it might be a little over-zealous to do it on the first offence.

Ideas?

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
author
#11 lore raw
Quoted 6 lines · Allen M
Quoted 3 lines

- The Intel IOMMU fault handler prints quite a lot of info in interrupt context, making it easier to livelock. Still I think the general problem applies on AMD too.

Someone at Intel looked into implementing measured rate printing in vt-d fault handler. He encountered some complications. I remember it had to do with measured rate printing not enabled by default (?). For now, I think having it print out only for debug case sounds simple enough. I will submit a patch for it.

That's great, thanks.

Quoted 6 lines
Quoted 6 lines

- Domain destruction re-assigns passed though cards to dom0, but the cards don't seem to get reset. So there's nothing to stop a card battering away at DMA in the meantime. That seems like a problem independent of livelock, actually.

From reading the code in libxl, it seems libxl__device_pci_reset() is called by both libxl__device_pci_add() and do_pci_remove(). Isn't do_pci_remove() called when the pass through device is reassigned to dom0 during a domain teardown?

Libxl could be too late, though. When a domain is destroyed, its iommu tables get torn down in Xen. So if it has active devices:
- they can start raising IOMMU faults immediately, and in some circumstances libxl might never get to run.
- since deassign is implemented as "assign to dom0" they might start DMAing over dom0 memory.
If we can rely on the dom0 tools always completely resetting a domains's devices before calling domctl_destroydomain, that should never happen. That seems a bit fragile, though I guess dom0 can shoot itself in the foot in
enough other ways. I prefer Jean's reset-in-xen approach; it's only a few
hundred lines of code and we could reuse some of it for resetting badly-behaved cards from the IOMMU fault handler.

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)