Skip to contentSkip to conversation

x86/vtd: fix IOMMU share PT destruction path

PATCH In review Wei Liu 4 participants 7 messages Oct 9, 2018 – Oct 11, 2018

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH v2 1/1 x86/vtd: fix IOMMU share PT destruction path

Commit 2916951c1 ("mm / iommu: include need_iommu() test in iommu_use_hap_pt()") included need_iommu() in iommu_use_hap_pt and 91d4eca7add ("mm / iommu: split need_iommu() into has_iommu_pt() and need_iommu_pt_sync()") made things finer grain by spliting need_iommu into three states.

The destruction path can't use iommu_use_hap_pt because at the point platform op is called, IOMMU is either already switched to or has always been in disabled state, and the shared PT test would always be false.

---
v2: fix bug and update comment.

---
 xen/drivers/passthrough/vtd/iommu.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +11 -1
index f94b522c73..4d1ff10817 100644
@@ -1752,7 +1752,17 @@ static void iommu_domain_teardown(struct domain *d)
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(iommu_enabled);
+
+    /*
+     * We can't use iommu_use_hap_pt here because either IOMMU state
+     * is already changed to IOMMU_STATUS_disabled at this point or
+     * has always been IOMMU_STATUS_disabled.
+     *
+     * We also need to test if HAP is enabled because PV guests can
+     * enter this path too.
+     */
+    if ( hap_enabled(d) && iommu_hap_pt_share )
         return;
 
     spin_lock(&hd->arch.mapping_lock);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 15:57
To: [email protected]
Cc: Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Wei Liu <[email protected]>; Kevin Tian <[email protected]>
Subject: [PATCH v2] x86/vtd: fix IOMMU share PT destruction path

Commit 2916951c1 ("mm / iommu: include need_iommu() test in iommu_use_hap_pt()") included need_iommu() in iommu_use_hap_pt and 91d4eca7add ("mm / iommu: split need_iommu() into has_iommu_pt() and need_iommu_pt_sync()") made things finer grain by spliting need_iommu into three states.

Quoted 6 lines

The destruction path can't use iommu_use_hap_pt because at the point platform op is called, IOMMU is either already switched to or has always been in disabled state, and the shared PT test would always be false.

Quoted 31 lines

---
v2: fix bug and update comment.

---
 xen/drivers/passthrough/vtd/iommu.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +11 -2
index f94b522c73..4d1ff10817 100644
@@ -1752,7 +1752,17 @@ static void iommu_domain_teardown(struct domain *d)
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(iommu_enabled);
+
+    /*
+     * We can't use iommu_use_hap_pt here because either IOMMU state
+     * is already changed to IOMMU_STATUS_disabled at this point or
+     * has always been IOMMU_STATUS_disabled.
+     *
+     * We also need to test if HAP is enabled because PV guests can
+     * enter this path too.
+     */
+    if ( hap_enabled(d) && iommu_hap_pt_share )
         return;
 
     spin_lock(&hd->arch.mapping_lock);
--
Quoted 1 line

2.11.0

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 1/1
#2 lore raw
In reply to Wei Liu
Quoted 6 lines · Wei Liu

Commit 2916951c1 ("mm / iommu: include need_iommu() test in iommu_use_hap_pt()") included need_iommu() in iommu_use_hap_pt and 91d4eca7add ("mm / iommu: split need_iommu() into has_iommu_pt() and need_iommu_pt_sync()") made things finer grain by spliting need_iommu into three states.

Quoted 6 lines

The destruction path can't use iommu_use_hap_pt because at the point platform op is called, IOMMU is either already switched to or has always been in disabled state, and the shared PT test would always be false.

This is fine (and will fix destroying HVM/PVH guests), but I would still like deallocate_iommu_page_tables (from pci_amd_iommu.c) to be fixed in order to avoid the usage of iommu_use_hap_pt there also.

IMO the check itself could be converted into ASSERT(!iommu_hap_pt_share) since it's unlikely that AMD will have support for share page tables anytime soon.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#3 lore raw
In reply to Wei Liu
Quoted 6 lines · Wei Liu

Commit 2916951c1 ("mm / iommu: include need_iommu() test in iommu_use_hap_pt()") included need_iommu() in iommu_use_hap_pt and 91d4eca7add ("mm / iommu: split need_iommu() into has_iommu_pt() and need_iommu_pt_sync()") made things finer grain by spliting need_iommu into three states.

Quoted 6 lines

The destruction path can't use iommu_use_hap_pt because at the point platform op is called, IOMMU is either already switched to or has always been in disabled state, and the shared PT test would always be false.

Kevin, can you ack/nack this patch? Staging is currently blocked by a bug which is fixed by this patch.

Thanks,
Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#4 lore raw

Add Kevin in the To: field

Quoted 12 lines · Wei Liu
Quoted 11 lines · Wei Liu

Commit 2916951c1 ("mm / iommu: include need_iommu() test in iommu_use_hap_pt()") included need_iommu() in iommu_use_hap_pt and 91d4eca7add ("mm / iommu: split need_iommu() into has_iommu_pt() and need_iommu_pt_sync()") made things finer grain by spliting need_iommu into three states.

The destruction path can't use iommu_use_hap_pt because at the point platform op is called, IOMMU is either already switched to or has always been in disabled state, and the shared PT test would always be false.

Quoted 7 lines
Quoted 1 line

Kevin, can you ack/nack this patch? Staging is currently blocked by a bug which is fixed by this patch.

Thanks,
Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by
#5 lore raw
In reply to Wei Liu
Quoted 17 lines

From: Wei Liu [mailto:[email protected]]
Sent: Thursday, October 11, 2018 4:28 PM

Quoted 2 lines · Wei Liu

Commit 2916951c1 ("mm / iommu: include need_iommu() test in iommu_use_hap_pt()") included need_iommu() in iommu_use_hap_pt

and

Quoted 1 line

91d4eca7add ("mm / iommu: split need_iommu() into has_iommu_pt()

and

Quoted 8 lines

need_iommu_pt_sync()") made things finer grain by spliting need_iommu into three states.

The destruction path can't use iommu_use_hap_pt because at the point platform op is called, IOMMU is either already switched to or has always been in disabled state, and the shared PT test would always be false.

Quoted 5 lines
Quoted 1 line

Kevin, can you ack/nack this patch? Staging is currently blocked by a bug which is fixed by this patch.

Sorry I thought I've sent the ack but looks not:

Thanks
Kevin

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#6 lore raw
Quoted 19 lines · Kevin
Quoted 19 lines

From: Wei Liu [mailto:[email protected]]
Sent: Thursday, October 11, 2018 4:28 PM

Quoted 2 lines · Wei Liu

Commit 2916951c1 ("mm / iommu: include need_iommu() test in iommu_use_hap_pt()") included need_iommu() in iommu_use_hap_pt

and

Quoted 1 line

91d4eca7add ("mm / iommu: split need_iommu() into has_iommu_pt()

and

Quoted 9 lines

need_iommu_pt_sync()") made things finer grain by spliting need_iommu into three states.

The destruction path can't use iommu_use_hap_pt because at the point platform op is called, IOMMU is either already switched to or has always been in disabled state, and the shared PT test would always be false.

Quoted 7 lines
Quoted 3 lines

Kevin, can you ack/nack this patch? Staging is currently blocked by a bug which is fixed by this patch.

Sorry I thought I've sent the ack but looks not:

Thank you!

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel