From: Baoquan He <bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: jroedel-l3A5Bk7waGM@public.gmane.org
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v8 07/13] iommu/amd: Do sanity check for irq remap of old dev table entry
Date: Fri, 21 Jul 2017 16:59:05 +0800 [thread overview]
Message-ID: <1500627551-12930-8-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1500627551-12930-1-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Firstly split the dev table entry copy into address translation part and
irq remapping part. Because these two parts could be enabled
independently.
Secondly check if IntCtl and IntTabLen are 10b and 1000b if they are
set.
Signed-off-by: Baoquan He <bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
drivers/iommu/amd_iommu.c | 5 -----
drivers/iommu/amd_iommu_init.c | 25 ++++++++++++++++++++++---
drivers/iommu/amd_iommu_types.h | 8 ++++++++
3 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 4d00f1bda900..5508f57a3e4f 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3776,11 +3776,6 @@ EXPORT_SYMBOL(amd_iommu_device_info);
static struct irq_chip amd_ir_chip;
-#define DTE_IRQ_PHYS_ADDR_MASK (((1ULL << 45)-1) << 6)
-#define DTE_IRQ_REMAP_INTCTL (2ULL << 60)
-#define DTE_IRQ_TABLE_LEN (8ULL << 1)
-#define DTE_IRQ_REMAP_ENABLE 1ULL
-
static void set_dte_irq_entry(u16 devid, struct irq_remap_table *table)
{
u64 dte;
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index aa9b5918d11f..052fa4a977d8 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -845,12 +845,12 @@ static int get_dev_entry_bit(u16 devid, u8 bit)
static int copy_dev_tables(void)
{
+ u64 int_ctl, int_tab_len, entry, last_entry = 0;
struct dev_table_entry *old_devtb = NULL;
u32 lo, hi, devid, old_devtb_size;
phys_addr_t old_devtb_phys;
- u64 entry, last_entry = 0;
struct amd_iommu *iommu;
- u16 dom_id, dte_v;
+ u16 dom_id, dte_v, irq_v;
static int copied;
for_each_iommu(iommu) {
@@ -889,8 +889,27 @@ static int copy_dev_tables(void)
amd_iommu_dev_table[devid] = old_devtb[devid];
dom_id = old_devtb[devid].data[1] & DEV_DOMID_MASK;
dte_v = old_devtb[devid].data[0] & DTE_FLAG_V;
- if (dte_v && dom_id)
+ if (dte_v && dom_id) {
+ amd_iommu_dev_table[devid].data[0]
+ = old_devtb[devid].data[0];
+ amd_iommu_dev_table[devid].data[1]
+ = old_devtb[devid].data[1];
__set_bit(dom_id, amd_iommu_pd_alloc_bitmap);
+ }
+
+ irq_v = old_devtb[devid].data[2] & DTE_IRQ_REMAP_ENABLE;
+ int_ctl = old_devtb[devid].data[2] & DTE_IRQ_REMAP_INTCTL_MASK;
+ int_tab_len = old_devtb[devid].data[2] & DTE_IRQ_TABLE_LEN_MASK;
+ if (irq_v && (int_ctl || int_tab_len)) {
+ if ((int_ctl != DTE_IRQ_REMAP_INTCTL) ||
+ (int_tab_len != DTE_IRQ_TABLE_LEN)) {
+ pr_err("Wrong old irq remapping flag: %#x\n", devid);
+ return -1;
+ }
+
+ amd_iommu_dev_table[devid].data[2]
+ = old_devtb[devid].data[2];
+ }
}
memunmap(old_devtb);
copied = 1;
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index 1c06bcc06f5c..7149fa52063f 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -250,6 +250,14 @@
#define GA_GUEST_NR 0x1
+/* Bit value definition for dte irq remapping fields*/
+#define DTE_IRQ_PHYS_ADDR_MASK (((1ULL << 45)-1) << 6)
+#define DTE_IRQ_REMAP_INTCTL_MASK (0x3ULL << 60)
+#define DTE_IRQ_TABLE_LEN_MASK (0xfULL << 1)
+#define DTE_IRQ_REMAP_INTCTL (2ULL << 60)
+#define DTE_IRQ_TABLE_LEN (8ULL << 1)
+#define DTE_IRQ_REMAP_ENABLE 1ULL
+
#define PAGE_MODE_NONE 0x00
#define PAGE_MODE_1_LEVEL 0x01
#define PAGE_MODE_2_LEVEL 0x02
--
2.5.5
next prev parent reply other threads:[~2017-07-21 8:59 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 8:58 [PATCH v8 00/13] Fix the on-flight DMA issue on system with amd iommu Baoquan He
[not found] ` <1500627551-12930-1-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-07-21 8:58 ` [PATCH v8 01/13] iommu/amd: Detect pre enabled translation Baoquan He
2017-07-27 15:04 ` Joerg Roedel
2017-07-28 2:31 ` Baoquan He
2017-07-21 8:59 ` [PATCH v8 02/13] iommu/amd: add several helper functions Baoquan He
2017-07-27 15:06 ` Joerg Roedel
[not found] ` <20170727150612.GK3610-l3A5Bk7waGM@public.gmane.org>
2017-07-28 2:36 ` Baoquan He
2017-07-31 10:01 ` Baoquan He
2017-07-31 10:07 ` Joerg Roedel
2017-07-21 8:59 ` [PATCH v8 04/13] iommu/amd: Define bit fields for DTE particularly Baoquan He
2017-07-21 8:59 ` Baoquan He [this message]
2017-07-21 8:59 ` [PATCH v8 09/13] iommu/amd: Use is_attach_deferred call-back Baoquan He
[not found] ` <1500627551-12930-10-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-07-27 15:53 ` Joerg Roedel
[not found] ` <20170727155327.GN3610-l3A5Bk7waGM@public.gmane.org>
2017-07-28 4:02 ` Baoquan He
2017-07-21 8:59 ` [PATCH v8 03/13] Revert "iommu/amd: Suppress IO_PAGE_FAULTs in kdump kernel" Baoquan He
2017-07-21 8:59 ` [PATCH v8 05/13] iommu/amd: Add function copy_dev_tables() Baoquan He
2017-07-27 15:29 ` Joerg Roedel
2017-07-28 3:59 ` Baoquan He
2017-07-21 8:59 ` [PATCH v8 06/13] iommu/amd: copy old trans table from old kernel Baoquan He
2017-07-27 15:38 ` Joerg Roedel
[not found] ` <20170727153825.GM3610-l3A5Bk7waGM@public.gmane.org>
2017-07-28 6:52 ` Baoquan He
2017-07-21 8:59 ` [PATCH v8 08/13] iommu: Add is_attach_deferred call-back to iommu-ops Baoquan He
2017-07-21 8:59 ` [PATCH v8 10/13] iommu/amd: Allocate memory below 4G for dev table if translation pre-enabled Baoquan He
[not found] ` <1500627551-12930-11-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-07-27 15:55 ` Joerg Roedel
2017-07-28 9:06 ` Baoquan He
2017-07-28 11:14 ` Joerg Roedel
2017-07-28 11:15 ` Baoquan He
2017-07-28 11:18 ` Joerg Roedel
[not found] ` <20170728111809.GC3431-l3A5Bk7waGM@public.gmane.org>
2017-07-28 11:26 ` Baoquan He
2017-07-31 10:15 ` Baoquan He
2017-07-31 10:21 ` Joerg Roedel
[not found] ` <20170731102153.GK3431-l3A5Bk7waGM@public.gmane.org>
2017-07-31 10:29 ` Baoquan He
2017-07-21 8:59 ` [PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer Baoquan He
[not found] ` <1500627551-12930-12-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-07-23 22:33 ` kbuild test robot
[not found] ` <201707240618.mJ6b2eHv%fengguang.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-07-23 23:53 ` Baoquan He
2017-07-27 15:57 ` Joerg Roedel
[not found] ` <20170727155755.GP3610-l3A5Bk7waGM@public.gmane.org>
2017-07-28 9:07 ` Baoquan He
2017-07-21 8:59 ` [PATCH v8 12/13] iommu/amd: Clear out the GV flag when handle deferred domain attach Baoquan He
2017-07-21 8:59 ` [PATCH v8 13/13] iommu/amd: Disable iommu only if amd_iommu=off is specified Baoquan He
[not found] ` <1500627551-12930-14-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-07-27 15:58 ` Joerg Roedel
[not found] ` <20170727155852.GQ3610-l3A5Bk7waGM@public.gmane.org>
2017-07-28 9:08 ` 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=1500627551-12930-8-git-send-email-bhe@redhat.com \
--to=bhe-h+wxahxf7alqt0dzr+alfa@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;
as well as URLs for NNTP newsgroup(s).