All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zhai, Edwin" <edwin.zhai@intel.com>
To: Keir Fraser <keir.fraser@eu.citrix.com>
Cc: xen-devel@lists.xensource.com, "Zhai, Edwin" <edwin.zhai@intel.com>
Subject: [PATCH][IOMMU] make vtd faults dmesg more readable
Date: Fri, 13 Nov 2009 17:36:31 +0800	[thread overview]
Message-ID: <4AFD289F.8070500@intel.com> (raw)

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

This simple patch makes the VTd faults dmesg more readable and helpful 
for debugging.

Signed-Off-By: Zhai Edwin <edwin.zhai@intel.com>


[-- Attachment #2: vtd_readable_faults.patch --]
[-- Type: application/octet-stream, Size: 4181 bytes --]

Index: xen-dev/xen/drivers/passthrough/vtd/iommu.c
===================================================================
--- xen-dev.orig/xen/drivers/passthrough/vtd/iommu.c
+++ xen-dev/xen/drivers/passthrough/vtd/iommu.c
@@ -664,24 +664,94 @@ static void iommu_disable_translation(st
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 }
 
+enum faulttype {
+    DMA_REMAP,
+    INTR_REMAP,
+    UNKNOWN,
+};
+
+static const char *dma_remap_fault_reasons[] =
+{
+    "Software",
+    "Present bit in root entry is clear",
+    "Present bit in context entry is clear",
+    "Invalid context entry",
+    "Access beyond MGAW",
+    "PTE Write access is not set",
+    "PTE Read access is not set",
+    "Next page table ptr is invalid",
+    "Root table address invalid",
+    "Context table ptr is invalid",
+    "non-zero reserved fields in RTP",
+    "non-zero reserved fields in CTP",
+    "non-zero reserved fields in PTE",
+    "Blocked a DMA translation request",
+};
+
+static const char *intr_remap_fault_reasons[] =
+{
+    "Detected reserved fields in the decoded interrupt-remapped request",
+    "Interrupt index exceeded the interrupt-remapping table size",
+    "Present field in the IRTE entry is clear",
+    "Error accessing interrupt-remapping table pointed by IRTA_REG",
+    "Detected reserved fields in the IRTE entry",
+    "Blocked a compatibility format interrupt request",
+    "Blocked an interrupt request due to source-id verification failure",
+};
+
+static const char *iommu_get_fault_reason(u8 fault_reason, int *fault_type)
+{
+    if ( fault_reason >= 0x20 && ( fault_reason < 0x20 +
+                ARRAY_SIZE(intr_remap_fault_reasons)) )
+    {
+        *fault_type = INTR_REMAP;
+        return intr_remap_fault_reasons[fault_reason - 0x20];
+    }
+    else if ( fault_reason < ARRAY_SIZE(dma_remap_fault_reasons) )
+    {
+        *fault_type = DMA_REMAP;
+        return dma_remap_fault_reasons[fault_reason];
+    }
+    else
+    {
+        *fault_type = UNKNOWN;
+        return "Unknown";
+    }
+}
+
 static struct iommu **irq_to_iommu;
 static int iommu_page_fault_do_one(struct iommu *iommu, int type,
                                    u8 fault_reason, u16 source_id, u64 addr)
 {
-    dprintk(XENLOG_WARNING VTDPREFIX,
-            "iommu_fault:%s: %x:%x.%x addr %"PRIx64" REASON %x "
-            "iommu->reg = %p\n",
-            (type ? "DMA Read" : "DMA Write"), (source_id >> 8),
-            PCI_SLOT(source_id & 0xFF), PCI_FUNC(source_id & 0xFF), addr,
-            fault_reason, iommu->reg);
-
+    const char *reason;
+    int fault_type;
+    reason = iommu_get_fault_reason(fault_reason, &fault_type);
+
+    if ( fault_type == DMA_REMAP )
+    {
+        dprintk(XENLOG_WARNING VTDPREFIX,
+                "DMAR:[%s] Request device [%02x:%02x.%d] "
+                "fault addr %"PRIx64", iommu reg = %p\n"
+                "DMAR:[fault reason %02xh] %s\n",
+                (type ? "DMA Read" : "DMA Write"),
+                (source_id >> 8), PCI_SLOT(source_id & 0xFF),
+                PCI_FUNC(source_id & 0xFF), addr, iommu->reg,
+                fault_reason, reason);
 #ifndef __i386__ /* map_domain_page() cannot be used in this context */
-    if ( fault_reason < 0x20 )
         print_vtd_entries(iommu, (source_id >> 8),
                           (source_id & 0xff), (addr >> PAGE_SHIFT));
 #endif
-
+    }
+    else
+        dprintk(XENLOG_WARNING VTDPREFIX,
+                "INTR-REMAP: Request device [%02x:%02x.%d] "
+                "fault index %"PRIx64", iommu reg = %p\n"
+                "INTR-REMAP:[fault reason %02xh] %s\n",
+                (source_id >> 8), PCI_SLOT(source_id & 0xFF),
+                PCI_FUNC(source_id & 0xFF), addr >> 48, iommu->reg,
+                fault_reason, reason);
     return 0;
+
 }
 
 static void iommu_fault_status(u32 fault_status)
@@ -718,9 +788,6 @@ static void iommu_page_fault(int irq, vo
     u32 fault_status;
     unsigned long flags;
 
-    dprintk(XENLOG_WARNING VTDPREFIX,
-            "iommu_page_fault: iommu->reg = %p\n", iommu->reg);
-
     fault_status = dmar_readl(iommu->reg, DMAR_FSTS_REG);
 
     iommu_fault_status(fault_status);

[-- 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:[~2009-11-13  9:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4AFD289F.8070500@intel.com \
    --to=edwin.zhai@intel.com \
    --cc=keir.fraser@eu.citrix.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.