arm: p2m.c bug-fix: hypervisor hang on __p2m_get_mem_access
PATCH 1/1 arm: p2m.c bug-fix: hypervisor hang on __p2m_get_mem_access
When __p2m_get_mem_access gets called, the p2m lock is already taken by either get_page_from_gva or p2m_get_mem_access.
Possible code paths:
1) -> get_page_from_gva
-> p2m_mem_access_check_and_get_page -> __p2m_get_mem_access 2) -> p2m_get_mem_access -> __p2m_get_mem_access
In both cases if __p2m_get_mem_access subsequently gets to call p2m_lookup (happens if !radix_tree_lookup(...)), a hypervisor hang will occur, since p2m_lookup also spin-locks on the p2m lock.
This bug-fix simply replaces the p2m_lookup call from __p2m_get_mem_access with a call to __p2m_lookup.
--- xen/arch/arm/p2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/p2m.c +1 -1
@@ -490,7 +490,7 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn,* No setting was found in the Radix tree. Check if the * entry exists in the page-tables. */ -paddr_t maddr =p2m_lookup (d,gfn_x (gfn) <<PAGE_SHIFT ,NULL ); +paddr_t maddr =__p2m_lookup (d,gfn_x (gfn) <<PAGE_SHIFT ,NULL );if (INVALID_PADDR == maddr )return -ESRCH ;
Signature · 1 line
2.5.0
Quoted 9 lines · Corneliu ZUZU
When
__p2m_get_mem_accessgets called, the p2m lock is already taken by eitherget_page_from_gvaorp2m_get_mem_access.Possible code paths:
1) ->get_page_from_gva-> p2m_mem_access_check_and_get_page -> __p2m_get_mem_access 2) -> p2m_get_mem_access -> __p2m_get_mem_access
What about:
-> p2m_mem_access_check -> p2m_get_mem_access
I can't see the lock being taken in that paths.
As well as fixing that I think it would be wise to add an assert that the lock is held before the call to p2m_lookup which you are changing into the unlocked variant.
Quoted 27 lines
In both cases if
__p2m_get_mem_accesssubsequently gets to callp2m_lookup(happens if !radix_tree_lookup(...)), a hypervisor hang will occur, sincep2m_lookupalso spin-locks on the p2m lock.This bug-fix simply replaces the
p2m_lookupcall from__p2m_get_mem_access
with a call to__p2m_lookup.Signed-off-by Corneliu ZUZU <[email protected]>---
xen/arch/arm/p2m.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/arm/p2m.c +1
-1@@ -490,7 +490,7 @@ static int __p2m_get_mem_access(struct domain *d,gfn_t gfn, * No setting was found in the Radix tree. Check if the * entry exists in the page-tables. */ - paddr_t maddr = p2m_lookup(d, gfn_x(gfn) << PAGE_SHIFT, NULL); + paddr_t maddr = __p2m_lookup(d, gfn_x(gfn) << PAGE_SHIFT, NULL); if ( INVALID_PADDR == maddr ) return -ESRCH;
Quoted 1 line
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
(we went offlist by mistake without noticing, resending my last reply which I think has sufficient context/quoting to make sense)
Quoted 11 lines · CORNELIU ZUZU
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Corneliu ZUZU
When
__p2m_get_mem_accessgets called, the p2m lock is already taken by eitherget_page_from_gvaorp2m_get_mem_access.Possible code paths:
1) ->get_page_from_gva-> p2m_mem_access_check_and_get_page -> __p2m_get_mem_access 2) -> p2m_get_mem_access -> __p2m_get_mem_access
Quoted 8 lines
Quoted 4 lines
What about:
-> p2m_mem_access_check -> p2m_get_mem_accessI can't see the lock being taken in that paths.
Yes, that's code path #2 I've previously mentioned, the lock is first taken in
p2m_get_mem_access(i.e. the line 'spin_lock(&p2m->lock)'), before__p2m_get_mem_accessis called.
Oh yes, not sure how I got myself confused there.
Quoted 10 lines
I'm looking @ the master branch of
git://xenbits.xenproject.org/xen.git
(although we've hit this bug on the 4.6 stable repo).Quoted 6 lines
As well as fixing that I think it would be wise to add an assert that the
lock is held before the call top2m_lookupwhich you are changing into the
unlocked variant.
Quoted 6 lines
Good idea, didn't know one could do that.
Concretely, I suppose this would be done byASSERT(spin_is_locked(&p2m->lock));
?
Right.
Quoted 4 lines
One question though. It seems that everytime
__p2m_get_mem_accessis called, the lock is taken *before the call*, not within the function itself.
Right. It's a common (but by no mean universal) convention within Xen that a __foo function is a version of foo which expects the relevant lock(s) to already be held.
Quoted 8 lines
Since
__p2m_get_mem_accessalso accesses other fields of the p2m pointer (e.g. 'p2m->mem_access_enabled'),
including performing a radix tree lookup before callingp2m_lookup, doesn't this mean that
the p2m lock is also needed for these accesses (especially for the radix tree lookup)? And if so,
shouldn't I position the assertion line @ the *beginning* of__p2m_get_mem_access, e.g. just before 'if ( !p2m->mem_access_enabled )'?
Yes, since p2m_get_mem_access requires the lock to be taken on entry it makes sense to put the assert as near the top of the function as possible.
This is true whether the initial bit of the function does anything which requires the lock.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 1/1 arm: p2m.c bug-fix: hypervisor hang on __p2m_get_mem_access
In reply to Corneliu ZUZUWhen __p2m_get_mem_access gets called, the p2m lock is already taken by either get_page_from_gva or p2m_get_mem_access. Possible code paths:
1) -> get_page_from_gva
-> p2m_mem_access_check_and_get_page -> __p2m_get_mem_access 2) -> p2m_get_mem_access -> __p2m_get_mem_access
In both cases if __p2m_get_mem_access subsequently gets to call p2m_lookup (happens if !radix_tree_lookup(...)), a hypervisor hang will occur, since p2m_lookup also spin-locks on the p2m lock.
This bug-fix simply replaces the p2m_lookup call from __p2m_get_mem_access with a call to __p2m_lookup and also adds an ASSERT to ensure that the p2m lock is already taken upon __p2m_get_mem_access entry.
---
Changed since v1:
* added p2m-lock ASSERT
--- xen/arch/arm/p2m.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/p2m.c +3 -1
@@ -468,6 +468,8 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn,#undef ACCESS }; +ASSERT (spin_is_locked (&p2m->lock)); +/* If no setting was ever set, just return rwx. */ if ( !p2m->mem_access_enabled ) {
@@ -490,7 +492,7 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn,* No setting was found in the Radix tree. Check if the * entry exists in the page-tables. */ -paddr_t maddr =p2m_lookup (d,gfn_x (gfn) <<PAGE_SHIFT ,NULL ); +paddr_t maddr =__p2m_lookup (d,gfn_x (gfn) <<PAGE_SHIFT ,NULL );if (INVALID_PADDR == maddr )return -ESRCH ;
Signature · 1 line
2.5.0
On Wed, 2016-02-03 at 13:37 +0200, Corneliu ZUZU wrote:
I just now applied a previous v2 which was already in my queue. Was this just an accidental resend of v2 or is there some important change and this is really a v3?
Quoted 51 lines
When
__p2m_get_mem_accessgets called, the p2m lock is already taken by eitherget_page_from_gvaorp2m_get_mem_access. Possible code paths:
1) ->get_page_from_gva-> p2m_mem_access_check_and_get_page -> __p2m_get_mem_access 2) -> p2m_get_mem_access -> __p2m_get_mem_accessIn both cases if
__p2m_get_mem_accesssubsequently gets to callp2m_lookup(happens if !radix_tree_lookup(...)), a hypervisor hang will occur, sincep2m_lookupalso spin-locks on the p2m lock.This bug-fix simply replaces the
p2m_lookupcall from__p2m_get_mem_access
with a call to__p2m_lookupand also adds an ASSERT to ensure that the p2m lock
is already taken upon__p2m_get_mem_accessentry.Signed-off-by Corneliu ZUZU <[email protected]>---
Changed since v1:
* added p2m-lock ASSERT
---
xen/arch/arm/p2m.c | 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)xen/arch/arm/p2m.c +0
-0@@ -468,6 +468,8 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn, #undef ACCESS };
+ ASSERT(spin_is_locked(&p2m->lock));
+
/* If no setting was ever set, just return rwx. */ if ( !p2m->mem_access_enabled )
{xen/arch/arm/p2m.c +1
-1@@ -490,7 +492,7 @@ static int __p2m_get_mem_access(struct domain *d,gfn_t gfn, * No setting was found in the Radix tree. Check if the * entry exists in the page-tables. */ - paddr_t maddr = p2m_lookup(d, gfn_x(gfn) << PAGE_SHIFT, NULL); + paddr_t maddr = __p2m_lookup(d, gfn_x(gfn) << PAGE_SHIFT, NULL); if ( INVALID_PADDR == maddr ) return -ESRCH;
Quoted 1 line
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 54 lines · Ian Campbell
On Wed, 2016-02-03 at 13:37 +0200, Corneliu ZUZU wrote:
I just now applied a previous v2 which was already in my queue. Was this just an accidental resend of v2 or is there some important change and this is really a v3?
Quoted 48 lines
When
__p2m_get_mem_accessgets called, the p2m lock is already taken by eitherget_page_from_gvaorp2m_get_mem_access. Possible code paths:
1) ->get_page_from_gva-> p2m_mem_access_check_and_get_page -> __p2m_get_mem_access 2) -> p2m_get_mem_access -> __p2m_get_mem_accessIn both cases if
__p2m_get_mem_accesssubsequently gets to callp2m_lookup(happens if !radix_tree_lookup(...)), a hypervisor hang will occur, sincep2m_lookupalso spin-locks on the p2m lock.This bug-fix simply replaces the
p2m_lookupcall from__p2m_get_mem_access
with a call to__p2m_lookupand also adds an ASSERT to ensure that the p2m lock
is already taken upon__p2m_get_mem_accessentry.Signed-off-by Corneliu ZUZU <[email protected]>---
Changed since v1:
* added p2m-lock ASSERT--- xen/arch/arm/p2m.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/arch/arm/p2m.c +2
-0@@ -468,6 +468,8 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn,#undef ACCESS }; +ASSERT (spin_is_locked (&p2m->lock)); +/* If no setting was ever set, just return rwx. */ if ( !p2m->mem_access_enabled ){xen/arch/arm/p2m.c +0
-1@@ -490,7 +492,7 @@ static int __p2m_get_mem_access(struct domain *d,gfn_t gfn, * No setting was found in the Radix tree. Check if the * entry exists in the page-tables. */ -paddr_t maddr =p2m_lookup (d,gfn_x (gfn) <<PAGE_SHIFT ,NULL );
Quoted 8 lines
xen/arch/arm/p2m.c static int __p2m_get_mem_access(struct domain *d, gfn_t gfn, · line 497
Quoted 4 lines
xen/arch/arm/p2m.c +1
-0+paddr_t maddr =__p2m_lookup (d,gfn_x (gfn) <<PAGE_SHIFT ,NULL );if (INVALID_PADDR == maddr )return -ESRCH ;_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
No, sorry, this is just a duplicate of the 1st v2, I thought the first one was not sent properly (after waiting a few days and noticing I was no longer finding it on the web).
Ignore this one. And thanks.
Corneliu.