Skip to contentSkip to conversation

x86/vtd: fix IOMMU share PT destruction path

PATCH Superseded Wei Liu 4 participants 12 messages Oct 9, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 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 already switched to disabled state and the shared PT test would always be false.

---
 xen/drivers/passthrough/vtd/iommu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +7 -1
index f94b522c73..d66d9e8ad0 100644
@@ -1752,7 +1752,13 @@ static void iommu_domain_teardown(struct domain *d)
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(hap_enabled(d));
+
+    /*
+     * We can't use iommu_use_hap_pt here because the IOMMU state is already
+     * changed to IOMMU_STATUS_disabled at this point.
+     */
+    if ( 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
#1 lore raw
Quoted 15 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 11:42
To: [email protected]
Cc: Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; Kevin Tian <[email protected]>
Subject: [PATCH] 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 4 lines

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

This is VT-d specific and the issue could affect AMD too. Can't you just switch round the call to teardown and setting IOMMU_status_disabled in xen/drivers/passthrough/iommu.c:iommu_teardown()?

Paul

Quoted 27 lines
---
 xen/drivers/passthrough/vtd/iommu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +4 -1
index f94b522c73..d66d9e8ad0 100644
@@ -1752,7 +1752,13 @@ static void iommu_domain_teardown(struct domain *d)
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(hap_enabled(d));
+
+    /*
+     * We can't use iommu_use_hap_pt here because the IOMMU state is

already

xen/drivers/passthrough/vtd/iommu.c +3 -1
+     * changed to IOMMU_STATUS_disabled at this point.
+     */
+    if ( 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

#2 lore raw
Quoted 25 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 09 October 2018 12:23
To: Wei Liu <[email protected]>; [email protected]
Cc: Kevin Tian <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/vtd: fix IOMMU share PT destruction path

Quoted 15 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 11:42
To: [email protected]
Cc: Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; Kevin Tian <[email protected]>
Subject: [PATCH] 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
Quoted 4 lines

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

This is VT-d specific and the issue could affect AMD too.

Yes, it looks like deallocate_iommu_page_tables() will then try to deallocate page tables that would not have been allocated. This probably happens to be safe because the root table is allocated on demand, but that might change in future so I think it better to fix as I suggest below.

Paul

Quoted 38 lines

Can't you just
switch round the call to teardown and setting IOMMU_status_disabled in xen/drivers/passthrough/iommu.c:iommu_teardown()?

Paul

xen/drivers/passthrough/vtd/iommu.c static void iommu_domain_teardown(struct domain

Quoted 11 lines
---
 xen/drivers/passthrough/vtd/iommu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +0 -0
index f94b522c73..d66d9e8ad0 100644
@@ -1752,7 +1752,13 @@ static void iommu_domain_teardown(struct domain

*d)

Quoted 16 lines
xen/drivers/passthrough/vtd/iommu.c +4 -1
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(hap_enabled(d));
+
+    /*
+     * We can't use iommu_use_hap_pt here because the IOMMU state is

already

xen/drivers/passthrough/vtd/iommu.c +3 -1
+     * changed to IOMMU_STATUS_disabled at this point.
+     */
+    if ( iommu_hap_pt_share )
         return;
 
     spin_lock(&hd->arch.mapping_lock);
--
Quoted 1 line

2.11.0

Quoted 4 lines

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

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

#6 lore raw
In reply to Paul Durrant
Quoted 15 lines · Paul Durrant
Quoted 15 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 11:42
To: [email protected]
Cc: Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; Kevin Tian <[email protected]>
Subject: [PATCH] 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
Quoted 4 lines

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

This is VT-d specific and the issue could affect AMD too. Can't you just switch round the call to teardown and setting IOMMU_status_disabled in xen/drivers/passthrough/iommu.c:iommu_teardown()?

AMD doesn't support shared page tables so far, but in order to avoid having to debug this again if AMD ever gains support for shared page tables I think switching the order in iommu_teardown might be better.

Thanks, Roger.

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

author
#3 lore raw
In reply to Paul Durrant
Quoted 30 lines · Paul Durrant
Quoted 30 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 09 October 2018 12:23
To: Wei Liu <[email protected]>; [email protected]
Cc: Kevin Tian <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/vtd: fix IOMMU share PT destruction path

Quoted 19 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 11:42
To: [email protected]
Cc: Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; Kevin Tian <[email protected]>
Subject: [PATCH] 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 already switched to disabled state and the shared PT test would always be false.

Quoted 9 lines
Quoted 1 line

This is VT-d specific and the issue could affect AMD too.

Yes, it looks like deallocate_iommu_page_tables() will then try to deallocate page tables that would not have been allocated. This probably happens to be safe because the root table is allocated on demand, but that might change in future so I think it better to fix as I suggest below.

Paul

Quoted 3 lines

Can't you just
switch round the call to teardown and setting IOMMU_status_disabled in xen/drivers/passthrough/iommu.c:iommu_teardown()?

OK. I will swap those lines instead.

Wei.

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

#7 lore raw
In reply to Roger Pau Monné
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 09.10.18 at 14:57, <[email protected]> wrote:
Quoted 20 lines · Paul Durrant
Quoted 19 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 11:42
To: [email protected]
Cc: Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; Kevin Tian <[email protected]>
Subject: [PATCH] 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 already switched to disabled state and the shared PT test would always be false.

Quoted 7 lines
Quoted 1 line

This is VT-d specific and the issue could affect AMD too. Can't you just

switch round the call to teardown and setting IOMMU_status_disabled in xen/drivers/passthrough/iommu.c:iommu_teardown()?

AMD doesn't support shared page tables so far, but in order to avoid having to debug this again if AMD ever gains support for shared page tables I think switching the order in iommu_teardown might be better.

I think we've pretty much ruled out AMD ever re-gaining such sharing functionality. In fact I thought we had settled that the dead code relating to this functionality could be ripped out, if anyone could carve out the time needed for doing so.

Jan

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

author
#4 lore raw
In reply to Wei Liu
Quoted 35 lines · Wei Liu
Quoted 34 lines · Paul Durrant
Quoted 25 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 09 October 2018 12:23
To: Wei Liu <[email protected]>; [email protected]
Cc: Kevin Tian <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/vtd: fix IOMMU share PT destruction path

Quoted 15 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 11:42
To: [email protected]
Cc: Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; Kevin Tian <[email protected]>
Subject: [PATCH] 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
Quoted 4 lines

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

This is VT-d specific and the issue could affect AMD too.

Yes, it looks like deallocate_iommu_page_tables() will then try to deallocate page tables that would not have been allocated. This probably happens to be safe because the root table is allocated on demand, but that might change in future so I think it better to fix as I suggest below.

Quoted 7 lines
Quoted 5 lines

Paul

Quoted 3 lines

Can't you just
switch round the call to teardown and setting IOMMU_status_disabled in xen/drivers/passthrough/iommu.c:iommu_teardown()?

OK. I will swap those lines instead.

Unfortunately swapping those two lines won't work, because for a DomU that doesn't have passthrough device, IOMMU is always disabled during its life cycle. Yet mm/p2m.c invokes iommu_share_p2m_table based solely on if hap is enabled.

Do you have other suggestions? It seems that we'd better make the predicates for enabling and disabling match.

Wei.

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

author
#8 lore raw
In reply to Wei Liu
Quoted 20 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 already switched to disabled state and the shared PT test would always be false.

---
 xen/drivers/passthrough/vtd/iommu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +0 -0
index f94b522c73..d66d9e8ad0 100644

xen/drivers/passthrough/vtd/iommu.c static void iommu_domain_teardown(struct domain *d) · line 1755

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -1752,7 +1752,13 @@ static void iommu_domain_teardown(struct domain *d)
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(hap_enabled(d));

This needs to be moved into the predicate below because PV domain can enter this path too.

Quoted 12 lines
xen/drivers/passthrough/vtd/iommu.c +6 -0
+
+    /*
+     * We can't use iommu_use_hap_pt here because the IOMMU state is already
+     * changed to IOMMU_STATUS_disabled at this point.
+     */
+    if ( iommu_hap_pt_share )
         return;
 
     spin_lock(&hd->arch.mapping_lock);
Signature · 1 line
2.11.0

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

#5 lore raw
In reply to Wei Liu
Quoted 61 lines

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

Quoted 3 lines · Wei Liu
Quoted 2 lines · Paul Durrant
Quoted 2 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On

Behalf

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Of Paul Durrant
Sent: 09 October 2018 12:23
To: Wei Liu <[email protected]>; [email protected]
Cc: Kevin Tian <[email protected]>; Wei Liu

<[email protected]>; Jan

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/vtd: fix IOMMU share PT

destruction

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

path

Quoted 6 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 11:42
To: [email protected]
Cc: Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>;

Wei Liu

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

<[email protected]>; Kevin Tian <[email protected]>
Subject: [PATCH] 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

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

need_iommu_pt_sync()") made things finer grain by spliting

need_iommu

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

into three states.

The destruction path can't use iommu_use_hap_pt because at the

point

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

platform op is called, IOMMU is already switched to disabled state

and

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

the shared PT test would always be false.

This is VT-d specific and the issue could affect AMD too.

Yes, it looks like deallocate_iommu_page_tables() will then try to

deallocate page tables that would not have been allocated. This probably happens to be safe because the root table is allocated on demand, but that might change in future so I think it better to fix as I suggest below.

Quoted 5 lines
Quoted 5 lines

Paul

Quoted 2 lines

Can't you just
switch round the call to teardown and setting IOMMU_status_disabled

in

Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

xen/drivers/passthrough/iommu.c:iommu_teardown()?

OK. I will swap those lines instead.

Unfortunately swapping those two lines won't work, because for a DomU that doesn't have passthrough device, IOMMU is always disabled during its life cycle. Yet mm/p2m.c invokes iommu_share_p2m_table based solely on if hap is enabled.

OK. This disparity between dom0 and domU set-up is annoying.

Quoted 4 lines

Do you have other suggestions? It seems that we'd better make the predicates for enabling and disabling match.

Since your patch to the VT-d code works, let's go with it then.

Paul

Quoted 1 line

Wei.

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

#9 lore raw
In reply to Wei Liu
Quoted 38 lines

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

Quoted 10 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 already switched to disabled state and the shared PT test would always be false.

Review

Quoted 6 lines
---
 xen/drivers/passthrough/vtd/iommu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/xen/drivers/passthrough/vtd/iommu.c

xen/drivers/passthrough/vtd/iommu.c static void iommu_domain_teardown(struct domain

Quoted 4 lines

index f94b522c73..d66d9e8ad0 100644

xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -1752,7 +1752,13 @@ static void iommu_domain_teardown(struct domain

*d)

xen/drivers/passthrough/vtd/iommu.c static void iommu_domain_teardown(struct domain *d) · line 1755

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(hap_enabled(d));
Quoted 11 lines

This needs to be moved into the predicate below because PV domain can enter this path too.

xen/drivers/passthrough/vtd/iommu.c static void iommu_domain_teardown(struct domain *d)

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+
+    /*
+     * We can't use iommu_use_hap_pt here because the IOMMU state is

already

Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+     * changed to IOMMU_STATUS_disabled at this point.
+     */
+    if ( iommu_hap_pt_share )
         return;

I guess the other option is to track whether there is anything to tear down in the iommu struct and test that. We have status and need_sync now, but maybe that's too simplistic.

Paul

Quoted 5 lines
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +0 -1
     spin_lock(&hd->arch.mapping_lock);
--

2.11.0

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

author
#10 lore raw
Quoted 44 lines · Paul Durrant
Quoted 44 lines

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

Quoted 10 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 already switched to disabled state and the shared PT test would always be false.

Review

Quoted 6 lines
---
 xen/drivers/passthrough/vtd/iommu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/xen/drivers/passthrough/vtd/iommu.c

xen/drivers/passthrough/vtd/iommu.c static void iommu_domain_teardown(struct domain

Quoted 4 lines

index f94b522c73..d66d9e8ad0 100644

xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -1752,7 +1752,13 @@ static void iommu_domain_teardown(struct domain

*d)

xen/drivers/passthrough/vtd/iommu.c static void iommu_domain_teardown(struct domain *d) · line 1755

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(hap_enabled(d));

This needs to be moved into the predicate below because PV domain can enter this path too.

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+
+    /*
+     * We can't use iommu_use_hap_pt here because the IOMMU state is
Quoted 7 lines
Quoted 5 lines

already

Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+     * changed to IOMMU_STATUS_disabled at this point.
+     */
+    if ( iommu_hap_pt_share )
         return;

I guess the other option is to track whether there is anything to tear down in the iommu struct and test that. We have status and need_sync now, but maybe that's too simplistic.

Using hap_enabled(d) && iommu_hap_pt_share should be good enough to me. Unless you feel strongly about this I'm not going to introduce more code churn than necessary.

Wei.

Quoted 8 lines

Paul

Quoted 5 lines
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +0 -1
     spin_lock(&hd->arch.mapping_lock);
--

2.11.0

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

#11 lore raw
Quoted 66 lines

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

Quoted 6 lines · Paul Durrant
Quoted 6 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 October 2018 15:26
To: [email protected]
Cc: Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Wei

Liu

Quoted 7 lines
Quoted 7 lines

<[email protected]>; Kevin Tian <[email protected]>
Subject: Re: [PATCH] x86/vtd: fix IOMMU share PT destruction path

Quoted 3 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

Quoted 1 line
Quoted 1 line
Quoted 1 line

need_iommu_pt_sync()") made things finer grain by spliting

need_iommu

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

into three states.

The destruction path can't use iommu_use_hap_pt because at the point platform op is called, IOMMU is already switched to disabled state

and

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

the shared PT test would always be false.

---
 xen/drivers/passthrough/vtd/iommu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/xen/drivers/passthrough/vtd/iommu.c

xen/drivers/passthrough/vtd/iommu.c static void iommu_domain_teardown(struct

Quoted 4 lines

index f94b522c73..d66d9e8ad0 100644

xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -1752,7 +1752,13 @@ static void iommu_domain_teardown(struct

domain

Quoted 7 lines
Quoted 7 lines

*d)

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
         xfree(mrmrr);
     }
 
-    if ( iommu_use_hap_pt(d) )
+    ASSERT(hap_enabled(d));
Quoted 6 lines
Quoted 6 lines

This needs to be moved into the predicate below because PV domain can enter this path too.

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+
+    /*
+     * We can't use iommu_use_hap_pt here because the IOMMU state

is

Quoted 6 lines
Quoted 5 lines

already

Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+     * changed to IOMMU_STATUS_disabled at this point.
+     */
+    if ( iommu_hap_pt_share )
         return;
Quoted 8 lines
Quoted 1 line

I guess the other option is to track whether there is anything to tear

down in the iommu struct and test that. We have status and need_sync now, but maybe that's too simplistic.

Using hap_enabled(d) && iommu_hap_pt_share should be good enough to me. Unless you feel strongly about this I'm not going to introduce more code churn than necessary.

Ok. Fair enough. Let's keep the patch small.

Paul

Quoted 10 lines

Wei.

Quoted 8 lines

Paul

Quoted 5 lines
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +0 -1
     spin_lock(&hd->arch.mapping_lock);
--

2.11.0

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