xen/altp2m: set access_required properly for all altp2ms
PATCH v2 1/2 xen/altp2m: set access_required properly for all altp2ms
For the hostp2m, access_required starts off as 0, then it can be set with xc_domain_set_access_required(). However, all the altp2ms set it to 1 on init, and ignore both the hostp2m and the hypercall. This patch sets access_required to the value from the hostp2m on altp2m init, and propagates the values received via hypercall to all the active altp2ms, when applicable.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Tamas K Lengyel <[email protected]>
---
Changes since V1:
- Corrected typos in the commit message.
- Moved arch_domain_set_access_required() to x86/mm/mem_access.c and arm/mem_access.c.
- Fixed wrong tab type.
- Removed the d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) check.
- Moved the setting of p2m_get_hostp2m(d)->access_required to the arch_domain_set_access_required() function.
--- xen/arch/arm/mem_access.c | 5 +++++ xen/arch/x86/mm/mem_access.c | 18 ++++++++++++++++++ xen/arch/x86/mm/p2m.c | 3 ++- xen/common/domctl.c | 4 ++-- xen/include/xen/domain.h | 2 ++ 5 files changed, 29 insertions(+), 3 deletions(-)
xen/arch/arm/mem_access.c +5 -0
@@ -453,6 +453,11 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn,return ret; } +void arch_domain_set_access_required (struct domain *d,bool access_required) +{ +p2m_get_hostp2m (d)->access_required = access_required; +} +/* * Local variables: * mode: C
xen/arch/x86/mm/mem_access.c +18 -0
@@ -465,6 +465,24 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access)return _p2m_get_mem_access (p2m, gfn, access); } +void arch_domain_set_access_required (struct domain *d,bool access_required) +{ +unsigned int i; + +p2m_get_hostp2m (d)->access_required = access_required; + +if ( !altp2m_active (d) ) +return ; + +for ( i =0 ; i <MAX_ALTP2M ; i++ ) + { +struct p2m_domain *p2m = d->arch.altp2m_p2m[i]; + +if ( p2m ) + p2m->access_required = access_required; + } +} +/* * Local variables: * mode: C
xen/arch/x86/mm/p2m.c +2 -1
@@ -199,6 +199,7 @@ static int p2m_init_altp2m(struct domain *d) {unsigned int i;struct p2m_domain *p2m; +struct p2m_domain *hostp2m =p2m_get_hostp2m (d);mm_lock_init (&d->arch.altp2m_list_lock);for ( i =0 ; i <MAX_ALTP2M ; i++ )
@@ -210,7 +211,7 @@ static int p2m_init_altp2m(struct domain *d)return -ENOMEM ; } p2m->p2m_class = p2m_alternate; - p2m->access_required =1 ; + p2m->access_required = hostp2m->access_required;_atomic_set (&p2m->active_vcpus,0 ); }
xen/common/domctl.c +2 -2
@@ -1092,8 +1092,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)else {domain_pause (d); -p2m_get_hostp2m (d)->access_required = - op->u.access_required.access_required; +arch_domain_set_access_required (d, + op->u.access_required.access_required);domain_unpause (d); }break ;
xen/include/xen/domain.h +2 -0
@@ -66,6 +66,8 @@ void arch_domain_unpause(struct domain *d);int arch_domain_soft_reset (struct domain *d); +void arch_domain_set_access_required (struct domain *d,bool access_required); +int arch_set_info_guest (struct vcpu *,vcpu_guest_context_u );void arch_get_info_guest (struct vcpu *,vcpu_guest_context_u );
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/2 x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
vcpu_altp2m(v).p2midx can become INVALID_ALTP2M with normal usage (in altp2m_vcpu_reset()), which can then result in that value being __vmwritten() in EPTP_INDEX by vmx_vcpu_update_eptp(). The value can then end up being __vmread() in vmx_vmexit_handler() which then calls BUG_ON(idx >= MAX_ALTP2M). Since MAX_ALTP2M is currently 10 and INVALID_ALTP2M is #defined as 0xffff, the domain will always crash in this case.
---
Cc: Jun Nakajima <[email protected]>
Cc: Kevin Tian <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Tamas K Lengyel <[email protected]>
--- xen/arch/x86/hvm/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -3592,7 +3592,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) } } -if ( idx !=vcpu_altp2m (v).p2midx ) +if ( idx !=INVALID_ALTP2M && idx !=vcpu_altp2m (v).p2midx ) {BUG_ON (idx >=MAX_ALTP2M );atomic_dec (&p2m_get_altp2m (v)->active_vcpus);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs *regs) · line 3597
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 13.06.18 at 10:52, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +1
-1@@ -3592,7 +3592,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) } } -if ( idx !=vcpu_altp2m (v).p2midx ) +if ( idx !=INVALID_ALTP2M && idx !=vcpu_altp2m (v).p2midx ) {BUG_ON (idx >=MAX_ALTP2M );
In the code immediately ahead of this there is an INVALID_ALTP2M check already (in the else branch). If the __vmread() can legitimately produce this value, why would the domain be crashed when getting back INVALID_ALTP2M in the other case? I think the correctness of your change can only be judged once both code paths behave consistently.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.06.18 at 10:52, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -3592,7 +3592,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) } }
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs *regs) · line 3597
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +1
-1-if ( idx !=vcpu_altp2m (v).p2midx ) +if ( idx !=INVALID_ALTP2M && idx !=vcpu_altp2m (v).p2midx ) {BUG_ON (idx >=MAX_ALTP2M );In the code immediately ahead of this there is an
INVALID_ALTP2Mcheck already (in the else branch). If the__vmread()can legitimately produce this value, why would the domain be crashed when getting backINVALID_ALTP2Min the other case? I think the correctness of your change can only be judged once both code paths behave consistently.
You're right, I had somehow convinced myself that this is a #VE-specific problem, but it looks like a generic altp2m problem. I'll simulate the other branch in the code and see what it does with my small test application.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
Quoted 19 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.06.18 at 10:52, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -3592,7 +3592,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) } }Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs *regs) · line 3597
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +1
-1-if ( idx !=vcpu_altp2m (v).p2midx ) +if ( idx !=INVALID_ALTP2M && idx !=vcpu_altp2m (v).p2midx ) {BUG_ON (idx >=MAX_ALTP2M );In the code immediately ahead of this there is an
INVALID_ALTP2Mcheck already (in the else branch). If the__vmread()can legitimately produce this value, why would the domain be crashed when getting backINVALID_ALTP2Min the other case? I think the correctness of your change can only be judged once both code paths behave consistently.
Quoted 4 lines
You're right, I had somehow convinced myself that this is a #VE-specific problem, but it looks like a generic altp2m problem. I'll simulate the other branch in the code and see what it does with my small test application.
After a bit of debugging, the issue explained in full seems to be this (it indeed appears to be #VE-specific, as initially assumed): client application calls xc_altp2m_set_domain_state(xci, domid, 1), followed by xc_altp2m_set_vcpu_enable_notify() (with a suitable gfn), followed by xc_altp2m_set_domain_state(xci, domid, 0).
This causes Xen to go through the following steps:
1. altp2m_vcpu_initialise() (calls altp2m_vcpu_reset()).
2. HVMOP_altp2m_vcpu_enable_notify -> vmx_vcpu_update_vmfunc_ve().
3. altp2m_vcpu_destroy() (calls altp2m_vcpu_reset() and (indirectly) vmx_vcpu_update_eptp()).
4. Still part of the altp2m_vcpu_destroy() workflow, altp2m_vcpu_update_vmfunc_ve(v) gets called.
At step 2, vmx_vcpu_update_vmfunc_ve() modifies v->arch.hvm_vmx.secondary_exec_control (from 0x1054eb to 0x1474eb - which has the SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS bit set).
At step 3, altp2m_vcpu_reset() sets av->p2midx = INVALID_ALTP2M, then vmx_vcpu_update_eptp() sees that SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS is set, and as a consequence calls __vmwrite(EPTP_INDEX, vcpu_altp2m(v).p2midx).
Now, at step 4 the SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS bit should now become 0, because altp2m_vcpu_reset() has set veinfo_gfn to INVALID_GFN. But _sometimes_, what happens is that _between_ steps 3 and 4 a vmx_vmexit_handler() occurs, which __vmread()s EPTP_INDEX (on the logic branch I've tried to fix), compares it to MAX_ALTP2M and then proceeds to BUG_ON(), bringing the hypervisor down.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
Quoted 50 lines
Quoted 1 line
Quoted 1 line · On 25.06.18 at 14:12, <[email protected]> wrote:
Quoted 19 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.06.18 at 10:52, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -3592,7 +3592,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) } }Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs *regs) · line 3597
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +1
-1-if ( idx !=vcpu_altp2m (v).p2midx ) +if ( idx !=INVALID_ALTP2M && idx !=vcpu_altp2m (v).p2midx ) {BUG_ON (idx >=MAX_ALTP2M );In the code immediately ahead of this there is an
INVALID_ALTP2Mcheck already (in the else branch). If the__vmread()can legitimately produce this value, why would the domain be crashed when getting backINVALID_ALTP2Min the other case? I think the correctness of your change can only be judged once both code paths behave consistently.Quoted 4 lines
You're right, I had somehow convinced myself that this is a #VE-specific problem, but it looks like a generic altp2m problem. I'll simulate the other branch in the code and see what it does with my small test application.
After a bit of debugging, the issue explained in full seems to be this (it indeed appears to be #VE-specific, as initially assumed): client application calls
xc_altp2m_set_domain_state(xci, domid, 1), followed byxc_altp2m_set_vcpu_enable_notify()(with a suitable gfn), followed byxc_altp2m_set_domain_state(xci, domid, 0).This causes Xen to go through the following steps:
1.
altp2m_vcpu_initialise()(callsaltp2m_vcpu_reset()).
2.HVMOP_altp2m_vcpu_enable_notify->vmx_vcpu_update_vmfunc_ve().
3.altp2m_vcpu_destroy()(callsaltp2m_vcpu_reset()and (indirectly)vmx_vcpu_update_eptp()).
4. Still part of thealtp2m_vcpu_destroy()workflow,altp2m_vcpu_update_vmfunc_ve(v)gets called.At step 2,
vmx_vcpu_update_vmfunc_ve()modifiesv->arch.hvm_vmx.secondary_exec_control(from0x1054ebto0x1474eb- which has theSECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSbit set).At step 3,
altp2m_vcpu_reset()setsav->p2midx=INVALID_ALTP2M, thenvmx_vcpu_update_eptp()sees thatSECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSis set, and as a consequence calls__vmwrite(EPTP_INDEX, vcpu_altp2m(v).p2midx).
Quoted 6 lines
Now, at step 4 the
SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSbit should now become 0, becausealtp2m_vcpu_reset()has setveinfo_gfntoINVALID_GFN. But _sometimes_, what happens is that _between_ steps 3 and 4 avmx_vmexit_handler()occurs, which __vmread()sEPTP_INDEX(on the logic branch I've tried to fix), compares it toMAX_ALTP2Mand then proceeds toBUG_ON(), bringing the hypervisor down.
Thanks for the detailed analysis. With that I wonder whether it is reasonable for a VM exit to occur in parallel with the processing of altp2m_vcpu_destroy(). Shouldn't a domain (or vCPU) undergoing such a mode change be paused?
I also remain unconvinced that a similar race is entirely impossible in the non-#VE case.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
Quoted 57 lines · Jan Beulich
Quoted 50 lines
Quoted 1 line
Quoted 1 line · On 25.06.18 at 14:12, <[email protected]> wrote:
Quoted 19 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.06.18 at 10:52, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -3592,7 +3592,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) } }Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs *regs) · line 3597
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +1
-1-if ( idx !=vcpu_altp2m (v).p2midx ) +if ( idx !=INVALID_ALTP2M && idx !=vcpu_altp2m (v).p2midx ) {BUG_ON (idx >=MAX_ALTP2M );In the code immediately ahead of this there is an
INVALID_ALTP2Mcheck already (in the else branch). If the__vmread()can legitimately produce this value, why would the domain be crashed when getting backINVALID_ALTP2Min the other case? I think the correctness of your change can only be judged once both code paths behave consistently.Quoted 4 lines
You're right, I had somehow convinced myself that this is a #VE-specific problem, but it looks like a generic altp2m problem. I'll simulate the other branch in the code and see what it does with my small test application.
After a bit of debugging, the issue explained in full seems to be this (it indeed appears to be #VE-specific, as initially assumed): client application calls
xc_altp2m_set_domain_state(xci, domid, 1), followed byxc_altp2m_set_vcpu_enable_notify()(with a suitable gfn), followed byxc_altp2m_set_domain_state(xci, domid, 0).This causes Xen to go through the following steps:
1.
altp2m_vcpu_initialise()(callsaltp2m_vcpu_reset()).
2.HVMOP_altp2m_vcpu_enable_notify->vmx_vcpu_update_vmfunc_ve().
3.altp2m_vcpu_destroy()(callsaltp2m_vcpu_reset()and (indirectly)vmx_vcpu_update_eptp()).
4. Still part of thealtp2m_vcpu_destroy()workflow,altp2m_vcpu_update_vmfunc_ve(v)gets called.At step 2,
vmx_vcpu_update_vmfunc_ve()modifiesv->arch.hvm_vmx.secondary_exec_control(from0x1054ebto0x1474eb- which has theSECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSbit set).At step 3,
altp2m_vcpu_reset()setsav->p2midx=INVALID_ALTP2M, thenvmx_vcpu_update_eptp()sees thatSECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSis set, and as a consequence calls__vmwrite(EPTP_INDEX, vcpu_altp2m(v).p2midx).Quoted 6 lines
Now, at step 4 the
SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSbit should now become 0, becausealtp2m_vcpu_reset()has setveinfo_gfntoINVALID_GFN. But _sometimes_, what happens is that _between_ steps 3 and 4 avmx_vmexit_handler()occurs, which __vmread()sEPTP_INDEX(on the logic branch I've tried to fix), compares it toMAX_ALTP2Mand then proceeds toBUG_ON(), bringing the hypervisor down.
Quoted 7 lines
Thanks for the detailed analysis. With that I wonder whether it is reasonable for a VM exit to occur in parallel with the processing of
altp2m_vcpu_destroy(). Shouldn't a domain (or vCPU) undergoing such a mode change be paused?I also remain unconvinced that a similar race is entirely impossible in the non-#VE case.
Apologies, I seem to have misread the crash timing.
A "good run":
(XEN) [ 1923.964832] altp2m_vcpu_initialise() (XEN) [ 1923.964836] altp2m_vcpu_reset()
(XEN) [ 1923.964837] 1 altp2m_vcpu_update_p2m() (XEN) [ 1923.964838] vmx_vcpu_update_eptp() (XEN) [ 1923.964876] HVMOP_altp2m_vcpu_enable_notify (XEN) [ 1923.964878] vmx_vcpu_update_vmfunc_ve(0), v->arch.hvm_vmx.secondary_exec_control: 0x1054eb (XEN) [ 1923.964880] exit vmx_vcpu_update_vmfunc_ve(0), v->arch.hvm_vmx.secondary_exec_control: 0x1474eb (XEN) [ 1923.964986] altp2m_vcpu_destroy() (XEN) [ 1923.964987] altp2m_vcpu_reset()
(XEN) [ 1923.964988] 2 altp2m_vcpu_update_p2m() (XEN) [ 1923.964989] vmx_vcpu_update_eptp() (XEN) [ 1923.964991] __vmwrite(EPTP_INDEX, 65535) (XEN) [ 1923.964992] vmx_vcpu_update_vmfunc_ve(0), v->arch.hvm_vmx.secondary_exec_control: 0x1474eb (XEN) [ 1923.964993] exit vmx_vcpu_update_vmfunc_ve(0), v->arch.hvm_vmx.secondary_exec_control: 0x1054eb
Crash:
(XEN) [ 1924.367273] altp2m_vcpu_initialise() (XEN) [ 1924.367277] altp2m_vcpu_reset()
(XEN) [ 1924.367278] 1 altp2m_vcpu_update_p2m() (XEN) [ 1924.367279] vmx_vcpu_update_eptp() (XEN) [ 1924.367318] HVMOP_altp2m_vcpu_enable_notify (XEN) [ 1924.367321] vmx_vcpu_update_vmfunc_ve(0), v->arch.hvm_vmx.secondary_exec_control: 0x1054eb (XEN) [ 1924.367326] exit vmx_vcpu_update_vmfunc_ve(0), v->arch.hvm_vmx.secondary_exec_control: 0x1474eb (XEN) [ 1924.367344] Xen BUG at vmx.c:3407
The vmx_vmexit_handler() call appears to happen right after the first vmx_vcpu_update_vmfunc_ve() call, but still before altp2m_vcpu_destroy(). I was also quite confuse that a vmx_vmexit_handler() run is possible in parallel with an HVMOP.
I'll keep digging.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
Quoted 21 lines
(XEN) [ 1923.964832]
altp2m_vcpu_initialise()(XEN) [ 1923.964836]altp2m_vcpu_reset()
(XEN) [ 1923.964837] 1altp2m_vcpu_update_p2m()(XEN) [ 1923.964838]vmx_vcpu_update_eptp()(XEN) [ 1923.964876]HVMOP_altp2m_vcpu_enable_notify(XEN) [ 1923.964878]vmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1054eb(XEN) [ 1923.964880] exitvmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1474eb(XEN) [ 1923.964986]altp2m_vcpu_destroy()(XEN) [ 1923.964987]altp2m_vcpu_reset()
(XEN) [ 1923.964988] 2altp2m_vcpu_update_p2m()(XEN) [ 1923.964989]vmx_vcpu_update_eptp()(XEN) [ 1923.964991]__vmwrite(EPTP_INDEX, 65535)(XEN) [ 1923.964992]vmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1474eb(XEN) [ 1923.964993] exitvmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1054ebCrash:
Quoted 10 lines
(XEN) [ 1924.367273]
altp2m_vcpu_initialise()(XEN) [ 1924.367277]altp2m_vcpu_reset()
(XEN) [ 1924.367278] 1altp2m_vcpu_update_p2m()(XEN) [ 1924.367279]vmx_vcpu_update_eptp()(XEN) [ 1924.367318]HVMOP_altp2m_vcpu_enable_notify(XEN) [ 1924.367321]vmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1054eb(XEN) [ 1924.367326] exitvmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1474eb(XEN) [ 1924.367344] Xen BUG at vmx.c:3407
Actually I think this shows us the problem: 65535 (INVALID_ALTP2M) is a stale value from a previous good run. But the EPTP_INDEX value is ignored unless SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS is set. So at the crash point, SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS just got set, the "live" index is 0, and the stale INVALID_ALTP2M value is being read from the previous run (and compared to 0 and MAX_ALTP2M).
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
Quoted 14 lines
Quoted 13 lines
Quoted 1 line · On 25.06.18 at 14:40, <[email protected]> wrote:
Crash:
(XEN) [ 1924.367273]
altp2m_vcpu_initialise()(XEN) [ 1924.367277]altp2m_vcpu_reset()
(XEN) [ 1924.367278] 1altp2m_vcpu_update_p2m()(XEN) [ 1924.367279]vmx_vcpu_update_eptp()(XEN) [ 1924.367318]HVMOP_altp2m_vcpu_enable_notify(XEN) [ 1924.367321]vmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1054eb(XEN) [ 1924.367326] exitvmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1474eb(XEN) [ 1924.367344] Xen BUG at vmx.c:3407
Quoted 6 lines
Actually I think this shows us the problem: 65535 (
INVALID_ALTP2M) is a stale value from a previous good run. But theEPTP_INDEXvalue is ignored unlessSECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSis set. So at the crash point,SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSjust got set, the "live" index is 0, and the staleINVALID_ALTP2Mvalue is being read from the previous run (and compared to 0 andMAX_ALTP2M).
So perhaps the writing of EPTP_INDEX should be done earlier?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 13 lines
Quoted 1 line · On 25.06.18 at 14:40, <[email protected]> wrote:
Crash:
(XEN) [ 1924.367273]
altp2m_vcpu_initialise()(XEN) [ 1924.367277]altp2m_vcpu_reset()
(XEN) [ 1924.367278] 1altp2m_vcpu_update_p2m()(XEN) [ 1924.367279]vmx_vcpu_update_eptp()(XEN) [ 1924.367318]HVMOP_altp2m_vcpu_enable_notify(XEN) [ 1924.367321]vmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1054eb(XEN) [ 1924.367326] exitvmx_vcpu_update_vmfunc_ve(0),v->arch.hvm_vmx.secondary_exec_control:0x1474eb(XEN) [ 1924.367344] Xen BUG at vmx.c:3407
Quoted 8 lines
Quoted 6 lines
Actually I think this shows us the problem: 65535 (
INVALID_ALTP2M) is a stale value from a previous good run. But theEPTP_INDEXvalue is ignored unlessSECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSis set. So at the crash point,SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONSjust got set, the "live" index is 0, and the staleINVALID_ALTP2Mvalue is being read from the previous run (and compared to 0 andMAX_ALTP2M).So perhaps the writing of
EPTP_INDEXshould be done earlier?
And indeed I can confirm this: I've added a sleep() in my test between xc_altp2m_set_vcpu_enable_notify() and xc_altp2m_set_domain_state(xci, domid, 0), and it _always_ crashes Xen on the second run.
Quite right, that's exactly what I've been doing: a satisfactory fix appears to be to simply reverse the order of altp2m_vcpu_update_p2m(v) and altp2m_vcpu_update_vmfunc_ve(v) in altp2m_vcpu_destroy().
I'll send out a patch ASAP.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH V2 2/2] x86/altp2m: Fixed domain crash with INVALID_ALTP2M EPTP index
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 25.06.18 at 14:59, <[email protected]> wrote:
Quite right, that's exactly what I've been doing: a satisfactory fix appears to be to simply reverse the order of
altp2m_vcpu_update_p2m(v)andaltp2m_vcpu_update_vmfunc_ve(v)inaltp2m_vcpu_destroy().
And that's also more logical considering that vmx_vcpu_update_vmfunc_ve() modifies SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS which vmx_vcpu_update_eptp() actually looks at to decide whether to write EPTP_INDEX.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 29 lines · Razvan Cojocaru
--- xen/arch/arm/mem_access.c | 5 +++++ xen/arch/x86/mm/mem_access.c | 18 ++++++++++++++++++ xen/arch/x86/mm/p2m.c | 3 ++- xen/common/domctl.c | 4 ++-- xen/include/xen/domain.h | 2 ++ 5 files changed, 29 insertions(+), 3 deletions(-)xen/arch/arm/mem_access.c +5
-0@@ -453,6 +453,11 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn,return ret; } +void arch_domain_set_access_required (struct domain *d,bool access_required) +{ +p2m_get_hostp2m (d)->access_required = access_required; +} +/* * Local variables: * mode: C xen/arch/x86/mm/mem_access.c +0
-0
xen/arch/x86/mm/mem_access.c int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access) · line 468
Quoted 4 lines
xen/arch/x86/mm/mem_access.c +1
-0@@ -465,6 +465,24 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access)return _p2m_get_mem_access (p2m, gfn, access); } +void arch_domain_set_access_required (struct domain *d,bool access_required)
arch_p2m_set_access_required?
Quoted 5 lines
xen/arch/x86/mm/mem_access.c +5
-0+{ +unsigned int i; + +p2m_get_hostp2m (d)->access_required = access_required; +
xen/arch/x86/mm/mem_access.c int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access) · line 483
Quoted 10 lines
xen/arch/x86/mm/mem_access.c +10
-0+if ( !altp2m_active (d) ) +return ; + +for ( i =0 ; i <MAX_ALTP2M ; i++ ) + { +struct p2m_domain *p2m = d->arch.altp2m_p2m[i]; + +if ( p2m ) + p2m->access_required = access_required; + }
It seems to me you should check for domain pause count at the beginning of this function to avoid mistakes.
The rest of looks fine (to my untrained eye).
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 33 lines · Wei Liu
Quoted 32 lines · Razvan Cojocaru
--- xen/arch/arm/mem_access.c | 5 +++++ xen/arch/x86/mm/mem_access.c | 18 ++++++++++++++++++ xen/arch/x86/mm/p2m.c | 3 ++- xen/common/domctl.c | 4 ++-- xen/include/xen/domain.h | 2 ++ 5 files changed, 29 insertions(+), 3 deletions(-)xen/arch/arm/mem_access.c +5
-0@@ -453,6 +453,11 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn,return ret; } +void arch_domain_set_access_required (struct domain *d,bool access_required) +{ +p2m_get_hostp2m (d)->access_required = access_required; +} +/* * Local variables: * mode: C xen/arch/x86/mm/mem_access.c +0
-0@@ -465,6 +465,24 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access)return _p2m_get_mem_access (p2m, gfn, access); }
Quoted 3 lines
xen/arch/x86/mm/mem_access.c int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access) · line 468
Quoted 1 line
xen/arch/x86/mm/mem_access.c +1
-0+void arch_domain_set_access_required (struct domain *d,bool access_required)
arch_p2m_set_access_required?
I'll change it.
Quoted 10 lines
Quoted 10 lines
xen/arch/x86/mm/mem_access.c +10
-0+{ +unsigned int i; + +p2m_get_hostp2m (d)->access_required = access_required; + +if ( !altp2m_active (d) ) +return ; + +for ( i =0 ; i <MAX_ALTP2M ; i++ ) + {
Quoted 8 lines
xen/arch/x86/mm/mem_access.c int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access) · line 483
Quoted 5 lines
xen/arch/x86/mm/mem_access.c +5
-0+struct p2m_domain *p2m = d->arch.altp2m_p2m[i]; + +if ( p2m ) + p2m->access_required = access_required; + }It seems to me you should check for domain pause count at the beginning of this function to avoid mistakes.
Do you mean ASSERT(atomic_read(&d->pause_count)); ?
Quoted 1 line
The rest of looks fine (to my untrained eye).
Thanks!
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 19 lines · Razvan Cojocaru
Quoted 10 lines
Quoted 10 lines
xen/arch/x86/mm/mem_access.c +10
-0+{ +unsigned int i; + +p2m_get_hostp2m (d)->access_required = access_required; + +if ( !altp2m_active (d) ) +return ; + +for ( i =0 ; i <MAX_ALTP2M ; i++ ) + {Quoted 8 lines
xen/arch/x86/mm/mem_access.c int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access) · line 483
Quoted 5 lines
xen/arch/x86/mm/mem_access.c +5
-0+struct p2m_domain *p2m = d->arch.altp2m_p2m[i]; + +if ( p2m ) + p2m->access_required = access_required; + }It seems to me you should check for domain pause count at the beginning of this function to avoid mistakes.
Quoted 1 line
Do you mean ASSERT(atomic_read(&d->pause_count)); ?
Yes.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel