x86/hvm: Fix altp2m_op hypercall continuations
PATCH 1/1 x86/hvm: Fix altp2m_op hypercall continuations
c/s 9383de210 "x86/altp2m: support for setting restrictions for an array of pages" introduced this logic, but do_hvm_op() was already capable of handling -ERESTART correctly.
More problematic however is a continuation from compat_altp2m_op(). The arg written back into register state points into the hypercall XLAT area, not at the original parameter passed by the guest. It may be truncated by the vmentry, but definitely won't be correct on the next invocation.
Delete the hypercall_create_continuation() call, and return -ERESTART, which will cause the compat case to start working correctly.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Razvan Cojocaru <[email protected]>
CC: Petre Pircalabu <[email protected]>
--- xen/arch/x86/hvm/hvm.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
xen/arch/x86/hvm/hvm.c +2 -10
@@ -4729,12 +4729,10 @@ static int do_altp2m_op(if ( rc >0 ) { a.u.set_mem_access_multi.opaque = rc; + rc = -ERESTART ;if (__copy_field_to_guest (guest_handle_cast (arg, xen_hvm_altp2m_op_t), &a, u.set_mem_access_multi.opaque) ) rc = -EFAULT ; -else - rc =hypercall_create_continuation (__HYPERVISOR_hvm_op,"lh" , - HVMOP_altp2m, arg); }break ;
@@ -4853,14 +4851,8 @@ static int compat_altp2m_op(switch ( a.cmd ) {case HVMOP_altp2m_set_mem_access_multi: -/* -* The return code can be positive only if it is the return value -* of hypercall_create_continuation. In this case, the opaque value -* must be copied back to the guest. -*/ -if ( rc >0 ) +if ( rc == -ERESTART ) { -ASSERT (rc == __HYPERVISOR_hvm_op); a.u.set_mem_access_multi.opaque = nat.altp2m_op->u.set_mem_access_multi.opaque; if ( __copy_field_to_guest(guest_handle_cast(arg,
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 30 lines · Andrew Cooper
c/s
9383de210"x86/altp2m: support for setting restrictions for an array of pages" introduced this logic, butdo_hvm_op()was already capable of handling-ERESTARTcorrectly.More problematic however is a continuation from
compat_altp2m_op(). The arg written back into register state points into the hypercall XLAT area, not at the original parameter passed by the guest. It may be truncated by the vmentry, but definitely won't be correct on the next invocation.Delete the
hypercall_create_continuation()call, and return-ERESTART, which will cause the compat case to start working correctly.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Razvan Cojocaru <[email protected]>
CC: Petre Pircalabu <[email protected]>--- xen/arch/x86/hvm/hvm.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0@@ -4729,12 +4729,10 @@ static int do_altp2m_op(if ( rc >0 ) {
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4737
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-3a.u.set_mem_access_multi.opaque = rc; + rc = -ERESTART ;if (__copy_field_to_guest (guest_handle_cast (arg, xen_hvm_altp2m_op_t), &a, u.set_mem_access_multi.opaque) ) rc = -EFAULT ; -else - rc =hypercall_create_continuation (__HYPERVISOR_hvm_op,"lh" , - HVMOP_altp2m, arg); }break ;
Right, that part was taken from the XENMEM_access_op_set_access_multi code and plopped in. Didn't follow the call chain all the way through and so missed the simpler way of doing this.
The changes certainly look correct. I'll run some tests tomorrow as well.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 36 lines · Razvan Cojocaru
Quoted 35 lines · Andrew Cooper
c/s
9383de210"x86/altp2m: support for setting restrictions for an array of pages" introduced this logic, butdo_hvm_op()was already capable of handling-ERESTARTcorrectly.More problematic however is a continuation from
compat_altp2m_op(). The arg written back into register state points into the hypercall XLAT area, not at the original parameter passed by the guest. It may be truncated by the vmentry, but definitely won't be correct on the next invocation.Delete the
hypercall_create_continuation()call, and return-ERESTART, which will cause the compat case to start working correctly.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Razvan Cojocaru <[email protected]>
CC: Petre Pircalabu <[email protected]>--- xen/arch/x86/hvm/hvm.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)xen/arch/x86/hvm/hvm.c +1
-0@@ -4729,12 +4729,10 @@ static int do_altp2m_op(if ( rc >0 ) { a.u.set_mem_access_multi.opaque = rc; + rc = -ERESTART ;if (__copy_field_to_guest (guest_handle_cast (arg, xen_hvm_altp2m_op_t), &a, u.set_mem_access_multi.opaque) ) rc = -EFAULT ;
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4737
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +0
-3-else - rc =hypercall_create_continuation (__HYPERVISOR_hvm_op,"lh" , - HVMOP_altp2m, arg); }break ;Right, that part was taken from the
XENMEM_access_op_set_access_multicode and plopped in. Didn't follow the call chain all the way through and so missed the simpler way of doing this.
do_memory_op() is the other way around. The compat wrapper is entered first, and calls into the native path, and any set-up continuations are then adjusted by hypercall_xlat_continuation() on the way back out.
All of this parameter handling is chronically complicated, and in serious need of a more simple way to be found.
Quoted 1 line
The changes certainly look correct. I'll run some tests tomorrow as well.
Thanks,
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines · Andrew Cooper
Quoted 1 line · Razvan Cojocaru
The changes certainly look correct. I'll run some tests tomorrow as well.
Thanks,
Continuation appears to work correctly with our tests (64-bit PV domain calling 64-bit Xen / dom0). Since we're only using the external altp2m model, HVMOPs from a 32-bit guest never occur, so the issues this patch fixes are not a problem for our introspection agent, at least.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.04.19 at 19:39, <[email protected]> wrote:
c/s
9383de210"x86/altp2m: support for setting restrictions for an array of pages" introduced this logic, butdo_hvm_op()was already capable of handling-ERESTARTcorrectly.More problematic however is a continuation from
compat_altp2m_op(). The arg written back into register state points into the hypercall XLAT area, not at the original parameter passed by the guest. It may be truncated by the vmentry, but definitely won't be correct on the next invocation.
Quoted 4 lines
Delete the
hypercall_create_continuation()call, and return-ERESTART, which will cause the compat case to start working correctly.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel