From: Baoquan He <bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: [Patch v3 07/12] iommu/amd: Add function copy_dev_tables
Date: Tue, 26 Jan 2016 18:29:21 +0800 [thread overview]
Message-ID: <1453804166-25646-8-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1453804166-25646-1-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Add function copy_dev_tables to copy old DTE in 1st kernel to
the new DTE table. Since all iommu share the same DTE table the
copy only need be done once as long as the physical address of
old DTE table is retrieved from iommu reg. Besides the old domain
id occupied in 1st kernel need be reserved in order to avoid touch
the old translation tables.
Signed-off-by: Baoquan He <bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
drivers/iommu/amd_iommu.c | 2 +-
drivers/iommu/amd_iommu_init.c | 40 ++++++++++++++++++++++++++++++++++++++++
drivers/iommu/amd_iommu_types.h | 1 +
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 93bc690..c0b96e0 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2011,7 +2011,7 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats)
flags |= tmp;
}
- flags &= ~(0xffffUL);
+ flags &= ~DEV_DOMID_MASK;
flags |= domain->id;
amd_iommu_dev_table[devid].data[1] = flags;
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 450adad..e5d28ec 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -704,6 +704,46 @@ static void copy_irq_table(u16 devid)
memunmap(old_intr_virt);
}
+static int copy_dev_tables(struct amd_iommu *iommu)
+{
+ u64 entry;
+ u32 lo, hi;
+ phys_addr_t old_devtb_phys;
+ struct dev_table_entry *old_devtb;
+ u16 dom_id;
+ u32 devid;
+ u64 flags = 0;
+ static int copied;
+
+ for_each_iommu(iommu) {
+ if (!translation_pre_enabled()) {
+ pr_err("IOMMU:%d is not pre-enabled!/n", iommu->index);
+ return -1;
+ }
+
+ if (copied)
+ continue;
+
+ lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET);
+ hi = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET + 4);
+ entry = (((u64) hi) << 32) + lo;
+ old_devtb_phys = entry & PAGE_MASK;
+ old_devtb = memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB);
+ for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) {
+ amd_iommu_dev_table[devid] = old_devtb[devid];
+ dom_id = amd_iommu_dev_table[devid].data[1] & DEV_DOMID_MASK;
+ flags = amd_iommu_dev_table[devid].data[0];
+ if (!flags & IOMMU_PTE_V)
+ continue;
+ __set_bit(dom_id, amd_iommu_pd_alloc_bitmap);
+ copy_irq_table(devid);
+ }
+ memunmap(old_devtb);
+ copied = 1;
+ }
+ return 0;
+}
+
void amd_iommu_apply_erratum_63(u16 devid)
{
int sysmgt;
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index 42cd3d5..9a768f6 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -303,6 +303,7 @@
#define DTE_FLAG_MASK (0x3ffULL << 32)
#define DTE_GLX_SHIFT (56)
#define DTE_GLX_MASK (3)
+#define DEV_DOMID_MASK 0xffffULL
#define DTE_GCR3_VAL_A(x) (((x) >> 12) & 0x00007ULL)
#define DTE_GCR3_VAL_B(x) (((x) >> 15) & 0x0ffffULL)
--
2.1.0
next prev parent reply other threads:[~2016-01-26 10:29 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-26 10:29 [Patch v3 00/12] Fix AMD IOMMU faults in kdump kernel Baoquan He
[not found] ` <1453804166-25646-1-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-01-26 10:29 ` [Patch v3 01/12] iommu/amd: Use standard bitmap operation to set bitmap Baoquan He
2016-01-26 10:29 ` [Patch v3 02/12] iommu/amd: Detect pre enabled translation Baoquan He
2016-01-26 10:29 ` [Patch v3 03/12] iommu/amd: move dte irq macro defitions to amd_iommu_types.h Baoquan He
[not found] ` <1453804166-25646-4-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-01-27 10:25 ` Wan Zongshun
[not found] ` <56A89B1F.6010004-6ukY98dZOFrYtjvyW6yDsg@public.gmane.org>
2016-01-28 9:50 ` Baoquan He
2016-01-26 10:29 ` [Patch v3 04/12] iommu/amd: add copy_irq_table function Baoquan He
[not found] ` <1453804166-25646-5-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-01-27 11:23 ` Wan Zongshun
[not found] ` <56A8A896.70405-6ukY98dZOFrYtjvyW6yDsg@public.gmane.org>
2016-01-28 9:52 ` Baoquan He
2016-01-26 10:29 ` [Patch v3 05/12] iommu/amd: change IOMMU_PTE_P to IOMMU_PTE_V Baoquan He
[not found] ` <1453804166-25646-6-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-01-27 10:18 ` Wan Zongshun
[not found] ` <56A89981.5010007-6ukY98dZOFrYtjvyW6yDsg@public.gmane.org>
2016-01-28 10:05 ` Baoquan He
[not found] ` <20160128100533.GD3851-ejN7fcUYdH/by3iVrkZq2A@public.gmane.org>
2016-01-29 2:55 ` Wan Zongshun
[not found] ` <56AAD4B8.8050701-6ukY98dZOFrYtjvyW6yDsg@public.gmane.org>
2016-01-29 3:12 ` Baoquan He
2016-01-26 10:29 ` [Patch v3 06/12] iommu/amd: Clean up the useless IOMMU_PTE_U/IOMMU_PTE_FC Baoquan He
[not found] ` <1453804166-25646-7-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-01-27 10:22 ` Wan Zongshun
[not found] ` <56A89A74.6060501-6ukY98dZOFrYtjvyW6yDsg@public.gmane.org>
2016-01-28 10:30 ` Baoquan He
2016-01-26 10:29 ` Baoquan He [this message]
2016-01-26 10:29 ` [Patch v3 08/12] iommu/amd: set the device table and re-enable event/cmd buffer Baoquan He
2016-01-26 10:29 ` [Patch v3 09/12] iommu/amd: Don't update the domain information to iommu dev before dev init Baoquan He
2016-01-26 10:29 ` [Patch v3 10/12] iommu/amd: Update related domain info to dev when dev driver init Baoquan He
2016-01-26 10:29 ` [Patch v3 11/12] iommu/amd: No need to wait iommu completion if no dte irq entry change Baoquan He
[not found] ` <1453804166-25646-12-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-01-27 11:03 ` Wan Zongshun
[not found] ` <56A8A3EC.7090701-6ukY98dZOFrYtjvyW6yDsg@public.gmane.org>
2016-01-28 10:24 ` Baoquan He
[not found] ` <20160128102401.GE3851-ejN7fcUYdH/by3iVrkZq2A@public.gmane.org>
2016-01-29 2:57 ` Wan Zongshun
2016-01-26 10:29 ` [Patch v3 12/12] iommu/amd: fix a code bug in do_attach Baoquan He
[not found] ` <1453804166-25646-13-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-01-26 10:51 ` Baoquan He
2016-01-26 10:48 ` [Patch v3 00/12] Fix AMD IOMMU faults in kdump kernel Baoquan He
2016-01-26 10:52 ` Baoquan He
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=1453804166-25646-8-git-send-email-bhe@redhat.com \
--to=bhe-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@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;
as well as URLs for NNTP newsgroup(s).