All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Ian Campbell <Ian.Campbell@eu.citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	Allen M Kay <allen.m.kay@intel.com>,
	Jan Beulich <JBeulich@novell.com>
Subject: Re: [PATCH 5 of 7] IOMMU VTD BUG: disable Extended Interrupt Mode when disabling Interupt Remapping [Reformatted]
Date: Wed, 15 Jun 2011 15:49:07 +0100	[thread overview]
Message-ID: <4DF8C663.5020205@citrix.com> (raw)
In-Reply-To: <1308123946.6615.22.camel@dagon.hellion.org.uk>

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

Reformatted for staging unstable following Allen's suggestions.

The problem about panicking on the kexec path will be fixed in a later
reformatted patch.

-- 
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer
T: +44 (0)1223 225 900, http://www.citrix.com


[-- Attachment #2: iommu-fix-disable-IR.patch --]
[-- Type: text/x-patch, Size: 3729 bytes --]

IOMMU VTD BUG: disable Extended Interrupt Mode when disabling Interupt Remapping

Experimental evidence shows that Extended Interrupt Mode remains in
effect even after Interrupt Remapping is disabled in each DMAR Global
Command Register.  A consiquence of this is that when we switch from
x2apic mode back to xapic mode, and disable interrupt remapping for
the kdump kernel, interrupts passing through the IO APICs are in
x2apic format as opposed xapic.  This causes a triple fault in the
kexec kernel.

As EIM is explicitly set up each time Interrup Remapping is enabled,
it is safe for us to clobber this when taring down.

Also, change the header definition of IRTA_REG_EIME_SHIFT.  It caused
verbose and error-prone code, and was only used in 1 place before.  We
now have IRTA_EIME which is the specific bit in the register.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

diff -r 7925f452afb7 xen/drivers/passthrough/vtd/intremap.c
--- a/xen/drivers/passthrough/vtd/intremap.c	Wed Jun 15 14:36:03 2011 +0100
+++ b/xen/drivers/passthrough/vtd/intremap.c	Wed Jun 15 15:45:57 2011 +0100
@@ -811,27 +811,12 @@ int enable_intremap(struct iommu *iommu,
 void disable_intremap(struct iommu *iommu)
 {
     u32 sts;
+    u64 irta;
     unsigned long flags;
 
     if ( !ecap_intr_remap(iommu->ecap) )
         return;
 
-    /* If we are disabling Interrupt Remapping, make sure we dont stay in
-     * Extended Interrupt Mode, as this is unaffected by the Interrupt 
-     * Remapping flag in each DMAR Global Control Register.
-     * Specifically, local apics in xapic mode do not like interrupts delivered
-     * in x2apic mode.  Any code turning interrupt remapping back on will set
-     * EIME back correctly.
-     */
-    if ( iommu_supports_eim() )
-    {
-        u64 irta;
-        irta = dmar_readl(iommu->reg, DMAR_IRTA_REG);
-        dmar_writel(iommu->reg, DMAR_IRTA_REG, irta & ~IRTA_EIME);
-        IOMMU_WAIT_OP(iommu, DMAR_IRTA_REG, dmar_readl,
-                      !(irta & IRTA_EIME), irta);
-    }
-
     spin_lock_irqsave(&iommu->register_lock, flags);
     sts = dmar_readl(iommu->reg, DMAR_GSTS_REG);
     if ( !(sts & DMA_GSTS_IRES) )
@@ -841,6 +826,26 @@ void disable_intremap(struct iommu *iomm
 
     IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, dmar_readl,
                   !(sts & DMA_GSTS_IRES), sts);
+
+    /* If we are disabling Interrupt Remapping, make sure we dont stay in
+     * Extended Interrupt Mode, as this is unaffected by the Interrupt 
+     * Remapping flag in each DMAR Global Control Register.
+     * Specifically, local apics in xapic mode do not like interrupts delivered
+     * in x2apic mode.  Any code turning interrupt remapping back on will set
+     * EIME back correctly.
+     */
+    if ( !ecap_eim(iommu->ecap) )
+        goto out;
+
+    /* Can't read the register unless we ecaps says we can */
+    irta = dmar_readl(iommu->reg, DMAR_IRTA_REG);
+    if ( !(irta & IRTA_EIME) )
+        goto out;
+
+    dmar_writel(iommu->reg, DMAR_IRTA_REG, irta & ~IRTA_EIME);
+    IOMMU_WAIT_OP(iommu, DMAR_IRTA_REG, dmar_readl,
+                  !(irta & IRTA_EIME), irta);
+
 out:
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 }
diff -r 7925f452afb7 xen/drivers/passthrough/vtd/iommu.h
--- a/xen/drivers/passthrough/vtd/iommu.h	Wed Jun 15 14:36:03 2011 +0100
+++ b/xen/drivers/passthrough/vtd/iommu.h	Wed Jun 15 15:45:57 2011 +0100
@@ -471,7 +471,7 @@ struct qinval_entry {
 
 #define IEC_GLOBAL_INVL         0
 #define IEC_INDEX_INVL          1
-#define IRTA_EIME               (1 << 11)
+#define IRTA_EIME               (((u64)1) << 11)
 
 /* 2^(IRTA_REG_TABLE_SIZE + 1) = IREMAP_ENTRY_NR */
 #define IRTA_REG_TABLE_SIZE     ( IREMAP_PAGE_ORDER + 7 )

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

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

  reply	other threads:[~2011-06-15 14:49 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-13 17:02 [PATCH 0 of 7] Fix kexec in Xen (take 4) Andrew Cooper
2011-06-13 17:02 ` [PATCH 1 of 7] APIC BUG: fix potential Protection Fault during shutdown Andrew Cooper
2011-06-14  8:44   ` Jan Beulich
2011-06-14  9:44     ` Andrew Cooper
2011-06-13 17:02 ` [PATCH 2 of 7] KEXEC BUG: nmi_shootdown_cpus doesn't look after the interrupt flag Andrew Cooper
2011-06-14  8:46   ` Jan Beulich
2011-06-14  9:46     ` Keir Fraser
2011-06-15 11:01       ` [PATCH 2 of 7] KEXEC BUG: nmi_shootdown_cpus doesn't look after the interrupt flag [Reformatted] Andrew Cooper
2011-06-14  9:51     ` [PATCH 2 of 7] KEXEC BUG: nmi_shootdown_cpus doesn't look after the interrupt flag Andrew Cooper
2011-06-13 17:02 ` [PATCH 3 of 7] IOMMU: Sanitise pointer work Andrew Cooper
2011-06-13 18:13   ` Keir Fraser
2011-06-14  9:53     ` Andrew Cooper
2011-06-14 11:51       ` Keir Fraser
2011-06-13 17:02 ` [PATCH 4 of 7] APIC: record local APIC state on boot Andrew Cooper
2011-06-14  8:57   ` Jan Beulich
2011-06-14 10:48     ` Ian Campbell
2011-06-14 11:21       ` Jan Beulich
2011-06-15 12:33         ` [PATCH 4 of 7] APIC: record local APIC state on boot [Reformatted] Andrew Cooper
2011-06-15 12:42           ` Keir Fraser
2011-06-15 13:38             ` Andrew Cooper
2011-06-15 14:49               ` Andrew Cooper
2011-06-15 12:50           ` Jan Beulich
2011-06-13 17:02 ` [PATCH 5 of 7] IOMMU VTD BUG: disable Extended Interrupt Mode when disabling Interupt Remapping Andrew Cooper
2011-06-14  9:02   ` Jan Beulich
2011-06-14  9:59     ` Andrew Cooper
2011-06-14 21:20     ` Kay, Allen M
2011-06-15  6:48       ` Jan Beulich
2011-06-15  7:45         ` Ian Campbell
2011-06-15 14:49           ` Andrew Cooper [this message]
2011-06-14 21:45   ` Kay, Allen M
2011-06-13 17:02 ` [PATCH 6 of 7] IOMMU: add crash_shutdown iommu_op Andrew Cooper
2011-06-14 12:10   ` Keir Fraser
2011-06-15 12:50     ` Andrew Cooper
2011-06-14 22:15   ` Kay, Allen M
2011-06-15 13:06     ` Andrew Cooper
2011-06-15 16:39       ` Kay, Allen M
2011-06-15 15:00     ` [PATCH 6 of 7] IOMMU: add crash_shutdown iommu_op [Reformatted] Andrew Cooper
2011-06-13 17:02 ` [PATCH 7 of 7] KEXEC: correctly revert x2apic state when kexecing Andrew Cooper
2011-06-14 12:11   ` Keir Fraser
2011-06-14 13:05     ` Andrew Cooper
2011-06-13 18:15 ` [PATCH 0 of 7] Fix kexec in Xen (take 4) Keir Fraser
2011-06-16 13:05   ` Andrew Cooper
2011-06-16 13:13     ` Keir Fraser

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=4DF8C663.5020205@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Ian.Campbell@eu.citrix.com \
    --cc=JBeulich@novell.com \
    --cc=allen.m.kay@intel.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.