Linux IOMMU Development
 help / color / mirror / Atom feed
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>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH] iommu/vt-d: Don't copy translation tables if we find unexpected RTT setting
Date: Wed, 10 Jun 2015 11:10:31 +0200	[thread overview]
Message-ID: <1433927431-28574-1-git-send-email-joro@8bytes.org> (raw)

From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>

The RTT bit in the RTADDR_REG can not be changed while
translation is enabled. So check its value if we boot into a
kdump kernel and find translation enabled, and if it is
different from what we would set it to, bail out and don't
try to copy over the translation tables from the old kernel.

Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
 drivers/iommu/intel-iommu.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 58abddb..08209c4 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -389,6 +389,7 @@ static void unmap_device_dma(struct dmar_domain *domain,
 				struct device *dev,
 				struct intel_iommu *iommu);
 static void iommu_check_pre_te_status(struct intel_iommu *iommu);
+static bool iommu_check_rtt(struct intel_iommu *iommu);
 static u8 g_translation_pre_enabled;
 
 /*
@@ -2917,9 +2918,11 @@ static int __init init_dmars(void)
 
 		/*
 		 * We don't even try to preserve anything when we are not in a
-		 * kdump kernel.
+		 * kdump kernel or when we have to change the RTT bit in the
+		 * RTADDR_REG.
 		 */
-		if (!is_kdump_kernel() && iommu->pre_enabled_trans) {
+		if (iommu->pre_enabled_trans &&
+		    (!is_kdump_kernel() || iommu_check_rtt(iommu))) {
 			iommu_disable_translation(iommu);
 			iommu->pre_enabled_trans = 0;
 			g_translation_pre_enabled = 0;
@@ -5087,3 +5090,13 @@ static void iommu_check_pre_te_status(struct intel_iommu *iommu)
 		g_translation_pre_enabled = 1;
 	}
 }
+
+static bool iommu_check_rtt(struct intel_iommu *iommu)
+{
+	u64 rtaddr;
+
+	rtaddr = dmar_readq(iommu->reg + DMAR_RTADDR_REG);
+
+	return (!!ecap_ecs(iommu->ecap) != !!(rtaddr & DMA_RTADDR_RTT));
+}
+
-- 
1.9.1

                 reply	other threads:[~2015-06-10  9:10 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=1433927431-28574-1-git-send-email-joro@8bytes.org \
    --to=joro-zlv9swrftaidnm+yrofe0a@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=jroedel-l3A5Bk7waGM@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@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