From: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Cc: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>,
David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
jroedel-zLv9SwRftAIdnm+yROfE0A@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
zhen-hual-VXdhtT5mjnY@public.gmane.org,
dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Subject: [PATCH 17/19] iommu/vt-d: Copy IR table from old kernel when in kdump mode
Date: Sat, 13 Jun 2015 08:47:25 +0200 [thread overview]
Message-ID: <1434178047-17809-18-git-send-email-joro@8bytes.org> (raw)
In-Reply-To: <1434178047-17809-1-git-send-email-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
When we are booting into a kdump kernel and find IR enabled,
copy over the contents of the previous IR table so that
spurious interrupts will not be target aborted.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/intel_irq_remapping.c | 70 +++++++++++++++++++++++++++++++++++++
include/linux/intel-iommu.h | 1 +
2 files changed, 71 insertions(+)
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index 8497028..2a90121 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -11,6 +11,7 @@
#include <linux/irq.h>
#include <linux/intel-iommu.h>
#include <linux/acpi.h>
+#include <linux/crash_dump.h>
#include <asm/io_apic.h>
#include <asm/smp.h>
#include <asm/cpu.h>
@@ -54,8 +55,28 @@ static struct hpet_scope ir_hpet[MAX_HPET_TBS];
*/
static DEFINE_RAW_SPINLOCK(irq_2_ir_lock);
+static void iommu_disable_irq_remapping(struct intel_iommu *iommu);
static int __init parse_ioapics_under_ir(void);
+static bool ir_pre_enabled(struct intel_iommu *iommu)
+{
+ return (iommu->flags & VTD_FLAG_IRQ_REMAP_PRE_ENABLED);
+}
+
+static void clear_ir_pre_enabled(struct intel_iommu *iommu)
+{
+ iommu->flags &= ~VTD_FLAG_IRQ_REMAP_PRE_ENABLED;
+}
+
+static void init_ir_status(struct intel_iommu *iommu)
+{
+ u32 gsts;
+
+ gsts = readl(iommu->reg + DMAR_GSTS_REG);
+ if (gsts & DMA_GSTS_IRES)
+ iommu->flags |= VTD_FLAG_IRQ_REMAP_PRE_ENABLED;
+}
+
static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
{
struct irq_cfg *cfg = irq_cfg(irq);
@@ -426,6 +447,44 @@ static int set_msi_sid(struct irte *irte, struct pci_dev *dev)
return 0;
}
+static int iommu_load_old_irte(struct intel_iommu *iommu)
+{
+ struct irte *old_ir_table;
+ phys_addr_t irt_phys;
+ size_t size;
+ u64 irta;
+
+ if (!is_kdump_kernel()) {
+ pr_warn("IRQ remapping was enabled on %s but we are not in kdump mode\n",
+ iommu->name);
+ clear_ir_pre_enabled(iommu);
+ iommu_disable_irq_remapping(iommu);
+ return -EINVAL;
+ }
+
+ /* Check whether the old ir-table has the same size as ours */
+ irta = dmar_readq(iommu->reg + DMAR_IRTA_REG);
+ if ((irta & INTR_REMAP_TABLE_REG_SIZE_MASK)
+ != INTR_REMAP_TABLE_REG_SIZE)
+ return -EINVAL;
+
+ irt_phys = irta & VTD_PAGE_MASK;
+ size = INTR_REMAP_TABLE_ENTRIES*sizeof(struct irte);
+
+ /* Map the old IR table */
+ old_ir_table = ioremap_cache(irt_phys, size);
+ if (!old_ir_table)
+ return -ENOMEM;
+
+ /* Copy data over */
+ memcpy(iommu->ir_table->base, old_ir_table, size);
+
+ __iommu_flush_cache(iommu, iommu->ir_table->base, size);
+
+ return 0;
+}
+
+
static void iommu_set_irq_remapping(struct intel_iommu *iommu, int mode)
{
unsigned long flags;
@@ -531,6 +590,17 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
}
}
+ init_ir_status(iommu);
+
+ if (ir_pre_enabled(iommu)) {
+ if (iommu_load_old_irte(iommu))
+ pr_err("Failed to copy IR table for %s from previous kernel\n",
+ iommu->name);
+ else
+ pr_info("Copied IR table for %s from previous kernel\n",
+ iommu->name);
+ }
+
iommu_set_irq_remapping(iommu, eim_mode);
return 0;
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index fff87f1..9aedf21 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -295,6 +295,7 @@ struct q_inval {
/* 1MB - maximum possible interrupt remapping table size */
#define INTR_REMAP_PAGE_ORDER 8
#define INTR_REMAP_TABLE_REG_SIZE 0xf
+#define INTR_REMAP_TABLE_REG_SIZE_MASK 0xf
#define INTR_REMAP_TABLE_ENTRIES 65536
--
1.9.1
next prev parent reply other threads:[~2015-06-13 6:47 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-13 6:47 [PATCH 00/19] Fix Intel IOMMU breakage in kdump kernel Joerg Roedel
2015-06-13 6:47 ` [PATCH 11/19] iommu/vt-d: Don't disable translation prior to OS handover Joerg Roedel
[not found] ` <1434178047-17809-1-git-send-email-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-06-13 6:47 ` [PATCH 01/19] iommu/vt-d: Cleanup log messages Joerg Roedel
2015-06-13 6:47 ` [PATCH 02/19] iommu/vt-d: Init QI before root entry is allocated Joerg Roedel
2015-06-13 6:47 ` [PATCH 03/19] iommu/vt-d: Make root entry visible for hardware right after allocation Joerg Roedel
2015-06-13 6:47 ` [PATCH 04/19] iommu/vt-d: Detect pre enabled translation Joerg Roedel
2015-06-13 6:47 ` [PATCH 05/19] iommu/vt-d: Copy translation tables from old kernel Joerg Roedel
2015-06-13 6:47 ` [PATCH 06/19] iommu/vt-d: Do not re-use domain-ids from the " Joerg Roedel
2015-06-13 6:47 ` [PATCH 07/19] iommu/vt-d: Mark copied context entries Joerg Roedel
2015-06-13 6:47 ` [PATCH 08/19] iommu/vt-d: Allocate si_domain in init_dmars() Joerg Roedel
2015-06-13 6:47 ` [PATCH 09/19] iommu/vt-d: Don't do early domain assignment if kdump kernel Joerg Roedel
2015-06-13 6:47 ` [PATCH 10/19] iommu/vt-d: Don't copy translation tables if RTT bit needs to be changed Joerg Roedel
2015-06-13 6:47 ` [PATCH 12/19] iommu/vt-d: Enable Translation only if it was previously disabled Joerg Roedel
2015-06-13 6:47 ` [PATCH 13/19] iommu/vt-d: Move EIM detection to intel_prepare_irq_remapping Joerg Roedel
2015-06-13 6:47 ` [PATCH 14/19] iommu/vt-d: Move QI initializationt to intel_setup_irq_remapping Joerg Roedel
2015-06-13 6:47 ` [PATCH 15/19] iommu/vt-d: Disable IRQ remapping in intel_prepare_irq_remapping Joerg Roedel
2015-06-13 6:47 ` [PATCH 16/19] iommu/vt-d: Set IRTA in intel_setup_irq_remapping Joerg Roedel
2015-06-13 6:47 ` Joerg Roedel [this message]
2015-06-13 6:47 ` [PATCH 18/19] iommu/vt-d: Make sure copied over IR entries are not reused Joerg Roedel
2015-06-13 6:47 ` [PATCH 19/19] iommu/vt-d: Don't disable IR when it was previously enabled Joerg Roedel
2015-06-25 6:40 ` [PATCH 00/19] Fix Intel IOMMU breakage in kdump kernel Li, ZhenHua
2015-06-23 13:31 ` David Woodhouse
[not found] ` <1435066290.12045.2.camel-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-06-23 14:06 ` Joerg Roedel
[not found] ` <20150623140631.GB2724-l3A5Bk7waGM@public.gmane.org>
2015-06-23 14:38 ` David Woodhouse
[not found] ` <1435070334.12045.24.camel-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-06-25 6:35 ` Li, ZhenHua
2015-06-25 8:06 ` David Woodhouse
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=1434178047-17809-18-git-send-email-joro@8bytes.org \
--to=joro-zlv9swrftaidnm+yrofe0a@public.gmane.org \
--cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=jroedel-l3A5Bk7waGM@public.gmane.org \
--cc=jroedel-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=zhen-hual-VXdhtT5mjnY@public.gmane.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox