From: Dario Faggioli <raistlin@linux.it>
To: xen-devel@lists.xensource.com
Cc: Wei Wang2 <wei.wang2@amd.com>, Tim Deegan <tim@xen.org>,
"allen.m.kay@intel.com" <allen.m.kay@intel.com>,
Jan Beulich <JBeulich@suse.com>
Subject: PATCH 1 of 2] Move IOMMU faults handling into softirq for VT-d.
Date: Mon, 19 Dec 2011 19:51:55 +0100 [thread overview]
Message-ID: <1324320715.2599.32.camel@Solace> (raw)
In-Reply-To: <1324319661.2599.28.camel@Solace>
[-- Attachment #1.1.1: Type: text/plain, Size: 3033 bytes --]
Dealing with interrupts from VT-d IOMMU is deferred to a
softirq-tasklet, raised by the actual IRQ handler. Since a new interrupt
is not generated, even if further faults occur, until we cleared all the
pending ones, there's no need to disabling IRQs, as the hardware does it
by its own. Notice that this may cause the log to overflow, but none of
the existing entry will be overwritten.
Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
diff -r a4bffc85bb71 xen/drivers/passthrough/vtd/iommu.c
--- a/xen/drivers/passthrough/vtd/iommu.c Mon Dec 19 09:37:52 2011 +0100
+++ b/xen/drivers/passthrough/vtd/iommu.c Mon Dec 19 16:46:14 2011 +0000
@@ -53,6 +53,8 @@ bool_t __read_mostly untrusted_msi;
int nr_iommus;
+static struct tasklet vtd_fault_tasklet;
+
static void setup_dom0_device(struct pci_dev *);
static void setup_dom0_rmrr(struct domain *d);
@@ -918,10 +920,8 @@ static void iommu_fault_status(u32 fault
}
#define PRIMARY_FAULT_REG_LEN (16)
-static void iommu_page_fault(int irq, void *dev_id,
- struct cpu_user_regs *regs)
+static void __do_iommu_page_fault(struct iommu *iommu)
{
- struct iommu *iommu = dev_id;
int reg, fault_index;
u32 fault_status;
unsigned long flags;
@@ -996,6 +996,33 @@ clear_overflow:
}
}
+static void do_iommu_page_fault(unsigned long data)
+{
+ struct acpi_drhd_unit *drhd;
+
+ if ( list_empty(&acpi_drhd_units) )
+ {
+ INTEL_IOMMU_DEBUG("no device found, something must be very wrong!\n");
+ return;
+ }
+
+ /* No matter from whom the interrupt came from, check all the
+ * IOMMUs present in the system. This allows for having just one
+ * tasklet (instead of one per each IOMMU) and should be more than
+ * fine, considering how rare the event of a fault should be. */
+ for_each_drhd_unit ( drhd )
+ __do_iommu_page_fault(drhd->iommu);
+}
+
+static void iommu_page_fault(int irq, void *dev_id,
+ struct cpu_user_regs *regs)
+{
+ /* Just flag the tasklet as runnable. This is fine, according to VT-d
+ * specs since a new interrupt won't be generated until we clear all
+ * the faults that caused this one to happen. */
+ tasklet_schedule(&vtd_fault_tasklet);
+}
+
static void dma_msi_unmask(struct irq_desc *desc)
{
struct iommu *iommu = desc->action->dev_id;
@@ -2144,6 +2171,8 @@ int __init intel_vtd_setup(void)
iommu->irq = ret;
}
+ softirq_tasklet_init(&vtd_fault_tasklet, do_iommu_page_fault, 0);
+
if ( !iommu_qinval && iommu_intremap )
{
iommu_intremap = 0;
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-------------------------------------------------------------------
Dario Faggioli, http://retis.sssup.it/people/faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
PhD Candidate, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa (Italy)
[-- Attachment #1.1.2: iommu-fault-tasklet_vtd.patch --]
[-- Type: text/x-patch, Size: 1958 bytes --]
# HG changeset patch
# Parent e5b12488f07ebb95eec6caf6150f0edf58157494
diff -r e5b12488f07e xen/drivers/passthrough/vtd/iommu.c
--- a/xen/drivers/passthrough/vtd/iommu.c Tue Dec 13 17:29:12 2011 +0100
+++ b/xen/drivers/passthrough/vtd/iommu.c Wed Dec 14 10:08:45 2011 +0100
@@ -918,10 +918,9 @@ static void iommu_fault_status(u32 fault
}
#define PRIMARY_FAULT_REG_LEN (16)
-static void iommu_page_fault(int irq, void *dev_id,
- struct cpu_user_regs *regs)
+static void do_iommu_page_fault(unsigned long iommu_ptr)
{
- struct iommu *iommu = dev_id;
+ struct iommu *iommu = (struct iommu*) iommu_ptr;
int reg, fault_index;
u32 fault_status;
unsigned long flags;
@@ -996,6 +995,14 @@ clear_overflow:
}
}
+static void iommu_page_fault(int irq, void *dev_id,
+ struct cpu_user_regs *regs)
+{
+ struct iommu *iommu = dev_id;
+
+ tasklet_schedule(&iommu->fault_tasklet);
+}
+
static void dma_msi_unmask(struct irq_desc *desc)
{
struct iommu *iommu = desc->action->dev_id;
@@ -2142,6 +2149,9 @@ int __init intel_vtd_setup(void)
goto error;
}
iommu->irq = ret;
+
+ softirq_tasklet_init(&iommu->fault_tasklet, do_iommu_page_fault,
+ (unsigned long) drhd->iommu);
}
if ( !iommu_qinval && iommu_intremap )
diff -r e5b12488f07e xen/include/xen/iommu.h
--- a/xen/include/xen/iommu.h Tue Dec 13 17:29:12 2011 +0100
+++ b/xen/include/xen/iommu.h Wed Dec 14 10:08:45 2011 +0100
@@ -63,6 +63,7 @@ struct iommu {
spinlock_t register_lock; /* protect iommu register handling */
u64 root_maddr; /* root entry machine address */
int irq;
+ struct tasklet fault_tasklet;
struct intel_iommu *intel;
unsigned long *domid_bitmap; /* domain id bitmap */
u16 *domid_map; /* domain id mapping array */
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
[-- Attachment #2: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2011-12-19 18:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-19 18:34 [PATCH 0 of 3] Deal with IOMMU faults in softirq context Dario Faggioli
2011-12-19 18:51 ` Dario Faggioli [this message]
2011-12-19 18:53 ` [PATCH 2 of 2] Move IOMMU faults handling into softirq for AMD-Vi Dario Faggioli
2011-12-20 12:11 ` Wei Wang2
2011-12-20 12:23 ` Dario Faggioli
2011-12-20 9:36 ` [PATCH 0 of 3] Deal with IOMMU faults in softirq context Jan Beulich
2011-12-20 10:04 ` Dario Faggioli
2011-12-20 10:45 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1324320715.2599.32.camel@Solace \
--to=raistlin@linux.it \
--cc=JBeulich@suse.com \
--cc=allen.m.kay@intel.com \
--cc=tim@xen.org \
--cc=wei.wang2@amd.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.