Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1693489 > unrolled thread
| Started by | Baoquan He <bhe@redhat.com> |
|---|---|
| First post | 2017-07-21 11:00 +0200 |
| Last post | 2017-07-28 11:10 +0200 |
| Articles | 19 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v8 00/13] Fix the on-flight DMA issue on system with amd iommu Baoquan He <bhe@redhat.com> - 2017-07-21 11:00 +0200
[PATCH v8 05/13] iommu/amd: Add function copy_dev_tables() Baoquan He <bhe@redhat.com> - 2017-07-21 11:00 +0200
Re: [PATCH v8 05/13] iommu/amd: Add function copy_dev_tables() Joerg Roedel <jroedel@suse.de> - 2017-07-27 17:30 +0200
Re: [PATCH v8 05/13] iommu/amd: Add function copy_dev_tables() Baoquan He <bhe@redhat.com> - 2017-07-28 06:00 +0200
[PATCH v8 06/13] iommu/amd: copy old trans table from old kernel Baoquan He <bhe@redhat.com> - 2017-07-21 11:00 +0200
Re: [PATCH v8 06/13] iommu/amd: copy old trans table from old kernel Joerg Roedel <jroedel@suse.de> - 2017-07-27 17:40 +0200
Re: [PATCH v8 06/13] iommu/amd: copy old trans table from old kernel Baoquan He <bhe@redhat.com> - 2017-07-28 09:00 +0200
[PATCH v8 12/13] iommu/amd: Clear out the GV flag when handle deferred domain attach Baoquan He <bhe@redhat.com> - 2017-07-21 11:10 +0200
[PATCH v8 07/13] iommu/amd: Do sanity check for irq remap of old dev table entry Baoquan He <bhe@redhat.com> - 2017-07-21 11:10 +0200
[PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer Baoquan He <bhe@redhat.com> - 2017-07-21 11:10 +0200
Re: [PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer Baoquan He <bhe@redhat.com> - 2017-07-24 02:00 +0200
Re: [PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer Joerg Roedel <jroedel@suse.de> - 2017-07-27 18:00 +0200
Re: [PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer Baoquan He <bhe@redhat.com> - 2017-07-28 11:10 +0200
[PATCH v8 09/13] iommu/amd: Use is_attach_deferred call-back Baoquan He <bhe@redhat.com> - 2017-07-21 11:10 +0200
Re: [PATCH v8 09/13] iommu/amd: Use is_attach_deferred call-back Joerg Roedel <jroedel@suse.de> - 2017-07-27 18:00 +0200
Re: [PATCH v8 09/13] iommu/amd: Use is_attach_deferred call-back Baoquan He <bhe@redhat.com> - 2017-07-28 06:10 +0200
[PATCH v8 13/13] iommu/amd: Disable iommu only if amd_iommu=off is specified Baoquan He <bhe@redhat.com> - 2017-07-21 11:10 +0200
Re: [PATCH v8 13/13] iommu/amd: Disable iommu only if amd_iommu=off is specified Joerg Roedel <jroedel@suse.de> - 2017-07-27 18:00 +0200
Re: [PATCH v8 13/13] iommu/amd: Disable iommu only if amd_iommu=off is specified Baoquan He <bhe@redhat.com> - 2017-07-28 11:10 +0200
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-21 11:00 +0200 |
| Subject | [PATCH v8 00/13] Fix the on-flight DMA issue on system with amd iommu |
| Message-ID | <u5BWV-2C2-5@gated-at.bofh.it> |
When kernel panicked and jump into the kdump kernel, DMA started by the
1st kernel is not stopped, this is called on-flight DMA. In the current
code it will disable iommu and build new translation table and attach
device to it. This will cause:
1. IO_PAGE_FAULT warning message can be seen.
2. transfer data to or from incorrect areas of memory.
Sometime it causes the dump failure or kernel hang.
The principle of the fix is to defer the assignment of device to domain to
device driver initializtion stage. A new call-back is_attach_deferred() is
added to iommu-ops, will check whether we need defer the domain attach/detach
in iommu-core code. If defer is needed, just return directly from amd iommu
attach/detach function. The attachment will be done in device driver
initializaiton stage when calling get_domain().
Change history:
v8:v7:
Rebase patchset v7 on the latest v4.13-rc1.
- And re-enable printing IO_PAGE_FAULT message in kdump kernel.
- Only disable iommu if amd_iommu=off is specified in kdump kernel.
v6->v7:
Two main changes are made according to Joerg's suggestion:
- Add is_attach_deferred call-back to iommu-ops. With this domain
can be deferred to device driver init cleanly.
- Allocate memory below 4G for dev table if translation pre-enabled.
AMD engineer pointed out that it's unsafe to update the device-table
while iommu is enabled. device-table pointer update is split up into
two 32bit writes in the IOMMU hardware. So updating it while the IOMMU
is enabled could have some nasty side effects.
v5->v6:
According to Joerg's comments made several below main changes:
- Add sanity check when copy old dev tables.
- If a device is set up with guest translations (DTE.GV=1), then don't
copy that information but move the device over to an empty guest-cr3
table and handle the faults in the PPR log (which just answer them
with INVALID).
v5:
bnx2 NIC can't reset itself during driver init. Post patch to reset
it during driver init. IO_PAGE_FAULT can't be seen anymore.
Below is link of v5 post.
https://lists.linuxfoundation.org/pipermail/iommu/2016-September/018527.html
Baoquan He (12):
iommu/amd: Detect pre enabled translation
iommu/amd: add several helper functions
Revert "iommu/amd: Suppress IO_PAGE_FAULTs in kdump kernel"
iommu/amd: Define bit fields for DTE particularly
iommu/amd: Add function copy_dev_tables()
iommu/amd: copy old trans table from old kernel
iommu/amd: Do sanity check for irq remap of old dev table entry
iommu: Add is_attach_deferred call-back to iommu-ops
iommu/amd: Use is_attach_deferred call-back
iommu/amd: Allocate memory below 4G for dev table if translation
pre-enabled
iommu/amd: Don't copy GCR3 table root pointer
iommu/amd: Clear out the GV flag when handle deferred domain attach
root (1):
iommu/amd: Disable iommu only if amd_iommu=off is specified
drivers/iommu/amd_iommu.c | 81 ++++++++-------
drivers/iommu/amd_iommu_init.c | 212 ++++++++++++++++++++++++++++++++++++----
drivers/iommu/amd_iommu_proto.h | 2 +
drivers/iommu/amd_iommu_types.h | 56 ++++++++++-
drivers/iommu/amd_iommu_v2.c | 18 +++-
drivers/iommu/iommu.c | 8 ++
include/linux/iommu.h | 1 +
7 files changed, 315 insertions(+), 63 deletions(-)
--
2.5.5
[toc] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-21 11:00 +0200 |
| Subject | [PATCH v8 05/13] iommu/amd: Add function copy_dev_tables() |
| Message-ID | <u5BWW-2C2-29@gated-at.bofh.it> |
| In reply to | #1693489 |
Add function copy_dev_tables to copy the old DEV table entries of the panicked
kernel to the new allocated DEV table. Since all iommus share the same DTE table
the copy only need be done one time. Besides, we also need to:
- Check whether all IOMMUs actually use the same device table with the same size
- Verify that the size of the old device table is the expected size.
- Reserve the old domain id occupied in 1st kernel to avoid touching the old
io-page tables. Then on-flight DMA can continue looking it up.
And also define MACRO DEV_DOMID_MASK to replace magic number 0xffffULL, it can be
reused in copy_dev_tables().
Signed-off-by: Baoquan He <bhe@redhat.com>
---
drivers/iommu/amd_iommu.c | 2 +-
drivers/iommu/amd_iommu_init.c | 55 +++++++++++++++++++++++++++++++++++++++++
drivers/iommu/amd_iommu_types.h | 1 +
3 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index e5a03f259986..4d00f1bda900 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2086,7 +2086,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 f6da5fe03b31..c58f091ce232 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -842,6 +842,61 @@ static int get_dev_entry_bit(u16 devid, u8 bit)
}
+static int copy_dev_tables(void)
+{
+ 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;
+ static int copied;
+
+ for_each_iommu(iommu) {
+ if (!translation_pre_enabled(iommu)) {
+ pr_err("IOMMU:%d is not pre-enabled!/n",
+ iommu->index);
+ return -1;
+ }
+
+ /* All IOMMUs should use the same device table with the same size */
+ lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET);
+ hi = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET + 4);
+ entry = (((u64) hi) << 32) + lo;
+ if (last_entry && last_entry != entry) {
+ pr_err("IOMMU:%d should use the same dev table as others!/n",
+ iommu->index);
+ return -1;
+ }
+ last_entry = entry;
+
+ old_devtb_size = ((entry & ~PAGE_MASK) + 1) << 12;
+ if (old_devtb_size != dev_table_size) {
+ pr_err("The device table size of IOMMU:%d is not expected!/n",
+ iommu->index);
+ return -1;
+ }
+
+ old_devtb_phys = entry & PAGE_MASK;
+ old_devtb = memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB);
+ if (!old_devtb)
+ return -1;
+
+ if (copied)
+ continue;
+ for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) {
+ 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)
+ __set_bit(dom_id, amd_iommu_pd_alloc_bitmap);
+ }
+ 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 ea36af19b5b9..1c06bcc06f5c 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -336,6 +336,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.5.5
[toc] | [prev] | [next] | [standalone]
| From | Joerg Roedel <jroedel@suse.de> |
|---|---|
| Date | 2017-07-27 17:30 +0200 |
| Subject | Re: [PATCH v8 05/13] iommu/amd: Add function copy_dev_tables() |
| Message-ID | <u7STE-7Md-3@gated-at.bofh.it> |
| In reply to | #1693490 |
On Fri, Jul 21, 2017 at 04:59:03PM +0800, Baoquan He wrote:
> Add function copy_dev_tables to copy the old DEV table entries of the panicked
Since there is only one (for now), you can name the function in
singular: copy_dev_table() or copy_device_table().
> kernel to the new allocated DEV table. Since all iommus share the same DTE table
> the copy only need be done one time. Besides, we also need to:
>
> - Check whether all IOMMUs actually use the same device table with the same size
>
> - Verify that the size of the old device table is the expected size.
>
> - Reserve the old domain id occupied in 1st kernel to avoid touching the old
> io-page tables. Then on-flight DMA can continue looking it up.
>
> And also define MACRO DEV_DOMID_MASK to replace magic number 0xffffULL, it can be
> reused in copy_dev_tables().
>
> Signed-off-by: Baoquan He <bhe@redhat.com>
> ---
> drivers/iommu/amd_iommu.c | 2 +-
> drivers/iommu/amd_iommu_init.c | 55 +++++++++++++++++++++++++++++++++++++++++
> drivers/iommu/amd_iommu_types.h | 1 +
> 3 files changed, 57 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
> index e5a03f259986..4d00f1bda900 100644
> --- a/drivers/iommu/amd_iommu.c
> +++ b/drivers/iommu/amd_iommu.c
> @@ -2086,7 +2086,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 f6da5fe03b31..c58f091ce232 100644
> --- a/drivers/iommu/amd_iommu_init.c
> +++ b/drivers/iommu/amd_iommu_init.c
> @@ -842,6 +842,61 @@ static int get_dev_entry_bit(u16 devid, u8 bit)
> }
>
>
> +static int copy_dev_tables(void)
> +{
> + 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;
> + static int copied;
> +
> + for_each_iommu(iommu) {
> + if (!translation_pre_enabled(iommu)) {
> + pr_err("IOMMU:%d is not pre-enabled!/n",
> + iommu->index);
> + return -1;
> + }
> +
> + /* All IOMMUs should use the same device table with the same size */
> + lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET);
> + hi = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET + 4);
> + entry = (((u64) hi) << 32) + lo;
> + if (last_entry && last_entry != entry) {
> + pr_err("IOMMU:%d should use the same dev table as others!/n",
> + iommu->index);
> + return -1;
> + }
> + last_entry = entry;
> +
> + old_devtb_size = ((entry & ~PAGE_MASK) + 1) << 12;
> + if (old_devtb_size != dev_table_size) {
> + pr_err("The device table size of IOMMU:%d is not expected!/n",
> + iommu->index);
> + return -1;
> + }
I think the loop can end here. There is only one table to copy, so you
don't need to copy it for every iommu. Just do the checks in the loop
and the copy once after the loop.
> +
> + old_devtb_phys = entry & PAGE_MASK;
> + old_devtb = memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB);
> + if (!old_devtb)
> + return -1;
> +
> + if (copied)
> + continue;
> + for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) {
> + 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)
> + __set_bit(dom_id, amd_iommu_pd_alloc_bitmap);
> + }
Please only copy the DTE when DTE.V is set in the old table. Also
don't copy any of the IOMMUv2 enablement bits from the old DTE. PRI
faults are recoverable by design and a device shouldn't fail on a
negative answer from the IOMMU.
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-28 06:00 +0200 |
| Subject | Re: [PATCH v8 05/13] iommu/amd: Add function copy_dev_tables() |
| Message-ID | <u84Br-6TA-1@gated-at.bofh.it> |
| In reply to | #1698099 |
On 07/27/17 at 05:29pm, Joerg Roedel wrote:
> On Fri, Jul 21, 2017 at 04:59:03PM +0800, Baoquan He wrote:
> > Add function copy_dev_tables to copy the old DEV table entries of the panicked
>
> Since there is only one (for now), you can name the function in
> singular: copy_dev_table() or copy_device_table().
Make sense, will change it to copy_device_table(). Thanks.
>
> > kernel to the new allocated DEV table. Since all iommus share the same DTE table
> > the copy only need be done one time. Besides, we also need to:
> >
> > - Check whether all IOMMUs actually use the same device table with the same size
> >
> > - Verify that the size of the old device table is the expected size.
> >
> > - Reserve the old domain id occupied in 1st kernel to avoid touching the old
> > io-page tables. Then on-flight DMA can continue looking it up.
> >
> > And also define MACRO DEV_DOMID_MASK to replace magic number 0xffffULL, it can be
> > reused in copy_dev_tables().
> >
> > Signed-off-by: Baoquan He <bhe@redhat.com>
> > ---
> > drivers/iommu/amd_iommu.c | 2 +-
> > drivers/iommu/amd_iommu_init.c | 55 +++++++++++++++++++++++++++++++++++++++++
> > drivers/iommu/amd_iommu_types.h | 1 +
> > 3 files changed, 57 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
> > index e5a03f259986..4d00f1bda900 100644
> > --- a/drivers/iommu/amd_iommu.c
> > +++ b/drivers/iommu/amd_iommu.c
> > @@ -2086,7 +2086,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 f6da5fe03b31..c58f091ce232 100644
> > --- a/drivers/iommu/amd_iommu_init.c
> > +++ b/drivers/iommu/amd_iommu_init.c
> > @@ -842,6 +842,61 @@ static int get_dev_entry_bit(u16 devid, u8 bit)
> > }
> >
> >
> > +static int copy_dev_tables(void)
> > +{
> > + 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;
> > + static int copied;
> > +
> > + for_each_iommu(iommu) {
> > + if (!translation_pre_enabled(iommu)) {
> > + pr_err("IOMMU:%d is not pre-enabled!/n",
> > + iommu->index);
> > + return -1;
> > + }
> > +
> > + /* All IOMMUs should use the same device table with the same size */
> > + lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET);
> > + hi = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET + 4);
> > + entry = (((u64) hi) << 32) + lo;
> > + if (last_entry && last_entry != entry) {
> > + pr_err("IOMMU:%d should use the same dev table as others!/n",
> > + iommu->index);
> > + return -1;
> > + }
> > + last_entry = entry;
> > +
> > + old_devtb_size = ((entry & ~PAGE_MASK) + 1) << 12;
> > + if (old_devtb_size != dev_table_size) {
> > + pr_err("The device table size of IOMMU:%d is not expected!/n",
> > + iommu->index);
> > + return -1;
> > + }
>
> I think the loop can end here. There is only one table to copy, so you
> don't need to copy it for every iommu. Just do the checks in the loop
> and the copy once after the loop.
Ok, will change. I worried that device table addr might not be stored
into iommu register correctly. I am fine we only do the check only at
the first time.
>
> > +
> > + old_devtb_phys = entry & PAGE_MASK;
> > + old_devtb = memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB);
> > + if (!old_devtb)
> > + return -1;
> > +
> > + if (copied)
> > + continue;
> > + for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) {
> > + 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)
> > + __set_bit(dom_id, amd_iommu_pd_alloc_bitmap);
> > + }
>
> Please only copy the DTE when DTE.V is set in the old table. Also
Sorry, the sanity check about DTE.V has been done in patch 7/13. I
should rewrite the subject and git log for patch 7/13.
> don't copy any of the IOMMUv2 enablement bits from the old DTE. PRI
> faults are recoverable by design and a device shouldn't fail on a
> negative answer from the IOMMU.
Yes, this is done in patch 11/13. Saw your comment in patch 11/13.
>
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-21 11:00 +0200 |
| Subject | [PATCH v8 06/13] iommu/amd: copy old trans table from old kernel |
| Message-ID | <u5BWW-2C2-35@gated-at.bofh.it> |
| In reply to | #1693489 |
Here several things need be done:
- If iommu is pre-enabled in a normal kernel, just disable it and print
warning.
- If failed to copy dev table of old kernel, continue to proceed as
it does in normal kernel.
- Disable and Re-enable event/cmd buffer, install the copied DTE table
to reg, and detect and enable guest vapic.
- Flush all caches
Signed-off-by: Baoquan He <bhe@redhat.com>
---
drivers/iommu/amd_iommu_init.c | 51 ++++++++++++++++++++++++++++++++++++------
1 file changed, 44 insertions(+), 7 deletions(-)
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index c58f091ce232..aa9b5918d11f 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -37,6 +37,7 @@
#include <asm/io_apic.h>
#include <asm/irq_remapping.h>
+#include <linux/crash_dump.h>
#include "amd_iommu_proto.h"
#include "amd_iommu_types.h"
#include "irq_remapping.h"
@@ -1489,9 +1490,12 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
iommu->int_enabled = false;
init_translation_status(iommu);
-
- if (translation_pre_enabled(iommu))
- pr_warn("Translation is already enabled - trying to copy translation structures\n");
+ if (translation_pre_enabled(iommu) && !is_kdump_kernel()) {
+ iommu_disable(iommu);
+ clear_translation_pre_enabled(iommu);
+ pr_warn("Translation was enabled for IOMMU:%d but we are not in kdump mode\n",
+ iommu->index);
+ }
ret = init_iommu_from_acpi(iommu, h);
if (ret)
@@ -1986,8 +1990,7 @@ static int __init init_memory_definitions(struct acpi_table_header *table)
}
/*
- * Init the device table to not allow DMA access for devices and
- * suppress all page faults
+ * Init the device table to not allow DMA access for devices
*/
static void init_device_table_dma(void)
{
@@ -2128,9 +2131,43 @@ static void early_enable_iommu(struct amd_iommu *iommu)
static void early_enable_iommus(void)
{
struct amd_iommu *iommu;
+ bool is_pre_enabled = false;
- for_each_iommu(iommu)
- early_enable_iommu(iommu);
+ for_each_iommu(iommu) {
+ if (translation_pre_enabled(iommu)) {
+ is_pre_enabled = true;
+ break;
+ }
+ }
+
+ if (!is_pre_enabled) {
+ for_each_iommu(iommu)
+ early_enable_iommu(iommu);
+ } else {
+ pr_warn("Translation is already enabled - trying to copy translation structures\n");
+ if (copy_dev_tables()) {
+ pr_err("Failed to copy DEV table from previous kernel.\n");
+ /*
+ * If failed to copy dev tables from old kernel, continue to proceed
+ * as it does in normal kernel.
+ */
+ for_each_iommu(iommu) {
+ clear_translation_pre_enabled(iommu);
+ early_enable_iommu(iommu);
+ }
+ } else {
+ pr_info("Copied DEV table from previous kernel.\n");
+ for_each_iommu(iommu) {
+ iommu_disable_command_buffer(iommu);
+ iommu_disable_event_buffer(iommu);
+ iommu_enable_command_buffer(iommu);
+ iommu_enable_event_buffer(iommu);
+ iommu_enable_ga(iommu);
+ iommu_set_device_table(iommu);
+ iommu_flush_all_caches(iommu);
+ }
+ }
+ }
#ifdef CONFIG_IRQ_REMAP
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
--
2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Joerg Roedel <jroedel@suse.de> |
|---|---|
| Date | 2017-07-27 17:40 +0200 |
| Subject | Re: [PATCH v8 06/13] iommu/amd: copy old trans table from old kernel |
| Message-ID | <u7T3k-7P8-25@gated-at.bofh.it> |
| In reply to | #1693492 |
On Fri, Jul 21, 2017 at 04:59:04PM +0800, Baoquan He wrote:
> @@ -2128,9 +2131,43 @@ static void early_enable_iommu(struct amd_iommu *iommu)
> static void early_enable_iommus(void)
> {
> struct amd_iommu *iommu;
> + bool is_pre_enabled = false;
>
> - for_each_iommu(iommu)
> - early_enable_iommu(iommu);
> + for_each_iommu(iommu) {
> + if (translation_pre_enabled(iommu)) {
> + is_pre_enabled = true;
> + break;
> + }
> + }
is_pre_enabled should only be true when _all_ iommus are pre-enabled. If
only one is found disabled just disable the others and continue without
copying the device table.
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-28 09:00 +0200 |
| Subject | Re: [PATCH v8 06/13] iommu/amd: copy old trans table from old kernel |
| Message-ID | <u87pD-gP-11@gated-at.bofh.it> |
| In reply to | #1698114 |
On 07/27/17 at 05:38pm, Joerg Roedel wrote:
> On Fri, Jul 21, 2017 at 04:59:04PM +0800, Baoquan He wrote:
> > @@ -2128,9 +2131,43 @@ static void early_enable_iommu(struct amd_iommu *iommu)
> > static void early_enable_iommus(void)
> > {
> > struct amd_iommu *iommu;
> > + bool is_pre_enabled = false;
> >
> > - for_each_iommu(iommu)
> > - early_enable_iommu(iommu);
> > + for_each_iommu(iommu) {
> > + if (translation_pre_enabled(iommu)) {
> > + is_pre_enabled = true;
> > + break;
> > + }
> > + }
>
> is_pre_enabled should only be true when _all_ iommus are pre-enabled. If
> only one is found disabled just disable the others and continue without
> copying the device table.
OK, will change as you suggested.
>
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-21 11:10 +0200 |
| Subject | [PATCH v8 12/13] iommu/amd: Clear out the GV flag when handle deferred domain attach |
| Message-ID | <u5C6D-2US-19@gated-at.bofh.it> |
| In reply to | #1693489 |
When handle deferred domain attach, we need check if the domain is
v2. If not, should try to clear out the GV flag which could be
copied from the old device table entry.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
drivers/iommu/amd_iommu.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 46d077784da0..98aaccecbb76 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2085,6 +2085,11 @@ static void clear_dte_entry(u16 devid)
amd_iommu_apply_erratum_63(devid);
}
+static void clear_dte_flag_gv(u16 devid)
+{
+ amd_iommu_dev_table[devid].data[0] &= (~DTE_FLAG_GV);
+}
+
static void do_attach(struct iommu_dev_data *dev_data,
struct protection_domain *domain)
{
@@ -2459,6 +2464,7 @@ static struct iommu_group *amd_iommu_device_group(struct device *dev)
*/
static struct protection_domain *get_domain(struct device *dev)
{
+ struct iommu_dev_data *dev_data = get_dev_data(dev);
struct protection_domain *domain;
struct iommu_domain *io_domain;
@@ -2466,11 +2472,21 @@ static struct protection_domain *get_domain(struct device *dev)
return ERR_PTR(-EINVAL);
domain = get_dev_data(dev)->domain;
- if (domain == NULL && get_dev_data(dev)->defer_attach) {
+ if (domain == NULL && dev_data->defer_attach) {
+ u16 alias = amd_iommu_alias_table[dev_data->devid];
get_dev_data(dev)->defer_attach = false;
io_domain = iommu_get_domain_for_dev(dev);
domain = to_pdomain(io_domain);
attach_device(dev, domain);
+ /*
+ * If the deferred attached domain is not v2, should clear out
+ * the old GV flag.
+ */
+ if (!(domain->flags & PD_IOMMUV2_MASK)) {
+ clear_dte_flag_gv(dev_data->devid);
+ if (alias != dev_data->devid)
+ clear_dte_flag_gv(dev_data->devid);
+ }
}
if (!dma_ops_domain(domain))
return ERR_PTR(-EBUSY);
--
2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-21 11:10 +0200 |
| Subject | [PATCH v8 07/13] iommu/amd: Do sanity check for irq remap of old dev table entry |
| Message-ID | <u5C6D-2US-33@gated-at.bofh.it> |
| In reply to | #1693489 |
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@redhat.com>
---
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
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-21 11:10 +0200 |
| Subject | [PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer |
| Message-ID | <u5C6E-2US-51@gated-at.bofh.it> |
| In reply to | #1693489 |
When iommu is pre_enabled in kdump kernel, if a device is set up with
guest translations (DTE.GV=1), then don't copy GCR3 table root pointer
but move the device over to an empty guest-cr3 table and handle the
faults in the PPR log (which answer them with INVALID). After all these
PPR faults are recoverable for the device and we should not allow the
device to change old-kernels data when we don't have to.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
drivers/iommu/amd_iommu.c | 28 +++-------------------------
drivers/iommu/amd_iommu_init.c | 11 +++++++++++
drivers/iommu/amd_iommu_proto.h | 1 +
drivers/iommu/amd_iommu_types.h | 24 ++++++++++++++++++++++++
drivers/iommu/amd_iommu_v2.c | 18 +++++++++++++++++-
5 files changed, 56 insertions(+), 26 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 4ff413b34b51..46d077784da0 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -103,30 +103,6 @@ int amd_iommu_max_glx_val = -1;
static const struct dma_map_ops amd_iommu_dma_ops;
/*
- * This struct contains device specific data for the IOMMU
- */
-struct iommu_dev_data {
- struct list_head list; /* For domain->dev_list */
- struct list_head dev_data_list; /* For global dev_data_list */
- struct protection_domain *domain; /* Domain the device is bound to */
- u16 devid; /* PCI Device ID */
- u16 alias; /* Alias Device ID */
- bool iommu_v2; /* Device can make use of IOMMUv2 */
- bool passthrough; /* Device is identity mapped */
- struct {
- bool enabled;
- int qdep;
- } ats; /* ATS state */
- bool pri_tlp; /* PASID TLB required for
- PPR completions */
- u32 errata; /* Bitmap for errata to apply */
- bool use_vapic; /* Enable device to use vapic mode */
- bool defer_attach;
-
- struct ratelimit_state rs; /* Ratelimit IOPF messages */
-};
-
-/*
* general struct to manage commands send to an IOMMU
*/
struct iommu_cmd {
@@ -386,10 +362,11 @@ static struct iommu_dev_data *find_dev_data(u16 devid)
return dev_data;
}
-static struct iommu_dev_data *get_dev_data(struct device *dev)
+struct iommu_dev_data *get_dev_data(struct device *dev)
{
return dev->archdata.iommu;
}
+EXPORT_SYMBOL(get_dev_data);
/*
* Find or create an IOMMU group for a acpihid device.
@@ -2540,6 +2517,7 @@ static int dir2prot(enum dma_data_direction direction)
else
return 0;
}
+
/*
* This function contains common code for mapping of a physically
* contiguous memory region into DMA address space. It is used by all
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index d7c301d0d672..8b4bac978062 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -209,6 +209,7 @@ u16 *amd_iommu_alias_table;
* for a specific device. It is also indexed by the PCI device id.
*/
struct amd_iommu **amd_iommu_rlookup_table;
+EXPORT_SYMBOL(amd_iommu_rlookup_table);
/*
* This table is used to find the irq remapping table for a given device id
@@ -262,6 +263,7 @@ bool translation_pre_enabled(struct amd_iommu *iommu)
{
return (iommu->flags & AMD_IOMMU_FLAG_TRANS_PRE_ENABLED);
}
+EXPORT_SYMBOL(translation_pre_enabled);
static void clear_translation_pre_enabled(struct amd_iommu *iommu)
{
@@ -852,6 +854,7 @@ static int copy_dev_tables(void)
struct amd_iommu *iommu;
u16 dom_id, dte_v, irq_v;
static int copied;
+ u64 tmp;
for_each_iommu(iommu) {
if (!translation_pre_enabled(iommu)) {
@@ -895,6 +898,14 @@ static int copy_dev_tables(void)
amd_iommu_dev_table[devid].data[1]
= old_devtb[devid].data[1];
__set_bit(dom_id, amd_iommu_pd_alloc_bitmap);
+ /* If gcr3 table existed, mask it out */
+ if (old_devtb[devid].data[0] & DTE_FLAG_GV) {
+ tmp = DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B;
+ tmp |= DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C;
+ amd_iommu_dev_table[devid].data[1] &= ~tmp;
+ tmp = DTE_GCR3_VAL_A(~0ULL) << DTE_GCR3_SHIFT_A;
+ amd_iommu_dev_table[devid].data[0] &= ~tmp;
+ }
}
irq_v = old_devtb[devid].data[2] & DTE_IRQ_REMAP_ENABLE;
diff --git a/drivers/iommu/amd_iommu_proto.h b/drivers/iommu/amd_iommu_proto.h
index a9666d2005bb..90e62e9b01c5 100644
--- a/drivers/iommu/amd_iommu_proto.h
+++ b/drivers/iommu/amd_iommu_proto.h
@@ -88,4 +88,5 @@ static inline bool iommu_feature(struct amd_iommu *iommu, u64 f)
}
extern bool translation_pre_enabled(struct amd_iommu *iommu);
+extern struct iommu_dev_data *get_dev_data(struct device *dev);
#endif /* _ASM_X86_AMD_IOMMU_PROTO_H */
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index 7149fa52063f..32c68f2fc1dc 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -619,6 +619,30 @@ struct devid_map {
bool cmd_line;
};
+/*
+ * This struct contains device specific data for the IOMMU
+ */
+struct iommu_dev_data {
+ struct list_head list; /* For domain->dev_list */
+ struct list_head dev_data_list; /* For global dev_data_list */
+ struct protection_domain *domain; /* Domain the device is bound to */
+ u16 devid; /* PCI Device ID */
+ u16 alias; /* Alias Device ID */
+ bool iommu_v2; /* Device can make use of IOMMUv2 */
+ bool passthrough; /* Device is identity mapped */
+ struct {
+ bool enabled;
+ int qdep;
+ } ats; /* ATS state */
+ bool pri_tlp; /* PASID TLB required for
+ PPR completions */
+ u32 errata; /* Bitmap for errata to apply */
+ bool use_vapic; /* Enable device to use vapic mode */
+ bool defer_attach;
+
+ struct ratelimit_state rs; /* Ratelimit IOPF messages */
+};
+
/* Map HPET and IOAPIC ids to the devid used by the IOMMU */
extern struct list_head ioapic_map;
extern struct list_head hpet_map;
diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c
index 6629c472eafd..0245d414a7b3 100644
--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -562,13 +562,29 @@ static int ppr_notifier(struct notifier_block *nb, unsigned long e, void *data)
unsigned long flags;
struct fault *fault;
bool finish;
- u16 tag;
+ u16 tag, devid;
int ret;
+ struct iommu_dev_data *dev_data;
+ struct pci_dev *pdev = NULL;
iommu_fault = data;
tag = iommu_fault->tag & 0x1ff;
finish = (iommu_fault->tag >> 9) & 1;
+ devid = iommu_fault->device_id;
+ pdev = pci_get_bus_and_slot(PCI_BUS_NUM(devid), devid & 0xff);
+ if (!pdev)
+ return -ENODEV;
+ dev_data = get_dev_data(&pdev->dev);
+
+ /* In kdump kernel pci dev is not initialized yet -> send INVALID */
+ if (translation_pre_enabled(amd_iommu_rlookup_table[devid])
+ && dev_data->defer_attach) {
+ amd_iommu_complete_ppr(pdev, iommu_fault->pasid,
+ PPR_INVALID, tag);
+ goto out;
+ }
+
ret = NOTIFY_DONE;
dev_state = get_device_state(iommu_fault->device_id);
if (dev_state == NULL)
--
2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-24 02:00 +0200 |
| Subject | Re: [PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer |
| Message-ID | <u6yX0-5zy-15@gated-at.bofh.it> |
| In reply to | #1693502 |
On 07/24/17 at 06:33am, kbuild test robot wrote:
> Hi Baoquan,
>
> [auto build test WARNING on iommu/next]
> [also build test WARNING on v4.13-rc1]
> [cannot apply to next-20170721]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>
> url: https://github.com/0day-ci/linux/commits/Baoquan-He/Fix-the-on-flight-DMA-issue-on-system-with-amd-iommu/20170724-060048
> base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
> config: x86_64-randconfig-x005-201730 (attached as .config)
> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64
>
> Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
> http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
>
> All warnings (new ones prefixed by >>):
>
> drivers//iommu/amd_iommu_v2.c: In function 'ppr_notifier':
> >> drivers//iommu/amd_iommu_v2.c:566:6: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
> int ret;
> ^~~
>
> vim +/ret +566 drivers//iommu/amd_iommu_v2.c
Thanks, it should return NOTIFY_DONE anyway when ppr faults is handled
in kdump kernel since the GCR3 table root pointer has been made NULL
intentionally.
I will add this into patch 11/13 when repost need be done.
From 742d8a51d8832e12884800840c4ebe802767d808 Mon Sep 17 00:00:00 2001
From: Baoquan He <bhe@redhat.com>
Date: Mon, 24 Jul 2017 07:48:10 +0800
Subject: [PATCH] iommu/amd: The ppr faults handled in kdump kernel should
return NOTIFY_DONE
Signed-off-by: Baoquan He <bhe@redhat.com>
---
drivers/iommu/amd_iommu_v2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c
index 0245d414a7b3..e705fac89cb4 100644
--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -578,6 +578,7 @@ static int ppr_notifier(struct notifier_block *nb, unsigned long e, void *data)
dev_data = get_dev_data(&pdev->dev);
/* In kdump kernel pci dev is not initialized yet -> send INVALID */
+ ret = NOTIFY_DONE;
if (translation_pre_enabled(amd_iommu_rlookup_table[devid])
&& dev_data->defer_attach) {
amd_iommu_complete_ppr(pdev, iommu_fault->pasid,
@@ -585,7 +586,6 @@ static int ppr_notifier(struct notifier_block *nb, unsigned long e, void *data)
goto out;
}
- ret = NOTIFY_DONE;
dev_state = get_device_state(iommu_fault->device_id);
if (dev_state == NULL)
goto out;
--
2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Joerg Roedel <jroedel@suse.de> |
|---|---|
| Date | 2017-07-27 18:00 +0200 |
| Subject | Re: [PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer |
| Message-ID | <u7TmG-7Yc-29@gated-at.bofh.it> |
| In reply to | #1693502 |
On Fri, Jul 21, 2017 at 04:59:09PM +0800, Baoquan He wrote: > When iommu is pre_enabled in kdump kernel, if a device is set up with > guest translations (DTE.GV=1), then don't copy GCR3 table root pointer > but move the device over to an empty guest-cr3 table and handle the > faults in the PPR log (which answer them with INVALID). After all these > PPR faults are recoverable for the device and we should not allow the > device to change old-kernels data when we don't have to. Okay, forget my previous comment about disabling IOMMUv2 features while copying. Its done in this patch.
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-28 11:10 +0200 |
| Subject | Re: [PATCH v8 11/13] iommu/amd: Don't copy GCR3 table root pointer |
| Message-ID | <u89rs-1IQ-25@gated-at.bofh.it> |
| In reply to | #1698126 |
On 07/27/17 at 05:57pm, Joerg Roedel wrote: > On Fri, Jul 21, 2017 at 04:59:09PM +0800, Baoquan He wrote: > > When iommu is pre_enabled in kdump kernel, if a device is set up with > > guest translations (DTE.GV=1), then don't copy GCR3 table root pointer > > but move the device over to an empty guest-cr3 table and handle the > > faults in the PPR log (which answer them with INVALID). After all these > > PPR faults are recoverable for the device and we should not allow the > > device to change old-kernels data when we don't have to. > > Okay, forget my previous comment about disabling IOMMUv2 features while > copying. Its done in this patch. Yeah, as you said. Thanks. >
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-21 11:10 +0200 |
| Subject | [PATCH v8 09/13] iommu/amd: Use is_attach_deferred call-back |
| Message-ID | <u5C6E-2US-63@gated-at.bofh.it> |
| In reply to | #1693489 |
Implement call-back is_attach_deferred and use it to defer the
domain attach from iommu driver init to device driver init when
iommu is pre-enabled in kdump kernel.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
drivers/iommu/amd_iommu.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 5508f57a3e4f..4ff413b34b51 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -121,6 +121,7 @@ struct iommu_dev_data {
PPR completions */
u32 errata; /* Bitmap for errata to apply */
bool use_vapic; /* Enable device to use vapic mode */
+ bool defer_attach;
struct ratelimit_state rs; /* Ratelimit IOPF messages */
};
@@ -371,12 +372,17 @@ static u16 get_alias(struct device *dev)
static struct iommu_dev_data *find_dev_data(u16 devid)
{
struct iommu_dev_data *dev_data;
+ struct amd_iommu *iommu = amd_iommu_rlookup_table[devid];
dev_data = search_dev_data(devid);
- if (dev_data == NULL)
+ if (dev_data == NULL) {
dev_data = alloc_dev_data(devid);
+ if (translation_pre_enabled(iommu))
+ dev_data->defer_attach = true;
+ }
+
return dev_data;
}
@@ -2477,11 +2483,18 @@ static struct iommu_group *amd_iommu_device_group(struct device *dev)
static struct protection_domain *get_domain(struct device *dev)
{
struct protection_domain *domain;
+ struct iommu_domain *io_domain;
if (!check_device(dev))
return ERR_PTR(-EINVAL);
domain = get_dev_data(dev)->domain;
+ if (domain == NULL && get_dev_data(dev)->defer_attach) {
+ get_dev_data(dev)->defer_attach = false;
+ io_domain = iommu_get_domain_for_dev(dev);
+ domain = to_pdomain(io_domain);
+ attach_device(dev, domain);
+ }
if (!dma_ops_domain(domain))
return ERR_PTR(-EBUSY);
@@ -3372,6 +3385,13 @@ static void amd_iommu_apply_resv_region(struct device *dev,
WARN_ON_ONCE(reserve_iova(&dma_dom->iovad, start, end) == NULL);
}
+static bool amd_iommu_is_attach_deferred(struct iommu_domain *domain,
+ struct device *dev)
+{
+ struct iommu_dev_data *dev_data = dev->archdata.iommu;
+ return dev_data->defer_attach;
+}
+
const struct iommu_ops amd_iommu_ops = {
.capable = amd_iommu_capable,
.domain_alloc = amd_iommu_domain_alloc,
@@ -3388,6 +3408,7 @@ const struct iommu_ops amd_iommu_ops = {
.get_resv_regions = amd_iommu_get_resv_regions,
.put_resv_regions = amd_iommu_put_resv_regions,
.apply_resv_region = amd_iommu_apply_resv_region,
+ .is_attach_deferred = amd_iommu_is_attach_deferred,
.pgsize_bitmap = AMD_IOMMU_PGSIZES,
};
--
2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Joerg Roedel <jroedel@suse.de> |
|---|---|
| Date | 2017-07-27 18:00 +0200 |
| Subject | Re: [PATCH v8 09/13] iommu/amd: Use is_attach_deferred call-back |
| Message-ID | <u7TmG-7Yc-13@gated-at.bofh.it> |
| In reply to | #1693505 |
On Fri, Jul 21, 2017 at 04:59:07PM +0800, Baoquan He wrote:
> +static bool amd_iommu_is_attach_deferred(struct iommu_domain *domain,
> + struct device *dev)
> +{
> + struct iommu_dev_data *dev_data = dev->archdata.iommu;
> + return dev_data->defer_attach;
> +}
If the redundant newline from patch 1 needs a new home, put it here :-)
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-28 06:10 +0200 |
| Subject | Re: [PATCH v8 09/13] iommu/amd: Use is_attach_deferred call-back |
| Message-ID | <u84L7-7bU-5@gated-at.bofh.it> |
| In reply to | #1698120 |
On 07/27/17 at 05:53pm, Joerg Roedel wrote:
> On Fri, Jul 21, 2017 at 04:59:07PM +0800, Baoquan He wrote:
> > +static bool amd_iommu_is_attach_deferred(struct iommu_domain *domain,
> > + struct device *dev)
> > +{
> > + struct iommu_dev_data *dev_data = dev->archdata.iommu;
> > + return dev_data->defer_attach;
> > +}
>
> If the redundant newline from patch 1 needs a new home, put it here :-)
Got it, will add a newline at this place. Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-21 11:10 +0200 |
| Subject | [PATCH v8 13/13] iommu/amd: Disable iommu only if amd_iommu=off is specified |
| Message-ID | <u5C6F-2US-67@gated-at.bofh.it> |
| In reply to | #1693489 |
From: root <root@amd-dinar-02.lab.bos.redhat.com> It's ok to disable iommu in normal kernel. While there's no need to disable it in kdump kernel after the on-flight dma issue has heen fixed. Signed-off-by: Baoquan He <bhe@redhat.com> --- drivers/iommu/amd_iommu_init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 8b4bac978062..880f693c809b 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -2494,7 +2494,8 @@ static int __init early_amd_iommu_init(void) goto out; /* Disable any previously enabled IOMMUs */ - disable_iommus(); + if (amd_iommu_disabled) + disable_iommus(); if (amd_iommu_irq_remap) amd_iommu_irq_remap = check_ioapic_information(); -- 2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Joerg Roedel <jroedel@suse.de> |
|---|---|
| Date | 2017-07-27 18:00 +0200 |
| Subject | Re: [PATCH v8 13/13] iommu/amd: Disable iommu only if amd_iommu=off is specified |
| Message-ID | <u7TmG-7Yc-17@gated-at.bofh.it> |
| In reply to | #1693506 |
On Fri, Jul 21, 2017 at 04:59:11PM +0800, Baoquan He wrote: > From: root <root@amd-dinar-02.lab.bos.redhat.com> You probaly need to reset the author on this one. > > It's ok to disable iommu in normal kernel. While there's no need > to disable it in kdump kernel after the on-flight dma issue has > heen fixed. > > Signed-off-by: Baoquan He <bhe@redhat.com> > --- > drivers/iommu/amd_iommu_init.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c > index 8b4bac978062..880f693c809b 100644 > --- a/drivers/iommu/amd_iommu_init.c > +++ b/drivers/iommu/amd_iommu_init.c > @@ -2494,7 +2494,8 @@ static int __init early_amd_iommu_init(void) > goto out; > > /* Disable any previously enabled IOMMUs */ > - disable_iommus(); > + if (amd_iommu_disabled) > + disable_iommus(); > > if (amd_iommu_irq_remap) > amd_iommu_irq_remap = check_ioapic_information(); > -- > 2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Date | 2017-07-28 11:10 +0200 |
| Subject | Re: [PATCH v8 13/13] iommu/amd: Disable iommu only if amd_iommu=off is specified |
| Message-ID | <u89rs-1IQ-31@gated-at.bofh.it> |
| In reply to | #1698121 |
On 07/27/17 at 05:58pm, Joerg Roedel wrote: > On Fri, Jul 21, 2017 at 04:59:11PM +0800, Baoquan He wrote: > > From: root <root@amd-dinar-02.lab.bos.redhat.com> > > You probaly need to reset the author on this one. Oops, sorry. I made this patch on a testing machine. Will correct it. Thanks a lot for all these comments and great suggestions. > > > > > It's ok to disable iommu in normal kernel. While there's no need > > to disable it in kdump kernel after the on-flight dma issue has > > heen fixed. > > > > Signed-off-by: Baoquan He <bhe@redhat.com> > > --- > > drivers/iommu/amd_iommu_init.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c > > index 8b4bac978062..880f693c809b 100644 > > --- a/drivers/iommu/amd_iommu_init.c > > +++ b/drivers/iommu/amd_iommu_init.c > > @@ -2494,7 +2494,8 @@ static int __init early_amd_iommu_init(void) > > goto out; > > > > /* Disable any previously enabled IOMMUs */ > > - disable_iommus(); > > + if (amd_iommu_disabled) > > + disable_iommus(); > > > > if (amd_iommu_irq_remap) > > amd_iommu_irq_remap = check_ioapic_information(); > > -- > > 2.5.5
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web